Before you start
You need:
- A ledger and an account for the customer, here with the alias
@customer_001. - An account that receives the fees, here with the alias
@fee_revenue. - The
account-plansandfee-chargespermissions on Midaz. See Permissions.
scheme. On a ledger with route validation, give each fee an accounting block too. See Accounting routes.
The examples use these shell variables. Every UUID is a placeholder. Use the values from your own environment.
1
Create the account plan
Send the plan to Create an account plan. The fee Midaz answers Keep the
tedSent charges 7.90 for each TED that the account sends, after 2 free TEDs in the month. The fee paperStatement charges 3 for each paper statement, after 1 free statement in the month.201 with the plan and its version 1. It fills in the defaults referenceAmount and period:id of the plan:2
Assign the plan to the account
Send the plan to Assign an account plan to an account:Midaz answers From now on, the fee packages of the ledger do not charge
200 with the active assignment:@customer_001 on the /v2 transactions it sends.3
Send a transaction and read its fee
Send a TED from the account with Create a Transaction using the v2 direct model. The The The third TED of the month is past the free quota. Its item has
scheme is TED, so the fee tedSent matches:201 response has accountPlanFees. The first TED of the month uses a free unit:"outcome": "charged", "unit": 3, and "amount": "7.9". The account sends 107.9: the 100 of the TED and the fee, which goes to @fee_revenue.A transaction with another scheme, or without one, gets "outcome": "no_match". The account pays no fee on it.Keep accountPlanFees from the create response. The reads of the transaction do not return it.4
Read the usage of the month
Read the units of the account with Get the account plan usage of an account:After three TEDs, the response is:
period.start and period.end are the month in the plan timezone, in UTC.5
Charge service fees
Charge two paper statements with Charge service fees to an account. Send an Midaz answers The fee transaction debits 3 from
X-Idempotency key, and send the same key when you retry the same charge:201. The first statement uses the free unit, and the second costs 3:@customer_001 and credits it to @fee_revenue. To undo the charge in the same month, revert that transaction.6
Create a new version
Raise the free TEDs to 5 from November. Send only the field that changes to Update an account plan:Midaz creates version 2 with both fees, and
tedSent has freeQuota: 5. Before November 1 in the plan timezone, the response and the transactions use version 1, and currentVersion is 2.7
End the assignment
To take the account off the plan, use End the account plan assignment of an account:Midaz answers
204. The fee packages of the ledger apply to the account again.
