Странная проблема здесь. Следуя документации, я присоединяю PaymentMethod к существующему клиенту, но он не работает. Грубо говоря, я:
- создать клиента
- создать платежное намерение с клиентом
- создать элемент карты с платежным намерением
- покупателя вводит данные карты
- , подтвердил успешную оплату и отправил намерение обратно бэкэнду
- , если намерение достигнуто и клиент решил сохранить свою карту, создайте способ оплаты с помощью метода намерения, а клиент
- получить ошибку
Код:
- python:
stripe.Customer.create(email=user.email, name=user.full_name)
- python:
stripe.PaymentIntent.create(amount=amount, currency="aud", customer=user.stripe_customer_id)
- js:
Stripe('{{ stripe_publishable_key }}').elements().create("card");
- пользователь: вводит данные карты
- js:
stripe.confirmCardPayment('{{ clientSecret }}', {
payment_method: {
card: card,
billing_details: {
// name: 'Jenny Rosen'
},
}
}).then(function (result) {
if (result.error) {
// Show error to your customer (e.g., insufficient funds)
console.log(result.error.message);
var displayError = document.getElementById('card-errors');
displayError.textContent = result.error.message;
} else {
// The payment has been processed!
if (result.paymentIntent.status === 'succeeded') {
// Show a success message to your customer
// There's a risk of the customer closing the window before callback
// execution. Set up a webhook or plugin to listen for the
// payment_intent.succeeded event that handles any business critical
// post-payment actions.
$('#fake-submit').click();
}
}
});
- python:
stripe.PaymentMethod.attach(stripe.PaymentIntent.retrieve(intent_id).payment_method, customer=user.stripe_customer_id)
- ошибка:
Request req_request_id: This PaymentMethod was previously used without being attached to a Customer or was detached from a Customer, and may not be used again.