Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stripe return url #3652

Merged
merged 2 commits into from Aug 10, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 17 additions & 3 deletions pkg/pay/stripe.go
Expand Up @@ -17,22 +17,36 @@ package pay
import (
"fmt"
"os"
"strings"

"github.com/labring/sealos/controllers/pkg/utils"

"github.com/stripe/stripe-go/v74"
)

var DefaultSuccessURL = fmt.Sprintf("https://%s", utils.GetEnvWithDefault("DOMAIN", DefaultDomain))
var DefaultURL = fmt.Sprintf("https://%s", utils.GetEnvWithDefault("DOMAIN", DefaultDomain))

const (
stripeSuccessPostfix = "STRIPE_SUCCESS_POSTFIX"
stripeCancelPostfix = "STRIPE_CANCEL_POSTFIX"
stripeCurrency = "STRIPE_CURRENCY"
)

var Currency string

func init() {
if port := os.Getenv("PORT"); port != "" {
DefaultSuccessURL = fmt.Sprintf("%s:%s", DefaultSuccessURL, port)
DefaultURL = fmt.Sprintf("%s:%s", DefaultURL, port)
}
currency := strings.ToLower(strings.TrimSpace(os.Getenv(stripeCurrency)))
if currency != USD {
currency = CNY
}
Currency = currency
}

func (s StripePayment) CreatePayment(amount int64, _ string) (string, string, error) {
session, err := CreateCheckoutSession(amount, CNY, DefaultSuccessURL, DefaultSuccessURL)
session, err := CreateCheckoutSession(amount, Currency, DefaultURL+os.Getenv(stripeSuccessPostfix), DefaultURL+os.Getenv(stripeCancelPostfix))
if err != nil {
return "", "", err
}
Expand Down