#jack - subscriptions and react
1 messages · Page 1 of 1 (latest)
These would all be subscriptions for a single customer, right?
within their account on your platform
What part of this are you struggling with?
I suspect you may want to include the post identifier in some custom metadata on the subscription to map this back to your system after checkout
eg: metadata: { post_id: 'post_12356'}
firstly thanks for the response so quickly, its much appreciated.
The part i'm struggling with is associating a subscription with a document in a database that isnt the user document.
So if they subscribe to promote a specific post, the subscription is tied to that post.
nearly every example i find is tied to user roles/access, but in my case its just setting a flag on a specific document.
Is metadata the best way to do that?
I wasnt sure it was possible on a checkout session as i was looking into elements at first but have switched after Ionic being a pain with styling.
Currently plan to work my way through this as the docs are fantastic: https://stripe.com/docs/checkout/quickstart
Though there is no mention of metadata on that page, is it as simple as adding it after the cancel_url ?
That really is up to you to handle on your system
ultimately there is a customer paying for this, from the stripe side we map this by customer
if you want to add some detail to a post/message record on your end that's fine!
tracking the ID to use via metadata is likely the right way to do that when you set up the subscription with stripe
awesome stuff, so it's literally as simple as me adding a metadata object to the session when created?
and you can link those subscriptions and posts together that way in your business logic
well, you may want it on the subscription too, using eg subscription_data[metadata] to pass that through
but again this really depends on where you need it and what you plan to do with it
Like so?
const session = await stripe.checkout.sessions.create({
line_items: [
{
// Provide the exact Price ID (for example, pr_1234) of the product you want to sell
price: '{{PRICE_ID}}',
quantity: 1,
},
],
mode: 'payment',
success_url: `${YOUR_DOMAIN}?success=true`,
cancel_url: `${YOUR_DOMAIN}?canceled=true`,
metadata: {post_id: "id here"}
});
If its as simple as that, i feel like an idiot haha.
Spent many a year working with react and firebase but only recently with payment stuff, so i had in my mind it would be really complex. But that seems brilliantly simple.
As long as you only need it on the checkout session itself to set this up, yep that's all!
but as I said you might also want to apply this metadata to the subscription itself (not just the session)
I think that would be smart, do you have an example of that in the docs anywhere at all?
Not a worked example, no, but you can see what's supported for pass-through in the API ref for subscription_data:
https://stripe.com/docs/api/checkout/sessions/create#create_checkout_session-subscription_data-metadata
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
Nice one, thanks very much.
I've already been adding the firebase user ID as metadata to the product so i'm sure its as simple as adding a second bit of data to it with the post ID.
a case of overthinking it i think
Thanks very much for your help, its really appreciated
Quite welcome!