У меня установлен cordova-plugin-applepay вместе со следующим скриптом:
Код: Выделить всё
require_once('/var/www/vhosts/stripe-php-latest/init.php');
// Initialize Stripe
const stripe = Stripe('');
// Create a payment request
const paymentRequest = stripe.paymentRequest({
country: 'US',
currency: 'usd',
total: {
label: 'Demo total',
amount: 100,
},
requestPayerName: true,
requestPayerEmail: true,
});
// Check the availability of the Payment Request API
const elements = stripe.elements();
const prButton = elements.create('paymentRequestButton', {
paymentRequest: paymentRequest,
});
// Check if the Apple Pay button can be displayed
paymentRequest.canMakePayment().then(function (result) {
if (result) {
document.getElementById('apple-pay-button').style.display = 'block';
prButton.mount('#apple-pay-button');
alert('Apple Pay');
} else {
alert('Apple Pay is not available.');
}
});
// Handle payment method creation
paymentRequest.on('paymentmethod', async (ev) => {
const {paymentIntent, error: backendError} = await fetch('nav/pay/payment.php', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
payment_method: ev.paymentMethod.id,
}),
}).then(r => r.json());
if (backendError) {
ev.complete('fail');
console.error(backendError);
} else {
ev.complete('success');
stripe.confirmCardPayment(paymentIntent.client_secret).then(function (result) {
if (result.error) {
console.error(result.error.message);
} else if (result.paymentIntent.status === 'succeeded') {
console.log('Payment succeeded!');
}
});
}
});
На данный момент я застрял в Cordova и не могу перейти на ионный/конденсаторный.
Кто-нибудь добился успеха с помощью Stripe.js/cordova/apple pay?
Подробнее здесь: https://stackoverflow.com/questions/787 ... -apple-pay