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
This commit is contained in:
Bill Thorp 2020-07-01 11:26:23 -04:00 committed by Bill Thorp
parent ac716e1514
commit 00ae5ebbab
2 changed files with 6 additions and 8 deletions

View File

@ -199,11 +199,9 @@ func (service *Service) updateTransactions(ctx context.Context, ids TransactionA
}, },
) )
// moment of transition to completed state, which indicates // moment of CoinPayments receives funds, not when STORJ does
// that customer funds were accepted and transferred to our // this was a business decision to not wait until StatusCompleted
// account, so we can apply this amount to customer balance. if info.Status >= coinpayments.StatusReceived {
// Therefore, create intent to update customer balance in the future.
if info.Status == coinpayments.StatusCompleted {
//monkit currently does not have a DurationVal //monkit currently does not have a DurationVal
mon.IntVal("coinpayment_duration").Observe(int64(time.Since(creationTimes[id]))) mon.IntVal("coinpayment_duration").Observe(int64(time.Since(creationTimes[id])))
applies = append(applies, id) applies = append(applies, id)

View File

@ -283,7 +283,7 @@ func (db *coinPaymentsTransactions) ListPending(ctx context.Context, offset int6
return page, nil 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) { func (db *coinPaymentsTransactions) ListUnapplied(ctx context.Context, offset int64, limit int, before time.Time) (_ stripecoinpayments.TransactionsPage, err error) {
defer mon.Task()(&ctx)(&err) defer mon.Task()(&ctx)(&err)
@ -299,13 +299,13 @@ func (db *coinPaymentsTransactions) ListUnapplied(ctx context.Context, offset in
FROM coinpayments_transactions as txs FROM coinpayments_transactions as txs
INNER JOIN stripecoinpayments_apply_balance_intents as ints INNER JOIN stripecoinpayments_apply_balance_intents as ints
ON txs.id = ints.tx_id ON txs.id = ints.tx_id
WHERE txs.status = ? WHERE txs.status >= ?
AND txs.created_at <= ? AND txs.created_at <= ?
AND ints.state = ? AND ints.state = ?
ORDER by txs.created_at DESC ORDER by txs.created_at DESC
LIMIT ? OFFSET ?`) 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 { if err != nil {
return stripecoinpayments.TransactionsPage{}, err return stripecoinpayments.TransactionsPage{}, err
} }