Snippets

Monil Gandhi Seed Personnel

Created by Monil Gandhi
<?php
use Braango\braangomodel as model;
use Braango\braangomodel\RequestHeader as rhdr;

require_once (__DIR__ . '/../../vendor/autoload.php');

/**
 *
 * @author braango
 *        
 *         Sample code showing how to create subDealer
 *        
 */

// TEST auth token. Please contact
// sales@braango.com to have one
// created for you
Braango\Configuration::getDefaultConfiguration()->setApiKey('auth_token', 'ISNWF0P30WM0CMK');

$api_instance = new Braango\braangoapi\PersonnelsApi();

// string | id of _sub_dealer_
$subdealerid = "subdealers2002";

// Braango\braangomodel\PersonnelRequestInput |
$personnelRequestInput = new \Braango\braangomodel\PersonnelRequestInput();

$typeAdfCRMEmail = FALSE;


/*
 * { "api_key": "ISNGvAzwuy4X7vAqrtV", "id": "any value",
 * "account_type": "partner" }
 */
$hdr = new rhdr();

// Set the account type to partner for
// virtual dealer and partner hosted
// accounts
$hdr->setAccountType("partner");

// dealer_api_key returned
// when partner_dealer was created
$hdr->setApiKey("ISNMdzuNiKG7jhl9d9v");

// ID that will be reflected back
$hdr->setId("create-personnel-s2002r5");

$personnelRequestInput->setHeader($hdr);

$personnelBody = new model\PersonnelRequest();

// Required field . Used for
// SMS login in to the UI
// For Braango Enterprise, this is don't care
// unless partner implements UI with SMS login
$personnelBody->setSmsLogin(FALSE);

$personnelBody->setPersonnelName("personnel rep5");

/*
 * This is a user name created while signing this personnel up.
 * Typically this user name can be used to log into the braango UI.
 * However for whitelabel product, it is expected that this will be used
 * for single signon with respect to dealer account on partner system.
 * i.e. it is expected that partner will pass on the same user name that
 * dealer has on its system to give seamless integration experience.
 */
$personnelBody->setUserName("subdealers2002r5");

/*
 * Password will be encrypted with SHA-25 and base64 encoded and stored
 * internally within the braango system. pattern:
 * ^(?=^.{6,10}$)(?=.*\d)(
 * ?=.*[a-z])(?=.*[A-Z])(?=.*[!@#$%^&*()_+}{&quot
 * ;:;'?/>.<,])(?!.*\s).*$
 *
 * Used for single sign on. needs to 6-10 characters with one capital,
 * one numberal and one special character
 */
$personnelBody->setPassword("test1T$");

$personnelBody->setEmail("s2002r3@subdealer2002r5.com");

// If email specified is that for
// CRM email (ADF XML compliant)

$personnelBody->setTypeAdfCrm($typeAdfCRMEmail);

/*
 * Number where dealer's root account can be reached via SMS
 * for leads
 *
 * pattern:^\(?(\d{3})\)?[- ]?(\d{3})[- ]?(\d{4})$
 */
$personnelBody->setPhoneNumber('4089763437');

/*
 * Number where dealer's root account can be reached via SMS
 * for leads
 *
 * pattern:^\(?(\d{3})\)?[- ]?(\d{3})[- ]?(\d{4})$
 */
$personnelBody->setSmsNumber('4089763437');

// Subscribe to the group
$personnelBody->setGroup('s2002r5g');

// OPTIONAL FIELDS

// List of dealer banners. Braango will
// randomly choose one when sending
// message to dealer via SMS
//
$dealerBanners = array(
    "s2002r5db1"
);
$personnelBody->setDealerBanners($dealerBanners);

// List of client banners. Braango
// will randomly choose one when
// sending dealer messages to client
$clientBanners = array(
    's2002r5cb1'
);

$personnelBody->setClientBanners($clientBanners);

// List of dealer footers. Braango will
// randomly choose one when sending
// message to dealer via SMS
//
$dealerFooters = array(
    's2002r5df1'
);
$personnelBody->setDealerFooters($dealerFooters);

// List of client footers. Braango
// will randomly choose one when
// sending dealer messages to client
$clientFooters = array(
    's2002r5cf1'
);
$personnelBody->setClientFooters($clientFooters);

// List of supervisor banners. Braango
// will randomly choose one when
// sending messages to supervisor
$supervisorBanners = array(
    's2002r5sb1'
);
$personnelBody->setSupervisorBanners($supervisorBanners);

// List of supervisor footers. Braango
// will randomly choose one when
// sending messages to supervisor
$supervisorFooters = array(
    's2002r5sf1'
);
$personnelBody->setSupervisorFooters($supervisorFooters);

$personnelRequestInput->setBody($personnelBody);

try {
    $result = $api_instance->createPersonnel($subdealerid, $personnelRequestInput);
    
    if ($result != null) {
        // Extract out response hdr and bdy
        $rspHdr = $result->getHeader();
        
        if ($requestHdr = ! null) {
            $rspId = $rspHdr->getId();
            $braangoRequestId = $rspHdr->getIsnRequestId();
            print_r("Response ID = " . $rspId . ", API Request Id = " . $braangoRequestId . "\n");
        }
        
        $rspBdy = $result->getBody();
        if ($rspBdy != null) {
            $status = $rspBdy->getStatus();
            
            // Typically this value should be always SUCCESS else exception will be thrown
            // Sometimes, this can be WARNING to indicate if any resource conflicted or not
            // In case of SUCCESS or WARNING, resources are always created (excepting warned sub-resources)
            print_r("Status = " . $status . "/n");
            
            $salesPersonId = $rspBdy->getData()->getSalesPersonId();
            
            print_r("SUCCESS : SalespersonID = " . $salesPersonId);
        }
    }
} catch (Exception $e) {
    echo 'Exception when calling PersonnelsApi->createPersonnel: ', $e->getMessage(), PHP_EOL;
}
?>

Comments (0)

HTTPS SSH

You can clone a snippet to your computer for local editing. Learn more.