支持拉卡拉多渠道支付和测试充值
This commit is contained in:
@@ -1,6 +1,9 @@
|
||||
package payment
|
||||
|
||||
import "errors"
|
||||
import (
|
||||
"errors"
|
||||
"strings"
|
||||
)
|
||||
|
||||
var (
|
||||
ErrDependencyUnavailable = errors.New("dependency unavailable")
|
||||
@@ -15,11 +18,19 @@ var (
|
||||
const MinWalletRechargeAmount = 0.01
|
||||
|
||||
type Service struct {
|
||||
repo *Repository
|
||||
repo *Repository
|
||||
walletRechargeEnabled bool
|
||||
}
|
||||
|
||||
func NewService(repo *Repository) *Service {
|
||||
return &Service{repo: repo}
|
||||
func NewService(repo *Repository, appEnv ...string) *Service {
|
||||
env := "production"
|
||||
if len(appEnv) > 0 {
|
||||
env = strings.ToLower(strings.TrimSpace(appEnv[0]))
|
||||
}
|
||||
return &Service{
|
||||
repo: repo,
|
||||
walletRechargeEnabled: env != "production",
|
||||
}
|
||||
}
|
||||
|
||||
func (s *Service) Start(userID uint64, orderID uint64, req StartPaymentRequest, clientIP string) (*PaymentDTO, error) {
|
||||
@@ -46,7 +57,10 @@ func (s *Service) StartWalletRecharge(userID uint64, req WalletRechargePaymentRe
|
||||
if s.repo == nil {
|
||||
return nil, ErrDependencyUnavailable
|
||||
}
|
||||
return nil, ErrWalletRechargeDisabled
|
||||
if !s.walletRechargeEnabled {
|
||||
return nil, ErrWalletRechargeDisabled
|
||||
}
|
||||
return s.repo.StartWalletRecharge(userID, req, clientIP)
|
||||
}
|
||||
|
||||
func (s *Service) QueryWalletRecharge(userID uint64, paymentID uint64) (*PaymentDTO, error) {
|
||||
@@ -66,6 +80,13 @@ func (s *Service) HandleLeshuaNotify(params map[string]string, rawPayload string
|
||||
return s.repo.HandleLeshuaNotify(params, rawPayload, contentType)
|
||||
}
|
||||
|
||||
func (s *Service) HandleNotify(provider string, params map[string]string, rawPayload string, contentType string, authorization string) (*NotifyResult, error) {
|
||||
if s.repo == nil {
|
||||
return nil, ErrDependencyUnavailable
|
||||
}
|
||||
return s.repo.HandleNotify(provider, params, rawPayload, contentType, authorization)
|
||||
}
|
||||
|
||||
func (s *Service) StartRefund(orderID uint64, refundAmountCent int64, bizType string, remark string) (*RefundDTO, error) {
|
||||
if s.repo == nil {
|
||||
return nil, ErrDependencyUnavailable
|
||||
|
||||
Reference in New Issue
Block a user