PHP code example of close / partner-sdk

1. Go to this page and download the library: Download close/partner-sdk library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

close / partner-sdk example snippets



// Require the Composer autoloader.
artnerSdk\Options;
use ClosePartnerSdk\Exception\CloseSdkException;

try {
  // Instantiate the Close client using the client credentials given by Close
  $sdk = new CloseSdk(
       new Options([
            'client_id' => 'client_test',
            'client_secret' => 'client_test_secret',
            'base_uri' => 'the endpoint for your environment, default is the close app production endpoint url',
       ])
  );
} catch (CloseSdkException $closeSdkException) {
    // You can receive an error if the token was not generated because of invalid credentials
}



use ClosePartnerSdk\Dto\Ticket;
use ClosePartnerSdk\Dto\EventId;
use ClosePartnerSdk\Dto\TicketGroup;
use ClosePartnerSdk\Dto\EventTime;
use ClosePartnerSdk\Exception\CloseSdkException;

try {  
  $eventId = new EventId('CLEV3BX47D58YCMERC6CGJ2L7xxx');
  $ticketGroup = new TicketGroup('+31666111000');
  $productTitle = 'Singular entrance ticket';
  $scanCode = '1234567890123';
  $ticket = new Ticket(
      $scanCode,
      new EventTime(new DateTime('2022-10-10 20:00:00')),
      $productTitle
  );
  $ticketGroup->addTicket($ticket);
  // Call endpoint
  $sdk
    ->ticket()
    ->import($eventId, $ticketGroup);
} catch (CloseSdkException $e) {
    echo "The ticket has not been imported.\n";
    // We recommend to retry after a couple of seconds.
}


use ClosePartnerSdk\Dto\EventId;
use ClosePartnerSdk\Dto\TicketGroup;
use ClosePartnerSdk\Dto\EventTime;
use ClosePartnerSdk\Exception\CloseSdkException;
use ClosePartnerSdk\Dto\Ticket;
use ClosePartnerSdk\Dto\SeatInfo;

try {
  // Define DTO structure
  $eventId = new EventId('CLEV3BX47D58YCMERC6CGJ2L7xxx');
  $ticketGroup = new TicketGroup('+31666111000');
  $productTitle = 'Singular entrance ticket';
  $scanCode = '1234567890123';
  
  $ticket = new Ticket(
      $scanCode,
      new EventTime(new DateTime('2022-10-10 20:00:00')),
      $productTitle
  );

  $seatInfo = new SeatInfo()
    ->withChair('12')
    ->withEntrance('E')
    ->withRow('3')
    ->withSection('A');

  $ticket = $ticket->withSeatInfo($seatInfo);

  $ticketGroup->addTicket($ticket);
  // Call endpoint
  $sdk
    ->ticket()
    ->import($eventId, $ticketGroup);
} catch (CloseSdkException $e) {
    echo "The ticket has not been imported.\n";
    // We recommend to retry after a couple of seconds.
}


use ClosePartnerSdk\Dto\EventId;
use ClosePartnerSdk\Dto\Product;
use ClosePartnerSdk\Dto\EventTime;
use ClosePartnerSdk\Exception\CloseSdkException;
use ClosePartnerSdk\Dto\TicketCancelDto;

try {
  // Define DTO structure
  $eventId = new EventId('CLEV3BX47D58YCMERC6CGJ2L7xxx');
  $scanCode = 'ABCD';
  $phoneNumber = '+31631111111';
  $eventTime = new EventTime(new DateTime('2022-10-10 20:00:00'));
  $ticketCancelDto = new TicketCancelDto($scanCode, $phoneNumber, $eventTime);
  // Call cancel endpoint
  $sdk
    ->ticket()
    ->cancel($eventId, $ticketCancelDto);
} catch (CloseSdkException $e) {
    echo "The ticket has not been cancelled.\n";
    // We recommend to retry after a couple of seconds.
}


use ClosePartnerSdk\CloseSdk;
use ClosePartnerSdk\Dto\EventId;
use ClosePartnerSdk\Dto\ChatId;
use ClosePartnerSdk\Exception\CloseSdkException;

try {
  // Define DTO structure
  $eventId = new EventId('CLEV3BX47D58YCMERC6CGJ2L7xxx');
  $chatId = new ChatId('CLECxxxxx');
  $message = 'This is the message to send';
  
  $sdk
    ->textMessage()
    ->sendToAllUsersForChat($eventId, $chatId, $message);
} catch (CloseSdkException $e) {
    echo "The text has not been sent.\n";
    // We recommend to retry after a couple of seconds.
}


use ClosePartnerSdk\CloseSdk;
use ClosePartnerSdk\Dto\EventId;
use ClosePartnerSdk\Dto\ItemFlowProperty;
use ClosePartnerSdk\Exception\CloseSdkException;

try {
  // Define DTO structure
  $eventId = new EventId('CLEV3BX47D58YCMERC6CGJ2L7xxx');
  $properties = [
    new ItemFlowProperty('vip', 'This is a great vip event!'),
    new ItemFlowProperty('promotion', 'This event has a special promotion'),
  ];
  
  $sdk->flowProperty()->setForAllUsersInAllChats(
    $eventId,
    $properties
  );
} catch (CloseSdkException $e) {
    echo "The property has not been sent.\n";
    // We recommend to retry after a couple of seconds.
}


use ClosePartnerSdk\CloseSdk;
use ClosePartnerSdk\Dto\EventId;
use ClosePartnerSdk\Exception\CloseSdkException;

try {
  // Define DTO structure
  $eventId = new EventId('CLEV3BX47D58YCMERC6CGJ2L7xxx');
  
  $properties = $sdk->flowConfig()->getChatConfig($eventId);
  
} catch (CloseSdkException $e) {
    echo "The event is not found sent.\n";
    // We recommend to retry after a couple of seconds.
}


use ClosePartnerSdk\CloseSdk;
use ClosePartnerSdk\Dto\EventId;
use ClosePartnerSdk\Dto\ChatId;
use ClosePartnerSdk\Dto\ItemFlowProperty;
use ClosePartnerSdk\Exception\CloseSdkException;

try {
  // Define DTO structure
  $eventId = new EventId('CLEV3BX47D58YCMERC6CGJ2L7xxx');
  $chatId = new ChatId('CLECxxxxx');
  
  $properties = $sdk->flowConfig()->getChatConfig($eventId);
  
   $itemFlowProperties = [
      new ItemFlowProperty('vip', 'true'),
      new ItemFlowProperty('promotion', 'This chat is the selected winner!'),
   ];

    $sdk->flowConfig()->setChatConfig($eventId, $chatId, $itemFlowProperties);
  
} catch (CloseSdkException $e) {
    echo "The event is not found sent.\n";
    // We recommend to retry after a couple of seconds.
}


use ClosePartnerSdk\CloseSdk;
use ClosePartnerSdk\Dto\EventId;
use ClosePartnerSdk\Dto\ItemFlowProperty;
use ClosePartnerSdk\Exception\CloseSdkException;

try {
  // Define DTO structure
  $eventId = new EventId('CLEV3BX47D58YCMERC6CGJ2L7xxx');
  
  $properties = $sdk->flowConfig()->getChatConfig($eventId);
  
} catch (CloseSdkException $e) {
    echo "The event is not found sent.\n";
    // We recommend to retry after a couple of seconds.
}


// Require the Composer autoloader.
artnerSdk\HttpClient\HttpClientBuilder;

// Instantiate the Close client using the client credentials given by Close
  return new CloseSdk(
       new Options([
            'client_builder' => new HttpClientBuilder($myownHttpClient),
            'client_id' => 'client_test',
            'client_secret' => 'client_test_secret',
       ])
  );