#Sandip Kundu - PM
1 messages · Page 1 of 1 (latest)
Hi! This is possible to do, but only if the payment method is attached to a customer. we recommend you use a SetupIntent or a PaymentIntent with setup_future_usage to do so.
https://stripe.com/docs/api/payment_methods/attach
$paymentIntents = $stripe->paymentIntents->create([
'amount' => $_REQUEST['amount']*100,
'currency' => $_REQUEST['currency'],
'payment_method_types' => ['card_present'],
'description' => 'Software development services',
'customer' => 'cus_LKt18Gbx03ynVq',
'payment_method' => 'pm_1KeEPwSFxQJUWTjSBr8jk9mQ',
]);
print_r($paymentIntents);
this is my code !
payment method is already attached with customer but when i am giving payment method it returns status code 500 error
Can you share the request ID (req_xxx)? Here's how you can find it: https://support.stripe.com/questions/finding-the-id-for-an-api-request
This error is expected, you can only attach a payment method to a customer once.
i am trying to charge same customer
Also note that directly creating a payment method like this is not recommended. It looks like you are storing the card numbers on your own server which requires to be PCI compliant.
i am trying to charge same customer
If the payment method was already attached to the customer, it should work. Do you have a request ID where you tried this and it failed?
yes
it showing incomplete
but not fails.
req_EhXrcC3dRUJPrs this is the request id
No we never store cards into our system.
The request you just shared is to retrieve a payment method. Can you share the request where you actually tried to make a payment?
req_V1RLkaXJ7QEi9L
No we never store cards into our system.
Maybe you don't store them, but it looks like your server process the raw card number, which is not allowed unless you are PCI compliant.
req_V1RLkaXJ7QEi9L this is the request id you are looking for
Thanks! In this request you forgot to set the payment_method .
You need to include both the customer and the payment_method when creating the PaymentIntent
when i set the payment method with payment intent then it will error.
but my question is payment method is already attached with the customer then why i need to attach the payment method again with payment intent ?
when i set the payment method with payment intent then it will error.
Can you share the request ID?
but my question is payment method is already attached with the customer then why i need to attach the payment method again with payment intent ?
No, if the payment method is already attached, you don't need to attach it again.
then why the payment status going incomplete due to payment method ?
In this reqyuest ( req_V1RLkaXJ7QEi9L ) , payment method is already attached with the customer then why i need to attach the payment method again with payment intent ?
why i need to attach the payment method again with payment intent ?
No, like I said multiple time, you only need to attach the payment method once.
In the request you just shared, you forgot to include the payment_method in the request.
You need to include both the customer and the payment_method when creating the PaymentIntent
To clarify: you attach the payment method to the customer once, but then for every PaymentIntent you create, you need to pass both the customer and the payment_method, otherwise it won't work.
can i use the same payment method which attached with the customer when creating PaymentIntent ?
I'm not sure I understand your question. Once you have a customer with a payment method attached, you can create multiple PaymentIntent for the existing customer and payment method.
The code you shared at the beginning should work, that why I asked you to give me a request ID to see the issue.
$paymentIntents = $stripe->paymentIntents->create([
'amount' => $_REQUEST['amount']*100,
'currency' => $_REQUEST['currency'],
'payment_method_types' => ['card_present'],
'description' => 'Software development services',
'customer' => 'cus_LKt18Gbx03ynVq',
'payment_method' => 'pm_1KeEPwSFxQJUWTjSBr8jk9mQ',
]);
req_GfOxS7mrbJtWWY this is the request id.
So here the error is that the payment method you set in the request isn't attached to the customer. You need to:
- Step 1: attach the payment method to the customer
- Step 2: create a PaymentIntent for that customer and payment method