优化结构
This commit is contained in:
@@ -182,6 +182,27 @@ type PaymentResult struct {
|
||||
FailureAck PaymentCallbackAck `json:"-"`
|
||||
}
|
||||
|
||||
// PaymentTestStage is one step of a provider connectivity test. A skipped
|
||||
// query/refund is reported explicitly because a prepay flow cannot be marked
|
||||
// paid without a sandbox payer interaction.
|
||||
type PaymentTestStage struct {
|
||||
Name string `json:"name"`
|
||||
Status string `json:"status"`
|
||||
Message string `json:"message,omitempty"`
|
||||
TradeNo string `json:"tradeNo,omitempty"`
|
||||
Duration int64 `json:"durationMs,omitempty"`
|
||||
}
|
||||
|
||||
type PaymentTestResult struct {
|
||||
Provider string `json:"provider"`
|
||||
TradeNo string `json:"tradeNo"`
|
||||
Passed bool `json:"passed"`
|
||||
FullFlow bool `json:"fullFlow"`
|
||||
Mode string `json:"mode,omitempty"`
|
||||
Stages []PaymentTestStage `json:"stages"`
|
||||
Result *PaymentResult `json:"result,omitempty"`
|
||||
}
|
||||
|
||||
type PaymentCallbackAck = paymentutil.CallbackAck
|
||||
type PaymentCallbackError = paymentutil.CallbackError
|
||||
|
||||
@@ -207,6 +228,10 @@ type PaymentRepo interface {
|
||||
HandleCallback(context.Context, *PaymentCallback) (*PaymentResult, error)
|
||||
}
|
||||
|
||||
type PaymentProviderTester interface {
|
||||
TestProvider(context.Context, string) (*PaymentTestResult, error)
|
||||
}
|
||||
|
||||
type PaymentHooks interface {
|
||||
BeforeCreate(context.Context, *PaymentRequest) error
|
||||
}
|
||||
@@ -477,6 +502,21 @@ func (uc *PaymentUsecase) Refund(ctx context.Context, provider, tradeNo string,
|
||||
return uc.refundWithOrder(ctx, provider, tradeNo, amount)
|
||||
}
|
||||
|
||||
// TestProvider exercises the configured provider without requiring a business
|
||||
// module or a real customer order. Provider adapters use their configured
|
||||
// sandbox/test endpoint when one is selected in integration settings.
|
||||
func (uc *PaymentUsecase) TestProvider(ctx context.Context, provider string) (*PaymentTestResult, error) {
|
||||
provider = strings.TrimSpace(provider)
|
||||
if !supportedPaymentProvider(provider) {
|
||||
return nil, errors.New("不支持的支付渠道")
|
||||
}
|
||||
tester, ok := uc.repo.(PaymentProviderTester)
|
||||
if !ok {
|
||||
return nil, errors.New("支付渠道仓储未接入")
|
||||
}
|
||||
return tester.TestProvider(ctx, provider)
|
||||
}
|
||||
|
||||
// Fulfill retries delivery for an already-paid order. It is intentionally
|
||||
// idempotent: the repository lease prevents concurrent attempts and a
|
||||
// succeeded order is returned as a duplicate without invoking the handler.
|
||||
|
||||
Reference in New Issue
Block a user