third_party/subscriptions-project/swg.js
/**
   * Handle is ready to pay for api v2.
   *
   * @param {!IsReadyToPayRequest} isReadyToPayRequest
   * @return {!Promise} The promise will contain the boolean result and error
   *     message when possible.
   * @private
   */
Handle is ready to pay for api v2.
@param {!IsReadyToPayRequest} isReadyToPayRequest
@return {!Promise} The promise will contain the boolean result and error
message when possible.
@private
Handle is ready to pay for api v2 . @param { !IsReadyToPayRequest } isReadyToPayRequest @return { !Promise } The promise will contain the boolean result and error message when possible . @private
isReadyToPayApiV2ForChromePaymentRequest_(isReadyToPayRequest) {
    let defaultPromise = Promise.resolve({'result': false});
    if (isReadyToPayRequest.existingPaymentMethodRequired) {
      defaultPromise = Promise.resolve({
        'result': false,
        'paymentMethodPresent': false,
      });
    }
    let nativePromise = defaultPromise;
    if (
      apiV2DoesMerchantSupportSpecifiedCardType(
        isReadyToPayRequest,
        Constants.AuthMethod.CRYPTOGRAM_3DS
      )
    ) {
      const nativeRtpRequest  = JSON.parse(
        JSON.stringify(isReadyToPayRequest)
      );
      for (let i = 0; i < nativeRtpRequest.allowedPaymentMethods.length; i++) {
        if (
          nativeRtpRequest.allowedPaymentMethods[i].type ==
          Constants.PaymentMethod.CARD
        ) {
          nativeRtpRequest.allowedPaymentMethods[i].parameters[
            'allowedAuthMethods'
          ] = [Constants.AuthMethod.CRYPTOGRAM_3DS];
        }
      }
      nativePromise = this.delegate_.isReadyToPay(nativeRtpRequest);
    }
    let webPromise = defaultPromise;
    if (
      apiV2DoesMerchantSupportSpecifiedCardType(
        isReadyToPayRequest,
        Constants.AuthMethod.PAN_ONLY
      )
    ) {
      webPromise = this.webActivityDelegate_.isReadyToPay(isReadyToPayRequest);
    }
    if (chromeSupportsPaymentHandler()) {
      return nativePromise.then(() => webPromise);
    }
    return nativePromise.then((nativeResult) => {
      if ((nativeResult && nativeResult['result']) == true) {
        return nativeResult;
      }
      return webPromise;
    });
  }
isReadyToPayApiV2ForChromePaymentRequest_ ( isReadyToPayRequest ) { let defaultPromise = Promise . resolve ( { 'result' : false } ) ; if ( isReadyToPayRequest . existingPaymentMethodRequired ) { defaultPromise = Promise . resolve ( { 'result' : false , 'paymentMethodPresent' : false , } ) ; } let nativePromise = defaultPromise ; if ( apiV2DoesMerchantSupportSpecifiedCardType ( isReadyToPayRequest , Constants . AuthMethod . CRYPTOGRAM_3DS ) ) { const nativeRtpRequest = JSON . parse ( JSON . stringify ( isReadyToPayRequest ) ) ; for ( let i = 0 ; i < nativeRtpRequest . allowedPaymentMethods . length ; i ++ ) { if ( nativeRtpRequest . allowedPaymentMethods [ i ] . type == Constants . PaymentMethod . CARD ) { nativeRtpRequest . allowedPaymentMethods [ i ] . parameters [ 'allowedAuthMethods' ] = [ Constants . AuthMethod . CRYPTOGRAM_3DS ] ; } } nativePromise = this . delegate_ . isReadyToPay ( nativeRtpRequest ) ; } let webPromise = defaultPromise ; if ( apiV2DoesMerchantSupportSpecifiedCardType ( isReadyToPayRequest , Constants . AuthMethod . PAN_ONLY ) ) { webPromise = this . webActivityDelegate_ . isReadyToPay ( isReadyToPayRequest ) ; } if ( chromeSupportsPaymentHandler ( ) ) { return nativePromise . then ( ( ) => webPromise ) ; } return nativePromise . then ( ( nativeResult ) => { if ( ( nativeResult && nativeResult [ 'result' ] ) == true ) { return nativeResult ; } return webPromise ; } ) ; }
Handle is ready to pay for api v2.
Handle is ready to pay for api v2 .
// If the merchant supports tokenized cards. // Make a separate call to gms core to check if the user isReadyToPay // with just tokenized cards. We can't pass in PAN_ONLY here // because gms core always returns true for PAN_ONLY. // Leave other payment methods as is. /** @type {!IsReadyToPayRequest} */ // Update session storage with payment handler canMakePayment result but // rely on web delegate for actual response