#BidBird®
1 messages · Page 1 of 1 (latest)
Payment Intents use Payment Methods not Sources. See this doc which details the changes from the legacy objects to the newer, recommended ones: https://stripe.com/docs/payments/payment-intents/migration
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?
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```
You can still pass a source to payment_method though: https://stripe.com/docs/api/payment_intents/update#update_payment_intent-payment_method
But yeah you can upgrade api version
It will probably introduce breaking changes
Read that guide before doing so
This section specifically: https://stripe.com/docs/upgrades#how-can-i-upgrade-my-api
ok, well it's all fallen apart. May as well upgrade!
Gotcha
Also recommend moving from sources to payment methods
That link I sent earlier is fairly comprehensive: https://stripe.com/docs/payments/payment-intents/migration
yes, so I'm at the point of https://stripe.com/docs/payments/payment-intents/migration#saving-cards-checkout-step-2
Gotcha
alright, upgraded that in dashboard. and the new error is thus:
"status": "requires_payment_method",
Yep that sounds right
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.
That method is just confirming a payment intent
however it's not retrieving a payment method
What's the error?
mmm. Ok. thats kind of odd isn't it? doesn't the element do that?
No
o
You have to specifically confirm the payment intent
That is what you're referring to right?
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)
No you need to create a payment intent before the form is rendered
Follow the guide I linked above
yes
how could a payment intent be created before someone even enters their card info?
Because a payment intent is an intent to pay
Not a payment itself
Go through that guide
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?
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
Ok, I may need a little clarification here. https://stripe.com/docs/payments/accept-a-payment?platform=web&ui=elements#web-create-intent
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],
]
);
Correct
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.
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
huh
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
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; }}
That doesn't quite make sense though
Why would the payment method not already be attached to the customer if it was previously created?
Yea, I can see that. just wanted to show where it was right now
Ok,
- take this intent put it on the jobs/create route.
- when the element is rendered, and submitted with customer quantities, retrieve the intent and update $amount?
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
Ok making some progress here. I can now see the pi_..._secret_... however, the elements no longer fully mounts.
What do you mean by not fully mounting? Are you creating and mounting the Payment Element as shared on this guide, https://stripe.com/docs/payments/accept-a-payment?platform=web&ui=elements#add-the-payment-element-to-your-payment-page?
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?
I think that is the issue, can you mount this outside of this frame? I see this screenshot is within a frame.