From 00ae5ebbabac34558918b4097e6814e5e105775f Mon Sep 17 00:00:00 2001 From: Bill Thorp Date: Wed, 1 Jul 2020 11:26:23 -0400 Subject: [PATCH] satellite/payemnts: Credit coin payments earlier Apply the coin payments when CoinPayments.net recieves the funds Instead of the when STORJ gets them from CoinPayments.net Based on 7/1/20 User Growth standup guidance by JG Relates to: https://storjlabs.atlassian.net/browse/USR-801 Change-Id: I174ca23a585010f39464c45525e1dfe0179b7c1a --- satellite/payments/stripecoinpayments/service.go | 8 +++----- satellite/satellitedb/coinpaymentstxs.go | 6 +++--- 2 files changed, 6 insertions(+), 8 deletions(-) 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 }