PHP code example of 9orky / espago-api-php

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

    

9orky / espago-api-php example snippets


$apiFactory = new \Gorky\Espago\Factory\ApiFactory(
    'https://sandbox.espago.com',
    new \Gorky\Espago\Model\ApiCredentials('app_id', 'public_key', 'password')
);

$tokensApi = $apiFactory->buildTokensApi();

// first we need Customer card's representation
$unauthorizedCard = $tokensApi->createUnauthorizedCard(
    '4111111111111111',
    'John',
    'Doe',
    '04',
    '2020',
    '111'
);

// so now we can transform it to a Token
$token = $tokensApi->createToken($unauthorizedCard);

$chargesApi = $apiFactory->buildChargesApi();

// carefuly study Gorky\Espago\Model\Response\Charge and corresponding API documents!
$charge = $chargesApi->createChargeByToken($token, 12.66, 'PLN', 'doughnuts');

$tokensApi = $apiFactory->buildTokensApi();

$unauthorizedCard = $tokensApi->createUnauthorizedCard(
    '4111111111111111',
    'John',
    'Doe',
    '04',
    '2020',
    '111'
);

$token = $tokensApi->createToken($unauthorizedCard);

$clientsApi = $apiFactory->buildClientsApi();

$client = $clientsApi->createClient($token, '[email protected]', 'Our precious client John');

$chargesApi = $apiFactory->buildChargesApi();

$charge = $chargesApi->createChargeByClient($client, 12.66, 'PLN', 'doughnuts');

// credentials.php

return [
    'app_id'     => 'your_app_id',
    'public_key' => 'your_public_key',
    'password'   => 'your_password'
];
bash
composer 
bash
php espago.php customer:create
bash
php espago.php customer:charge --interactive
bash
php espago.php customer:charge --clientId="1234" --amount="6.67" --currency="PLN" --description="flowers"
bash
php espago.php customer:charge --capture --chargeId="pay_COy6zH9fLj1d7K" --amount="23.44"
bash
php espago.php customer:charge --refund --chargeId="pay_COy6zH9fLj1d7K" --amount="23.44"
bash
php espago.php customer:charge --cancel --chargeId="pay_COy6zH9fLj1d7K"
bash
php espago.php customer:charge --cancel --interactive