#craigmac-subscription

1 messages · Page 1 of 1 (latest)

split pivot
normal garden
#

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?

split pivot
#

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

normal garden
#

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?

split pivot
#

What is the ChargeService that you're referring here?

normal garden
#

can i post my code snippet here?

split pivot
#

Yup sure!

normal garden
#

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

split pivot
#

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?

normal garden
#

oh ok, i didnt know that was an option, i will have a look at that

split pivot
#

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

normal garden
#

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?

split pivot
#

I see, in this case. After you receive customer.subscription.updated event, I recommend:

  1. Get the subscription ID from the event
  2. Use SubscriptionService to expand the latest_invoice.payment_intent, and this will return you the charge ID (ch_xxx)
  3. Use ChargeService to expand balance_transaction to get the Stripe Fee under fee_details param
normal garden
#

ok thanks