checkoutfi/charge-api

此包已被废弃,不再维护。未建议替代包。

Charge API实现

dev-master 2018-02-19 13:59 UTC

This package is not auto-updated.

Last update: 2020-01-24 16:05:47 UTC


README

此库已弃用。

Build Status

授权

为了为商户创建收费,商户必须首先授予收费授权。您可以通过以下方式请求授权:

POST: https://rpcapi.checkout.fi/charge/authorize

<?php
 
$post_data = [
     'MERCHANT'      => '123456',
     'AUTHORIZER'    => '654321',
     'VALID'         => '2016-01-01', // or ''
     'MESSAGE'       => 'By granting the authorization you accept monthly fees from xyz service', // max 1000 chars
     'TIMESTAMP'     => time(true),
     'MAC'           => $mac
];

....

$mac = hash_hmac('sha256', "{$merchant}&{$authorizer}&{$valid}&{$message}&{$timestamp}", $secret);

响应

{
    success: true || false,
    response_code: <response code>,
    message: Created
}

列出授权

获取待处理和批准的授权请求列表

POST: https://rpcapi.checkout.fi/charge/list

<?php 

$post_data = [
   'MERCHANT'      => '123456',
   'TIMESTAMP'     => time(true),
   'MAC'           => $mac
];

...
 
$mac = hash_hmac('sha256', "{$merchant}&{$timestamp}", $this->secret);

响应

{
    success: true || false,
    response_code: <response code>,
    message: OK
    data: [
        {merchant_id: 654321, approved_at: '2016-01-23', valid_until: null || 'Y-m-d'}
    ]
}

创建收费

POST: https://rpcapi.checkout.fi/charge/debit

<?php

$post_data = [
     'MERCHANT'     => '123456',
     'CHARGE_FROM'  => '654321',
     'DATE'         => '2015-12-12',
     'AMOUNT'       => '1500', // amout is in cents
     'REFERENCE'    => '12344',
     'STAMP'        => '1234567890', // must be unique
     'DESCRIPTION'  => 'Description of the charge',
     'MAC'          => $mac
];

....
 
$mac = hash_hmac('sha256', "{merchant}&{$charge_from}&{$date}&{$amount}&{$reference}&{$stamp}&{$description}", $secret);

响应

{
    success: true || false,
    response_code: <response code>,
    message: Message,
    data: {
        STAMP: 1234567890,
        AMOUNT: 1500,
        ID: Checkout id
    }
}

响应代码

响应代码 描述
0 成功
100 商户id无效
110 MAC不匹配错误
120 拒绝服务访问
130 授权者id无效
140 授权已存在
150 未找到有效授权
160 AMOUNT不是整数
170 AMOUNT是0
180 余额不足
190 信用失败,交易已取消
200 借记失败