支付模块
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

102 řádky
2.1 KiB

  1. package merchant
  2. import (
  3. "errors"
  4. "io/ioutil"
  5. "path/filepath"
  6. "strings"
  7. adapayCore "code.fnuoos.com/go_rely_warehouse/zyos_go_pay.git/lib/adapay-sdk/adapay-core"
  8. )
  9. type Merchant struct {
  10. MultiMerchSysConfigs map[string]*adapayCore.MerchSysConfig
  11. DefaultMerchSysConfig *adapayCore.MerchSysConfig
  12. }
  13. func InitDefaultMerchSysConfig(filePath string) (*Merchant, error) {
  14. config, err := adapayCore.ReadMerchConfig(filePath)
  15. if err != nil {
  16. return nil, err
  17. }
  18. ada := &Merchant{
  19. DefaultMerchSysConfig: config,
  20. }
  21. return ada, nil
  22. }
  23. func InitMultiMerchSysConfigs(fileDir string) (*Merchant, error) {
  24. dirs, _ := ioutil.ReadDir(fileDir)
  25. configs := map[string]*adapayCore.MerchSysConfig{}
  26. for _, f := range dirs {
  27. ext := filepath.Ext(f.Name())
  28. if ext == ".json" {
  29. config, err := adapayCore.ReadMerchConfig(fileDir + f.Name())
  30. if err != nil {
  31. continue
  32. }
  33. key := strings.Replace(f.Name(), ".json", "", -1)
  34. configs[key] = config
  35. }
  36. }
  37. ada := &Merchant{
  38. MultiMerchSysConfigs: configs,
  39. }
  40. return ada, nil
  41. }
  42. func GetMerchantByDBSysConfig(configKey, ApiKeyLive, ApiKeyTest, RspPubKey, RspPriKey string) (*Merchant, error) {
  43. configs := map[string]*adapayCore.MerchSysConfig{}
  44. if ApiKeyLive == "" || ApiKeyTest == "" ||
  45. RspPubKey == "" || RspPriKey == "" {
  46. return nil, errors.New("Config Setting Failed ")
  47. }
  48. var config adapayCore.MerchSysConfig
  49. config.ApiKeyLive = ApiKeyLive
  50. config.ApiKeyTest = ApiKeyTest
  51. config.RspPubKey = RspPubKey
  52. config.RspPriKey = RspPriKey
  53. configs[configKey] = &config
  54. ada := &Merchant{
  55. MultiMerchSysConfigs: configs,
  56. DefaultMerchSysConfig: &config,
  57. }
  58. return ada, nil
  59. }
  60. func (a *Merchant) HandleConfig(multiMerchConfigId ...string) *adapayCore.MerchSysConfig {
  61. if multiMerchConfigId == nil {
  62. return a.DefaultMerchSysConfig
  63. } else {
  64. return a.MultiMerchSysConfigs[multiMerchConfigId[0]]
  65. }
  66. }
  67. func (m *Merchant) BatchInput() *BatchInput {
  68. return &BatchInput{Merchant: m}
  69. }
  70. func (a *Merchant) Entry() *Entry {
  71. return &Entry{Merchant: a}
  72. }
  73. func (a *Merchant) MerProfile() *MerProfile {
  74. return &MerProfile{Merchant: a}
  75. }
  76. func (a *Merchant) Version() string {
  77. return "1.0.0"
  78. }