#remi.lapierre

1 messages · Page 1 of 1 (latest)

lusty pagodaBOT
loud robin
#

Hey there

#

Can you provide the request ID where you see this error?

merry totem
#

req_uhWThHcA2EGXab

#

Thank you so much!

#

its in test mode

loud robin
#

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

merry totem
#

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?

loud robin
#

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])

merry totem
#

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

loud robin
#

Yep so adjusting it to use the PaymentIntents API will be necessary in that case

merry totem
#

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?

loud robin
#

Why do you need to do that?

#

Also you still aren't passing the PaymentMethod ID there

#

Nor confirm

merry totem
#

Thats in the normal checkout

loud robin
#

So nothing is going to happen other than creating a PaymentIntent (no underlying charge attempt will be created)

merry totem
#

With all the confirmation sequence

loud robin
#

Oh sorry

#

That is you collecting card details the first time

merry totem
#

Im trying to save the card for future use

loud robin
#

Yep that looks good

#

But also

#

You don't need to use both payment_method_types and automatic_payment_methods

merry totem
#

Yes thats why im unset($data['payment_method_types']);

#

It wouldnt be sent

loud robin
#

Right I'm basically just saying why not just use automatic_payment_methods all the time?

merry totem
#

Because sometimes its a guest checkout :/

#

And im afraid to get errors lol

loud robin
#

Don't you want to allow guests to Checkout with any payment method type that is supported for their currency?

merry totem
#

Only credit cards for now

loud robin
#

Oh okay. Then why ever set automatic_payment_methods?

merry totem
#

So we will be able to bill their credit cards in a X days after

#

its for recurring payments for the sports sector

loud robin
#

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.

merry totem
#

Yes that will be for the next request i guess?

loud robin
#

Correct that would be for the recurring paymenet

merry totem
#

Can I do a paymentintent in one request to charge the customer

loud robin
#

Yep

merry totem
#

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?

loud robin
#

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)

merry totem
#

I need to create one before?

#

So i need 2 calls...

loud robin
#

No you would use the one that you previously collected when you confirmed client side

merry totem
#

Charge was easier hahaha

loud robin
#

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

#

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

merry totem
#

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 ?? '?' : '?',
],
];

loud robin
#

Yep

merry totem
#

I need to specify

#

'payment_method_types' => ['card'],

loud robin
#

Nope

#

That is optional

merry totem
#

Thanks so much!!!

loud robin
#

Sure thing!

merry totem
#

Last question, I should save the payment_method the same way i save my customer id?

north ginkgo
#

Hi there. Taking over for bismarck as they have to step out. Give me a moment to catch up on context

merry totem
#

Thanks so much!

north ginkgo
#

Hi sorry juggling some other threads. Can you elaborate on the question?

merry totem
#

Im trying to be able to recharge an already charged customer

#

For that I will need to save the customer_id and the Payment method correct?