本文介绍了此商家没有可接受的信用卡 - Google Pay的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

此商家没有可接受的信用卡.

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

这是我正在使用的代码:

const allowedAuthMethods = ['PAN_ONLY','CRYPTOGRAM_3DS'] ;const baseCardPaymentMethod = {类型:'卡',参数: {allowedCardNetworks: allowedNetworks,allowedAuthMethods: allowedAuthMethods}};const googlePayBaseConfiguration = {api版本:2,apiVersionMinor: 0,allowedPaymentMethods: [baseCardPaymentMethod]};/*** 保存用于调用不同可用方法的 Google Pay 客户端* 通过 API.* @type {PaymentsClient}* @私人的*/让 googlePayClient;/*** 定义和处理与集成相关的主要操作* 谷歌支付.当 Google Pay 库脚本有* 加载完毕.*/函数 onGooglePayLoaded() {googlePayClient = 新的 google.payments.api.PaymentsClient({环境:'测试'});googlePayClient.isReadyToPay(googlePayBaseConfiguration).then(功能(响应){如果(响应.结果){createAndAddButton();} 别的 {alert("无法使用 Google Pay 支付");}}).catch(函数(错误){console.error("确定是否准备好使用 Google Pay 时出错:", err);});}/*** 处理使用 Google Pay 支付的按钮的创建.* 创建后,此按钮将附加到 DOM 元素下* '立即购买'.*/函数 createAndAddButton() {const googlePayButton = googlePayClient.createButton({//如果默认或省略,当前默认为黑色buttonColor: '默认',//如果省略则默认为 long按钮类型:'长',onClick: onGooglePaymentsButtonClicked});document.getElementById('buy-now').appendChild(googlePayButton);}/*** 处理点击按钮以使用 Google Pay 付款.需要* 定义用于加载的支付数据请求* 用户可用的付款方式.*/函数 onGooglePaymentsButtonClicked() {const 标记化规范 = {类型:'PAYMENT_GATEWAY',参数: {网关:'示例',gatewayMerchantId: 'exampleGatewayMerchantId'}};const cardPaymentMethod = {类型:'卡',标记化规范:标记化规范,参数: {allowedCardNetworks: ['VISA','MASTERCARD'],allowedAuthMethods: ['PAN_ONLY','CRYPTOGRAM_3DS'],billingAddressRequired: 真,billingAddress 参数:{格式:'完整',电话号码必填:true}}};常量事务信息 = {totalPriceStatus:'最终',总价:'123.45',货币代码:'美元',国家代码:'美国'};const 商户信息 = {MerchantId: '01234567890123456789',//仅在生产中商家名称:'示例商家名称'};const paymentDataRequest = Object.assign({}, googlePayBaseConfiguration, {allowedPaymentMethods: [cardPaymentMethod],交易信息:交易信息,商户信息:商户信息});谷歌支付客户端.loadPaymentData(paymentDataRequest).then(function(paymentData) {处理付款(付款数据);}).catch(函数(错误){//日志错误:{ statusCode: CANCELED ||开发人员_错误 }});}函数 processPayment(paymentData) {//TODO:使用有效负载向您的处理器发送 POST 请求//https://us-central1-devrel-payments.cloudfunctions.net/google-pay-server//抱歉,这超出了此代码实验室的范围.返回新的承诺(功能(解决,拒绝){//@todo 将支付令牌传递给您的网关以处理支付const paymentToken = paymentData.paymentMethodData.tokenizationData.token;console.log('模拟发送令牌' + paymentToken + ' 到支付处理器');设置超时(函数(){console.log('来自处理器的模拟响应');警报('完成');解决({});}, 800);});}```
解决方案

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

这是我根据您的代码段创建的 JSFiddle:

I am trying to integrate Google Pay web into my website but when i click "pay with googlepay" its shows the below error:

There are no accepted cards available for use with this merchant.

When i read documentation it says you can add example as merchant for testing, I just wanted to use test environment but still its not working.

Here is the code that i am using:

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);
  });
} ```
解决方案

This message means that the current Google user doesn't have any cards that are compatible with the payment options that the merchant has provided. Specifically allowedCardNetworks and allowedAuthMethods.

Here is a JSFiddle that I created based on your snippet: https://jsfiddle.net/aumg6ncb/

This is what I get back after clicking on the button:

这篇关于此商家没有可接受的信用卡 - Google Pay的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-26 08:34