aleksandrzhiliaev/omnipay-okpay

There is no license information available for the latest version (1.0.0.0) of this package.

Okpay gateway for Omnipay payment processing library

1.0.0.0 2017-05-28 11:53 UTC

This package is auto-updated.

Last update: 2022-01-10 05:57:10 UTC


README

Build Status Codacy Badge Latest Stable Version Total Downloads

Okpay gateway for Omnipay payment processing library.

Omnipay is a framework agnostic, multi-gateway payment processing library for PHP 5.3+. This package implements Okpay support for Omnipay.

Installation

Omnipay is installed via Composer. To install, simply add it to your composer.json file:

{
    "require": {
        "aleksandrzhiliaev/omnipay-okpay": "*"
    }
}

And run composer to update your dependencies:

$ curl -s http://getcomposer.org/installer | php
$ php composer.phar update

Basic Usage

The following gateways are provided by this package:

  • Okpay

For general usage instructions, please see the main Omnipay repository. See also the Okpay Documentation

Example

  1. Purchase:
$gateway = Omnipay::create('Okpay');

$gateway->setAccount('');
$gateway->setAccountName('');
$gateway->setSecret('');

$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();
}
  1. Validate webhook
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()
}
  1. Do refund
try {
    $response = $gateway->refund(
        [
            'payeeAccount' => 'OK993835197',
            'amount' => 0.1,
            'description' => 'Testing okpay',
            'currency' => 'USD',
        ]
    )->send();

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

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

Support

If you are having general issues with Omnipay, we suggest posting on Stack Overflow. Be sure to add the omnipay tag so it can be easily found.

If you want to keep up to date with release anouncements, discuss ideas for the project, or ask more detailed questions, there is also a mailing list which you can subscribe to.

If you believe you have found a bug, please report it using the GitHub issue tracker.