Skip to content
This repository was archived by the owner on Jul 1, 2024. It is now read-only.

Commit 5531d39

Browse files
authored
Merge pull request #41 from oxygenpay/develop
Fix payment expiration worker
2 parents 1082905 + 084a874 commit 5531d39

File tree

1 file changed

+5
-13
lines changed

1 file changed

+5
-13
lines changed

internal/service/processing/service_incoming.go

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -407,32 +407,24 @@ func (s *Service) expirePayment(ctx context.Context, paymentID int64) error {
407407
}
408408

409409
// 1. Cancel if tx exists
410-
var hasTransaction bool
411-
412410
tx, err := s.transactions.GetLatestByPaymentID(ctx, pt.ID)
413411
switch {
414412
case errors.Is(err, transaction.ErrNotFound):
415413
// that's expected, do nothing
416414
case err != nil:
417415
return errors.Wrap(err, "unable to get transaction")
418-
case tx != nil:
419-
hasTransaction = true
420416
}
421417

422-
if hasTransaction {
423-
if tx.Status != transaction.StatusPending {
424-
return errors.Errorf("invalid transaction status %q", tx.Status)
425-
}
426-
427-
if errTX := s.transactions.Cancel(ctx, tx, transaction.StatusCancelled, "payment expired", nil); errTX != nil {
418+
if tx != nil && tx.Status != transaction.StatusCancelled {
419+
errCancel := s.transactions.Cancel(ctx, tx, transaction.StatusCancelled, "payment expired", nil)
420+
if errCancel != nil {
428421
return errors.Wrap(err, "unable to cancel transaction")
429422
}
430423
}
431424

432425
// 2. Cancel payment itself
433-
_, err = s.payments.Update(ctx, pt.MerchantID, pt.ID, payment.UpdateProps{Status: payment.StatusFailed})
434-
if err != nil {
435-
return errors.Wrap(err, "unable to expire payment")
426+
if errFail := s.payments.Fail(ctx, pt); errFail != nil {
427+
return errors.Wrap(errFail, "unable to expire payment")
436428
}
437429

438430
return nil

0 commit comments

Comments
 (0)