PHP code example of wearesho-team / i-pay

1. Go to this page and download the library: Download wearesho-team/i-pay 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/ */

    

wearesho-team / i-pay example snippets




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);




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
    }
}