支付模块
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

158 linhas
3.1 KiB

  1. package adapay
  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 Adapay struct {
  10. MultiMerchSysConfigs map[string]*adapayCore.MerchSysConfig
  11. DefaultMerchSysConfig *adapayCore.MerchSysConfig
  12. AppId string
  13. }
  14. func InitDefaultMerchSysConfig(filePath string) (*Adapay, error) {
  15. config, err := adapayCore.ReadMerchConfig(filePath)
  16. if err != nil {
  17. return nil, err
  18. }
  19. ada := &Adapay{
  20. DefaultMerchSysConfig: config,
  21. }
  22. return ada, nil
  23. }
  24. func InitMultiMerchSysConfigs(fileDir string) (*Adapay, error) {
  25. dirs, _ := ioutil.ReadDir(fileDir)
  26. configs := map[string]*adapayCore.MerchSysConfig{}
  27. for _, f := range dirs {
  28. ext := filepath.Ext(f.Name())
  29. if ext == ".json" {
  30. config, err := adapayCore.ReadMerchConfig(fileDir + f.Name())
  31. if err != nil {
  32. continue
  33. }
  34. key := strings.Replace(f.Name(), ".json", "", -1)
  35. configs[key] = config
  36. }
  37. }
  38. ada := &Adapay{
  39. MultiMerchSysConfigs: configs,
  40. }
  41. return ada, nil
  42. }
  43. func GetAdapayByDBSysConfig(configKey, appId, ApiKeyLive, ApiKeyTest, RspPubKey, RspPriKey string) (*Adapay, error) {
  44. configs := map[string]*adapayCore.MerchSysConfig{}
  45. if ApiKeyLive == "" || ApiKeyTest == "" ||
  46. RspPubKey == "" || RspPriKey == "" {
  47. return nil, errors.New("Config Setting Failed ")
  48. }
  49. var config adapayCore.MerchSysConfig
  50. config.ApiKeyLive = ApiKeyLive
  51. config.ApiKeyTest = ApiKeyTest
  52. config.RspPubKey = RspPubKey
  53. config.RspPriKey = RspPriKey
  54. configs[configKey] = &config
  55. ada := &Adapay{
  56. MultiMerchSysConfigs: configs,
  57. DefaultMerchSysConfig: &config,
  58. AppId: appId,
  59. }
  60. return ada, nil
  61. }
  62. func (a *Adapay) HandleConfig(multiMerchConfigId ...string) *adapayCore.MerchSysConfig {
  63. if multiMerchConfigId == nil {
  64. return a.DefaultMerchSysConfig
  65. } else {
  66. return a.MultiMerchSysConfigs[multiMerchConfigId[0]]
  67. }
  68. }
  69. func (a *Adapay) Payment() *Payment {
  70. return &Payment{Adapay: a}
  71. }
  72. func (a *Adapay) PaymentConfirm() *PaymentConfirm {
  73. return &PaymentConfirm{Adapay: a}
  74. }
  75. func (a *Adapay) PaymentReverse() *PaymentReverse {
  76. return &PaymentReverse{Adapay: a}
  77. }
  78. func (a *Adapay) SettleAccount() *SettleAccount {
  79. return &SettleAccount{Adapay: a}
  80. }
  81. func (a *Adapay) AdapayTools() *AdapayTools {
  82. return &AdapayTools{Adapay: a}
  83. }
  84. func (a *Adapay) Drawcash() *Drawcash {
  85. return &Drawcash{Adapay: a}
  86. }
  87. func (a *Adapay) CorpMember() *CorpMember {
  88. return &CorpMember{Adapay: a}
  89. }
  90. func (a *Adapay) Member() *Member {
  91. return &Member{Adapay: a}
  92. }
  93. func (a *Adapay) Refund() *Refund {
  94. return &Refund{Adapay: a}
  95. }
  96. func (a *Adapay) Wallet() *Wallet {
  97. return &Wallet{Adapay: a}
  98. }
  99. func (a *Adapay) Account() *Account {
  100. return &Account{Adapay: a}
  101. }
  102. func (a *Adapay) Checkout() *Checkout {
  103. return &Checkout{Adapay: a}
  104. }
  105. func (a *Adapay) FastPay() *FastPay {
  106. return &FastPay{Adapay: a}
  107. }
  108. func (a *Adapay) FreezeAccount() *FreezeAccount {
  109. return &FreezeAccount{Adapay: a}
  110. }
  111. func (a *Adapay) UnFreezeAccount() *UnFreezeAccount {
  112. return &UnFreezeAccount{Adapay: a}
  113. }
  114. func (a *Adapay) Transfer() *Transfer {
  115. return &Transfer{Adapay: a}
  116. }
  117. func (a *Adapay) Version() string {
  118. return "1.3.1"
  119. }