From afa4040243c54783d3942c51bef85492b4920ed4 Mon Sep 17 00:00:00 2001 From: James Wyndham Date: Thu, 29 Feb 2024 09:04:04 +0800 Subject: [PATCH] bugfix - success and cancel stripe redirects --- Backend/Dockerfile | 6 ++++-- Backend/README.md | 8 ++++---- Backend/compose.yaml | 3 ++- Backend/fly.toml | 6 ++++-- Backend/main.go | 18 ++++++++++-------- Backend/script.sh | 3 ++- 6 files changed, 26 insertions(+), 18 deletions(-) diff --git a/Backend/Dockerfile b/Backend/Dockerfile index 8b138b0..3bf76f9 100644 --- a/Backend/Dockerfile +++ b/Backend/Dockerfile @@ -6,7 +6,8 @@ FROM golang:latest # Set the Current Working Directory inside the container WORKDIR /app ARG STRIPE_SECRET_KEY="" -ARG STRIPE_RETURN_URL="" +ARG STRIPE_CANCEL_URL="" +ARG STRIPE_SUCCESS_URL="" ARG HOST="" ARG PORT="443" ARG DEVELOPMENT="" @@ -14,7 +15,8 @@ ARG DEVELOPMENT="" # Set Environment Variables ENV DEBIAN_FRONTEND=noninteractive ENV STRIPE_SECRET_KEY=${STRIPE_SECRET_KEY} -ENV STRIPE_RETURN_URL=${STRIPE_RETURN_URL} +ENV STRIPE_CANCEL_URL=${STRIPE_CANCEL_URL} +ENV STRIPE_SUCCESS_URL=${STRIPE_SUCCESS_URL} ENV HOST=${HOST} ENV PORT=${PORT} ENV DEVELOPMENT=${DEVELOPMENT} diff --git a/Backend/README.md b/Backend/README.md index 93d32fa..fa0c7b2 100644 --- a/Backend/README.md +++ b/Backend/README.md @@ -62,11 +62,11 @@ Optionally, to speed up the setup, we have added a [fixtures file](stripe_bootst 1. clone this package 1. set your environment variables to the following -1. Dog 1. STRIPE_SECRET_KEY=sk_test... - 2. STRIPE_RETURN_URL=url_to_your_site_after_checkout - 3. HOST=url_to_where_pocketbase_is_hosted - 4. DEVELOPMENT="" <-- leave blank if deploying live + 2. STRIPE_CANCEL_URL=url_to_your_site_after_checkout_cancel + 3. STRIPE_SUCCESS_URL=url_to_your_site_after_checkout_success + 4. HOST=url_to_where_pocketbase_is_hosted + 5. DEVELOPMENT="" <-- leave blank if deploying live 1. Run `go run main.go serve` from a command line in the root of the folder 1. Go to a webbrowser and browse to `https://127.0.0.1:8090/_/` and create new admin account and login 1. Click `Settings` on the left hand side bar and go to `Import Collections` diff --git a/Backend/compose.yaml b/Backend/compose.yaml index f740fd3..ba99609 100644 --- a/Backend/compose.yaml +++ b/Backend/compose.yaml @@ -6,7 +6,8 @@ services: args: STRIPE_SECRET_KEY: sk_test_51Oc1xLGaxPbSqiRDaGtJNmtk3aMQHFHVVSqIaC7TCUK74HQxzkb3jbjDqq5NQyoDEyKSeDitPB2bHX4vXqS8s0z100rXePxwfB HOST: 0.0.0.0 - STRIPE_RETURN_URL: https://sign365.com.au/account + STRIPE_SUCCESS_URL: https://sign365.com.au/account + STRIPE_CANCEL_URL: https://sign365.com.au/pricing PORT: 8090 DEVELOPMENT: "" platform: linux/amd64 diff --git a/Backend/fly.toml b/Backend/fly.toml index 9f6c06c..f79b8f2 100644 --- a/Backend/fly.toml +++ b/Backend/fly.toml @@ -12,8 +12,10 @@ primary_region = 'syd' DEVELOPMENT = '' HOST = 'fastpocket.fly.dev' PORT = '8090' - STRIPE_RETURN_URL = 'https://www.fastpocket.dev/account' - STRIPE_SECRET_KEY = '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' + STRIPE_SUCCESS_URL = 'https://www.fastpocket.dev/account' + STRIPE_CANCEL_URL = 'https://www.fastpocket.dev/pricing' + # requires STRIPE_SECRET_KEY = '{sk_live_...}' to be setup as a secret + # see: https://fly.io/docs/reference/secrets/#setting-secrets [[mounts]] source = 'data_fastpocket' diff --git a/Backend/main.go b/Backend/main.go index d95b182..39bd2a0 100644 --- a/Backend/main.go +++ b/Backend/main.go @@ -50,6 +50,8 @@ func main() { app := pocketbase.New() // Retreive your STRIPE_SECRET_KEY from environment variables stripe.Key = os.Getenv("STRIPE_SECRET_KEY") + stripeSuccessURL := os.Getenv("STRIPE_SUCCESS_URL") + stripeCancelURL := os.Getenv("STRIPE_CANCEL_URL") app.OnBeforeServe().Add(func(e *core.ServeEvent) error { e.Router.POST("/create-checkout-session", func(c echo.Context) error { // 1. Destructure the price and quantity from the POST body @@ -126,8 +128,8 @@ func main() { CustomerUpdate: customerUpdateParams, Mode: stripe.String("subscription"), AllowPromotionCodes: stripe.Bool(true), - SuccessURL: stripe.String("https://www.sign365.com.au/account"), - CancelURL: stripe.String("https://www.sign365.com.au/"), + SuccessURL: &stripeSuccessURL, + CancelURL: &stripeCancelURL, LineItems: lineParams, SubscriptionData: subscriptionParams, } @@ -152,8 +154,8 @@ func main() { CustomerUpdate: customerUpdateParams, Mode: stripe.String("payment"), AllowPromotionCodes: stripe.Bool(true), - SuccessURL: stripe.String("https://www.sign365.com.au/account"), - CancelURL: stripe.String("https://www.sign365.com.au/"), + SuccessURL: &stripeSuccessURL, + CancelURL: &stripeCancelURL, LineItems: lineParams, } sesh, _ := checkoutSession.New(sessionParams) @@ -185,8 +187,8 @@ func main() { CustomerUpdate: customerUpdateParams, Mode: stripe.String("subscription"), AllowPromotionCodes: stripe.Bool(true), - SuccessURL: stripe.String("https://www.sign365.com.au/account"), - CancelURL: stripe.String("https://www.sign365.com.au/"), + SuccessURL: &stripeSuccessURL, + CancelURL: &stripeCancelURL, LineItems: lineParams, SubscriptionData: subscriptionParams, } @@ -211,8 +213,8 @@ func main() { CustomerUpdate: customerUpdateParams, Mode: stripe.String("payment"), AllowPromotionCodes: stripe.Bool(true), - SuccessURL: stripe.String("https://www.sign365.com.au/account"), - CancelURL: stripe.String("https://www.sign365.com.au/"), + SuccessURL: &stripeSuccessURL, + CancelURL: &stripeCancelURL, LineItems: lineParams, } sesh, _ := checkoutSession.New(sessionParams) diff --git a/Backend/script.sh b/Backend/script.sh index bf43dde..959ebc9 100644 --- a/Backend/script.sh +++ b/Backend/script.sh @@ -1,7 +1,8 @@ #!/bin/bash echo "STRIPE_SECRET_KEY = $STRIPE_SECRET_KEY" -echo "STRIPE_RETURN_URL = $STRIPE_RETURN_URL" +echo "STRIPE_CANCEL_URL = $STRIPE_CANCEL_URL" +echo "STRIPE_SUCCESS_URL = $STRIPE_SUCCESS_URL" echo "HOST = $HOST" echo "PORT = $PORT" echo "DEVELOPMENT = $DEVELOPMENT"