Last active
March 25, 2022 21:10
-
-
Save cjavilla-stripe/0c11afd766807906ce791dacf196fb12 to your computer and use it in GitHub Desktop.
New simplified invoice creation flow
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
{ | |
"cells": [ | |
{ | |
"cell_type": "code", | |
"execution_count": 1, | |
"metadata": { | |
"dotnet_interactive": { | |
"language": "csharp" | |
} | |
}, | |
"outputs": [], | |
"source": [ | |
"import stripe\n", | |
"\n", | |
"stripe.api_key = 'sk_test_'\n", | |
"\n" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 2, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"cus_LF23zMGcsqhUVr\n" | |
] | |
} | |
], | |
"source": [ | |
"customer = stripe.Customer.create(\n", | |
" description=\"Invoicing customer\",\n", | |
" email='[email protected]',\n", | |
" name='Jenny Rosen'\n", | |
")\n", | |
"print(customer.id)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 3, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"in_1KYY1OCZ6qsJgndJyIgh2flK\n" | |
] | |
} | |
], | |
"source": [ | |
"invoice = stripe.Invoice.create(\n", | |
" customer=customer.id,\n", | |
" pending_invoice_items_behavior='exclude',\n", | |
" collection_method='send_invoice',\n", | |
" days_until_due=7\n", | |
")\n", | |
"print(invoice.id)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 5, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"ii_1KYY3PCZ6qsJgndJuyfP1RM2\n" | |
] | |
} | |
], | |
"source": [ | |
"invoice_item = stripe.InvoiceItem.create(\n", | |
" customer=customer.id,\n", | |
" invoice=invoice.id,\n", | |
" price_data={\n", | |
" 'currency': 'usd',\n", | |
" 'unit_amount': 10000,\n", | |
" 'tax_behavior': 'exclusive',\n", | |
" 'product': 'prod_KuSCiurdHC8Ny7'\n", | |
" }\n", | |
")\n", | |
"print(invoice_item.id)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 6, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"in_1KYY1OCZ6qsJgndJyIgh2flK\n", | |
"open\n" | |
] | |
} | |
], | |
"source": [ | |
"invoice = stripe.Invoice.finalize_invoice(invoice.id)\n", | |
"print(invoice.id)\n", | |
"print(invoice.status)" | |
] | |
} | |
], | |
"metadata": { | |
"interpreter": { | |
"hash": "0dbc7650520110c2ecfbdb1c5e57e75db14ea0613a374ef98930ad14c9878b42" | |
}, | |
"kernelspec": { | |
"display_name": ".NET (C#)", | |
"language": "python", | |
"name": "python3" | |
}, | |
"language_info": { | |
"codemirror_mode": { | |
"name": "ipython", | |
"version": 3 | |
}, | |
"file_extension": ".py", | |
"mimetype": "text/x-python", | |
"name": "python", | |
"nbconvert_exporter": "python", | |
"pygments_lexer": "ipython3", | |
"version": "3.9.5" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 2 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment