fixes
This commit is contained in:
1 parent
6586722652
commit
1e7c7bbfbb
65 files changed
+1345
-640
No files matched your search
@@ -328,6 +328,10 @@ func (s *StripeService) CreateCheckoutSession(ctx context.Context, companyID uui
|
||||
return CheckoutResult{}, fmt.Errorf("%w: %s %s", ErrStripePriceMissing, plan, term)
|
||||
}
|
||||
|
||||
if err := s.requireEuroStripePrice(ctx, priceID); err != nil {
|
||||
return CheckoutResult{}, err
|
||||
}
|
||||
|
||||
customerID, err := s.ensureCustomer(ctx, companyID, email, companyName)
|
||||
if err != nil {
|
||||
return CheckoutResult{}, err
|
||||
@@ -406,6 +410,10 @@ func (s *StripeService) CreateCreditPackCheckout(ctx context.Context, companyID
|
||||
return CheckoutResult{}, fmt.Errorf("%w: credit pack %s", ErrStripePriceMissing, pack.ID)
|
||||
}
|
||||
|
||||
if err := s.requireEuroStripePrice(ctx, priceID); err != nil {
|
||||
return CheckoutResult{}, err
|
||||
}
|
||||
|
||||
customerID, err := s.ensureCustomer(ctx, companyID, email, companyName)
|
||||
if err != nil {
|
||||
return CheckoutResult{}, err
|
||||
@@ -1034,6 +1042,22 @@ func verifyStripeSignature(payload []byte, header, secret string, tolerance time
|
||||
return ErrStripeBadSignature
|
||||
}
|
||||
|
||||
// requireEuroStripePrice blocks checkout against old USD Stripe Price IDs.
|
||||
// Publishing euro list prices cannot alter an existing Stripe Price currency.
|
||||
func (s *StripeService) requireEuroStripePrice(ctx context.Context, priceID string) error {
|
||||
var price struct {
|
||||
Currency string `json:"currency"`
|
||||
Active bool `json:"active"`
|
||||
}
|
||||
if err := s.stripeGET(ctx, "https://api.stripe.com/v1/prices/"+url.PathEscape(priceID), &price); err != nil {
|
||||
return fmt.Errorf("verify Stripe EUR price: %w", err)
|
||||
}
|
||||
if !price.Active || !strings.EqualFold(strings.TrimSpace(price.Currency), "eur") {
|
||||
return errors.New("Stripe Price must be active and denominated in EUR; configure a EUR Price ID before checkout")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// LoadStripePriceIDs reads STRIPE_PRICE_* env into the price map.
|
||||
func LoadStripePriceIDs(getenv func(string) string) map[string]string {
|
||||
out := map[string]string{}
|
||||
|
||||
Reference in new issue
Block a user