优化结构
This commit is contained in:
+8
-6
@@ -78,7 +78,7 @@ PayPal `AUTHORIZE` 意图后的授权捕获,以及账单、分账、转账等
|
||||
|
||||
| Provider | 实现方式 |
|
||||
| --- | --- |
|
||||
| `alipay`、`alipay-v3`、`wechat-v2`、`wechat-v3`、`apple-iap`、`paypal`、`douyin`、`qq`、`allinpay`、`lakala`、`saobei` | 统一走上面的 GoPay v1.5.122 adapter;业务层只接收 `biz.PaymentResult` |
|
||||
| `alipay`、`alipay-v3`、`wechat-v2`、`wechat-v3`、`apple-iap`、`paypal`、`douyin`、`qq`、`allinpay`、`lakala`、`saobei` | 统一走上面的 GoPay v1.5.122 adapter;业务层只接收 `paymentbiz.PaymentResult` |
|
||||
| `chinaums` | 配置驱动的银联商务 JSON 签名适配器 |
|
||||
| `sft` | 配置驱动的商福通 JSON/MD5 适配器 |
|
||||
| `supper-pay` | 配置驱动的 Supper Pay HMAC 适配器 |
|
||||
@@ -131,18 +131,20 @@ PayPal `AUTHORIZE` 意图后的授权捕获,以及账单、分账、转账等
|
||||
每个业务模块先实现可信订单来源:
|
||||
|
||||
```go
|
||||
import paymentbiz "kra/internal/biz/payment"
|
||||
|
||||
type GameItemPayment struct {
|
||||
orders GameItemOrderRepo
|
||||
}
|
||||
|
||||
func (GameItemPayment) Type() string { return "game_item" }
|
||||
|
||||
func (p GameItemPayment) PreparePayment(ctx context.Context, provider, tradeNo, businessID string) (*biz.PaymentIntent, error) {
|
||||
func (p GameItemPayment) PreparePayment(ctx context.Context, provider, tradeNo, businessID string) (*paymentbiz.PaymentIntent, error) {
|
||||
order, err := p.orders.FindPayable(ctx, businessID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &biz.PaymentIntent{
|
||||
return &paymentbiz.PaymentIntent{
|
||||
Provider: provider, TradeNo: tradeNo,
|
||||
BusinessType: "game_item", BusinessID: businessID,
|
||||
Subject: order.Title, Amount: order.PayableAmount, Currency: order.Currency,
|
||||
@@ -153,7 +155,7 @@ func (p GameItemPayment) PreparePayment(ctx context.Context, provider, tradeNo,
|
||||
然后注册按业务类型分发的发货处理器:
|
||||
|
||||
```go
|
||||
func (p GameItemPayment) Fulfill(ctx context.Context, c *biz.PaymentConfirmation) error {
|
||||
func (p GameItemPayment) Fulfill(ctx context.Context, c *paymentbiz.PaymentConfirmation) error {
|
||||
return p.orders.Transaction(ctx, func(tx GameItemOrderTx) error {
|
||||
// confirmation_id 必须有唯一约束。已处理时直接返回 nil。
|
||||
if tx.HasPaymentConfirmation(c.ID) {
|
||||
@@ -166,7 +168,7 @@ func (p GameItemPayment) Fulfill(ctx context.Context, c *biz.PaymentConfirmation
|
||||
})
|
||||
}
|
||||
|
||||
func (p GameItemPayment) AuthorizeRefund(ctx context.Context, order *biz.PaymentOrder, amount int64) error {
|
||||
func (p GameItemPayment) AuthorizeRefund(ctx context.Context, order *paymentbiz.PaymentOrder, amount int64) error {
|
||||
return p.orders.CheckRefundable(ctx, order.BusinessID, amount)
|
||||
}
|
||||
```
|
||||
@@ -405,4 +407,4 @@ Chinaums、SFT、Supper Pay、微信小游戏和抖音小游戏没有在代码
|
||||
|
||||
## 日志
|
||||
|
||||
支付日志在 `internal/biz/payment_log.go` 通过 `PaymentLogger` 独立抽象,包含下单、查单失败、回调查单、金额校验、重复回调和发货结果等结构化事件。日志只记录渠道、商户订单号、业务类型、业务 ID、确认 ID 等审计字段,不记录私钥、密钥、证书内容或完整敏感回调原文。
|
||||
支付日志在 `internal/biz/payment/payment_log.go` 通过 `PaymentLogger` 独立抽象,包含下单、查单失败、回调查单、金额校验、重复回调和发货结果等结构化事件。日志只记录渠道、商户订单号、业务类型、业务 ID、确认 ID 等审计字段,不记录私钥、密钥、证书内容或完整敏感回调原文。
|
||||
|
||||
Reference in New Issue
Block a user