PHP code example of ampeco / omnipay-fibank

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

    

ampeco / omnipay-fibank example snippets


$gateway = Omnipay::create('\Ampeco\OmnipayFibank\Gateway');
$gateway->initialize([
    'merchantCertificate'           => '... The PEM certificate you got from the bank',
    'merchantCertificatePassword'   => 'The Certificate Password',
    'createCardAmount'              => 1.00, // The amount and currency to use for the create account initial payment
    'createCardCurrency'            => 'BGN',
    'testMode' => true,
]);

try{
    $response = $gateway->createCard([
        'clientIp'      => 'CLIENT IP ADDRESS',
        'expiry'        => date('Y-m-d', strtotime('+10 years')),
        'description'   => 'Register a new payment method. The amount will be credited to your account',
])->send();
} catch (EcommException $e) {
    abort(422, $e->getMessage());
}

if (!$response->isSuccessful()) {
    abort(422, $response->getMessage());
}

// You must redirect the client to:
echo $response->getRedirectUrl();
echo $response->getTransactionId(); // The transaction ID assigned by the bank

$transactionReference = '1234567890'; // Fetched from above - $response->getTransactionId()
try {
    $result = $gateway->transactionResult([
        'transactionId' => $transactionReference,
        'clientIp' => 'CLIENT IP ADDRESS',
    ])->send();
} catch (EcommException $e) {
    abort(422, $e->getMessage());
}

if (!$result->isSuccessful()){
    abort(422, $result->getMessage());
}

// The card reference
echo $result->getCardReference(); // recurring_test_reference1234`

try {
    $cardReference = 'recurring_test_reference1234'; // saved from above - $result->getCardReference();
    $response = $gateway->purchase([
        'cardReference'     => $cardReference,
        'amount'            => 3,
        'currency'          => 'BGN',
        'description'       => 'Purchase #1234',
    ])->send();
} catch (EcommException $e) {
    abort(422, $e->getMessage());
}

if ($response->isSuccessful()) {
    echo $response->getTransactionReference();
    
} else {
    abort(422, $response->getMessage());
}