PHP code example of leandroferreirama / asaas-client
1. Go to this page and download the library: Download leandroferreirama/asaas-client 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/ */
leandroferreirama / asaas-client example snippets
saas\AsaasConfig;
use Asaas\HttpClient;
use Asaas\Endpoints\SubaccountEndpoint;
use Asaas\Models\Subaccount;
use Asaas\Config\VariavelAmbiente;
// Token de acesso
VariavelAmbiente::load(__DIR__.'/../');
$token = getenv('ASAAS_TOKEN');
// Configuração
$config = new AsaasConfig(AsaasConfig::ENV_SANDBOX);
$httpClient = new HttpClient($token, $config);
$subaccountEndpoint = new SubaccountEndpoint($httpClient);
// Criar subconta
$subaccount = new Subaccount(
'Minha Subconta',
'[email protected]',
'00000000000000',
'41000000000',
5000.00,
'000',
'00000000',
companyType: 'LIMITED'
);
$response = $subaccountEndpoint->create($subaccount);
var_dump($response);
saas\AsaasConfig;
use Asaas\Config\VariavelAmbiente;
use Asaas\HttpClient;
use Asaas\Endpoints\BoletoEndpoint;
use Asaas\Factories\ChargeFactory;
try {
// Token de acesso
VariavelAmbiente::load(__DIR__.'/../');
$token = getenv('ASAAS_TOKEN');
// Configuração
$config = new AsaasConfig(AsaasConfig::ENV_SANDBOX);
$httpClient = new HttpClient(
$token,
$config
);
$boletoEndpoint = new BoletoEndpoint($httpClient);
// Criando uma cobrança parcelada via boleto
$boletoCharge = ChargeFactory::createCharge(
'cus_000006562001', // ID do cliente
'BOLETO', // Tipo de cobrança
0, // Valor não necessário para parcelamento
'2025-04-01', // Data de vencimento
'Pedido Parcelado 056985', // Descrição (opcional)
'056985' // Referência externa (opcional)
);
// Adicionando detalhes do parcelamento
$boletoCharge->addInstallmentFields(
3, // Número de parcelas
450.0, // Valor total (opcionalmente pode usar installmentValue)
null // Valor individual de cada parcela (calculado automaticamente)
);
$boletoCharge->addInterest(1);
$boletoCharge->addFine(2, 'PERCENTAGE');
$boletoCharge->addDiscount(10, 5, 'PERCENTAGE');
// Criando a cobrança e obtendo o Identification Field
$response = $boletoEndpoint->create($boletoCharge);
// Resposta final combinada
var_dump($response);
} catch (Exception $e) {
echo 'Erro: ' . $e->getMessage();
}