#shrey
1 messages · Page 1 of 1 (latest)
Can I check if a customer_id has paid for a specific price_id?
how are you planning on integrating with Stripe?
are you thinking about using Checkout?
Yes
in that case it would be better to use Payment Links
and create a Payment Link per product
And after every successful payment, update the user in my DB with the plan they paid for?
yes that's one way
Not possible?
Basically, I have two membership plans, and I let the customer choose any one. They're just one time payments, not subscriptions.
So how do I know which plan a customer is in?
By saving their customer_id?
Or do I save their plan in my DB, after checkout?
there's multiple ways, on the Stripe side you can add metadata to the relevant API objects that your systems can then look at when you retrieve them from the API (https://stripe.com/docs/api/metadata) . That's probably the best way.
Can I check if a customer_id has paid for a specific price_id
not in any like one-off native way no, you can list all payments for a given customer and check if any of them correspond to the Price ,or use metadata on the Customer object as mentioned above
the other way is that you store this in your database, i.e. when you handle the checkout.session.completed event(https://dev.to/stripe/purchase-fulfilment-with-checkout-or-wait-what-was-i-paid-for-335d) you add a row in your database saying "user my_user_id_1234 , who is Stripe customer cus_xxxx, has paid for my_product_xxx"
you can list all payments for a given customer and check if any of them correspond to the Price
But there is no price_id in the PaymentIntent object
correct
so if you're using Checkout for the payment, maybe use https://stripe.com/docs/api/checkout/sessions/list#list_checkout_sessions-customer instead for instance
but the point is I wouldn't do it that way, listing all payments and filtering them in your code each time you need to check this, seems like a pain. You'd be better off either just adding metadata to something like the Customer object that you can retrieve in one call, or using your own database
Where do I add metadata to customer object? In the checkout.session.completed event?
yep, I think that in my code for handling that event, I would figure out what the customer bought(see the blog post linked above) and then make an API call to update the Customer object with some metadata to indicate that, and then store the customer ID cus_xxx in my local database in the row/collection for my users