PHP code example of chico-rei / cielo-ecommerce-v3-php

1. Go to this page and download the library: Download chico-rei/cielo-ecommerce-v3-php 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/ */

    

chico-rei / cielo-ecommerce-v3-php example snippets




use \ChicoRei\Packages\Cielo\Cielo;
use \ChicoRei\Packages\Cielo\Merchant;
use \ChicoRei\Packages\Cielo\Util;

$merchant = Merchant::create([
    'id' => 'Your_ID',
    'key' => 'Your_KEY',
]);

$cielo = new Cielo($merchant); // For sandbox use: new Cielo($merchant, true);

try {
    $response = $cielo->sale()->create([
        'merchantOrderId' => '19800731',
        'payment' => [
            'type' => 'CreditCard',
            'amount' => 15700, // 157,00
            'installments' => 2,
            'softDescriptor' => 'Your Company',
            'capture' => true,
            'creditCard' => [
                'cardNumber' => '4551870000000000',
                'holder' => 'Name',
                'expirationDate' => '12/2021',
                'securityCode' => '123',
                'brand' => 'Visa'
            ]
        ]
    ]);
    
    echo $response->getPayment()->getStatus(); // Transaction Status Code 
    
    $returnCode = $response->getPayment()->getReturnCode(); // Ex: '00'
    $details = Util::getReturnCodeDetails($returnCode);
    echo $details['definition']; // Transação autorizada com sucesso.
    
} catch (CieloAPIException $e) {
    // Handle API errors (or validation errors)
} catch (Exception $e) {
   // Handle exceptions
}
bash
$ composer