From a80d6af035265dbc2158e417e130f5de9157abcd Mon Sep 17 00:00:00 2001 From: shanshanzhong Date: Tue, 9 Dec 2025 00:58:03 -0800 Subject: [PATCH] =?UTF-8?q?refactor(payment):=20=E7=A7=BB=E9=99=A4ApplePay?= =?UTF-8?q?=E6=94=AF=E4=BB=98=E5=B9=B3=E5=8F=B0=E6=94=AF=E6=8C=81=E5=B9=B6?= =?UTF-8?q?=E6=95=B4=E5=90=88=E5=88=B0Stripe?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 将ApplePay支付方式整合到Stripe平台处理,移除独立的ApplePay平台代码 简化支付逻辑,统一通过Stripe处理所有支付方式 --- .../handler/notify/paymentNotifyHandler.go | 2 +- .../public/portal/purchaseCheckoutLogic.go | 26 ++++++------------- pkg/payment/platform.go | 13 +--------- 3 files changed, 10 insertions(+), 31 deletions(-) diff --git a/internal/handler/notify/paymentNotifyHandler.go b/internal/handler/notify/paymentNotifyHandler.go index bd5cb3c..cd7d8b9 100644 --- a/internal/handler/notify/paymentNotifyHandler.go +++ b/internal/handler/notify/paymentNotifyHandler.go @@ -39,7 +39,7 @@ func PaymentNotifyHandler(svcCtx *svc.ServiceContext) func(c *gin.Context) { return } c.String(http.StatusOK, "%s", "success") - case payment.Stripe, payment.ApplePay: + case payment.Stripe: l := notify.NewStripeNotifyLogic(c.Request.Context(), svcCtx) if err := l.StripeNotify(c.Request, c.Writer); err != nil { result.HttpResult(c, nil, err) diff --git a/internal/logic/public/portal/purchaseCheckoutLogic.go b/internal/logic/public/portal/purchaseCheckoutLogic.go index 18065b2..46ba839 100644 --- a/internal/logic/public/portal/purchaseCheckoutLogic.go +++ b/internal/logic/public/portal/purchaseCheckoutLogic.go @@ -86,18 +86,7 @@ func (l *PurchaseCheckoutLogic) PurchaseCheckout(req *types.CheckoutOrderRequest case paymentPlatform.Stripe: // Process Stripe payment - creates payment sheet for client-side processing - stripePayment, err := l.stripePayment(paymentConfig.Config, orderInfo, "", "") - if err != nil { - return nil, errors.Wrapf(xerr.NewErrCode(xerr.ERROR), "stripePayment error: %v", err.Error()) - } - resp = &types.CheckoutOrderResponse{ - Type: "stripe", // Client should use Stripe SDK - Stripe: stripePayment, - } - - case paymentPlatform.ApplePay: - // Process Apple Pay payment - uses Stripe with 'card' method - stripePayment, err := l.stripePayment(paymentConfig.Config, orderInfo, "", "card") + stripePayment, err := l.stripePayment(paymentConfig.Config, orderInfo, "") if err != nil { return nil, errors.Wrapf(xerr.NewErrCode(xerr.ERROR), "stripePayment error: %v", err.Error()) } @@ -219,7 +208,7 @@ func (l *PurchaseCheckoutLogic) alipayF2fPayment(pay *payment.Payment, info *ord // stripePayment processes Stripe payment by creating a payment sheet // It supports various payment methods including WeChat Pay and Alipay through Stripe -func (l *PurchaseCheckoutLogic) stripePayment(config string, info *order.Order, identifier string, forceMethod string) (*types.StripePayment, error) { +func (l *PurchaseCheckoutLogic) stripePayment(config string, info *order.Order, identifier string) (*types.StripePayment, error) { // Parse Stripe configuration from payment settings stripeConfig := &payment.StripeConfig{} @@ -228,10 +217,6 @@ func (l *PurchaseCheckoutLogic) stripePayment(config string, info *order.Order, return nil, errors.Wrapf(xerr.NewErrCode(xerr.ERROR), "Unmarshal error: %s", err.Error()) } - if forceMethod != "" { - stripeConfig.Payment = forceMethod - } - // Initialize Stripe client with API credentials client := stripe.NewClient(stripe.Config{ SecretKey: stripeConfig.SecretKey, @@ -253,12 +238,17 @@ func (l *PurchaseCheckoutLogic) stripePayment(config string, info *order.Order, ) // Create Stripe payment sheet for client-side processing + // Map apple_pay to card for Stripe API, but keep apple_pay in config/response + paymentMethod := stripeConfig.Payment + if paymentMethod == "apple_pay" { + paymentMethod = "card" + } ord := &stripe.Order{ OrderNo: info.OrderNo, Subscribe: strconv.FormatInt(info.SubscribeId, 10), Amount: convertAmount, Currency: "cny", - Payment: stripeConfig.Payment, + Payment: paymentMethod, } usr := &stripe.User{Email: identifier} l.Infow("stripe request", logger.Field("order", ord), logger.Field("user", usr)) diff --git a/pkg/payment/platform.go b/pkg/payment/platform.go index 9cc6af1..a460847 100644 --- a/pkg/payment/platform.go +++ b/pkg/payment/platform.go @@ -11,7 +11,6 @@ const ( Balance CryptoSaaS AppleIAP - ApplePay UNSUPPORTED Platform = -1 ) @@ -22,7 +21,6 @@ var platformNames = map[string]Platform{ "EPay": EPay, "balance": Balance, "AppleIAP": AppleIAP, - "ApplePay": ApplePay, "unsupported": UNSUPPORTED, } @@ -51,7 +49,7 @@ func GetSupportedPlatforms() []types.PlatformInfo { "public_key": "Publishable key", "secret_key": "Secret key", "webhook_secret": "Webhook secret", - "payment": "Payment Method, only supported card/alipay/wechat_pay", + "payment": "Payment Method, only supported card/alipay/wechat_pay/apple_pay", }, }, { @@ -94,14 +92,5 @@ func GetSupportedPlatforms() []types.PlatformInfo { "environment": "Environment: Sandbox/Production", }, }, - { - Platform: ApplePay.String(), - PlatformUrl: "https://stripe.com", - PlatformFieldDescription: map[string]string{ - "public_key": "Publishable key", - "secret_key": "Secret key", - "webhook_secret": "Webhook secret", - }, - }, } }