#BidBird®

1 messages · Page 1 of 1 (latest)

distant jasperBOT
trim wagon
#

Do you already have a payment method saved?

#

Or are you just trying to create a PI that only takes card payments?

crisp wind
#

Well, in this case I continue to receive this error "status": "requires_payment_method",

#

No payment method is saved.

I thought that PaymentIntent automatically set the payment method. However, I am using stripeElements new API

#

I suppose, for this form using card only is ok.

#

That bit of code above is used when the payment page is requested. It creates the PI, and then makes it available to the form, which is later updated.

trim wagon
#

I think we may need to take a step back here. Can you tell me more about what this page is trying to do?

crisp wind
#

sure. So we have this form:

trim wagon
#

Are you making a page that can either pay with new card details or use saved payment method details?

crisp wind
#

it's possible there are saved details, but I think just to get this going lets focus on new card details only.

I'm migrating from the 2018 api stripe elements

#

When the page renders I can see the $stripeIntent variable has this data:

"payment_method_options": { "card": { "installments": null, "mandate_options": null, "network": null, "request_three_d_secure": "automatic" } }, "payment_method_types": [ "card" ],

So, that's why it's confusing the "id": "pi_3MeL5ZKT8fxib8XB0IUEKtis", gives this error "status": "requires_payment_method",

trim wagon
#

It is expected unless you pass it the ID of an already saved payment method when creating the intent

crisp wind
#

ahh, so don't be concerned?

trim wagon
#

Are you able to confirm the intent with your page? Or is it giving you some other error?

crisp wind
#

confirm the intent?

trim wagon
#

Correct, payment_method_types is what defines what kinds of payment methods can be used. requires_payment_method is referring to an actual payment method object to charge via the payment intent

#

Confirm is our verb for "attempt to charge"

crisp wind
#

ahh, yes, for instance the PI are created on Stripe dashboard. but they are all incomplete

trim wagon
#

Yeah, that is also just the default state. A lot of integrations will have many Incomplete payments unless they make sure to clean up unused ones after some time

#

Or rather that is how the default state will show up in the dashboard

crisp wind
#

ahh, we need a garbage collector!

#

After submitting the form,

$payment_method =
\Stripe\PaymentMethod::retrieve($stripeIntent);

$payment_method->attach(['customer' => $stripeIntent]);

Where are the payment methods stored? Isn't this a session based object?

I'm trying to submit the $stripeIntent with the form, so that these methods used. Is that correct?

twilit ice
#

👋 stepping in

#

Catching up

crisp wind
#

cool!

twilit ice
#

So you are trying to attach a PaymentMethod after confirming a PaymentIntent?

#

Is there a reason you aren't just passing a Customer ID to the PaymentIntent?

#

Then it will be attached automatically on confirm

#

And no separate request necessary

crisp wind
#

ok, well, I'm not sure of the simplest way to make a charge

#

So I'd like to just have a customer choose the number of credits and charge them. Where would you create the customer in that simple flow?

#

maybe create a customer prior to the payment intent?

twilit ice
#

Yep

crisp wind
#

a lot of the docs have great stuff, but we need numerous pages and sometimes i get confused as to what's really needed... So if I should ditch the attach->customer code, that's fine

twilit ice
#

Yeah I would create the Customer just before the PaymentIntent

crisp wind
#

ok, let me give that a go.

twilit ice
#

Yep

crisp wind
#

My question then is should I be saving this on our db?

twilit ice
#

That's totally up to you

#

Most likely yes.

crisp wind
#

ha

twilit ice
#

But that depends on your flow

#

How are you handling authentication?

#

Like you are going to need to know when that user logs in in the future right?

#

So you need that Customer ID in your Database for that at the very least

#

Or some association that you can rely on

crisp wind
#

We have an email based login.

ok, I have a table, looks like it was for stripe_ach_customers Is there a need for it to be ach? for example the table has our unique user_id and the stripeId

#

I may change the name, if the stripeId is all we need for many payment types

twilit ice
#

Yep no need for ach

crisp wind
#

ok, I'll ditch that

twilit ice
#

I'd assume that is in reference to the fact that you were only taking ach payments in the past?

#

Dunno

crisp wind
#

well, I'm upgrading from the 2018 elements. That didn't need a customer_id for stripe elements. But ach did. However it seems like it changed. with the new api

#

ok I'll try and wire this up real quick. please keep this open. thank you ~

twilit ice
#

Sure let me know

crisp wind
#

so, ok, got the db renamed. I'm wondering is this enough info on the stripeCustomer?

if (! auth()->user()->stripeCustomer()) {             $stripeCustomer = \Stripe\Customer::create();  

  \App\Models\StripeCustomer::create([        
'user_id' => auth()->user()->id,        
'stripeId' => $stripeCustomer    
]);
}

$stripeIntent = \Stripe\PaymentIntent::create([    'setup_future_usage' => 'off_session',    
'amount' => 500,    
'currency' => 'usd',    
'customer' => $stripeCustomer,], 
['api_key' => $this->apiKey]);
#

Meaning, should I store more info on the customer at our db?

twilit ice
#

As long as you can retrieve the Customer based on your UUID then you are good in terms of making future payments for that Customer

#

Up to you if you want to record more info like their attached PaymentMethod or if you just want to retrieve that stuff at time of future payment

crisp wind
#

so, when the customer is created will stripe save that automatically at stripes servers with this line: $stripeCustomer = \Stripe\Customer::create();

#

or is that only saved by stripe with the paymentIntent

twilit ice
#

Yep that automatically creates the Customer regardless of the PaymentIntent

crisp wind
#

ahh, ok

twilit ice
#

The PaymentMethod will only be attached to the Customer if the PaymnetIntent is successfully confirmed.

crisp wind
#

interesting. What info would you recommend to save on our end? Or if we have the stripeId will that automatically pull up the customer info?