Last active
August 6, 2017 17:24
-
-
Save matthewarkin/bb310ee27323ffee7ab8 to your computer and use it in GitHub Desktop.
stripe upgrade, prorate, and bill for proration instantly
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//create subscription | |
// $20 a month | |
curl https://api.stripe.com/v1/customers/cus_18nj91X8lMXyju/subscriptions | |
-u private key: | |
-d plan=gold | |
//change subscription - upgrade plan | |
//$40 a month | |
curl https://api.stripe.com/v1/customers/cus_18nj91X8lMXyju/subscriptions/sub_4HWcxqoS8wG7T3 \ | |
-u private key: \ | |
-d plan=platinum | |
//create an invoice this has two items (items get added automatically) | |
// an invoice item - $20 | |
// an invoice item + $40 | |
curl https://api.stripe.com/v1/invoices \ | |
-u private key: \ | |
-d customer=cus_18nj91X8lMXyju | |
//invoice repsonse | |
{ | |
"date": 1403630438, | |
"id": "in_4HWedjWJ6yHAOi", | |
"period_start": 1403630314, | |
"period_end": 1403630438, | |
"lines": { | |
"object": "list", | |
"total_count": 2, | |
"has_more": false, | |
"url": "/v1/invoices/in_4HWedjWJ6yHAOi/lines", | |
"data": [ | |
{ | |
"id": "ii_4HWeKdQstOPDJE", | |
"object": "line_item", | |
"type": "invoiceitem", | |
"livemode": false, | |
"amount": 4000, | |
"currency": "usd", | |
"proration": true, | |
"period": { | |
"start": 1403630422, | |
"end": 1403630422 | |
}, | |
"quantity": null, | |
"plan": null, | |
"description": "Remaining time on Amazing Gold Plan after 24 Jun 2014", | |
"metadata": {} | |
}, | |
{ | |
"id": "ii_4HWe6lCsznwjVe", | |
"object": "line_item", | |
"type": "invoiceitem", | |
"livemode": false, | |
"amount": -2000, | |
"currency": "usd", | |
"proration": true, | |
"period": { | |
"start": 1403630422, | |
"end": 1403630422 | |
}, | |
"quantity": null, | |
"plan": null, | |
"description": "Unused time on Amazing Gold Plan after 24 Jun 2014", | |
"metadata": {} | |
} | |
] | |
}, | |
"subtotal": 2000, | |
"total": 2000, | |
"customer": "cus_18nj91X8lMXyju", | |
"object": "invoice", | |
"attempted": false, | |
"closed": false, | |
"paid": false, | |
"livemode": false, | |
"attempt_count": 0, | |
"amount_due": 2000, | |
"currency": "usd", | |
"starting_balance": 0, | |
"ending_balance": null, | |
"next_payment_attempt": 1403634038, | |
"webhooks_delivered_at": null, | |
"charge": null, | |
"discount": null, | |
"application_fee": null, | |
"subscription": null, | |
"metadata": {}, | |
"statement_description": null, | |
"description": null | |
//then you'd have to charge the invoice |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment