PHP code example of haykkarapetyan / omnipay-ameriabank

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

    

haykkarapetyan / omnipay-ameriabank example snippets


    use Omnipay\Omnipay;


$gateway = Omnipay::create('Ameriabank');
$gateway->setClientId('Client_ID'); // Shoud be your Ameriabank Client ID (e.g. 7e7ef8ff-6300-4a78-bb31-3ad1a8c67d5f)
$gateway->setUsername('Username');  // Should be your Ameria Username 
$gateway->setPassword('Password');  // Should be your Ameria password
$gateway->setOpaque('Opaque');      // Is not mandatory field and used as additional information during information exchange 
$gateway->setOrderId('Order_ID');   // Is randomly generated ID. Integer which is generated by using system local time e.g. time()
$gateway->setCurrency('AMD');       // Uses national currency e.g. AMD, USD, EUR 
$gateway->setTestMode(false);       // Boolean and can be only true or false
$payment = $gateway->purchase([             
     'amount' => '100',         
     'returnUrl' => 'http://example.com/xxx',  // The URL to which you will be redirected after completing the purchase. Please also refer to poin 4 below
     'description' => 'Description ...'
    ]
)->createPaymentRequest();



if (empty($payment->GetPaymentIDResult->PaymentID) || $payment->GetPaymentIDResult->Respmessage != 'OK') {

    return $payment->GetPaymentIDResult; // in case if response was negative (rejected).

} else {
    $gateway->setPaymentId($payment->GetPaymentIDResult->PaymentID);            //if positive, call receive payment ID 
    $gateway->setClientUrl("http://example.com/ameriarequestframe.aspx");       // Setting /ameriarequestframe.aspx inside your site
    $gateway->setLanguage('en');
    $response = $gateway->purchase()->send();                                   // generate unique URL 
    return [
        'redirectUrl' => $response->getRedirectUrl()                            // redirection to previously generated unique URL 
    ];
}




$gateway = Omnipay::create('Ameriabank');
$gateway->setClientId('Client_ID'); // Shoud be your Ameriabank Client ID (e.g. 7e7ef8ff-6300-4a78-bb31-3ad1a8c67d5f)
$gateway->setUsername('Username');  // Should be your Ameria Username 
$gateway->setPassword('Password');  // Should be your Ameria password
$gateway->setOrderId('Order_ID');   // Is randomly generated ID. Integer which is generated by using system local time e.g. time()
$gateway->setTestMode(false);       // Boolean and can be only true or false
$$webService = $gateway->completePurchase([             
     'amount' => '100'
    ]
)->getPaymentFields();

if ($paymentFields = $webService->GetPaymentFieldsResult) {
   // Your logic
    return $paymentFields;
}

return $webService; // Return error text in case of connection errors