2017 © Pedro Peláez
 

library i-pay

IPay integration (PHP)

image

wearesho-team/i-pay

IPay integration (PHP)

  • Sunday, April 15, 2018
  • by Horat1us
  • Repository
  • 3 Watchers
  • 0 Stars
  • 0 Installations
  • PHP
  • 0 Dependents
  • 1 Suggesters
  • 0 Forks
  • 0 Open issues
  • 11 Versions
  • 0 % Grown

The README.md

IPay Integration

Latest Stable Version Total Downloads Build Status codecov, (*1)

Change Log, (*2)

Installation

Using composer:, (*3)

composer install wearesho-team/i-pay

Requirements

  • PHP >= 7.1
  • SimpleXML

Usage

Creating Payments

For configuring you application use ConfigInterface (implementation also available in Config class), (*4)

<?php

use Wearesho\Bobra\IPay;

$config = new IPay\Config($merchantId = 14, $merchantKey = 123456789, $merchantSecret = 987654321);
$config->setMode(IPay\Config::MODE_REAL); // Switching to production API (default: test)

// Note: you should use DI container to instantiate IPay\Client
$client = new IPay\Client($config, new \GuzzleHttp\Client());


/**
 * Creating payment
 */

$payment = $client->createPayment(
    new IPay\UrlPair(
        'http://ipay.ua/good',
        'http://ipay.ua/bad'
    ),
    [
        new IPay\Transaction(
            100, // Operation ID
            100.50, // Will be transformed into 10050 when requesting
            "Service Payment"
        ),
    ]
);
$payment->getUrl(); // You should redirect user to this page to make payment

/**
 * Competing payment
 */
$client->completePayment($paymentId = 3456);

/**
 * Reversing payment
 */
$client->completePayment($paymentId = 3456, IPay\Client::ACTION_REVERSAL);
// or
$client->reversePayment($paymentId = 3456);

Handling notification

Implement controller using your framework, (*5)

<?php

namespace App;

use Wearesho\Bobra\IPay;

class Controller {
    public function actionIPay() {
        // You may handle as many merchant id as you want
        // just pass here configurations with different merchant IDs
        $configProvider = new IPay\Notification\ConfigProvider([
            new IPay\Config(1, "key", "secret"),
            new IPay\Config(2, "another-key", "another-secret"),
        ]);
        $server = new IPay\Notification\Server($configProvider);

        $xml = $_POST['xml'];
        if (empty($xml)) {
            throw new \HttpException(400, "Missing XML");
        }

        try {
            // Sign checking will be done automatically 
            $payment = $server->handle($xml);
        } catch (IPay\Notification\InvalidBodyException | IPay\InvalidSignException $exception) {
            throw new \HttpException(400, $exception->getMessage(), 0, $exception);
        } catch (IPay\Notification\UnsupportedMerchantException $exception) {
            throw new \HttpException(
                501,
                "Merchant ID {$exception->getMerchantId()} is not configured"
            );
        }

        // do what you want with payment
    }
}

License

MIT, (*6)

The Versions

15/04 2018
15/04 2018
15/04 2018
09/04 2018

3.3.0

3.3.0.0

IPay integration (PHP)

  Sources   Download

MIT

The Requires

 

The Development Requires

by Alexander Letnikow

09/04 2018

3.2.0

3.2.0.0

IPay integration (PHP)

  Sources   Download

MIT

The Requires

 

The Development Requires

by Alexander Letnikow

09/04 2018

3.1.0

3.1.0.0

IPay integration (PHP)

  Sources   Download

MIT

The Requires

 

The Development Requires

by Alexander Letnikow

09/04 2018

3.0.0

3.0.0.0

IPay integration (PHP)

  Sources   Download

MIT

The Requires

 

The Development Requires

by Alexander Letnikow