add some
Some checks failed
CI/CD / Vet, test, build (push) Has been cancelled
CI/CD / Docker image (push) Has been cancelled
CI/CD / Deploy binary to server (push) Has been cancelled

This commit is contained in:
2026-09-19 04:47:43 +05:00
parent 6c7c402390
commit 599c12ef87
9 changed files with 68 additions and 25 deletions

View File

@@ -101,6 +101,7 @@ func (r *repository) Quote(ctx context.Context, orderID int64) (visamasterpay.Pa
Type: derefOrEmpty(orderType),
ExchangeRateUsd: usdRate,
MaxAmountTmt: round2(*amountUsd * usdRate),
PayableToday: isPayableDay(time.Now()),
}
if isSber(orderType) {
@@ -142,6 +143,10 @@ func (r *repository) Pay(ctx context.Context, orderID int64, dto visamasterpay.P
if err != nil {
return visamasterpay.PaymentInitResultDTO{}, err
}
if !isPayableDay(time.Now()) {
r.logStep(ctx, orderID, dto.CreatedBy, "rejected", map[string]string{"reason": "payment_window_closed"})
return visamasterpay.PaymentInitResultDTO{}, visamasterpay.ErrPaymentWindowClosed
}
if paid {
r.logStep(ctx, orderID, dto.CreatedBy, "rejected", map[string]string{"reason": "already_paid"})
return visamasterpay.PaymentInitResultDTO{}, visamasterpay.ErrAlreadyPaid
@@ -411,6 +416,20 @@ func (r *repository) fetchRate(ctx context.Context, from string) (float64, error
return strconv.ParseFloat(result.Currencies[0].Value.String(), 64)
}
// ashgabatZone is Turkmenistan's fixed UTC+5 offset (no DST observed).
var ashgabatZone = time.FixedZone("+05", 5*60*60)
// isPayableDay reports whether GBÜS payouts can be initiated on t's
// Ashgabat-local calendar day - false on Saturday/Sunday, since GBÜS/the
// bank does not process payouts on weekends. Because Saturday and Sunday
// are always adjacent, this alone also produces the right month-end cutoff
// (e.g. if the 31st is a Sunday, the 30th is a Saturday, so the 29th -
// Friday - is the last payable day) without any separate month-end logic.
func isPayableDay(t time.Time) bool {
wd := t.In(ashgabatZone).Weekday()
return wd != time.Saturday && wd != time.Sunday
}
func isSber(orderType *string) bool {
return orderType != nil && strings.EqualFold(strings.TrimSpace(*orderType), orderTypeSber)
}

View File

@@ -12,6 +12,9 @@ import (
// Sber orders have no GBÜS fee but add a USD-denominated TVEB fee (shown
// both as-is and converted to TMT) and also show the RUB rate for
// reference, using their own SberBankFeeTmt instead of BankFeeTmt.
// PayableToday is false on Saturday/Sunday (Asia/Ashgabat) - GBÜS/the bank
// does not process payouts on weekends, so the frontend should disable the
// Pay action rather than let the request fail.
type PaymentQuoteDTO struct {
Type string `json:"type"`
ExchangeRateUsd float64 `json:"exchangeRateUsd"`
@@ -21,6 +24,7 @@ type PaymentQuoteDTO struct {
TvebFeeUsd *float64 `json:"tvebFeeUsd,omitempty"`
TvebFeeTmt *float64 `json:"tvebFeeTmt,omitempty"`
MaxAmountTmt float64 `json:"maxAmountTmt"`
PayableToday bool `json:"payableToday"`
}
// PayOrderDTO starts a payout attempt for a visa/master/sber order.

View File

@@ -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):
case errors.Is(err, ErrAlreadyPaid), errors.Is(err, ErrAmountNotSet), 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)

View File

@@ -20,6 +20,10 @@ var ErrAmountExceedsMax = errors.New("amount exceeds the order's requested amoun
// attempt id that doesn't exist.
var ErrPaymentNotFound = errors.New("payment attempt not found")
// ErrPaymentWindowClosed is returned when today is not a business day
// (Saturday/Sunday) - GBÜS/the bank does not process payouts on weekends.
var ErrPaymentWindowClosed = errors.New("payment window is closed on weekends")
type Repository interface {
// OwnerInfo returns the order's owner/branch so the handler can run
// rbac.GuardOrder without importing cards/visamaster.