Yuansfer PHP SDK
Yuansfer Online API
Requirements
- PHP >= 5.3
- CURL extension
Installation
-
Install composer:
$ curl -sS https://getcomposer.org/installer | php
More info about installation on Linux / Unix / OSX
and Windows.
-
Run the Composer command to install the latest version of SDK:
$ php composer.phar require yuansfer/yuansfer-php-sdk
-
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
API |
Call |
Description |
Create QRC API |
$yuansfer->createTransQrcode() |
This API generates a QR Code and transaction number for the customer to scan via their digital wallet app, allowing them to initiate the payment process. |
Customer Presented Workflow
API |
Call |
Description |
Add Transaction API |
$yuansfer->createAdd() |
This API enables the creation of a transaction object and allows the customer to retrieve a transaction number for initiating payment. |
Pay Transaction API |
$yuansfer->createPrepay() |
This will allow customers to make the final confirmation before submitting payment which will process through the digital wallet servers. |
Cancel API |
$yuansfer->createCancel() |
This API allows for canceling a payment transaction in either use case when the transaction is abandoned before submission, ensuring that merchants can efficiently manage their transactions. |
REFUND AND QUERY API'S
API |
Call |
Description |
Refund API |
$yuansfer->createRefund() |
In the instance where a customer requests a refund, the following request and response objects are initiated to complete the refund workflow. |
Query API |
$yuansfer->createTranQuery() |
This API is used for polling transaction results, researching transactions for refunds, and generating custom reports. |
ECOMMERCE API'S
Pockyt Hosted Checkout
API |
Call |
Description |
SecurePay API |
$yuansfer->createSecurePay() |
By using this API, the merchant website can send customers to Pockyt to receive payments. |
Pockyt Integrated Payments
API |
Call |
Description |
Process API |
$yuansfer->createProcess() |
Utilize our Partner Payment Gateways to accept popular wallets such as PayPal, Venmo, Google Pay, and Apple Pay. When integrating with Partner Payment Gateways, utilize both the 'process' endpoint |
Customer Records
API |
Call |
Description |
Register Customer |
$yuansfer->createCustomerCreate() |
Use this API to create a new customer, and receiving the Customer Number from Pockyt, to be invoked during calls to the SecurePay API. |
Retrieve Customer |
$yuansfer->createCustomerRetrieve() |
Use this API to retrieve the customer information stored in the record, to be used in calls to the SecurePay API. |
Update Customer |
$yuansfer->createCustomerUpdate() |
Use this API to update information related to the customer's record. |
PAYOUTS API'S
Payouts
API |
Call |
Description |
Register Payee |
$yuansfer->createPayeeRegister() |
To initiate payments to your payees, you must first register an account with Pockyt. Send a POST request to the Register Customer endpoint, and you'll receive a customerNo in response. |
Retrieve Payee |
$yuansfer->createPayeeRetrieve() |
Acquire detailed information about a payee's account by sending a POST request to Pockyt's Retrieve Payee Account API. This enables you to manage and verify payee accounts effectively, maintaining the |
Update Payee |
$yuansfer->createPayeeUpdate() |
To update payee details such as name, address, email, and bank info by providing customer No and new details. The API returns a confirmation message upon successful execution |
Add Payee Bank |
$yuansfer->createPayeeAddBank() |
Add a new payment method for the payee, such as a bank account. This endpoint requires the user to provide the Merhcnat ID and the payment details in the request payload. |
Transfer Payout |
$yuansfer->createPayoutPay() |
To execute a payment, send a POST request to the payments endpoint. Upon successful validation, the specified amount will be transferred to the receiver, completing the payment transaction. |
YIP
Official Documents
API |
Call |
Description |
/order/v4/capture |
$yuansfer->createYipOrderCapture() |
To fund a payment with a credit or debit card. |
API |
Call |
Description |
/online/v4/secure-pay |
$yuansfer->createYipSecurePay() |
|
PayPal Payment Method |
$yuansfer->createYipOrderProcess() |
Call this API when the customer approved the payment order, see HTML Sample code at #line 57 |
Card Payment Method |
$yuansfer->createYipOrderProcess() |
Call this API when the customer approved the payment order, see HTML Sample code at #line 57 |
API |
Call |
Description |
Capture order and save payment methods |
$yuansfer->createYipSecurePayVault() |
|
Complete the payment transaction |
$yuansfer->createYipOrderProcess() |
Call this API when the customer approved the payment order, see HTML Sample code at #line 57 |
Pay with saved payment methods |
$yuansfer->createYipSecurePayVaultSaved() |
|