WordPress MicroPayments (CMMP) + External API Add-on - Use Case - Control Wallet From External Apps
Use Case - How to Control Wallet From External Apps
Note: This use case requires this to be installed and activated:
- WordPress MicroPayments - This document uses version 1.9.5
- MicroPayments External API Add-on - This document uses version 1.0.2
Video Use-Case
Introduction
The WordPress MicroPayments is a points and rewards plugin for WordPress that allows you to create digital wallets for your users, reward them with points, and let them pay for them using real money.
The MicroPayments External API Add-on, in turn, gives you the power to connect the plugin to other apps. As a result you can, for example, create an Android app with a button that adds points to a MicroPayments wallet.
Advanced
This add-on is aimed at users with sufficient know-how to set up the API integration between a WordPress plugin and their apps.
Back-end Example
TIP: Still New to WordPress MicroPayments?
This article focuses on the integrations with PeepSo. If you haven't already created the wallet system, read:
Use Case Assumptions
In this example use case guide, we'll cover how to set up wallets for you users and allow them to buy points with real money.
We consider that you have already bought the plugin, but not installed it.
It follows:
- Installing the plugin
- Setting up WordPress MicroPayments recap
- What you can do with this add-on
- Set Up
- How To Use This Add-on - Actions
- External wallet
- Response Format
Installing the Plugin and Add-on
The process is the same for all CM plugins.
- Download the add-on from your customer dashboard.
- Log in to WordPress and navigate to the WordPress Admin → Plugins settings.
- Click on Add New.
- Activate it and add the license.
Setting Up WordPress MicroPayments - Recap
If you still have question with these steps:
- Installing the plugin
- Setting up WordPress MicroPayments
- How users can obtain points
- Grant points for purchase
- Use points for discounts
- Translating the interface
- Shortcodes
- Reports
- Exporting wallets to CSV
- Adding or subtracting points periodically
- Troubleshooting
Then check the guide WordPress MicroPayments (CMMP) - Use Case - How to Allow Users to Buy Points Using Real Money.
What You Can Do With This Add-on
The MicroPayments External API Add-on allows you to connect your apps to 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.
Additional Resources
Installation
Installing an add-on works just as installing a plugin. The only requirement is that the base plugin (WordPress MicroPayments) has to be activated in order for the add-on to work.
Check the article for the base plugin: WordPress MicroPayments Plugin (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
- 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:
- Adding points to the wallet.
- 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
Setup the External API credentials. Head to Settings → External API tab. Here, check Open external API gateway and generate an API key.
- Generate the wallets.
Setup 2) Client Side
Head to Settings → External wallet tab.
- Past the API secure key that was just generated.
- Check the option Enable external wallet.
Add the URL of the main site including the http protocol to the field API host URL. (Example: https://www.site.com)
This completes the configuration!
Checking Connection
You can check the connection at any time by pressing the relevant button:
When You Add Points
Every time you add points from the main site, you should refresh the state by pressing the relevant 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 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 |