yuansfertest/yuansfer-php-test-sdk

Yuansfer PHP SDK

v3.1 2021-04-29 23:44 UTC

This package is not auto-updated.

Last update: 2024-09-28 11:20:54 UTC


README

Latest Stable Version Total Downloads Monthly Downloads License

Yuansfer 在线 API

要求

  • PHP >= 5.3
  • CURL 扩展

安装

使用 Composer(推荐)

  1. 安装 composer

    $ curl -sS https://getcomposer.org/installer | php

    有关 Linux / Unix / OSX 和 Windows 上安装的更多信息,请参阅 Linux / Unix / OSXWindows

  2. 运行 Composer 命令以安装 SDK 的最新版本

    php composer.phar require yuansfer/yuansfer-php-sdk
  3. 在您的 PHP 脚本中要求 Composer 的自动加载器(假设它位于您安装 Composer 的同一目录中)

    require('vendor/autoload.php');

带有捆绑依赖的 PHAR

不推荐使用!使用 Composer 作为与 PHP 包一起工作的现代方式。

  1. 下载 PHAR 文件

  2. 要求文件

    require('path-to-sdk/yuansfer-php-sdk.phar');

请记住,捆绑的依赖项可能会干扰您的其他依赖项。

用法

请参阅 示例

1. 初始化

use Yuansfer\Yuansfer;

$config = array(
    Yuansfer::MERCHANT_NO => 'The merchant NO.',
    Yuansfer::STORE_NO => 'The store NO.',
    Yuansfer::API_TOKEN => 'Yuansfer API token',
    Yuansfer::TEST_API_TOKEN => 'Yuansfer API token for test mode',
);

$yuansfer = new Yuansfer($config);

2. 创建 API

$api = $yuansfer->createSecurePay();

3. 设置 API 参数

$api
    ->setAmount(9.9) //The amount of the transaction.
    ->setCurrency('USD') // The currency, USD, CAD supported yet.
    ->setVendor('alipay') // The payment channel, alipay, wechatpay, unionpay, enterprisepay are supported yet.
    ->setReference('44444') //The unque ID of client's system.
    ->setIpnUrl('http://domain/example/callback_secure_pay_ipn.php') // The asynchronous callback method.
    ->setCallbackUrl('http://domain/example/callback_secure_pay.php'); // The Synchronous callback method.

4.1. 发送

$response = $api->send();

4.2. 使用测试模式

$yuansfer->setTestMode();
$response = $api->send();

5. API 返回 JSON,已解码为数组

if ($response['ret_code'] === '000100') {
	header('Location: ' . $response['result']['cashierUrl']);
}

6. 发送时发生的异常

try {
    $response = $api->send();
} catch (\Yuansfer\Exception\YuansferException $e) {
    // required param is empty
    if ($e instanceof \Yuansfer\Exception\RequiredEmptyException) {
        $message = 'The param: ' . $e->getParam() . ' is empty, in API: ' . $e->getApi();
    }

    // http connect error
    if ($e instanceof \Yuansfer\Exception\HttpClientException) {
        $message = $e->getMessage();
    }

    // http response status code < 200 or >= 300, 301 and 302 will auto redirect
    if ($e instanceof \Yuansfer\Exception\HttpErrorException) {
        /** @var \Httpful\Response http response */
        $response = $e->getResponse();
    }
}

API 文档

官方文档

支付

在线支付

Yuansfer 检查站
Yuansfer 集成支付

POS 支付

扫描二维码

创建二维码

交易撤销

交易数据搜索