diff --git a/controller/subscription_payment_epay.go b/controller/subscription_payment_epay.go index 8b613dcd4..a328436a0 100644 --- a/controller/subscription_payment_epay.go +++ b/controller/subscription_payment_epay.go @@ -81,20 +81,6 @@ func SubscriptionRequestEpay(c *gin.Context) { return } - uri, params, err := client.Purchase(&epay.PurchaseArgs{ - Type: req.PaymentMethod, - ServiceTradeNo: tradeNo, - Name: fmt.Sprintf("SUB:%s", plan.Title), - Money: strconv.FormatFloat(plan.PriceAmount, 'f', 2, 64), - Device: epay.PC, - NotifyUrl: notifyUrl, - ReturnUrl: returnUrl, - }) - if err != nil { - common.ApiErrorMsg(c, "拉起支付失败") - return - } - order := &model.SubscriptionOrder{ UserId: userId, PlanId: plan.Id, @@ -108,6 +94,20 @@ func SubscriptionRequestEpay(c *gin.Context) { common.ApiErrorMsg(c, "创建订单失败") return } + uri, params, err := client.Purchase(&epay.PurchaseArgs{ + Type: req.PaymentMethod, + ServiceTradeNo: tradeNo, + Name: fmt.Sprintf("SUB:%s", plan.Title), + Money: strconv.FormatFloat(plan.PriceAmount, 'f', 2, 64), + Device: epay.PC, + NotifyUrl: notifyUrl, + ReturnUrl: returnUrl, + }) + if err != nil { + _ = model.ExpireSubscriptionOrder(tradeNo) + common.ApiErrorMsg(c, "拉起支付失败") + return + } c.JSON(http.StatusOK, gin.H{"message": "success", "data": params, "url": uri}) }