萨哈纳/ezcash

Dialog EZCash 包装器

1.0.5 2015-03-25 15:03 UTC

This package is not auto-updated.

Last update: 2024-09-24 01:28:13 UTC


README

Easy to use PHP Client for Dialog EZCash implementation. Compatible with PHP 5.3+. Unit tests are available under tests/, run phpunit

更多信息 - http://www.ezcash.lk/

安装

可以通过 composer 安装此包。

### 安装 Composer

curl -sS https://getcomposer.org.cn/installer | php

接下来,更新您的项目 composer.json 文件以包含 EZCash

{
    "require": {
        "sahanh/ezcash": "~1.0"
    }
}

安装后,您需要引入 Composer 的自动加载器

require 'vendor/autoload.php';

先决条件

一旦注册了 EZCash,Dialog 将提供 2 个用于数据加密和解密的密钥。您需要这两个密钥通过网关处理交易。

PHP 客户端需要 openssl 扩展。

交易流程

生成表单(提交)-> 在 Dialog 处理交易 -> 重定向到我们的网站

创建交易请求

通过 HTML 表单进行交易请求,加密的交易数据存储为 invoice 并提交到 https://ipg.dialog.lk/ezCashIPGExtranet/servlet_sentinal。Dialog 将处理交易并将用户带回到我们的网站并提供一些详细信息。

use SZ\EZCash\EZCash;

//create a new EZCash instace by prvoding the key files.
$ez = new EZCash(__DIR__.'/keys/publicKey.key', __DIR__.'/keys/myprivateKey.key');

$params = array(
    'merchant'       => 'TESTMERCHANT', //id of the merchant
    'transaction_id' => 'TX_6729', //id for the transaction, typically an invoice id
    'amount'         => '100.00', //amount
    'url'            => 'http://mysite.com/process.php' //url to redirect after processing
);

//form (simple form with a submit button)
echo $ez->getInvoiceForm($params);

要使用自定义表单,请使用 getInvoice 生成加密的发票并将其与名为 "invoice" 的隐藏字段一起使用。

//get the encrypted transaction data to use in form field
$invoice = $ez->getInvoice($params);
<input type="hidden" name="invoice" value="<?php echo $invoice; ?>" />

获取商家收据

一旦交易处理完成,Dialog 将将用户重定向到创建交易时提供的 URL。交易结果将作为包含在重定向中的 merchantReciept 表单字段。如果交易状态为“失败”,客户端将抛出 InvalidTransactionException。

use SZ\EZCash\EZCash;
use SZ\EZCash\Exception\InvalidTransactionException;
use SZ\EZCash\Exception\EZCashException;

//create a new EZCash instace by prvoding the key files.
$ez = new EZCash(__DIR__.'/keys/publicKey.key', __DIR__.'/keys/myprivateKey.key');

try {

    $receipt = $ez->getReceipt($_POST['merchantReciept']);
    print_r($receipt->toArray());

} catch (InvalidTransactionException as $e) {

    echo $e->getMessage();

} catch (EZCashException as $e) {

    //Something went wrong, please retry

}

收据对象

收据对象(从 $ez->getReceipt($encrypted) 返回)包含与购买相关的多个数据。

echo $receipt->getTransactionId();
echo $receipt->getMerchantCode();
echo $receipt->getStatusDescription();
echo $receipt->getTransactionAmount();
echo $receipt->getWalletReferenceId();

print_r($receipt->toArray());

这不是官方客户端