PHP code example of zgabievi / geopayment

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

    

zgabievi / geopayment example snippets



Longman\GeoPayment\Payment;

// You can specify all options here
$options = [
    'option1' => 'value1',
    'option2' => 'value2',
    'option3' => 'value3',
    . . .
];

// or create .configfile file and specify file path in options
$options = [
    'config_path' => '/path/to/folder/.configfile',
];

// Create payment instance
$payment = new Payment('{provider}', '{type}', $options);

// do more job depending on bank documentation



Longman\GeoPayment\Payment;

$options = [
    'config_path' => '/path/to/config/.bog',
];

// Create payment instance
$payment = new Payment('bog', Payment::TYPE_CARD, $options);

// Set mode 'redirect'
$payment->setMode('redirect');

// Set success url
$payment->setSuccessUrl('your_success_url');

// Set fail url
$payment->setFailUrl('your_fail_url');

// Set order id or any payment identificator in your db
$payment->addParam('order_id', 'your_order_id');

// You can add more params if needed
$payment->addParam('param1', 'value1');
$payment->addParam('param2', 'value2');

// And simple redirect
$payment->redirect();

// Or get payment initialization url if needed and after redirect
$url = $payment->getPaymentUrl();
. . .
$payment->redirect($url);


Longman\GeoPayment\Payment;

$options = [
    'config_path' => '/path/to/config/.bog',
];

$payment = new Payment('bog', Payment::TYPE_CARD, $options);

// Set mode 'check'
$payment->setMode('check');

// Check IP (if needed)
$payment->checkIpAllowed();

// Check HTTP authorization
$payment->checkHttpAuth();

// Check signature validation (depends on documentation)
$payment->checkSignature();

// Here you must check order_id or any other parameters which before redirecting set via $payment->addParam
$order_id = $payment->getParam('o.order_id');
if (!$order_id) {
    $payment->sendErrorResponse('order_id is empty!');
}

// check if order exists
$order = get_order_from_yout_db($order_id);
if (empty($order)) {
    $payment->sendErrorResponse('order with id "'.$order_id.'" not found!');
}

// check if order already completed
if ($order->isCompleted()) {
    $payment->sendErrorResponse('Purchase for order "'.$order_id.'" already completed!');
}
. . .

// Build parameters for response
$params = [];
$params['amount'] = 'Order price (In minor units)';
$params['short_desc'] = 'Payment short description';
$params['long_desc'] = 'Payment long description';

$payment->sendSuccessResponse($params);



Longman\GeoPayment\Payment;

$options = [
    'config_path' => '/path/to/config/.bog',
];

$payment = new Payment('bog', Payment::TYPE_CARD, $options);

// Set mode 'reg'
$payment->setMode('reg');

// Check IP (if needed)
$payment->checkIpAllowed();

// Check HTTP authorization
$payment->checkHttpAuth();

// Check signature validation (depends on documentation)
$payment->checkSignature();

// Here you must check order_id or any other parameters which before redirecting set via $payment->addParam
$order_id = $payment->getParam('o.order_id');
if (!$order_id) {
    $payment->sendErrorResponse('order_id is empty!');
}

// check if order exists
$order = get_order_from_yout_db($order_id);
if (empty($order)) {
    $payment->sendErrorResponse('order with id "'.$order_id.'" not found!');
}

// check if order already completed
if ($order->isCompleted()) {
    $payment->sendErrorResponse('Purchase for order "'.$order_id.'" already completed!');
}

// Get and check payment result code
$result_code = $payment->getParam('result_code');
if (empty($result_code)) {
    $payment->sendErrorResponse('result_code is empty!');
}

// Register payment with result code (1 - success, 2 - failed)
. . .

// Send response
$payment->sendSuccessResponse();



Longman\GeoPayment\Payment;

$options = [
    'config_path' => '/path/to/config/.cartu',
];

// Create payment instance
$payment = new Payment('cartu', Payment::TYPE_CARD, $options);

// Set mode 'redirect'
$payment->setMode('redirect');

// generate order id
$order_id = '1111111';

// prepare parameters for redirect
$purchase_desc = $order_id.'!<product name>!<product quantity>!<etc>';
$purchase_amt = '20.25';

$payment->addParam('PurchaseDesc', $purchase_desc);
$payment->addParam('PurchaseAmt', $purchase_amt);

// And simple redirect
$payment->redirect();

// Or get payment initialization url if needed and after redirect
$url = $payment->getPaymentUrl();
. . .
$payment->redirect($url);


Longman\GeoPayment\Payment;

$options = [
    'config_path' => '/path/to/config/.cartu',
];

$payment = new Payment('cartu', Payment::TYPE_CARD, $options);

$payment->setMode('response');

// Check IP (if needed)
$payment->checkIpAllowed();

// get bank parameters
$TransactionId = $payment->getTransactionId();
$PaymentId = $payment->getPaymentId();
$PaymentDate = $payment->getPaymentDate();
$Amount = $payment->getAmount();
$CardType = $payment->getCardType();
$Reason = $payment->getReason();
$Status = $payment->getStatus();

switch($Status) {
    case 'C': // check
        // check order availability by TransactionId

        $payment->sendSuccessResponse($params);
        break;

    case 'Y': // success
        // update order status by TransactionId

        $payment->sendSuccessResponse($params);
        break;

    case 'N': // failed
        // set order status to failed

        $payment->sendErrorResponse('Transaction failed');
        break;

    case 'U': // unfinished

        $payment->sendErrorResponse('Unfinished request');

        break;

    default:
        // throw error
        $payment->sendErrorResponse('Status unspecified');

        break;
}




Longman\GeoPayment\Payment;

$options = [
    'config_path' => '/path/to/config/.tbcpay',
];

// Create payment instance
$payment = new Payment('tbcpay', Payment::TYPE_PAY, $options);

// Set mode 'check'
$payment->setMode('check');

// Check IP (if needed)
$payment->checkIpAllowed();

// Check HTTP authorization
$payment->checkHttpAuth();

// Get account identifier from request
$account = $payment->getParam('account');
if (empty($account)) {
    // Pass response code and message
    $payment->sendErrorResponse(4, 'Invalid Account Number Format');
}

// Check account id in db and show error if needed
. . .

// Generate some extra data for response. You can add more parameters if needed
$extra = [];
$extra['customer'] = 'John Doe';
$extra['debt'] = '500.00';

$payment->sendSuccessResponse($extra);



Longman\GeoPayment\Payment;

$options = [
    'config_path' => '/path/to/config/.tbcpay',
];

// Create payment instance
$payment = new Payment('tbcpay', Payment::TYPE_PAY, $options);

// Set mode 'reg'
$payment->setMode('reg');

// Check IP (if needed)
$payment->checkIpAllowed();

// Check HTTP authorization
$payment->checkHttpAuth();

// Get account identifier from request
$account = $payment->getParam('account');
if (empty($account)) {
    $payment->sendErrorResponse(4, 'Invalid Account Number Format');
}

// Check account id in db and show error if needed
. . .

// Get transaction id
$txn_id = $payment->getParam('txn_id');
if (empty($txn_id)) {
    $payment->sendErrorResponse(300, 'txn_id is not defined');
}

// Check transaction id in db and show error if needed
. . .

// Get payd amount
$sum = $payment->getParam('sum');
if (empty($sum)) {
    $payment->sendErrorResponse(300, 'sum is not defined');
}

$payment->sendSuccessResponse();