tkhconsult/kina-pg-sdk

Kinabank支付网关SDK

v1.0.5 2021-08-02 06:07 UTC

This package is auto-updated.

Last update: 2024-09-07 19:06:46 UTC


README

GitHub issues Version

Packagist包(库),为任何基于PHP的网站提供访问KinaBank接口的方式,该接口是商家系统用来处理基于标准CGI/WWW表单提交方法的信用卡电子商务交易。此接口透明地支持各种持卡人身份验证协议,如3-D Secure和Secure Code,以及传统的非验证SSL电子商务交易。

🏠 主页

演示

安装

composer require tkhconsult/kina-pg-sdk

需求

  • PHP >= 5.5
  • OpenSSL >=0.9.8

用法

步骤1. 环境配置(非必需)

您可以使用以下Composer包之一

composer require vlucas/phpdotenv

composer require symfony/dotenv

.env文件

# Merchant ID / Card acceptor ID assigned by bank
KINA_BANK_MERCHANT_ID=xxxxxxxxxxxxxxx

# Merchant Terminal ID assigned by bank 
KINA_BANK_MERCHANT_TERMINAL=xxxxxxxx

# Merchant primary web site URL
KINA_BANK_MERCHANT_URL='http://example.com'

# Merchant name (recognizable by cardholder)
KINA_BANK_MERCHANT_NAME='Merchant company name'

# Merchant company registered office address
KINA_BANK_MERCHANT_ADDRESS='Merchant address'

# File name of merchant secret key
KINA_BANK_MERCHANT_SECRET_KEY=secret.key

# Payment page type (embedded / hosted)
KINA_BANK_PAYMENT_PAGE_TYPE=embedded

# Default Merchant shop timezone
# Used to calculate the timezone offset sent to KinaBank
# Refer: https://php.ac.cn/manual/en/timezones.php
KINA_BANK_MERCHANT_TIMEZONE_NAME='Pacific/Port_Moresby'

# Merchant shop 2-character country code. 
# Must be provided if merchant system is located 
# in a country other than the gateway server's country. 
KINA_BANK_MERCHANT_COUNTRY_CODE=PG

# Default currency for all operations: 3-character currency code 
KINA_BANK_MERCHANT_DEFAULT_CURRENCY=PGK

# Default forms language
# By default are available forms in en
# If need forms in another languages please contact gateway
# administrator
KINA_BANK_MERCHANT_DEFAULT_LANGUAGE=en

步骤2. 初始化网关客户端

通过configureFromEnv方法初始化网关客户端

<?php

use TkhConsult\KinaBankGateway\KinaBankGateway;

$kinaBankGateway = new KinaBankGateway();

$secretKeyDir = '/path/to/keys';
$kinaBankGateway
    ->configureFromEnv($secretKeyDir)
;

手动初始化网关客户端

您可以重现configureFromEnv()方法的实现

步骤3. 请求支付授权 - 跳转到银行页面

<?php

use TkhConsult\KinaBankGateway\KinaBankGateway;
$backRefUrl = getenv('KINA_BANK_MERCHANT_URL').'/after-payment/';

/** @var KinaBankGateway $kinaBankGateway */
$kinaBankGateway
    ->requestAuthorization($orderId = 1, $amount = 1, $backRefUrl, $currency = "PGK", $description = "iPhone X Pro", $clientEmail = "customer@yopmail.com", $language = 'en')
;

步骤4. 接收银行响应 - 所有银行响应都是异步服务器到服务器,并由相同的URI处理

<?php

use TkhConsult\KinaBankGateway\KinaBankGateway;
use TkhConsult\KinaBankGateway\KinaBank\Exception;
use TkhConsult\KinaBankGateway\KinaBank\Response;

/** @var KinaBankGateway $kinaBankGateway */
$bankResponse = $kinaBankGateway->getResponseObject($_POST);

if (!$bankResponse->isValid()) {
    throw new Exception('Invalid bank Auth response');
}

switch ($bankResponse::TRX_TYPE) {
    case KinaBankGateway::TRX_TYPE_AUTHORIZATION:
        $orderId        = KinaBankGateway::deNormalizeOrderId($bankResponse->{Response::ORDER});
        $amount         = $bankResponse->{Response::AMOUNT};
        $bankOrderCode  = $bankResponse->{Response::ORDER};
        $rrn            = $bankResponse->{Response::RRN};
        $intRef         = $bankResponse->{Response::INT_REF};

        #
        # You must save $rrn and $intRef from the response here for reversal requests
        #
        echo '<pre>';
        print_r([$bankResponse, $orderId]);

        # Funds locked on bank side - transfer the product/service to the customer and request completion
        $kinaBankGateway->requestCompletion($orderId, $amount, $rrn, $intRef, $currency = "PGK");
        break;

    default:
        throw new Exception('Unknown bank response transaction type');
}

作者

👤 由 TkhConsult团队 精心打造

🤝 贡献

欢迎贡献、问题和功能请求!
请随意查看 问题页面