Issuing Bonuses to Advocates Using the SDK

This guide explains how to award bonuses to your advocates using the Genius Referrals platform with the PHP SDK. After a referral completes a specified action in your application, you can issue a bonus to the advocate. Follow these simple steps to complete the process.

Prerequisites

  1. Register on the Platform: Sign up for Genius Referrals and obtain your API credentials.
  2. Genius Referrals SDK: Ensure you have installed the Genius Referrals SDK for PHP.
Step 1: Client Configuration
Set up the Genius Referrals SDK client in your PHP application.
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);
Step 2: Find the Referral
Prepare the necessary data to request the bonus.
<?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);
Please Note: You need the referral's email referralEmail to process and issue the bonus.
Step 3: Submit the Request to Issue the Bonus
Send the request to award the bonus to the advocate.
<?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.
}
Complete Code Example
<?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.
}
Was this page helpful?
LANGUAGE