feat: add refund statuses

This commit is contained in:
Rogee
2025-05-06 20:23:06 +08:00
parent b7ebdf1ce6
commit 41cdc821da
13 changed files with 266 additions and 114 deletions

View File

@@ -7,8 +7,8 @@ import (
"quyun/app/models"
"quyun/database/fields"
"quyun/providers/wepay"
"github.com/go-pay/gopay/wechat/v3"
"github.com/pkg/errors"
. "github.com/riverqueue/river"
log "github.com/sirupsen/logrus"
@@ -20,7 +20,7 @@ import (
var _ contracts.JobArgs = (*WechatPayNotify)(nil)
type WechatPayNotify struct {
PayNotify *wepay.PayNotify `json:"notify_req"`
Notify *wechat.V3DecryptPayResult `json:"notify"`
}
func (s WechatPayNotify) InsertOpts() InsertOpts {
@@ -46,7 +46,7 @@ func (w *WechatPayNotifyWorker) Work(ctx context.Context, job *Job[WechatPayNoti
log.Infof("[Start] Working on job with strings: %+v", job.Args)
defer log.Infof("[End] Finished %s", job.Args.Kind())
notify := job.Args.PayNotify
notify := job.Args.Notify
if notify.TradeState != "SUCCESS" {
log.Warnf("TradeState is not SUCCESS for order %s", notify.OutTradeNo)
@@ -60,23 +60,23 @@ func (w *WechatPayNotifyWorker) Work(ctx context.Context, job *Job[WechatPayNoti
}
if order.Status != fields.OrderStatusPending {
log.Infof("Order %s is paid, processing...", job.Args.PayNotify.OutTradeNo)
log.Infof("Order %s is paid, processing...", job.Args.Notify.OutTradeNo)
return JobCancel(fmt.Errorf("Order already paid, currently status: %d", order.Status))
}
needToPay := order.Price * int64(order.Discount) / 100
if notify.Amount.Total != needToPay {
log.Errorf("Order %s amount mismatch: expected %d, got %d", job.Args.PayNotify.OutTradeNo, needToPay, notify.Amount.Total)
return fmt.Errorf("amount mismatch for order %s", job.Args.PayNotify.OutTradeNo)
if int64(notify.Amount.Total) != needToPay {
log.Errorf("Order %s amount mismatch: expected %d, got %d", job.Args.Notify.OutTradeNo, needToPay, notify.Amount.Total)
return fmt.Errorf("amount mismatch for order %s", job.Args.Notify.OutTradeNo)
}
order.TransactionID = notify.TransactionID
order.TransactionID = notify.TransactionId
order.Currency = notify.Amount.Currency
order.PaymentMethod = notify.TradeType
order.Status = fields.OrderStatusCompleted
order.Meta = fields.ToJson(fields.OrderMeta{
PayNotify: *notify,
PayNotify: notify,
})
log.Infof("Updated order details: %+v", order)