#rangermillze_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/1267812592777297961
๐ Have more to share? Add more details, code, screenshots, videos, etc. below.
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.
- rangermillze_code, 1 hour ago, 19 messages
Hi, let me help you with this.
Are you trying to use Stripe Payment Element? Or Stripe Embedded Checkout?
Are you following any docs?
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
Both Stripe Checkout, and Elements support Subscriptions.
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
That's fine too. But Checkout is less customizable than Elements: https://docs.stripe.com/payments/accept-a-payment?platform=web&ui=embedded-form
can i do the same with elements? because i wanted to originally use elements
๐ taking over for my colleague. Let me catch up.
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'],
]);
Correct
then i call the element?
It's described in detail in the doc. You send the client_secret to the frontend and render the Elements
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!
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
awesome, thanks again!
๐ taking over for my colleague. Let me know if there's any follow-up Qs I can answer!
thanks very much, im just altering my code to see if i can get this working with payment elements instead of the embedded checkout
sure let me know if you need any more help