summaryrefslogtreecommitdiff
path: root/internal/billing/stripe.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/billing/stripe.go')
-rw-r--r--internal/billing/stripe.go23
1 files changed, 21 insertions, 2 deletions
diff --git a/internal/billing/stripe.go b/internal/billing/stripe.go
index b06eb6a..b887035 100644
--- a/internal/billing/stripe.go
+++ b/internal/billing/stripe.go
@@ -7,6 +7,7 @@ import (
"fmt"
"io"
"net/http"
+ "net/url"
"strings"
"github.com/jackc/pgx/v5"
@@ -32,8 +33,8 @@ func (s *Service) CreateCheckout(ctx context.Context, input CheckoutInput) (Chec
Mode: stripe.String("payment"),
ClientReferenceID: stripe.String(orderID),
IntegrationIdentifier: stripe.String(s.integrationIdentifier),
- SuccessURL: stripe.String(s.stripeSuccessURL),
- CancelURL: stripe.String(s.stripeCancelURL),
+ SuccessURL: stripe.String(checkoutReturnURL(s.stripeSuccessURL, orderID, true)),
+ CancelURL: stripe.String(checkoutReturnURL(s.stripeCancelURL, orderID, false)),
Metadata: map[string]string{
"aigw_topup_order_id": orderID,
"aigw_tenant_id": strings.TrimSpace(input.TenantID),
@@ -67,6 +68,24 @@ func (s *Service) CreateCheckout(ctx context.Context, input CheckoutInput) (Chec
return CheckoutResult{OrderID: orderID, SessionID: session.ID, URL: session.URL}, nil
}
+func checkoutReturnURL(raw, orderID string, includeStripeSession bool) string {
+ parsed, err := url.Parse(raw)
+ if err != nil {
+ return raw
+ }
+ query := parsed.Query()
+ query.Set("order_id", orderID)
+ if includeStripeSession {
+ query.Set("session_id", "{CHECKOUT_SESSION_ID}")
+ } else {
+ query.Del("session_id")
+ }
+ encoded := query.Encode()
+ encoded = strings.ReplaceAll(encoded, url.QueryEscape("{CHECKOUT_SESSION_ID}"), "{CHECKOUT_SESSION_ID}")
+ parsed.RawQuery = encoded
+ return parsed.String()
+}
+
func (s *Service) WebhookHandler() http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if r.Method != http.MethodPost {