checkoutfi/token-payment

此包已被弃用且不再维护。未建议替代包。

令牌支付API实现

dev-master 2018-02-19 14:07 UTC

This package is not auto-updated.

Last update: 2020-01-24 16:23:17 UTC


README

此库已弃用。

安装

composer require checkoutfi/token-payment dev-master

注册支付方式/信用卡

<?php

use CheckoutFinland\TokenPayment\Client as TokenClient;

$merchant_id        = '';
$merchant_secret    = '';		 

$token_client = new TokenClient($merchant_id, $merchant_secret);

$stamp      = str_replace('.','', microtime(true));
$return_url = 'https://...';

$response = $token_client->registerPaymentMethod($stamp, $return_url);

registerPaymentMethod()的响应是一个包含错误消息或可用于注册支付方式的服务的xml列表。目前只有信用卡选项。xml包含用于构建将用户重定向到第三方服务的表单的输入字段值和名称。

{foreach register/service as service}
    <form method="{service/form/method}" action="{service/form/action}">
    	{foreach service/fields/field as field}
    		<input type="hidden" name="{field/name}" value="{field/value}" />
    	{endforeach}
    <input type="image" src="{service/info/icon}" />
    {service/info/name}
    </form>
{endforeach}

用户注册信用卡后,将被重定向回registerPaymentMethod()中提供的return_url。

use CheckoutFinland\TokenPayment\Client as TokenClient;

$merchant_id    = '';
$secret         = '';

$version    = $_GET['VERSION'];
$merchant   = $_GET['MERCHANT'];
$stamp      = $_GET['STAMP'];
$algorithm  = $_GET['ALGORITHM'];
$token      = $_GET['TOKEN']; // if empty == failed
$key        = $_GET['KEY'];
$service    = $_GET['SERVICE'];
$mac        = $_GET['MAC']; // if empty == failed

$token_client = new TokenClient($merchant_id, $secret);

if($token_client->validateRegisterReturn($version, $merchant, $stamp, $algorithm, $token, $key, $service, $mac)) {
    // success, do things, save received token to use on creating a debit charge later
} else {
    // failed
}

使用先前注册的令牌创建收费

create-charge.php

成功支付的响应

<response>
	<code>0</code>
	<text>OK</text>
	<payment>1234</payment><!-- This a unique id for the payment --> 
</response>

如果支付需要额外处理或对支付是否成功有延迟响应,则返回的代码是1000。支付状态将通过return url稍后使用正常的支付响应进行更新。请参阅此文档中支付的正常返回响应。有关示例,请参阅https://github.com/rkioski/CheckoutAPIClient/blob/master/example/return.php

<response>
    <code>1000</code>
    <text>PROCESSING</text>
</response>