#BidBird®

1 messages · Page 1 of 1 (latest)

cloud hollowBOT
still agate
pine belfry
#

that's strange:

"id": "pi_3McbAIKT8fxib8XB188HOMBm",  
"object": "payment_intent",
...
 "status": "requires_source",
#

could you have a look at that? it's saying I need a source, right?

still agate
#

You're probably on an older API version

#

Let me check

#

Yeah you're on a 2018 api version:


requires_source has been renamed to requires_payment_method
requires_source_action has been renamed to requires_action```
pine belfry
#

ahh,

#

ok, may I upgrade that?

still agate
#

But yeah you can upgrade api version

#

It will probably introduce breaking changes

#

Read that guide before doing so

pine belfry
#

ok, well it's all fallen apart. May as well upgrade!

still agate
#

Gotcha

#

Also recommend moving from sources to payment methods

pine belfry
still agate
#

Gotcha

pine belfry
#

alright, upgraded that in dashboard. and the new error is thus:

#

"status": "requires_payment_method",

still agate
#

Yep that sounds right

pine belfry
#

so, I've tried adding this in the StripePaymentGateway.php

$payment_method = \Stripe\PaymentMethod::retrieve('{{PAYMENT_METHOD_ID}}');$payment_method->attach(['customer' => '{{CUSTOMER_ID}}']);
#

however it's not retrieving a payment method. Doesn't this js method create one?

#
form.addEventListener('submit', function(event) {    event.preventDefault();    console.log(event);    stripe.confirmCardPayment(        {            payment_method: {card: cardElement}        }
#

Some of these charges will be first timers.

still agate
#

That method is just confirming a payment intent

#

however it's not retrieving a payment method
What's the error?

pine belfry
#

mmm. Ok. thats kind of odd isn't it? doesn't the element do that?

still agate
#

No

pine belfry
#

o

still agate
#

You have to specifically confirm the payment intent

#

That is what you're referring to right?

pine belfry
#

Well, not fully sure. So, when the form posts to the server a payment intent is created like so: (at least I'm trying to do that)

still agate
#

No you need to create a payment intent before the form is rendered

#

Follow the guide I linked above

pine belfry
#

yes

#

how could a payment intent be created before someone even enters their card info?

still agate
#

Because a payment intent is an intent to pay

#

Not a payment itself

#

Go through that guide

pine belfry
#

Ok, then I may need something else. The old stripe elements allowed this to ork

#

So see here, someone can select however many credits they want. then pay

#

are you saying I'd need to 2-step this form?

still agate
#

Guide I shared covers how to achieve that as well

#

That step

#

Basically you'd create payment intent up front

#

And then update the amount if the customer changes the num of credits

#

Alternative would be to do it in 2 steps if you'd rather though

pine belfry
#

on that step it says to create a payment intent with this code. So, If I understand this. It's saying when the page is initially rendered the PI should be created and available to the form?

$stripe->paymentIntents->create(
  [
    'amount' => 1099,
    'currency' => 'usd',
    'automatic_payment_methods' => ['enabled' => true],
  ]
);
still agate
#

Correct

pine belfry
#

I guess the trouble I'm seeing is that I don't know what the amount will be. As the customer can change the # of items they purchase.

still agate
#

I would create the PI with a quantity of 1

#

Because they have to purchase at least 1 right?

#

Then give them the option to change the amount

pine belfry
#

huh

still agate
#

So if 1 credit is $5, you can create a payment intent for $5

#

Then if they select a different amount, just update the PI

pine belfry
#

I see, ok. So here's how it currently is setup. The customer selects the number of items, when they hit submit this php method is called:

public function charge($amount){    
  
try {        $stripeIntent = \Stripe\PaymentIntent::create([            'setup_future_usage' => 'off_session',            'amount' => $amount,            'currency' => 'usd',        ], ['api_key' => $this->apiKey]);        

$payment_method = \Stripe\PaymentMethod::retrieve('{{PAYMENT_METHOD_ID}}');   

$payment_method->attach(['customer' => '{{CUSTOMER_ID}}']);        

return new PaymentIntent([            'setup_future_usage' => $stripeIntent['setup_future_usage'],            'amount' => $stripeIntent['amount'],            'id' => $stripeIntent['id'],            'payment_method' => $payment_method        ]);    } catch (InvalidRequestException $e) {        throw new PaymentFailedException;    }}
still agate
#

That doesn't quite make sense though

#

Why would the payment method not already be attached to the customer if it was previously created?

pine belfry
#

Yea, I can see that. just wanted to show where it was right now

#

Ok,

  1. take this intent put it on the jobs/create route.
  2. when the element is rendered, and submitted with customer quantities, retrieve the intent and update $amount?
still agate
#

You can update the amount on the fly (whenever the amount selector in your frontend changes)

#

Or you could wait until submit. Up to you I guess

#

Actually I think you'll need to do it on the fly so the element gets updated with the new amount

#

I have to head out but if you have further questions, you can ask my colleague @misty vector

pine belfry
#

thank you much ~

#

please keep this open for a bit, I'll work on this now

pine belfry
#

Ok making some progress here. I can now see the pi_..._secret_... however, the elements no longer fully mounts.

misty vector
pine belfry
#

here's what I mean.

#

see it mounts, but doesn't fully mount

#

isn't that strange?

misty vector
#

Hmm, can you share a link for me to replicate this? You can use ngrok, https://ngrok.com/ to achieve this. Are you seeing errors on your Dev Console?

pine belfry
#

yes, there are a few

#

cors related

misty vector
#

I think that is the issue, can you mount this outside of this frame? I see this screenshot is within a frame.