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.
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.
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:
The above example will not result in a match if you store numbers formatted:
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.
||A keyword that describes the action we want to take. There are two keywords supported by this plugin.
||The point amount we want to transfer. Can not contain empty spaces!|
||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!|
||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
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.
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.