#MYoussef-paymentmethod
1 messages · Page 1 of 1 (latest)
Hi! So you have a customer object with a PaymentMethod set, and you would like to know how to use that PaymentMethod for a payment?
yes, for one time payment items like shop items
You have two main options:
- Create a PaymentIntent and pass the existing PaymentMethod https://stripe.com/docs/api/payment_intents/create#create_payment_intent-payment_method
- Or create an invoice item for that customer, and it will automatically be added to the next subscription invoice https://stripe.com/docs/api/invoiceitems/create
if i created a payment intent and passing the customer payment method id
should i set confirm to true to collect the payment immediately
https://stripe.com/docs/api/payment_intents/create#create_payment_intent-confirm
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
and at this time i should check the status of the response to make sure it is paid ?
how to pass LineItemOptions, i want to pass the price ids of the items if i used create payment intent option ?
PaymentIntents don't use line items or Prices
they just take the raw amount and currency, so you have to pass those in directly.
I mean if you want to charge the customer $150, you pass amount:15000 and currency:usd on the API request to create the PaymentIntent.
the only parts of our API that take Prices and line items are Checkout, and Invoices/Subscriptions. Raw PaymentIntents are more primitive.
Can I ask why you're not using Checkout here? Also is this a payment while the customer is still on your site, or did you set up their payment method in the past and are charging them now? can you explain the overall use case in more detail?
the customer should pay while he is still on my site, my case is i provide repair services for devices with discount level based on the number of repair services that the customer buy
for example if he bought repair service for 2 iphone 7 devices then he will take 5% discount and if he bought for 3 devices then he will take 10% discount and so on
but each device(subscription) should be a separate subscription to enable the customer to remove it at any time or cancel the auto-renewal for one device and keep the other one
i contacted the support and they told me you cannot create checkout session for 2 devices with the same price/plan id
and they recommend to use setup mode and then create subscription with the payment method id from setup mode and check the status (which should be active) to make sure that the subscription is paid
but i have shop items also which is one time payment like accessories
and the customer can buy a subscription and 1 or 2 accessories from the shop
for subscriptions i handled it as i mentioned based on stripe support recommendation
but for shop items, what should i do? "for that i think create payment intent with confirm true will solve my case"
please advice
ok! So yes, you can't use Checkout to create two Subscriptions at the same time.
You can use it to create a Subscription and charge for multiple one-time items at the same time.
Do you really need the multiple separate subscriptions? you say you do, which is fair enough, but if you drop that requirement then things are a lot easier.
unfortunately, the owners need that because they want to deal with each device as a separate subscription
otherwise your only option is :
- use Checkout in setup mode to collect the payment details
- handle the webhook for the successful set up and :
- write code to look at the Prices/details of the subscriptions you want to create and the one-time items
- add up the amounts of all those so you can figure out how much you want to charge the customer today
- create a PaymentIntent for that amount
- when that succeeds, create the multiple subscriptions(using trial periods to skip the first payment).
It's complex but can be done.
alternatively, make it so either the customer can't create mutliple subscriptions, or if they do, they have to go through separate checkout flows each time, so you can use Checkout for them. I'd highly recommend trying to do that and not doing the steps I mentioned above, which is really just a hack.
"when that succeeds, create the multiple subscriptions(using trial periods to skip the first payment)", i did that in another way, i created subscription and pass the payment method id then i checked the status, if it is active then the subscription is paid and i activated it in my site and i use webhooks only for checking the renewal at the end of the year
is it works for subscription part ?
that could work!
you should carefully check you are not accidentally charging the customer twice in that flow just to be sure but it could work.
your are right and i see it becomes complex and i will try with the owners to disable this part to make it easier but if they insist
how to use " checkout flows each time " ? is it mean that i can make many checkout sessions and enable the customer to pay at the same time "for example like form wizard"?
I mean you'd create and redirect to one CheckoutSession for starting up one subscription(and optionally some one-time line items as well), and can separately create and redirect to a different CheckoutSession for starting a different subscription
i got you
is there any way to simulate the subscription renewal date is coming? i read before about something like that
can you share it with me ?
if you can get access to the beta mentioned there it does this, alternatively you have to update an existing subscription to have trial_end set to a few minutes in the future to test, when the trial ends, it will generate a recurring invoice payment.
thanks a lot, i appreciate your awesome help