Emitir Bonificaciones a los Promotores via SDK

Aprende cómo otorgar bonificaciones a tus promotores después de que uno de sus referidos complete una acción en tu aplicación. Una vez que hayas identificado la acción de activación, puedes proceder a otorgar la bonificación. Esta guía te mostrará cómo hacerlo utilizando la SDK de PHP.

Requisitos Previos

  1. Registro en la plataforma: Regístrate en Genius Referrals y obtén tus credenciales de API.
  2. SDK de Genius Referrals: Asegúrate de haber instalado la SDK de Genius Referrals para PHP.
Paso 1: Configuración del Cliente
Configura el cliente de la SDK de Genius Referrals en tu aplicación PHP.

Ejemplo de Configuración del Cliente en 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);

Paso 2: Buscar al referido
Prepara los datos necesarios para la solicitud de bonificación.

<?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);

Nota: Debe tener a mano el correo electrónico del referido referralEmail para poder procesarlo y emitir la bonificación.
Paso 3: Enviar la Solicitud para Emitir la Bonificación
Envía la solicitud para otorgar la bonificación al promotor.

<?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.
}

Todo el Código Junto

<?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.
}
¿Fue útil esta página?
LANGUAGE