rm -rf amount in db
This commit is contained in:
1 parent
45378559ca
commit
87e4b33322
11 files changed
+48
-35
No files matched your search
@@ -74,7 +74,7 @@ type CreateVisaMasterPaymentOrderDTO struct {
|
||||
RecieverPassportSerie *string `json:"recieverPassportSerie"`
|
||||
RecieverPassportNumber *string `json:"recieverPassportNumber"`
|
||||
RecieverDepositAccount *string `json:"recieverDepositAccount"`
|
||||
AmountUsd float64 `json:"amountUsd" binding:"required"`
|
||||
AmountUsd float64 `json:"amountUsd"`
|
||||
Paid *bool `json:"paid"`
|
||||
}
|
||||
|
||||
@@ -102,7 +102,7 @@ type UpdateVisaMasterPaymentOrderDTO struct {
|
||||
RecieverPassportSerie *string `json:"recieverPassportSerie"`
|
||||
RecieverPassportNumber *string `json:"recieverPassportNumber"`
|
||||
RecieverDepositAccount *string `json:"recieverDepositAccount"`
|
||||
AmountUsd float64 `json:"amountUsd" binding:"required"`
|
||||
AmountUsd float64 `json:"amountUsd"`
|
||||
Paid bool `json:"paid"`
|
||||
}
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ func NewRepository(client postgresql.Client, logger *logging.Logger) paymentsett
|
||||
return &repository{client: client, logger: logger}
|
||||
}
|
||||
|
||||
const settingsColumnsSQL = `bank_fee_tmt, gbus_fee_tmt, sber_bank_fee_tmt, tveb_fee_usd, updated_by, updated_at`
|
||||
const settingsColumnsSQL = `bank_fee_tmt, gbus_fee_tmt, sber_bank_fee_tmt, tveb_fee_usd, max_amount_usd, updated_by, updated_at`
|
||||
|
||||
func (r *repository) Get(ctx context.Context) (paymentsettings.PaymentSettingsDTO, error) {
|
||||
row := r.client.QueryRow(ctx, `SELECT `+settingsColumnsSQL+` FROM payment_settings WHERE id = 1`)
|
||||
@@ -27,13 +27,13 @@ func (r *repository) Get(ctx context.Context) (paymentsettings.PaymentSettingsDT
|
||||
func (r *repository) Update(ctx context.Context, dto paymentsettings.UpdatePaymentSettingsDTO) (paymentsettings.PaymentSettingsDTO, error) {
|
||||
query := `
|
||||
UPDATE payment_settings SET
|
||||
bank_fee_tmt = $1, gbus_fee_tmt = $2, sber_bank_fee_tmt = $3, tveb_fee_usd = $4, updated_by = $5,
|
||||
bank_fee_tmt = $1, gbus_fee_tmt = $2, sber_bank_fee_tmt = $3, tveb_fee_usd = $4, max_amount_usd = $5, updated_by = $6,
|
||||
updated_at = (CURRENT_TIMESTAMP AT TIME ZONE 'UTC')
|
||||
WHERE id = 1
|
||||
RETURNING ` + settingsColumnsSQL
|
||||
|
||||
return scanSettings(r.client.QueryRow(ctx, query,
|
||||
dto.BankFeeTmt, dto.GbusFeeTmt, dto.SberBankFeeTmt, dto.TvebFeeUsd, dto.UpdatedBy,
|
||||
dto.BankFeeTmt, dto.GbusFeeTmt, dto.SberBankFeeTmt, dto.TvebFeeUsd, dto.MaxAmountUsd, dto.UpdatedBy,
|
||||
))
|
||||
}
|
||||
|
||||
@@ -42,7 +42,7 @@ func scanSettings(row interface {
|
||||
}) (paymentsettings.PaymentSettingsDTO, error) {
|
||||
var item paymentsettings.PaymentSettingsDTO
|
||||
if err := row.Scan(
|
||||
&item.BankFeeTmt, &item.GbusFeeTmt, &item.SberBankFeeTmt, &item.TvebFeeUsd, &item.UpdatedById, &item.UpdatedAt,
|
||||
&item.BankFeeTmt, &item.GbusFeeTmt, &item.SberBankFeeTmt, &item.TvebFeeUsd, &item.MaxAmountUsd, &item.UpdatedById, &item.UpdatedAt,
|
||||
); err != nil {
|
||||
return paymentsettings.PaymentSettingsDTO{}, err
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ type PaymentSettingsDTO struct {
|
||||
GbusFeeTmt float64 `json:"gbusFeeTmt"`
|
||||
SberBankFeeTmt float64 `json:"sberBankFeeTmt"`
|
||||
TvebFeeUsd float64 `json:"tvebFeeUsd"`
|
||||
MaxAmountUsd float64 `json:"maxAmountUsd"`
|
||||
UpdatedById *int64 `json:"-"`
|
||||
UpdatedAt time.Time `json:"updatedAt"`
|
||||
}
|
||||
@@ -16,5 +17,6 @@ type UpdatePaymentSettingsDTO struct {
|
||||
GbusFeeTmt float64 `json:"gbusFeeTmt" binding:"required"`
|
||||
SberBankFeeTmt float64 `json:"sberBankFeeTmt" binding:"required"`
|
||||
TvebFeeUsd float64 `json:"tvebFeeUsd" binding:"required"`
|
||||
MaxAmountUsd float64 `json:"maxAmountUsd" binding:"required"`
|
||||
UpdatedBy *int64 `json:"-"`
|
||||
}
|
||||
@@ -72,20 +72,16 @@ func (r *repository) OwnerInfo(ctx context.Context, orderID int64) (*int64, int6
|
||||
|
||||
func (r *repository) Quote(ctx context.Context, orderID int64) (visamasterpay.PaymentQuoteDTO, error) {
|
||||
var orderType *string
|
||||
var amountUsd *float64
|
||||
var paid bool
|
||||
err := r.client.QueryRow(ctx,
|
||||
`SELECT type, amount_usd, paid FROM visa_master_payment_orders WHERE id = $1 AND deleted_at IS NULL`, orderID,
|
||||
).Scan(&orderType, &amountUsd, &paid)
|
||||
`SELECT type, paid FROM visa_master_payment_orders WHERE id = $1 AND deleted_at IS NULL`, orderID,
|
||||
).Scan(&orderType, &paid)
|
||||
if err != nil {
|
||||
return visamasterpay.PaymentQuoteDTO{}, err
|
||||
}
|
||||
if paid {
|
||||
return visamasterpay.PaymentQuoteDTO{}, visamasterpay.ErrAlreadyPaid
|
||||
}
|
||||
if amountUsd == nil {
|
||||
return visamasterpay.PaymentQuoteDTO{}, visamasterpay.ErrAmountNotSet
|
||||
}
|
||||
|
||||
usdRate, err := r.fetchRate(ctx, "USD")
|
||||
if err != nil {
|
||||
@@ -100,7 +96,7 @@ func (r *repository) Quote(ctx context.Context, orderID int64) (visamasterpay.Pa
|
||||
quote := visamasterpay.PaymentQuoteDTO{
|
||||
Type: derefOrEmpty(orderType),
|
||||
ExchangeRateUsd: usdRate,
|
||||
MaxAmountTmt: round2(*amountUsd * usdRate),
|
||||
MaxAmountTmt: round2(settings.MaxAmountUsd * usdRate),
|
||||
PayableToday: isPayableDay(time.Now()),
|
||||
}
|
||||
|
||||
@@ -132,14 +128,13 @@ func (r *repository) Quote(ctx context.Context, orderID int64) (visamasterpay.Pa
|
||||
// passes back except to look up our own row.
|
||||
func (r *repository) Pay(ctx context.Context, orderID int64, dto visamasterpay.PayOrderDTO) (visamasterpay.PaymentInitResultDTO, error) {
|
||||
var orderType *string
|
||||
var amountUsd *float64
|
||||
var paid bool
|
||||
var branchID int64
|
||||
var userID int64
|
||||
err := r.client.QueryRow(ctx,
|
||||
`SELECT type, amount_usd, paid, branch_id, user_id FROM visa_master_payment_orders WHERE id = $1 AND deleted_at IS NULL`,
|
||||
`SELECT type, paid, branch_id, user_id FROM visa_master_payment_orders WHERE id = $1 AND deleted_at IS NULL`,
|
||||
orderID,
|
||||
).Scan(&orderType, &amountUsd, &paid, &branchID, &userID)
|
||||
).Scan(&orderType, &paid, &branchID, &userID)
|
||||
if err != nil {
|
||||
return visamasterpay.PaymentInitResultDTO{}, err
|
||||
}
|
||||
@@ -151,10 +146,6 @@ func (r *repository) Pay(ctx context.Context, orderID int64, dto visamasterpay.P
|
||||
r.logStep(ctx, orderID, dto.CreatedBy, "rejected", map[string]string{"reason": "already_paid"})
|
||||
return visamasterpay.PaymentInitResultDTO{}, visamasterpay.ErrAlreadyPaid
|
||||
}
|
||||
if amountUsd == nil {
|
||||
r.logStep(ctx, orderID, dto.CreatedBy, "rejected", map[string]string{"reason": "amount_not_set"})
|
||||
return visamasterpay.PaymentInitResultDTO{}, visamasterpay.ErrAmountNotSet
|
||||
}
|
||||
|
||||
usdRate, err := r.fetchRate(ctx, "USD")
|
||||
if err != nil {
|
||||
@@ -166,7 +157,7 @@ func (r *repository) Pay(ctx context.Context, orderID int64, dto visamasterpay.P
|
||||
return visamasterpay.PaymentInitResultDTO{}, err
|
||||
}
|
||||
|
||||
maxAmountTmt := round2(*amountUsd * usdRate)
|
||||
maxAmountTmt := round2(settings.MaxAmountUsd * usdRate)
|
||||
amountTmt := maxAmountTmt
|
||||
if dto.AmountTmt != nil {
|
||||
if *dto.AmountTmt <= 0 || *dto.AmountTmt > maxAmountTmt {
|
||||
@@ -179,7 +170,7 @@ func (r *repository) Pay(ctx context.Context, orderID int64, dto visamasterpay.P
|
||||
}
|
||||
|
||||
r.logStep(ctx, orderID, dto.CreatedBy, "validated", map[string]interface{}{
|
||||
"orderType": derefOrEmpty(orderType), "amountUsd": *amountUsd, "amountTmt": amountTmt, "exchangeRateUsd": usdRate,
|
||||
"orderType": derefOrEmpty(orderType), "maxAmountUsd": settings.MaxAmountUsd, "amountTmt": amountTmt, "exchangeRateUsd": usdRate,
|
||||
})
|
||||
|
||||
sber := isSber(orderType)
|
||||
|
||||
@@ -171,7 +171,7 @@ func (h *handler) handleError(c *gin.Context, err error, action string) bool {
|
||||
switch {
|
||||
case errors.Is(err, pgx.ErrNoRows):
|
||||
c.JSON(http.StatusNotFound, appresult.ErrNotFound)
|
||||
case errors.Is(err, ErrAlreadyPaid), errors.Is(err, ErrAmountNotSet), errors.Is(err, ErrAmountExceedsMax), errors.Is(err, ErrPaymentWindowClosed):
|
||||
case errors.Is(err, ErrAlreadyPaid), errors.Is(err, ErrAmountExceedsMax), errors.Is(err, ErrPaymentWindowClosed):
|
||||
c.JSON(http.StatusBadRequest, appresult.ErrNotAcceptable)
|
||||
default:
|
||||
h.logger.Errorf("%s visa master payment order failed: %v", action, err)
|
||||
|
||||
@@ -9,12 +9,10 @@ import (
|
||||
// was paid by a concurrent request that won the race).
|
||||
var ErrAlreadyPaid = errors.New("order already paid")
|
||||
|
||||
// ErrAmountNotSet is returned when the order has no amount_usd set yet.
|
||||
var ErrAmountNotSet = errors.New("order has no requested amount")
|
||||
|
||||
// ErrAmountExceedsMax is returned when the submitted amountTmt is above
|
||||
// what the order's amount_usd converts to at the current rate.
|
||||
var ErrAmountExceedsMax = errors.New("amount exceeds the order's requested amount")
|
||||
// ErrAmountExceedsMax is returned when the submitted amountTmt is above the
|
||||
// admin-configured max amount (settings.MaxAmountUsd) converted at the
|
||||
// current rate.
|
||||
var ErrAmountExceedsMax = errors.New("amount exceeds the configured max amount")
|
||||
|
||||
// ErrPaymentNotFound is returned when a callback references a payment
|
||||
// attempt id that doesn't exist.
|
||||
|
||||
Reference in new issue
Block a user