2023-07-26 03:06:05 +00:00
|
|
|
package pay
|
|
|
|
|
|
|
|
import "fusenapi/constants"
|
|
|
|
|
|
|
|
type Config struct {
|
|
|
|
// stripe支付
|
2023-11-02 07:58:13 +00:00
|
|
|
Stripe Stripe `json:"stripe"`
|
2023-07-26 03:06:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// NewPayDriver 实例化方法
|
|
|
|
func NewPayDriver(PayMethod int64, config *Config) Pay {
|
|
|
|
switch PayMethod {
|
|
|
|
case int64(constants.PAYMETHOD_STRIPE):
|
2023-09-21 11:01:48 +00:00
|
|
|
return &Stripe{Key: config.Stripe.Key, PayType: config.Stripe.PayType}
|
2023-07-26 03:06:05 +00:00
|
|
|
default:
|
2023-09-21 11:01:48 +00:00
|
|
|
return &Stripe{Key: config.Stripe.Key, PayType: config.Stripe.PayType}
|
2023-07-26 03:06:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// Pay 支付集成接口
|
|
|
|
type Pay interface {
|
2023-07-28 11:03:36 +00:00
|
|
|
|
|
|
|
// 支付预处理
|
2023-07-26 03:06:05 +00:00
|
|
|
GeneratePrepayment(req *GeneratePrepaymentReq) (res *GeneratePrepaymentRes, err error)
|
2023-07-28 11:03:36 +00:00
|
|
|
|
|
|
|
// 支付退款申请
|
|
|
|
PayRefund(req *PayRefundReq) (res *PayRefundRes, err error)
|
2023-07-26 03:06:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type GeneratePrepaymentReq struct {
|
2023-09-22 08:27:17 +00:00
|
|
|
Metadata map[string]string `json:"metadata"` // 元数据
|
|
|
|
Amount int64 `json:"amount"` // 支付金额
|
|
|
|
Currency string `json:"currency"` // 支付货币
|
|
|
|
ProductName string `json:"product_name"` // 商品名称
|
|
|
|
ProductDescription string `json:"product_description"` // 商品描述
|
|
|
|
ProductImages []*string `json:"product_imageso"` // 商品照片
|
|
|
|
Quantity int64 `json:"quantity"` //数量
|
|
|
|
SuccessURL string `json:"success_url"` // 支付成功回调
|
|
|
|
CancelURL string `json:"cancel_url"` // 支付取消回调
|
2023-07-26 03:06:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type GeneratePrepaymentRes struct {
|
2023-07-28 03:15:42 +00:00
|
|
|
URL string `json:"url"` // 支付重定向地址
|
|
|
|
TradeNo string `json:"trade_no"` //交易ID
|
|
|
|
ClientSecret string `json:"clientSecret"` //交易密钥
|
|
|
|
SessionId string `json:"session_id"` //SessionId
|
2023-07-26 03:06:05 +00:00
|
|
|
}
|
2023-07-28 11:03:36 +00:00
|
|
|
|
|
|
|
type PayRefundReq struct {
|
|
|
|
TradeNo string `json:"trade_no"` // 交易编号
|
|
|
|
}
|
|
|
|
|
|
|
|
type PayRefundRes struct {
|
|
|
|
}
|