Introduction

Estimated reading: 6 minutes 430 views

Introduction

Without this plugin, a transfer from one user to another is done via the mycred_transfer or mycred_send shortcodes. This plugin adds a third option where transfers are executed via SMS messages.

 

By sending a specially designed SMS message to a given number, a user can request that a sum of points from their account is transferred to another user on your website. Based on your setup, you can send confirmation SMS messages back to users informing them of the results of their request.

 

One big advantage of transferring via SMS messages is that the user does not need to be logged in on the website in order to transfer points. It can even be used as a point of sale, where the buyer can “pay” a seller by sending an SMS message instead of having to login to the website and use a shortcode.

Phone Numbers

In order for this to work, we need to know each users phone number. This is so when the SMS message is received by us, we know who it belongs to. If we do not know the sender, we can not make a transfer, just like if a user is not logged in on your website, we do not know who they are.

 

So in order for this plugin to work, we need to know where each users phone number is stored in our database. Usually, user related details are stored in our user meta table so this plugin was built for looking for phone numbers here. If your website stored phone numbers somewhere else, you will need to add customization to this plugin to get it to work.

 

If you use BuddyPress, the meta field can be a BuddyPress Extended Profile Field. Just nominate the name of the Field you created to hold the phone number.

Number Format

Twilio will transmit phone numbers formatted with the country code appended to the beginning and without any empty spaces or special characters. This might not be the way you store phone numbers in your database.

 

When the plugin tries to find the phone number Twilio sends with the phone numbers stored in your database, it will search for exact matches. This might not work well if you store phone numbers without a country code or even worse, if phone numbers are stored formatted. In these cases, we can use the mycred_twilio_phone_number filter to format the number so a number can be matched.

 

Example of how a North American number is submitted by Twilio:

+11234567890

The above example will not result in a match if you store numbers formatted:

(123) 456-7890

The SMS Message

Our next challenge is the SMS message itself. While we get the senders ID from their phone number, we will also need to know how much points we want to send, to whom and optionally allow a message to be added to the transfer.

 

To help us out, the plugin provides a message structure that your users need to use for transfers to work correctly.

Position Detail Description
1st ACTION A keyword that describes the action we want to take. There are two keywords supported by this plugin. CANCEL which allows you to cancel the transfer and a keyword that you get to select to indicate that we want to make a transfer. It could be anything but should be something your users can easily remember like SEND or PAY etc. Can not contain empty spaces!
2nd AMOUNT The point amount we want to transfer. Can not contain empty spaces!
3rd RECIPIENT Next we need to identify the recipient. This can be a users ID, username or email. You will have to decide which one to use when you setup this plugin. Can not contain empty spaces!
4th MESSAGE Optional message to add to the log entry. This is optional and not required to be used.

Example: Send 10 points to a user with the username john without any message. In this example we have set to indicate a transfer using the keyword “PAY”.

PAY 10 john

SMS Replies

Once a transfer is completed, or if we run into issues, we need to inform the sender about this. This is done by sending SMS messages back to the user, informing them of the status of the request. These messages are set in your plugin settings.

Example: Transfer 150 coins to the user with the username sara.
 

Check Balances

As an added feature, your users can also check their balances by sending a SMS message. By default, this is done by sending the action keyword CHECK but you can change this to any unique word. Just make sure this is not the same action keyword you set for transfers or cancels.

 
Example how you can request your current balance. The keyword can be set to anything you want.