PHP code example of pedrobruning / phpix

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

    

pedrobruning / phpix example snippets

 

ENDÊNCIAS
use PedroBruning\PhPix\Services\PhPixServiceFactory;
use PedroBruning\PhPix\Services\Providers;
use Symfony\Component\HttpClient\HttpClient; 

//INSTÂNCIA
//CRIAÇÃO DO CLIENT: Se o provider que você está utilizando precisa de token de authorization você deve informa-lo na criação do client
$client = HttpClient::create();
$client = $client->withOptions([
    'headers' => ['Authorization' => 'YOUR_TOKEN']
]);

$provider = Providers::YourProvider;
$phPixService = PhPixServiceFactory::make($provider, $client);

$chargeId = 'chargeId';
$charge = $phPixService->charges()->getById($chargeId);

$filter = [
    'start' => '2021-03-01T17:28:51.882Z',
    'end' => '2021-03-05T17:28:51.882Z',
    'status' => 'ACTIVE',
];
$charges = $phPixService->charges()->getByFilter($filter);

use PedroBruning\PhPix\Models\OpenPix\ChargeRequest;
$chargeRequest = new ChargeRequest(
    correlationId: 'validCorrelation',
    value: 100,
    comment: 'validComment',
    identifier: 'validIdentifier',
    customer: [
        'name' => 'Test Customer',
        'email' => '[email protected]',
        'phone' => '(00) 00000-0000',
        'taxID' => '000000000000'
    ]
);
$charge = $phPixService->charges()->create($chargeRequest);

$refundId = 'refundId';
$refund = $phPixService->refunds()->getById($refundId);

$refund = $phPixService->refunds()->getAll();

use PedroBruning\PhPix\Models\OpenPix\RefundRequest;
$refundRequest = new RefundRequest(
    value: 100,
    transactionEndToEndId: 'validTransactionEndToEndId',
    correlationId: 'validCorrelation'
);
$refund = $phPixService->refunds()->create($refundRequest);