我正试图在我的网站上使用Stripe建立Apple Pay。
我遵循这里的说明,https://stripe.com/docs/stripe-js/elements/payment-request-button
我已经在Stripe上注册了我的域名
然后,我在我的macbook上的钱包里添加了测试卡,见这里。
当我在本地主机上运行ngrok时,ngrok向我展示了以下内容
ngrok (Ctrl+C to quit)
Hello World! https://ngrok.com/next-generation
Session Status online
Account XXXXXXX (Plan: Pro)
Version 3.0.6
Region United States (us)
Latency 302ms
Web Interface http://127.0.0.1:4040
Forwarding https://XXXXXXXXXX.ngrok.io -> https://blabla.xxxxx.com:443
Connections ttl opn rt1 rt5 p50 p90
91 0 0.01 0.01 5.03 9.41
HTTP Requests
-------------
GET /frontend/web/debug/default/toolbar 200 OK
GET /frontend/web/payment/checkout/ 200 OK
GET /frontend/web/debug/default/toolbar 200 OK
GET /frontend/web/payment/checkout/ 200 OK
GET /frontend/web/debug/default/toolbar 200 OK
GET /frontend/web/payment/checkout/ 200 OK
GET /frontend/web/debug/default/toolbar 200 OK
GET /frontend/web/payment/checkout/ 200 OK
GET /frontend/web/debug/default/toolbar 200 OK
GET /frontend/web/payment/checkout/ 200 OK
当我通过Safari上的ngrok域查看我的站点时,我在safari控制台上得到了这个错误
Either you do not have a card saved to your Wallet or the current domain (XXXXXXXX.ngrok.io) is not registered for Apple Pay. Visit https://dashboard.stripe.com/account/apple_pay to register this domain.
我使用stripe.js和stripe.js作为我的付款。这是我的JS
var publishableKey = document.getElementById('payment-form').getAttribute('data-stripe-publishable-key');
var paymentIntent = document.getElementById('payment-form').getAttribute('data-stripe-paymentIntent');
document.addEventListener('DOMContentLoaded', async () => {
if (!publishableKey) {
document.getElementById('applepay-error').textContent = 'No publishable key returned from the server';
}
// 1. Initialize Stripe
const stripe = Stripe(publishableKey, {
apiVersion: '2020-08-27',
});
// 2. Create a payment request object
var paymentRequest = stripe.paymentRequest({
country: 'US',
currency: 'usd',
total: {
label: 'Demo total',
amount: 1999,
},
requestPayerName: true,
requestPayerEmail: true,
});
// 3. Create a PaymentRequestButton element
const elements = stripe.elements();
const prButton = elements.create('paymentRequestButton', {
paymentRequest: paymentRequest,
});
// Check the availability of the Payment Request API,
// then mount the PaymentRequestButton
paymentRequest.canMakePayment().then(function (result) {
if (result) {
prButton.mount('#applepay-element');
} else {
document.getElementById('applepay-element').style.display = 'none';
document.getElementById('applepay-error').textContent = 'Apple Pay support not found. Check the pre-requisites above and ensure you are testing in a supported browser.';
}
});
paymentRequest.on('paymentmethod', async (e) => {
// Confirm the PaymentIntent without handling potential next actions (yet).
let {error, paymentIntent} = await stripe.confirmCardPayment(
clientSecret,
{
payment_method: e.paymentMethod.id,
},
{
handleActions: false,
}
);
if (error) {
document.getElementById('applepay-error').textContent = error.message;
// 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.
e.complete('fail');
return;
}
// Report to the browser that the confirmation was successful, prompting
// it to close the browser payment method collection interface.
e.complete('success');
// Check if the PaymentIntent requires any actions and if so let Stripe.js
// handle the flow. If using an API version older than "2019-02-11" instead
// instead check for: `paymentIntent.status === "requires_source_action"`.
if (paymentIntent.status === 'requires_action') {
// Let Stripe.js handle the rest of the payment flow.
let {error, paymentIntent} = await stripe.confirmCardPayment(
clientSecret
);
if (error) {
// The payment failed -- ask your customer for a new payment method.
document.getElementById('applepay-error').textContent = error.message;
return;
}
document.getElementById('applepay-error').textContent = 'Payment ${paymentIntent.status}: ${paymentIntent.id}';
}
document.getElementById('applepay-error').textContent = 'Payment ${paymentIntent.status}: ${paymentIntent.id}';
});
});
知道怎么让这件事起作用吗?谢谢。
发布于 2022-08-22 02:48:24
可能有多个原因需要反复检查:
你可以再检查一遍,向你的朋友或同事寻求检查的帮助。如果这没有帮助,那么写信给Stripe支持,他们将能够帮助进一步检查3)。
https://stackoverflow.com/questions/73427218
复制相似问题