#FSOCIETY
1 messages ยท Page 1 of 1 (latest)
Hey! Thanks for tuning in ๐
Hi ๐ Card Intent is not a Stripe object, so I'm not sure what you're referring to by that. You can't create a Subscription from just a single one-time price, nor do you do so directly via a Payment Intent.
Are you looking to build a subscription flow in which you control the renewal logic and use Stripe to process the payments, or are you trying to fully model your subscriptions in Stripe via our Subscription objects?
im currently using:
const subscription = await stripe.subscriptions.create({
customer: customerId,
items: [
{
price: product,
quantity: 1,
},
],
payment_behavior: "default_incomplete",
expand: ["latest_invoice.payment_intent"],
});
to create the subscription itself and retrieve the client secret for the card element
My goal now is to determine by the product chosen by the user if that's a subscription or a 1 time payment product
so then ill create the right intent for the payment
The field that shows whether a price was set up to be recurring or one-time is the type field that is stored on the Price object:
https://stripe.com/docs/api/prices/object#price_object-type
If you're creating a Subscription object then there is no need to create a Payment Intent. The Subscription will automatically create Invoices which will automatically create the related Payment Intents.
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
I have done it before with checkout sessions... but the price id that im trying to implement is not a subscription
const session = await stripe.checkout.sessions.create({
customer: customerId,
line_items: [
{
price: types[wlType],
quantity: 1,
},
],
mode: wlType === "3" ? "payment" : "subscription",
....
for example, here i can use the mode field to set if that's a payment or subscription type... looking to do the same with the intent that are getting created
to create subscription object in some situations and the other object (what im asking for) for the 1-time products
Checkout Sessions either create Subscriptions, Payment Intents, or Setup Intents. If you want to directly create an object to process a one-time payment, then you want to either create a Payment Intent or an Invoice (specifically a one-off invoice).
But how can i pass the product into the payment intent object? there's no field for that
You don't. Are you going to need to go back and reference the Price/Product that are associated with that payment later?
Yes
Im adding values to my database right after the payment.. for example the product id they have bought
Gotcha, you have two choices then.
-
You can create an Invoice for the one-time payment, these accept Price objects as inputs when you're creating the associated Invoice Line Items:
https://stripe.com/docs/api/invoiceitems/create
https://stripe.com/docs/api/invoices/create -
You can leverage the
metadatafield to store custom data that is pertinent to your flows:
https://stripe.com/docs/api/metadata
Most of our objects have ametadatafield where you can store extra data, so you could put this information on the Payment Intent:
https://stripe.com/docs/api/payment_intents/create#create_payment_intent-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.
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
perfect then!
Thanks!
One last question tho..
The best choice to manage subscription status (for example - update / cancel / create) would be the
customer.subscription.created && customer.subscription.deleted && customer.subscription.updated ?
basically i need to listen for every move in the customer's subscription so ill need to remove / update values.. for exmplae when customer's subscription is expired
Yup, those are the right events to have your webhook endpoint listen for in order to be made aware of all changes to your Subscription objects.
for subscription expire for expire for example can listen to customer.subscription.updated and check if
previous_attributes.status === 'active' && object.status === 'past_due'
and for subsection deleted by the user / admin in dashboard i can listen to customer.subscription.deleted
right?
just making sure i know what im doing xD
customer.subscription.deleted is triggered when the Subscription is ended. You'll want to double check what your Subscription settings are in you dashboard to know the possible status changes that can occur for failed payments.
That is in the Managed failed payments section of this page:
https://dashboard.stripe.com/settings/billing/automatic
Sign in to the Stripe Dashboard to manage business payments and operations in your account. Manage payments and refunds, respond to disputes and more.