#remi.lapierre
1 messages · Page 1 of 1 (latest)
Thanks looking
So that customer has a PaymentMethod attached but with PaymentMethods we don't use defaults for one-off charges. You should be creating a PaymentIntent here (https://stripe.com/docs/api/payment_intents/create) and passing the PaymentMethod to the payment_method param as well as confirm: true
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
I cannot do a
$data = [
'customer' => $stripe_customer_id,
'amount' => $amount,
'currency' => $this->currency,
'application_fee_amount' => $this->calculateFeeInCents($amount),
'metadata' => [
'organization_id' => $this->organization_id,
'organization_name' => isset($this->organization) ? $this->organization->name ?? '?' : '?',
]
];
$this->prepareStripe();
$charge = \Stripe\Charge::create($data, [
'stripe_account' => $this->stripe_id,
]);
After?
No, you are combining our legacy API (the Charges API) with our newer PaymentMethods API
The PaymentMethods API is not compatible directly with the Charges API
You need to use the PaymentMethods API with the PaymentIntents API
Or use Tokens with Charges
You created that PaymentMethod via confirming a PaymentIntent.
So looks like you are already working with the PaymentIntents API
Why are you trying to also use the Charges API?
You can accomplish exactly what you are trying to do above by passing that same data (plus adding payment_method and confirm params) to $stripe->paymentIntents->create([data])
I see - i am trying to create a cron job to do monthly payments
I took some old code that i wrote couple of years ago
Yep so adjusting it to use the PaymentIntents API will be necessary in that case
Amazing...
$data = [
'payment_method_types' => ['card'],
'amount' => $amount,
'currency' => $this->currency,
'application_fee_amount' => $this->calculateFeeInCents($amount),
'metadata' => [
'organization_id' => $this->organization_id,
'organization_name' => isset($this->organization) ? $this->organization->name ?? '?' : '?',
],
];
if (isset($stripe_customer_id)){
unset($data['payment_method_types']);
$data = array_merge($data, [
'customer' => $stripe_customer_id,
'setup_future_usage' => 'off_session',
'automatic_payment_methods' => [
'enabled' => 'true',
],
]);
}
$this->prepareStripe();
$paymentIntent = \Stripe\PaymentIntent::create($data, [
'stripe_account' => $this->stripe_id,
]);
Im doing a unset($data['payment_method_types']);
When i have the cutomer_id
This shouldnt break anything correct?
Why do you need to do that?
Also you still aren't passing the PaymentMethod ID there
Nor confirm
Thats in the normal checkout
So nothing is going to happen other than creating a PaymentIntent (no underlying charge attempt will be created)
With all the confirmation sequence
Im trying to save the card for future use
Yep that looks good
But also
You don't need to use both payment_method_types and automatic_payment_methods
Right I'm basically just saying why not just use automatic_payment_methods all the time?
Don't you want to allow guests to Checkout with any payment method type that is supported for their currency?
Only credit cards for now
Oh okay. Then why ever set automatic_payment_methods?
So we will be able to bill their credit cards in a X days after
its for recurring payments for the sports sector
That isn't what that does really
You don't have to worry about payment_method_types or automatic_payment_methods at all if you already have payment method details.
You just pass the PM ID to the payment_method param in that case
payment_method_types and automatic_payment_methods is to help determine which types of payment methods you support collecting.
Yes that will be for the next request i guess?
Correct that would be for the recurring paymenet
Can I do a paymentintent in one request to charge the customer
Yep
the Equivilent of Stripe Charge
$data = [
'customer' => $stripe_customer_id,
'payment_method_types' => ['card'],
'amount' => $amount,
'confirm' => true,
'currency' => $this->currency,
'application_fee_amount' => $this->calculateFeeInCents($amount),
'metadata' => [
'organization_id' => $this->organization_id,
'organization_name' => isset($this->organization) ? $this->organization->name ?? '?' : '?',
],
];
'confirm' => true,
Thats the one?
Yeah you need the payment_method param to pass the PM ID
Correct
confirm => true triggers a charge attempt
But you must specify the PaymentMethod ID to charge as well (the pm_xxxxx)
No you would use the one that you previously collected when you confirmed client side
Charge was easier hahaha
And when you used setup_future_usage
The Charges API involved less parameters, yes, but it also could not support things like 3DS which you now will have support for here.
So looking back at your original example, that customer has pm_1LnnCVLGvUgYkFidOkkyoqDf attached
That PaymentMethod was attached due to this request: https://dashboard.stripe.com/test/logs/req_nttI7KgCXcSU8t
Which was your client-side confirmation using Stripe JS and Card Element
So now you want to pass that PaymentMethod ID when you are creating your recurring charges
I see
So now this will work:
$data = [
'customer' => $stripe_customer_id,
'payment_method_types' => ['card'],
'payment_method' => $payment_method,
'amount' => $amount,
'confirm' => true,
'currency' => $this->currency,
'application_fee_amount' => $this->calculateFeeInCents($amount),
'metadata' => [
'organization_id' => $this->organization_id,
'organization_name' => isset($this->organization) ? $this->organization->name ?? '?' : '?',
],
];
Yep
Sure thing!
Last question, I should save the payment_method the same way i save my customer id?
Hi there. Taking over for bismarck as they have to step out. Give me a moment to catch up on context
Thanks so much!
Hi sorry juggling some other threads. Can you elaborate on the question?