* Validate IsReadyToPayRequest. * * @param {!IsReadyToPayRequest} isReadyToPayRequest * @return {?string} errorMessage if the request is invalid.
(isReadyToPayRequest)
| 16072 | * @return {?string} errorMessage if the request is invalid. |
| 16073 | */ |
| 16074 | function validateIsReadyToPayRequest(isReadyToPayRequest) { |
| 16075 | if (!isReadyToPayRequest) { |
| 16076 | return 'isReadyToPayRequest must be set!'; |
| 16077 | } else if (isReadyToPayRequest.apiVersion >= 2) { |
| 16078 | if (!('apiVersionMinor' in isReadyToPayRequest)) { |
| 16079 | return 'apiVersionMinor must be set!'; |
| 16080 | } |
| 16081 | if (!isReadyToPayRequest.allowedPaymentMethods || |
| 16082 | !Array.isArray(isReadyToPayRequest.allowedPaymentMethods) || |
| 16083 | isReadyToPayRequest.allowedPaymentMethods.length == 0) { |
| 16084 | return 'for v2 allowedPaymentMethods must be set to an array containing a list of accepted payment methods'; |
| 16085 | } |
| 16086 | for (var i = 0; i < isReadyToPayRequest.allowedPaymentMethods.length; i++) { |
| 16087 | let allowedPaymentMethod = isReadyToPayRequest.allowedPaymentMethods[i]; |
| 16088 | if (allowedPaymentMethod['type'] == Constants.PaymentMethod.CARD) { |
| 16089 | if (!allowedPaymentMethod['parameters']) { |
| 16090 | return 'Field parameters must be setup in each allowedPaymentMethod'; |
| 16091 | } |
| 16092 | var allowedCardNetworks = |
| 16093 | allowedPaymentMethod['parameters']['allowedCardNetworks']; |
| 16094 | if (!allowedCardNetworks || !Array.isArray(allowedCardNetworks) || |
| 16095 | allowedCardNetworks.length == 0) { |
| 16096 | return 'allowedCardNetworks must be setup in parameters for type CARD'; |
| 16097 | } |
| 16098 | var allowedAuthMethods = |
| 16099 | allowedPaymentMethod['parameters']['allowedAuthMethods']; |
| 16100 | if (!allowedAuthMethods || !Array.isArray(allowedAuthMethods) || |
| 16101 | allowedAuthMethods.length == 0 || |
| 16102 | !allowedAuthMethods.every(isAuthMethodValid)) { |
| 16103 | return 'allowedAuthMethods must be setup in parameters for type \'CARD\' ' + |
| 16104 | ' and must contain \'CRYPTOGRAM_3DS\' and/or \'PAN_ONLY\''; |
| 16105 | } |
| 16106 | } |
| 16107 | } |
| 16108 | return null; |
| 16109 | } else if ( |
| 16110 | !isReadyToPayRequest.allowedPaymentMethods || |
| 16111 | !Array.isArray(isReadyToPayRequest.allowedPaymentMethods) || |
| 16112 | isReadyToPayRequest.allowedPaymentMethods.length == 0 || |
| 16113 | !isReadyToPayRequest.allowedPaymentMethods.every(isPaymentMethodValid)) { |
| 16114 | return 'allowedPaymentMethods must be set to an array containing \'CARD\' ' + |
| 16115 | 'and/or \'TOKENIZED_CARD\'!'; |
| 16116 | } |
| 16117 | return null; |
| 16118 | } |
| 16119 | |
| 16120 | /** |
| 16121 | * Validate the payment method. |