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();
}

$response = $gateway->fetchTransaction([
    'transactionReference' => 'TXN-123456',
])->send();

if ($response->isSuccessful()) {
    $isPaid = $response->isPaid();
    $amount = $response->getAmount();
    $currency = $response->getCurrency();
    $status = $response->getTransactionStatus();
    $date = $response->getTransactionDate();
    
    echo "Transaction " . ($isPaid ? "is paid" : "is not paid");
} else {
    echo "Transaction not found: " . $response->getMessage();
}

$response = $gateway->refund([
    'transactionReference' => 'TXN-123456',
    'amount' => '5.00', // Partial refund of 5.00
    'currency' => 'GTQ',
])->send();

if ($response->isSuccessful()) {
    $refundRef = $response->getTransactionReference();
    echo "Refund successful! Reference: " . $refundRef;
} else {
    echo "Refund failed: " . $response->getMessage();
}

$response = $gateway->purchase([
    'amount' => '10.00',
    'currency' => 'GTQ',
    'transactionId' => 'ORDER-123456',
    'returnUrl' => 'https://yoursite.com/return',
    
    // Custom 3D Secure parameters
    'challengeIndicator' => '03', // Challenge preference
    'challengeWindowSize' => 4,    // Window size for challenge
    'authenticationIndicator' => '04', // Authentication type
    
    // Custom hosted page settings
    'pageName' => 'MyCustomPage',
    'pageSet' => 'PTZ/MyPageSet',
])->send();