/** * */ package com.braango.virtualdealer; import java.util.ArrayList; import java.util.List; import java.util.Map; import java.util.UUID; import com.braango.client.ApiCallback; import com.braango.client.ApiClient; import com.braango.client.ApiException; import com.braango.client.braangoapi.PersonnelsApi; import com.braango.client.braangomodel.HeaderResponse; import com.braango.client.braangomodel.PersonnelOutputWrapper; import com.braango.client.braangomodel.RequestHeader; import com.braango.client.braangomodel.SubDealerBody; import com.braango.client.braangomodel.SubDealerRequestInput; /** * @author braango * * Sample code showing how to create subDealer * */ public class CreateSubDealer { static String basePath = "https://testapi2.braango.com/v2/braango"; /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub ApiClient braangoApiClient = new ApiClient(); String authToken = "ISNWF0P30WM0CMK"; // TEST auth token. Please contact // sales@braango.com to have one // created for you braangoApiClient.setBasePath(basePath); // Set the auth_token for api client to // interact with Braango system braangoApiClient.setApiKey(authToken); // Api key is authorization to to access // resources within braango system // // This key is different than auth_token // that is used to validate the master account String apiKey = "ISNfTMNOumV3xYNDd2g"; PersonnelsApi personnelsApi = new PersonnelsApi(braangoApiClient); // Create subDealer . subDealer is actually the business // that virtual dealer is hosting. // ApiCallback callBack = new ApiCallback() { @Override public void onUploadProgress(long bytesWritten, long contentLength, boolean done) { System.out .println("Place holder for tracking request progress"); } @Override public void onSuccess(PersonnelOutputWrapper result, int statusCode, Map> responseHeaders) { UUID salesPersonId = result.getBody().getData().getSalesPersonId(); System.out.println("SUCCESS : SalespersonID = " + salesPersonId.toString()); } @Override public void onFailure(ApiException e, int statusCode, Map> responseHeaders) { System.out.println("Error is " + statusCode + " " + e.getResponseBody()); } @Override public void onDownloadProgress(long bytesRead, long contentLength, boolean done) { } }; // SubDealerRequestInput wraps RequestHeader and subDealerBody SubDealerRequestInput subDealerRequestInput = new SubDealerRequestInput(); /* * { "api_key": "ISNGvAzwuy4X7vAqrtV", "id": "any value", * "account_type": "partner" } */ RequestHeader hdr = new RequestHeader(); // 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(apiKey); // ID that will be reflected back hdr.setId("create-sub-dealer-s1002"); subDealerRequestInput.setHeader(hdr); SubDealerBody body = new SubDealerBody(); // REQUIRED FIELDS // 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 body.setSmsLogin(false); body.setDealerName("test dealer s1002"); // Create SubDealer creates full functional // braango personnel with added capability // Provide personnel name that is typical // contact point body.setPersonnelName("name of manager"); /* * 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. */ body.setUserName("subdealers1002r1"); /* * 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])(?=.*[!@#$%^&*()_+}{" * ;:;'?/>.<,])(?!.*\s).*$ * * Used for single sign on. needs to 6-10 characters with one capital, * one numberal and one special character */ body.setPassword("test1T$"); /* * pattern: ^(?:Starter|Small Business|Rooftop|Franchise)$ * * Every sub_dealer needs to have braango package */ body.setPackage("Small Business"); // Required field. Indicates the // ID for this business // All internal resources, leads, personnel, // braango number are associated with this id // Needs to be unique within Braango system // // Will return error if there is clash // // Recommended to use unique naming convention // or UUID string body.setSubDealerId("subdealers1002"); // OPTIONAL FIELDS // List of banners. Braango will // randomly choose one when sending // message to dealer via SMS // List dealerBanners = new ArrayList(); dealerBanners.add("s1002db1"); body.setDealerBanners(dealerBanners); // List of client banners. Braango // will randomly choose one when // sending dealer messages to client List clientBanners = new ArrayList(); clientBanners.add("s1002cb1"); body.setClientBanners(clientBanners); // List of supervisor banners. Braango // will randomly choose one when // sending messages to supervisor List supervisorBanners = new ArrayList(); supervisorBanners.add("s1002sb1"); body.setSupervisorBanners(supervisorBanners); // List of dealer footers. Braango will // randomly choose one when sending // message to dealer via SMS // List dealerFooters = new ArrayList(); dealerFooters.add("s1002df1"); body.setDealerFooters(dealerFooters); // List of client footers. Braango // will randomly choose one when // sending dealer messages to client List clientFooters = new ArrayList(); clientFooters.add("s1002cf1"); body.setClientFooters(clientFooters); // List of supervisor footers. Braango // will randomly choose one when // sending messages to supervisor List supervisorFooters = new ArrayList(); supervisorBanners.add("s1002sf1"); body.setSupervisorFooters(supervisorFooters); String email = "s1002r1@subdealer1002.com"; body.setEmail(email); // If email specified is that for // CRM email (ADF XML compliant) Boolean typeAdfCRMEmail = false; body.setTypeAdfCrm(typeAdfCRMEmail); /* * Number where dealer's root account can be reached via SMS * for leads * * pattern:^\(?(\d{3})\)?[- ]?(\d{3})[- ]?(\d{4})$ */ String smsNumber = "4089763433"; body.setSmsNumber(smsNumber); /* * Number where dealer's root account can be reached via voice * for leads * * pattern:^\(?(\d{3})\)?[- ]?(\d{3})[- ]?(\d{4})$ * */ String phoneNumber = "4089763433"; body.setPhoneNumber(phoneNumber); // SubDealer's can create unique groups // that personnel can subscribe to String group = "s1002grp"; body.setGroup(group); subDealerRequestInput.setBody(body); try { personnelsApi.createSubDealerAsync(subDealerRequestInput, callBack); } catch (ApiException e1) { e1.printStackTrace(); } } }