|
- package merchant
-
- import (
- "errors"
- "io/ioutil"
- "path/filepath"
- "strings"
-
- adapayCore "code.fnuoos.com/go_rely_warehouse/zyos_go_pay.git/lib/adapay-sdk/adapay-core"
- )
-
- type Merchant struct {
- MultiMerchSysConfigs map[string]*adapayCore.MerchSysConfig
-
- DefaultMerchSysConfig *adapayCore.MerchSysConfig
- }
-
- func InitDefaultMerchSysConfig(filePath string) (*Merchant, error) {
-
- config, err := adapayCore.ReadMerchConfig(filePath)
- if err != nil {
- return nil, err
- }
-
- ada := &Merchant{
- DefaultMerchSysConfig: config,
- }
-
- return ada, nil
- }
-
- func InitMultiMerchSysConfigs(fileDir string) (*Merchant, 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 := &Merchant{
- MultiMerchSysConfigs: configs,
- }
-
- return ada, nil
- }
- func GetMerchantByDBSysConfig(configKey, ApiKeyLive, ApiKeyTest, RspPubKey, RspPriKey string) (*Merchant, 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 := &Merchant{
- MultiMerchSysConfigs: configs,
- DefaultMerchSysConfig: &config,
- }
-
- return ada, nil
- }
-
- func (a *Merchant) HandleConfig(multiMerchConfigId ...string) *adapayCore.MerchSysConfig {
- if multiMerchConfigId == nil {
- return a.DefaultMerchSysConfig
- } else {
- return a.MultiMerchSysConfigs[multiMerchConfigId[0]]
- }
- }
-
- func (m *Merchant) BatchInput() *BatchInput {
- return &BatchInput{Merchant: m}
- }
-
- func (a *Merchant) Entry() *Entry {
- return &Entry{Merchant: a}
- }
-
- func (a *Merchant) MerProfile() *MerProfile {
- return &MerProfile{Merchant: a}
- }
-
- func (a *Merchant) Version() string {
- return "1.0.0"
- }
|