支付模块
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

adapay.go 3.1 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  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. }