Deposit Flow

### 1. When user click on "Proceed" button, request is sent to
```json
const paylaod = {
transactionEntityId: values.transactionEntityId,
amount: values.depositAmount,
currency: 'USD',
action: 'WALLET_FUNDING',
session,
);
```
```javascript=
const authParam = getAuthParam(session);
post("/api/torc/Transaction", payload, authParam, true);
```
### 2. When initiate transaction response is received. a reqeust is made to verify OTP action
```json
const reqPayload = {
session,
mobile: `${EnsureMobileExtensionFormat(phoneCode)}${phone}`,
action: `WALLET_FUNDING-{transactionId}`,
actionText:
this.props.LOV.result.OTPActionText.DEPOSIT_TO_WALLET_ACTION_TEXT, // from LOV api
};
```
```javascript
const { action, session } = payload;
const url = `${ENDPOINT}/checkOTPVerifiedForAction/${action}`;
const authParam = getAuthParam(session);
get(`${ENDPOINT}/checkOTPVerifiedForAction/${action}`, authParam )
```
### 3. When verifyOtpAction response is received, depends on whether response.OtpVerified is true:
#### 3.1 when OtpVerified === false:
##### 3.1.1 `/api/otpUserService/sendOtpForAction` is called
```json
const payload = {
action: "WALLET_FUNDING-${transactionId}",
actionText:
this.props.LOV.result.OTPActionText.DEPOSIT_TO_WALLET_ACTION_TEXT,
session: this.props.session,
};
```
```javascript
const authParam = getAuthParam(session);
post("/api/otpUserService/sendOtpForAction",payload,authParam )
```
##### 3.1.2 When response is received from sendOtpForAction, OTP Diaglogue is opend in the UI

##### 3.1.3 User enters OTP and `/api/otpUserService/validateOtpVerifiedForAction` is called
```json
{
otp: otpInput,
action: `WALLET_FUNDING-${this.props.initiateTransactionAction.data.transactionId}`,
session: this.props.session,
}
```
```javascript
export const validateOtp = (payload) => {
const { otp, action, session } = payload;
const url = `/api/otpUserService/validateOtpVerifiedForAction`;
const authParam = getAuthParam(session);
const requestPayload = { otp, action };
return post(url, requestPayload, authParam);
};
```
##### 3.1.4 When response is received from validateOtpVerifiedForAction: call `/api/otpUserService/getRakOtpForAction`
- Continues [3.2](3.2-When-OtpVerifyed-====true:)
#### 3.2 When OtpVerifyed ====true:
##### 3.2.1 `/api/otpUserService/getRakOtpForAction` is called.
// sorry im still trying to figure out what is this guy doing thus the full code
// `otpRakFlag` came from `LOV.result.general.rakOtpTimerFlag`, not sure what that mean
```json
const payload = {
session: this.props.session,
otpRakFlag: this.state.otpRakFlag,
otpType: this.state.rakAccountSelected
? 'DigInvestmentAccount'
: 'DigInvestmentCreditCard',
customerType: 'R',
reqReferenceNo: '',
customerId: this.props.userInfo.customerId,
resend: false,
maskedCreditCard: '',
otp_metadata: {
accountType: 'A',
value: {
currency: 'USD',
amount: this.props.initiateTransactionAction.data.amount,
},
},
};
```
```javascript
export const sendRakOtp = (payload) => {
const {
otpRakFlag,
otpType,
customerType,
customerId,
reqReferenceNo,
otp_metadata: {
accountType,
value: { currency, amount },
},
resend,
maskedCreditCard,
session,
} = payload;
const url = `/api/otpUserService/getRakOtpForAction`;
const authParam = getAuthParam(session);
const requestPayload = {
otpType,
customerType,
customerId,
reqReferenceNo,
accountType,
currency,
amount,
resend,
maskedCreditCard,
};
// eslint-disable-next-line prefer-const
let apiresponse = {
response: {
result: {
otp_reference_no: '353689',
otp_generated_date: '2021-08-04T10:05:58.000Z',
otp_expiry_date: '2021-08-04T10:15:58.000Z',
},
},
};
// eslint-disable-next-line radix
if (parseInt(otpRakFlag) === 0) {
if (resend === false) {
return apiresponse;
}
return new Promise((resolve) =>
setTimeout(() => {
resolve(apiresponse);
}, 5000),
);
}
return post(url, requestPayload, authParam);
};
```
##### 3.2.2 When response is received from getRakOtpForAction, Rak OTP diaglogue is shown and `response.result.otp_reference_no` is stored for later use

##### 3.2.3 User enters the OTP and `/api/otpUserService/validateRakOtpForAction` is called
```json
const reqPayload = {
session: this.props.session,
otpRakFlag: this.state.otpRakFlag,
otpType: this.state.rakAccountSelected
? 'DigInvestmentAccount'
: 'DigInvestmentCreditCard',
customerType: 'R',
customerId: this.props.userInfo.customerId,
reqReferenceNo: this.state.reqReferenceNo,
otp: otpRakInput,
maskedCreditCard: '',
otp_metadata: {
accountType: 'A',
value: {
currency: 'USD',
amount: this.props.initiateTransactionAction.data.amount,
},
},
};
```
```javascript
export const validateRakOtp = (payload) => {
const {
otpRakFlag,
otpType,
customerType,
customerId,
reqReferenceNo,
otp_metadata: {
accountType,
value: { currency, amount },
},
otp,
maskedCreditCard,
session,
} = payload;
const url = `/api/otpUserService/validateRakOtpForAction/validateRakOtpForAction`;
const authParam = getAuthParam(session);
const requestPayload = {
otpType,
customerType,
customerId,
reqReferenceNo,
accountType,
currency,
amount,
otp,
maskedCreditCard,
};
const finalresponse = {
response: { result: 200 },
// response: { result: 204 },
};
// eslint-disable-next-line radix
if (parseInt(otpRakFlag) === 0) {
if (otp === '221100') {
return finalresponse;
}
return Promise.reject(getErrorInfo('403'));
}
return post(url, requestPayload, authParam);
};
```
##### 3.2.4 after validateRakOtpForAction response is received, `/api/torc/Transaction` is called
```
{
transactionId: this.props.initiateTransactionAction.data.transactionId,
status: 'INIT_COMPLETED',
session: this.props.session,
}
```
```javascript
export const completeTransaction = ({
transactionId,
status,
session,
goalId,
}) => {
const url = `/api/torc/Transaction`;
let payload = {
transactionId,
status,
};
if (goalId) {
payload = {
transactionId,
status,
goalId,
};
}
const authParam = getAuthParam(session);
return update(url, payload, authParam, true);
};
```