2017 © Pedro Peláez
 

library omnipay-platbox

PlatBox driver for the Omnipay payment processing library

image

webtoucher/omnipay-platbox

PlatBox driver for the Omnipay payment processing library

  • Monday, July 31, 2017
  • by webtoucher
  • Repository
  • 1 Watchers
  • 1 Stars
  • 435 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 1 Versions
  • 22 % Grown

The README.md

Omnipay: PlatBox

PlatBox payment processing driver for the Omnipay PHP payment processing library., (*1)

Latest Stable Version Total Downloads Daily Downloads Latest Unstable Version License, (*2)

Installation

The preferred way to install this library is through composer., (*3)

Either run, (*4)

$ php composer.phar require webtoucher/omnipay-platbox "*"

or add, (*5)

"webtoucher/omnipay-platbox": "*"

to the require section of your composer.json file., (*6)

Usage

The following gateways are provided by this package:, (*7)

  • PlatBox API (https://api.platbox.com)
    $gateway = \Omnipay\Omnipay::create('PlatBox');
    $gateway->setMerchantId('[MERCHANT_ID]');
    $gateway->setSecretKey('[SECRET_KEY]');
    $gateway->setProject('[PROJECT]');
    // $gateway->setTestMode(true);

The first step is preparing data and sending to PlatBox., (*8)

    $request = $gateway->purchase([
        'order_id' => $orderId,
        'amount' => $amount,
        'currency' => 'RUB',
        'account_id' => $userId,
        'phone_number' => $phone,
    ]);
    $response = $request->send();
    $result = $response->isSuccessful();

There is the callback request handler., (*9)

    try {
        $data = json_decode(file_get_contents('php://input'), true);
    } catch (\Exception $e) {
        $data = [];
    }
    $action = isset($data['action']) ? $data['action'] : null;
    switch ($action) {
        case 'check':
            $request = $gateway->check($data);
            handleCallback($request, $failCallback);
            break;
        case 'pay':
            $request = $gateway->completePurchase($data);
            handleCallback($request, $failCallback, $successCallback);
            break;
        case 'cancel':
            $request = $gateway->completePurchase($data);
            handleCallback($request, $failCallback, $cancelCallback);
            break;
        default:
            // wrong request handler
    }

There is the callback request 'check' handler., (*10)

    function handleCallback($request, $failCallback = null, $completeCallback = null) {
        try {
            $orderId = $request->getOrderId();
            $order = [...]; // find order model by order ID.
            if (!$order) {
                PlatBoxException::throwException(PlatBoxException::CODE_ORDER_NOT_FOUND_OR_BAD_DATA);
            }
            // Check order status
            if ($order->status = [...]) { // already paid
                PlatBoxException::throwException(PlatBoxException::CODE_PAYMENT_ALREADY_COMPLETED);
            }
            if ($order->status = [...]) { // already cancelled
                PlatBoxException::throwException(PlatBoxException::CODE_PAYMENT_ALREADY_CANCELED);
            }

            $request->setMerchantOrderId($order->id);
            $request->setMerchantAmount($order->amount);
            $request->setMerchantCurrency($order->currency);

            $responseData = $response->getData();
            $response->confirm();
            if (is_callable($successCallback)) {
                call_user_func($successCallback, $response);
            }
        } catch (PlatBoxException $e) {
            if (is_callable($failCallback)) {
                call_user_func($failCallback, $response);
            }
            $request->error($e->getMessage(), $e->getCode());
        } catch (\Exception $e) {
            if (is_callable($failCallback)) {
                call_user_func($failCallback, $response);
            }
            $request->error();
        }
    }

For general usage instructions, please see the main Omnipay repository., (*11)

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., (*12)

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., (*13)

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

The Versions

31/07 2017

dev-master

9999999-dev https://github.com/webtoucher/omnipay-platbox

PlatBox driver for the Omnipay payment processing library

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

by Alexey Kuznetsov

payment pay gateway merchant omnipay payments mobile platbox