Skip to content

Commit

Permalink
docs(stripe): fix stripe integration docs (#339)
Browse files Browse the repository at this point in the history
* docs(stripe): fix stripe integration docs

* docs: update readme
  • Loading branch information
sinedied committed Sep 12, 2023
1 parent 55a2d0f commit bc34abd
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 11 deletions.
4 changes: 1 addition & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -249,11 +249,9 @@ This project uses [Azure Developer CLI (`azd`)](https://aka.ms/azd) to provision

```bash
# Login to azd. Only required once per install.
# If the command fails, try using the --use-device-code flag
azd auth login

# Use Flag if login does not work
azd auth login --use-device-code

# Provision infrastructure and the azd development environment
azd provision

Expand Down
40 changes: 32 additions & 8 deletions docs/README-scenario-5.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,14 @@ This scenario uses [Stripe](https://stripe.com) to handle payments. To use Strip
1. Create a free Stripe account here: https://dashboard.stripe.com/register
2. Once you have created your account, you will be redirected to the Stripe dashboard. Click on the `Developers` menu item, and then click on the `API keys` tab on the left.
3. Copy the `Public key` and `Secret key` and paste them into a new `.stripe.env` file in the `scripts/infra` folder, like this:
3. Copy the `Public key` and `Secret key` and paste them into a new `.stripe.env` file in the root folder, like this:

```bash
STRIPE_PUBLIC_KEY=<your public key>
STRIPE_SECRET_KEY=<your secret key>
```

4. Click on the `Webhooks` tab on the left, and then select the `Add endpoint` button. For the endpoint URL, enter `http://dummy.com` and choose the `Select events` option. Search for `checkout`, and enable the events `checkout.session.completed` and `checkout.session.expired`. Then click on the `Add endpoint` button.
4. Click on the `Webhooks` tab on the left, and then select the `Add endpoint` button. For the endpoint URL, enter `http://dummy.com` and choose the `Select events` option. Search for `checkout`, and enable the events `checkout.session.completed` and `checkout.session.expired`. Then click on the `Add endpoint` button. **Note that the endpoint URL will need to be updated later on.**

5. Copy the `Signing secret key` from your webhook and paste it into the `.stripe.env` file, like this:

Expand All @@ -59,15 +59,39 @@ STRIPE_WEBHOOK_SECRET=<your webhook key>
Once your Stripe keys have been configured, you can provision the Azure resources required for this scenario. To do this, run the following command:

```bash
./scripts/infra/setup.sh
# Export the environment variables from the .stripe.env file
export $(cat .stripe.env | xargs)

# Login to azd (only required once the first time)
azd auth login

# Provision infrastructure and the azd development environment
azd provision

# Package the app using the environment variables in .azure/env + deploy the code on Azure
azd deploy
```

This all-in-one script will provision all the needed Azure resources, setup the database, build the projects, and deploy them to Azure.
Except for the first command, the deployment commands are the same as the ones used in the [Deploy to Azure](../README.md#deploy-to-azure) guide.

After the deployment is complete, you will need to update the Stripe webhook endpoint URL with the one generated by the deployment.

1. First, run the following command to get the endpoint URL:
```bash
# Create a .env file with the environment variables from the azd environment
azd env get-env > .env

# Get the endpoint URL
source .env && echo "Your Stripe webhook endpoint URL is:\n$SERVICE_STRIPE_URI/stripe-api/stripe/webhook"
```

2. Copy the resulting URL, and then go back to the Stripe dashboard, and select on the `Webhooks` tab on the left.
3. Pick on the webhook you created earlier, click on the `...` button then select `Update details`.
4. Replace the `http://dummy.com` value with the URL you copied earlier, and then click on the `Update endpoint` button.

You should now have a fully working Stripe test integration.

It will also create various `.env` files:
- `scripts/infra/.env`: contains all environments variables and secrets required for deployment
- `.env.local`: contains all environment variables and secrets required for local development, with the services running locally but connected to the Azure database
- `.env.docker`: same as `.env.local` but in a format without quotes that can be used for running Docker containers
> **Note:** if you want to test the Stripe integration, you can use the [Stripe test cards](https://stripe.com/docs/testing#cards).
### Starting the Stripe service

Expand Down

0 comments on commit bc34abd

Please sign in to comment.