Android 在 Nexus 上支付移动网络意外错误

Android Pay Mobile Web on Nexus unexpected error

我已经开始尝试 android 在我们的一个网站上工作以获得报酬。我已经设置了一个基本的设置脚本来在测试站点上创建普通支付。

一切似乎都很顺利,直到用户单击触发 Android 支付的元素。当用户单击 OS 中的 "slide up" 但它在显示任何内容之前就死了,我收到一条错误消息:

“请求失败

发生意外错误。请稍后再试。"

控制台或调试器中没有任何内容可以给出错误性质的任何指示。

这是JS:

<script>

    if (window.PaymentRequest) {

        var request = createPaymentRequest();

      request.canMakePayment()
          .then(function (result) {
            if (result) {
              addPayWithGoogleButton();
            }
          })
          .catch(function (err) {
            showErrorForDebugging(
                'canMakePayment() error! ' + err.name + ' error: ' + err.message);
          });
    } else {
      showErrorForDebugging('PaymentRequest API not available.');
    }

    /**
     * Add a purchase button alongside the existing checkout option
     */
    function addPayWithGoogleButton() {
      var payWithGoogleButton = document.createElement('button');
      payWithGoogleButton.appendChild(document.createTextNode('Purchase'));
      payWithGoogleButton.addEventListener('click', onPayWithGoogleClicked);
      document.getElementById('checkout').appendChild(payWithGoogleButton);
    }

    /**
     * Show purchase chooser when buy button clicked
     */
    function onPayWithGoogleClicked() {
      createPaymentRequest()
          .show()
          .then(function(response) {
            // Dismiss payment dialog
            response.complete('success');
            handlePaymentResponse(response);
          })
          .catch(function(err) {
            showErrorForDebugging('show() error! ' + err.name + ' error: ' + err.message);
          });
    }

    /**
     * Configure support for the Google Payments API
     *
     * @returns {object} data attribute suitable for PaymentMethodData
     */
    function getGooglePaymentsConfiguration() {
      return {
        // Merchant ID available after approval by Google.
        // 'merchantId':'01234567890123456789',
        'environment': 'TEST',
        'apiVersion': 1,
        'allowedPaymentMethods': ['CARD', 'TOKENIZED_CARD'],
        'paymentMethodTokenizationParameters': {
          'tokenizationType': 'PAYMENT_GATEWAY',
          // Check with your payment gateway on the parameters to pass.
          'parameters': {}
        },
        'cardRequirements': {
          'allowedCardNetworks': ['AMEX', 'DISCOVER', 'MASTERCARD', 'VISA'],
          'billingAddressRequired': true,
          'billingAddressFormat': 'MIN'
        },
        'phoneNumberRequired': true,
        'emailRequired': true,
        'shippingAddressRequired': true
      };
    }

    /**
     * Create a PaymentRequest
     *
     * @returns {PaymentRequest}
     */
    function createPaymentRequest() {
      // Support Google Payment API.
      var methodData = [{
        'supportedMethods': ['https://google.com/pay'],
        'data': getGooglePaymentsConfiguration()
      }];

      var details = {
        total: {label: 'Test Purchase', amount: {currency: 'USD', value: '1.00'}}
      };

      return new PaymentRequest(methodData, details);
    }

    /**
     * Process a PaymentResponse
     *
     * @param {PaymentResponse} response returned when user approves the purchase request
     */
    function handlePaymentResponse(response) {
      var formattedResponse = document.createElement('pre');
      formattedResponse.appendChild(
          document.createTextNode(JSON.stringify(response.toJSON(), null, 2)));
      document.getElementById('checkout')
          .insertAdjacentElement('afterend', formattedResponse);
    }

    /**
     * Display an error message
     *
     * @param {string} text message to display
     */
    function showErrorForDebugging(text) {
      var errorDisplay = document.createElement('code');
      errorDisplay.style.color = 'red';
      errorDisplay.appendChild(document.createTextNode(text));
      var p = document.createElement('p');
      p.appendChild(errorDisplay);
      document.getElementById('checkout').insertAdjacentElement('afterend', p);
    }
</script>

对于遇到此问题的任何其他人 - 教程代码似乎有问题。我们通过更改以下代码来修复它:

function createPaymentRequest() {
  // Support Google Payment API.
  var methodData = [{
    'supportedMethods': ['https://google.com/pay'],
    'data': getGooglePaymentsConfiguration()
  }];

  var details = {
    total: {label: 'Test Purchase', amount: {currency: 'USD', value: '1.00'}}
  };

  return new PaymentRequest(methodData, details);
}

对此:

function createPaymentRequest() {
      // Support Google Payment API.
      var methodData = [{
        'supportedMethods': 'basic-card',
        'data': getGooglePaymentsConfiguration()
      }];

      var details = {
        total: {label: 'Test Purchase', amount: {currency: 'USD', value: '1.00'}}
      };

      return new PaymentRequest(methodData, details);
    }