fix(payment): apply product affix to subscriptions
This commit is contained in:
parent
18790386a7
commit
61b6272110
@ -499,24 +499,41 @@ func selectedInstanceSupportedTypes(sel *payment.InstanceSelection) string {
|
||||
|
||||
func (s *PaymentService) buildPaymentSubject(plan *dbent.SubscriptionPlan, limitAmount float64, cfg *PaymentConfig, sel *payment.InstanceSelection) string {
|
||||
if plan != nil {
|
||||
if plan.ProductName != "" {
|
||||
return plan.ProductName
|
||||
productName := plan.ProductName
|
||||
if productName == "" {
|
||||
productName = "Sub2API Subscription " + plan.Name
|
||||
}
|
||||
return "Sub2API Subscription " + plan.Name
|
||||
return applyPaymentProductNameAffix(productName, cfg)
|
||||
}
|
||||
currency := payment.DefaultPaymentCurrency
|
||||
if sel != nil {
|
||||
currency = paymentProviderConfigCurrency(sel.ProviderKey, sel.Config)
|
||||
}
|
||||
amountStr := payment.FormatAmountForCurrency(limitAmount, currency)
|
||||
pf := strings.TrimSpace(cfg.ProductNamePrefix)
|
||||
sf := strings.TrimSpace(cfg.ProductNameSuffix)
|
||||
if pf != "" || sf != "" {
|
||||
return strings.TrimSpace(pf + " " + amountStr + " " + sf)
|
||||
if hasPaymentProductNameAffix(cfg) {
|
||||
return applyPaymentProductNameAffix(amountStr, cfg)
|
||||
}
|
||||
return "Sub2API " + amountStr + " " + currency
|
||||
}
|
||||
|
||||
func hasPaymentProductNameAffix(cfg *PaymentConfig) bool {
|
||||
if cfg == nil {
|
||||
return false
|
||||
}
|
||||
pf := strings.TrimSpace(cfg.ProductNamePrefix)
|
||||
sf := strings.TrimSpace(cfg.ProductNameSuffix)
|
||||
return pf != "" || sf != ""
|
||||
}
|
||||
|
||||
func applyPaymentProductNameAffix(productName string, cfg *PaymentConfig) string {
|
||||
if !hasPaymentProductNameAffix(cfg) {
|
||||
return productName
|
||||
}
|
||||
pf := strings.TrimSpace(cfg.ProductNamePrefix)
|
||||
sf := strings.TrimSpace(cfg.ProductNameSuffix)
|
||||
return strings.TrimSpace(pf + " " + productName + " " + sf)
|
||||
}
|
||||
|
||||
func (s *PaymentService) maybeBuildWeChatOAuthRequiredResponse(ctx context.Context, req CreateOrderRequest, amount, payAmount, feeRate float64) (*CreateOrderResponse, error) {
|
||||
return s.maybeBuildWeChatOAuthRequiredResponseForSelection(ctx, req, amount, payAmount, feeRate, nil)
|
||||
}
|
||||
|
||||
@ -138,6 +138,41 @@ func TestCalculateCreateOrderPayAmountRejectsFractionalZeroDecimal(t *testing.T)
|
||||
}
|
||||
}
|
||||
|
||||
func TestBuildPaymentSubjectAppliesAffixToSubscriptionPlanProductName(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
svc := &PaymentService{}
|
||||
cfg := &PaymentConfig{
|
||||
ProductNamePrefix: "PRE",
|
||||
ProductNameSuffix: "SUF",
|
||||
}
|
||||
plan := &dbent.SubscriptionPlan{
|
||||
Name: "Pro Monthly",
|
||||
ProductName: "Claude Pro",
|
||||
}
|
||||
|
||||
got := svc.buildPaymentSubject(plan, 0, cfg, nil)
|
||||
if got != "PRE Claude Pro SUF" {
|
||||
t.Fatalf("buildPaymentSubject() = %q, want %q", got, "PRE Claude Pro SUF")
|
||||
}
|
||||
}
|
||||
|
||||
func TestBuildPaymentSubjectAppliesAffixToSubscriptionPlanDefaultName(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
svc := &PaymentService{}
|
||||
cfg := &PaymentConfig{
|
||||
ProductNamePrefix: "PRE",
|
||||
ProductNameSuffix: "SUF",
|
||||
}
|
||||
plan := &dbent.SubscriptionPlan{Name: "Team Monthly"}
|
||||
|
||||
got := svc.buildPaymentSubject(plan, 0, cfg, nil)
|
||||
if got != "PRE Sub2API Subscription Team Monthly SUF" {
|
||||
t.Fatalf("buildPaymentSubject() = %q, want %q", got, "PRE Sub2API Subscription Team Monthly SUF")
|
||||
}
|
||||
}
|
||||
|
||||
func TestMaybeBuildWeChatOAuthRequiredResponse(t *testing.T) {
|
||||
t.Setenv("PAYMENT_RESUME_SIGNING_KEY", "0123456789abcdef0123456789abcdef")
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user