PHP code example of tuks128 / g2a-pay-php5-api

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

    

tuks128 / g2a-pay-php5-api example snippets




use Tuxxx128\G2aPay\G2aPayApi;
use Tuxxx128\G2aPay\G2aPayItem;

$g2aPayApi = new G2aPayApi('API HASH', 'SECRET KEY', true, 'EMAIL OF STORE');



$item = (new G2aPayItem)->itemTemplate();

$item->name = "My item";
$item->url = "http://...";
$item->price = 10; // default currency is 'EUR'

$g2aPayApi->addItem($item);



$item = (new G2aPayItem)->itemTemplate();

$item->name = "Discount";
$item->url = "http://...";



$g2aPayApi->setCurrency("USD"); // from default currency 'EUR' to 'USD'



$g2aPayApi->setUrlFail("http://..");
$g2aPayApi->setUrlSuccess("http://..");
$g2aPayApi->setOrderId(ORDER ID);
// $g2aPayApi->setEmail('[email protected]');

header('Location: '.$g2aPayApi->getRedirectUrlOnGateway());



$transactionDetail = $g2aPayApi->getPaymentDetailById($transactionId);

var_dump($transactionDetail);



if($g2aPayApi->checkIsProductionEnvironment()) {
	// ...
}
else {
	// ...
}



if($_POST['hash'] == $g2aPayApi->calculateIpnHash($transactionId, $orderId, $amount)) {
	// ...
}
else {
	// ...
}



echo $g2aPayApi->getTotalPrice();
echo ' ';
echo $g2aPayApi->getCurrency();