#FSOCIETY

1 messages ยท Page 1 of 1 (latest)

rancid wrenBOT
lilac scarab
#

Hey! Thanks for tuning in ๐Ÿ™‚

wind gazelle
#

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?

lilac scarab
#

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

wind gazelle
#

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.

lilac scarab
#

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

wind gazelle
#

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).

lilac scarab
#

But how can i pass the product into the payment intent object? there's no field for that

wind gazelle
#

You don't. Are you going to need to go back and reference the Price/Product that are associated with that payment later?

lilac scarab
#

Yes

#

Im adding values to my database right after the payment.. for example the product id they have bought

wind gazelle
#

Gotcha, you have two choices then.

  1. 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

  2. You can leverage the metadata field to store custom data that is pertinent to your flows:
    https://stripe.com/docs/api/metadata
    Most of our objects have a metadata field 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

lilac scarab
#

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

wind gazelle
#

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.

lilac scarab
#

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

wind gazelle
#

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