#arielbo-metadata
1 messages · Page 1 of 1 (latest)
$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 ?
hello @wild spoke! can you share what specifically doesn't work? are you getting an error message?
just not save metadata
of course
POST /v1/subscriptions
Status
200 OK
ID
req_0ujpB5IEbcONiI
"id": "sub_1JjycyHHulAmiNnDR4vlFbFF",
👀
the subscription does have the metadata, if you search in https://dashboard.stripe.com/test/logs/req_0ujpB5IEbcONiI for dteca_test, you'd be able to see it in the response
yes I see now, but I need to put this metadata in this event "id": "evt_1JiRbmHHulAmiNnDECGHg8eU"
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
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 ?
are you using Checkout?
custom php stripe
yes, so after first payment for the subscription, the status updates to become active
I found customer.subscription.updated this?
oh actually none of those have the metadata of the subscription too
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?
do you need to know / log each invoice payment?
or in reality, all you need to know is whether the subscription is "active"
log each invoice payment
becouse I need to update my database
with every successful payment
alright, and why do you need the subscription metadata?
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?
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?
to be very clear
upon successful subscription creation response -> save metadata details and order id and corresponding subscription id to db
let me try now
then when you receive an invoice.payment.succeeded event, pull the corresponding order id / metadata details from your DB based off the subscription id
I need to step away, someone else will be on later so they'll take a look if you still need help then!
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?
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
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?
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
I already had the order created in my database, so I am updating it
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
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?
?
Sorry for the late response