2017 © Pedro Peláez
 

library omnipay-platbox

PlatBox gateway for Omnipay payment processing library

image

eugenevv/omnipay-platbox

PlatBox gateway for Omnipay payment processing library

  • Wednesday, April 12, 2017
  • by eugenevv
  • Repository
  • 1 Watchers
  • 1 Stars
  • 258 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

Omnipay: PlatBox

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

Omnipay is a framework agnostic, multi-gateway payment processing library for PHP 5.3+. This package implements PayPal support for Omnipay., (*2)

Installation

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

{
    "require": {
        "eugenevv/omnipay-platbox": "*"
    }
}

And run composer to update your dependencies:, (*4)

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

Basic Usage

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

  • PlatBox API (https://platbox.com/new/docs/paybox_api_1.pdf), (*6)

  • Init, (*7)

    $this->gateway = Omnipay\Omnipay::create('PlatBox');
    $this->gateway->setMerchantId('MERCHANT_ID');
    $this->gateway->setSecretKey('SECRET_KEY');
    $this->gateway->setProject('PROJECT');
    $this->gateway->setTestMode(false);
  • initPayment (from PlatBox API)
    //From your DB
    $order = OrderModel::findByPk('ORDER_ID');

    $request = $this->gateway->purchase();

    $request->setAccountId('USER_ACCOUNT_ID');
    $request->setPhoneNumber($phone);   //format: XXXXXXXXXX
    $request->setAmount($amount); //amount in kopecks
    $request->setCurrency('RUB');
    $request->setOrderId($order->id);
    $response = $request->send();
    $result = $response->getData();
  • callback "check" (from PlatBox API)
    try {
      $data = file_get_contents('php://input');
      $data = json_decode($data, true);

      $request = $this->gateway->completePurchase($data);

      //From your DB
      $order = OrderModel::findByPk($request->getOrderId());

      $request->setMerchantTxId($order->id);
      $request->setMerchantTxExtra(
        json_encode(
          array(
            'type'     => 'order_id',
            'order_id' => $order->id,
          )
        )
      );
      $request->setMerchantAmount($order->amount);
      $request->setMerchantCurrency('RUB');
      $request->setExceptionMessage("[billing_payment_orders].id = {$order->id}");

      //some custom statuses
      switch ($order->status) {
        case 'STATUS_SUCCESS':
          $request->setExceptionCode(PlatBoxException::CODE_PAYMENT_ALREADY_COMPLETED);
          break;
        case 'STATUS_CANCELED':
          $request->setExceptionCode(PlatBoxException::CODE_PAYMENT_ALREADY_CANCELED);
          break;
        case 'STATUS_INVALID_AMOUNT':
          $request->setExceptionCode(PlatBoxException::CODE_INVALID_PAYMENT_AMOUNT);
          break;
        default:
      }

      $response = $request->send();
      $result = $response->getData();

      $confirm = $response->confirm();

    } catch (PlatBoxException $e) {
      if ($e->getCode() == PlatBoxException::CODE_INVALID_PAYMENT_AMOUNT && $order) {// Bad payment sum
        //... your code
      }

      $request->error($e->getMessage(), $e->getCode());

    } catch (Exception $e) {

      $request->error('Unknown error');

    }
  • callback "pay" (from PlatBox API)
    //Example transaction for Yii
    //$transaction = Yii::app()->db->beginTransaction();

    try {
      $data = file_get_contents('php://input');
      $data = json_decode($data, true);

      $request = $this->gateway->pay($data);

      //From your DB
      $order = OrderModel::findByPk($request->getOrderId());

      $request->setMerchantTxId($order->id);
      $request->setMerchantTxTimestamp($order->start_date);
      $request->setMerchantTxExtra(
        json_encode(
          array(
            'type'     => 'order_id',
            'order_id' => $order->id,
          )
        )
      );
      $request->setMerchantAmount($order->amount);
      $request->setMerchantCurrency('RUB');
      $request->setExceptionMessage("[billing_payment_orders].id = {$order->id}");

      //some custom statuses
      switch ($order->status) {
        case 'STATUS_SUCCESS':
          $request->setExceptionCode(PlatBoxException::CODE_PAYMENT_ALREADY_COMPLETED);
          break;
        case 'STATUS_CANCELED':
          $request->setExceptionCode(PlatBoxException::CODE_PAYMENT_ALREADY_CANCELED);
          break;
        case 'STATUS_INVALID_AMOUNT':
          $request->setExceptionCode(PlatBoxException::CODE_INVALID_PAYMENT_AMOUNT);
          break;
        default:
      }

      $response = $request->send();
      $result = $response->getData();

      $confirm = $response->confirm();

      // ... your code for payment success ($user->addAmount($order->amount))

      //Example transaction for Yii
      //$transaction->commit();

    } catch (PlatBoxException $e) {
      if ($e->getCode() == PlatBoxException::CODE_INVALID_PAYMENT_AMOUNT && $order) {// Bad payment sum
        // ... your code for bad payment sum
      }

      //Example transaction for Yii
      //$transaction->commit();

      $request->error($e->getMessage(), $e->getCode());

    } catch (Exception $e) {

      //$transaction->rollback();

      $request->error('Unknown error');

    }
  • callback "cancel" (from PlatBox API)
    try {
      $data = file_get_contents('php://input');
      $data = json_decode($data, true);    

      $request = $this->gateway->cancel($data);

      //From your DB
      $order = OrderModel::findByPk($request->getOrderId());

      $request->setMerchantTxId($order->id);
      $request->setMerchantTxTimestamp($order->start_date);
      $request->setMerchantTxExtra(
        json_encode(
          array(
            'type'     => 'order_id',
            'order_id' => $order->id,
          )
        )
      );
      $request->setMerchantAmount($order->amount);
      $request->setMerchantCurrency('RUB');
      $request->setExceptionMessage("[billing_payment_orders].id = {$order->id}");

      //some custom statuses
      switch ($order->status) {
        case 'STATUS_SUCCESS':
          $request->setExceptionCode(PlatBoxException::CODE_PAYMENT_ALREADY_COMPLETED);
          break;
        default:
      }

      $response = $request->send();
      $result = $response;

      if ($order) {
        // ... your code for cancel payment
      }

      $confirm = $response->confirm();

    } catch (PlatBoxException $e) {
      if ($e->getCode() == PlatBoxException::CODE_INVALID_PAYMENT_AMOUNT && $order) {// Bad payment sum
        // ... your code for bad payment sum
      }

      $request->error($e->getMessage(), $e->getCode());

    } catch (Exception $e) {

      $error = $request->error('Unknown error');

    }

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

Out Of Scope

Omnipay does not cover recurring payments or billing agreements, and so those features are not included in this package. Extensions to this gateway are always welcome., (*9)

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

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

If you believe you have found a bug, please report it using the GitHub issue tracker, or better yet, fork the library and submit a pull request., (*12)

The Versions

12/04 2017

dev-master

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

PlatBox gateway for Omnipay payment processing library

  Sources   Download

MIT

The Requires

 

The Development Requires

by Eugene Velikanov

payment pay gateway merchant purchase omnipay platbox