bugfix - success and cancel stripe redirects

This commit is contained in:
James Wyndham 2024-02-29 09:04:04 +08:00
parent a826f1bee6
commit afa4040243
6 changed files with 26 additions and 18 deletions

View File

@ -6,7 +6,8 @@ FROM golang:latest
# Set the Current Working Directory inside the container # Set the Current Working Directory inside the container
WORKDIR /app WORKDIR /app
ARG STRIPE_SECRET_KEY="" ARG STRIPE_SECRET_KEY=""
ARG STRIPE_RETURN_URL="" ARG STRIPE_CANCEL_URL=""
ARG STRIPE_SUCCESS_URL=""
ARG HOST="" ARG HOST=""
ARG PORT="443" ARG PORT="443"
ARG DEVELOPMENT="" ARG DEVELOPMENT=""
@ -14,7 +15,8 @@ ARG DEVELOPMENT=""
# Set Environment Variables # Set Environment Variables
ENV DEBIAN_FRONTEND=noninteractive ENV DEBIAN_FRONTEND=noninteractive
ENV STRIPE_SECRET_KEY=${STRIPE_SECRET_KEY} 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 HOST=${HOST}
ENV PORT=${PORT} ENV PORT=${PORT}
ENV DEVELOPMENT=${DEVELOPMENT} ENV DEVELOPMENT=${DEVELOPMENT}

View File

@ -62,11 +62,11 @@ Optionally, to speed up the setup, we have added a [fixtures file](stripe_bootst
1. clone this package 1. clone this package
1. set your environment variables to the following 1. set your environment variables to the following
1. Dog
1. STRIPE_SECRET_KEY=sk_test... 1. STRIPE_SECRET_KEY=sk_test...
2. STRIPE_RETURN_URL=url_to_your_site_after_checkout 2. STRIPE_CANCEL_URL=url_to_your_site_after_checkout_cancel
3. HOST=url_to_where_pocketbase_is_hosted 3. STRIPE_SUCCESS_URL=url_to_your_site_after_checkout_success
4. DEVELOPMENT="" <-- leave blank if deploying live 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. 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. 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` 1. Click `Settings` on the left hand side bar and go to `Import Collections`

View File

@ -6,7 +6,8 @@ services:
args: args:
STRIPE_SECRET_KEY: sk_test_51Oc1xLGaxPbSqiRDaGtJNmtk3aMQHFHVVSqIaC7TCUK74HQxzkb3jbjDqq5NQyoDEyKSeDitPB2bHX4vXqS8s0z100rXePxwfB STRIPE_SECRET_KEY: sk_test_51Oc1xLGaxPbSqiRDaGtJNmtk3aMQHFHVVSqIaC7TCUK74HQxzkb3jbjDqq5NQyoDEyKSeDitPB2bHX4vXqS8s0z100rXePxwfB
HOST: 0.0.0.0 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 PORT: 8090
DEVELOPMENT: "" DEVELOPMENT: ""
platform: linux/amd64 platform: linux/amd64

View File

@ -12,8 +12,10 @@ primary_region = 'syd'
DEVELOPMENT = '' DEVELOPMENT = ''
HOST = 'fastpocket.fly.dev' HOST = 'fastpocket.fly.dev'
PORT = '8090' PORT = '8090'
STRIPE_RETURN_URL = 'https://www.fastpocket.dev/account' STRIPE_SUCCESS_URL = 'https://www.fastpocket.dev/account'
STRIPE_SECRET_KEY = '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' 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]] [[mounts]]
source = 'data_fastpocket' source = 'data_fastpocket'

View File

@ -50,6 +50,8 @@ func main() {
app := pocketbase.New() app := pocketbase.New()
// Retreive your STRIPE_SECRET_KEY from environment variables // Retreive your STRIPE_SECRET_KEY from environment variables
stripe.Key = os.Getenv("STRIPE_SECRET_KEY") 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 { app.OnBeforeServe().Add(func(e *core.ServeEvent) error {
e.Router.POST("/create-checkout-session", func(c echo.Context) error { e.Router.POST("/create-checkout-session", func(c echo.Context) error {
// 1. Destructure the price and quantity from the POST body // 1. Destructure the price and quantity from the POST body
@ -126,8 +128,8 @@ func main() {
CustomerUpdate: customerUpdateParams, CustomerUpdate: customerUpdateParams,
Mode: stripe.String("subscription"), Mode: stripe.String("subscription"),
AllowPromotionCodes: stripe.Bool(true), AllowPromotionCodes: stripe.Bool(true),
SuccessURL: stripe.String("https://www.sign365.com.au/account"), SuccessURL: &stripeSuccessURL,
CancelURL: stripe.String("https://www.sign365.com.au/"), CancelURL: &stripeCancelURL,
LineItems: lineParams, LineItems: lineParams,
SubscriptionData: subscriptionParams, SubscriptionData: subscriptionParams,
} }
@ -152,8 +154,8 @@ func main() {
CustomerUpdate: customerUpdateParams, CustomerUpdate: customerUpdateParams,
Mode: stripe.String("payment"), Mode: stripe.String("payment"),
AllowPromotionCodes: stripe.Bool(true), AllowPromotionCodes: stripe.Bool(true),
SuccessURL: stripe.String("https://www.sign365.com.au/account"), SuccessURL: &stripeSuccessURL,
CancelURL: stripe.String("https://www.sign365.com.au/"), CancelURL: &stripeCancelURL,
LineItems: lineParams, LineItems: lineParams,
} }
sesh, _ := checkoutSession.New(sessionParams) sesh, _ := checkoutSession.New(sessionParams)
@ -185,8 +187,8 @@ func main() {
CustomerUpdate: customerUpdateParams, CustomerUpdate: customerUpdateParams,
Mode: stripe.String("subscription"), Mode: stripe.String("subscription"),
AllowPromotionCodes: stripe.Bool(true), AllowPromotionCodes: stripe.Bool(true),
SuccessURL: stripe.String("https://www.sign365.com.au/account"), SuccessURL: &stripeSuccessURL,
CancelURL: stripe.String("https://www.sign365.com.au/"), CancelURL: &stripeCancelURL,
LineItems: lineParams, LineItems: lineParams,
SubscriptionData: subscriptionParams, SubscriptionData: subscriptionParams,
} }
@ -211,8 +213,8 @@ func main() {
CustomerUpdate: customerUpdateParams, CustomerUpdate: customerUpdateParams,
Mode: stripe.String("payment"), Mode: stripe.String("payment"),
AllowPromotionCodes: stripe.Bool(true), AllowPromotionCodes: stripe.Bool(true),
SuccessURL: stripe.String("https://www.sign365.com.au/account"), SuccessURL: &stripeSuccessURL,
CancelURL: stripe.String("https://www.sign365.com.au/"), CancelURL: &stripeCancelURL,
LineItems: lineParams, LineItems: lineParams,
} }
sesh, _ := checkoutSession.New(sessionParams) sesh, _ := checkoutSession.New(sessionParams)

View File

@ -1,7 +1,8 @@
#!/bin/bash #!/bin/bash
echo "STRIPE_SECRET_KEY = $STRIPE_SECRET_KEY" 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 "HOST = $HOST"
echo "PORT = $PORT" echo "PORT = $PORT"
echo "DEVELOPMENT = $DEVELOPMENT" echo "DEVELOPMENT = $DEVELOPMENT"