* Validate PaymentDataRequest. * * @param {!PaymentDataRequest} paymentDataRequest * @return {?string} errorMessage if the request is invalid.
(paymentDataRequest)
| 16144 | * @return {?string} errorMessage if the request is invalid. |
| 16145 | */ |
| 16146 | function validatePaymentDataRequest(paymentDataRequest) { |
| 16147 | if (!paymentDataRequest) { |
| 16148 | return 'paymentDataRequest must be set!'; |
| 16149 | } |
| 16150 | if (paymentDataRequest.swg) { |
| 16151 | return validatePaymentDataRequestForSwg(paymentDataRequest.swg); |
| 16152 | } else if (!paymentDataRequest.transactionInfo) { |
| 16153 | return 'transactionInfo must be set!'; |
| 16154 | } else if (!paymentDataRequest.transactionInfo.currencyCode) { |
| 16155 | return 'currencyCode in transactionInfo must be set!'; |
| 16156 | } else if ( |
| 16157 | !paymentDataRequest.transactionInfo.totalPriceStatus || |
| 16158 | !Object.values(Constants.TotalPriceStatus) |
| 16159 | .includes(paymentDataRequest.transactionInfo.totalPriceStatus)) { |
| 16160 | return 'totalPriceStatus in transactionInfo must be set to one of' + |
| 16161 | ' NOT_CURRENTLY_KNOWN, ESTIMATED or FINAL!'; |
| 16162 | } else if ( |
| 16163 | paymentDataRequest.transactionInfo.totalPriceStatus !== |
| 16164 | 'NOT_CURRENTLY_KNOWN' && |
| 16165 | !paymentDataRequest.transactionInfo.totalPrice) { |
| 16166 | return 'totalPrice in transactionInfo must be set when' + |
| 16167 | ' totalPriceStatus is ESTIMATED or FINAL!'; |
| 16168 | } |
| 16169 | |
| 16170 | // Validate payment data request for UPI payment method |
| 16171 | const allowedPaymentMethod = getUpiPaymentMethod(paymentDataRequest); |
| 16172 | if (allowedPaymentMethod) { |
| 16173 | if (!allowedPaymentMethod['parameters']) { |
| 16174 | return 'parameters must be set in allowedPaymentMethod!'; |
| 16175 | } |
| 16176 | |
| 16177 | var parameters = allowedPaymentMethod['parameters']; |
| 16178 | if (!parameters['payeeVpa']) { |
| 16179 | return 'payeeVpa in allowedPaymentMethod parameters must be set!'; |
| 16180 | } else if (!parameters['payeeName']) { |
| 16181 | return 'payeeName in allowedPaymentMethod parameters must be set!'; |
| 16182 | } else if (!parameters['referenceUrl']) { |
| 16183 | return 'referenceUrl in allowedPaymentMethod parameters must be set!'; |
| 16184 | } else if (!parameters['mcc']) { |
| 16185 | return 'mcc in allowedPaymentMethod parameters must be set!'; |
| 16186 | } else if (!parameters['transactionReferenceId']) { |
| 16187 | return 'transactionReferenceId in allowedPaymentMethod parameters' + |
| 16188 | ' must be set!'; |
| 16189 | } |
| 16190 | |
| 16191 | if (paymentDataRequest['transactionInfo']['currencyCode'] !== 'INR') { |
| 16192 | return 'currencyCode in transactionInfo must be set to INR!'; |
| 16193 | } else if ( |
| 16194 | paymentDataRequest['transactionInfo']['totalPriceStatus'] !== 'FINAL') { |
| 16195 | return 'totalPriceStatus in transactionInfo must be set to FINAL!'; |
| 16196 | } else if (!paymentDataRequest['transactionInfo']['transactionNote']) { |
| 16197 | return 'transactionNote in transactionInfo must be set!'; |
| 16198 | } |
| 16199 | } |
| 16200 | return null; |
| 16201 | } |
| 16202 | |
| 16203 | /** |
no test coverage detected