PHP code example of opentickettech / powertranz-hhp
1. Go to this page and download the library: Download opentickettech/powertranz-hhp 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/ */
opentickettech / powertranz-hhp example snippets
use Omnipay\Omnipay;
// Create the gateway
$gateway = Omnipay::create('Powertranz');
// Configure with your credentials
$gateway->setPowertranzId('your-powertranz-id');
$gateway->setPowertranzPassword('your-powertranz-password');
$gateway->setTestMode(true); // Use false for production
$response = $gateway->purchase([
'amount' => '10.00',
'currency' => 'GTQ', // Supports GTQ, USD, EUR, GBP
'transactionId' => 'ORDER-123456', // Your unique order reference
'returnUrl' => 'https://yoursite.com/payment/return',
'description' => 'Order #123456',
])->send();
if ($response->isRedirect()) {
// Get the SPI token for the payment
$spiToken = $response->getSpiToken();
// Get the transaction reference for future operations
$transactionRef = $response->getTransactionReference();
// Redirect to the payment page
$response->redirect();
} else {
// Payment initiation failed
echo $response->getMessage();
}
// The SPI token will be in the return URL parameters
$response = $gateway->completePurchase([
'spiToken' => $_GET['SpiToken'], // Automatically captured from request if not provided
])->send();
if ($response->isSuccessful()) {
// Payment was successful
$transactionRef = $response->getTransactionReference();
$authCode = $response->getAuthorizationCode();
$maskedCard = $response->getMaskedCard();
echo "Payment successful! Reference: " . $transactionRef;
} else {
// Payment failed
echo "Payment failed: " . $response->getMessage();
}