fix:调整支付方式
This commit is contained in:
parent
48a6ae9888
commit
1a6822da64
@ -3,12 +3,14 @@ package pay
|
|||||||
import (
|
import (
|
||||||
"github.com/stripe/stripe-go/v74"
|
"github.com/stripe/stripe-go/v74"
|
||||||
"github.com/stripe/stripe-go/v74/checkout/session"
|
"github.com/stripe/stripe-go/v74/checkout/session"
|
||||||
|
"github.com/stripe/stripe-go/v74/paymentintent"
|
||||||
"github.com/stripe/stripe-go/v74/refund"
|
"github.com/stripe/stripe-go/v74/refund"
|
||||||
"github.com/zeromicro/go-zero/core/logx"
|
"github.com/zeromicro/go-zero/core/logx"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Stripe struct {
|
type Stripe struct {
|
||||||
Key string `json:"key"`
|
Key string `json:"key"`
|
||||||
|
PayType string `json:"pay_type"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// 生成退款
|
// 生成退款
|
||||||
@ -43,7 +45,9 @@ func (stripePay *Stripe) GeneratePrepayment(req *GeneratePrepaymentReq) (res *Ge
|
|||||||
// images[0] = stripe.String(image)
|
// images[0] = stripe.String(image)
|
||||||
// productData.Images = images
|
// productData.Images = images
|
||||||
stripe.Key = stripePay.Key
|
stripe.Key = stripePay.Key
|
||||||
|
var resultPayment resultPayment
|
||||||
|
switch stripePay.PayType {
|
||||||
|
case "session":
|
||||||
// session 方式
|
// session 方式
|
||||||
params := &stripe.CheckoutSessionParams{
|
params := &stripe.CheckoutSessionParams{
|
||||||
PaymentIntentData: &stripe.CheckoutSessionPaymentIntentDataParams{Metadata: map[string]string{"order_sn": req.OrderSn}},
|
PaymentIntentData: &stripe.CheckoutSessionPaymentIntentDataParams{Metadata: map[string]string{"order_sn": req.OrderSn}},
|
||||||
@ -66,26 +70,45 @@ func (stripePay *Stripe) GeneratePrepayment(req *GeneratePrepaymentReq) (res *Ge
|
|||||||
SuccessURL: stripe.String(req.SuccessURL),
|
SuccessURL: stripe.String(req.SuccessURL),
|
||||||
CancelURL: stripe.String(req.CancelURL),
|
CancelURL: stripe.String(req.CancelURL),
|
||||||
}
|
}
|
||||||
result, err := session.New(params)
|
resCheckoutSession, err := session.New(params)
|
||||||
|
|
||||||
// 密钥方式
|
|
||||||
// params := &stripe.PaymentIntentParams{
|
|
||||||
// Amount: stripe.Int64(req.Amount),
|
|
||||||
// Currency: stripe.String(string(req.Currency)),
|
|
||||||
// AutomaticPaymentMethods: &stripe.PaymentIntentAutomaticPaymentMethodsParams{
|
|
||||||
// Enabled: stripe.Bool(true),
|
|
||||||
// },
|
|
||||||
// }
|
|
||||||
// result, err := paymentintent.New(params)
|
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
resultPayment.Url = resCheckoutSession.URL
|
||||||
|
resultPayment.SessionId = resCheckoutSession.ID
|
||||||
|
case "intent":
|
||||||
|
// 密钥方式
|
||||||
|
params := &stripe.PaymentIntentParams{
|
||||||
|
Amount: stripe.Int64(req.Amount),
|
||||||
|
Currency: stripe.String(string(req.Currency)),
|
||||||
|
AutomaticPaymentMethods: &stripe.PaymentIntentAutomaticPaymentMethodsParams{
|
||||||
|
Enabled: stripe.Bool(true),
|
||||||
|
},
|
||||||
|
PaymentMethodTypes: stripe.StringSlice([]string{
|
||||||
|
"card",
|
||||||
|
// "ideal",
|
||||||
|
}),
|
||||||
|
}
|
||||||
|
resPaymentintent, err := paymentintent.New(params)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
resultPayment.TradeNo = resPaymentintent.ID
|
||||||
|
resultPayment.ClientSecret = resPaymentintent.ClientSecret
|
||||||
|
default:
|
||||||
|
}
|
||||||
|
|
||||||
return &GeneratePrepaymentRes{
|
return &GeneratePrepaymentRes{
|
||||||
URL: result.URL,
|
URL: resultPayment.Url,
|
||||||
//TradeNo: result.ID,
|
SessionId: resultPayment.SessionId,
|
||||||
SessionId: result.ID,
|
TradeNo: resultPayment.TradeNo,
|
||||||
// ClientSecret: result.ClientSecret,
|
ClientSecret: resultPayment.ClientSecret,
|
||||||
}, err
|
}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type resultPayment struct {
|
||||||
|
Url string
|
||||||
|
SessionId string
|
||||||
|
TradeNo string
|
||||||
|
ClientSecret string
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user