alias2k/omnipay-payu

Omnipay支付处理库的PayU网关

v1.0.0 2020-02-17 08:24 UTC

This package is auto-updated.

Last update: 2024-09-17 19:36:34 UTC


README

Omnipay PHP支付处理库的PayU驱动程序

Omnipay 是一个不依赖于框架的多网关支付处理库,适用于PHP 5.6+。此包实现了Omnipay v3的PayU在线支付网关支持。

PayU REST API 2.1 文档

此实现使用OAuth 2

安装

Omnipay通过 Composer 安装。要安装,只需将其添加到您的 composer.json 文件中。

{
    "require": {
        "alias2k/omnipay-payu": "~1.0.0"
    }
}

TL;DR

<?php
require 'vendor/autoload.php';

use Omnipay\PayU\GatewayFactory;

$dotenv = new Dotenv\Dotenv(__DIR__);
$dotenv->load();

// default is official sandbox
$posId = isset($_ENV['POS_ID']) ? $_ENV['POS_ID'] : '300046';
$secondKey = isset($_ENV['SECOND_KEY']) ? $_ENV['SECOND_KEY'] : '0c017495773278c50c7b35434017b2ca';
$oAuthClientSecret = isset($_ENV['OAUTH_CLIENT_SECRET']) ? $_ENV['OAUTH_CLIENT_SECRET'] : 'c8d4b7ac61758704f38ed5564d8c0ae0';

$gateway = GatewayFactory::createInstance($posId, $secondKey, $oAuthClientSecret, true);

try {
    $orderNo = '12345677';
    $returnUrl = 'https://:8000/gateway-return.php';
    $description = 'Shopping at myStore.com';

    $purchaseRequest = [
        'purchaseData' => [
            'customerIp'    => '127.0.0.1',
            'continueUrl'   => $returnUrl,
            'notifyUrl'     => $notifyUrl,
            'merchantPosId' => $posId,
            'description'   => $description,
            'currencyCode'  => 'PLN',
            'totalAmount'   => 15000,
            'extOrderId'    => $orderNo,
            'buyer'         => (object)[
                'email'     => 'test@test.com',
                'firstName' => 'Tester',
                'lastName'  => 'Tester',
                'language'  => 'pl'
            ],
            'products'      => [
                (object)[
                    'name'      => 'Lenovo ThinkPad Edge E540',
                    'unitPrice' => 15000,
                    'quantity'  => 1
                ]
            ],
            'payMethods'    => (object)[
                'payMethod' => (object)[
                    'type'  => 'PBL', // this is for card-only forms (no bank transfers available)
                    'value' => 'c'
                ]
            ]
        ]
    ];

    $response = $gateway->purchase($purchaseRequest);

    echo "TransactionId: " . $response->getTransactionId() . PHP_EOL;
    echo 'Is Successful: ' . (bool) $response->isSuccessful() . PHP_EOL;
    echo 'Is redirect: ' . (bool) $response->isRedirect() . PHP_EOL;

    // Payment init OK, redirect to the payment gateway
    echo $response->getRedirectUrl() . PHP_EOL;
} catch (\Exception $e) {
    dump((string)$e);
}

为自定义沙盒payu网关,根据 .env-default 准备 .env 文件。

测试卡

正授权

负授权

卡的过期日期应为有效日期范围,值CVC / CVV2 (3个随机数字)。沙盒环境不支持3DS。