【问题标题】:There are no accepted cards available for use with this merchant - Google Pay没有可用于此商家的可接受的卡 - Google Pay
【发布时间】:2020-03-09 07:23:46
【问题描述】:

我正在尝试将 Google Pay 网络集成到我的网站中,但是当我点击“使用 googlepay 付款”时,它会显示以下错误:

没有可用于此商家的可接受的卡。

当我阅读文档时,它说您可以添加示例作为商家进行测试,我只是想使用测试环境但仍然无法正常工作。

这是我正在使用的代码:

const allowedAuthMethods = ['PAN_ONLY','CRYPTOGRAM_3DS'] ;

const baseCardPaymentMethod = {
  type: 'CARD',
  parameters: {
    allowedCardNetworks: allowedNetworks,
    allowedAuthMethods: allowedAuthMethods 
  }
};

const googlePayBaseConfiguration = {
  apiVersion: 2,
  apiVersionMinor: 0,
  allowedPaymentMethods: [baseCardPaymentMethod]
};

/**
 * Holds the Google Pay client used to call the different methods available
 * through the API.
 * @type {PaymentsClient}
 * @private
 */
let googlePayClient;

/**
 * Defines and handles the main operations related to the integration of
 * Google Pay. This function is executed when the Google Pay library script has
 * finished loading.
 */
function onGooglePayLoaded() {
  googlePayClient = new google.payments.api.PaymentsClient({
        environment: 'TEST'
    });

  googlePayClient.isReadyToPay(googlePayBaseConfiguration)
  .then(function(response) {
    if(response.result) {
      createAndAddButton();
    } else {
      alert("Unable to pay using Google Pay");
    }
  }).catch(function(err) {
    console.error("Error determining readiness to use Google Pay: ", err);
  });

}

/**
 * Handles the creation of the button to pay with Google Pay.
 * Once created, this button is appended to the DOM, under the element 
 * 'buy-now'.
 */
function createAndAddButton() {

  const googlePayButton = googlePayClient.createButton({

    // currently defaults to black if default or omitted
    buttonColor: 'default',

    // defaults to long if omitted
    buttonType: 'long',

    onClick: onGooglePaymentsButtonClicked
  });

  document.getElementById('buy-now').appendChild(googlePayButton);
}

/**
 * Handles the click of the button to pay with Google Pay. Takes
 * care of defining the payment data request to be used in order to load
 * the payments methods available to the user.
 */
function onGooglePaymentsButtonClicked() {

  const tokenizationSpecification = {
  type: 'PAYMENT_GATEWAY',
  parameters: {
    gateway: 'example',
    gatewayMerchantId: 'exampleGatewayMerchantId'
  }
 };

  const cardPaymentMethod = {
  type: 'CARD',
  tokenizationSpecification: tokenizationSpecification,
  parameters: {
    allowedCardNetworks: ['VISA','MASTERCARD'],
    allowedAuthMethods: ['PAN_ONLY','CRYPTOGRAM_3DS'],
    billingAddressRequired: true,
    billingAddressParameters: {
      format: 'FULL',
      phoneNumberRequired: true
      }
    }
  };

  const transactionInfo = {
  totalPriceStatus: 'FINAL',
  totalPrice: '123.45',
  currencyCode: 'USD',
  countryCode: 'US'
  };

  const merchantInfo = {
   merchantId: '01234567890123456789', //Only in PRODUCTION
  merchantName: 'Example Merchant Name'
  };

  const paymentDataRequest = Object.assign({}, googlePayBaseConfiguration, {
  allowedPaymentMethods: [cardPaymentMethod],
  transactionInfo: transactionInfo,
  merchantInfo: merchantInfo   
  });

  googlePayClient
  .loadPaymentData(paymentDataRequest)
  .then(function(paymentData) {
    processPayment(paymentData);
  }).catch(function(err) {
    // Log error: { statusCode: CANCELED || DEVELOPER_ERROR }
  });
}

function processPayment(paymentData) {
  // TODO: Send a POST request to your processor with the payload
  // https://us-central1-devrel-payments.cloudfunctions.net/google-pay-server 
  // Sorry, this is out-of-scope for this codelab.
  return new Promise(function(resolve, reject) {
    // @todo pass payment token to your gateway to process payment
    const paymentToken = paymentData.paymentMethodData.tokenizationData.token;
    console.log('mock send token ' + paymentToken + ' to payment processor');
    setTimeout(function() {
      console.log('mock response from processor');
      alert('done');
      resolve({});
    }, 800);
  });
} ```

【问题讨论】:

    标签: javascript payment-gateway google-pay


    【解决方案1】:

    没有可用于此商家的可接受的卡。

    此消息表示当前的 Google 用户没有任何与商家提供的付款方式兼容的卡。特别是allowedCardNetworksallowedAuthMethods

    这是我根据您的 sn-p 创建的 JSFiddle:https://jsfiddle.net/aumg6ncb/

    这是我点击按钮后返回的内容:

    【讨论】:

      【解决方案2】:

      如果您使用的是测试模式:- 我认为您在 Chrome 浏览器或 Google 电子钱包上使用了测试卡

      在测试 Google Pay 时,您应该在 Chrome 浏览器或 Google 电子钱包中保存一张真实卡,并激活您的测试 API 密钥/测试 Google Pay 环境。真卡不会收费,Google 在结帐流程中通过了一张测试卡,而不是真卡。当用户尝试将其保存在 Chrome 中时,我们的普通测试卡无法与 Google Pay 一起使用

      【讨论】:

        猜你喜欢
        • 2020-10-21
        • 1970-01-01
        • 1970-01-01
        • 2019-03-13
        • 1970-01-01
        • 2021-10-18
        • 2018-03-01
        • 2017-10-14
        • 2013-08-21
        相关资源
        最近更新 更多