Register Alipay and WxPay option keys and sync option updates into runtime payment settings.
62 lines
1.6 KiB
Go
62 lines
1.6 KiB
Go
package setting
|
|
|
|
import "strconv"
|
|
|
|
type AlipaySetting struct {
|
|
Enabled bool `json:"enabled"`
|
|
AppID string `json:"app_id"`
|
|
PrivateKey string `json:"private_key"`
|
|
PublicKey string `json:"public_key"`
|
|
GatewayUrl string `json:"gateway_url"`
|
|
NotifyURL string `json:"notify_url"`
|
|
ReturnURL string `json:"return_url"`
|
|
}
|
|
|
|
var Alipay = AlipaySetting{
|
|
GatewayUrl: "https://openapi.alipay.com/gateway.do",
|
|
}
|
|
|
|
const (
|
|
AlipayEnabledOption = "AlipayEnabled"
|
|
AlipayAppIDOption = "AlipayAppID"
|
|
AlipayPrivateKeyOption = "AlipayPrivateKey"
|
|
AlipayPublicKeyOption = "AlipayPublicKey"
|
|
AlipayGatewayUrlOption = "AlipayGatewayUrl"
|
|
AlipayNotifyURLOption = "AlipayNotifyURL"
|
|
AlipayReturnURLOption = "AlipayReturnURL"
|
|
)
|
|
|
|
func AlipayOptionValues() map[string]string {
|
|
return map[string]string{
|
|
AlipayEnabledOption: strconv.FormatBool(Alipay.Enabled),
|
|
AlipayAppIDOption: Alipay.AppID,
|
|
AlipayPrivateKeyOption: Alipay.PrivateKey,
|
|
AlipayPublicKeyOption: Alipay.PublicKey,
|
|
AlipayGatewayUrlOption: Alipay.GatewayUrl,
|
|
AlipayNotifyURLOption: Alipay.NotifyURL,
|
|
AlipayReturnURLOption: Alipay.ReturnURL,
|
|
}
|
|
}
|
|
|
|
func UpdateAlipayOption(key string, value string) bool {
|
|
switch key {
|
|
case AlipayEnabledOption:
|
|
Alipay.Enabled = value == "true"
|
|
case AlipayAppIDOption:
|
|
Alipay.AppID = value
|
|
case AlipayPrivateKeyOption:
|
|
Alipay.PrivateKey = value
|
|
case AlipayPublicKeyOption:
|
|
Alipay.PublicKey = value
|
|
case AlipayGatewayUrlOption:
|
|
Alipay.GatewayUrl = value
|
|
case AlipayNotifyURLOption:
|
|
Alipay.NotifyURL = value
|
|
case AlipayReturnURLOption:
|
|
Alipay.ReturnURL = value
|
|
default:
|
|
return false
|
|
}
|
|
return true
|
|
}
|