Skip to content

Latest commit

 

History

History
129 lines (85 loc) · 4.55 KB

gcp_tutorial.md

File metadata and controls

129 lines (85 loc) · 4.55 KB

Stripe + Firebase/Google Cloud Platform Demo

Getting started

This tutorial will help you deploy the Stripe + Firebase/GCP demo to your Firebase/GCP project.

The demo showcases an event-driven service that processes payments and receipt delivery automatically with virtually unlimited scalability, auto retry, and data analytics integration. It uses the following products and services:

It takes approximately 10 minutes to complete the tutorial.

Click Start to continue.

Setup

  1. Set up Stripe. In the Stripe Dashboard, get your test API keys. Write down both the publishable key and the secret key.

  2. Create a new Google Cloud Platform project.

    Open the Google Cloud Console. Create a new Google Cloud Platform project.

  3. Enable Cloud Firestore.

    In the Cloud Console, select Firestore from the left navigation lane. Use Cloud Firestore in Native mode and us-central for this tutorial. Click Create Database.

  4. Enable the APIs.

    Cloud Console will ask for your project ID. Choose the same one as your Google Cloud Platform project created earlier in the list.

  5. Set up SendGrid.

  6. Authenticate Cloud SDK:

    gcloud config set project YOUR-PROJECT-ID
    

    Replace YOUR-PROJECT-ID with the ID of your Google Cloud Platform project.

Click Next to continue.

Set up Stripe Webhooks

  1. Open Stripe Dashboard > Developers > Webhooks.

  2. Click Add Endpoint.

    Type in https://us-central1-[YOUR-GCP-PROJECT].cloudfunctions.net/fulfillment as the the endpoint URL. Replace [YOUR-GCP-PROJECT] with the ID of your Google Cloud Platform project. Use the lastest API version, and add payment_intent.succeeded as the event to send. Click Add Endpoint.

  3. In the endpoint details page, click Click to Reveal to reveal to the signing secret. Write down the secret. This is the secret for the fulfillment endpoint.

  4. Return to the Webhooks page. Repeat the steps above and add another endpoint.

    Type in https://us-central1-[YOUR-GCP-PROJECT].cloudfunctions.net/cancellation as the the endpoint URL. Replace [YOUR-GCP-PROJECT] with the ID of your Google Cloud Platform project. Use the lastest API version, and add payment_intent.payment_failed as the event to send. Click Add Endpoint.

    Similarly, reveal the signing secret of the new endpoint. This is the secret for the cancellation endpoint.

Deploy the functions

  1. Open gcp_quickstart.sh from the file explorer on the left side.

  2. Edit the first two lines of the file. Replace YOUR-STRIPE-API-KEY, YOUR-SENDGRID-API-KEY, YOUR-FULFILLMENT-ENDPOINT-SECRET and YOUR-CANCELLATION-ENDPOINT-SECRET with values of your own.

  3. Run the following command to deploy the functions:

    chmod +x gcp_quickstart.sh
    ./gcp_quickstart.sh
    

    It may take a few minutes to complete the operations.

Click Next to continue.

Try it out

First, open app/static/stripe.js in the file explorer. Replace YOUR-API-KEY with the value of your Stripe public API key.

Run the command below to start the example app that incorporates the payment process:

cd ~/stripe-google-demo/app
pip3 install -r requirements.txt --user
python3 main.py

If you are running this tutorial in Cloud Shell, click the Web Preview Buttion () on the top right of the screen, then click Preview on Port 8080 to open the web app. Otherwise, open your browser and go to localhost:8080.

You may use the VISA card 4242 4242 4242 4242 to make the purchase. Pick any future date as the expiration date, any 3-digit number as the CVC, and any 5-digit number as the zip code. You should see a confirmation email in your inbox soon. The charge should also be visible in the Stripe dashboard.

Click Next to continue.

Congratulations

You have deployed the demo.