MCPcopy Index your code
hub / github.com/bytebase/bytebase / GetPromotionByCode

Function GetPromotionByCode

backend/plugin/stripe/stripe.go:490–507  ·  view source on GitHub ↗

GetPromotionByCode looks up an active promotion code eligible for first-time customers.

(code string, priceInCents int64)

Source from the content-addressed store, hash-verified

488
489// GetPromotionByCode looks up an active promotion code eligible for first-time customers.
490func GetPromotionByCode(code string, priceInCents int64) *stripego.PromotionCode {
491 iter := promotioncode.List(&stripego.PromotionCodeListParams{
492 Code: stripego.String(code),
493 Active: stripego.Bool(true),
494 })
495 for iter.Next() {
496 promo := iter.PromotionCode()
497 if v := promo.Restrictions; v != nil {
498 if v.MinimumAmount <= priceInCents && v.FirstTimeTransaction {
499 return promo
500 }
501 }
502 }
503 if err := iter.Err(); err != nil {
504 slog.Error("failed to get promotion", log.BBError(err), slog.String("code", code))
505 }
506 return nil
507}

Callers 1

CreateCheckoutSessionFunction · 0.85

Calls 4

BBErrorFunction · 0.92
StringMethod · 0.65
NextMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected