refactor payment platform canonicalization and order method consistency
Build docker and publish / build (20.15.1) (push) Failing after 8m1s

This commit is contained in:
2026-03-04 02:15:32 -08:00
parent 82626dd749
commit 0c544268e5
10 changed files with 160 additions and 23 deletions
@@ -36,11 +36,13 @@ func NewCreatePaymentMethodLogic(ctx context.Context, svcCtx *svc.ServiceContext
}
func (l *CreatePaymentMethodLogic) CreatePaymentMethod(req *types.CreatePaymentMethodRequest) (resp *types.PaymentConfig, err error) {
if payment.ParsePlatform(req.Platform) == payment.UNSUPPORTED {
platformType := payment.ParsePlatform(req.Platform)
if platformType == payment.UNSUPPORTED {
l.Errorw("unsupported payment platform", logger.Field("mark", req.Platform))
return nil, errors.Wrapf(xerr.NewErrCodeMsg(400, "UNSUPPORTED_PAYMENT_PLATFORM"), "unsupported payment platform: %s", req.Platform)
}
config := parsePaymentPlatformConfig(l.ctx, payment.ParsePlatform(req.Platform), req.Config)
req.Platform = platformType.String()
config := parsePaymentPlatformConfig(l.ctx, platformType, req.Config)
var paymentMethod = &paymentModel.Payment{
Name: req.Name,
Platform: req.Platform,
@@ -55,7 +57,7 @@ func (l *CreatePaymentMethodLogic) CreatePaymentMethod(req *types.CreatePaymentM
Token: random.KeyNew(8, 1),
}
err = l.svcCtx.PaymentModel.Transaction(l.ctx, func(tx *gorm.DB) error {
if req.Platform == "Stripe" {
if platformType == payment.Stripe {
var cfg paymentModel.StripeConfig
if err = cfg.Unmarshal([]byte(paymentMethod.Config)); err != nil {
l.Errorf("[CreatePaymentMethod] unmarshal stripe config error: %s", err.Error())
@@ -29,7 +29,8 @@ func NewUpdatePaymentMethodLogic(ctx context.Context, svcCtx *svc.ServiceContext
}
func (l *UpdatePaymentMethodLogic) UpdatePaymentMethod(req *types.UpdatePaymentMethodRequest) (resp *types.PaymentConfig, err error) {
if payment.ParsePlatform(req.Platform) == payment.UNSUPPORTED {
platformType := payment.ParsePlatform(req.Platform)
if platformType == payment.UNSUPPORTED {
l.Errorw("unsupported payment platform", logger.Field("mark", req.Platform))
return nil, errors.Wrapf(xerr.NewErrCodeMsg(400, "UNSUPPORTED_PAYMENT_PLATFORM"), "unsupported payment platform: %s", req.Platform)
}
@@ -38,7 +39,13 @@ func (l *UpdatePaymentMethodLogic) UpdatePaymentMethod(req *types.UpdatePaymentM
l.Errorw("find payment method error", logger.Field("id", req.Id), logger.Field("error", err.Error()))
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DatabaseQueryError), "find payment method error: %s", err.Error())
}
config := parsePaymentPlatformConfig(l.ctx, payment.ParsePlatform(req.Platform), req.Config)
existingPlatformType := payment.ParsePlatform(method.Platform)
if existingPlatformType != payment.UNSUPPORTED && existingPlatformType != platformType {
l.Errorw("payment platform mismatch", logger.Field("id", req.Id), logger.Field("current", method.Platform), logger.Field("request", req.Platform))
return nil, errors.Wrapf(xerr.NewErrCodeMsg(xerr.InvalidParams, "payment platform mismatch"), "payment platform mismatch: %s -> %s", method.Platform, req.Platform)
}
req.Platform = platformType.String()
config := parsePaymentPlatformConfig(l.ctx, platformType, req.Config)
tool.DeepCopy(method, req, tool.CopyWithIgnoreEmpty(false))
method.Config = config
if err := l.svcCtx.PaymentModel.Update(l.ctx, method); err != nil {