A free points management plugin for WordPress.
myCRED Logo
myCRED Logo
  • Chapters
    • Chapter I – Introduction
    • Chapter II – Getting Started
    • Chapter III – Add-ons
    • Chapter IV – Premium Add-ons
    • Chapter V – For Developers
    • Chapter VI – Reference Guides
  • Categories
    • Actions
    • Classes
    • Constants
    • Filters
    • Functions
    • Objects
    • Shortcodes
    • Hooks
    • Template Tags
  • Packages
    • mycred/api
    • mycred/badge
    • mycred/balance
    • mycred/banking
    • mycred/content
    • mycred/core
    • mycred/coupon
    • mycred/email
    • mycred/game
    • mycred/log
    • mycred/notice
    • mycred/payment
    • mycred/purchase
    • mycred/rank
    • mycred/transfer
  • Store
  • Download
Chapter I
Introduction
  1. The Plugin
  2. Points
  3. The Log
  4. Administration
  5. Automatic Points
  6. Multisites
    • Master Template
    • Central Logging
  7. Add-ons
  8. Supported Plugins
  9. BuddyPress
  10. Usage Examples
  11. Limitations
Chapter II
Getting Started
  1. Installation
  2. Point Type Settings
  3. Multiple Point Types
  4. Adjusting Balances
  5. Setup Hooks
  6. Import Data
    • Importing Balances
    • Importing Log Entries
    • Import CubePoints
  7. Export Data
  8. Widgets
  9. Shortcodes
  10. Optimization
  11. Uninstall
Chapter III
Add-ons
  1. Badges
    • Creating Badges
    • Manual Badges
    • Displaying Badges
    • Developer Resources
  2. Banking
    • Central Banking
    • Compound Interest
    • Recurring Payout
    • Developer Resources
  3. buyCRED
    • Selling Points
    • Add-on Setup
    • Payment Gateways
    • The Checkout Page
    • Pending Payments
    • Developer Resources
  4. Coupons
    • Creating Coupons
    • Redeeming Coupons
    • Coupon Management
    • Developer Resources
  5. Email Notifications
    • Add-on Setup
    • Creating Emails
    • Unsubscribe
    • Developer Resources
  6. Gateway
    • WooCommerce
    • WP E-Commerce
    • Event Espresso
    • Events Manager
    • Developer Resources
  7. Notifications
    • Troubleshooting
    • Developer Resources
  8. Ranks
    • Introduction
    • Add-on Setup
    • Create New Rank
    • Displaying Ranks
    • Developer Resources
  9. Sell Content
    • Add-on Setup
    • Manual Mode
    • Available Shortcodes
    • Troubleshooting
    • Developer Resources
  10. Statistics
    • Available Shortcodes
    • Settings
    • For Developers
  11. Transfers
    • Add-on Setup
    • Available Shortcodes
    • Transfer Messages
    • Transfer Types
    • Developer Resources
Chapter IV
Premium Add-ons
  1. The myCred Store
  2. buyCRED Gateways
    • Stripe
    • Payza
    • Wepay
    • PayFast
    • 2checkout
    • Coinbase
    • ComproPago
    • Paymentwall
    • Robokassa
    • CoinPayments
  3. Third-party Bridges
    • myCred Beaver Builder
    • myCred WCVendors
    • LifterLMS Plugin Integration with myCred
    • myCred Gutenberg
    • myCred Dokan
    • myCred Elementor
    • myCred for WPBakery Page Builder
    • myCred for UserPro
    • myCred for Users Ultra
  4. Games
    • myCred PacMan
    • myCred Learndash
    • Fortune Wheel Addon
    • Lottery Add-on
    • Scratch Cards Add-on
    • Custom Set for Scratch Card Add-on
  5. Enhancements
    • Level Cred Add-on
    • myCred Expiration Add on
    • myCred REST API
    • myCred Reset Point Add on
    • Progress Bar
    • Notifications Plus
    • Social Share Add on
    • Transfer Plus
    • Twilio Transfers
    • Video Add-on
    • Video Add-on for JW Player
    • BuddyPress Charges
    • Partial Payments – WooCommerce
  6. Store Gateways
    • Jigoshop
    • Easy Digital Downloads
    • WPMUDEV Fundraising
  7. Freebies
    • BP Group Leaderboards
    • myCred for Events Manager Pro
Chapter V
For Developers
  1. Introduction
  2. White Labeling
  3. Flowcharts
  4. Playing with Balances
  5. myCRED Objects
  6. Log API
  7. Hook API
  8. Module API
  9. Gateway API
  10. Remote API
    • Version 1.0
    • Version 2.0
  11. Front-end Encryption
Chapter VI
Reference Guides
  1. Log References
  2. Shortcodes
  3. Template Tags
  4. Globals
  5. Constants
  6. Actions
  7. Filters
  8. Objects
  9. Functions
  10. Classes
Remote API - version 1.0

The Remote API allows you to connect multiple myCred installations running on separate websites by sending action requests between them. You could use this to query a users balance on a different site or make remote transactions by for example building a payment gateway that myCred manages.

Note that the Remote API requires WordPress permalinks to be enabled.

All examples given in this documentation will be using the built-in functions that WordPress offers for convenience. You can use your own functions if you prefer.

Structure

The myCred Remote API is managed by the myCred_Remote class located in the includes directory of your myCred installation. This class comes with a large set of action and filter hooks which allows you to add / customize it’s functionality.

 

Remote API Setup

The remote API can be enabled / changed in your admin area by visiting the myCred > Settings page. If you do not see the “Remote API” tab, click on “Management” and make sure the checkbox is selected for “Enable the Remote API”. Click “Save Changes” and you now should have the “Remote API” tab available with a red icon (off). Enter your secret key or click “Generate Key” and set the URL address where API calls are to be accepted from. Calls made to any other URL will be ignored. Click “Save Changes” and your icon should now be green (on).

 

Supported Methods

The current version of the remote API supports GET, POST and JSON methods for communication between sites.

 

Supported Actions

GET

Retrieve a users current balance.

CREDIT

Add points to a users current balance.

DEBIT

Deduct points from a users balance.

PAY

Transfer points from one user to another.

Identifying Users

The remote api uses email addresses to identify users. This means that the user registered on site A must have registered with the same email address on site B in order for us to be able to get their balance from the other site.

 

Security Token

To prevent users to execute mischievous requests on your sites, each request must contain a security token. This security token is a md5 hash of the request combined with the secret key that you have to setup in order to use the API.

This means that all sites that are to be connected must be setup to use the same secret key! If you change the key on one website, you must change it on all other sites as well.

Action: GET

The GET action allows you to query a specific users balance.

You can use this to display a users balance from another site or to sync two or more sites to always have the same point balance. In order to query a users balance, you must provide the users email address as a minimum. If you are using myCred 1.4 or higher, you can also use the type attribute to request a specific point type balance.

For the GET action, you must hash the host, action and your secret key.

You can consult the myCred_Remote class documentation for error codes.

Example

$secret_key = 'mysecretkey';
$remote_url = 'http://siteb.com/api/';

$action     = 'GET';
$account    = 'john.doe@email.com';
$point_type = 'my_custom_type';
$host       = get_bloginfo( 'url' );
$token      = md5( $host . $action . $secret_key );

$request    = array(
	'method' => 'POST',
	'body'   => array(
		'action'  => $action,
		'account' => $account,
		'type'    => $point_type,
		'token'   => $token,
		'host'    => $host
	)
);

$response = wp_remote_post( $remote_url, $request );

Response

  • 0.00
    The amount formatted according to your sites myCred setup.
Action: CREDIT

The CREDIT action allows you to add points to a users account. It works the same way as the mycred_add function meaning you are required to provide a reference, the amount of points and a log entry at minimum in order for points to be awarded. Reference ID, point type (requires myCred 1.4 or higher) and data is optional.

For the CREDIT action, you must hash host, action, amount and your secret key.

You can consult the myCred_Remote class documentation for error codes.

Example

$secret_key = 'mysecretkey';
$remote_url = 'http://siteb.com/api/';

$action     = 'CREDIT';
$account    = 'john.doe@email.com';
$amount     = 10;
$ref        = 'reference';
$ref_id     = 0;
$entry      = 'Points for viewing video';
$data       = 'optional extra';
$point_type = 'my_custom_type';
$host       = get_bloginfo( 'url' );

$token      = md5( $host . $action . $amount . $secret_key );

$request    = array(
	'method' => 'POST',
	'body'   => array(
		'action'  => $action,
		'account' => $account,
		'amount'  => $amount,
		'ref'     => $ref,
		'ref_id'  => $ref_id,
		'type'    => $point_type,
		'entry'   => $entry,
		'data'    => $data,
		'token'   => $token,
		'host'    => $host
	)
);

$response = wp_remote_post( $remote_url, $request );

Response

Note that all response codes are submitted in capital letters and are not translatable.

  • DUPLICATE Your attempt has been executed before and is considered to be duplicate. You should utilize the data variable to make each entry unique.
  • COMPLETED The transaction was successfully completed.
  • FAILED Failed to transfer the funds. Note that the myCred_add filter is used here twice. Once when the amount is deducted from the sender and once when the amount is credited to the recipients account.
Action: DEBIT

The DEBIT action allows you to deduct points to a users account. It works the same way as the myCred_subtract function meaning you are required to provide a reference, the amount of points and a log entry at minimum in order for points to be awarded. Reference ID, point type (requires myCred 1.4 or higher) and data is optional.

For the DEBIT action, you must hash host, action, amount and your secret key.

You can consult the myCred_Remote class documentation for error codes.

Even if you want to deduct points, the amount should never be sent as a negative value! myCred will take care of this for you.

Example

$secret_key = 'mysecretkey';
$remote_url = 'http://siteb.com/api/';

$action     = 'DEBIT';
$account    = 'john.doe@email.com';
$amount     = -10;
$ref        = 'reference';
$point_type = 'my_custom_type';
$ref_id     = 0;
$entry      = 'Payment for movie tickets';
$data       = 'optional extra';
$host       = get_bloginfo( 'url' );

$token      = md5( $host . $action . $amount . $secret_key );

$request    = array(
	'method' => 'POST',
	'body'   => array(
		'action'  => $action,
		'account' => $account,
		'amount'  => $amount,
		'ref'     => $ref,
		'ref_id'  => $ref_id,
		'type'    => $point_type,
		'entry'   => $entry,
		'data'    => $data,
		'token'   => $token,
		'host'    => $host
	)
);

$response = wp_remote_post( $remote_url, $request );

Response

Note that all response codes are submitted in capital letters and are not translatable.

  • DUPLICATE
    Your attempt has been executed before and is considered to be duplicate. You should utilize the data variable to make each entry unique.
  • DECLINED
    The requested amount exceeds the amount a user has on their account. Note that the myCred_transfer_acc_limit filter is used here.
  • COMPLETED
    The transaction was successfully completed.
  • FAILED
    Failed to transfer the funds. Note that the myCred_add filter is used here twice. Once when the amount is deducted from the sender and once when the amount is credited to the recipients account.
Action: PAY

The PAY action allows you to transfer money from one account to another. First the user defined under the account variable is deducted the given amount and then added to the recipients account. You define the recipient under the to variable.

For the PAY action, you must hash host, action, amount, account, to and your secret key.

Example

$secret_key = 'mysecretkey';
$remote_url = 'http://siteb.com/api/';

$action     = 'PAY';
$from       = 'john.doe@email.com';
$amount     = 10.50;
$to         = 'sara@email.com';
$ref        = 'reference';
$ref_id     = 0;
$entry      = 'Payment for order #1234';
$data       = 'optional extra';
$point_type = 'my_custom_type';
$host       = get_bloginfo( 'url' );

$token      = md5( $host . $action . $amount . $from . $to . $secret_key );

$request    = array(
	'method' => 'POST',
	'body'   => array(
		'action'  => $action,
		'account' => $from,
		'amount'  => $amount,
		'to'      => $to,
		'ref'     => $ref,
		'ref_id'  => $ref_id,
		'type'    => $point_type,
		'entry'   => $entry,
		'data'    => $data,
		'token'   => $token,
		'host'    => $host
	)
);

$response = wp_remote_post( $remote_url, $request );

Response

Note that all response codes are submitted in capital letters and are not translatable.

  • DUPLICATE
    Your attempt has been executed before and is considered to be duplicate. You should utilize the data variable to make each entry unique.
  • DECLINED
    The sender does not have enough points to fulfill this transaction. Note that the myCred_transfer_acc_limit filter is used here.
  • COMPLETED
    The transaction was successfully completed.
  • FAILED
    Failed to transfer the funds. Note that the myCred_add filter is used here twice. Once when the amount is deducted from the sender and once when the amount is credited to the recipients account.

About myCred

myCred is a free, open-source and developer friendly points management tool for WordPress powered websites.

Download Rate Plugin

Documentation

  • Add-ons
  • Core Shortcodes
  • F.A.Q.
  • Tutorials
  • Third Party Plugins
  • Code Snippets

Support

  • Product Licenses
  • Customization
  • Support Forums
  • Plugin Changelog
  • Contact

Copyright 2013 - 2019 byWPExperts; All rights reserved. myCred is licensed under GPL 2.0

Terms & Conditions • Use of Cookies • Store Policy • Community Rules

Suggest Codex Example

You can submit suggestions for codex examples that you have available as a public gist. If you are a member on the mycred.me website, you can earn Tokens for each submission. To claim these Tokens, make sure you provide your mycred.me username.

Please make sure the example you submit is relevant and if you include documentation, it's provided in English.

logo
  • Chapters
    • Chapter I – Introduction
    • Chapter II – Getting Started
    • Chapter III – Add-ons
    • Chapter IV – Premium Add-ons
    • Chapter V – For Developers
    • Chapter VI – Reference Guides
  • Categories
    • Actions
    • Classes
    • Constants
    • Filters
    • Functions
    • Objects
    • Shortcodes
    • Hooks
    • Template Tags
  • Packages
    • mycred/api
    • mycred/badge
    • mycred/balance
    • mycred/banking
    • mycred/content
    • mycred/core
    • mycred/coupon
    • mycred/email
    • mycred/game
    • mycred/log
    • mycred/notice
    • mycred/payment
    • mycred/purchase
    • mycred/rank
    • mycred/transfer
  • Store
  • Download