mirror of
https://github.com/QuantumNous/new-api.git
synced 2026-11-30 19:21:36 +08:00
* feat(payment): 易支付支持 RSA 签名方式 支付设置新增「签名方式」,可在 MD5 与 RSA 之间二选一。默认 MD5,已配置 MD5 的站点升级后行为不变。 - RSA 模式用商户私钥签名下单请求,跳转 /api/pay/submit;充值和订阅回调用平台公钥验签,MD5 签名的回调会被拒绝 - 保存时校验密钥:RSA 生效期间商户私钥和平台公钥必须能解析,切换到 RSA 前要先保存两把密钥;读取设置时不返回密钥 - 设置页选择 MD5 时只显示商户密钥,选择 RSA 时显示商户私钥和平台公钥;七种语言补齐文案 - go-epay 升级到 v0.0.6 * refactor(payment): 易支付签名设置改用 payment_setting 注册配置 签名方式、商户私钥、平台公钥改为 PaymentSetting 的字段,键名为 payment_setting.epay_sign_type、payment_setting.epay_merchant_private_key、payment_setting.epay_platform_public_key,由配置管理器统一加载和保存,不再在 option.go 里逐项初始化和赋值。 - 保存校验移到 operation_setting.ValidateEpaySignOption,规则不变 - 读取设置时不返回以 private_key 结尾的配置项;平台公钥可以正常显示和修改
116 lines
3.0 KiB
Go
116 lines
3.0 KiB
Go
package controller
|
|
|
|
import (
|
|
"strings"
|
|
|
|
"github.com/QuantumNous/new-api/setting"
|
|
"github.com/QuantumNous/new-api/setting/operation_setting"
|
|
)
|
|
|
|
func isPaymentComplianceConfirmed() bool {
|
|
return operation_setting.IsPaymentComplianceConfirmed()
|
|
}
|
|
|
|
func isStripeTopUpEnabled() bool {
|
|
if !isPaymentComplianceConfirmed() {
|
|
return false
|
|
}
|
|
return strings.TrimSpace(setting.StripeApiSecret) != "" &&
|
|
strings.TrimSpace(setting.StripeWebhookSecret) != "" &&
|
|
strings.TrimSpace(setting.StripePriceId) != ""
|
|
}
|
|
|
|
func isStripeWebhookConfigured() bool {
|
|
return strings.TrimSpace(setting.StripeWebhookSecret) != ""
|
|
}
|
|
|
|
func isStripeWebhookEnabled() bool {
|
|
return isStripeTopUpEnabled()
|
|
}
|
|
|
|
func isCreemTopUpEnabled() bool {
|
|
if !isPaymentComplianceConfirmed() {
|
|
return false
|
|
}
|
|
products := strings.TrimSpace(setting.CreemProducts)
|
|
return strings.TrimSpace(setting.CreemApiKey) != "" &&
|
|
products != "" &&
|
|
products != "[]"
|
|
}
|
|
|
|
func isCreemWebhookConfigured() bool {
|
|
return strings.TrimSpace(setting.CreemWebhookSecret) != ""
|
|
}
|
|
|
|
func isCreemWebhookEnabled() bool {
|
|
return isCreemTopUpEnabled() && isCreemWebhookConfigured()
|
|
}
|
|
|
|
func isWaffoTopUpEnabled() bool {
|
|
if !isPaymentComplianceConfirmed() {
|
|
return false
|
|
}
|
|
if !setting.WaffoEnabled {
|
|
return false
|
|
}
|
|
|
|
return isWaffoWebhookConfigured()
|
|
}
|
|
|
|
func isWaffoWebhookConfigured() bool {
|
|
if setting.WaffoSandbox {
|
|
return strings.TrimSpace(setting.WaffoSandboxApiKey) != "" &&
|
|
strings.TrimSpace(setting.WaffoSandboxPrivateKey) != "" &&
|
|
strings.TrimSpace(setting.WaffoSandboxPublicCert) != ""
|
|
}
|
|
|
|
return strings.TrimSpace(setting.WaffoApiKey) != "" &&
|
|
strings.TrimSpace(setting.WaffoPrivateKey) != "" &&
|
|
strings.TrimSpace(setting.WaffoPublicCert) != ""
|
|
}
|
|
|
|
func isWaffoWebhookEnabled() bool {
|
|
return isWaffoTopUpEnabled()
|
|
}
|
|
|
|
func isWaffoPancakeTopUpEnabled() bool {
|
|
if !isPaymentComplianceConfirmed() {
|
|
return false
|
|
}
|
|
// Presence-of-credentials = enabled. Webhook public keys ship inside
|
|
// the SDK; mode (test/prod) is read from each event.
|
|
return strings.TrimSpace(setting.WaffoPancakeMerchantID) != "" &&
|
|
strings.TrimSpace(setting.WaffoPancakePrivateKey) != "" &&
|
|
strings.TrimSpace(setting.WaffoPancakeProductID) != ""
|
|
}
|
|
|
|
func isWaffoPancakeWebhookConfigured() bool {
|
|
return isWaffoPancakeTopUpEnabled()
|
|
}
|
|
|
|
func isWaffoPancakeWebhookEnabled() bool {
|
|
return isWaffoPancakeTopUpEnabled()
|
|
}
|
|
|
|
func isEpayTopUpEnabled() bool {
|
|
if !isPaymentComplianceConfirmed() {
|
|
return false
|
|
}
|
|
return isEpayWebhookConfigured() && len(operation_setting.PayMethods) > 0
|
|
}
|
|
|
|
func isEpayWebhookConfigured() bool {
|
|
if strings.TrimSpace(operation_setting.PayAddress) == "" || strings.TrimSpace(operation_setting.EpayId) == "" {
|
|
return false
|
|
}
|
|
if paymentSetting := operation_setting.GetPaymentSetting(); paymentSetting.EpaySignType == operation_setting.EpaySignTypeRSA {
|
|
return strings.TrimSpace(paymentSetting.EpayMerchantPrivateKey) != "" &&
|
|
strings.TrimSpace(paymentSetting.EpayPlatformPublicKey) != ""
|
|
}
|
|
return strings.TrimSpace(operation_setting.EpayKey) != ""
|
|
}
|
|
|
|
func isEpayWebhookEnabled() bool {
|
|
return isEpayTopUpEnabled()
|
|
}
|