Skip to content

Commit

Permalink
add stripe custom currency
Browse files Browse the repository at this point in the history
  • Loading branch information
bxy4543 committed Aug 9, 2023
1 parent 624ecac commit 00b0dc0
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion pkg/pay/stripe.go
Expand Up @@ -17,6 +17,7 @@ package pay
import (
"fmt"
"os"
"strings"

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

Expand All @@ -28,16 +29,24 @@ var DefaultURL = fmt.Sprintf("https://%s", utils.GetEnvWithDefault("DOMAIN", Def
const (
stripeSuccessPostfix = "STRIPE_SUCCESS_POSTFIX"
stripeCancelPostfix = "STRIPE_CANCEL_POSTFIX"
stripeCurrency = "STRIPE_CURRENCY"
)

var Currency string

func init() {
if port := os.Getenv("PORT"); 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, DefaultURL+os.Getenv(stripeSuccessPostfix), DefaultURL+os.Getenv(stripeCancelPostfix))
session, err := CreateCheckoutSession(amount, Currency, DefaultURL+os.Getenv(stripeSuccessPostfix), DefaultURL+os.Getenv(stripeCancelPostfix))
if err != nil {
return "", "", err
}
Expand Down

0 comments on commit 00b0dc0

Please sign in to comment.