Charging and paying people repeatedly
The current version of charges.py will charge and pay people a cumulative amount each month, rather than just the amount required for that month.
It seems that some of the charging/payment logic needs to be stored somewhere and managed more rigorously. What's the MVC for that?
Transactions
Includes both charges and payments. There is one transaction per profile per month. It records the total amount charged, paid, or owed to/from that individual. The AdClicks are linked to the Transactions so it's possible to trace the activity. There is a job (run nightly) to update the Transactions for the current month.
- Month (is the first of the month that the payment applies)
- Date (date the actual payment is executed)
- Status (was it executed?)
- Type (charge or payment) - could later be expanded to e.g. refund
- Profile - the person being paid or charged
-
Create
advertisement_amount
-
Create
website_amount
- Amounts should default to zero
-
Add a
transaction_type
ofCURRENT
for the current month -
Remove the
PAY-IN
andPAY-OUT
transaction types - Make website payments negative
- Calculate a total amount dynamically from the two above
- Handle other kinds of transactions such as refunds
-
Merge
transaction_type
withstatus
Showing current amounts to user
- Show the user their current month advertisement charge total
- Show the user their current month website payment total
- Give the user the ability to view a time series chart of their advertisement clicks by ad
- Give the user the ability to view a time series chart of their website clicks by website
Changes to AdClicks
- advertisement_charge_transaction
- website_payment_transaction
Transaction Update job
Meant to be run nightly, it updates the Transactions for the current month with the newest AdClicks. Note that if a profile has both ads and web sites, both are included in the same transaction.
- Create new Transactions
- Update a Transaction if it already exists
- Enter amount charged
- Enter amount paid
- Limit to the current month
- Double-check that Transactions whose time/status has passed don't update
- View the results of recent job runs
- Automatically run the job nightly
- Incorporate a commission
Execute transactions job
- Test for expected API responses with the test API token (e.g. HTTP 200)
- Test for the balances of the different users with the test API token
-
Go through all the transactions with status
NEW
and find out which ones have negative and positivenet_amount
-
If it has a negative
net_amount
, run on the 1st of the month -
If it has a positive
net_amount
, run in the middle of the month to give time for the charge payments to execute (that way we don't lose money)
Transaction verification job
A job to confirm that the transactions agree with the adclicks for a given month