PHP code example of g2a / integration-api-client

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

    

g2a / integration-api-client example snippets




ig = new \G2A\IntegrationApi\Model\Config(
    '[email protected]',
    'sandboxapi.g2a.com',
    'qdaiciDiyMaTjxMt',
    'b0d293f6-e1d2-4629-8264-fd63b5af3207b0d293f6-e1d2-4629-8264-fd63b5af3207'
);

$g2aApiClient = new \G2A\IntegrationApi\Client($config);



ig = new \G2A\IntegrationApi\Model\Config(
    '[email protected]',
    'sandboxapi.g2a.com',
    'qdaiciDiyMaTjxMt',
    'b0d293f6-e1d2-4629-8264-fd63b5af3207b0d293f6-e1d2-4629-8264-fd63b5af3207'
);
    
$g2aApiClient = new \G2A\IntegrationApi\Client($config);

// add an order
$request = new G2A\IntegrationApi\Request\OrderAddRequest($g2aApiClient);
$request
    ->setProductId('10000037846002')
    ->setCurrency('USD')
    ->setMaxPrice(45.12)
    ->call();

$response = $request->getResponse();

echo 'Order ID: ' . $response->getOrderId() . PHP_EOL;


// …
$request = new \G2A\IntegrationApi\Request\ProductsListRequest($g2aApiClient);
$request
    ->setPage(1)
    ->setMinQty(5)
    ->call();

$response = $request->getResponse();

foreach ($response->getProducts() as $product) {
    echo $product->getId() . ' ' . $product->getName() . PHP_EOL;
}


// …
$request = new G2A\IntegrationApi\Request\OrderAddRequest($g2aApiClient);
$request
    ->setProductId('10000037846002')
    ->setCurrency('USD')
    ->setMaxPrice(45.12)
    ->call();

$response = $request->getResponse();

echo 'Order ID: ' . $response->getOrderId() . PHP_EOL;


// …
$request = new G2A\IntegrationApi\Request\OrderPaymentRequest($g2aApiClient);
$request
    ->setOrderId(1532096834)
    ->call();

$response = $request->getResponse();

echo 'Payment transaction ID: ' . $response->getTransactionId() . PHP_EOL;
echo 'Payment status: ' . $response->getStatus() . PHP_EOL;


// …
$request = new \G2A\IntegrationApi\Request\OrderDetailsRequest($g2aApiClient);
$request
    ->setOrderId(1532096834)
    ->call();

$response = $request->getResponse();

echo 'Order status: ' . $response->getStatus() . PHP_EOL;
echo 'Price: ' . $response->getPrice() . PHP_EOL;
echo 'Currency: ' . $response->getCurrency() . PHP_EOL;


// …
$request = new \G2A\IntegrationApi\Request\OrderKeyRequest($g2aApiClient);
$request
    ->setOrderId(1532096834)
    ->call();

$response = $request->getResponse();

echo 'Order key: ' . $response->getKey() . PHP_EOL;