Skip to content
joeydehaas edited this page Oct 6, 2022 · 17 revisions

Introduction

This is a PHP SDK to make easier to communicate with the Plug&Pay API.

Not all functionalities are present. If you're missing something, feel free to request it through our Discord channel.

Authentication

You can generate the API access token in the admin. You can use that token to create a client:

use PlugAndPay\Sdk\Service\Client;

$client = new Client('your_access_token');

Exceptions

Your application will be better and more stable if you take the exceptions into account. It is therefore good to catch the errors when they arise. Then you can decide for yourself how you want to deal with the error.

use PlugAndPay\Sdk\Exception\NotFoundException;
use PlugAndPay\Sdk\Exception\RelationNotLoadedException;
use PlugAndPay\Sdk\Exception\ValidationException;
use PlugAndPay\Sdk\Exception\UnauthenticatedException;

try {

    // Place your code that uses the SDK inside this block.

} catch (ValidationException $exception) {

    # The information that has been sent is incorrect. If
    # you want to forward this in your response, this would
    # return an HTTP status Unprocessable Entity (422).
 
    // All messages separated by a space
    $message = $exception->getMessage();
    // First notification of the first error. There can be
    // multiple errors with the same field
    $exception->errors()[0]->message());
    // The field that did not pass the validation successfully.
    $exception->errors()[0]->field());

 } catch (UnauthenticatedException $exception) {
 
    # Unable to connect with Plug&Pay. Request is
    # unauthenticated. Please check if the token
    # is correct.
    # Unauthorized Error (401).
    
} catch (NotFoundException $exception) {
 
    # Entry not found. You probably gave the wrong id to
    # the service. You have to solve this error in your
    # application, otherwise you would expect an HTTP
    # Internal Server Error (500).
    
} catch (RelationNotLoadedException $exception) {

    # You are trying to extract a relation from an entity
    # that has not yet been loaded. You can include this
    # by using the `include()` method of the service. You
    # have to solve this error in your application, otherwise
    # you would expect an HTTP Internal Server Error (500).
    
} catch (BadFunctionCallException $exception) {
 
    # It is not possible to use this function in this way.
    # Unauthorized Error (500).
     
 } catch (DecodeResponseException $exception) {

    # Failed to decode the response. You would expect an
    # HTTP Internal Server Error (500) and you have to
    # contact Plug&Pay customer service.
    
}
Clone this wiki locally