#geo_api
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/1313626704383709275
š Have more to share? Add more details, code, screenshots, videos, etc. below.
Hi there
Hi!
Hm, this sounds like the opposite order of things
Typically, you'll create a Customer, then create a Subscription for that Customer. You'll use the PaymentIntent on the latest Invoice to collect payment details. Confirming the PaymentIntent will automatically attach the PaymentMethod to the Customer
What does this PaymentIntent represent exactly? https://dashboard.stripe.com/test/logs/req_bZRJ5zmw2XXfpo
Is this intended to be the first payment on a Subscription or a totally unrelated payment?
the first payment, as in they just purchased the subscription
I can create a loom video if you'd like
No need
If this should be the first payment on their Subscription, you shouldn't create the PaymentIntent yourself
Instead, you should create a Subscription then use the latest_invoice.payment_intent.client_secret to collect payment details
hmm that kinda goes against our current flow, we essentially list them as a price our system, when the use checks out we listen for the payment_intent.succeeded and then we were thinking of actually creating the subscription after
we were hoping to reuse the same flow we use for other products we sell on site
we use this flow for the other products we offer, in this case it would be a "the customer just purchased this subscription"
Hm
It's still the wrong pattern to process a payment independent of the Subscription if your goal is to have that payment be the charge for the first billing period
Taking a step back, is your real goal to be able to collect payment details and then determine whether to use those payment details for a PaymentIntent (for a one-off payment) or a Subscription (for a recurring payment)?
We do payment intents as our main product is selling tickets, which we sort of need to cancel if needed. In this case, I wanted to use the payment_intent.succeeded as the customer purchased the subscription so now since the payment is successful I should create the actual subscription product in stripe
not sure if I'm making sense?
I can totally make that loom if that helps
Also on payment_intent.succeeded I have the customer's information and on the payload I get the the payment method
so a payload would look like this
{
"invoice_settings": {
"default_payment_method": "pm_1QS3oIDY3BzcP9iqyEikWJNj"
},
"address": {
"line1": "",
"state": "",
"postal_code": "",
"city": "",
"line2": ""
},
"email": "geo+20241203@onthestage.com",
"payment_method": "pm_1QS3oIDY3BzcP9iqyEikWJNj",
"phone": "",
"name": "testwith newemail"
}
but this is where I'm running into issues
So you can still use payment_intent.succeeded if you create the Subscription first. We'll still emit that event type
Let's say you don't run into that error and you're able to create a customer and then a Subscription. When you create the Subscription, we'll immediately create a non-zero Invoice and attempt to pay it automatically for the first billing period, which will ultimately double charge your customers
If the $156.30 amount is intended to be the first charge for this annual Subscription, you should create the Customer and Subscription first, and then use the PaymentIntent that's automatically created for the first invoice to collect payment
If you want to integrate directly with PaymentIntents and manage subscription cycles on your end (i.e., create a PaymentIntent every year on your own/directly vs having Stripe auto charge), you don't have to create Subscriptions at all. What you should do instead is create a Customer, then create the PaymentIntent with setup_future_usage: 'off_session
Could this behavior not be altered with a setting in the payload?
Kind of but it's more a hacky way of doing this
You could introduce a trial period on the first Subscription so the first invoice will be a zero-amount invoice
Note that this might mess with any revenue recognition reports you have
I see, so I need to create the customer first, then the subscription then listen to payment_intent.succeeded for any post purchase action I need to do in my system?
and definitely can't use my current flow of payment intent charged seperatly and then create the customer and subscription
Correct. If you use your current flow, you would end up either double charging customers (when you create the Subscription) or would have to add a trial period to the Subscription
You can listen for payment_intent.succeeded but there are a few others, too, if you want details about the parent Invoice and/or Subscription: https://docs.stripe.com/billing/subscriptions/overview#subscription-events
would that non-zero Invoice be created as soon as the payment intent succeeds or does it take some time to generate?
Give me a few minutes to pull this up on my end
Ah, you wouldn't see the double charges since none of your calls to create Subscriptions have succeeded
actually, I see one
I've also created some subscription using my flow and the payments seem right to me as in there is a payed invoice and the next invoice seems right sub_1QS2tDDY3BzcP9iqAObNHtGP
That's the one I'm looking at: https://dashboard.stripe.com/test/logs/req_ezUlzemyHt7VRM
yep
It looks like there was an immediate payment of 163.80 and the next invoice is scheduled for Dec 3, 2025 which makes sense since this is supposed to be a 1-year recurring subscription
The PaymentMethod used for this Customer was added via the Dashboard though
so I don't think it was tested in the same way
yep but other than that I've purchased it via my current flow which is why the only missing piece was creating the customer and attaching the payment method but that error is preventing me from doing so
I had to add the payment method via the dashboard to work around the error
Right, understood. Integrating with PaymentIntents directly when you intend to use Subscriptions is the wrong flow to use though
Flow aside, what could be the root cause of the original error?This PaymentMethod was previously used without being attached to a Customer or was detached from a Customer, and may not be used again.'
Hello! I'm taking over and catching up...
Hi! Thank you!
To clarify, you're asking where the This PaymentMethod was previously used without being attached to a Customer or was detached from a Customer, and may not be used again. error comes from?
No, more like what is the root cause. What elements from this payload is triggering the error
https://dashboard.stripe.com/test/logs/req_NgMmoUuR0wlfO9?t=1733262550
Ah, the cause for that error in that request is that you're trying to attach a Payment Method to that Customer, but that Payment Method has already been consumed and can't be used again for anything.
Payment Methods are, by default, single-use only. That single use can be for a payment, or that single use can be to set it up for future use and save it to a Customer which enables it to be reused.
In this particular case you already used this Payment Method for a payment, so that used it up, and it can never be used again for anything else.
I see, could I use something from payment_intent.succeeded to attach to customer as their payment method or would I have to create the user while the payment method is still "active"?
If your use case is Subscriptions you wouldn't typically don't interact directly with the Payment Intent at all. The Subscription will create an Invoice, and the Invoice will create a Payment Intent, and that Payment Intent will have setup_future_usage and a customer set, so when the payment succeeds the Payment Intent will also set it up for future use and attach it to the Customer for future use for you.
I really want to stress that you are going about this from the wrong end. Payment Intents are low-level payment objects, and are the foundation higher-level objects like Subscirptions and Invoices are built on.
You need to think mostly in terms of Subscriptions and Invoices rather than Payment Intents, unless you're doing something unusual.
I recommend you read through our docs about how Subscriptions work to get an idea of how all the pieces fit together: https://docs.stripe.com/billing/subscriptions/overview
I understand but unfortunatly that is the way we have this set up so I need to find a way to make it work with what I have š¦
What do you mean? You can't change it?
Give me a sec let me make a loom with our current flow, maybe that would help?
Sure.
hope this makes sense
Yeah, this won't work by creating a Payment Intent like you're doing now. Instead of creating a Payment Intent in that flow you need to create a Subscription Instead. You can't create a Payment Intent first and then create a Subscription after that like you describe in the video. This is the guide you want to follow: https://docs.stripe.com/billing/subscriptions/build-subscriptions?platform=web&ui=elements
I see, I will follow that. Thank you!