Commit Graph

274 Commits

Author SHA1 Message Date
dlamarmorgan
a010459520 satellite/payments/stripe/{client,server}: add set invoice status cmd
Change-Id: I6d9b4fe2ed4b17d63d858f7ceefd7c14adb062bb
2023-06-28 21:04:34 +00:00
Cameron
37e7eeb0e9 satellite/payments/accountfreeze: set grace period default to 15 days
Change-Id: Ied8f3758b579b83ebf04cba0fde9715c689bac4f
2023-06-22 18:53:03 +00:00
Wilfred Asomani
4a49bc4b65 satellite/payments: fix account freeze chore race condition
This change fixes an issue where a formerly warned/frozen user will be
warned again even though they have made payment for the invoice that got
them frozen in the first place. A payment status check is now made
right before a warn/freeze event to make sure the invoice hasn't been
paid already.

Issue: https://github.com/storj/storj/issues/5931

Change-Id: I3f6ac1e224f40107d58dc8f7bdbce58bbbea0196
2023-06-14 10:10:56 +00:00
Wilfred Asomani
09a7d23003 satellite/console: add endpoint to invite users to project
This change adds a new endpoint that uses the new project invite flow's
 functionality instead of directly adding users to a project's members.

Issue: https://github.com/storj/storj/issues/5741

Change-Id: I6734f7e95be07086387fb133d6bdfd95e47cf4d9
2023-06-13 15:22:25 +00:00
JT Olio
3fff61f04a payments: don't redefine compensation rates twice
Change-Id: Ic00abe3795a000d4f0284c99f270180123a2f663
2023-06-10 12:40:43 +00:00
Wilfred Asomani
4791a6422d satellite/console: add STORJ bonus to transactions
This change includes STORJ bonuses to the list of transactions returned
by the /wallet/payments endpoint.

Issue: https://github.com/storj/storj/issues/5755

Change-Id: Icc95c2cb9dd9fc5ee7a373e68c1cf8a991e1aa58
2023-05-26 20:36:30 +00:00
Cameron
09ec5f107d satellite/payments: Remove expired package credits
During billing, before invoice creation, check if users are part of a
package plan. If so, and if the package plan is expired, remove unused
credit from the user's balance. If the user has credit in addition to
the package credit, send an analytics event to notify someone to handle
the credit removal manually.

Change-Id: Iad71d791f67c9733f9d9e42f962c64b2780264cc
2023-05-22 11:58:37 +00:00
Michal Niewrzal
87d0789691 satellite/payments/stripe: avoid full table scan while listing records
Stripe invoice project records while listing are causing full table scan
because of OFFSET caluse. This change is refactoring query to list using
cursor.

Change-Id: I6b73b9b2815173d7ef02cf615408778476eb3b7b
2023-05-09 14:16:55 +00:00
dlamarmorgan
cf5d2d792c satellite/payments/stripe/service.go: fix payment for multiple invoices
Fix an error that can occur when processing multiple invoices for the same user in a single invoice cycle when the user is paying with Storj tokens.

Change-Id: I54af8c7dde1965d994f687fdfc4e4b5ef4deeb2d
2023-05-08 21:17:14 +00:00
dlamarmorgan
b89e0e0272 payments/stripe: Remove apply coupon from generate invoice command
Remove the command to apply free tier coupons from the generate invoices
command. Applying free tier coupons should instead be done outside the
normal time window for invoice generation to save time during the
invoicing cycle.

Change-Id: If8fecc558411d5a6fff9d5689143d72f3b709e55
2023-04-27 08:24:12 -07:00
dlamarmorgan
efcae857ba satellite/main,stripe/{client,service}: stripe balance invoice item cmd
Add a new billing command that will convert stripe customer balances into invoice items so that the charges can be processed normally by the invoicing workflow.

Change-Id: Iaa8350e7aca80a0f14e94eb8ef8b7d6ce0b5b3b8
2023-04-25 21:08:23 +00:00
Wilfred Asomani
260b71e70c satellite/{console,accountfreeze}: test freeze effects
This change adds more tests to the autofreeze chore and the freeze
service according to the testplan linked in the issue below.

Issue: https://github.com/storj/storj/issues/5738

Change-Id: Ib2afaa283961b2e7ef6fb6e5613ee083ac7d79eb
2023-04-25 13:04:37 +00:00
dlamarmorgan
d402ed4b71 satellite/payments/stripe/service.go: fix typo in credit note memo
Remove the extra prepended '0x' from the wallet address.
Remove prepended '0x' from the transaction ID.

Change-Id: Id215536915fba62cc348aa2c3356ecc7898d68a2
2023-04-17 20:35:58 +00:00
Egon Elbre
eecb055dfd satellite/buckets: move Bucket definition
Move Bucket struct definition.

Updates https://github.com/storj/storj/issues/5291

Change-Id: I6bfc5ce287793ea479f2cb8b17878ba3cf6b63e0
2023-04-13 17:55:40 -04:00
Jeremy Wharton
34b2a369f7 satellite/payments/stripe: apply egress discount to project charges
The project charge information used by the satellite frontend to
compute project cost estimates has been updated to account for
configured egress discounts.

Resolves storj/storj-private#215

Change-Id: Ic90b015d65f5bea104ac96fb0cea545b3f9f1f8f
2023-04-13 17:34:50 +00:00
Michal Niewrzal
a21afeddd1 satellite/payments/stripe: avoid full table scan while listing
Query to list (with pages) stripe customers were doing full table scan
because Offset clause was used. This refactoring changed listing to
use cursor instead Offset.

Change-Id: I14688e6c533bc932ba0d209a061562f080b4cf54
2023-04-13 12:36:31 +02:00
Jeremy Wharton
c92fdba972 satellite/payments/stripe: apply egress discount to invoice items
Invoicing has been modified to account for an egress discount ratio,
which specifies the fraction of the amount of data stored that egress
usage should be discounted.

The egress discount ratio measures discounted egress units per storage
unit-months, so a ratio of 0.5 with 2 MB-months of storage would
discount 1 MB of egress.

Resolves storj/storj-private#224

Change-Id: I43d7d6719391c303712c082709aef77249c65f62
2023-04-12 15:28:00 +00:00
Jeremy Wharton
6e9dae06d5 satellite/payments: add egress discount ratio to price override config
This change allows for specifying the ratio of free egress per unit
of storage within a price override configuration.

References storj/storj-private#215
References storj/storj-private#224

Change-Id: Ib1c79f77ec8bb11dd5b2f9dace13800b0b3ce942
2023-04-12 14:52:19 +00:00
Andrew Harding
8c5924d6ea satellite/payments/billing: add bonus transactions
- only applies to storjscan transactions
- applies a 10% bonus by default
- bonus transactions have a distinct source "type" to allow for
  filtering on the frontend

Fixes: https://github.com/storj/storj/issues/5702

Change-Id: I32d65f776c58bcb41227ff5bc77a8e4cb62a9add
2023-04-10 16:26:56 +00:00
Michal Niewrzal
8a50a3baa3 satellite/payments: rename 'stripecoinpayments' package to 'stripe'
Automatic rename. May require some more cleanups later.

Change-Id: I18220a4278056d25c41fb137832bb81f2b876ac1
2023-04-06 16:51:43 +00:00
Jeremy Wharton
f2ae202024 satellite/payments,web/satellite: separate UI cost estimates by partner
Components related to project usage costs have been updated to show
different estimations for each partner, and the satellite has been
updated to send the client the information it needs to do this.

Previously, project costs in the satellite frontend were estimated
using only the price model corresponding to the partner that the user
registered with. This caused users who had a project containing
differently-attributed buckets to see an incorrect price estimation.

Resolves storj/storj-private#186

Change-Id: I2531643bc49f24fcb2e5f87e528b552285b6ff20
2023-04-04 15:56:16 +00:00
Cameron
c2cd213c4f satellite/console: purchase package grants credit
Instead of granting a coupon when purchasing a package, grant credit.
This changes paymentsconfig.PackagePlan to use credit amount rather than
coupon ID. Add additional check to see if a paid invoice with the
description exists. If so, don't create and pay another invoice.

Change-Id: I81df24984c519c773db5fc8e9070bd7797070ec2
2023-03-31 22:29:54 +00:00
Cameron
a2e3247471 satellite/payments: add Balances interface
Add and implement interface to manage customer balances. Adds ability to
add credit to a user's balance, list balance transactions, and get the
balance.

Change-Id: I7fd65d07868bb2b7489d1141a5e9049514d6984e
2023-03-31 21:51:37 +00:00
Jeremy Wharton
e0bb410192 satellite/payments/stripecoinpayments: parallelize invoice methods
Invoicing-related payment service methods have been modified to send
Stripe API requests in parallel.

Additionally, randomness has been added to the Stripe backend wrapper's
exponential backoff strategy in order to reduce the effects of the
thundering herd problem, which arises when executing many simultaneous
API calls.

Resolves #5156

Change-Id: I568f933284f4229ef41c155377ca0cc33f0eb5a4
2023-03-31 17:14:22 +00:00
Cameron
21249e6c00 Revert "satellite/payments: add partnered field to coupon struct"
We are changing package plans to use credits instead of coupons.

This reverts commit 73ff35f160.

Change-Id: I1a5bc27a3a198e1aa09afbb06670dde776f66f36
2023-03-31 16:03:48 +00:00
Cameron
549732228d satellite/satellitedb: add package info to customers db
Add columns package_plan and purchased_package_at to stripe_customers
table and add methods to update and select these values from console
service and payments accounts.

Change-Id: I1e89909055cc3054bfb7baa33c9dca3dfdc7336e
2023-03-31 15:51:30 +00:00
Andrew Harding
f5e110f2aa satellite/satellitedb: support insert for many billing txs in one db tx
Implementing https://github.com/storj/storj/issues/5702 means adding a
bonus billing transaction for each storjscan transaction being recorded.
To do this idempotently, we need to the ability to for both the
storjscan and bonus transaction to be committed together.

This change updates the billing database to allow multiple billing
transactions to be inserted under the same database transaction.

Change-Id: I941864f47fc64d65aab076eec2e96fd04fcc7aac
2023-03-31 14:48:17 +00:00
Wilfred Asomani
e750f6f145 satellite/accountfreeze: change price threshold default
The default price threshold has been changed to 10000 cents. The help
text has also been modified to clarify that this value is in cents.

Change-Id: I3b605056c860a3afef7202950180bc8b863fe16a
2023-03-28 16:05:08 +00:00
Wilfred Asomani
fd1a94a84d satellite/accountfreeze: add debug logs
A debug log has been added to the autofreeze chore to show numbers of
invoices, users involved, users frozen, users warned and users bypassed
due to larger than config amount owed.

Issue: https://github.com/storj/storj/issues/5700

Change-Id: I4e628606fe234b6d239b76167a4781ca9e276308
2023-03-28 15:30:31 +00:00
Wilfred Asomani
ed70a03844 satellite/{console,db,analytics}: better warning handling
This handles cases where a user is warned and triggers payment for their
account. Previously, only a frozen account will trigger this payment,
and will be unfrozen on successful payment. Now, accounts in warning
state trigger payments and are removed from that state on successful payment.

Issue: https://github.com/storj/storj/issues/5691

Change-Id: Icc2107f5d256657d176d8b0dd0a43a470eb01277
2023-03-28 14:30:38 +00:00
Jeremy Wharton
01f0e602b4 satellite/payments/stripecoinpayments: retry API calls with exp backoff
A Stripe backend implementation has been added that uses an exponential
backoff strategy to retry failed API calls. This behavior can be
configured in the satellite config.

References #5156

Change-Id: I16ff21a39775ea331c442457f976be0c95a7b695
2023-03-22 07:20:27 -05:00
Wilfred Asomani
bf45e53169 satellite/{web,payments}: display correct stripe balance
This correctly displays the stripe balance in dollars, which was
previously displayed in cents.

Change-Id: Ifb14a63a90d3701201c616780cee466525c8be18
2023-03-17 11:54:08 -05:00
Jeremy Wharton
b95ef36541 satellite/payments/stripecoinpayments: add ctx to Stripe method calls
This commit ensures that all invocations of Stripe library methods
include a context. This allows us to control the timeout and
cancellation of the underlying HTTP requests made by the Stripe
library.

References #5156

Change-Id: I8ddb317f3f2cbb06cfab869fbebdaf2ad78b7999
2023-03-14 17:52:17 +00:00
Jeremy Wharton
73ff35f160 satellite/payments: add partnered field to coupon struct
A field has been added to the coupon struct indicating whether it is
associated with a partner's pricing package. This is required to
alter the appearance of partner coupons in the satellite frontend.

References storj/storj-private#172

Change-Id: Ie48ae3902aaa108abf9a399242a0cd98cb53d1c3
2023-03-13 02:54:26 -05:00
Wilfred Asomani
0177ef79da satellite/{console,analytics,accountfreeze}: send unfreeze event
This change sends an event to segment for when a user is unfrozen.
It also moves freeze and warning event triggers from the autofreeze
chore to the account freeze service.

Change-Id: I5c0522b921b7baf52d6db5eb7ef841c08644a461
2023-03-10 23:21:20 +00:00
Wilfred Asomani
b1d4763086 satellite/{web,payments}: show STORJ balance
This change adds a card to the billing overview page, which shows the
user's token balance from coinpayments.

Issue: https://github.com/storj/storj-private/issues/151

Change-Id: I11e295b48791b32b745cb7a11c5b4aad6b56618e
2023-03-10 13:01:15 +00:00
Vitalii
b6721633f1 satellite/payments: return public project ID for project charges
We should return public project id instead of regular one when quering project charges so that it is consistent on a client side.
This is a fix for an issue with displaying project name on a Billing screen.

Issue:
https://github.com/storj/storj/issues/5641

Change-Id: Ic0c544dbe7369aa88f3a7c97a2f5de5bc854e1fd
2023-03-06 22:50:21 +00:00
Egon Elbre
63fa386b0a satellite/payments/stripecoinpayments: avoid mock cross-talk in tests
The tests were using global variables for keeping the mock state, which
was indexed by the satellite ID. However, the satellite ID-s are
deterministic and it's possible for two tests end up using the same
mocks.

Instead make the mock creation not depend on the satellite ID and
instead require it being configured via paymentsconfig.

This fixes TestAutoFreezeChore failure.

Change-Id: I531d3550a934fbb36cff2973be96fd43b7edc44a
2023-03-03 20:20:48 +02:00
Wilfred Asomani
faeea88265 satellite/{db,analytics,payments}: add chore for auto account freeze
This change adds a new chore that will check for failed invoices and
potentially freeze corresponding accounts.
It makes slight modifications to stripemock.go and invoices.go (adding
stripe CustomerID to the Invoice struct).

Issue: https://github.com/storj/storj-private/issues/140

Change-Id: I161f4037881222003bd231559c75f43360509894
2023-03-01 09:31:27 +00:00
Jeremy Wharton
cbbd5ab1ef satellite/payments/stripecoinpayments: undo price override removal
Commit fb59974 disabled usage price overrides because of a failing
test. This change reenables it while resolving the issue that caused
the test to fail.

The previous version of the test passed Gerrit verification and was
merged, but it failed for the primary Jenkins pipeline after merge.

This is due to a difference in how the Jenkins build runs Cockroach
and Postgres for each pipeline.

This commit rewrites the test to be safe for concurrent execution by
ensuring any mutable variables are defined within each test so that
shared state across tests is reduced.

Change-Id: Ia4566c9cd2d698afdb2caa4b7e2808b17e18de4e
2023-02-24 16:54:51 +00:00
Cameron
8842985571 satellite/console/consoleweb: create purchase-package endpoint
Add new purchase-package endpoint to Server. The endpoint can be enabled
or disabled by a new config, --console.pricing-packages-enabled.
The purchase-package endpoint applies a coupon and adds and charges a
credit card if user's useragent is a partner with a configured package
plan.

github issue: https://github.com/storj/storj-private/issues/125

Change-Id: I0d6ccccd6874ddba360c45f338fd1c44f95e135a
2023-02-23 15:42:36 -05:00
Jeremy Wharton
fb5997484e satellite/payments/stripecoinpayments: remove usage price overriding
Project usage price overriding has been removed because it produces
incorrect results when tested. It should not be re-implemented until
the issues it causes are resolved.

Change-Id: Ic92eff374c9af4fea3bf32782a72303a7978b055
2023-02-23 13:36:59 +00:00
Cameron
19d4fcc530 satellite/console: return card from AddCreditCard
Change-Id: I1a2667d26e2864606cfafc21a146a6be02798715
2023-02-21 20:48:15 +00:00
Cameron
e2cf486fcb satellite/console: add Purchase method to console.Payments
Purchase collects a payment from user using the specified price,
description, and payment method. This is implemented at the lower layers
using the payments.Invoices interface. There are also additions to
stripecoinpayments stripemock to simulate errors returned from stripe
invoices New and Pay. If an invoice exists with the same description, if
it is a draft, it is deleted and a new one is created and paid. If it is
open, pay it and don't create a new one.

Change-Id: Ic3147434bc44a0777ecbedb3a4ed4c768eb02ea3
2023-02-21 20:10:42 +00:00
Cameron
26f80f8e26 satellite/payments: add Invoices Delete
Add Invoices method Delete to delete draft invoices.

Change-Id: I221c6208df98ab11e648d25b94c52a411bf65b9a
2023-02-21 17:54:42 +00:00
Cameron
78e68cdca2 satellite/payments: add constants for invoice status
Change-Id: Iaf94d57d99caff3d435a44c56bd47c7b715ff4c0
2023-02-21 17:04:23 +00:00
Cameron
d48f745668 satellite/payments: trigger errors in stripemock payment methods
stripecoinpayments.mockStripeClient implements the
stripecoinpayments.StripeClient interface which is used to interact with
stripe's APIs in production. We use it in tests to simulate API calls to
stripe. This change introduces new stripecoinpayments package level
constants: TestPaymentMethodsNewFailure and
TestPaymentMethodsAttachFailure. These can be passed as part of the
arguments their respective stripe mock methods to signal to the method
that it should return an error. This is useful so that we can test how
layers on top of the StripeClient interface handle errors.

Change-Id: Ib64c08ba1e91f31e755b66a1ad563c3b6e77f6f0
2023-02-16 10:00:20 -05:00
Cameron
8d9b61c78e satellite/console: ApplyCoupon and ApplyFreeTierCoupon
Add new console service payments methods ApplyCoupon and
ApplyFreeTierCoupon. ApplyCoupon applies a coupon to an account based on
the coupon ID passed to it. ApplyFreeTierCoupon applies the satellite
configured free tier coupon to the account.

Change-Id: Ic221092278553a79207ac2a0c9229c374d76c881
2023-02-16 10:00:20 -05:00
Jeremy Wharton
add3034b43 satellite/payments/stripecoinpayments: forbid replacing partner coupons
Users with a partner package plan should be unable to replace their
plan's coupon. This change enforces this behavior by rejecting coupon
application attempts from users that meet this criteria.

Change-Id: I6383d19f2c7fbd9e1a2826473b2f867ea8a8ea3e
2023-02-03 17:15:01 +00:00
Jeremy Wharton
091ed29935 satellite/payments/stripecoinpayments: make price overrides per-bucket
This change causes the bucket's partner info to be used rather than the
user's when calculating project usage prices. This ensures that users
who own differently-partnered buckets will be charged correctly for
usage based on the specific bucket they are utilizing.
according to the bucket's partner.

Related to storj/storj-private#90

Change-Id: Ieeedfcc5451e254216918dcc9f096758be6a8961
2023-02-01 23:17:25 +00:00