PHP code example of chags / apicielophp

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

    

chags / apicielophp example snippets



use apicielophp\Cielo;  

// Credenciais de produção
$merchantId = '8937bd5b-9796-494d-9fe5-f76b3e4da633';
$merchantKey = 'XKGHUBSBKIRXKAVPSKWLVXYCLVJUGTNZLIHPUSYV';

// Instanciar o cliente no ambiente de teste
$cielo = new Cielo($merchantId, $merchantKey, 'sandbox');

// Dados da venda
$data =[
    'MerchantOrderId' => '123456',
    'Customer' => ['Name' => 'Teste'],
    'Payment' => [
        'Type' => 'CreditCard',
        'Amount' => 10000,
        'Installments' => 1,
        'CreditCard' => [
            'CardNumber' => '1234123412341234',
            'Holder' => 'Teste',
            'ExpirationDate' => '12/2030',
            'SecurityCode' => '123',
            'Brand' => 'Visa'
        ]
    ]
];

try {
    $response = $cielo->createPhysicalSale($data);
    print_r($response);
} catch (\Exception $e) {
    echo 'Erro: ' . $e->getMessage();
}