#mni-santiago_api

1 messages ¡ Page 1 of 1 (latest)

versed dewBOT
#

👋 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/1270442517732528199

📝 Have more to share? Add more details, code, screenshots, videos, etc. below.

placid lynx
#

This is the object that I have generated to create the subscription

{
customer: 'cus_Pz9HnjPF1gDyMT',
start_date: 'now',
end_behavior: 'cancel',
phases: [ { items: [Array], iterations: 3 } ],
metadata: {
softruckId: '4e81e1f4-eae1-4579-be3e-660b82c21fd2',
flokzuFormId: '28c517d1-6598-1129-c55c-0e5c75c95c0f',
flokzuProcessId: 'INGS-22',
type: 'Softruck'
}
}

simple lotus
placid lynx
#

Is there a way to do it from the creation of the subscription?

simple lotus
placid lynx
#

So how could I solve my problem. Let me give you context, I am trying to reuse a hook and to do so I want to pass metadata to differentiate from my code what type of payment it refers to. When entering the subscription from the panel I cannot see the metadata either.

simple lotus
#

You can create the subscription with the metadata, and then immediately update the PaymentIntent with the metadata.

placid lynx
#

How do I do it if I still don't have a payment intent at the time of creating the subscription?

simple lotus
#

Then at that point there is not any payment so you can't 'differentiate from my code what type of payment it refers to'.

#

Once the payment succeeds, you can update the payment intent

versed dewBOT
placid lynx
#

Is there any other event triggered by subscriptions that could help me?

soft mango
#

Hello
Taking over..

Let me give you context, I am trying to reuse a hook and to do so I want to pass metadata to differentiate from my code what type of payment it refers to. When entering the subscription from the panel I cannot see the metadata either.

Not sure I fully grasp the context.. Can you share an example?

placid lynx
#

I have 2 payment methods within my app, subscriptions and normal payments. I have set up a hook that notifies me whenever there is a payment_intent_succeeded.

In order to differentiate the different payments, I want to pass metadata with a "type" and from my backend I capture that "type" and perform different operations depending on it.

This is my code when creating the subscription:
const subscriptionSchedule = await this.stripe.subscriptionSchedules.create({
customer: user.paymentInformation.stripeCustomerId,
start_date: 'now',
end_behavior: 'cancel',
phases: [
{
items: [
{
quantity: 1,
price: priceId,
},
],
iterations: iterations,
metadata: { ...metadata }
},
],
});

Resulting:

{
customer: 'cus_Pz9HnjPF1gDyMT',
start_date: 'now',
end_behavior: 'cancel',
phases: [ { items: [Array], iterations: 3 } ],
metadata: {
softruckId: '4e81e1f4-eae1-4579-be3e-660b82c21fd2',
flokzuFormId: '28c517d1-6598-1129-c55c-0e5c75c95c0f',
flokzuProcessId: 'INGS-22',
type: 'Softruck'
}
}

But when the hook notifies me, the metadata is empty. pgskc told me that the metadata cannot be maintained. So I wonder, is there any event specific to subscriptions to be able to differentiate them? Or some way to keep the metadata without updating the payment_intent?

Sorry if something is not understood, my English is not very good

soft mango
#

Do you use invoicing for "normal" (one-time) payments?

#

If not, the easier route might be to check if the payment intent has an associated invoice: https://docs.stripe.com/api/payment_intents/object#payment_intent_object-invoice

If it does, then the PaymentIntent was for the subscription versus if it doesn't then the PaymentIntent was for one-time (normal) payment

placid lynx
#

How can I check if I am using invoicing for one-time payments?

#

The invoice.payment_succeeded event could serve me instead of payment_intent_succeeded?

soft mango
#

How can I check if I am using invoicing for one-time payments?
If you create one-time invoices using the dashboard or use /v1/invoices endpoint to create invoices then you're likely using invoicing

The invoice.payment_succeeded event could serve me instead of payment_intent_succeeded?
Yes, you can listen to invoice.payment_succeeded or invoice.paid events

#

each invoice would have a billing_reason parameter: https://docs.stripe.com/api/invoices/object#invoice_object-billing_reason

manual: Unrelated to a subscription, for example, created via the invoice editor.

subscription: No longer in use. Applies to subscriptions from before May 2018 where no distinction was made between updates, cycles, and thresholds.

subscription_create: A new subscription was created.

subscription_cycle: A subscription advanced into a new period.

subscription_threshold: A subscription reached a billing threshold.

subscription_update: A subscription was updated.

upcoming: Reserved for simulated invoices, per the upcoming invoice endpoint.

placid lynx
#

Great, I'm going to develop a solution with this information, thank you very much for your time.