-
Notifications
You must be signed in to change notification settings - Fork 460
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2493 from jupyter-naas/2492-stripe-create-a-payme…
…nt-link feat: Stripe - Create a payment link
- Loading branch information
Showing
1 changed file
with
241 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,241 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "markdown", | ||
"id": "50c45395-1739-4e34-a40e-09c399320a5e", | ||
"metadata": { | ||
"papermill": {}, | ||
"tags": [] | ||
}, | ||
"source": [ | ||
"<img width=\"8%\" alt=\"Naas.png\" src=\"https://raw.githubusercontent.com/jupyter-naas/awesome-notebooks/master/.github/assets/logos/Naas.png\" style=\"border-radius: 15%\">" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"id": "d39aa314-8e04-41ff-a1c0-a78c2d233d93", | ||
"metadata": { | ||
"papermill": {}, | ||
"tags": [] | ||
}, | ||
"source": [ | ||
"# Stripe - Create a payment link" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"id": "e0fb5a6e-b02d-444c-9209-20dfe0f3f04d", | ||
"metadata": { | ||
"papermill": {}, | ||
"tags": [] | ||
}, | ||
"source": [ | ||
"**Tags:** #stripe #payment #link #api #python #notebook" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"id": "5a7267ad-c9bb-42cf-a13c-4eee1d685f7f", | ||
"metadata": { | ||
"papermill": {}, | ||
"tags": [] | ||
}, | ||
"source": [ | ||
"**Author:** [Florent Ravenel](https://www.linkedin.com/in/florent-ravenel/)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"id": "d6f3afb5-bcf4-4c80-b3e4-f7180c12d4a9", | ||
"metadata": { | ||
"papermill": {}, | ||
"tags": [] | ||
}, | ||
"source": [ | ||
"**Last update:** 2024-02-07 (Created: 2024-02-07)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"id": "0276dac5-e3ec-47be-bd8d-66badc2b0158", | ||
"metadata": { | ||
"papermill": {}, | ||
"tags": [] | ||
}, | ||
"source": [ | ||
"**Description:** This notebook demonstrates how to create a payment link using Stripe's API. It provides a step-by-step guide on how to use the Stripe Python library to generate a payment link for a specific product or service." | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"id": "ed5cd18c-9855-4169-bd08-3f665a771055", | ||
"metadata": { | ||
"papermill": {}, | ||
"tags": [] | ||
}, | ||
"source": [ | ||
"**References:**\n- [Stripe API Documentation](https://stripe.com/docs/api)\n- [Stripe Python Library](https://stripe.com/docs/libraries#python)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"id": "e7b9daa6-dd28-408c-af97-b5d21d571d9a", | ||
"metadata": { | ||
"papermill": {}, | ||
"tags": [] | ||
}, | ||
"source": [ | ||
"## Input" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"id": "dc117a6d-87d3-492c-b510-7cc2e6cc35f8", | ||
"metadata": { | ||
"papermill": {}, | ||
"tags": [] | ||
}, | ||
"source": [ | ||
"### Import libraries" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "a4b5ef37-b701-4785-827b-6042fe6af3de", | ||
"metadata": { | ||
"papermill": {}, | ||
"tags": [] | ||
}, | ||
"source": "import stripe", | ||
"outputs": [] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"id": "0b7c5d26-c7d8-4b78-a0b6-39b91a7cb00d", | ||
"metadata": { | ||
"papermill": {}, | ||
"tags": [] | ||
}, | ||
"source": [ | ||
"### Setup variables\n- `stripe.api_key`: Your secret Stripe API key. You can find this in your Stripe Dashboard under Developers > API Keys. Make sure to use the secret key, not the publishable one.\n- `product`: The ID of the product that you want to create a payment link for. You can find this in your Stripe Dashboard under Products.\n- `unit_amount`: The amount to charge for the product, in the smallest currency unit (e.g., 100 cents to charge $1.00).\n- `currency`: The currency of the payment. This must be a valid ISO 4217 currency code." | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "989a4d7c-cd1a-4a3a-bb35-9bb570d77c26", | ||
"metadata": { | ||
"papermill": {}, | ||
"tags": [] | ||
}, | ||
"source": "stripe.api_key = \"sk_test_4eC39HqLyjWDarjtT1zdp7dc\"\nproduct = \"prod_J6a8Jqj1I3kVVf\"\nunit_amount = 100\ncurrency = \"usd\"", | ||
"outputs": [] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"id": "e5c353da-a99e-4f2d-ac53-8a9701478c25", | ||
"metadata": { | ||
"papermill": {}, | ||
"tags": [] | ||
}, | ||
"source": [ | ||
"## Model" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"id": "e5efa03d-7495-4b25-b042-ae10e8a55e59", | ||
"metadata": { | ||
"papermill": {}, | ||
"tags": [] | ||
}, | ||
"source": [ | ||
"### Create a payment link" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"id": "49d4d2cd-6531-4e6e-a911-9f5961bc449d", | ||
"metadata": { | ||
"papermill": {}, | ||
"tags": [] | ||
}, | ||
"source": [ | ||
"This function creates a payment link for a specific product. The payment link can be shared with customers to allow them to make a payment. The function uses the Stripe API's `payment_links.create` method, which requires the product ID, unit amount, and currency as parameters." | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "1f75bdf0-7dce-4df8-8470-47dbb3f92bfa", | ||
"metadata": { | ||
"papermill": {}, | ||
"tags": [] | ||
}, | ||
"source": "payment_link = stripe.PaymentLink.create(\n line_items=[\n {\n \"price_data\": {\n \"product\": product,\n \"unit_amount\": unit_amount,\n \"currency\": currency,\n },\n \"quantity\": 1,\n }\n ],\n mode=\"payment\",\n success_url=\"https://example.com/success\",\n cancel_url=\"https://example.com/cancel\",\n)", | ||
"outputs": [] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"id": "ed02d73b-11b9-44c1-8307-30e339ae7df0", | ||
"metadata": { | ||
"papermill": {}, | ||
"tags": [] | ||
}, | ||
"source": [ | ||
"## Output" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"id": "b0c2b97a-7c03-44bc-b673-1fd9f6606d77", | ||
"metadata": { | ||
"papermill": {}, | ||
"tags": [] | ||
}, | ||
"source": [ | ||
"### Display result" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "859202f8-f2b3-470e-ab7a-dbcc6e8146f7", | ||
"metadata": { | ||
"papermill": {}, | ||
"tags": [] | ||
}, | ||
"source": "print(payment_link.url)", | ||
"outputs": [] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Python 3", | ||
"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.6" | ||
}, | ||
"widgets": { | ||
"application/vnd.jupyter.widget-state+json": { | ||
"state": {}, | ||
"version_major": 2, | ||
"version_minor": 0 | ||
} | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 5 | ||
} |