支付成功回调
This commit is contained in:
@@ -24,6 +24,7 @@ type Pay interface {
|
||||
}
|
||||
|
||||
type GeneratePrepaymentReq struct {
|
||||
OrderSn string `json:"order_sn"` // 订单编号
|
||||
Amount int64 `json:"amount"` // 支付金额
|
||||
Currency string `json:"currency"` // 支付货币
|
||||
ProductName string `json:"product_name"` // 商品名称
|
||||
@@ -35,6 +36,8 @@ type GeneratePrepaymentReq struct {
|
||||
}
|
||||
|
||||
type GeneratePrepaymentRes struct {
|
||||
URL string `json:"url"` // 支付重定向地址
|
||||
TradeNo string `json:"trade_no"` //交易ID
|
||||
URL string `json:"url"` // 支付重定向地址
|
||||
TradeNo string `json:"trade_no"` //交易ID
|
||||
ClientSecret string `json:"clientSecret"` //交易密钥
|
||||
SessionId string `json:"session_id"` //SessionId
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@ type Stripe struct {
|
||||
// 生成预付款
|
||||
func (stripePay *Stripe) GeneratePrepayment(req *GeneratePrepaymentReq) (res *GeneratePrepaymentRes, err error) {
|
||||
var productData stripe.CheckoutSessionLineItemPriceDataProductDataParams
|
||||
// productData.Metadata = map[string]string{"order_id": "33333333333333"}
|
||||
|
||||
if req.ProductName != "" {
|
||||
productData.Name = stripe.String(req.ProductName)
|
||||
@@ -30,7 +31,14 @@ func (stripePay *Stripe) GeneratePrepayment(req *GeneratePrepaymentReq) (res *Ge
|
||||
// productData.Images = images
|
||||
stripe.Key = stripePay.Key
|
||||
|
||||
// session 方式
|
||||
params := &stripe.CheckoutSessionParams{
|
||||
PaymentIntentData: &stripe.CheckoutSessionPaymentIntentDataParams{Metadata: map[string]string{"order_sn": req.OrderSn}},
|
||||
// Params: stripe.Params{Metadata: map[string]string{"order_id": "1111111111111"}},
|
||||
PaymentMethodTypes: stripe.StringSlice([]string{
|
||||
"card",
|
||||
// "ideal",
|
||||
}),
|
||||
LineItems: []*stripe.CheckoutSessionLineItemParams{
|
||||
{
|
||||
PriceData: &stripe.CheckoutSessionLineItemPriceDataParams{
|
||||
@@ -47,12 +55,24 @@ func (stripePay *Stripe) GeneratePrepayment(req *GeneratePrepaymentReq) (res *Ge
|
||||
}
|
||||
result, 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 {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &GeneratePrepaymentRes{
|
||||
URL: result.URL,
|
||||
TradeNo: result.ID,
|
||||
URL: result.URL,
|
||||
//TradeNo: result.ID,
|
||||
SessionId: result.ID,
|
||||
// ClientSecret: result.ClientSecret,
|
||||
}, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user