* Convert Tez payment data to GPay payment data if payment succeeded, or * reject if payment failed * * @private * @param {!PaymentData} tezPaymentData The payment data object from Tez. * @param {!PaymentDataRequest} paymentDataRequest The payment data request. * @param {!Object} u
(tezPaymentData, paymentDataRequest, upiPaymentMethod)
| 17117 | * error message. |
| 17118 | */ |
| 17119 | processData_(tezPaymentData, paymentDataRequest, upiPaymentMethod) { |
| 17120 | const tezResponse = JSON.parse(tezPaymentData['tezResponse']); |
| 17121 | if (tezResponse['Status'] === 'FAILURE') { |
| 17122 | let error; |
| 17123 | switch (tezResponse['responseCode']) { |
| 17124 | case 'ZM': |
| 17125 | // payment failure due to invalid MPIN |
| 17126 | error = { |
| 17127 | 'errorCode': PublicErrorCode.BUYER_ACCOUNT_ERROR, |
| 17128 | 'errorMessage': 'Payment failure due to invalid MPIN.' |
| 17129 | }; |
| 17130 | break; |
| 17131 | case 'Z9': |
| 17132 | // payment failure due to insufficient funds |
| 17133 | error = { |
| 17134 | 'errorCode': PublicErrorCode.BUYER_ACCOUNT_ERROR, |
| 17135 | 'errorMessage': 'Payment failure due to insufficient funds.' |
| 17136 | }; |
| 17137 | break; |
| 17138 | case '91': |
| 17139 | // payment failure due to transaction timeout or connection issue |
| 17140 | error = { |
| 17141 | 'errorCode': PublicErrorCode.INTERNAL_ERROR, |
| 17142 | 'errorMessage': |
| 17143 | 'Payment failure due to transaction timeout or connection' + |
| 17144 | ' issue.' |
| 17145 | }; |
| 17146 | break; |
| 17147 | default: |
| 17148 | // payment failure due to user cancel or other issues |
| 17149 | error = {'errorMessage': 'Payment cancelled.'}; |
| 17150 | } |
| 17151 | return Promise.reject(error); |
| 17152 | } |
| 17153 | |
| 17154 | const signedMessage = { |
| 17155 | 'paymentMethodType': 'UPI', |
| 17156 | 'payeeVpa': upiPaymentMethod['parameters']['payeeVpa'], |
| 17157 | 'status': tezResponse['Status'], |
| 17158 | 'transactionReferenceId': |
| 17159 | upiPaymentMethod['parameters']['transactionReferenceId'], |
| 17160 | 'transactionId': upiPaymentMethod['parameters']['transactionId'] ? |
| 17161 | upiPaymentMethod['parameters']['transactionId'] : |
| 17162 | tezResponse['txnId'], |
| 17163 | 'transactionInfo': paymentDataRequest['transactionInfo'], |
| 17164 | }; |
| 17165 | |
| 17166 | let paymentData = { |
| 17167 | 'apiVersion': paymentDataRequest['apiVersion'], |
| 17168 | 'apiVersionMinor': paymentDataRequest['apiVersionMinor'], |
| 17169 | 'paymentMethodData': { |
| 17170 | 'type': upiPaymentMethod['type'], |
| 17171 | 'tokenizationData': { |
| 17172 | 'type': 'DIRECT', |
| 17173 | 'token': { |
| 17174 | 'protocolVersion': 'ECv1', |
| 17175 | // TODO: Verify that response comes from tez and |
| 17176 | // add signature and encrypt signed message here |
no test coverage detected