accounts.js

Members

(constant) accounts#

Handles user specific accounts with **balance**s that increase with **deposit**s from receipt verified WebMonetization payments and are **deduct**ed when streaming media data to the client.
Source:

paywallThreshold#

paywallThreshold has two functions: 1. Speed up the inital load of media by allowing some content to be loaded before the wallet is ready to pay (this can take few seconds). 2. Create a "preview" mode where some content can be shown also to users that don't have wallet set up, while instructing them to set up a wallet once the initial balance has run out.
Source:

Methods

balance(userId) โ†’ {number}#

Get users specific account balance. Creates and returns initial amount for new users ("paywallThreshold"), if user don't exist.
Parameters:
NameTypeDescription
userIdstring
Source:
Returns:
users balance
Type
number

deposit(userId, amount) โ†’ {number}#

Increments user specific account with given amount.
Parameters:
NameTypeDescription
userIdstring
amountnumberamount to be deposited
Source:
Returns:
users balance after the deposit.
Type
number

spend(userId, amount) โ†’ {boolean}#

Deducts given amount from users account, if the accounts balance is equal or larger to the given amount.
Parameters:
NameTypeDescription
userIdstring
amountnumberto be spent
Source:
Returns:
true for succesfull action, false for failure.
Type
boolean