longman/geopayment

用于处理格鲁吉亚支付服务商和银行的PHP库

0.5.4 2018-10-29 13:09 UTC

This package is auto-updated.

Last update: 2024-08-24 04:14:30 UTC


README

Build Status Latest Stable Version Total Downloads Downloads Month License

格鲁吉亚银行/终端支付集成库

目录

安装

Composer

通过Composer安装此包。

编辑你的项目composer.json文件,以需要longman/geopayment

创建composer.json文件

{
    "name": "yourproject/yourproject",
    "type": "project",
    "require": {
        "longman/geopayment": "*"
    }
}

并运行composer update

或者在你的命令行中运行命令

composer require longman/geopayment

(返回顶部)

用法

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

use Longman\GeoPayment\Payment;

// You can specify all options here
$options = [
    'option1' => 'value1',
    'option2' => 'value2',
    'option3' => 'value3',
    . . .
];

// or create .configfile file and specify file path in options
$options = [
    'config_path' => '/path/to/folder/.configfile',
];

// Create payment instance
$payment = new Payment('{provider}', '{type}', $options);

// do more job depending on bank documentation

重要:如果你的.config文件位于服务器document_root下,你必须通过http拒绝对该文件的访问。

Apache

在您的<.htaccess>文件中添加以下内容

<Files ~ "^\.(.*)$">
    Order allow,deny
    Deny from all
    Satisfy all
</Files>

Nginx

在服务器部分

location ~ /\. {
    deny all;
    access_log off;
    log_not_found off;
}

卡支付

Bog

你可以在这里找到BOG配置示例 .bog.example

Bog 步骤 1:在支付页面上重定向
<?php
require __DIR__.'/vendor/autoload.php';

use Longman\GeoPayment\Payment;

$options = [
    'config_path' => '/path/to/config/.bog',
];

// Create payment instance
$payment = new Payment('bog', Payment::TYPE_CARD, $options);

// Set mode 'redirect'
$payment->setMode('redirect');

// Set success url
$payment->setSuccessUrl('your_success_url');

// Set fail url
$payment->setFailUrl('your_fail_url');

// Set order id or any payment identificator in your db
$payment->addParam('order_id', 'your_order_id');

// You can add more params if needed
$payment->addParam('param1', 'value1');
$payment->addParam('param2', 'value2');

// And simple redirect
$payment->redirect();

// Or get payment initialization url if needed and after redirect
$url = $payment->getPaymentUrl();
. . .
$payment->redirect($url);
Bog 步骤 2:银行检查支付可用性
<?php
require __DIR__.'/vendor/autoload.php';

use Longman\GeoPayment\Payment;

$options = [
    'config_path' => '/path/to/config/.bog',
];

$payment = new Payment('bog', Payment::TYPE_CARD, $options);

// Set mode 'check'
$payment->setMode('check');

// Check IP (if needed)
$payment->checkIpAllowed();

// Check HTTP authorization
$payment->checkHttpAuth();

// Check signature validation (depends on documentation)
$payment->checkSignature();

// Here you must check order_id or any other parameters which before redirecting set via $payment->addParam
$order_id = $payment->getParam('o.order_id');
if (!$order_id) {
    $payment->sendErrorResponse('order_id is empty!');
}

// check if order exists
$order = get_order_from_yout_db($order_id);
if (empty($order)) {
    $payment->sendErrorResponse('order with id "'.$order_id.'" not found!');
}

// check if order already completed
if ($order->isCompleted()) {
    $payment->sendErrorResponse('Purchase for order "'.$order_id.'" already completed!');
}
. . .

// Build parameters for response
$params = [];
$params['amount'] = 'Order price (In minor units)';
$params['short_desc'] = 'Payment short description';
$params['long_desc'] = 'Payment long description';

$payment->sendSuccessResponse($params);
Bog 步骤 3:银行登记支付
<?php
require __DIR__.'/vendor/autoload.php';

use Longman\GeoPayment\Payment;

$options = [
    'config_path' => '/path/to/config/.bog',
];

$payment = new Payment('bog', Payment::TYPE_CARD, $options);

// Set mode 'reg'
$payment->setMode('reg');

// Check IP (if needed)
$payment->checkIpAllowed();

// Check HTTP authorization
$payment->checkHttpAuth();

// Check signature validation (depends on documentation)
$payment->checkSignature();

// Here you must check order_id or any other parameters which before redirecting set via $payment->addParam
$order_id = $payment->getParam('o.order_id');
if (!$order_id) {
    $payment->sendErrorResponse('order_id is empty!');
}

// check if order exists
$order = get_order_from_yout_db($order_id);
if (empty($order)) {
    $payment->sendErrorResponse('order with id "'.$order_id.'" not found!');
}

// check if order already completed
if ($order->isCompleted()) {
    $payment->sendErrorResponse('Purchase for order "'.$order_id.'" already completed!');
}

// Get and check payment result code
$result_code = $payment->getParam('result_code');
if (empty($result_code)) {
    $payment->sendErrorResponse('result_code is empty!');
}

// Register payment with result code (1 - success, 2 - failed)
. . .

// Send response
$payment->sendSuccessResponse();

(返回顶部)

Cartu

你可以在以下位置找到Cartu配置示例 .cartu.example

Cartu 步骤 1:在支付页面上重定向
<?php
require __DIR__.'/vendor/autoload.php';

use Longman\GeoPayment\Payment;

$options = [
    'config_path' => '/path/to/config/.cartu',
];

// Create payment instance
$payment = new Payment('cartu', Payment::TYPE_CARD, $options);

// Set mode 'redirect'
$payment->setMode('redirect');

// generate order id
$order_id = '1111111';

// prepare parameters for redirect
$purchase_desc = $order_id.'!<product name>!<product quantity>!<etc>';
$purchase_amt = '20.25';

$payment->addParam('PurchaseDesc', $purchase_desc);
$payment->addParam('PurchaseAmt', $purchase_amt);

// And simple redirect
$payment->redirect();

// Or get payment initialization url if needed and after redirect
$url = $payment->getPaymentUrl();
. . .
$payment->redirect($url);
Cartu 步骤 2:银行登记支付
<?php
require __DIR__.'/vendor/autoload.php';

use Longman\GeoPayment\Payment;

$options = [
    'config_path' => '/path/to/config/.cartu',
];

$payment = new Payment('cartu', Payment::TYPE_CARD, $options);

$payment->setMode('response');

// Check IP (if needed)
$payment->checkIpAllowed();

// get bank parameters
$TransactionId = $payment->getTransactionId();
$PaymentId = $payment->getPaymentId();
$PaymentDate = $payment->getPaymentDate();
$Amount = $payment->getAmount();
$CardType = $payment->getCardType();
$Reason = $payment->getReason();
$Status = $payment->getStatus();

switch($Status) {
    case 'C': // check
        // check order availability by TransactionId

        $payment->sendSuccessResponse($params);
        break;

    case 'Y': // success
        // update order status by TransactionId

        $payment->sendSuccessResponse($params);
        break;

    case 'N': // failed
        // set order status to failed

        $payment->sendErrorResponse('Transaction failed');
        break;

    case 'U': // unfinished

        $payment->sendErrorResponse('Unfinished request');

        break;

    default:
        // throw error
        $payment->sendErrorResponse('Status unspecified');

        break;
}

(返回顶部)

终端支付

TBC Pay

TBC Pay配置示例可以在以下位置找到 .tbcpay.example

TBC Pay 步骤 1:检查支付
<?php
require __DIR__.'/vendor/autoload.php';

use Longman\GeoPayment\Payment;

$options = [
    'config_path' => '/path/to/config/.tbcpay',
];

// Create payment instance
$payment = new Payment('tbcpay', Payment::TYPE_PAY, $options);

// Set mode 'check'
$payment->setMode('check');

// Check IP (if needed)
$payment->checkIpAllowed();

// Check HTTP authorization
$payment->checkHttpAuth();

// Get account identifier from request
$account = $payment->getParam('account');
if (empty($account)) {
    // Pass response code and message
    $payment->sendErrorResponse(4, 'Invalid Account Number Format');
}

// Check account id in db and show error if needed
. . .

// Generate some extra data for response. You can add more parameters if needed
$extra = [];
$extra['customer'] = 'John Doe';
$extra['debt'] = '500.00';

$payment->sendSuccessResponse($extra);
TBC Pay 步骤 2:登记支付
<?php
require __DIR__.'/vendor/autoload.php';

use Longman\GeoPayment\Payment;

$options = [
    'config_path' => '/path/to/config/.tbcpay',
];

// Create payment instance
$payment = new Payment('tbcpay', Payment::TYPE_PAY, $options);

// Set mode 'reg'
$payment->setMode('reg');

// Check IP (if needed)
$payment->checkIpAllowed();

// Check HTTP authorization
$payment->checkHttpAuth();

// Get account identifier from request
$account = $payment->getParam('account');
if (empty($account)) {
    $payment->sendErrorResponse(4, 'Invalid Account Number Format');
}

// Check account id in db and show error if needed
. . .

// Get transaction id
$txn_id = $payment->getParam('txn_id');
if (empty($txn_id)) {
    $payment->sendErrorResponse(300, 'txn_id is not defined');
}

// Check transaction id in db and show error if needed
. . .

// Get payd amount
$sum = $payment->getParam('sum');
if (empty($sum)) {
    $payment->sendErrorResponse(300, 'sum is not defined');
}

$payment->sendSuccessResponse();
TBC Pay:推荐响应代码

(返回顶部)

Liberty Pay

Liberty Pay 步骤 1:检查支付

待定

Liberty Pay 步骤 2:登记支付

待定

Liberty Pay:推荐响应代码

(返回顶部)

待办事项

添加更多提供商并编写更多测试

故障排除

如果你喜欢冒险,请在PHP GeoPayment问题页面上报告你发现的任何错误。

贡献

欢迎提交拉取请求。有关信息,请参阅CONTRIBUTING.md

许可

请参阅此存储库中包含的LICENSE,以获取MIT许可的完整副本,该项目据此许可。

致谢

完整的致谢名单请见CREDITS