factory.go 725 B

12345678910111213141516171819202122232425
  1. package provider
  2. import (
  3. "fmt"
  4. "github.com/Wei-Shaw/sub2api/internal/payment"
  5. )
  6. // CreateProvider creates a Provider from a provider key, instance ID and decrypted config.
  7. func CreateProvider(providerKey string, instanceID string, config map[string]string) (payment.Provider, error) {
  8. switch providerKey {
  9. case payment.TypeEasyPay:
  10. return NewEasyPay(instanceID, config)
  11. case payment.TypeAlipay:
  12. return NewAlipay(instanceID, config)
  13. case payment.TypeWxpay:
  14. return NewWxpay(instanceID, config)
  15. case payment.TypeStripe:
  16. return NewStripe(instanceID, config)
  17. case payment.TypeAirwallex:
  18. return NewAirwallex(instanceID, config)
  19. default:
  20. return nil, fmt.Errorf("unknown provider key: %s", providerKey)
  21. }
  22. }