#arielbo-metadata

1 messages · Page 1 of 1 (latest)

slender panther
wild spoke
#

$subscription = $stripe->subscriptions->create([
'customer' => $json_obj->cus,
'items' => [[
'price' => $json_obj->s_price_id,
]],
'metadata' => ['dteca_userid' => '123'],
'payment_behavior' => 'default_incomplete',
'expand' => ['latest_invoice.payment_intent.'],
]);

#

I try this code please maybe something is bad ?

#

'metadata' => ['dteca_userid' => '123'], ? its good ?

slender panther
#

hello @wild spoke! can you share what specifically doesn't work? are you getting an error message?

wild spoke
#

just not save metadata

slender panther
#

can you provide an example subscription id?

#

it'd look like sub_123

wild spoke
#

of course

#

POST /v1/subscriptions
Status
200 OK
ID
req_0ujpB5IEbcONiI

#

"id": "sub_1JjycyHHulAmiNnDR4vlFbFF",

slender panther
#

👀

wild spoke
#

yes I see now, but I need to put this metadata in this event "id": "evt_1JiRbmHHulAmiNnDECGHg8eU"

slender panther
#

that is the invoice.payment_succeeded event, it's not possible to have a Subscription metadata show on an Invoice event

#

you can only see the Subscription metadata on a Subscription event

wild spoke
#

yes

#

what I am trying to do is save metadata and then enable my user in the service I buy. I have two types of service, the one-time payment, and the recurring monthly subscription, as I understand you, I would have to use different events, correct? which could they be? if you can help me please.

#

I try to use this event payment_intent.succeeded for the case of one-time payment would it be correct? And in the case of subscriptions, what would be the appropriate event? Thanks in advance

#

I want to use this scheme with webhook

#

hello ?

slender panther
#

are you using Checkout?

wild spoke
#

custom php stripe

slender panther
#

maybe listen for the subscription.updated event?

#

status : active

wild spoke
#

let me see

#

I need to enable the service just when the invoice payment is successful

slender panther
#

yes, so after first payment for the subscription, the status updates to become active

wild spoke
#

I found customer.subscription.updated this?

slender panther
#

oh actually none of those have the metadata of the subscription too

wild spoke
#

Excuse me I'm confused, which event would be the ideal to read the payment of the first month, and which event would be the appropriate for the subsequent months?

slender panther
#

do you need to know / log each invoice payment?

#

or in reality, all you need to know is whether the subscription is "active"

wild spoke
#

log each invoice payment

#

becouse I need to update my database

#

with every successful payment

slender panther
#

alright, and why do you need the subscription metadata?

wild spoke
#

I need to know which order should I do the update in my system? But there could still use the subscription id, o el paymentintent id. In case that I does not use metadata what would be the usual events to achieve this result?

slender panther
#

okay, when your system creates the order id (and any other related details), this is linked to the subscription. Subsequently, in your database, you would have a order id linked to the subscription id after creation right?

#

i.e. upon successful creation of a subscription, save and link the subscription id to the order id in your db

#

when you receive an invoice.payment.succeeded event, that has the subscription id, is there any reason why you can't derive the order id from the subscription id?

wild spoke
#

yes at this moment Im save the id sub ie. sub_1Jjz5kHHulAmiNnD9CNXXYet

#

not really

slender panther
#

to be very clear
upon successful subscription creation response -> save metadata details and order id and corresponding subscription id to db

wild spoke
#

let me try now

slender panther
#

then when you receive an invoice.payment.succeeded event, pull the corresponding order id / metadata details from your DB based off the subscription id

wild spoke
#

ok I try

#

give me a few min

slender panther
#

I need to step away, someone else will be on later so they'll take a look if you still need help then!

wild spoke
#

until this moment all works

#

I have a question that afflicts me, for the 2nd and subsequent payments I use the same invoice.payment.succeeded event, correct? or do I need to do something additional?

green trellis
#

Hi, I will step in from here

#

invoice.payment_succeeded could work yes, you will need to find the Subscription Id related to that Invoice, and look at your DB

wild spoke
#

Hi orakaro,

#

Thanks for your answer, I get stuck in how the second and subsequent payments would be, look in the first case I updated according to the order created in my system, but for the second payment I am afraid that I will have to insert a new record, but what I do not understand is How does stripe work, that is, when the payment is made, what data would it hear, could you please explain better this part of the second payment and the data that it would receive?

green trellis
#

Yeah sure

#

So upon Subscription creation success, you created an order on your database and saved the Subscription Id, correct?

#

Each time Subscription is created or updated (1st or 2nd onward), Stripe will generate an Invoice associated to that Subscription

wild spoke
#

I already had the order created in my database, so I am updating it

green trellis
#

So you listen to invoice.payment_succeed, find the Subscription Id, and if the Id exists on your DB, you know that Subscription is renewing

wild spoke
#

So as I understand you I do everything with the correct subscription id?

#

I imagine that 2nd onward, all data of subscription created is the same and only change the invoice data right?

#

?

green trellis
#

Sorry for the late response