PHP code example of abacatepay / php-sdk

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

    

abacatepay / php-sdk example snippets


use AbacatePay\Clients\Client;

Client::setToken($_ENV["ABACATEPAY_TOKEN"]);

use AbacatePay\Clients\BillingClient;

$billingClient = new BillingClient();

$billings = $billingClient->list();

use AbacatePay\Resources\Billing;
use AbacatePay\Resources\Billing\Product;
use AbacatePay\Resources\Billing\Metadata as BillingMetadata;
use AbacatePay\Enums\Billing\Methods;
use AbacatePay\Enums\Billing\Frequencies;
use AbacatePay\Resources\Customer;
use AbacatePay\Resources\Customer\Metadata as CustomerMetadata;

$billing = $billingClient->create(new Billing([
    'frequency' => Frequencies::ONE_TIME,
    'methods' => [Methods::PIX],
    'products' => [
        new Product([
            'external_id' => 'abc_123',
            'name' => 'Product A',
            'description' => 'Description of product A',
            'quantity' => 1,
            'price' => 100 // Price in cents
        ])
    ],
    'metadata' => new BillingMetadata([
        'return_url' => 'https://www.abacatepay.com',
        'completion_url' => 'https://www.abacatepay.com'
    ]),
    'customer' => new Customer([
        'metadata' => new CustomerMetadata([
            'name' => 'John Doe',
            'cellphone' => '01912341234',
            'email' => '[email protected]',
            'tax_id' => '13827826837'
        ])
    ])
]));

// ...
    'customer' => new Customer([
        'id' => 'abc_123'
    ])
// ...

use AbacatePay\Clients\CustomerClient;
use AbacatePay\Resources\Customer;

$customerClient = new CustomerClient();

$customers = $customerClient->list();

use AbacatePay\Resources\Customer;
use AbacatePay\Resources\Customer\Metadata;

$customer = $customerClient->create(new Customer([
    'metadata' => new Metadata([
        'name' => 'John Doe',
        'cellphone' => '01912341234',
        'email' => '[email protected]',
        'tax_id' => '13827826837'
    ])
]));

use AbacatePay\Exceptions\ApiException;

try {
    $billing = $billingClient->create($billingData);
} catch (ApiException $e) {
    // Handle API-specific errors
    echo $e->getMessage();
} catch (\Exception $e) {
    // Handle general errors
    echo $e->getMessage();
}
bash
composer