yuansfer/yuansfer-php-sdk

Yuansfer PHP SDK

v3.0.5 2023-12-20 01:40 UTC

This package is auto-updated.

Last update: 2024-10-11 08:27:22 UTC


README

Latest Stable Version Total Downloads Monthly Downloads License

Yuansfer Online API

Requirements

  • PHP >= 5.3
  • CURL extension

Installation

  1. Install composer:

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

    More info about installation on Linux / Unix / OSX and Windows.

  2. Run the Composer command to install the latest version of SDK:

    $ php composer.phar require yuansfer/yuansfer-php-sdk
  3. Require Composer's autoloader in your PHP script (assuming it is in the same directory where you installed Composer):

    require('vendor/autoload.php');

Usage

Please see examples

1. Init

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::MER_GROUP_NO => 'The merchant group NO, optional.',
);

$yuansfer = new Yuansfer($config);

2. Create API

$api = $yuansfer->createSecurePay();

3. Set API Parameters

$api
    ->setAmount(9.9) //The amount of the transaction.
    ->setCurrency('USD') // The currency, USD, CAD supported yet.
    ->setSettleCurrency('USD') // When the currency is "GBP", the settlement currency is "GBP". All other currencies settle with "USD"
    ->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. Send

$response = $api->send();

4.2. Use Test Mode

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

5. API return JSON, already decoded as array

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

6. Exceptions when sending

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 Documents

Official Documents

IN-STORE API'S

Merchant Presented Workflow

Customer Presented Workflow

REFUND AND QUERY API'S

ECOMMERCE API'S

Pockyt Hosted Checkout

Pockyt Integrated Payments

Customer Records

PAYOUTS API'S

Payouts

YIP

Official Documents

capture

no_vaulting

with_vaulting