PHP code example of aleksandrzhiliaev / omnipay-perfectmoney

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



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

$gateway->setAccount('');
$gateway->setAccountName('');
$gateway->setBaggageFields('');
$gateway->setSuggestedMemo('');
$gateway->setPassphrase('');
$gateway->setCurrency('');

$response = $gateway->purchase([
       'amount' => '0.1',
       'currency' => 'USD',
       'transactionId' => time(),
       'description' => 'Order # 123',
       'cancelUrl' => 'https://example.com',
       'returnUrl' => 'https://example.com',
       'notifyUrl' => 'https://example.com'
        ])->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();
    $transactionId = $response->getTransactionId();
    $amount = $response->getAmount();
    $success = $response->isSuccessful();
    $currency = $response->getCurrency();
    if ($success) {
       // success
    }
} catch (\Exception $e) {
  // check $e->getMessage()
}

try {
    $response = $gateway->refund(
        [
            'payeeAccount' => 'U123456789',
            'amount' => 0.1,
            'description' => 'Testing perfectmoney',
            'currency' => 'USD',
        ]
    )->send();

    if ($response->isSuccessful()) {
        // success
    } else {
        // check $response->getMessage();
    }

} catch (\Exception $e) {
    // check $e->getMessage();
}