Skip to content

Commit

Permalink
refactor(payment): 重构支付模块 (#120)
Browse files Browse the repository at this point in the history
* 完成微信回调支付通知接口及其测试
* 支付模块集成到app,注册回调handler
  • Loading branch information
longyue0521 authored Apr 28, 2024
1 parent be8680f commit 08cdcf2
Show file tree
Hide file tree
Showing 23 changed files with 2,236 additions and 1,048 deletions.
4 changes: 2 additions & 2 deletions internal/order/internal/event/consumer.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,10 @@ func (c *PaymentConsumer) Consume(ctx context.Context) error {
}

var warnMessage string
if evt.Status == uint8(payment.PaymentStatusPaid) {
if evt.Status == uint8(payment.StatusPaidSuccess) {
err = c.svc.SucceedOrder(ctx, order.BuyerID, order.ID)
warnMessage = "设置订单'支付成功'状态失败"
} else if evt.Status == uint8(payment.PaymentStatusFailed) {
} else if evt.Status == uint8(payment.StatusFailed) {
err = c.svc.FailOrder(ctx, order.BuyerID, order.ID)
warnMessage = "设置订单'支付失败'状态失败"
} else {
Expand Down
16 changes: 8 additions & 8 deletions internal/order/internal/integration/module_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2043,7 +2043,7 @@ func (s *OrderModuleTestSuite) TestPaymentConsumer_Consume() {
evt: event.PaymentEvent{
OrderSN: "orderSN-22",
PayerID: testUID,
Status: uint8(payment.PaymentStatusPaid),
Status: uint8(payment.StatusPaidSuccess),
},
after: func(t *testing.T, orderSN string) {
t.Helper()
Expand All @@ -2065,7 +2065,7 @@ func (s *OrderModuleTestSuite) TestPaymentConsumer_Consume() {
evt: event.PaymentEvent{
OrderSN: "",
PayerID: testUID,
Status: uint8(payment.PaymentStatusPaid),
Status: uint8(payment.StatusPaidSuccess),
},
after: func(t *testing.T, orderSN string) {},
errRequireFunc: require.Error,
Expand All @@ -2082,7 +2082,7 @@ func (s *OrderModuleTestSuite) TestPaymentConsumer_Consume() {
evt: event.PaymentEvent{
OrderSN: "InvalidOrderSN",
PayerID: testUID,
Status: uint8(payment.PaymentStatusPaid),
Status: uint8(payment.StatusPaidSuccess),
},
after: func(t *testing.T, orderSN string) {},
errRequireFunc: require.Error,
Expand All @@ -2099,7 +2099,7 @@ func (s *OrderModuleTestSuite) TestPaymentConsumer_Consume() {
evt: event.PaymentEvent{
OrderSN: "OrderSN-3",
PayerID: 0,
Status: uint8(payment.PaymentStatusPaid),
Status: uint8(payment.StatusPaidSuccess),
},
after: func(t *testing.T, orderSN string) {},
errRequireFunc: require.Error,
Expand Down Expand Up @@ -2137,7 +2137,7 @@ func (s *OrderModuleTestSuite) TestPaymentConsumer_Consume() {
evt: event.PaymentEvent{
OrderSN: "orderSN-23",
PayerID: testUID,
Status: uint8(payment.PaymentStatusFailed),
Status: uint8(payment.StatusFailed),
},
after: func(t *testing.T, orderSN string) {
t.Helper()
Expand All @@ -2159,7 +2159,7 @@ func (s *OrderModuleTestSuite) TestPaymentConsumer_Consume() {
evt: event.PaymentEvent{
OrderSN: "",
PayerID: testUID,
Status: uint8(payment.PaymentStatusFailed),
Status: uint8(payment.StatusFailed),
},
after: func(t *testing.T, orderSN string) {},
errRequireFunc: require.Error,
Expand All @@ -2176,7 +2176,7 @@ func (s *OrderModuleTestSuite) TestPaymentConsumer_Consume() {
evt: event.PaymentEvent{
OrderSN: "InvalidOrderSN",
PayerID: testUID,
Status: uint8(payment.PaymentStatusFailed),
Status: uint8(payment.StatusFailed),
},
after: func(t *testing.T, orderSN string) {},
errRequireFunc: require.Error,
Expand All @@ -2193,7 +2193,7 @@ func (s *OrderModuleTestSuite) TestPaymentConsumer_Consume() {
evt: event.PaymentEvent{
OrderSN: "OrderSN-3",
PayerID: 0,
Status: uint8(payment.PaymentStatusFailed),
Status: uint8(payment.StatusFailed),
},
after: func(t *testing.T, orderSN string) {},
errRequireFunc: require.Error,
Expand Down
10 changes: 5 additions & 5 deletions internal/payment/internal/domain/payment.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,11 @@ func (s PaymentStatus) ToUnit8() uint8 {
}

const (
PaymentStatusUnpaid PaymentStatus = 1
PaymentStatusPaid PaymentStatus = 2
PaymentStatusFailed PaymentStatus = 3
PaymentStatusRefund PaymentStatus = 4
PaymentStatusUnpaid PaymentStatus = 1
PaymentStatusProcessing PaymentStatus = 2
PaymentStatusPaidSuccess PaymentStatus = 3
PaymentStatusPaidFailed PaymentStatus = 4
PaymentStatusRefund PaymentStatus = 5
)

type Amount struct {
Expand All @@ -61,7 +62,6 @@ type Payment struct {
Status PaymentStatus
Records []PaymentRecord
Ctime int64
Utime int64
}

type PaymentChannel struct {
Expand Down
192 changes: 0 additions & 192 deletions internal/payment/internal/integration/credit_payment_service_test.go

This file was deleted.

Loading

0 comments on commit 08cdcf2

Please sign in to comment.