PHP code example of yuansfer / yuansfer-php-sdk

1. Go to this page and download the library: Download yuansfer/yuansfer-php-sdk library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

yuansfer / yuansfer-php-sdk example snippets


       

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);

$api = $yuansfer->createSecurePay();

$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.

$response = $api->send();

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

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

try {
    $response = $api->send();
} catch (\Yuansfer\Exception\YuansferException $e) {
    // am: ' . $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();
    }
}
sh
    $ curl -sS https://getcomposer.org/installer | php
    
sh
    $ php composer.phar