Page MenuHomekolab.org

Implement a changelog to further the debiting of wallet balances
ClosedPublic

Authored by vanmeeuwen on Feb 25 2020, 9:08 AM.

Details

Summary

This differential maintains a changelog entry for every modification to an entitlement, as it happens.

After a period of time (most notably, 13 days, 14 days, 15 days, 1 month, 2 months, etc.), the expected charges can be calculated from that changelog.

There's a number of TODOs left;

  • Pro rata temporis calculation
  • Actual charging of the wallet.
  • Prediction of the next charge (when, what and how much)
  • Collate the 'creating' and 'charging' queries to ->sum() the values of the columns.
  • Evaluate the number of duplicate 'cost' columns
  • subscription period for the sku (i.e. domain registered with us -> yearly)
Test Plan
$ vendor/bin/phpunit tests/Feature/BillingTest.php

Diff Detail

Repository
rK kolab
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.

Event Timeline

vanmeeuwen requested review of this revision.Feb 25 2020, 9:08 AM
vanmeeuwen created this revision.
vanmeeuwen updated this revision to Diff 2329.Feb 25 2020, 9:11 AM
  • This was pointless
vanmeeuwen edited the summary of this revision. (Show Details)Feb 25 2020, 9:23 AM
vanmeeuwen updated this revision to Diff 2335.Feb 25 2020, 9:24 AM
  • Implement the pro rata temporis calculation
vanmeeuwen planned changes to this revision.Feb 25 2020, 1:22 PM

Testing shows this fails, I'll have to redo with another approach.

vanmeeuwen updated this revision to Diff 2386.Feb 27 2020, 9:45 AM
  • work
  • Renew the basics for billing
vanmeeuwen edited the summary of this revision. (Show Details)Feb 27 2020, 9:46 AM
vanmeeuwen updated this revision to Diff 2392.Feb 27 2020, 12:18 PM
  • Just use the relationship
  • The inverse of the same relationship
  • Do it without the changelogs table
vanmeeuwen updated this revision to Diff 2395.Feb 27 2020, 12:20 PM
  • Superfluous log
machniak added inline comments.
src/tests/Feature/Jobs/UserVerifyTest.php
46

It fails for me too sometimes. Maybe $user->fresh()->isImapReady() would fix it.

machniak added inline comments.Feb 27 2020, 9:07 PM
src/tests/Feature/Jobs/UserVerifyTest.php
46

No, it does not make sense.

vanmeeuwen marked 2 inline comments as done.Feb 28 2020, 11:16 AM

The test can be written "better", or at least in a way that is supposed to be more reliable.

vanmeeuwen updated this revision to Diff 2407.Feb 28 2020, 11:18 AM
  • Test userverify with a "guaranteed to be new" user, and a fake queue

Looks good for now.

src/app/Observers/PackageSkuObserver.php
20

You calculated this a few lines above.

src/app/Wallet.php
89

I guess we should use db transactions here. Also, I'm thinking that we may anyway need a changelog table to have easy access to what/when was charged?

vanmeeuwen marked 2 inline comments as done.Mar 3 2020, 1:03 PM
vanmeeuwen added inline comments.
src/app/Observers/PackageSkuObserver.php
20

hihi, indeed, because of the superfluous debug ;-)

src/app/Wallet.php
89

This would be in some sort of transactions table, for sure -- I just don't want a future use of cashier (stripe/braintree) to have us need to redo whatever that transactions table is.

vanmeeuwen updated this revision to Diff 2467.Mar 3 2020, 1:03 PM
vanmeeuwen marked 2 inline comments as done.
  • This was pointless
  • Implement the pro rata temporis calculation
  • work
  • Renew the basics for billing
  • Just use the relationship
  • The inverse of the same relationship
  • Do it without the changelogs table
  • Superfluous log
  • Test userverify with a "guaranteed to be new" user, and a fake queue
  • Remove superfluous debug statement and duplicate calculation
machniak accepted this revision.Mar 6 2020, 9:51 AM

I reviewed it again, I guess it's ready to be merged.

One note, at this project stage we anyway use migrate:refresh often (are we?), so I think that these database changes don't require a new migration file, they could be added to the file that creates the table.

This revision is now accepted and ready to land.Mar 6 2020, 9:52 AM
This revision was automatically updated to reflect the committed changes.