1. Home
  2. Library
  3. SDK PHP
  4. Create and retrieve a PHP client

Create and retrieve a PHP client

Create a client has different purposes, the main one is be able to save tokens in order to use them multiple times.

As we have said in the past, tokens tok_xxxxx  can be used only once, nevertheless, it’s probable that the application nature requieres tokens to be used more than once. In this case the first step to achieve recurrent tokens is to create a client.

Pre-requisites

Have installed and configured the SDK

Process

1. Import SrPago.php class.

include_once './vendor/SrPago_php/SrPago.php';

2. Create an object with email and the client’s name.

$data['email'] = $email;   //Los datos normalmente serán extraídos de una base de datos
$data['name'] = $name;

3. Use the object to create a client

try{
        $customer = $srPago->createCustomer($data);
}
catch (Exception $e){
    echo 'Error ' . $e->getMessage() . ' ' . $e->getFile();
}

4. This method will return an array with a token cus_xxxxx in the position $customer[‘result’][‘id’]. It would be important to save this token in a DB for future operations.

5. To retrieve a client information we will need the token generated in point 4, the method is

try{
 $customer = $srPago->findCustomer($customer['result']['id']);
}
catch (Exception $e){
   echo 'Error ' . $e->getMessage() . ' ' . $e->getFile();
}

This method will return an array with client information, included the active Credit Cards from that client. To know how to add additional cards please review the documentation

Note: To know more about the responses and possible error codes you may refer to the API docs

Was this article helpful to you? Yes 1 No 11