PHP code example of fabriciogferreira / abacatepay-php-sdk

1. Go to this page and download the library: Download fabriciogferreira/abacatepay-php-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/ */

    

fabriciogferreira / abacatepay-php-sdk example snippets


use AbacatePay\v2\Clients\AbacatePayClient;

$abacatePayClient = new AbacatePayClient('YOUR_ABACATE_PAY_TOKEN');

use AbacatePay\v2\Clients\AbacatePayClient;
use AbacatePay\v2\RequestData\Customer\CustomerCreateRequestData;

$abacatePayClient = new AbacatePayClient('YOUR_ABACATE_PAY_TOKEN');

$customerCreateRequestData = CustomerCreateRequestData::make('[email protected]')
  ->name('Fabrício')
  ->metadata([
    'herói favorito' => 'flash',
    'idade' => 24
  ]);

$customerCreateResponseBody = $abacatePayClient->customers()
  ->create($customerCreateRequestData);

AbacatePay\v2\ResponseBody\Customer\CustomerCreateResponseBody

use AbacatePay\v2\Exceptions\AbacatePayNetworkException;
use AbacatePay\v2\Exceptions\AbacatePayValidationException;
use AbacatePay\v2\Exceptions\AbacatePayInvalidRequestException;
use AbacatePay\v2\Exceptions\AbacatePayAuthorizationException;
use AbacatePay\v2\Exceptions\AbacatePayAuthenticationException;
use AbacatePay\v2\Exceptions\AbacatePayRateLimitException;
use AbacatePay\v2\Exceptions\AbacatePayNotFoundException;
use AbacatePay\v2\Exceptions\AbacatePayApiException;

try {
  $customerCreateResponseBody = $abacatePayClient->customers()
      ->create($customerCreateRequestData);
} catch (AbacatePayNetworkException $e) {
  // Handle network error (0)
} catch (AbacatePayValidationException $e) {
  // Handle validation error (422)
} catch (AbacatePayInvalidRequestException $e) {
  // Handle invalid request error(400)
} catch (AbacatePayAuthorizationException $e) {
  // Handle authorization (403)
} catch (AbacatePayAuthenticationException $e) {
  // Handle authentication error (401)
} catch (AbacatePayRateLimitException $e) {
  // Handle rate limit error (429)
} catch (AbacatePayNotFoundException $e) {
  // Handle not found error (404)
} catch (AbacatePayApiException $e) {
  // Handle unexpected API errors (500)
}
bash
composer