Fixed billing fees unreachable error propagation. Added USDT ledger creation. Fixed ledger boundaries operation types
This commit is contained in:
@@ -60,7 +60,7 @@ func (s *Service) postExternalCreditResponder(_ context.Context, req *ledgerv1.P
|
||||
|
||||
existingEntry, err := s.storage.JournalEntries().GetByIdempotencyKey(ctx, orgRef, req.IdempotencyKey)
|
||||
if err == nil && existingEntry != nil {
|
||||
recordDuplicateRequest("credit")
|
||||
recordDuplicateRequest(journalEntryTypeCredit)
|
||||
logger.Info("Duplicate external credit request (idempotency)",
|
||||
zap.String("existingEntryID", existingEntry.GetID().Hex()))
|
||||
return &ledgerv1.PostResponse{
|
||||
@@ -70,34 +70,34 @@ func (s *Service) postExternalCreditResponder(_ context.Context, req *ledgerv1.P
|
||||
}, nil
|
||||
}
|
||||
if err != nil && err != storage.ErrJournalEntryNotFound {
|
||||
recordJournalEntryError("credit", "idempotency_check_failed")
|
||||
recordJournalEntryError(journalEntryTypeCredit, journalEntryErrorIdempotencyCheck)
|
||||
logger.Warn("Failed to check idempotency", zap.Error(err))
|
||||
return nil, merrors.Internal("failed to check idempotency")
|
||||
}
|
||||
|
||||
account, accountRef, err := s.resolveAccount(ctx, strings.TrimSpace(req.LedgerAccountRef), roleModel, orgRef, req.Money.Currency, "account")
|
||||
if err != nil {
|
||||
recordJournalEntryError("credit", "account_resolve_failed")
|
||||
recordJournalEntryError(journalEntryTypeCredit, journalEntryErrorAccountResolve)
|
||||
return nil, err
|
||||
}
|
||||
if err := validateAccountForOrg(account, orgRef, req.Money.Currency); err != nil {
|
||||
recordJournalEntryError("credit", "account_invalid")
|
||||
recordJournalEntryError(journalEntryTypeCredit, journalEntryErrorAccountInvalid)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
systemAccount, err := s.systemAccount(ctx, pmodel.SystemAccountPurposeExternalSource, req.Money.Currency)
|
||||
if err != nil {
|
||||
recordJournalEntryError("credit", "system_account_resolve_failed")
|
||||
recordJournalEntryError(journalEntryTypeCredit, journalEntryErrorSystemAccountResolve)
|
||||
return nil, err
|
||||
}
|
||||
if err := validateSystemAccount(systemAccount, pmodel.SystemAccountPurposeExternalSource, req.Money.Currency); err != nil {
|
||||
recordJournalEntryError("credit", "system_account_invalid")
|
||||
recordJournalEntryError(journalEntryTypeCredit, journalEntryErrorSystemAccountInvalid)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
systemAccountID := systemAccount.GetID()
|
||||
if systemAccountID == nil {
|
||||
recordJournalEntryError("credit", "system_account_missing_id")
|
||||
recordJournalEntryError(journalEntryTypeCredit, journalEntryErrorSystemAccountMissing)
|
||||
return nil, merrors.Internal("system account missing identifier")
|
||||
}
|
||||
|
||||
@@ -186,7 +186,7 @@ func (s *Service) postExternalCreditResponder(_ context.Context, req *ledgerv1.P
|
||||
}
|
||||
|
||||
if !entryTotal.IsZero() {
|
||||
recordJournalEntryError("credit", "unbalanced_after_contra")
|
||||
recordJournalEntryError(journalEntryTypeCredit, journalEntryErrorUnbalancedAfterContra)
|
||||
return nil, merrors.Internal("failed to balance journal entry")
|
||||
}
|
||||
|
||||
@@ -240,13 +240,13 @@ func (s *Service) postExternalCreditResponder(_ context.Context, req *ledgerv1.P
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
recordJournalEntryError("credit", "transaction_failed")
|
||||
recordJournalEntryError(journalEntryTypeCredit, journalEntryErrorTransactionFailed)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
amountFloat, _ := creditAmount.Float64()
|
||||
recordTransactionAmount(req.Money.Currency, "credit", amountFloat)
|
||||
recordJournalEntry("credit", "success", 0)
|
||||
recordTransactionAmount(req.Money.Currency, journalEntryTypeCredit, amountFloat)
|
||||
recordJournalEntry(journalEntryTypeCredit, journalEntryStatusSuccess, 0)
|
||||
return result.(*ledgerv1.PostResponse), nil
|
||||
}
|
||||
}
|
||||
@@ -293,7 +293,7 @@ func (s *Service) postExternalDebitResponder(_ context.Context, req *ledgerv1.Po
|
||||
|
||||
existingEntry, err := s.storage.JournalEntries().GetByIdempotencyKey(ctx, orgRef, req.IdempotencyKey)
|
||||
if err == nil && existingEntry != nil {
|
||||
recordDuplicateRequest("debit")
|
||||
recordDuplicateRequest(journalEntryTypeDebit)
|
||||
logger.Info("Duplicate external debit request (idempotency)",
|
||||
zap.String("existingEntryID", existingEntry.GetID().Hex()))
|
||||
return &ledgerv1.PostResponse{
|
||||
@@ -303,34 +303,34 @@ func (s *Service) postExternalDebitResponder(_ context.Context, req *ledgerv1.Po
|
||||
}, nil
|
||||
}
|
||||
if err != nil && err != storage.ErrJournalEntryNotFound {
|
||||
recordJournalEntryError("debit", "idempotency_check_failed")
|
||||
recordJournalEntryError(journalEntryTypeDebit, journalEntryErrorIdempotencyCheck)
|
||||
logger.Warn("Failed to check idempotency", zap.Error(err))
|
||||
return nil, merrors.Internal("failed to check idempotency")
|
||||
}
|
||||
|
||||
account, accountRef, err := s.resolveAccount(ctx, strings.TrimSpace(req.LedgerAccountRef), roleModel, orgRef, req.Money.Currency, "account")
|
||||
if err != nil {
|
||||
recordJournalEntryError("debit", "account_resolve_failed")
|
||||
recordJournalEntryError(journalEntryTypeDebit, journalEntryErrorAccountResolve)
|
||||
return nil, err
|
||||
}
|
||||
if err := validateAccountForOrg(account, orgRef, req.Money.Currency); err != nil {
|
||||
recordJournalEntryError("debit", "account_invalid")
|
||||
recordJournalEntryError(journalEntryTypeDebit, journalEntryErrorAccountInvalid)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
systemAccount, err := s.systemAccount(ctx, pmodel.SystemAccountPurposeExternalSink, req.Money.Currency)
|
||||
if err != nil {
|
||||
recordJournalEntryError("debit", "system_account_resolve_failed")
|
||||
recordJournalEntryError(journalEntryTypeDebit, journalEntryErrorSystemAccountResolve)
|
||||
return nil, err
|
||||
}
|
||||
if err := validateSystemAccount(systemAccount, pmodel.SystemAccountPurposeExternalSink, req.Money.Currency); err != nil {
|
||||
recordJournalEntryError("debit", "system_account_invalid")
|
||||
recordJournalEntryError(journalEntryTypeDebit, journalEntryErrorSystemAccountInvalid)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
systemAccountID := systemAccount.GetID()
|
||||
if systemAccountID == nil {
|
||||
recordJournalEntryError("debit", "system_account_missing_id")
|
||||
recordJournalEntryError(journalEntryTypeDebit, journalEntryErrorSystemAccountMissing)
|
||||
return nil, merrors.Internal("system account missing identifier")
|
||||
}
|
||||
|
||||
@@ -419,7 +419,7 @@ func (s *Service) postExternalDebitResponder(_ context.Context, req *ledgerv1.Po
|
||||
}
|
||||
|
||||
if !entryTotal.IsZero() {
|
||||
recordJournalEntryError("debit", "unbalanced_after_contra")
|
||||
recordJournalEntryError(journalEntryTypeDebit, journalEntryErrorUnbalancedAfterContra)
|
||||
return nil, merrors.Internal("failed to balance journal entry")
|
||||
}
|
||||
|
||||
@@ -473,13 +473,13 @@ func (s *Service) postExternalDebitResponder(_ context.Context, req *ledgerv1.Po
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
recordJournalEntryError("debit", "transaction_failed")
|
||||
recordJournalEntryError(journalEntryTypeDebit, journalEntryErrorTransactionFailed)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
amountFloat, _ := debitAmount.Float64()
|
||||
recordTransactionAmount(req.Money.Currency, "debit", amountFloat)
|
||||
recordJournalEntry("debit", "success", 0)
|
||||
recordTransactionAmount(req.Money.Currency, journalEntryTypeDebit, amountFloat)
|
||||
recordJournalEntry(journalEntryTypeDebit, journalEntryStatusSuccess, 0)
|
||||
return result.(*ledgerv1.PostResponse), nil
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user