CM MicroPayments (CMMP) - Filters - Overview

Wallet - transactions

Filters allowing to check and change the values of the wallets either assigned to users or using their name/wallet_id.

Check if wallet has enough points

This filter can be used to check if there's enough points in given wallet.

  • Filter name: wallet_has_enough_points
  • Attributes: (array)
    • wallet_id – name of the checked wallet
    • points – value of the points

Example: $hasEnoughPoints = apply_filters('wallet_has_enough_points', array('wallet_id' => '372yfgf3gfg23gf32', '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 name: 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 name: 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' => '123', '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 name: withdraw_wallet_points
  • Attributes: (array)
    • wallet_id – name of the checked wallet
    • points – value of the points

Example: $pointsAfterWithdraw = apply_filters('withdraw_wallet_points', array('wallet_id' => '372yfgf3gfg23gf32', '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 name: 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' => '123', 'to' => '123', 'points' => 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 name: 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('wallet_has_enough_points', array('from' => '372yfgf3gfg23gf32', 'to' => '654jfbs64gziegw1azo', 'points' => 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 name: charge_wallet
  • Attributes: (array)
    • wallet_id – ID of the checked wallet (string)
    • amount – value of the points (integer)

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' => 'XXXXXXXXXXXXXXX', '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 name: charge_user_wallet
  • Attributes: (array)
    • user_id – user_id which will be charged (integer)
    • amount – value of the points (integer)

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' => '372yfgf3gfg23gf32', 'amount' => 100));

Wallet – information

Filters allowing to obtain information about the wallet.

  • Filter name: cm_micropayments_user_wallet_id
  • Returns the id (int) of the wallet for given user_id
  • Returns: wallet_id (int)
  • Example: $walletId = apply_filter('cm_micropayments_user_wallet_id', 1);
  • Filter name: cm_micropayments_user_wallet_code
  • Returns the code (string) of the wallet for given user_id
  • Returns: wallet_code (string)
  • Example: $walletCode = apply_filter('cm_micropayments_user_wallet_code', 1);
  • Return: string
  • Filter name: cm_micropayments_user_wallet_url
  • Returns the permalink to the User’s wallet page
  • Returns: url (string)
  • Example: $walletPageUrl = apply_filter('cm_micropayments_user_wallet_url', 1);
  • Filter name: cm_micropayments_get_wallet_by_code
  • Returns the wallet object for given code
  • Returns: wallet (object)
  • Example: $walletObj = apply_filter('cm_micropayments_get_wallet_by_code', 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX');

More information about the CM MicroPayments WordPress  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