Acquire.Client._cheque module¶
-
class
Cheque[source]¶ Bases:
objectThis class acts like a real world cheque, except it can only be used to transfer money from a regular user to a service user’s account. This allows users to pay for services. This can be written by a user against one of their accounts, to be sent to a recipient service to pay for a named service. The recipient can send the cheque to the accounting service to trigger payment, upon which a CreditNote will be returned. Once receipted, payment will be complete.
-
accounting_service()[source]¶ Return the accounting service that will honour this cheque. Note that this will only return the service if it is trusted by the service on which this function is called
-
accounting_service_url()[source]¶ Return the URL of the accounting service that will honour this cheque
-
cash(spend, resource, receipt_within=3600)[source]¶ Cash this cheque, specifying how much to be cashed, and the resource that will be paid for using this cheque. This will send the cheque to the accounting service (if we trust that accounting service). The accounting service will check that the cheque is valid, and the signature of the item is correct. It will then withdraw ‘spend’ funds from the account that signed the cheque, returning valid CreditNote(s) that can be trusted to show that the funds exist.
If ‘receipt_within’ is set, then the CreditNotes will be automatically cancelled if they are not receipted within ‘receipt_within’ seconds
It is your resposibility to receipt the note for the actual valid incurred once the service has been delivered, thereby actually transferring the cheque funds into your account (on that accounting service)
This returns a list of the CreditNote(s) that were cashed from the cheque
-
static
from_data(data)[source]¶ Return a cheque constructed from the passed (json-deserialised dictionary)
-
read(spend, resource, receipt_by)[source]¶ Read the cheque - this will read the cheque to return the decrypted contents. This will only work if this function is called on the accounting service that will cash the cheque, if the signature on the cheque matches the service that is authorised to cash the cheque, and if the passed resource matches the resource encoded in the cheque. If this is all correct, then the returned dictionary will contain;
- {“recipient_url”: The URL of the service which was sent the cheque,
- “recipient_key_fingerprint”: Verified fingerprint of the service
- key that signed this cheque
“spend”: The amount authorised by this cheque, “uid”: The unique ID for this cheque, “resource”: String that identifies the resource this cheque will
be used to pay for,“account_uid”: UID of the account from which funds will be drawn “authorisation” : Verified authorisation from the user who
says they own the account for the spend- “receipt_by” : Time when we must receipt the cheque, or
- we will lose the money
}
You must pass in the spend you want to draw from the cheque, a string representing the resource this cheque will be used to pay for, and the time by which you promise to receipt the cheque after cashing
-
static
write(account=None, resource=None, recipient_url=None, max_spend=None, expiry_date=None)[source]¶ Create and return a cheque that can be used at any point in the future to authorise a transaction. If ‘canonical_url’ is supplied, then only the service with matching canonical url can ‘cash’ the cheque (it will need to sign the cheque before sending it to the accounting service). If ‘max_spend’ is specified, then the cheque is only valid up to that maximum spend. Otherwise, it is valid up to the maximum daily spend limit (or other limits) of the account. If ‘expiry_date’ is supplied then this cheque is valid only before the supplied datetime. If ‘resource’ is supplied then this cheque is only valid to pay for the specified resource (this should be a string that everyone agrees represents the resource in question). Note that this cheque is for a future transaction. We do not check to see if there are sufficient funds now, and this does not affect the account. If there are insufficient funds when the cheque is cashed (or it breaks spending limits) then the cheque will bounce.
-