PHP code example of aleksandrzhiliaev / omnipay-unitpay

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

    

aleksandrzhiliaev / omnipay-unitpay example snippets


$gateway = Omnipay::create('Unitpay');

$gateway->setPublicKey('');
$gateway->setSecretKey('');

$response = $gateway->purchase([
       'amount' => '0.1',
       'currency' => 'USD',
       'transactionId' => time(),
       'description' => 'Order # 123',
        ])->send();

if ($response->isSuccessful()) {
   // success
} elseif ($response->isRedirect()) {

   # Generate form to do payment
   $hiddenFields = '';
   foreach ($response->getRedirectData() as $key => $value) {
       $hiddenFields .= sprintf(
          '<input type="hidden" name="%1$s" value="%2$s" />',
           htmlentities($key, ENT_QUOTES, 'UTF-8', false),
           htmlentities($value, ENT_QUOTES, 'UTF-8', false)
          )."\n";
   }

   $output = '<form action="%1$s" method="post"> %2$s <input type="submit" value="Purchase" /></form>';
   $output = sprintf(
      $output,
      htmlentities($response->getRedirectUrl(), ENT_QUOTES, 'UTF-8', false),
      $hiddenFields
   );
   echo $output;
   # End of generating form
} else {
   echo $response->getMessage();
}

try {
    $response = $gateway->completePurchase()->send();
    $success = $response->isSuccessful();
    if ($success) {
       $transactionId = $response->getTransactionId();
       $amount = $response->getAmount();
       $currency = $response->getCurrency();
       // success 
    }
} catch (\Exception $e) {
  // check $e->getMessage()
}