GetPromotionByCode looks up an active promotion code eligible for first-time customers.
(code string, priceInCents int64)
| 488 | |
| 489 | // GetPromotionByCode looks up an active promotion code eligible for first-time customers. |
| 490 | func 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 | } |
no test coverage detected