【问题标题】:Apple Pay - "Payment Not Completed" - Using StripeApple Pay - “付款未完成” - 使用 Stripe
【发布时间】:2019-04-05 06:43:18
【问题描述】:

我正在使用条纹“付款请求按钮”为我的网站实施 Apple Pay。在事情的条纹方面一切都很好。正如我在 Stripe 日志中验证的那样,令牌通过了正确的传递。 https://stripe.com/docs/stripe-js/elements/payment-request-button

但是,我每次尝试完成测试付款时都会收到一条错误消息:Apple Pay 发出“付款未完成”。

这让我陷入了困境,我不确定如何调试或修复。有任何想法吗?

我得到一个未定义的令牌

这是错误:

我的设置:

前端:

<script src="https://js.stripe.com/v3/"></script>
<div id="payment-request-button">
  <!-- A Stripe Element will be inserted here. -->
</div>



<script>
var stripe = Stripe('pk_test_xxxxx');

var paymentRequest = stripe.paymentRequest({
  country: 'US',
  currency: 'usd',
  total: {
    label: 'JobQuiz',
    amount: 999,
  },
  requestPayerName: true,
  requestPayerEmail: false,
});


var elements = stripe.elements();
var prButton = elements.create('paymentRequestButton', {
  paymentRequest: paymentRequest,
});

// Check the availability of the Payment Request API first.
paymentRequest.canMakePayment().then(function(result) {
  if (result) {
    prButton.mount('#payment-request-button');
  } else {
    document.getElementById('payment-request-button').style.display = 'none';
  }
});

   paymentRequest.on('token', function(ev) {
  // Send the token to your server to charge it!
    fetch('/apple-pay', {
    method: 'POST',
    body: JSON.stringify({token: ev.token.id}),
    headers: {'content-type': 'application/json'},
  })
  .then(function(response) {
    if (response.ok) {
      // Report to the browser that the payment was successful, prompting
      // it to close the browser payment interface.
      ev.complete('success');
    } else {
      // Report to the browser that the payment failed, prompting it to
      // re-show the payment interface, or show an error message and close
      // the payment interface.
      ev.complete('fail');
    }
  });
});

</script>

app.js 中的服务器端代码

app.post('/apple-pay', function(req, res, next) {


// Set your secret key: remember to change this to your live secret key in production
// See your keys here: https://dashboard.stripe.com/account/apikeys
var stripe = require("stripe")("sk_test_xxxxxx");

// Token is created using Checkout or Elements!
// Get the payment token ID submitted by the form:
const token = req.body.token; // Using Express

const charge = stripe.charges.create({
  amount: 999,
  currency: 'usd',
  description: 'Example charge',
  source: token,
}, function(err, charge){ 
if (err){

} else { 

}
});
});

【问题讨论】:

  • 你能澄清错误吗?它是出现在 Apple Pay 模式中还是稍后出现在 Stripe 中?这个流程在我看来是正确的。
  • 在手机上,在 Apple Pay 中,我没有收到指示付款成功的复选标记 - 我收到“付款未完成”错误。
  • 任何想法@korben?
  • 您需要实际设置一个端点以接受 Apple Pay 在 /charges 创建的令牌,该令牌使用该令牌创建费用 (stripe.com/docs/api#create_charge)。
  • @korben - 谢谢!!!您是否有机会向我指出如何正确使用节点来做到这一点?

标签: ios node.js express stripe-payments payment


【解决方案1】:

终于解决了。它最终成为我的 bodyParser 设置的问题。这解释了为什么令牌虽然是空的却被传递。我忽略了包含 app.use(bodyParser.json());下面...

app.use(bodyParser.urlencoded({extended: true}));
app.use(bodyParser.json());

【讨论】:

    猜你喜欢
    • 2018-12-31
    • 2014-12-20
    • 1970-01-01
    • 1970-01-01
    • 2020-09-18
    • 2022-07-21
    • 2014-12-19
    • 1970-01-01
    • 2017-05-13
    相关资源
    最近更新 更多