1200wd/quickpay-php-client

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

PHP-SDK 用于与支付提供商 QuickPay 通信

dev-patch-php53 2016-03-23 11:44 UTC

This package is not auto-updated.

Last update: 2021-07-25 09:29:58 UTC


README

Build Status

quickpay-php-client 是 QuickPay API 的官方客户端。[QuickPay API](http://tech.quickpay.net/api) 允许您以安全可靠的方式接收支付。此包目前支持 QuickPay v10 API。

安装

/QuickPay/ 上传到您的网页空间。

用法

在进行任何操作之前,您应该向 QuickPay 注册并获取访问凭证。如果您还没有,请点击此处申请。

创建新客户端

首先,您应该创建一个匿名客户端实例或使用 QuickPay 提供的 api_key 或登录凭证授权的客户端实例。

初始化匿名客户端

<?php
    namespace QuickPay;
    require_once( 'QuickPay.php' );
    try {
        $client = new QuickPay();
    }
    catch(Exception $e) {
        //...
    }
?>

使用 QuickPay API Key 初始化客户端

<?php
    namespace QuickPay;
    require_once( 'QuickPay.php' );
    try {
        $api_key = 'xxx';
        $client = new QuickPay(":{$api_key}");
    }
    catch(Exception $e) {
        //...
    }
?>

或者,您可以提供如下的登录凭证

<?php
    namespace QuickPay;
    require_once( 'QuickPay.php' );
    try {
        $qp_username = 'xxx';
        $qp_password = 'xxx';
        $client = new QuickPay("{$qp_username}:{$qp_password}");
    }
    catch(Exception $e) {
        //...
    }
?>

API 调用

您可以使用相应的 HTTP 方法和方法端点调用 QuickPay API 中描述的任何方法。目前支持的方法有:getpostputpatchdelete

// Get all payments
$payments = $client->request->get('/payments');

// Get specific payment
$payments = $client->request->get('/payments/{id}');

// Create payment
$form = array(
    'order_id' => $order_id,
    'currency' => $currency,
    ...
);
$payments = $client->request->post('/payments', $form);

处理响应

获取 HTTP 状态码

$response = $client->request->get('/payments');
$status = $response->http_status();

if( $status == 200 ) {
    // Successful request
}

返回的响应对象支持三种返回响应体的方式:as_raw()as_objectas_array()

// Get the HTTP status code, headers and raw response body.
list($status_code, $headers, $response_body) = $client->request->get('/payments')->as_raw();

// Get the response body as an object
$response_body = $client->request->get('/payments')->as_object();

// Get the response body as an array
$response_body = $client->request->get('/payments')->as_array();


// Example usage
$payments = $client->request->get('/payments')->as_array();

foreach( $payments as $payment ) {
    //...
}

您可以在http://tech.quickpay.net/api/ 上了解更多关于 API 响应的信息。

测试

使用 composer 创建自动加载器

$ composer update
$ phpunit --bootstrap vendor/autoload.php