Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Stripe - How to create a PaymentMethod without attaching to an user?

Our user can enter a card to pay our services. He/she can choose to save or to NOT save card for reusing.

When user is NOT saving card, we are creating a PaymentIntent passing

        [
            'amount'         => floatval($this->cart->total_gross) * 100,
            'currency'       => 'EUR',
            'payment_method' => $this->pm,
            'off_session'    => true,
            'capture_method' => 'manual',
            'confirm'        => true,
        ];

This because it's a preauthorization of a payment that will be captured in 2-3 days.

Using this config we got the following error

Stripe\Exception\MissingParameterException - 400 - The provided PaymentMethod is already attached to another object. You cannot reuse PaymentMethods without attaching them to a Customer object first.

To be clear:

  • user enters a NEW CARD
  • choose to NOT save for future usage
  • stripe.js automatically handle the 3d secure card auth
  • the returned pm_... is sent to server with the amount and the instruction to NOT save card (so we do not create a stripe customer)
  • using the above config we call the \Stripe\PaymentIntent::create method
  • we got the error above

What is the meaning of this error? Why does it says that the PM is already attached to another object? Which? Of which kind?

I triple-checked my code and it's the ONLY api call we are making after receiving the pm from frontend.

And the frontend, previously, simply use a setupIntent to authorize the card using official stripe.js calls. So the pm, returned from stripe.js is sent to our server without doing nothing with it. And our server simply call the create method, and got this error every time.

Asking your help to diagnose and understand.

We're using latest official stripe-php versions

Thanks in advance

like image 616
realtebo Avatar asked Sep 24 '19 16:09

realtebo


1 Answers

I finally received an official response on this problem.

Simply: we cannot save a card for of_session payments and then use the payment method in a later moment to capture the pre-authorized amount

So, we modified our flow

User choose or save a card and we inform the user that we must save the card to be able to reuse to complete the payment flow.

like image 169
realtebo Avatar answered Nov 15 '22 07:11

realtebo