Snippets

Monil Gandhi Create Braango Number

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
 *    one braango number for subdealer
 *    for given group
 *
 *
 */

// 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\BraangonumbersApi();

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

// string | Group for which the braango number is being created
$group = "DEFAULT"; 

// Braango\braangomodel\BraangoNumberCreateInput | 
$braangoNumberCreateInput = new \Braango\braangomodel\BraangoNumberCreateInput(); 

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

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


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

// ID that will be reflected back

$hrd->setId(" create-braango-number");

$braangoNumberCreateInput->setHeader($hrd);

$braangoNumberCreateInputBody = new model\BraangoNumberCreateInputBody();

// All all the personnel in represented
// by this group for this sub-dealer

$braangoNumberCreateInputBody->setAllPersonnel(TRUE);

$braangoNumberCreateInputBody->setFakeBraangoNumber(TRUE);

$braangoNumberCreateInput->setBody($braangoNumberCreateInputBody);
try {
    $result = $api_instance->createBraangoNumber($subdealerid, $group, $braangoNumberCreateInput);
    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");
            
            $braangoNumberOutputBodyData = $rspBdy->getData();
            print "Braango Numbers: ";
            print_r($braangoNumberOutputBodyData->getBraangoNumberList());
        }
    }
} catch (Exception $e) {
    echo 'Exception when calling BraangonumbersApi->createBraangoNumber: ', $e->getMessage(), PHP_EOL;
}
?>

Comments (0)