#dragonlord_api

1 messages ยท Page 1 of 1 (latest)

formal pewterBOT
#

๐Ÿ‘‹ 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.

mint laurel
#

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.

orchid pawn
#

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

#

?

mint laurel
#

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?

orchid pawn
#

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?

mint laurel
#

Yeah, that won't work, because you're directly attaching the Payment Method to the Customer, thus it's not set up properly.

orchid pawn
#

so I have to create the payment method before?

mint laurel
#

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.

orchid pawn
#

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.

mint laurel
#

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.

orchid pawn
#

So their's no other way to do that unless i go through the process once in setup mode?

mint laurel
#

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.

orchid pawn
#

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

mint laurel
#

Let's back up a bit. You said this is for test mode, to demo the Checkout flow?

orchid pawn
#

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

mint laurel
#

But you don't want to reuse the same Customer for the demos, you always want it to be a new Customer every time?

orchid pawn
#

No I do not care about using the same customer

#

just prefilling the credit card info

mint laurel
#

Okay, but you want to use a different email address every time?

orchid pawn
#

yes if possible because we would like the receipt to be received by the user

mint laurel
#

We don't send emails in test mode, so they're not going to get emailed receipts regardless.

orchid pawn
#

I am sending the emails ourselves

#

through out website

mint laurel
#

Ah, I see.

#

Where are you collecting the email address?

orchid pawn
#

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\

mint laurel
#

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.

orchid pawn
#

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?

mint laurel
#

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.

orchid pawn
#

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

mint laurel
#

One sec, let me check something...

#

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.

orchid pawn
#

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

mint laurel
#

That's happening before you create the Checkout Session, correct?

orchid pawn
#

yes

mint laurel
#

And $setupIntent->payment_method contains the expected Payment Method ID at that point?

formal pewterBOT
orchid pawn
#

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

mint laurel
#

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?

orchid pawn
#

seti_1Q0pPKR0IjjP2oRQ4OFq5qiI

leaden sleet
#

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.

orchid pawn
#

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

leaden sleet
#

The Payment Method needs full billing details

orchid pawn
#

Can you check this id pm_1Q0pe2R0IjjP2oRQOsbJwTxD, I added full billing details but it still not working

leaden sleet
orchid pawn
#

 $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

leaden sleet
#

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?

orchid pawn
#

perfect

#

that was it

leaden sleet
#

๐Ÿฅณ glad to hear!

orchid pawn
#

yea