#cashiersprit_docs
1 messages ยท Page 1 of 1 (latest)
๐ Welcome to your new thread!
โฒ๏ธ We'll be here soon! We typically respond in a few minutes, but in some cases we might need a bit more time (e.g., server's busy, you've got a complex question, etc.).
โฑ๏ธ We close idle threads, which makes them read-only. Once a thread is closed it won't be reopened, but you can 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/1249732184596680907
๐ Have more to share? Add details, code, screenshots, videos, etc. below.
Hi there
Sounds like you want to collect a new payment method without taking payment at that moment and then set that payment method to be charged in the future for the Subscription, correct?
everything could happen. the card may be working initially, but later, the card may be expired or lost, so there are cases, customer need to update their payment method
that's our thinking ๐
Sure, but I'm just asking if you are updating while taking a payment or updating in between those times, or both?
beteen. since I saw the approcah how to use payment element to initial a subscpriton https://docs.stripe.com/payments/accept-a-payment-deferred?type=subscription , which is applicable to our existing system
my main concern is what if 1st payment successful, but 2nd payment failed, how customer could update payment method?
Yep so then you create a SetupIntent to collect the payment method. If you want the deferred-intent approach then you would follow: https://docs.stripe.com/payments/accept-a-payment-deferred?platform=web&type=setup
So you still use Payment Element to collect the payment method, just using a SetupIntent to confirm it
Then you can update the default_payment_method for the Subscription
I want to update existing subscription's payment method, not to create a new subscrpition.
Correct, using a SetupIntent you don't create a new Sub
You just collect a new payment method
oh, i c. I just let customer submit a new payment method, and then I can get the new payment method id, and I just update the payment_method_id to subscription's default_payment_method
am I right?
Yep
bingo. it should works. thanks very much for your advice!
can I ask 2nd question about best pratice?
Sure
in our work flow, payment element component is rendered at very first beginning, after render, customer can still change total price by updating quantity. but in https://docs.stripe.com/payments/accept-a-payment-deferred?platform=web&type=subscription#add-the-payment-element-to-your-checkout-page, in render payment element stage, it already request to bind total amount for subscription. at that time, we actually don't know actual amount
the actual amount will be settled when customer clidk submit button, so I just need to update subscription amount later?
No you should wait to create the Subscription until you know the actual amount
You can always update the amount client-side by using elements.update(): https://docs.stripe.com/js/elements_object/update
No you should wait to create the Subscription until you know the actual amount
I hope so. but it does not work with our current workflow. It will change all our workflow to know actual amount before rendering payment element, which is too hard
That's not when you create the Subscription
See the docs you linked above, you create your Payment Element first and then you only create the Subscription on submission when you call your backend
I cannot update subscription amount later by updating subscription api?
Not really -- the initial Invoice will already be cut
It will be a mess if you are updating
The whole point of the above flow is you shouldn't need to update
how mess will be? can I create a trial subscription? and then change to charged subscription?
Why are you creating your Subscription before you know the final amount?
There shouldn't be any reason to do that
To be clear, you can render Payment Element without creating a Subscription
interesting. I just followed your example, so
const options = {
mode: 'subscription',
amount: 1099,
currency: 'usd',
// Fully customizable with appearance API.
appearance: {/*...*/},
};
// Set up Stripe.js and Elements to use in checkout form
const elements = stripe.elements(options);
// Create and mount the Payment Element
const paymentElement = elements.create('payment');
paymentElement.mount('#payment-element');
so here mode and amount is optional? I can skip them? and then in
post '/create-subscription' do
content_type 'application/json'
data = JSON.parse(request.body.read)
customer_id = cookies[:customer]
price_id = data['priceId']
subscription = Stripe::Subscription.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', 'pending_setup_intent']
)
if subscription.pending_setup_intent != null
{ type: 'setup', clientSecret: subscription.pending_setup_intent.client_secret }.to_json
else
{ type: 'payment', clientSecret: subscription.latest_invoice.payment_intent.client_secret }.to_json
end
end
pass correct amount to create subscription, right?
Mode and amount is not optional, no. But you can update that client-side at any point using elements.update()
And then yes, you just pass the correct amount (the correct Price really) on your backend when you actually create the Subscription
haha, so
const options = {
mode: 'subscription',
amount: 1099,
currency: 'usd',
// Fully customizable with appearance API.
appearance: {/*...*/},
};
the amount does not matter at all, as long as I pass correct amount in
subscription = Stripe::Subscription.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', 'pending_setup_intent']
)
it will override payment element's amount?
Yes
But you do want to use the correct amount client-side so that the correct payment method types are shown as options
Also if your customer uses something like a wallet (Google Pay / Apple Pay) then the client-side amount will show up in the UI
https://docs.stripe.com/js/elements_object/update_payment_element I did not find how to update amount
I linked above.... https://docs.stripe.com/js/elements_object/update
You update the Elements object, not the Payment Element
is it the right place?
i c , i c. perfectly, perfectly. that's everything I want. thank you so much!
Sure thing