#dragonlord_api
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/1286386119436406879
๐ Have more to share? Add more details, code, screenshots, videos, etc. below.
Hello! Checkout will only provide saved Payment Methods as an option under certain circumstances. Generally the Payment Method must be a card or bank acount that was set up for future use properly. Try using Checkout in setup mode to save a test card, then create another Checkout Session for that Customer and see if it shows up.
I only need it for test mode purposes so the user does not need to input the test credit card numbers.
Do you mean use setup_intent_data.on_behalf_of
?
No, not exactly.
You can't prefill a test card the way you're trying to. You need to create and set up a Payment Method associated with a Customer before it will show up in Checkout as an option.
Can you tell me more, at a high level, about what you're trying to do?
So the idea is we want users to try the checkout flow withoug having to setup a stripe connect account yet.
So we want to use a static stripe account which prefills all the information for a payment, so the webhook gets called and we do not need to tell the user what to input for the test credit card.
So far I am creating the payment method for the customer with the code I put in the ticket what am I missing to create the customer with proper payment method for the test credit card information?
Yeah, that won't work, because you're directly attaching the Payment Method to the Customer, thus it's not set up properly.
so I have to create the payment method before?
Try creating a Checkout Session in setup mode for this Customer, then enter the 4242 card number manually, then after that Checkout Sessions created for that Customer in payment mode should present the saved card as an option as long as all of the other criteria are met.
so the issue i get is that I cant pass prices id if checout session is in setup mode
Mode cannot be setupwhen using prices.
Right, setup mode is only for setting up the Payment Method without taking a payment.
To calrify, going through setup mode is a one-time operation just to get it set up.
You should only need to do that once, then you can create many Checkout Sessions in payment mode for that Customer after that.
So their's no other way to do that unless i go through the process once in setup mode?
You can do it via the API by creating a Setup Intent with the correct parameters, but I recommend doing it through Checkout to make sure all of the criteria for reuse in Checkout are met.
I wanted to be able to create customers whenever with any email and the test credit card. So I am assuming I can't prefill the information with different emails
like I do not want the user to go through the form twice
Let's back up a bit. You said this is for test mode, to demo the Checkout flow?
yes in test mode to demo the checkout flow without having the user to input a credit card, and still trigger the webhook payment intent succeeded
But you don't want to reuse the same Customer for the demos, you always want it to be a new Customer every time?
Okay, but you want to use a different email address every time?
yes if possible because we would like the receipt to be received by the user
We don't send emails in test mode, so they're not going to get emailed receipts regardless.
Either the user's email on our website or the email they input on the screen before they click on checkout to go to the stripe page\
Okay, so when they provide the email, you need to 1) create a Customer 2) create a Setup Intent for that Customer and the pm_card_visa test Payment Method 3) confirm that Setup Intent with off_session set to true 4) create a Checkout Session for that Customer and 5) redirect them to the Checkout Session's url.
I am doing it like this
$customer = \Stripe\Customer::create([
'description' => 'Test Customer',
'email' => 'test_email@test.com',
'payment_method' => 'pm_card_visa', // Stripe test payment method ID
'invoice_settings' => [
'default_payment_method' => 'pm_card_visa',
],
], ['stripe_account' => $stripe_connect_id]);
$setupIntent = \Stripe\SetupIntent::create([
'payment_method' => 'pm_card_visa', // Stripe test payment method ID
'customer' => $customer->id,
'usage' => 'off_session',
'return_url' => 'localhost:8000'
'confirm' => true,
], ['stripe_account' => $stripe_connect_id]);
Do i setup the intent like this?
You need to remove payment_method and invoice_settings from the Customer creation call.
The Setup Intent needs to be used to attach the Payment Method to the Customer (this happens during confirmation), you shouldn't attach directly.
I am creating the session like
$checkout_session = \Stripe\Checkout\Session::create(
[
'line_items' => $line_items,
'locale'=> 'auto',
'mode' => 'payment',
'customer' => $customer->id,
'success_url' => 'test.com',
'cancel_url' => 'test.com',
'allow_promotion_codes' => true,
'payment_method_data' => ['allow_redisplay' => 'always'],
],
['stripe_account' => $stripe_connect_id]
);
But it still is not working
am i missing something
One sec, let me check something...
Oh, that's right, there's an extra step now that I forgot about. After the Setup Intent is successfully confirmed you need to update the Payment Method and set allow_redisplay to always: https://docs.stripe.com/api/payment_methods/update#update_payment_method-allow_redisplay
Note that you need to use the actual Payment Method ID that was generated, you can't use pm_card_visa at this point. The new Payment Method's ID will be on the Setup Intent object you get back in the confirmation call.
Yes I will try this one second and see if that works
I am updating the payment method like this
$test = \Stripe\PaymentMethod::update(
$setupIntent->payment_method,
['allow_redisplay' => 'always'],
['stripe_account' => $stripe_connect_id]
);
and it's still not working
That's happening before you create the Checkout Session, correct?
yes
And $setupIntent->payment_method contains the expected Payment Method ID at that point?
yes I am looking at my console and it exists
But on the stripe dashboard it does not have a default payment method
does that mean I am doing something wrong still
No, it doesn't need to be set as the default. Can you give me the Setup Intent ID so I can take a look?
seti_1Q0pPKR0IjjP2oRQ4OFq5qiI
Hi there ๐ jumping in as my teammate needs to step away soon. Checkout Sessions only prefill card details in very specific scenarios, and the exact requirements for that fluctuate with the mode of the Checkout Session that you're creating. It's a bit buried, but we talk about those scenarios here:
https://docs.stripe.com/payments/accept-a-payment?platform=web&ui=stripe-hosted#handling-existing-customers
Typically the thing that I see keep the cards from being displayed is that they don't have full billing details like address and email address.
So i just followed these steps made the customer have full billing details and the credit card info is still not prefilling
cus_QsalUnEid7x7W2
that is the customer id
The Payment Method needs full billing details
Can you check this id pm_1Q0pe2R0IjjP2oRQOsbJwTxD, I added full billing details but it still not working
That one I believe the problem is that allow_redisplay isn't set to always on the Payment Method, can you try updating that parameter?
https://docs.stripe.com/api/payment_methods/update#update_payment_method-allow_redisplay
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
$checkout_session = \Stripe\Checkout\Session::create(
[
'line_items' => $line_items,
'customer' = $customer->id;
'locale'=> 'auto',
'mode' => 'payment',
'customer_email' => $email_address,
'success_url' => 'asd'
'cancel_url' => 'asd',
'allow_promotion_codes' => true,
'payment_intent_data' => [
'application_fee_amount' => 100, // Assuming a fixed fee; adjust as necessary
'setup_future_usage' => 'off_session',
],
'payment_method_data' => ['allow_redisplay' => 'always'],
],
['stripe_account' => $stripe_connect_id]
);
This is how I am creating the the checkout session
I am setting setup_future_usage to off_session and allow_redisplay to always
This isn't regarding how you're creating the Checkout Session. Can you try updating the allow_redisplay field on the Payment Method that you provided in the ID for?
๐ฅณ glad to hear!
yea