#jellybeer-_checkout-modes-prices

1 messages · Page 1 of 1 (latest)

maiden trenchBOT
#

👋 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/1364632969129496580

📝 Have more to share? Add more details, code, screenshots, videos, etc. below.

runic laurel
#

Hi 👋

I"m sorry but I do not understand how your question has to do with Stripe APIs. I don't know what "embed" means in this case

fiery gazelle
#

well okay, i made a payment page. on the left side of the page i got pdf that shows a invoice and on the right side i got the stripe payment. the stripe payment has ben embedded inside the page using 'ui_mode' => 'embedded',. now it worked fine when i only used one time payments. after that i wanted to add subscriptions together with the one time payments inside the embedded ui. that sadly doesnt work and only works without the embedded part.

this is my checkout.php without the subscription part:

https://pastebin.com/0FBEvkhN

this is my invoice.php (frontend that shows the checkout.php):

https://pastebin.com/EJzarwyf

now is there a way on how i can put one time payments and subscriptions on one payments session inside the embedded ui?

runic laurel
#

OH you mean the embedded Stripe Checkout?

fiery gazelle
#

yh sorry

runic laurel
#

What is the error you receive when attempting to create the Checkout Session?

fiery gazelle
#

okay so in the code i added this:

    $line_items = [];

    foreach ($_SESSION['data'] as $item) {
        $price_data = [
            'currency' => 'eur',
            'unit_amount' => $item['unit_amount'],
            'product_data' => [
                'name' => $item['product_name'],
            ],
        ];

        if ($item['recurring'] === 'month') {
            $price_data['recurring'] = ['interval' => 'month'];
        } elseif ($item['recurring'] === 'year') {
            $price_data['recurring'] = ['interval' => 'year'];
        }
        // Als 'once' of onbekend, dan géén recurring toevoegen

        $line_items[] = [
            'quantity' => $item['quantity'],
            'price_data' => $price_data,
            'tax_rates' => [$tax_rate->id],
        ];
    }

here is where it when wrong

the ID is: req_KulxeD167rtrO9

in the error its says this:

{
"error": {
"message": "You specified payment mode but passed a recurring price. Either switch to subscription mode or use only one-time prices.",
"param": "line_items[2]",
"request_log_url": "https://dashboard.stripe.com/test/logs/req_KulxeD167rtrO9?t=1745424922",
"type": "invalid_request_error"
}
}

but i cant player payment subsciption and one time payments inside one session

runic laurel
#

Okay great. The error message is correct. If you are mixing one-off and recurring prices you must use mode: "subscription" when creating the Checkout Session

fiery gazelle
#

you mean like this (line 3):

    foreach ($_SESSION['data'] as $item) {
        $price_data = [
            'mode' => 'subscription',
            'currency' => 'eur',
            'unit_amount' => $item['unit_amount'],
            'product_data' => [
                'name' => $item['product_name'],
            ],
        ];

        if ($item['recurring'] === 'month') {
            $price_data['recurring'] = ['interval' => 'month'];
        } elseif ($item['recurring'] === 'year') {
            $price_data['recurring'] = ['interval' => 'year'];
        }
        // Als 'once' of onbekend, dan géén recurring toevoegen

        $line_items[] = [
            'quantity' => $item['quantity'],
            'price_data' => $price_data,
            'tax_rates' => [$tax_rate->id],
        ];
    }
runic laurel
#

'mode' => 'subscription',, yes that is what I mean. Can you test that and share the request ID?

fiery gazelle
#

doesnt work..

req_yq0bhYAXZMjvNe

probaly because i got products with one time payments, monthly and yearly payments...

this is the json he gets his data from:

{
    "recurring": "month",
    "quantity": 1,
    "product_name": "Maandelijkse onderhoud",
    "unit_amount": "1999"
},
{
    "recurring": "once",
    "quantity": 1,
    "product_name": "Extra pagina (per stuk)",
    "unit_amount": "7500"
},
{
    "recurring": "year",
    "quantity": 1,
    "product_name": "Domeinnaam (per jaar)",
    "unit_amount": "999"
},
runic laurel
#

Oh wait sorry

#

The reason that request failed in you need to specify the mode as a top level parameter, NOT for each Line Item

#

If you look at that request, you will see you are still passing mode: "payment" in the top level parameter.

fiery gazelle
#

yas my bad i see the problem:

    $line_items = [];

    foreach ($_SESSION['data'] as $item) {
        $price_data = [
           ** 'mode' => 'subscription',**
            'currency' => 'eur',
            'unit_amount' => $item['unit_amount'],
            'product_data' => [
                'name' => $item['product_name'],
            ],
        ];

        if ($item['recurring'] === 'month') {
            $price_data['recurring'] = ['interval' => 'month'];
        } elseif ($item['recurring'] === 'year') {
            $price_data['recurring'] = ['interval' => 'year'];
        }
        // Als 'once' of onbekend, dan géén recurring toevoegen

        $line_items[] = [
            'quantity' => $item['quantity'],
            'price_data' => $price_data,
            'tax_rates' => [$tax_rate->id],
        ];
    }



    $checkout_session = \Stripe\Checkout\Session::create([
        'ui_mode' => 'embedded',
       ** 'mode' => 'payment',**
        'return_url' => 'https://betaling.web4ever.nl/return.php',
        'line_items' => $line_items,
    ]);

i put 2 modes haha. do i need to remove the first mode and change the mode payment to mode subscription?

runic laurel
#

Yes. So remove the mode in the $price_data array and set the top level mode to "subscription" and test that out

fiery gazelle
#

req_AI5TMbwOgxLYJV

rip this is the problem i was worried about

runic laurel
#

Okay yeah that is what I thought. Youn can't mix multiple billing intervals on the same Subscription.

fiery gazelle
#

is there a way i can still put mulitple billing intervals inside one checkout?

runic laurel
#

No

fiery gazelle
#

dammit

#

well i tried

#

then i will need to make 2 septrate checkouts

runic laurel
#

What you can do is save the customer's payment method as their default and create a second subscription using that saved payment method

#

Then the customer doesn't have to complete Checkout twice

fiery gazelle
#

is there a documentation for that?

runic laurel
fiery gazelle
#

i will try that thanks 🙂

runic laurel
#

Although you shouldn't need to change anything

#

If you use Checkout in subscription mode, Stripe automatically saves the payment method to charge it for subsequent payments.

#

So what I recommend is this:

  • Complete a checkout session in Test mode with mode "subscription"
  • Examine the Customer and Payment Method associated with that Checkout Session
fiery gazelle
#

alright

#

i will try