payment_currency.go 745 B

12345678910111213141516171819202122232425262728
  1. package service
  2. import (
  3. "strings"
  4. dbent "github.com/Wei-Shaw/sub2api/ent"
  5. "github.com/Wei-Shaw/sub2api/internal/payment"
  6. )
  7. func paymentProviderConfigCurrency(providerKey string, cfg map[string]string) string {
  8. switch strings.TrimSpace(providerKey) {
  9. case payment.TypeStripe, payment.TypeAirwallex:
  10. currency, err := payment.NormalizePaymentCurrency(cfg["currency"])
  11. if err == nil {
  12. return currency
  13. }
  14. }
  15. return payment.DefaultPaymentCurrency
  16. }
  17. func PaymentOrderCurrency(order *dbent.PaymentOrder) string {
  18. if snapshot := psOrderProviderSnapshot(order); snapshot != nil {
  19. if currency, err := payment.NormalizePaymentCurrency(snapshot.Currency); err == nil {
  20. return currency
  21. }
  22. }
  23. return payment.DefaultPaymentCurrency
  24. }