#craigmac-subscription
1 messages · Page 1 of 1 (latest)
Hi, you can expand latest_invoice.payment_intent while retrieving subscription via API. charge ID will be there:
i can see the latest_invoice but there are no nodes below this?
this is on customer.subscription.updated
ok so if i call options.AddExpand("latest_invoice");
that will give me the options?
actually that wont work as the customer.subscription.updated is posted to us, we dont control what is in the post
or would i use the ChargeService to bring back the last 20 charges and match the invoice id?
Expanded data doesn't work in event, but only via API, i.e. after getting the subscription ID from the event, then you make a query to expand the latest_invoice.payment_intent from subscription API
ok i think i can do this...
call ChargeService for the customer, get the charge invoice.Id mataches the latest_invoice
ChargeService List is that in the most recent charge order?
What is the ChargeService that you're referring here?
can i post my code snippet here?
Yup sure!
var options = new ChargeListOptions { Customer = strCustId };
options.AddExpand("invoice.subscription");
var service1 = new ChargeService(sc);
StripeList<Charge> charges = service1.List(options);
var charge = charges.FirstOrDefault(a => a.Invoice.Id == latest_invoice);
latest_invoice is the ID returned from the customer.subscription.updated
Can you explain why you're not using invoice.paid for the subscription when a customer completes a payment for each cycle, then obtain payment_intent ID from there?
oh ok, i didnt know that was an option, i will have a look at that
Every successfully paid subscription cycle will generate invoice.paid event, which contain its corresponding payment_intent ID
Then you can use that to obtain the charge for retrieving the fees
oh because we need to know if a subscription failed to update our membership system, i dont think paid is called if the payment failed?
we need to use customer.subscription.updated
we have 1 method that updates our system depending on the payment status
so what we are doing is correct, so getting the charge with the code above would work?
I see, in this case. After you receive customer.subscription.updated event, I recommend:
- Get the subscription ID from the event
- Use SubscriptionService to expand the
latest_invoice.payment_intent, and this will return you the charge ID (ch_xxx) - Use ChargeService to expand
balance_transactionto get the Stripe Fee under fee_details param
ok thanks