Skip to content

Commit 035700d

Browse files
committed
update
1 parent 3b7fd4d commit 035700d

File tree

11 files changed

+93
-101
lines changed

11 files changed

+93
-101
lines changed

base.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import (
55
"github.com/webx-top/payment/config"
66
)
77

8-
var _ Hook = New()
8+
var _ Driver = New()
99

1010
func New() *Base {
1111
return &Base{}
@@ -20,12 +20,12 @@ func (a *Base) IsSupported(s config.Support) bool {
2020
return false
2121
}
2222

23-
func (a *Base) SetNotifyCallback(callback func(echo.Context) error) Hook {
23+
func (a *Base) SetNotifyCallback(callback func(echo.Context) error) Driver {
2424
a.NotifyCallback = callback
2525
return a
2626
}
2727

28-
func (a *Base) SetAccount(account *config.Account) Hook {
28+
func (a *Base) SetAccount(account *config.Account) Driver {
2929
a.Account = account
3030
return a
3131
}
@@ -35,7 +35,7 @@ func (a *Base) Pay(ctx echo.Context, cfg *config.Pay) (*config.PayResponse, erro
3535
}
3636

3737
// PayNotify 付款回调处理
38-
//! *务必在内部验证签名*
38+
// ! *务必在内部验证签名*
3939
func (a *Base) PayNotify(ctx echo.Context) error {
4040
return config.ErrUnsupported
4141
}
@@ -49,7 +49,7 @@ func (a *Base) Refund(ctx echo.Context, cfg *config.Refund) (*config.Result, err
4949
}
5050

5151
// RefundNotify 退款回调处理
52-
//! *务必在内部验证签名*
52+
// ! *务必在内部验证签名*
5353
func (a *Base) RefundNotify(ctx echo.Context) error {
5454
return config.ErrUnsupported
5555
}

driver/alipay/alipay.go

Lines changed: 33 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ func init() {
2929
payment.Register(Name, `支付宝`, New)
3030
}
3131

32-
func New() payment.Hook {
32+
func New() payment.Driver {
3333
return &Alipay{}
3434
}
3535

@@ -43,12 +43,12 @@ func (a *Alipay) IsSupported(s config.Support) bool {
4343
return supports.IsSupported(s)
4444
}
4545

46-
func (a *Alipay) SetNotifyCallback(callback func(echo.Context) error) payment.Hook {
46+
func (a *Alipay) SetNotifyCallback(callback func(echo.Context) error) payment.Driver {
4747
a.notifyCallback = callback
4848
return a
4949
}
5050

51-
func (a *Alipay) SetAccount(account *config.Account) payment.Hook {
51+
func (a *Alipay) SetAccount(account *config.Account) payment.Driver {
5252
a.account = account
5353
return a
5454
}
@@ -108,12 +108,12 @@ func (a *Alipay) Pay(ctx echo.Context, cfg *config.Pay) (*config.PayResponse, er
108108
return result, err
109109
}
110110
if !results.IsSuccess() {
111-
if len(results.Content.SubMsg) > 0 {
112-
results.Content.Msg += `: ` + results.Content.SubMsg
111+
if len(results.SubMsg) > 0 {
112+
results.Msg += `: ` + results.SubMsg
113113
}
114-
return nil, errors.New(results.Content.Msg)
114+
return nil, errors.New(results.Msg)
115115
}
116-
result.QRCodeContent = results.Content.QRCode
116+
result.QRCodeContent = results.QRCode
117117
result.Raw = results
118118
return result, err
119119
}
@@ -204,20 +204,20 @@ func (a *Alipay) PayQuery(ctx echo.Context, cfg *config.Query) (*config.Result,
204204
return nil, err
205205
}
206206
if !resp.IsSuccess() {
207-
if len(resp.Content.SubMsg) > 0 {
208-
resp.Content.Msg += `: ` + resp.Content.SubMsg
207+
if len(resp.SubMsg) > 0 {
208+
resp.Msg += `: ` + resp.SubMsg
209209
}
210-
return nil, errors.New(resp.Content.Msg)
210+
return nil, errors.New(resp.Msg)
211211
}
212212

213213
return &config.Result{
214214
Operation: config.OperationPayment,
215-
Status: string(resp.Content.TradeStatus),
216-
TradeNo: resp.Content.TradeNo,
217-
OutTradeNo: resp.Content.OutTradeNo,
218-
Currency: resp.Content.PayCurrency,
219-
TotalAmount: param.AsFloat64(resp.Content.TotalAmount),
220-
Reason: resp.Content.SubMsg,
215+
Status: string(resp.TradeStatus),
216+
TradeNo: resp.TradeNo,
217+
OutTradeNo: resp.OutTradeNo,
218+
Currency: resp.PayCurrency,
219+
TotalAmount: param.AsFloat64(resp.TotalAmount),
220+
Reason: resp.SubMsg,
221221
Raw: resp,
222222
}, err
223223
}
@@ -229,14 +229,6 @@ func (a *Alipay) Refund(ctx echo.Context, cfg *config.Refund) (*config.Result, e
229229
RefundAmount: MoneyFeeToString(cfg.RefundAmount),
230230
RefundReason: cfg.RefundReason,
231231
OutRequestNo: cfg.OutRefundNo,
232-
OperatorId: ``, // 可选 商户的操作员编号
233-
StoreId: ``, // 可选 商户的门店编号
234-
TerminalId: ``, // 可选 商户的终端编号
235-
}
236-
if cfg.Options != nil {
237-
refundConfig.OperatorId = cfg.Options.String(`operatorId`)
238-
refundConfig.StoreId = cfg.Options.String(`storeId`)
239-
refundConfig.TerminalId = cfg.Options.String(`terminalId`)
240232
}
241233
if len(refundConfig.OutRequestNo) == 0 {
242234
refundConfig.OutRequestNo = fmt.Sprintf("%d%d", time.Now().Local().Unix(), rand.Intn(9999))
@@ -246,20 +238,20 @@ func (a *Alipay) Refund(ctx echo.Context, cfg *config.Refund) (*config.Result, e
246238
return nil, err
247239
}
248240
if !resp.IsSuccess() {
249-
if len(resp.Content.SubMsg) > 0 {
250-
resp.Content.Msg += `: ` + resp.Content.SubMsg
241+
if len(resp.SubMsg) > 0 {
242+
resp.Msg += `: ` + resp.SubMsg
251243
}
252-
return nil, errors.New(resp.Content.Msg)
244+
return nil, errors.New(resp.Msg)
253245
}
254246
return &config.Result{
255247
Operation: config.OperationRefund,
256248
Status: config.TradeStatusSuccess,
257-
TradeNo: resp.Content.TradeNo,
258-
OutTradeNo: resp.Content.OutTradeNo,
249+
TradeNo: resp.TradeNo,
250+
OutTradeNo: resp.OutTradeNo,
259251
Currency: ``,
260252
TotalAmount: 0,
261-
Reason: resp.Content.SubMsg,
262-
RefundFee: param.AsFloat64(resp.Content.RefundFee),
253+
Reason: resp.SubMsg,
254+
RefundFee: param.AsFloat64(resp.RefundFee),
263255
OutRefundNo: cfg.OutRefundNo,
264256
Raw: resp,
265257
}, err
@@ -314,13 +306,13 @@ func (a *Alipay) RefundQuery(ctx echo.Context, cfg *config.Query) (*config.Resul
314306
return nil, err
315307
}
316308
if !resp.IsSuccess() {
317-
if len(resp.Content.SubMsg) > 0 {
318-
resp.Content.Msg += `: ` + resp.Content.SubMsg
309+
if len(resp.SubMsg) > 0 {
310+
resp.Msg += `: ` + resp.SubMsg
319311
}
320-
return nil, errors.New(resp.Content.Msg)
312+
return nil, errors.New(resp.Msg)
321313
}
322314
var status string
323-
switch resp.Content.RefundStatus {
315+
switch resp.RefundStatus {
324316
case `REFUND_SUCCESS`:
325317
status = config.TradeStatusSuccess
326318
case `REFUND_FAIL`:
@@ -333,13 +325,13 @@ func (a *Alipay) RefundQuery(ctx echo.Context, cfg *config.Query) (*config.Resul
333325
return &config.Result{
334326
Operation: config.OperationRefund,
335327
Status: status,
336-
TradeNo: resp.Content.TradeNo,
337-
OutTradeNo: resp.Content.OutTradeNo,
328+
TradeNo: resp.TradeNo,
329+
OutTradeNo: resp.OutTradeNo,
338330
Currency: ``,
339-
TotalAmount: param.AsFloat64(resp.Content.TotalAmount),
340-
Reason: resp.Content.SubMsg,
341-
RefundFee: param.AsFloat64(resp.Content.RefundAmount),
342-
OutRefundNo: resp.Content.OutRequestNo,
331+
TotalAmount: param.AsFloat64(resp.TotalAmount),
332+
Reason: resp.SubMsg,
333+
RefundFee: param.AsFloat64(resp.RefundAmount),
334+
OutRefundNo: resp.OutRequestNo,
343335
Raw: resp,
344336
}, err
345337
}

driver/alipay/helpers.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package alipay
22

33
import (
4+
"fmt"
45
"net/url"
56

67
alipay "github.com/admpub/alipay/v3"
@@ -15,12 +16,9 @@ func (a *Alipay) VerifySign(ctx echo.Context) error {
1516
}
1617

1718
func (a *Alipay) verifySign(req url.Values) error {
18-
ok, err := a.Client().VerifySign(req)
19+
err := a.Client().VerifySign(req)
1920
if err != nil {
20-
return err
21-
}
22-
if !ok {
23-
return config.ErrSignature
21+
return fmt.Errorf(`%w: %v`, config.ErrSignature, err)
2422
}
2523
return nil
2624
}

driver/epusdt/epusdt.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ func init() {
3131
payment.Register(Name, `USDT`, New)
3232
}
3333

34-
func New() payment.Hook {
34+
func New() payment.Driver {
3535
return &EPUSDT{}
3636
}
3737

@@ -45,12 +45,12 @@ func (a *EPUSDT) IsSupported(s config.Support) bool {
4545
return supports.IsSupported(s)
4646
}
4747

48-
func (a *EPUSDT) SetNotifyCallback(callback func(echo.Context) error) payment.Hook {
48+
func (a *EPUSDT) SetNotifyCallback(callback func(echo.Context) error) payment.Driver {
4949
a.notifyCallback = callback
5050
return a
5151
}
5252

53-
func (a *EPUSDT) SetAccount(account *config.Account) payment.Hook {
53+
func (a *EPUSDT) SetAccount(account *config.Account) payment.Driver {
5454
a.account = account
5555
a.apiURL = strings.TrimSuffix(account.Options.Extra.String(`apiURL`), `/`)
5656
return a

driver/mugglepay/mugglepay.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ func init() {
2525
payment.Register(Name, `麻瓜宝`, New)
2626
}
2727

28-
func New() payment.Hook {
28+
func New() payment.Driver {
2929
return &Mugglepay{}
3030
}
3131

@@ -39,12 +39,12 @@ func (a *Mugglepay) IsSupported(s config.Support) bool {
3939
return supports.IsSupported(s)
4040
}
4141

42-
func (a *Mugglepay) SetNotifyCallback(callback func(echo.Context) error) payment.Hook {
42+
func (a *Mugglepay) SetNotifyCallback(callback func(echo.Context) error) payment.Driver {
4343
a.notifyCallback = callback
4444
return a
4545
}
4646

47-
func (a *Mugglepay) SetAccount(account *config.Account) payment.Hook {
47+
func (a *Mugglepay) SetAccount(account *config.Account) payment.Driver {
4848
a.account = account
4949
return a
5050
}

driver/payjs/payjs.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ func init() {
2323
payment.Register(Name, `PayJS支付`, New)
2424
}
2525

26-
func New() payment.Hook {
26+
func New() payment.Driver {
2727
return &PayJS{}
2828
}
2929

@@ -37,12 +37,12 @@ func (a *PayJS) IsSupported(s config.Support) bool {
3737
return supports.IsSupported(s)
3838
}
3939

40-
func (a *PayJS) SetNotifyCallback(callback func(echo.Context) error) payment.Hook {
40+
func (a *PayJS) SetNotifyCallback(callback func(echo.Context) error) payment.Driver {
4141
a.notifyCallback = callback
4242
return a
4343
}
4444

45-
func (a *PayJS) SetAccount(account *config.Account) payment.Hook {
45+
func (a *PayJS) SetAccount(account *config.Account) payment.Driver {
4646
a.account = account
4747
return a
4848
}

driver/paypal/paypal.go

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ func init() {
2222
payment.Register(Name, `贝宝`, New)
2323
}
2424

25-
func New() payment.Hook {
25+
func New() payment.Driver {
2626
return &Paypal{}
2727
}
2828

@@ -36,12 +36,12 @@ func (a *Paypal) IsSupported(s config.Support) bool {
3636
return supports.IsSupported(s)
3737
}
3838

39-
func (a *Paypal) SetNotifyCallback(callback func(echo.Context) error) payment.Hook {
39+
func (a *Paypal) SetNotifyCallback(callback func(echo.Context) error) payment.Driver {
4040
a.notifyCallback = callback
4141
return a
4242
}
4343

44-
func (a *Paypal) SetAccount(account *config.Account) payment.Hook {
44+
func (a *Paypal) SetAccount(account *config.Account) payment.Driver {
4545
a.account = account
4646
return a
4747
}
@@ -60,9 +60,9 @@ func (a *Paypal) Client() *paypal.Client {
6060

6161
func (a *Paypal) Pay(ctx echo.Context, cfg *config.Pay) (*config.PayResponse, error) {
6262
var p = &paypal.Payment{}
63-
p.Intent = paypal.K_PAYMENT_INTENT_SALE
63+
p.Intent = paypal.PaymentIntentSale
6464
p.Payer = &paypal.Payer{}
65-
p.Payer.PaymentMethod = paypal.K_PAYMENT_METHOD_PAYPAL
65+
p.Payer.PaymentMethod = paypal.PaymentMethodPayPal
6666
p.RedirectURLs = &paypal.RedirectURLs{}
6767
p.RedirectURLs.CancelURL = cfg.CancelURL
6868
p.RedirectURLs.ReturnURL = cfg.ReturnURL
@@ -110,7 +110,7 @@ func (a *Paypal) PayQuery(ctx echo.Context, cfg *config.Query) (*config.Result,
110110
transactionFeeValue string // 交易手续费金额
111111
transactionFeeCurrency string // 交易手续费币种
112112
)
113-
if payment.State == paypal.K_PAYMENT_STATE_APPROVED {
113+
if payment.State == paypal.PaymentStateApproved {
114114
paid = true
115115
}
116116
for _, transaction := range payment.Transactions {
@@ -122,7 +122,7 @@ func (a *Paypal) PayQuery(ctx echo.Context, cfg *config.Query) (*config.Result,
122122
currency = resource.Sale.Amount.Currency
123123
transactionFeeValue = resource.Sale.TransactionFee.Value
124124
transactionFeeCurrency = resource.Sale.TransactionFee.Currency
125-
if resource.Sale.State != paypal.K_SALE_STATE_COMPLETED {
125+
if resource.Sale.State != paypal.SaleStateCompleted {
126126
paid = false
127127
break
128128
}
@@ -158,7 +158,7 @@ func (a *Paypal) PayNotify(ctx echo.Context) error {
158158
return nil
159159
}
160160
switch event.EventType {
161-
case paypal.K_EVENT_TYPE_PAYMENT_SALE_COMPLETED:
161+
case paypal.EventTypePaymentSaleCompleted:
162162
sale := event.Sale()
163163
if a.notifyCallback != nil {
164164
var reason, sep string
@@ -186,7 +186,7 @@ func (a *Paypal) PayNotify(ctx echo.Context) error {
186186
return err
187187
}
188188
}
189-
case paypal.K_EVENT_TYPE_PAYMENT_SALE_REFUNDED:
189+
case paypal.EventTypePaymentSaleRefunded:
190190
refund := event.Refund()
191191
if len(refund.Description) > 0 {
192192
refund.Reason += "; " + refund.Description
@@ -235,13 +235,13 @@ func (a *Paypal) Refund(ctx echo.Context, cfg *config.Refund) (*config.Result, e
235235
}
236236
var status string
237237
switch refund.State {
238-
case paypal.K_REFUND_STATE_COMPLETED:
238+
case paypal.RefundStateCompleted:
239239
status = config.TradeStatusSuccess
240-
case paypal.K_REFUND_STATE_CANCELLED:
240+
case paypal.RefundStateCancelled:
241241
status = config.TradeStatusClosed
242-
case paypal.K_REFUND_STATE_FAILED:
242+
case paypal.RefundStateFailed:
243243
status = config.TradeStatusException
244-
case paypal.K_REFUND_STATE_PENDING:
244+
case paypal.RefundStatePending:
245245
status = config.TradeStatusProcessing
246246
}
247247
return &config.Result{
@@ -267,13 +267,13 @@ func (a *Paypal) RefundQuery(ctx echo.Context, cfg *config.Query) (*config.Resul
267267
}
268268
var status string
269269
switch refund.State {
270-
case paypal.K_REFUND_STATE_COMPLETED:
270+
case paypal.RefundStateCompleted:
271271
status = config.TradeStatusSuccess
272-
case paypal.K_REFUND_STATE_CANCELLED:
272+
case paypal.RefundStateCancelled:
273273
status = config.TradeStatusClosed
274-
case paypal.K_REFUND_STATE_FAILED:
274+
case paypal.RefundStateFailed:
275275
status = config.TradeStatusException
276-
case paypal.K_REFUND_STATE_PENDING:
276+
case paypal.RefundStatePending:
277277
status = config.TradeStatusProcessing
278278
}
279279
return &config.Result{

0 commit comments

Comments
 (0)