#jamie_97274

1 messages · Page 1 of 1 (latest)

ocean domeBOT
#

Hello! We'll be with you shortly. Below are links to other discussions we've had with you in the past week in case you want to review that information. If your question is related to one of these previous discussions, please provide a comprehensive summary of the current state and what you need help with now. We help many users simultaneously, so a summary allows us to resolve your issue as soon as possible.

crystal verge
#

Hmmm, I'm not sure. Let me check

wintry loom
#

Thank you, this is for a referral system, when a customer refers another user in our platform we add credit to the customer. When said credit is used we need to remove it from our local DB entries also - so need to identify when and how much credit has been used exactly whenever a succeeded invoice comes through

crystal verge
#

Ok, you'd actually look at total (which is the invoice amount pre balance) and amount_due

#

Balance isn't applied as a payment, it's more of a discount

wintry loom
#

so (total - amount_due) = balance used?

crystal verge
#

Yes, but be wary that other factors can influence the amount_due too (discounts/coupons, etc)

wintry loom
#

coupons are discounts no? So apart from checking for coupons is there anything else to take into account?

crystal verge
#

Well a Coupon transforms into a discount which are in the discounts field

wintry loom
#

And there is absolutely no other property to check the amount of balance used? You always need to manually calculate this?

#

(or a different object?)

crystal verge
#

Well there'd be a customer.updated event that would fire on invoice payment to reflect the balance changing

wintry loom
#

that might be a cleaner way than checking on invoice succeeded for my use case? do you have any thoughts

crystal verge
#

Only issue would be mapping/tying the events together

wintry loom
#

I'm not sure I would need to do so? I just need to remove a balance entry in our database connected to the customer ID

crystal verge
#

Sure, that would work then

wintry loom
#

its something I will have to test, but customer.updated gives me another avenue to test

#

do you know off the top of your head if that event will give previous balance - current balance?

crystal verge
#

It'd have a balance field that would reflect the new balance post invoice payment. But then you can use previous_attributes[balance] to calculate a diff

#

i.e. If I applied all $100 of my balance to an invoice, balance: 0 and previous_attributes[balance]: -1000

wintry loom
#

-10000 (in cents) I assume?

crystal verge
#

Yes

wintry loom
#

ok great I think that's better than checking the invoice amounts so I odn't have to account for discounts

#

thank you, have a good day