#gmgarrison_code
1 messages ยท Page 1 of 1 (latest)
๐ Welcome to your new thread!
โฒ๏ธ We'll be here soon! Typically we respond in a few minutes, but sometimes we might take a bit longer if the server is busy or if you have a particularly tricky question.
โฑ๏ธ We close idle threads, which makes them read-only. Once a thread is closed it won't be reopened, but you can always start a new thread if you have another question.
๐ This thread will always be available, even after it's closed. You can find it again using Discord's search, or you can save this link: https://discord.com/channels/841573134531821608/1298631319932371017
๐ Have more to share? Add more details, code, screenshots, videos, etc. below.
hi there!
Hello soma ๐
so you want to save a card so you can charge it later?
Yeah, I want customers to be able to add cards or bank accounts for later payments
then the first link you shared is correct: https://docs.stripe.com/payments/save-and-reuse?lang=php
What's the difference between that and the second link?
the second link is to charge the card right away, and without saving it. so it's quite different.
The opposite! Ha
Alright, I'll do some coding from the first link. Thanks for the quick help.
happy to help ๐
I'm not following step #2 - Create a Checkout Session. I don't see how to get the Elements UI loaded on the front-end. The first code section doesn't have any Stripe-specific code at and the second is the backend code to create a session, but then how is that session delivered to the front-end?
If you're using PaymentElement then you should switch tabs to "custom payment flow" guide
https://docs.stripe.com/payments/save-and-reuse?platform=web&ui=elements
All good!
Okay, now we're making some progress. ๐ I've got the Elements form showing up on my Manage Payment Methods page which is what I want, but it only shows a credit card entry form.
The Stripe account has bank accounts, Apple Pay, and Google Pay also enabled. Do I need to specifically enable them when creating the Elements form?
You would need to run the site under HTTPS and register the domain for the wallets to show - https://docs.stripe.com/payments/save-and-reuse?platform=web&ui=elements#apple-pay-and-google-pay
Also, if you're manually setting payment methods when you create a SetupIntent then you'd likely want to switch to automatic payment methods - https://docs.stripe.com/payments/save-and-reuse?platform=web&ui=elements#create-intent
I understand about the Apply Pay and Google Pay - but I don't have to register a domain for bank accounts, do I? Shoudn't that still appear in my dev environment?
It should, can you share the example SetupIntent ID you're working with?
I can if you tell me where to find it ๐
seti_1QD4NXH1Z1K59F9KPaXW1vak
Hmm the request that created the SetupIntent was made to /v1/checkout/sessions - which isn't the API endpoint you should be using for custom flow
This is my front-end page:
<x-app-layout>
@section('title', 'Manage Payment Methods')
<h3 class="text-white">Manage Your Payment Methods</h3>
<div class=" mt-4 text-white">
<div class="row">
<p>Your Current Payment Methods</p>
</div>
<div class="row contentWidth">
<ul id="payment-methods-list" class="list-group">
@foreach($paymentMethods as $method)
<li class="list-group-item d-flex justify-content-between align-items-center">
{{ ucfirst($method->bank) }} ****{{ $method->last_4 }}
<button class="btn btn-danger btn-sm ms-2" onclick="removePaymentMethod('{{ $method->id }}')">Remove</button>
</li>
@endforeach
</ul>
</div>
<div class="row">
<p class="mt-5">Add a New Payment Method</p>
</div>
</div>
<script nonce="{{ csp_nonce() }}" src="https://js.stripe.com/v3/"></script>
<script nonce="{{ csp_nonce() }}">
const stripe = Stripe('');
</script>
<form class="bg-white p-3 rounded contentWidth" id="payment-form">
<div id="payment-element"></div>
<button id="submit">Submit</button>
<div id="error-message"></div>
</form>
<script nonce="{{ csp_nonce() }}">
const options = {
mode: 'setup',
currency: 'usd',
setupFutureUsage: 'off_session',
appearance: {/*...*/},
};
// Set up Stripe.js and Elements to use in checkout form
const elements = stripe.elements(options);
// Create and mount the Payment Element
const paymentElement = elements.create('payment');
paymentElement.mount('#payment-element');
</script>
</x-app-layout>
(with my API key removed)
Oh you're using defer intent flow - https://docs.stripe.com/payments/accept-a-payment-deferred?platform=web&type=setup
That's different from the guides I've shared above..
Everytime I think I understand what's going on, I realize I don't
I don't know how to explain what I need... I'm not trying to collect a payment or create an intent. I want to create a new payment method that can be used later.
In our payment workflow right now, we offer a dropdown of payment methods the customer can choose to use. I'm trying to build the UI to add a method to that dropdown.
Right.. There are two flows you can use to do that..
The one you're currently using allows you to render PaymentElement without creating a SetupIntent first - https://docs.stripe.com/payments/accept-a-payment-deferred?platform=web&type=setup
The other one is where you create the SetupIntent prior to rendering the PaymentElement and configure elements to use the SetupIntent - https://docs.stripe.com/payments/save-and-reuse?platform=web&ui=elements
The difference between the both is quite subtle.
The defer intent flow looks directly at your payment method settings on your account to load supported payment methods..
The other flow will look at the SetupIntent that has been created to load supported payment methods.
I don't think I understand what the role of the SetupIntent is. What does it represent?
Like PaymentIntent is an object that represent the attempt to Pay, SetupIntent is an object that represent the attempt to save the payment method for future use.
So in the first flow, if I render the PaymentElement with no existing SetupIntent, is one created for me if the form is submitted successfully?
I guess I don't have any experience dealing with SetupIntents directly. In one of our payment flows, you're a new customer and all I do is create a PaymentIntent then show you the PaymentElement to capture payment.
In our other flow, I've already collected all your PaymentMethods and stored their IDs and then let you select one and then I again just create a PaymentIntent to be processed for payments.
I don't know what to do with SetupIntents
In our other flow, I've already collected all your PaymentMethods and stored their IDs
How exactly are you saving the PaymentMethods?
But it sounds like I should use the second flow you described above to create the SetupIntent and then show the PaymentElement to complete it
I have a script that uses the Stripe API to iterate over customers and get PaymentMethods and then they're saved in the application database
I save the ID, fingerprint, type, last_4 and bank
(It used to be the case that I just rendered the PaymentElement every time for every payment. I finally figured out that I could save the PaymentMethods and save my customers from re-entering methods they've used before.)
I have a script that uses the Stripe API to iterate over customers and get PaymentMethods
Stripe does not store payment methods of customers by default
Are you setting setup_future_usage when you create the PaymentIntent?
Yes
I see.
Yeah that wasn't clear from the thread prior. All good though..
So yeah you can use either of the flows I mentioned above to save payment methods and reuse them without charging them. To be clear, both flows use SetupIntents to save the payment method. The only difference is "when" do you create the SetupIntent.
Based on your current flow with PaymentIntent, yeah you should use the second flow.. So this guide - https://docs.stripe.com/payments/save-and-reuse?platform=web&ui=elements
It's starting to make sense - thank you
Then after the Elements form is submitted, can I listen for setup_intent.succeeded to look at the payment method ID and add it to my application database?
Correct