martinvondrak/platba-mobilom-php-sdk

PHP7.0的PlatbaMobilom.sk支付网关SDK

1.0 2019-01-11 16:17 UTC

This package is auto-updated.

Last update: 2024-09-12 05:02:52 UTC


README

此库提供了一个简单的接口,通过PlatbaMobilom.sk进行支付。一般来说,PlatbaMobilom.sk支持在线和离线支付。此库目前仅支持在线支付。

要求

  • PHP >= 7.0

安装

安装SDK最简单的方法是使用名为Composer的依赖管理器。

$ composer require martinvondrak/platba-mobilom-php-sdk

基本使用

设置客户端

use MartinVondrak\PlatbaMobilom\PlatbaMobilomClient;

$pid = 1; // merchant ID
$url = 'https//www.shop.com/callback'; // URL of callback where user will be redirected from PlatbaMobilom.sk
$pwd = 'SecretPass'; // passphrase used for signing requests
$email = 'sales@shop.com'; // merchant email (optional)
$debug = true; // flag whether production or test environment is used
$platbaMobilomClient = new PlatbaMobilomClient($pid, $url, $pwd, $email, $debug);

创建支付

use MartinVondrak\PlatbaMobilom\Http\Request;

$id = 'aef4622'; // unique ID of payment
$description = 'Payment in www.shop.com'; // description of payment
$price = 6.5; // amount to pay in EUR
$request = new Request($id, $description, $price);
// client from previous step
$redirectUrl = $platbaMobilomClient->getGatewayUrl($request);
// now redirect user to $redirectUrl

验证支付

use MartinVondrak\PlatbaMobilom\Exception\InvalidSignatureException;
use MartinVondrak\PlatbaMobilom\Http\Response;

// following attributes are in query string in request on callback url from first step
$id = $_GET['ID']; // unique ID of payment
$result = $_GET['RES']; // status of payment
$responseSignature = $_GET['SIGN']; // signature of received parameters
$phone = $_GET['PHONE']; // phone number used for payment (optional)
$response = new Response($id, $result, $responseSignature, $phone);

try {
    // client from first step
    if ($platbaMobilomClient->checkResponse($response)) {
        // paid
    } else {
        // not paid or error
    }
} catch (InvalidSignatureException $ex) {
    // signature is not valid for received data
}

PlatbaMobilom.sk文档

有关更多信息,请参阅PlatbaMobilom.sk的官方文档。遗憾的是,文档仅以斯洛伐克语提供。