/*
* On your action method just do something like this
*/
// Create a new GRPHPAPIClient object
$objGeniusReferralsAPIClient = new GRPHPAPIClient('YOUR_USERNAME', 'YOUR_API_TOKEN');
//preparing the data to be sent on the request
$arrAdvocate = array(
'advocate' => array(
"name" => "Jonh",
"lastname" => "Smith",
"email" => "jonh@email.com",
"payout_threshold" => 5
)
);
$objResponse = $objGeniusReferralsAPIClient->postAdvocate('my-store', $arrAdvocate);
$intResponseCode = $objGeniusReferralsAPIClient->getResponseCode();
// advocate successfully created
if($intResponseCode == 201){
//getting the advocate token from the Location header
$arrLocation = $objResponse->getHeader('Location')->raw();
$strLocation = $arrLocation[0];
$arrParts = explode('/', $strLocation);
$strAdvocateToken = end($arrParts);
//Updating the advocate currency
$arrParams = array('currency_code' => 'USD');
$objResponse = $objGeniusReferralsAPIClient->patchAdvocate('my-store', $strAdvocateToken, $arrParams);
$intResponseCode1 = $objGeniusReferralsAPIClient->getResponseCode();
if($intResponseCode1 == 204){
//currency successfully updated
// TODO: Save the reference between the new advocate and the customer on your local database.
// Use the $strAdvocateToken as a reference so that you can later use the method getAdvocate(...)
// to retrive the advocate data.
}
else{
// handle errors
}
}
else{
// handle errors
}