WordPress MicroPayments (CMMP) - Advanced - Filters Overview
Wallet - Transactions
Note: This guide is intended to be read by developers, as it talks about WordPress APIs. Learn more.
The WordPress MicroPayments filters allow to check and change the values of the wallets either assigned to users or using their wallet_id.
Wallet ID vs. Wallet Code
Wallets have two unique identifiers.
- Wallet Code - Unique string with 32 HEX characters. Example: ae010ac8c293c02b7f78b3758b377c64
- Wallet ID - Unique integer starting from 1, and increased incrementally with each new wallet. Examples: 1, 5, 20.
Check if wallet has enough points
This filter can be used to check if there's enough points in given wallet.
- Filter: wallet_has_enough_points
- Attributes: (array)
- wallet_id – ID of the checked wallet
- points – value of the points
Example: $hasEnoughPoints = apply_filters('wallet_has_enough_points', array('wallet_id' => '2', 'points' => 100));
Check if user has enough points
The filter can be used to check if there's enough points in the wallet assigned to the user.
- Filter: user_has_enough_points
- Attributes: (array)
- username – login of the checked user
- points – value of the points
Example: $hasEnoughPoints = apply_filters('user_has_enough_points', array('username' => 'dummy_user', 'points' => 100));
Check if user has enough points by user id
The filter can be used to check if there's enough points in the wallet assigned to the user.
- Filter: user_has_enough_points_by_user_id
- Attributes: (array)
- user_id – ID of the user
- points – value of the points
Example: $hasEnoughPoints = apply_filters('user_has_enough_points_by_user_id', array('user_id' => '4', 'points' => 100));
Withdraw points
The filter can be used to withdraw points from wallet. This can be useful if you want users to pay for some action like viewing your page, downloading a file, sending a form etc.
- Filter: withdraw_wallet_points
- Attributes: (array)
- wallet_id – ID of the checked wallet
- points – value of the points
Example: $pointsAfterWithdraw = apply_filters('withdraw_wallet_points', array('wallet_id' => '6', 'points' => 100));
Transferring points between users
This filter can be used to transfer points from one user to another. If you need to make an exchange of points between the users this is the filter you should use.
- Filter: transfer_points
- Attributes: (array)
- from – user_id which wallet will be withdrawn
- to – user_id which wallet will be charged
- amount – number of the points (integer)
Example: $hasEnoughPoints = apply_filters('transfer_points', array('from' => '1', 'to' => '2', 'amount' => 100));
Transferring points between wallets
This filter can be used to transfer points from one wallet to another. If you need to make a transaction between wallets, this is the filter you should use. Also this way you can make transfers between users anonymously.
- Filter: transfer_points_by_wallet_id
- Attributes: (array)
- from – ID of wallet which will be withdrawn
- to – ID of wallet which will be charged
- amount – value of the points
Example: $result = apply_filters('transfer_points_by_wallet_id', array('from' => '1', 'to' => '2', 'amount' => 100));
Charge wallet
This filter can be used in two ways:
- a) if you want to add points to the wallet,
- b) if you want to subtract points from the wallet,
Please take note that using this filter the points are not transferred anywhere, so it's either creating points or removing them completely.
- Filter: charge_wallet
- Attributes: (array)
- wallet_id – ID of the checked wallet
- amount – value of the points
This filter can be used in two ways: to add points, or to subtract them. All depends on the number passed as the amount:
- if it's positive (>0) - then the points will be added to the wallet
- if it's negative (<0) - then the points will be removed/subtracted from the wallet
Example: $grantPoints = apply_filters('charge_wallet', array('wallet_id' => '1', 'amount' => 100));
Charge user wallet
This filter works the same way as the charge_wallet the only difference is that instead of requiring the wallet_id you can use the user id. Of course it will only work if the wallets are assigned to the users.
- Filter: charge_user_wallet
- Attributes: (array)
- user_id – user_id which will be charged
- amount – value of the points
This filter can be used in two ways: to add points, or to subtract them. All depends on the number passed as the 'amount':
- if it's positive (>0) - then the points will be added to the wallet
- if it's negative (<0) - then the points will be removed/subtracted from the wallet
Example: $pointsAfterCharge = apply_filters('charge_user_wallet', array('user_id' => '1', 'amount' => 100));
Wallet – information
Filters allowing to obtain information about the wallet.
- Filter: cm_micropayments_user_wallet_id
- Returns the id (int) of the wallet for given user_id
- Returns: wallet_id (int)
- Example: $walletId = apply_filters('cm_micropayments_user_wallet_id', 1);
- Filter: cm_micropayments_user_wallet_code
- Returns the code (string) of the wallet for given user_id
- Returns: wallet_code (string)
- Example: $walletCode = apply_filters('cm_micropayments_user_wallet_code', 1);
- Filter: cm_micropayments_user_wallet_url
- Returns the permalink to the User’s wallet page
- Returns: url (string)
- Example: $walletPageUrl = apply_filters('cm_micropayments_user_wallet_url', 1);
- Filter: cm_micropayments_get_wallet_by_code
- Returns the wallet object for given code
- Returns: wallet (object)
- Example: $walletObj = apply_filters('cm_micropayments_get_wallet_by_code', 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX');
More information about the WordPress MicroPayments plugin Other WordPress products can be found at CreativeMinds WordPress Store |
|
Let us know how we can Improve this Product Documentation Page To open a Support Ticket visit our support center |