Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 48 additions & 2 deletions billing/credit/mocks/transaction_repository.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions billing/credit/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ type TransactionRepository interface {
GetByID(ctx context.Context, id string) (Transaction, error)
GetBalanceForRange(ctx context.Context, accountID string, start time.Time, end time.Time) (int64, error)
GetBalanceForRangeWithoutOverdraft(ctx context.Context, accountID string, start time.Time, end time.Time) (int64, error)
DeleteByAccountID(ctx context.Context, accountID string) error
}

type CustomerRepository interface {
Expand Down Expand Up @@ -175,6 +176,12 @@ func (s Service) GetByID(ctx context.Context, id string) (Transaction, error) {
return s.transactionRepository.GetByID(ctx, id)
}

// DeleteByAccountID removes all credit transactions of a billing account. It is
// meant for account teardown; the deletion is recorded in audit records.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This says the deletion is recorded in audit records, but nothing in the stack writes audit records for credit transactions. Only checkout deletes get them (#1839). Suggest dropping the sentence, or adding the audit record if it was intended.

func (s Service) DeleteByAccountID(ctx context.Context, accountID string) error {
return s.transactionRepository.DeleteByAccountID(ctx, accountID)
}

// createAuditRecord creates an audit record for billing transaction events.
func (s Service) createAuditRecord(ctx context.Context, customerID string, eventType pkgAuditRecord.Event, txID string, txEntry Transaction) error {
customerAcc, err := s.customerRepository.GetByID(ctx, customerID)
Expand Down
17 changes: 17 additions & 0 deletions internal/store/postgres/billing_transactions_repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,23 @@ func (r BillingTransactionRepository) UpdateByID(ctx context.Context, toUpdate c
return customerModel.transform()
}

func (r BillingTransactionRepository) DeleteByAccountID(ctx context.Context, accountID string) error {
query, params, err := dialect.Delete(TABLE_BILLING_TRANSACTIONS).Where(goqu.Ex{
"account_id": accountID,
}).ToSQL()
if err != nil {
return fmt.Errorf("%w: %w", errParse, err)
}

if err = r.dbc.WithTimeout(ctx, TABLE_BILLING_TRANSACTIONS, "DeleteByAccountID", func(ctx context.Context) error {
_, err := r.dbc.ExecContext(ctx, query, params...)
return err
}); err != nil {
return fmt.Errorf("%w: %w", errTxn, err)
}
return nil
}

func (r BillingTransactionRepository) List(ctx context.Context, filter credit.Filter) ([]credit.Transaction, error) {
stmt := dialect.Select().From(TABLE_BILLING_TRANSACTIONS).Order(goqu.I("created_at").Desc())
if filter.CustomerID != "" {
Expand Down
Loading