Issuing Bonuses to Advocates Using the SDK
Prerequisites
Client Configuration Example in PHP:
<?php
require_once "../vendor/autoload.php";
$contentType = "application/json"; // The content type
$xAuthToken = "2f266b71b8038e674ba93b6"; // Your API Token, you can get your token here https://app.geniusreferrals.com/en/settings/api-access
$accountSlug = 'sandbox';
$client = new GeniusReferralsLib\GeniusReferralsClient($contentType, $xAuthToken);
<?php
// 1. Find referral by email
$referralEmail = 'jane.doe@example.com'; // The referral's email
$advocatesController = $client->getAdvocates();
$referralResponse = $advocatesController->getAdvocates($accountSlug,1,1, 'email::' . $referralEmail);
<?php
// 2. Process the referral to issue a bonus to the referring advocate.
if($referralResponse->data->total == 1){ // Found the referral?
$referral = $referralResponse->data->results[0];
$bonusesModel = new \GeniusReferralsLib\Models\Bonuses();
$bonusesModel->advocateToken = $referral->token; // This is the token of the referral
$bonusesModel->paymentAmount = 1000; // This is the amount the referral has paid.
$bonusesModel->reference = 'Order 373625236273'; // This is an external reference e.g. order id, transaction id, etc.
$bonusesForm = new \GeniusReferralsLib\Models\BonusesForm($bonusesModel);
$bonusesController = $client->getBonuses();
$bonus = $bonusesController->postBonus($accountSlug, $bonusesForm);
}else{
// We couldn't find the referral, nothing to do here.
}
<?php
require_once "../vendor/autoload.php";
$contentType = "application/json"; // The content type
$xAuthToken = "2f266b71b8038e674ba"; // Your API Token, you can get your token here https://app.geniusreferrals.com/en/settings/api-access
$accountSlug = 'sandbox';
$client = new GeniusReferralsLib\GeniusReferralsClient($contentType, $xAuthToken);
// 1. Find referral by email
$referralEmail = 'jane.doe@example.com'; // The referral's email
$advocatesController = $client->getAdvocates();
$referralResponse = $advocatesController->getAdvocates($accountSlug,1,1, 'email::' . $referralEmail);
// 2. Process the referral to issue a bonus to the referring advocate.
if($referralResponse->data->total == 1){ // Found the referral?
$referral = $referralResponse->data->results[0];
$bonusesModel = new \GeniusReferralsLib\Models\Bonuses();
$bonusesModel->advocateToken = $referral->token; // This is the token of the referral
$bonusesModel->paymentAmount = 1000; // This is the amount the referral has paid.
$bonusesModel->reference = 'Order 373625236273'; // This is an external reference e.g. order id, transaction id, etc.
$bonusesForm = new \GeniusReferralsLib\Models\BonusesForm($bonusesModel);
$bonusesController = $client->getBonuses();
$bonus = $bonusesController->postBonus($accountSlug, $bonusesForm);
}else{
// We couldn't find the referral, nothing to do here.
}