1. Go to this page and download the library: Download uqpay/uqpay_php 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/ */
uqpay / uqpay_php example snippets
use uqpay\payment\config\ConfigOfAPI;
use uqpay\payment\Constants;
use uqpay\payment\Gateway;
use uqpay\payment\model\BankCard;
use uqpay\payment\model\HttpClientInterface;
use uqpay\payment\model\PaymentOrder;
use uqpay\payment\PayMethodHelper;
$merchant_id = 1005004;
$prv_key = 'Your_Private_Key_Content';
$pub_key = 'The_UQPAY_Public_Key_Your_Downloaded_Content';
// under test mode all request will call the test sandbox of UQPAY, and for default the test mode is on
$test_mode = true;
$uqpay_config = ConfigOfAPI::builder(
$prv_key,
Constants::SIGN_TYPE_RSA,
$pub_key,
$merchant_id,
$test_mode
);
$uqpay_gateway = new Gateway($uqpay_config);
/**
* Implementing HttpClientInterface
* here we just use curl
**/
class HttpClient implements HttpClientInterface {
public function post( array $headers, $body, $url ) {
$curl_headers = array();
$curl_headers[] = 'Content-type: '.$headers['content-type'];
$curl_headers[] = 'UQPAY-Version: '.$headers['UQPAY-Version'];
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 1);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HTTPHEADER, $curl_headers);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $body);
$res = curl_exec($curl);
curl_close($curl);
return $res;
}
}
$uqpay_gateway->setHttpClient(new HttpClient());
/**
* credit card payment
**/
$payment_order = new PaymentOrder();
$payment_order->method_id = PayMethodHelper::UNION_PAY_EXPRESS_PAY;
$payment_order->order_id = time();
$payment_order->trans_name = 'product name';
$payment_order->amount = 1;
$payment_order->currency = 'HKD';
$payment_order->date = time();
$payment_order->client_ip = '127.0.0.1';
$payment_order->callback_url = 'https://localhost:8080/async';
$bank_card = new BankCard();
$bank_card->first_name = 'test';
$bank_card->last_name = 'test';
$bank_card->card_num='6250947000000014';
$bank_card->cvv='123';
$bank_card->expire_year=33;
$bank_card->expire_month=12;
$result = $uqpay_gateway->pay($payment_order, $bank_card);
var_dump($result);
/**
* host-ui server side
*/
/**
* host pre-init
*/
$host_pre = new HostPreInit();
$host_pre->customer = "1005004";
$host_pre->date = time();
$result = $uqpay_gateway->hostPreInit($host_pre);
var_dump($result);
/**
* host pay
*/
$host_pay = new HostPayOrder();
$host_pay->card_token = '92796b16ced54e448e3c04e031a72cf4';
$host_pay->order_id = time();
$host_pay->trans_name = 'product name';
$host_pay->amount = 1;
$host_pay->currency = 'HKD';
$host_pay->date = time();
$host_pay->client_ip = '127.0.0.1';
$host_pay->callback_url = 'https://localhost:8080/async';
$result = $uqpay_gateway->hostPay($host_pay);
var_dump($result);
shell script
composer
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.