Closed adrienverge closed 4 years ago
Hey @adrienverge !
I propose to add the following unit test inside one of the two commit (feel free to change or improve it!):
--- a/test.sh
+++ b/test.sh
@@ -469,6 +469,29 @@ curl -sSf -u $SK: $HOST/v1/subscriptions/$sub \
curl -sSf -u $SK: $HOST/v1/invoices?customer=$cus
+cus=$(curl -sSf -u $SK: $HOST/v1/customers \
+ -d description='This customer will switch from a yearly to another yearly plan' \
+ -d email=switch@bar.com \
+ | grep -oE 'cus_\w+' | head -n 1)
+
+curl -sSf -u $SK: $HOST/v1/customers/$cus/sources \
+ -d source=$tok
+
+sub=$(curl -sSf -u $SK: $HOST/v1/subscriptions \
+ -d customer=$cus \
+ -d items[0][plan]=basique-annuel)
+sub_id=$(echo "$sub" | grep -oE 'sub_\w+' | head -n 1)
+sub_item_id=$(echo "$sub" | grep -oE 'si_\w+' | head -n 1)
+
+sub=$(curl -sSf -u $SK: $HOST/v1/subscriptions/$sub_id \
+ -d items[0][plan]=pro-annuel \
+ -d items[0][id]=$sub_item_id)
+
+in=$(curl -sSf -u $SK: $HOST/v1/invoices \
+ -d customer=$cus)
+echo $in | grep "Abonnement PRO (annuel)"
+echo $in | grep "Abonnement basique (annuel)"
+
cus=$(curl -sSf -u $SK: $HOST/v1/customers \
-d email=john.malkovich@example.com \
| grep -oE 'cus_\w+' | head -n 1)
I checked that before the PR it fails, and on it, it works.
I propose to add the following unit test inside one of the two commit (feel free to change or improve it!):
So nice!!!
I took it as is, and just changed this for a better display (otherwise it's very hard to read and debug), otherwise, thanks :ok_hand:
-echo $in | grep "Abonnement PRO (annuel)"
-echo $in | grep "Abonnement basique (annuel)"
+grep -q "Abonnement PRO (annuel)" <<<"$in"
+grep -q "Abonnement basique (annuel)" <<<"$in"
InvoiceItem: Include 'plan' and 'subscription' info if available
That's what real Stripe does, e.g. on a plan upgrade:
Invoice: Create SubscriptionItems (not InvoiceItems) for upcoming
This fixes a bug when a subscription is upgraded to another plan with a different billing cycle (e.g. monthly to yearly). In such a case, the invoice is generated when the user creates the invoice then calls API
/pay
, but in this case the invoice is made fromInvoice._get_next_invoice()
, not fromSubscription._create_invoice()
.Subsciption items need to be created as
SubscriptionItem
, notInvoiceItem
(since commit a80dda2 "feat: Support invoice line items (il_) from Stripe API 2019-12-03").