Created
October 5, 2022 11:46
-
-
Save bennettblack/8ecac49cfa9a0b185b84cba22ab49e61 to your computer and use it in GitHub Desktop.
RicorocksDigitalAgency SOAP Example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Console\Commands\Misc; | |
use Illuminate\Console\Command; | |
use Illuminate\Support\Facades\Cache; | |
use RicorocksDigitalAgency\Soap\Facades\Soap; | |
/** | |
| | | |
| This command is not being used. Hanging on to it to use as an example for any future SOAP | | |
| integrations. | | |
| | | |
*/ | |
class LoadCventRegistrants extends Command | |
{ | |
private $account_number = 'xxxxxxxxxx'; | |
private $user_name = 'xxxxxxxxxx'; | |
private $password = 'xxxxxxxxxx'; | |
private $event_id = 'xxxxxxxxxx'; | |
private $server_wsdl = 'https://api.cvent.com/soap/V200611.ASMX?WSDL'; | |
protected $signature = 'load-cvent-registrants'; | |
protected $description = 'Command description'; | |
public function __construct() | |
{ | |
parent::__construct(); | |
} | |
public function handle() | |
{ | |
/******************************************************************************************************************* | |
* Process Registration Objects | |
*******************************************************************************************************************/ | |
// Get Registration object UUIDs | |
$registration_ids = $this->getRegistrationIds()->chunk(200); | |
$this->info($registration_ids->count() . ' chunks of registrations to be processed.'); | |
// Get Registration objects, to obtain Contact UUIDs | |
foreach ($registration_ids as $chunk) { | |
// Use values() to reset array keys. Cvent API does not respond to any array | |
// payloads that don't start keyed at '0'. | |
$registrations = $this->getRegistrations($chunk->values()->toArray()); | |
// Do some work | |
// ... | |
} | |
$this->info('Done...!'); | |
} | |
/** | |
* Authenticate with CVENT API and assign headers to initialize client request object. | |
*/ | |
public function login(): \RicorocksDigitalAgency\Soap\Request\Request | |
{ | |
// Initiate SOAP client.. can dump $client to see available methods. | |
$client = Soap::to($this->server_wsdl); | |
$session_header = Cache::remember('cvent_session_header', 3480, function () use ($client) { | |
$login_response = $client->call('Login', [ | |
'AccountNumber' => $this->account_number, | |
'UserName' => $this->user_name, | |
'Password' => $this->password, | |
]); | |
if ($login_response->LoginResult->LoginSuccess) { | |
return $login_response->LoginResult->CventSessionHeader; | |
} | |
}); | |
// Build header object with session key. | |
$header = Soap::header() | |
->name('CventSessionHeader') | |
->namespace('http://api.cvent.com/2006-11') | |
->data(['CventSessionValue' => $session_header]); | |
// Add header to client before returning | |
return Soap::to($this->server_wsdl)->withHeaders($header); | |
} | |
/** | |
* Return UUIDs of all current registrations for 2021 expo. | |
*/ | |
public function getRegistrationIds(): \Illuminate\Support\Collection | |
{ | |
// Each request should have its own client. | |
$client = $this->login(); | |
$ids = $client->call('Search', [ | |
'ObjectType' => 'Registration', | |
'CvSearchObject' => [ | |
'SearchType' => 'AndSearch', | |
'Filter' => [ | |
'Field' => 'EventId', | |
'Operator' => 'Equals', | |
'Value' => $this->event_id, | |
], | |
], | |
]); | |
return collect($ids->response->SearchResult->Id); | |
} | |
/** | |
* Return Registration objects by IDs. | |
*/ | |
public function getRegistrations(array $ids): \Illuminate\Support\Collection | |
{ | |
// Each request should have its own client. | |
$client = $this->login(); | |
$registrations = $client->call('Retrieve', [ | |
'ObjectType' => 'Registration', | |
'Ids' => $ids, | |
]); | |
return collect($registrations); | |
} | |
/** | |
* Return Contact objects by IDs. | |
*/ | |
public function getContacts(array $ids): \Illuminate\Support\Collection | |
{ | |
// Each request should have its own client. | |
$client = $this->login(); | |
$contacts = $client->call('Retrieve', [ | |
'ObjectType' => 'Contact', | |
'Ids' => $ids, | |
]); | |
return collect($contacts); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment