|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157 |
- package adapay
-
- import (
- "errors"
- "io/ioutil"
- "path/filepath"
- "strings"
-
- adapayCore "code.fnuoos.com/go_rely_warehouse/zyos_go_pay.git/lib/adapay-sdk/adapay-core"
- )
-
- type Adapay struct {
- MultiMerchSysConfigs map[string]*adapayCore.MerchSysConfig
-
- DefaultMerchSysConfig *adapayCore.MerchSysConfig
-
- AppId string
- }
-
- func InitDefaultMerchSysConfig(filePath string) (*Adapay, error) {
-
- config, err := adapayCore.ReadMerchConfig(filePath)
- if err != nil {
- return nil, err
- }
-
- ada := &Adapay{
- DefaultMerchSysConfig: config,
- }
-
- return ada, nil
- }
-
- func InitMultiMerchSysConfigs(fileDir string) (*Adapay, error) {
-
- dirs, _ := ioutil.ReadDir(fileDir)
-
- configs := map[string]*adapayCore.MerchSysConfig{}
-
- for _, f := range dirs {
-
- ext := filepath.Ext(f.Name())
- if ext == ".json" {
- config, err := adapayCore.ReadMerchConfig(fileDir + f.Name())
- if err != nil {
- continue
- }
-
- key := strings.Replace(f.Name(), ".json", "", -1)
- configs[key] = config
- }
- }
-
- ada := &Adapay{
- MultiMerchSysConfigs: configs,
- }
-
- return ada, nil
- }
-
- func GetAdapayByDBSysConfig(configKey, appId, ApiKeyLive, ApiKeyTest, RspPubKey, RspPriKey string) (*Adapay, error) {
-
- configs := map[string]*adapayCore.MerchSysConfig{}
- if ApiKeyLive == "" || ApiKeyTest == "" ||
- RspPubKey == "" || RspPriKey == "" {
- return nil, errors.New("Config Setting Failed ")
- }
- var config adapayCore.MerchSysConfig
- config.ApiKeyLive = ApiKeyLive
- config.ApiKeyTest = ApiKeyTest
- config.RspPubKey = RspPubKey
- config.RspPriKey = RspPriKey
- configs[configKey] = &config
- ada := &Adapay{
- MultiMerchSysConfigs: configs,
- DefaultMerchSysConfig: &config,
- AppId: appId,
- }
-
- return ada, nil
- }
-
- func (a *Adapay) HandleConfig(multiMerchConfigId ...string) *adapayCore.MerchSysConfig {
- if multiMerchConfigId == nil {
- return a.DefaultMerchSysConfig
- } else {
- return a.MultiMerchSysConfigs[multiMerchConfigId[0]]
- }
- }
-
- func (a *Adapay) Payment() *Payment {
- return &Payment{Adapay: a}
- }
-
- func (a *Adapay) PaymentConfirm() *PaymentConfirm {
- return &PaymentConfirm{Adapay: a}
- }
-
- func (a *Adapay) PaymentReverse() *PaymentReverse {
- return &PaymentReverse{Adapay: a}
- }
-
- func (a *Adapay) SettleAccount() *SettleAccount {
- return &SettleAccount{Adapay: a}
- }
-
- func (a *Adapay) AdapayTools() *AdapayTools {
- return &AdapayTools{Adapay: a}
- }
-
- func (a *Adapay) Drawcash() *Drawcash {
- return &Drawcash{Adapay: a}
- }
-
- func (a *Adapay) CorpMember() *CorpMember {
- return &CorpMember{Adapay: a}
- }
-
- func (a *Adapay) Member() *Member {
- return &Member{Adapay: a}
- }
-
- func (a *Adapay) Refund() *Refund {
- return &Refund{Adapay: a}
- }
-
- func (a *Adapay) Wallet() *Wallet {
- return &Wallet{Adapay: a}
- }
-
- func (a *Adapay) Account() *Account {
- return &Account{Adapay: a}
- }
-
- func (a *Adapay) Checkout() *Checkout {
- return &Checkout{Adapay: a}
- }
-
- func (a *Adapay) FastPay() *FastPay {
- return &FastPay{Adapay: a}
- }
-
- func (a *Adapay) FreezeAccount() *FreezeAccount {
- return &FreezeAccount{Adapay: a}
- }
-
- func (a *Adapay) UnFreezeAccount() *UnFreezeAccount {
- return &UnFreezeAccount{Adapay: a}
- }
-
- func (a *Adapay) Transfer() *Transfer {
- return &Transfer{Adapay: a}
- }
-
- func (a *Adapay) Version() string {
- return "1.3.1"
- }
|