The SDK written in PHP for Close partner developers.

Related tags

API partner-sdk-php
Overview

Close SDK for PHP

Lastest Version Run PHP Unit tests Apache 2 License

The Close SDK for PHP makes it easy for developers to communicate with The Close App in their PHP code. Get started really fast by installing the SDK through Composer.

Jump To:

Getting Started

  1. Get your credentials – Before you begin, you need to already have an account with Close. If that is not the case, feel free to contact us.

  2. Minimum requirements – In order to use the Close SDK, your system will need to meet the [minimum requirements][docs-requirements], which includes having PHP >= 7.4.

  3. Install the SDK – The recommended way to use the Close SDK is by installing it with Composer:

    composer require close/partner-sdk
    
  4. Using the SDK – In this page you will learn how to use the SDK, but if you want to get more information about the calls, you can always see our Close Partner API Documentation, which this SDK is a wrapper of.

Quick Examples

Create the Close SDK client

<?php
// Require the Composer autoloader.
require 'vendor/autoload.php';

use ClosePartnerSdk\CloseSdk;
use ClosePartnerSdk\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',
       ])
  );
} catch (CloseSdkException $closeSdkException) {
    // You can receive an error if the token was not generated because of invalid credentials
}

Import tickets using the Close App

Import ticket with required information

<?php
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.
}

Import ticket with seat information

<?php
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.
}

Cancelling tickets

Cancel a ticket in the Close App

<?php
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.
}

Sending messages

Send a message to all users in a chat

<?php
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.
}

Flow Properties

To set a value in the flow properties

<?php
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.
}

Setting properties in the chat

You can also retrieve and set properties that will be available for everyone who is in the chat of the show.

For retrieving all the flow properties:

<?php
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.
}

For setting a property for the whole chat:

<?php
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.
}
<?php
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.
}

Getting Help

Feel free to let us know if you have encountered any questions or problems using our SDK. We will try to make sure that we will get back to you as soon as possible.

  • If you have questions that have not been answered in this documentation, please contact us.
  • If you think that you may have found a bug, feel free to open an issue.

Features

  • Provides a very easy way to communicate with our Partner API for all of the supported endpoints. This means that we always fetch the correct data based on your API credentials.
  • It is built on the latest software, with the highest security standards and following the PSR conventions.
  • You can provide your own Http client as a dependency of the client builder and providing the instance in the options object. You have an example above.
  • We use Guzzle to generate these requests, and we make use of its technology (async requests, middlewares, etc.).
  • We provide a data structure f our domain that can be easily used by external PHP applications.
  • We give back clear responses and exceptions in case something doesn't go as expected.

Advanced features

  1. In case you want to make usage of your own HttpClient, you can provide the implementation to the client builder when instantiating our SDK:
<?php
// Require the Composer autoloader.
require 'vendor/autoload.php';

use ClosePartnerSdk\CloseSdk;
use ClosePartnerSdk\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',
       ])
  );

Important: The client needs to implement the PSR-7 conventions to be accepted by our SDK. 2. In case you don't provide any instance, we use the discovery functionality from HttpPlug, which look up for an available implementation of \Http\Client\HttpClient.

Contributing

If you have ideas on how to improve our SDK, don't hesitate to open an issue and let us know! If you already have code ready that would help us improve our system, you are free to open a PR. All the extra help is highly appreciated!

Resources

  • API Docs – For more details about the parameters of each endpoint, validation and responses.
  • Website – More information about Close and what we do.
  • Issues – Report issues and submit pull requests.
  • License – More information about our license.
You might also like...
Notion PHP SDK
Notion PHP SDK

Notion PHP SDK This is an unofficial PHP SDK for the new public Notion API. It's work in progress as we didn't get the change to be included to the pr

爱发电非官方简易 PHP SDK

afdian-php-sdk 爱发电非官方简易 PHP SDK by Akkariin 这是一个简单的 SDK,可以用于查询爱发电的订单和赞助者信息 Installation 将项目 clone 到本地即可 git clone https://github.com/ZeroDream-CN/afdi

AWS Cognito package using the AWS SDK for PHP/Laravel
AWS Cognito package using the AWS SDK for PHP/Laravel

Laravel Package to manage Web and API authentication with AWS Cognito AWS Cognito package using the AWS SDK for PHP This package provides a simple way

PHP SDK to interact with the Casper Network nodes via RPC

casper-php-sdk PHP SDK to interact with Casper Network nodes via RPC Install composer require make-software/casper-php-sdk Examples RPC Client: $node

A Laravel 5+ (and 4) service provider for the AWS SDK for PHP

AWS Service Provider for Laravel 5/6/7/8 This is a simple Laravel service provider for making it easy to include the official AWS SDK for PHP in your

SDK of the LINE Login API for PHP

LINE Login for PHP SDK of the LINE Login API for PHP Documentation See the official API documentation for more information. Installation Use the packa

PHP SDK - Flexie CRM fiskalizimi solution

PHP SDK - Flexie CRM fiskalizimi solution Fiskalizimi PHP SDK allows you to talk and generate your e-invoices programmatically from your own solution

PHP Digital Green Certificate SDK

Digital Green Certificate SDK PHP Indice Contesto Installazione Uso Licenza Dettaglio licenza Contesto Attenzione, questo repository è derivato dalle

Esse SDK em PHP foi desenvolvido no intuito de tornar mais prático a integração com nossa API.

Sobre Beedoo SDK Acessar documentação completa da Beedoo API. A API é organizada seguindo a arquitetura REST, boas práticas, convenções e padrões como

Comments
  • [CL-7196] Add import tickets endpoint

    [CL-7196] Add import tickets endpoint

    This PR adds the endpoint to import tickets through the Close app:

    1. When SDK is being instantiated, it will generate the access token and it will throw an error if the credentials were not authorised.
    2. It provides a consistent structure to build the request to import tickets.
    3. Do not authorise the token in each request, only when instance was created. Would be even better if we keep on checking the expiration time, but I think that's for later.
    opened by david-close 0
  • CL-7196 implement http client

    CL-7196 implement http client

    This PR includes the implementation of the OAuth token, defining for the first time the code structure to add other endpoints as well. I was really inspired by this article: https://madewithlove.com/blog/software-engineering/building-an-sdk-with-php-part-1/

    The idea is to prepare the SDK to accept other HTTP client instances using the constructor. The client must follow the PSR convention.

    opened by close-dev-team 0
Releases(v1.0.3)
Owner
Close Dev Team
Close Dev Team
Amazon Selling Partner SPI - PHP SDKs

Amazon Selling Partner API - PHP SDK This repository is not an official Amazon PHP library for their SP API. Why next library? There are already few p

Amazon PHP 77 Dec 19, 2022
A complete Notion SDK for PHP developers.

notion-sdk-php A complete Notion SDK for PHP developers. Installation composer require mariosimao/notion-php Getting started A Notion token will be n

Mario Simão 77 Nov 29, 2022
Shopware PHP SDK is a simple SDK implementation of Shopware 6 APIs

Shopware PHP SDK is a simple SDK implementation of Shopware 6 APIs. It helps to access the API in an object-oriented way.

Thuong Le 77 Dec 19, 2022
Zoho CRM API SDK is a wrapper to Zoho CRM APIs. By using this sdk, user can build the application with ease

Archival Notice: This SDK is archived. You can continue to use it, but no new features or support requests will be accepted. For the new version, refe

null 81 Nov 4, 2022
This package makes it easy for developers to access WhatsApp Cloud API service in their PHP code.

The first PHP API to send and receive messages using a cloud-hosted version of the WhatsApp Business Platform

NETFLIE 135 Dec 29, 2022
Best resources restful api for developers

Best resources restful api for developers (with JSON:API standar specification design).

Noval 2 Jan 18, 2022
Best resources restful api for developers (with JSON:API standar specification design)

List API Best resources restful api for developers (with JSON:API standar specification design). API Resource Endpoint Name Resource Description Al Qu

Noval 2 Jan 18, 2022
The 1Password Connect PHP SDK provides your PHP applications access to the 1Password Connect API hosted on your infrastructure and leverage the power of 1Password Secrets Automation

1Password Connect PHP SDK The 1Password Connect PHP SDK provides your PHP applications access to the 1Password Connect API hosted on your infrastructu

Michelangelo van Dam 12 Dec 26, 2022
Facebook SDK for PHP (v6) - allows you to access the Facebook Platform from your PHP app

Facebook SDK for PHP (v6) This repository contains the open source PHP SDK that allows you to access the Facebook Platform from your PHP app. Installa

null 0 Aug 10, 2022
Unofficial Firebase Admin SDK for PHP

Firebase Admin PHP SDK Table of Contents Overview Installation Documentation Support License Overview Firebase provides the tools and infrastructure y

kreait 1.9k Jan 3, 2023