lzaplata/payu

此软件包的最新版本(dev-master)没有可用的许可证信息。

PayU的Nette框架包装器。

dev-master 2018-02-05 08:31 UTC

This package is auto-updated.

Last update: 2024-09-25 07:16:25 UTC


README

这是一个PayU网关的小型Nette框架包装器。

安装

通过Composer安装库是最简单的方法。

$ composer require lzaplata/payu: dev-master

或者编辑项目中 composer.json 文件

"require": {
        "lzaplata/payu": "dev-master"
}

您需要在 config.neon 文件中将库注册为扩展。

extensions:
        payu: LZaplata\PayU\DI\Extension

现在您可以设置参数...

payu:
        posId           : *
        clientId        : *
        clientSecret    : *
        key2            : *
        sandbox         : true

...并将库自动注入到演示者中

use LZaplata\PayU\Service;

/** @var Service @inject */
public $payu;

用法

第一步您必须创建订单实例。

$order = $this->payu->createOrder([
        "description" => $description,          
        "currencyCode" => $currency,            
        "totalAmount" => $price,                    // order price in lowest currency unit (1 CZK = 100)
        "extOrderId" => $id,                        // eshop unique id
        "notifyUrl" => $notifyUrl,                  // url form sending notifications from PayU  
        "continueUrl" => $continueUrl,              // url to redirect after successful payment     
        "products" => [
                0 => [
                        "name" => $productName,
                        "unitPrice" => $unitPrice,  // product price in lowest currency unit (1 CZK = 100)
                        "quantity" => $quantity
                ]
        ],
        "buyer" => [
                "email" => $email,
                "phone" => $phone,
                "firstName" => $name,
                "lastName" => $surname
        ]
]);

第二步决定创建订单是否成功...

try {
        $response = $this->payu->pay($order);
} catch (\OpenPayU_Exception $e) {
        print $e->getMessage();
}

...最后您可以重定向到网关。

$this->sendResponse($response);