<?php
include("nusoap/nusoap.php");
$url = "http://www.paysbuy.com/api_paynow/api_paynow.asmx?WSDL";
$client = new soap_client($url, true);
$psbID = "Your PSBID";
$username = "Your PAYSBUY Account";
$secureCode = "Your Secure Code";
$inv = "Your Invoice";
$itm = "Description of product";
$amt = "Price of product";
$paypal_amt = "Price of product (US Dolla Only)";
$curr_type = "TH";
$com = "";
$method = "1"; //1=PAYSBUY Account, 2=Credit Card
$language = "T";
//Change to your URL
$resp_front_url = "URL of frontend process";
$resp_back_url = "URL of backend process";
//Optional data
$opt_fix_redirect = "";
$opt_fix_method = "";
$opt_name = "";
$opt_email = "";
$opt_mobile = "";
$opt_address = "";
$opt_detail = "";
$result = "";
//1. Step 1 call method api_paynow_authentication
$params = array("psbID"=>$psbID, "username"=>$username, "secureCode"=>$secureCode, "inv"=>$inv, "itm"=>$itm, "amt"=>$amt, "paypal_amt"=>$paypal_amt, "curr_type"=>$curr_type, "com"=>$com, "method"=>$method, "language"=>$language, "resp_front_url"=>$resp_front_url, "resp_back_url"=>$resp_back_url, "opt_fix_redirect"=>$opt_fix_redirect, "opt_fix_method"=>$opt_fix_method, "opt_name"=>$opt_name, "opt_email"=>$opt_email, "opt_mobile"=>$opt_mobile, "opt_address"=>$opt_address, "opt_detail"=>$opt_detail);
$result = $client->call('api_paynow_authentication_new', array('parameters' => $params), 'http://tempuri.org/', 'http://tempuri.org/api_paynow_authentication_new', false, true);
if ($client->getError()) {
echo "<h2>Constructor error</h2><pre>" . $client->getError() . "</pre>";
} else {
$result = $result["api_paynow_authentication_newResult"];
}
echo "<br>result ->".$result;
$approveCode = substr($result,0,2);
echo "<br>approveCode->".$approveCode;
$intLen = strlen($result);
$strRef = substr($result,2, $intLen-2);
//2. If authentication is successful, then the server responds 00, The process continues redirect to PAYSBUY API Page.
if($approveCode=="00") {
echo "<meta http-equiv='refresh'
content='0;url=https://www.paysbuy.com/api_payment/paynow.aspx?securecode=".$strSecureCode."&refid=".$strRef."'>";
} else {
echo "<br>Can't login to paysbuy server";
}
?>
>?php
//1. รับค่าจากทาง PAYSBUY โดย POST Method
$strResult = trim($_REQUEST["result"]);
$strApCode = trim($_REQUEST["apCode"]);
$strAmt = trim($_REQUEST["amt"]);
$strMethod = trim($_REQUEST["method"]);
if(($strResult!="")&&($strApCode!="")&&($strAmt!="")&&($strMethod!="")){
$len = strlen($strResult);
$payment_status = substr($strResult, 0,2);
$strInvoice = substr($strResult, 2,$len-2);
//2 บันทึกข้อมูลลง Database ชื่อ api
if (!$link = mysql_connect('localhost', 'ชื่อผู้มีสิทธิ์ใช้ฐานข้อมูล', 'รหัสผ่าน')) {
echo 'Could not connect to mysql';
exit;
}
if (!mysql_select_db('ชื่อฐานข้อมูล', $link)) {
echo 'Could not select database';
exit;
}
$sql = "INSERT INTO payment(PaymentResult, PaymentApCode, PaymentAmt, PaymentMethod,
PaymentDate,PaymentInvoice, PaymentStatus )VALUES ('$strResult', '$strApCode', '$strAmt', '$strMethod',
NOW(),'$strInvoice','$payment_status' )";
$result = mysql_query($sql, $link);
if (!$result) {
echo "DB Error, could not query the database\n";
echo 'MySQL Error: ' . mysql_error();
exit;
}
mysql_close($link);
}else{
//insert error log into table
}
?>
<?php
$IsTrue = "false";
//1. รับค่าจากทาง PAYSBUY โดย POST Method
$strResult = trim($_REQUEST["result"]);
$strApCode = trim($_REQUEST["apCode"]);
$strAmt = trim($_REQUEST["amt"]);
$strMethod = trim($_REQUEST["method"]);
if(($strResult!="")&&($strApCode!="")&&($strAmt!="")&&($strMethod!="")){
$len = strlen($strApCode);
$payment_status = substr($strApCode, 0,2);
$strInvoice = substr($strApCode, 2,$len-2);
//2. ตรวจสอบค่าที่ได้จาก Backend Process
$IsTrue = checkBackEndProcess($strResult,$strApCode,$strAmt);
//echo "<br>checkBackEndProcess=>".$IsTrue ;
if($IsTrue){
//Delivery the product to customer.
echo "<br>This transaction is complete.";
}else{
echo "<br>This transaction is uncomplete.";
}
}else{
echo "<br>Can't receive data from paysbuy";
}
//************************ Function checkBackEndProcess *****************************//
function checkBackEndProcess($strResult,$strApCode,$strAmt){
$isBackend = "true";
$strResultB="";
$strApCodeB="";
$strAmtB="";
if (!$link = mysql_connect('localhost', 'ชื่อผู้มีสิทธิ์ใช้ฐานข้อมูล', 'รหัสผ่าน')) {
echo 'Could not connect to mysql';
exit;
}
if (!mysql_select_db('ชื่อฐานข้อมูล', $link)) {
echo 'Could not select database';
exit;
}
$sql = 'SELECT * FROM payment WHERE PaymentResult= '.$strResult;
$result = mysql_query($sql, $link);
if (!$result) {
echo "DB Error, could not query the database\n";
echo 'MySQL Error: ' . mysql_error();
exit;
}
while ($row = mysql_fetch_assoc($result)) {
$strResultB = trim($row['PaymentResult']);
$strApCodeB = trim($row['PaymentApCode']);
$strAmtB = trim($row['PaymentAmt']);
}
//echo "<br>strResultB=>".$strResultB ;
//echo "<br>strApCodeB=>".$strApCodeB ;
//echo "<br>strAmtB=>".$strAmtB ;
if($strResultB!=$strResult){
$isBackend = "false";
}
if($strApCodeB!=$strApCode){
$isBackend = "false";
}
if($strAmtB!=$strAmt){
$isBackend = "false";
}
mysql_free_result($result);
mysql_close($link);
//echo "<br>isBackend=>".$isBackend ;
return $isBackend;
}
//************** End Function checkBackEndProcess ************************//
?>