diff --git a/satellite/payments/stripecoinpayments/service.go b/satellite/payments/stripecoinpayments/service.go index 065f41c4e..19ae70afb 100644 --- a/satellite/payments/stripecoinpayments/service.go +++ b/satellite/payments/stripecoinpayments/service.go @@ -199,11 +199,9 @@ func (service *Service) updateTransactions(ctx context.Context, ids TransactionA }, ) - // moment of transition to completed state, which indicates - // that customer funds were accepted and transferred to our - // account, so we can apply this amount to customer balance. - // Therefore, create intent to update customer balance in the future. - if info.Status == coinpayments.StatusCompleted { + // moment of CoinPayments receives funds, not when STORJ does + // this was a business decision to not wait until StatusCompleted + if info.Status >= coinpayments.StatusReceived { //monkit currently does not have a DurationVal mon.IntVal("coinpayment_duration").Observe(int64(time.Since(creationTimes[id]))) applies = append(applies, id) diff --git a/satellite/satellitedb/coinpaymentstxs.go b/satellite/satellitedb/coinpaymentstxs.go index 64dea4d9c..d29b7ac91 100644 --- a/satellite/satellitedb/coinpaymentstxs.go +++ b/satellite/satellitedb/coinpaymentstxs.go @@ -283,7 +283,7 @@ func (db *coinPaymentsTransactions) ListPending(ctx context.Context, offset int6 return page, nil } -// List Unapplied returns TransactionsPage with transactions completed transaction that should be applied to account balance. +// List Unapplied returns TransactionsPage with a pending or completed status, that should be applied to account balance. func (db *coinPaymentsTransactions) ListUnapplied(ctx context.Context, offset int64, limit int, before time.Time) (_ stripecoinpayments.TransactionsPage, err error) { defer mon.Task()(&ctx)(&err) @@ -299,13 +299,13 @@ func (db *coinPaymentsTransactions) ListUnapplied(ctx context.Context, offset in FROM coinpayments_transactions as txs INNER JOIN stripecoinpayments_apply_balance_intents as ints ON txs.id = ints.tx_id - WHERE txs.status = ? + WHERE txs.status >= ? AND txs.created_at <= ? AND ints.state = ? ORDER by txs.created_at DESC LIMIT ? OFFSET ?`) - rows, err := db.db.QueryContext(ctx, query, coinpayments.StatusCompleted, before, applyBalanceIntentStateUnapplied, limit+1, offset) + rows, err := db.db.QueryContext(ctx, query, coinpayments.StatusReceived, before, applyBalanceIntentStateUnapplied, limit+1, offset) if err != nil { return stripecoinpayments.TransactionsPage{}, err }