#rangermillze_code

1 messages ยท Page 1 of 1 (latest)

teal juniperBOT
#

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

๐Ÿ“ Have more to share? Add more details, code, screenshots, videos, etc. below.

round shardBOT
#

Below are links to other discussions we've had with you in the past week in case you want to review that information. If your question is related to one of these previous discussions, please provide a comprehensive summary of the current state and what you need help with now. We help many users simultaneously, so a summary allows us to resolve your issue as soon as possible.

tough grove
#

Hi, let me help you with this.

#

Are you trying to use Stripe Payment Element? Or Stripe Embedded Checkout?

#

Are you following any docs?

balmy bramble
#

hi, im trying to use Embedded Checkout.

#

i'm not using any specific docs because the requirements I have are slightly different to the nrm

#

I basically only need to accept subscriptions

teal juniperBOT
tough grove
#

Both Stripe Checkout, and Elements support Subscriptions.

balmy bramble
#

Prior to calling the stripe.initEmbeddedCheckout I run some php code that checks if a customer email exists on stripe and returns the ID or creates the account on script and then returns the ID. Then i get the client secret by creating a session

#

$checkout_session = $stripe->checkout->sessions->create([
'ui_mode' => 'embedded',
'customer' => $st_userid,
'line_items' => [[
# Provide the exact Price ID (e.g. pr_1234) of the product you want to sell
'price' => 'price_1PgRWbHG3ehKFpGUTodhg81x',
'quantity' => 1,
]],
'mode' => 'subscription',
'redirect_on_completion' => 'never'
]);

#

maybe i should be using elements?

#

this seems to be the way that works at the moment in test

tough grove
balmy bramble
#

can i do the same with elements? because i wanted to originally use elements

spare parrot
#

๐Ÿ‘‹ taking over for my colleague. Let me catch up.

balmy bramble
#

do i create a session with elements?

#

or use the session i created to impliment the element?

#

so i just need:

#

$subscription = $stripe->subscriptions->create
([
'customer
' => $customer_id,
'items
' => [[
'price
' => $price_id,
]],
'payment_behavior
' => 'default_incomplete',
'payment_settings
' => ['save_default_payment_method
' => 'on_subscription'],
'expand
' => ['latest_invoice.payment_intent'],
]);

tough grove
#

Correct

balmy bramble
#

then i call the element?

tough grove
#

It's described in detail in the doc. You send the client_secret to the frontend and render the Elements

balmy bramble
#

I guess i pass 'subscriptionId' => $subscription->id,
'clientSecret' => $subscription->latest_invoice->payment_intent->client_secret, to the payment element?

#

okeys that makes more sense. thankyou!

tough grove
#

Please note, if the Subscription contains a trial, first Invoice is $0, and there's no PaymentIntent. You should use $subscription->pending_setup_intent->client_secret then.

#

This will allow you to save the PaymentMethod for subsequent Invoice payments

balmy bramble
#

awesome, thanks again!

spare parrot
#

๐Ÿ‘‹ taking over for my colleague. Let me know if there's any follow-up Qs I can answer!

balmy bramble
#

thanks very much, im just altering my code to see if i can get this working with payment elements instead of the embedded checkout

spare parrot
#

sure let me know if you need any more help