chore: remove payment compliance check system entirely
Docker Build / Build and Push Docker Image (push) Failing after 2m36s
Docker Build / Build and Push Docker Image (push) Failing after 2m36s
This commit is contained in:
+1
-12
@@ -29,10 +29,6 @@ var completionRatioMetaOptionKeys = []string{
|
|||||||
"AudioCompletionRatio",
|
"AudioCompletionRatio",
|
||||||
}
|
}
|
||||||
|
|
||||||
func isPaymentComplianceOptionKey(key string) bool {
|
|
||||||
return strings.HasPrefix(key, "payment_setting.compliance_")
|
|
||||||
}
|
|
||||||
|
|
||||||
func isPositiveOptionValue(value string) bool {
|
func isPositiveOptionValue(value string) bool {
|
||||||
intValue, err := strconv.Atoi(strings.TrimSpace(value))
|
intValue, err := strconv.Atoi(strings.TrimSpace(value))
|
||||||
if err == nil {
|
if err == nil {
|
||||||
@@ -139,15 +135,8 @@ func UpdateOption(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
switch option.Key {
|
switch option.Key {
|
||||||
case "QuotaForInviter", "QuotaForInvitee":
|
case "QuotaForInviter", "QuotaForInvitee":
|
||||||
if isPositiveOptionValue(option.Value.(string)) && !operation_setting.IsPaymentComplianceConfirmed() {
|
// no compliance check needed
|
||||||
common.ApiErrorI18n(c, i18n.MsgPaymentComplianceRequired)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
default:
|
default:
|
||||||
if isPaymentComplianceOptionKey(option.Key) {
|
|
||||||
common.ApiErrorMsg(c, "合规确认字段不允许通过通用设置接口修改")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
switch option.Key {
|
switch option.Key {
|
||||||
case "GitHubOAuthEnabled":
|
case "GitHubOAuthEnabled":
|
||||||
|
|||||||
@@ -1,82 +0,0 @@
|
|||||||
package controller
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"net/http"
|
|
||||||
"strconv"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/QuantumNous/new-api/common"
|
|
||||||
"github.com/QuantumNous/new-api/i18n"
|
|
||||||
"github.com/QuantumNous/new-api/logger"
|
|
||||||
"github.com/QuantumNous/new-api/model"
|
|
||||||
"github.com/QuantumNous/new-api/setting/operation_setting"
|
|
||||||
|
|
||||||
"github.com/gin-gonic/gin"
|
|
||||||
)
|
|
||||||
|
|
||||||
type PaymentComplianceRequest struct {
|
|
||||||
Confirmed bool `json:"confirmed"`
|
|
||||||
}
|
|
||||||
|
|
||||||
func requirePaymentCompliance(c *gin.Context) bool {
|
|
||||||
if !operation_setting.IsPaymentComplianceConfirmed() {
|
|
||||||
common.ApiErrorI18n(c, i18n.MsgPaymentComplianceRequired)
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
func ConfirmPaymentCompliance(c *gin.Context) {
|
|
||||||
if c.GetBool("use_access_token") {
|
|
||||||
c.JSON(http.StatusForbidden, gin.H{
|
|
||||||
"success": false,
|
|
||||||
"message": "This operation requires dashboard session authentication. API access token is not allowed.",
|
|
||||||
})
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
var req PaymentComplianceRequest
|
|
||||||
if err := common.DecodeJson(c.Request.Body, &req); err != nil {
|
|
||||||
common.ApiErrorMsg(c, "参数错误")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if !req.Confirmed {
|
|
||||||
common.ApiErrorMsg(c, "请确认合规声明")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
now := time.Now().Unix()
|
|
||||||
userId := c.GetInt("id")
|
|
||||||
clientIP := c.ClientIP()
|
|
||||||
|
|
||||||
updates := map[string]string{
|
|
||||||
"payment_setting.compliance_confirmed": "true",
|
|
||||||
"payment_setting.compliance_terms_version": operation_setting.CurrentComplianceTermsVersion,
|
|
||||||
"payment_setting.compliance_confirmed_at": strconv.FormatInt(now, 10),
|
|
||||||
"payment_setting.compliance_confirmed_by": strconv.Itoa(userId),
|
|
||||||
"payment_setting.compliance_confirmed_ip": clientIP,
|
|
||||||
}
|
|
||||||
|
|
||||||
for key, value := range updates {
|
|
||||||
if err := model.UpdateOption(key, value); err != nil {
|
|
||||||
common.ApiError(c, err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
logger.LogInfo(c.Request.Context(), fmt.Sprintf(
|
|
||||||
"payment compliance confirmed user_id=%d ip=%s terms_version=%s confirmed_at=%d",
|
|
||||||
userId,
|
|
||||||
clientIP,
|
|
||||||
operation_setting.CurrentComplianceTermsVersion,
|
|
||||||
now,
|
|
||||||
))
|
|
||||||
|
|
||||||
common.ApiSuccess(c, gin.H{
|
|
||||||
"confirmed": true,
|
|
||||||
"terms_version": operation_setting.CurrentComplianceTermsVersion,
|
|
||||||
"confirmed_at": now,
|
|
||||||
"confirmed_by": userId,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
@@ -7,14 +7,7 @@ import (
|
|||||||
"github.com/QuantumNous/new-api/setting/operation_setting"
|
"github.com/QuantumNous/new-api/setting/operation_setting"
|
||||||
)
|
)
|
||||||
|
|
||||||
func isPaymentComplianceConfirmed() bool {
|
|
||||||
return operation_setting.IsPaymentComplianceConfirmed()
|
|
||||||
}
|
|
||||||
|
|
||||||
func isStripeTopUpEnabled() bool {
|
func isStripeTopUpEnabled() bool {
|
||||||
if !isPaymentComplianceConfirmed() {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
return strings.TrimSpace(setting.StripeApiSecret) != "" &&
|
return strings.TrimSpace(setting.StripeApiSecret) != "" &&
|
||||||
strings.TrimSpace(setting.StripeWebhookSecret) != "" &&
|
strings.TrimSpace(setting.StripeWebhookSecret) != "" &&
|
||||||
strings.TrimSpace(setting.StripePriceId) != ""
|
strings.TrimSpace(setting.StripePriceId) != ""
|
||||||
@@ -29,9 +22,6 @@ func isStripeWebhookEnabled() bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func isCreemTopUpEnabled() bool {
|
func isCreemTopUpEnabled() bool {
|
||||||
if !isPaymentComplianceConfirmed() {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
products := strings.TrimSpace(setting.CreemProducts)
|
products := strings.TrimSpace(setting.CreemProducts)
|
||||||
return strings.TrimSpace(setting.CreemApiKey) != "" &&
|
return strings.TrimSpace(setting.CreemApiKey) != "" &&
|
||||||
products != "" &&
|
products != "" &&
|
||||||
@@ -47,9 +37,6 @@ func isCreemWebhookEnabled() bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func isWaffoTopUpEnabled() bool {
|
func isWaffoTopUpEnabled() bool {
|
||||||
if !isPaymentComplianceConfirmed() {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
if !setting.WaffoEnabled {
|
if !setting.WaffoEnabled {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
@@ -74,11 +61,6 @@ func isWaffoWebhookEnabled() bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func isWaffoPancakeTopUpEnabled() bool {
|
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) != "" &&
|
return strings.TrimSpace(setting.WaffoPancakeMerchantID) != "" &&
|
||||||
strings.TrimSpace(setting.WaffoPancakePrivateKey) != "" &&
|
strings.TrimSpace(setting.WaffoPancakePrivateKey) != "" &&
|
||||||
strings.TrimSpace(setting.WaffoPancakeProductID) != ""
|
strings.TrimSpace(setting.WaffoPancakeProductID) != ""
|
||||||
@@ -93,9 +75,6 @@ func isWaffoPancakeWebhookEnabled() bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func isEpayTopUpEnabled() bool {
|
func isEpayTopUpEnabled() bool {
|
||||||
if !isPaymentComplianceConfirmed() {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
return isEpayWebhookConfigured() && len(operation_setting.PayMethods) > 0
|
return isEpayWebhookConfigured() && len(operation_setting.PayMethods) > 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -8,21 +8,7 @@ import (
|
|||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
func confirmPaymentComplianceForTest(t *testing.T) {
|
|
||||||
t.Helper()
|
|
||||||
paymentSetting := operation_setting.GetPaymentSetting()
|
|
||||||
originalConfirmed := paymentSetting.ComplianceConfirmed
|
|
||||||
originalTermsVersion := paymentSetting.ComplianceTermsVersion
|
|
||||||
t.Cleanup(func() {
|
|
||||||
paymentSetting.ComplianceConfirmed = originalConfirmed
|
|
||||||
paymentSetting.ComplianceTermsVersion = originalTermsVersion
|
|
||||||
})
|
|
||||||
paymentSetting.ComplianceConfirmed = true
|
|
||||||
paymentSetting.ComplianceTermsVersion = operation_setting.CurrentComplianceTermsVersion
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestStripeWebhookEnabledRequiresTopUpAndWebhookConfig(t *testing.T) {
|
func TestStripeWebhookEnabledRequiresTopUpAndWebhookConfig(t *testing.T) {
|
||||||
confirmPaymentComplianceForTest(t)
|
|
||||||
originalAPISecret := setting.StripeApiSecret
|
originalAPISecret := setting.StripeApiSecret
|
||||||
originalWebhookSecret := setting.StripeWebhookSecret
|
originalWebhookSecret := setting.StripeWebhookSecret
|
||||||
originalPriceID := setting.StripePriceId
|
originalPriceID := setting.StripePriceId
|
||||||
@@ -45,7 +31,6 @@ func TestStripeWebhookEnabledRequiresTopUpAndWebhookConfig(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestCreemWebhookEnabledRequiresTopUpAndWebhookConfig(t *testing.T) {
|
func TestCreemWebhookEnabledRequiresTopUpAndWebhookConfig(t *testing.T) {
|
||||||
confirmPaymentComplianceForTest(t)
|
|
||||||
originalAPIKey := setting.CreemApiKey
|
originalAPIKey := setting.CreemApiKey
|
||||||
originalProducts := setting.CreemProducts
|
originalProducts := setting.CreemProducts
|
||||||
originalWebhookSecret := setting.CreemWebhookSecret
|
originalWebhookSecret := setting.CreemWebhookSecret
|
||||||
@@ -68,7 +53,6 @@ func TestCreemWebhookEnabledRequiresTopUpAndWebhookConfig(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestWaffoWebhookEnabledRequiresTopUpAndWebhookConfig(t *testing.T) {
|
func TestWaffoWebhookEnabledRequiresTopUpAndWebhookConfig(t *testing.T) {
|
||||||
confirmPaymentComplianceForTest(t)
|
|
||||||
originalEnabled := setting.WaffoEnabled
|
originalEnabled := setting.WaffoEnabled
|
||||||
originalSandbox := setting.WaffoSandbox
|
originalSandbox := setting.WaffoSandbox
|
||||||
originalAPIKey := setting.WaffoApiKey
|
originalAPIKey := setting.WaffoApiKey
|
||||||
@@ -113,7 +97,6 @@ func TestWaffoWebhookEnabledRequiresTopUpAndWebhookConfig(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestWaffoPancakeWebhookEnabledRequiresTopUpAndWebhookConfig(t *testing.T) {
|
func TestWaffoPancakeWebhookEnabledRequiresTopUpAndWebhookConfig(t *testing.T) {
|
||||||
confirmPaymentComplianceForTest(t)
|
|
||||||
originalMerchantID := setting.WaffoPancakeMerchantID
|
originalMerchantID := setting.WaffoPancakeMerchantID
|
||||||
originalPrivateKey := setting.WaffoPancakePrivateKey
|
originalPrivateKey := setting.WaffoPancakePrivateKey
|
||||||
originalProductID := setting.WaffoPancakeProductID
|
originalProductID := setting.WaffoPancakeProductID
|
||||||
@@ -123,9 +106,6 @@ func TestWaffoPancakeWebhookEnabledRequiresTopUpAndWebhookConfig(t *testing.T) {
|
|||||||
setting.WaffoPancakeProductID = originalProductID
|
setting.WaffoPancakeProductID = originalProductID
|
||||||
})
|
})
|
||||||
|
|
||||||
// Presence of all three credentials enables the gateway. Webhook public
|
|
||||||
// keys are bundled in the SDK and there is no separate Enabled toggle —
|
|
||||||
// clear any of the three fields to disable.
|
|
||||||
setting.WaffoPancakeMerchantID = ""
|
setting.WaffoPancakeMerchantID = ""
|
||||||
setting.WaffoPancakePrivateKey = "private"
|
setting.WaffoPancakePrivateKey = "private"
|
||||||
setting.WaffoPancakeProductID = "product"
|
setting.WaffoPancakeProductID = "product"
|
||||||
@@ -143,7 +123,6 @@ func TestWaffoPancakeWebhookEnabledRequiresTopUpAndWebhookConfig(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestEpayWebhookEnabledRequiresTopUpAndWebhookConfig(t *testing.T) {
|
func TestEpayWebhookEnabledRequiresTopUpAndWebhookConfig(t *testing.T) {
|
||||||
confirmPaymentComplianceForTest(t)
|
|
||||||
originalPayAddress := operation_setting.PayAddress
|
originalPayAddress := operation_setting.PayAddress
|
||||||
originalEpayID := operation_setting.EpayId
|
originalEpayID := operation_setting.EpayId
|
||||||
originalEpayKey := operation_setting.EpayKey
|
originalEpayKey := operation_setting.EpayKey
|
||||||
|
|||||||
@@ -8,7 +8,6 @@ import (
|
|||||||
"github.com/QuantumNous/new-api/common"
|
"github.com/QuantumNous/new-api/common"
|
||||||
"github.com/QuantumNous/new-api/i18n"
|
"github.com/QuantumNous/new-api/i18n"
|
||||||
"github.com/QuantumNous/new-api/model"
|
"github.com/QuantumNous/new-api/model"
|
||||||
"github.com/QuantumNous/new-api/setting/operation_setting"
|
|
||||||
|
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
)
|
)
|
||||||
@@ -60,11 +59,6 @@ func GetRedemption(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func AddRedemption(c *gin.Context) {
|
func AddRedemption(c *gin.Context) {
|
||||||
if !operation_setting.IsPaymentComplianceConfirmed() {
|
|
||||||
common.ApiErrorI18n(c, i18n.MsgPaymentComplianceRequired)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
redemption := model.Redemption{}
|
redemption := model.Redemption{}
|
||||||
err := c.ShouldBindJSON(&redemption)
|
err := c.ShouldBindJSON(&redemption)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -6,7 +6,6 @@ import (
|
|||||||
|
|
||||||
"github.com/QuantumNous/new-api/common"
|
"github.com/QuantumNous/new-api/common"
|
||||||
"github.com/QuantumNous/new-api/model"
|
"github.com/QuantumNous/new-api/model"
|
||||||
"github.com/QuantumNous/new-api/setting/operation_setting"
|
|
||||||
"github.com/QuantumNous/new-api/setting/ratio_setting"
|
"github.com/QuantumNous/new-api/setting/ratio_setting"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
"gorm.io/gorm"
|
"gorm.io/gorm"
|
||||||
@@ -29,11 +28,6 @@ type SubscriptionBalancePayRequest struct {
|
|||||||
// ---- User APIs ----
|
// ---- User APIs ----
|
||||||
|
|
||||||
func GetSubscriptionPlans(c *gin.Context) {
|
func GetSubscriptionPlans(c *gin.Context) {
|
||||||
if !operation_setting.IsPaymentComplianceConfirmed() {
|
|
||||||
common.ApiSuccess(c, []SubscriptionPlanDTO{})
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
var plans []model.SubscriptionPlan
|
var plans []model.SubscriptionPlan
|
||||||
if err := model.DB.Where("enabled = ?", true).Order("sort_order desc, id desc").Find(&plans).Error; err != nil {
|
if err := model.DB.Where("enabled = ?", true).Order("sort_order desc, id desc").Find(&plans).Error; err != nil {
|
||||||
common.ApiError(c, err)
|
common.ApiError(c, err)
|
||||||
@@ -98,10 +92,6 @@ func UpdateSubscriptionPreference(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func SubscriptionRequestBalancePay(c *gin.Context) {
|
func SubscriptionRequestBalancePay(c *gin.Context) {
|
||||||
if !requirePaymentCompliance(c) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
userId := c.GetInt("id")
|
userId := c.GetInt("id")
|
||||||
var req SubscriptionBalancePayRequest
|
var req SubscriptionBalancePayRequest
|
||||||
if err := c.ShouldBindJSON(&req); err != nil || req.PlanId <= 0 {
|
if err := c.ShouldBindJSON(&req); err != nil || req.PlanId <= 0 {
|
||||||
@@ -139,10 +129,6 @@ type AdminUpsertSubscriptionPlanRequest struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func AdminCreateSubscriptionPlan(c *gin.Context) {
|
func AdminCreateSubscriptionPlan(c *gin.Context) {
|
||||||
if !requirePaymentCompliance(c) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
var req AdminUpsertSubscriptionPlanRequest
|
var req AdminUpsertSubscriptionPlanRequest
|
||||||
if err := c.ShouldBindJSON(&req); err != nil {
|
if err := c.ShouldBindJSON(&req); err != nil {
|
||||||
common.ApiErrorMsg(c, "参数错误")
|
common.ApiErrorMsg(c, "参数错误")
|
||||||
@@ -204,10 +190,6 @@ func AdminCreateSubscriptionPlan(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func AdminUpdateSubscriptionPlan(c *gin.Context) {
|
func AdminUpdateSubscriptionPlan(c *gin.Context) {
|
||||||
if !requirePaymentCompliance(c) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
id, _ := strconv.Atoi(c.Param("id"))
|
id, _ := strconv.Atoi(c.Param("id"))
|
||||||
if id <= 0 {
|
if id <= 0 {
|
||||||
common.ApiErrorMsg(c, "无效的ID")
|
common.ApiErrorMsg(c, "无效的ID")
|
||||||
@@ -305,10 +287,6 @@ type AdminUpdateSubscriptionPlanStatusRequest struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func AdminUpdateSubscriptionPlanStatus(c *gin.Context) {
|
func AdminUpdateSubscriptionPlanStatus(c *gin.Context) {
|
||||||
if !requirePaymentCompliance(c) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
id, _ := strconv.Atoi(c.Param("id"))
|
id, _ := strconv.Atoi(c.Param("id"))
|
||||||
if id <= 0 {
|
if id <= 0 {
|
||||||
common.ApiErrorMsg(c, "无效的ID")
|
common.ApiErrorMsg(c, "无效的ID")
|
||||||
@@ -333,10 +311,6 @@ type AdminBindSubscriptionRequest struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func AdminBindSubscription(c *gin.Context) {
|
func AdminBindSubscription(c *gin.Context) {
|
||||||
if !requirePaymentCompliance(c) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
var req AdminBindSubscriptionRequest
|
var req AdminBindSubscriptionRequest
|
||||||
if err := c.ShouldBindJSON(&req); err != nil || req.UserId <= 0 || req.PlanId <= 0 {
|
if err := c.ShouldBindJSON(&req); err != nil || req.UserId <= 0 || req.PlanId <= 0 {
|
||||||
common.ApiErrorMsg(c, "参数错误")
|
common.ApiErrorMsg(c, "参数错误")
|
||||||
@@ -376,10 +350,6 @@ type AdminCreateUserSubscriptionRequest struct {
|
|||||||
|
|
||||||
// AdminCreateUserSubscription creates a new user subscription from a plan (no payment).
|
// AdminCreateUserSubscription creates a new user subscription from a plan (no payment).
|
||||||
func AdminCreateUserSubscription(c *gin.Context) {
|
func AdminCreateUserSubscription(c *gin.Context) {
|
||||||
if !requirePaymentCompliance(c) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
userId, _ := strconv.Atoi(c.Param("id"))
|
userId, _ := strconv.Atoi(c.Param("id"))
|
||||||
if userId <= 0 {
|
if userId <= 0 {
|
||||||
common.ApiErrorMsg(c, "无效的用户ID")
|
common.ApiErrorMsg(c, "无效的用户ID")
|
||||||
|
|||||||
@@ -21,10 +21,6 @@ type SubscriptionCreemPayRequest struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func SubscriptionRequestCreemPay(c *gin.Context) {
|
func SubscriptionRequestCreemPay(c *gin.Context) {
|
||||||
if !requirePaymentCompliance(c) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
var req SubscriptionCreemPayRequest
|
var req SubscriptionCreemPayRequest
|
||||||
|
|
||||||
// Keep body for debugging consistency (like RequestCreemPay)
|
// Keep body for debugging consistency (like RequestCreemPay)
|
||||||
|
|||||||
@@ -22,10 +22,6 @@ type SubscriptionEpayPayRequest struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func SubscriptionRequestEpay(c *gin.Context) {
|
func SubscriptionRequestEpay(c *gin.Context) {
|
||||||
if !requirePaymentCompliance(c) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
var req SubscriptionEpayPayRequest
|
var req SubscriptionEpayPayRequest
|
||||||
if err := c.ShouldBindJSON(&req); err != nil || req.PlanId <= 0 {
|
if err := c.ShouldBindJSON(&req); err != nil || req.PlanId <= 0 {
|
||||||
common.ApiErrorMsg(c, "参数错误")
|
common.ApiErrorMsg(c, "参数错误")
|
||||||
|
|||||||
@@ -21,10 +21,6 @@ type SubscriptionStripePayRequest struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func SubscriptionRequestStripePay(c *gin.Context) {
|
func SubscriptionRequestStripePay(c *gin.Context) {
|
||||||
if !requirePaymentCompliance(c) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
var req SubscriptionStripePayRequest
|
var req SubscriptionStripePayRequest
|
||||||
if err := c.ShouldBindJSON(&req); err != nil || req.PlanId <= 0 {
|
if err := c.ShouldBindJSON(&req); err != nil || req.PlanId <= 0 {
|
||||||
common.ApiErrorMsg(c, "参数错误")
|
common.ApiErrorMsg(c, "参数错误")
|
||||||
|
|||||||
@@ -21,10 +21,6 @@ type SubscriptionWaffoPancakePayRequest struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func SubscriptionRequestWaffoPancakePay(c *gin.Context) {
|
func SubscriptionRequestWaffoPancakePay(c *gin.Context) {
|
||||||
if !requirePaymentCompliance(c) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
var req SubscriptionWaffoPancakePayRequest
|
var req SubscriptionWaffoPancakePayRequest
|
||||||
if err := c.ShouldBindJSON(&req); err != nil || req.PlanId <= 0 {
|
if err := c.ShouldBindJSON(&req); err != nil || req.PlanId <= 0 {
|
||||||
common.ApiErrorMsg(c, "参数错误")
|
common.ApiErrorMsg(c, "参数错误")
|
||||||
|
|||||||
+2
-8
@@ -22,13 +22,8 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func GetTopUpInfo(c *gin.Context) {
|
func GetTopUpInfo(c *gin.Context) {
|
||||||
complianceConfirmed := operation_setting.IsPaymentComplianceConfirmed()
|
|
||||||
|
|
||||||
// 获取支付方式
|
// 获取支付方式
|
||||||
payMethods := operation_setting.PayMethods
|
payMethods := operation_setting.PayMethods
|
||||||
if !complianceConfirmed {
|
|
||||||
payMethods = []map[string]string{}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 如果启用了 Stripe 支付,添加到支付方法列表
|
// 如果启用了 Stripe 支付,添加到支付方法列表
|
||||||
if isStripeTopUpEnabled() {
|
if isStripeTopUpEnabled() {
|
||||||
@@ -101,9 +96,8 @@ func GetTopUpInfo(c *gin.Context) {
|
|||||||
"enable_creem_topup": isCreemTopUpEnabled(),
|
"enable_creem_topup": isCreemTopUpEnabled(),
|
||||||
"enable_waffo_topup": enableWaffo,
|
"enable_waffo_topup": enableWaffo,
|
||||||
"enable_waffo_pancake_topup": enableWaffoPancake,
|
"enable_waffo_pancake_topup": enableWaffoPancake,
|
||||||
"enable_redemption": complianceConfirmed,
|
"enable_redemption": true,
|
||||||
"payment_compliance_confirmed": complianceConfirmed,
|
"payment_compliance_confirmed": true,
|
||||||
"payment_compliance_terms_version": operation_setting.CurrentComplianceTermsVersion,
|
|
||||||
"waffo_pay_methods": func() interface{} {
|
"waffo_pay_methods": func() interface{} {
|
||||||
if enableWaffo {
|
if enableWaffo {
|
||||||
return setting.GetWaffoPayMethods()
|
return setting.GetWaffoPayMethods()
|
||||||
|
|||||||
@@ -17,7 +17,6 @@ import (
|
|||||||
"github.com/QuantumNous/new-api/model"
|
"github.com/QuantumNous/new-api/model"
|
||||||
"github.com/QuantumNous/new-api/service"
|
"github.com/QuantumNous/new-api/service"
|
||||||
"github.com/QuantumNous/new-api/setting"
|
"github.com/QuantumNous/new-api/setting"
|
||||||
"github.com/QuantumNous/new-api/setting/operation_setting"
|
|
||||||
|
|
||||||
"github.com/QuantumNous/new-api/constant"
|
"github.com/QuantumNous/new-api/constant"
|
||||||
|
|
||||||
@@ -344,10 +343,6 @@ type TransferAffQuotaRequest struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TransferAffQuota(c *gin.Context) {
|
func TransferAffQuota(c *gin.Context) {
|
||||||
if !requirePaymentCompliance(c) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
id := c.GetInt("id")
|
id := c.GetInt("id")
|
||||||
user, err := model.GetUserById(id, true)
|
user, err := model.GetUserById(id, true)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -1104,11 +1099,6 @@ func getTopUpLock(userID int) *topUpTryLock {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TopUp(c *gin.Context) {
|
func TopUp(c *gin.Context) {
|
||||||
if !operation_setting.IsPaymentComplianceConfirmed() {
|
|
||||||
common.ApiErrorI18n(c, i18n.MsgPaymentComplianceRequired)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
id := c.GetInt("id")
|
id := c.GetInt("id")
|
||||||
lock := getTopUpLock(id)
|
lock := getTopUpLock(id)
|
||||||
if !lock.TryLock() {
|
if !lock.TryLock() {
|
||||||
|
|||||||
@@ -152,7 +152,6 @@ const (
|
|||||||
MsgPaymentWebhookNotConfig = "payment.webhook_not_configured"
|
MsgPaymentWebhookNotConfig = "payment.webhook_not_configured"
|
||||||
MsgPaymentPriceIdNotConfig = "payment.price_id_not_configured"
|
MsgPaymentPriceIdNotConfig = "payment.price_id_not_configured"
|
||||||
MsgPaymentCreemNotConfig = "payment.creem_not_configured"
|
MsgPaymentCreemNotConfig = "payment.creem_not_configured"
|
||||||
MsgPaymentComplianceRequired = "payment.compliance_required"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// Topup related messages
|
// Topup related messages
|
||||||
|
|||||||
+2
-3
@@ -11,7 +11,6 @@ import (
|
|||||||
"github.com/QuantumNous/new-api/common"
|
"github.com/QuantumNous/new-api/common"
|
||||||
"github.com/QuantumNous/new-api/dto"
|
"github.com/QuantumNous/new-api/dto"
|
||||||
"github.com/QuantumNous/new-api/logger"
|
"github.com/QuantumNous/new-api/logger"
|
||||||
"github.com/QuantumNous/new-api/setting/operation_setting"
|
|
||||||
|
|
||||||
"github.com/bytedance/gopkg/util/gopool"
|
"github.com/bytedance/gopkg/util/gopool"
|
||||||
"gorm.io/gorm"
|
"gorm.io/gorm"
|
||||||
@@ -418,7 +417,7 @@ func (user *User) Insert(inviterId int) error {
|
|||||||
if common.QuotaForNewUser > 0 {
|
if common.QuotaForNewUser > 0 {
|
||||||
RecordLog(user.Id, LogTypeSystem, fmt.Sprintf("新用户注册赠送 %s", logger.LogQuota(common.QuotaForNewUser)))
|
RecordLog(user.Id, LogTypeSystem, fmt.Sprintf("新用户注册赠送 %s", logger.LogQuota(common.QuotaForNewUser)))
|
||||||
}
|
}
|
||||||
if inviterId != 0 && operation_setting.IsPaymentComplianceConfirmed() {
|
if inviterId != 0 {
|
||||||
if common.QuotaForInvitee > 0 {
|
if common.QuotaForInvitee > 0 {
|
||||||
_ = IncreaseUserQuota(user.Id, common.QuotaForInvitee, true)
|
_ = IncreaseUserQuota(user.Id, common.QuotaForInvitee, true)
|
||||||
RecordLog(user.Id, LogTypeSystem, fmt.Sprintf("使用邀请码赠送 %s", logger.LogQuota(common.QuotaForInvitee)))
|
RecordLog(user.Id, LogTypeSystem, fmt.Sprintf("使用邀请码赠送 %s", logger.LogQuota(common.QuotaForInvitee)))
|
||||||
@@ -479,7 +478,7 @@ func (user *User) FinalizeOAuthUserCreation(inviterId int) {
|
|||||||
if common.QuotaForNewUser > 0 {
|
if common.QuotaForNewUser > 0 {
|
||||||
RecordLog(user.Id, LogTypeSystem, fmt.Sprintf("新用户注册赠送 %s", logger.LogQuota(common.QuotaForNewUser)))
|
RecordLog(user.Id, LogTypeSystem, fmt.Sprintf("新用户注册赠送 %s", logger.LogQuota(common.QuotaForNewUser)))
|
||||||
}
|
}
|
||||||
if inviterId != 0 && operation_setting.IsPaymentComplianceConfirmed() {
|
if inviterId != 0 {
|
||||||
if common.QuotaForInvitee > 0 {
|
if common.QuotaForInvitee > 0 {
|
||||||
_ = IncreaseUserQuota(user.Id, common.QuotaForInvitee, true)
|
_ = IncreaseUserQuota(user.Id, common.QuotaForInvitee, true)
|
||||||
RecordLog(user.Id, LogTypeSystem, fmt.Sprintf("使用邀请码赠送 %s", logger.LogQuota(common.QuotaForInvitee)))
|
RecordLog(user.Id, LogTypeSystem, fmt.Sprintf("使用邀请码赠送 %s", logger.LogQuota(common.QuotaForInvitee)))
|
||||||
|
|||||||
@@ -186,7 +186,6 @@ func SetApiRouter(router *gin.Engine) {
|
|||||||
{
|
{
|
||||||
optionRoute.GET("/", controller.GetOptions)
|
optionRoute.GET("/", controller.GetOptions)
|
||||||
optionRoute.PUT("/", controller.UpdateOption)
|
optionRoute.PUT("/", controller.UpdateOption)
|
||||||
optionRoute.POST("/payment_compliance", controller.ConfirmPaymentCompliance)
|
|
||||||
optionRoute.GET("/channel_affinity_cache", controller.GetChannelAffinityCacheStats)
|
optionRoute.GET("/channel_affinity_cache", controller.GetChannelAffinityCacheStats)
|
||||||
optionRoute.DELETE("/channel_affinity_cache", controller.ClearChannelAffinityCache)
|
optionRoute.DELETE("/channel_affinity_cache", controller.ClearChannelAffinityCache)
|
||||||
optionRoute.POST("/rest_model_ratio", controller.ResetModelRatio)
|
optionRoute.POST("/rest_model_ratio", controller.ResetModelRatio)
|
||||||
|
|||||||
@@ -5,16 +5,8 @@ import "github.com/QuantumNous/new-api/setting/config"
|
|||||||
type PaymentSetting struct {
|
type PaymentSetting struct {
|
||||||
AmountOptions []int `json:"amount_options"`
|
AmountOptions []int `json:"amount_options"`
|
||||||
AmountDiscount map[int]float64 `json:"amount_discount"` // 充值金额对应的折扣,例如 100 元 0.9 表示 100 元充值享受 9 折优惠
|
AmountDiscount map[int]float64 `json:"amount_discount"` // 充值金额对应的折扣,例如 100 元 0.9 表示 100 元充值享受 9 折优惠
|
||||||
|
|
||||||
ComplianceConfirmed bool `json:"compliance_confirmed"`
|
|
||||||
ComplianceTermsVersion string `json:"compliance_terms_version"`
|
|
||||||
ComplianceConfirmedAt int64 `json:"compliance_confirmed_at"`
|
|
||||||
ComplianceConfirmedBy int `json:"compliance_confirmed_by"`
|
|
||||||
ComplianceConfirmedIP string `json:"compliance_confirmed_ip"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const CurrentComplianceTermsVersion = "v1"
|
|
||||||
|
|
||||||
// 默认配置
|
// 默认配置
|
||||||
var paymentSetting = PaymentSetting{
|
var paymentSetting = PaymentSetting{
|
||||||
AmountOptions: []int{10, 20, 50, 100, 200, 500},
|
AmountOptions: []int{10, 20, 50, 100, 200, 500},
|
||||||
@@ -29,7 +21,3 @@ func init() {
|
|||||||
func GetPaymentSetting() *PaymentSetting {
|
func GetPaymentSetting() *PaymentSetting {
|
||||||
return &paymentSetting
|
return &paymentSetting
|
||||||
}
|
}
|
||||||
|
|
||||||
func IsPaymentComplianceConfirmed() bool {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|||||||
Reference in New Issue
Block a user