CM MicroPayments (CMMP) - Add-on - External API


MicroPayments - External API Add-on

Back to User Guides

Requirement

In order to use this add-on, you need to have the CM MicroPayments WordPress Plugin installed and activated.

Table of Contents

  1. What is This Addon
  2. Installation
  3. Set Up
  4. How To Use This Add-on - Actions
    1. Check if Wallet has Enough Points
    2. Withdraw points
    3. Charge/Top up Wallet
  5. External wallet
  6. Response Format

What Is This Add-on

The MicroPayments External API Add-on allows you to connect your apps to MicroPayment wallets. This works by using WordPress REST API methods.

Allowed HTTPs requests

  • GET
  • POST

Supported actions

  • Check if wallet has enough points
  • Withdraw points
  • Charge wallet

You can also allow external calls to the site to perform those actions (added in version 1.0.2)

This add-on is aimed at users with sufficient know-how to set up the API integration between a WordPress plugin and their apps. 

Additional resources


Installation

Installing an add-on works just as installing a plugin. The only requirement is that the base plugin (MicroPayments) has to be activated in order for the add-on to work.

Check the article for the base plugin: CM MicroPayments (CMMP) - Installation


Set Up

To start using the add-on, head to Admin Dashboard → CM Micropayment Platform → Settings → External API tab.

  • Enable the "Open external API gateway" option to allow external requests, effectively enabling this add-on
  • Click the "Generate secure key" button. You will use this key as an argument. Clicking on it again will generate a new one

How To Use This Add-on

This is the list of actions with their respective URLs and arguments.

Actions

1) Check if Wallet has Enough Points

Use: Check if there's enough points in a given wallet.
URL: your_domain/wp-json/cmmpexapi/v1/wallet_has_enough_points
Arguments:
  • wallet_id - name of the checked wallet OR email - email of user who has the checked wallet
  • points (required) - value of the points
  • key (required) - secure key

Examples:

  • your_domain/wp-json/cmmpexapi/v1/wallet_has_enough_points?wallet_id=123&points=10&key=abcde
  • your_domain/wp-json/cmmpexapi/v1/wallet_has_enough_points?email=john@doe.com&points=10&key=abcde

2) Withdraw Points

Use: Withdraw points from wallet. This can be useful if you want users to pay for an action such as viewing your page, downloading a file, sending a form etc.

URL: your_domain/wp-json/cmmpexapi/v1/withdraw_wallet_points

Arguments you need to pass:

  • wallet_id - name of the checked wallet OR email - email of user who has the checked wallet
  • points - value of the points
  • key  - secure key

Examples

  • test.com/wp-json/cmmpexapi/v1/withdraw_wallet_points?wallet_id=123&points=10&key=abcde
  • test.com/wp-json/cmmpexapi/v1/withdraw_wallet_points?email=john@doe.com&points=10&key=abcde

3) Charge/Top up Wallet

Important: Note that, by using this API method, the points are not transferred anywhere. They are either created or removed altogether.

Uses: Can be used in two ways:

  1. Adding points to the wallet
  2. Subtracting points from the wallet

URL: your_domain/wp-json/cmmpexapi/v1/charge_wallet

Required arguments:

  • wallet_id - ID of the checked wallet OR email - email of user who has the checked wallet
  • points - value of the points. A positive value (>0) adds points to the wallet; a negative value (<0) subtracts points from it
  • key - secure key

Examples

  • your_domain/wp-json/cmmpexapi/v1/charge_wallet?wallet_id=123&points=-10&key=abcde
  • your_domain/wp-json/cmmpexapi/v1/charge_wallet?email=john@doe.com&points=-10&key=abcde


External Wallets

Starting from version 1.0.2, it's possible to add calls from external site to manage wallets. This requires configuration in both server and client sides.

Setup 1) Server Side

  1. Setup the External API credentials.

    Head to Settings → External API. Here, check Open external API gateway and generate an API key.
  2. Generate the wallets

Setup 2) Client Side

  1. Head to Settings → External wallet
  2. Past the API secure key that was just generated
  3. Enable external wallet
  4. Add the URL of the main site including the http protocol. (Example: https://www.site.com)

This completes the configuration!

Checking Connection

You can check the connection at any time by pressing the button

When You Add Points

Every time you add points from the main site, you should refresh the state by pressing the button

Don't Close The Browser Window

If you have many wallets, refreshing the state might take several minutes.


Response Format

The response format is JSON.

  • "success" - true or false
  • "message" - explain what is wrong if "success" is false

Example 

  • {"success":false,"message":["Wallet doesn't have enough points"]}{"success":true,"message":[]}
  • {"success":false,"message":["Please provide wallet id or email and points"]}
  • {"success":false,"message":["Please provide a secure key"]}


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