| Server IP : 210.245.233.93 / Your IP : 216.73.216.226 Web Server : Apache/2.2.15 (CentOS) System : Linux webserver2.onesolution.com.hk 2.6.32-754.35.1.el6.x86_64 #1 SMP Sat Nov 7 12:42:14 UTC 2020 x86_64 User : apache ( 48) PHP Version : 5.3.3 Disable Function : exec, shell_exec, system, passthru, popen, proc_open, pcntl_exec MySQL : ON | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : ON Directory : /var/www/hkosl.com/innoutstorage2019/paypal/ |
Upload File : |
<?php
/********************************************
* ReviewOrder.php
*
* This file is called after the user clicks on a button during
* the checkout process to use PayPal's Express Checkout. The
* user logs in to their PayPal account.
*
* This file is called twice.
*
* On the first pass, the code executes the if statement:
*
* if (! isset ($token))
*
* The code collects transaction parameters from the form
* displayed by SetExpressCheckout.html then constructs and
* sends a SetExpressCheckout request string to the PayPal
* server. The paymentType variable becomes the PAYMENTACTION
* parameter of the request string. The RETURNURL parameter
* is set to this file; this is how ReviewOrder.php is called
* twice.
*
* On the second pass, the code executes the else statement.
*
* On the first pass, the buyer completed the authorization in
* their PayPal account; now the code gets the payer details
* by sending a GetExpressCheckoutDetails request to the PayPal
* server. Then the code calls GetExpressCheckoutDetails.php.
*
* Note: Be sure to check the value of PAYPAL_URL. The buyer is
* sent to this URL to authorize payment with their PayPal
* account. For testing purposes, this should be set to the
* PayPal sandbox.
*
* Called by SetExpressCheckout.html.
*
* Calls GetExpressCheckoutDetails.php, CallerService.php,
* and APIError.php.
********************************************/
require_once 'CallerService.php';
require_once '../webadmin/basic_info.php';
$session_id = session_id();
$session_data = $_SESSION;
if (!empty($session_data["nvpReqArray"]["PWD"])) {
$session_data["nvpReqArray"]["PWD"] = "";
}
if (!empty($session_data["nvpReqArray"]["USER"])) {
$session_data["nvpReqArray"]["USER"] = "";
}
if (!empty($session_data["nvpReqArray"]["SIGNATURE"])) {
$session_data["nvpReqArray"]["SIGNATURE"] = "";
}
if(isset($_SESSION["langcode"])){
$langcode = $_SESSION["langcode"];
}else{
if(isset($_GET["langcode"])){
$langcode = $_GET["langcode"];
$_SESSION["langcode"] = $langcode;
}else{
$langcode = "en";
$_SESSION["langcode"] = $langcode;
}
}
if(!empty($_SESSION["warehousing_web"])){
$warehousing_date = $_SESSION["warehousing_web"]["warehousing_date"];
$date = new DateTime($warehousing_date);
$date->modify('+1 month');
$recurring_payment_start_date = $date->format("Y-m-d");
$rent_month = $_SESSION["warehousing_web"]["rent_month"];
}else{
$recurring_payment_start_date = date("Y-m-d");
$rent_month = 0;
}
if ($langcode == "tc") {
$LOCALECODE = "zh_HK";
$total_months_fee_text = "所有月份租金";
$first_month_fee_text = "首月租金";
$deposit_text = "按金";
$new_customer_text = "新客戶";
$discount_text = "首月半價";
$recurring_payment_text = "租金定期自動付款 - 開始日期: ".$recurring_payment_start_date.",每月自動付款 $".$_SESSION["warehousing_web"]["discounted_price"].",共 ".($rent_month-1)." 個月";
$total_amount_zero_text = "此帳單已支付。";
$hold_room_error = "你未能在指定限時內完成網上租倉,預留給你的倉庫單位已被釋出,請重新進行租倉流程。";
} else {
$LOCALECODE = "US";
$total_months_fee_text = "Total Months Fee";
$first_month_fee_text = "First Month Fee";
$deposit_text = "Deposit";
$new_customer_text = "New Customer";
$discount_text = "First Month Fee With 50% Discount";
$recurring_payment_text = "Monthly Rent Fees Recurring Payment - Start From: ".$recurring_payment_start_date." Auto Paid $".$_SESSION["warehousing_web"]["discounted_price"]." Monthly, Charge ".($rent_month-1)." Months.";
$total_amount_zero_text = "You have paid this bill.";
$hold_room_error = "You do not complete the online storage renting in a limit time, the room which reserves for you is released. Please redo the online storage renting again.";
}
$subtotal = 0;
$v_total = 0;
$nvpstr = "";
$i = 0;
if (isset($_GET["id"]) && (int)$_GET["id"] > 0 && !empty($_GET["type"])) {
//user click email paypal link
$email_location = "/../".$langcode."/rent_email.php?type=INVOICE&id=" . (int)$_GET["id"];
$cancelurl = "/../".$langcode."/index.php";
$errorurl = "/../".$langcode."/index.php?error=1";
$id = (int)$_GET["id"];
$balance = 0;
$code = "";
if ($_GET["type"] == "INVOICE") {
$invoice_info = get_invoice($id);
$balance = $invoice_info["invoice_balance"];
$code = $invoice_info["invoice_code"];
}
if ($_GET["type"] == "DEPOSIT") {
$deposit_info = get_deposit($id);
$balance = $deposit_info["deposit_balance"];
$code = $deposit_info["invoice_code"];
}
$type_info = get_master_type_code("PAYMENT_TYPE", $_GET["type"]);
$subtotal = $balance;
$v_total = $balance;
$nvpstr .= "&L_NAME$i=" . urlencode($type_info["name_" . $langcode]);
$nvpstr .= "&L_AMT$i=" . urlencode($balance); //HKD
$nvpstr .= "&L_QTY$i=" . urlencode(1);
$nvpstr .= "&L_NUMBER$i=" . urlencode($code);
$i++;
} else {
//customer online rent room and do payment
$email_location = "../" . $langcode . "/rent_email.php";
$cancelurl = "/../" . $langcode . "/confirm_rent.php";
$errorurl = "/../" . $langcode . "/confirm_rent.php?error=1";
if (!empty($_SESSION["warehousing_web"])) {
//final check the room status
$sql = "select * from room where status = ? and online_hold_time < ? and session_id = ? and id = ?";
$parameters = array("OPEN_FOR_INTERNAL", date("Y-m-d H:i:s"), session_id(), $_SESSION["warehousing_web"]["room_id"]);
$check_room = bind_pdo($sql, $parameters, "selectone");
if(!empty($check_room)){
echo "<script>alert('".$hold_room_error."'); window.location.href='../".$langcode."/rent.php?id=".$_SESSION["warehousing_web"]["master_room_id"]."';</script>";
exit;
}
if ($_SESSION["warehousing_web"]["prepaid"] == 1) {
$nvpstr .= "&L_NAME$i=" . urlencode($total_months_fee_text);
$nvpstr .= "&L_AMT$i=" . urlencode($_SESSION["warehousing_web"]["discounted_price"]); //HKD
$nvpstr .= "&L_QTY$i=" . urlencode($_SESSION["warehousing_web"]["rent_month"]);
$subtotal += $_SESSION["warehousing_web"]["discounted_price"] * $_SESSION["warehousing_web"]["rent_month"];
$i++;
} else {
//only first month
$nvpstr .= "&L_NAME$i=" . urlencode($first_month_fee_text);
$nvpstr .= "&L_AMT$i=" . urlencode($_SESSION["warehousing_web"]["discounted_price"]); //HKD
$nvpstr .= "&L_QTY$i=" . urlencode(1);
$subtotal += $_SESSION["warehousing_web"]["discounted_price"];
$i++;
}
$nvpstr .= "&L_NAME$i=" . urlencode($deposit_text);
$nvpstr .= "&L_AMT$i=" . urlencode($_SESSION["warehousing_web"]["deposit"]); //HKD
$nvpstr .= "&L_QTY$i=" . urlencode(1);
$subtotal += $_SESSION["warehousing_web"]["deposit"];
$i++;
if (!empty($_SESSION["warehousing_web"]["order_product"])) {
foreach ($_SESSION["warehousing_web"]["order_product"] as $product) {
$product_info = get_product($product["product_id"]);
$nvpstr .= "&L_NAME$i=" . urlencode($product_info["name_" . $langcode]);
$nvpstr .= "&L_AMT$i=" . urlencode($product["price"]); //HKD
$nvpstr .= "&L_QTY$i=" . urlencode($product["qty"]);
$nvpstr .= "&L_NUMBER$i=" . urlencode($product_info["code"]);
$subtotal += $product["price"] * $product["qty"];
$i++;
}
}
if ($_SESSION["warehousing_web"]["first_month_half_price"] > 0) {
$nvpstr .= "&L_NAME$i=" . urlencode($discount_text);
$nvpstr .= "&L_AMT$i=" . urlencode(-$_SESSION["warehousing_web"]["first_month_half_price"]); //HKD
$nvpstr .= "&L_QTY$i=" . urlencode(1);
$nvpstr .= "&L_DESC$i=" . urlencode($new_customer_text);
$subtotal -= $_SESSION["warehousing_web"]["first_month_half_price"];
$i++;
}
$v_total = $subtotal;
$i++;
}
}
if (!$_SESSION["warehousing_web"]["auto_paid"]) {
//normal express checkout
//TODO: process order with zero amount
if ($v_total < 0.1) {
echo "<script>alert('".$total_amount_zero_text."'); window.location.href='../".$langcode."/index.php';</script>";
exit;
}
$token = $_REQUEST['token'];
if (!isset($token)) {
/* The servername and serverport tells PayPal where the buyer
should be directed back to after authorizing payment.
In this case, its the local webserver that is running this script
Using the servername and serverport, the return URL is the first
portion of the URL that buyers will return to after authorizing payment
*/
$serverName = $_SERVER['SERVER_NAME'];
$serverPort = $_SERVER['SERVER_PORT'];
$url = dirname('http://' . $serverName . ':' . $serverPort . $_SERVER['REQUEST_URI']);
$nvpstr .= "&LOCALECODE=" . urlencode($LOCALECODE);
$currency = "HKD";
$nvpstr .= "&CURRENCYCODE=" . urlencode($currency);
$nvpstr .= "&ITEMAMT=" . urlencode($subtotal);
$nvpstr .= "&NOSHIPPING=1";
$nvpstr .= "&AMT=" . urlencode($v_total);
$nvpstr .= "&ReturnUrl=" . urlencode($url . "/ReviewOrder.php");
$nvpstr .= "&cancelURL=" . urlencode($url . $cancelurl);
$nvpstr .= "&PAYMENTACTION=Sale";
/* Make the call to PayPal to set the Express Checkout token
If the API call succeded, then redirect the buyer to PayPal
to begin to authorize payment. If an error occured, show the
resulting errors
*/
$resArray = hash_call("SetExpressCheckout", $nvpstr);
$_SESSION['reshash'] = $resArray;
$ack = strtoupper($resArray["ACK"]);
if ($ack == "SUCCESS") {
$sql = "insert into paypal_record (session_id, order_id, nvpstr, createdate) values (?, ?, ?, ?)";
$parameters = array($session_id, $order_info{"order_id"}, $nvpstr, $nowdate);
if (!($sth = $dbh->prepare($sql))) {
throw new Exception('[' . $sth->errorCode() . ']: ' . print_r($sth->errorInfo()));
}
if (!$sth->execute($parameters)) {
throw new Exception('[' . $sth->errorCode() . ']: ' . print_r($sth->errorInfo()));
}
$_SESSION['paypalid'] = $dbh->lastInsertId();
if (isset($_SESSION['paypalid']) && !empty($_SESSION['paypalid'])) {
// Redirect to paypal.com here
$token = urldecode($resArray["TOKEN"]);
$payPalURL = PAYPAL_URL . $token;
header("Location: " . $payPalURL);
} else {
$_SESSION['my_error_no'] = 'Unexpected SQL error in paypal record insert';
header("Location: APIError.php");
exit;
}
} else {
$_SESSION['my_error_no'] = 'Unexpected ACK in SetExpressCheckout';
header("Location: APIError.php");
exit;
}
} else {
/* At this point, the buyer has completed in authorizing payment
at PayPal. The script will now call PayPal with the details
of the authorization, incuding any shipping information of the
buyer. Remember, the authorization is not a completed transaction
at this state - the buyer still needs an additional step to finalize
the transaction
*/
$token = urlencode($_REQUEST['token']);
/* Build a second API request to PayPal, using the token as the
ID to get the details on the payment authorization
*/
$nvpstr = "&TOKEN=" . $token;
//$nvpstr = $nvpHeader.$nvpstr;
/* Make the API call and store the results in an array. If the
call was a success, show the authorization details, and provide
an action to complete the payment. If failed, show the error
*/
$resArray = hash_call("GetExpressCheckoutDetails", $nvpstr);
$_SESSION['reshash'] = $resArray;
$ack = strtoupper($resArray["ACK"]);
if ($ack == 'SUCCESS' || $ack == 'SUCCESSWITHWARNING') {
$_SESSION['token'] = $_REQUEST['token'];
$_SESSION['payer_id'] = $_REQUEST['PayerID'];
ini_set('session.bug_compat_42', 0);
ini_set('session.bug_compat_warn', 0);
$serverName = $_SERVER['SERVER_NAME'];
$resArray = $_SESSION['reshash'];
$nvpstr .= "&ITEMAMT=" . urlencode($resArray['ITEMAMT']);
$nvpstr .= "&NOSHIPPING=" . urlencode($resArray['NOSHIPPING']);
$nvpstr .= "&AMT=" . urlencode($resArray['AMT']);
$nvpstr .= "&TOKEN=" . urlencode($resArray['TOKEN']);
$nvpstr .= "&PAYERID=" . urlencode($resArray['PAYERID']);
$nvpstr .= "&PAYMENTACTION=" . urlencode("Sale");
$nvpstr .= "&CURRENCYCODE=" . urlencode($resArray['CURRENCYCODE']);
$nvpstr .= "&IPADDRESS=" . urlencode($serverName);
//TODO: process order with zero amount
if ($resArray['AMT'] < 0.1 && $v_total < 0.1) {
header("Location: " . $errorurl);
exit;
}
$resArray_str = var_export($resArray, true);
$resArray = hash_call("DoExpressCheckoutPayment", $nvpstr);
$ack = strtoupper($resArray["ACK"]);
if ($ack != 'SUCCESS' && $ack != 'SUCCESSWITHWARNING') {
$resArray["PassVar"] = $nvpstr;
$_SESSION['reshash'] = $resArray;
$_SESSION['my_error_no'] = 'Unexpected ACK in DoExpressCheckoutPayment';
header("Location: APIError.php");
}
//if (!empty($resArray['PAYMENTINFO_0_TRANSACTIONID']) && $resArray['PAYMENTINFO_0_PAYMENTSTATUS'] == 'Completed') {
//paypal successful
// Update DB record
$sql = "update paypal_record set paystatus = ?, nvpstr2 = ? where paypal_id=?";
$parameters = array("1", $resArray_str, $_SESSION['paypalid']);
if (!($sth = $dbh->prepare($sql))) {
throw new Exception('[' . $sth->errorCode() . ']: ' . print_r($sth->errorInfo()));
}
if (!$sth->execute($parameters)) {
throw new Exception('[' . $sth->errorCode() . ']: ' . print_r($sth->errorInfo()));
} else {
$_SESSION["paystatus"] = 1;
header("Location: " . $email_location);
exit;
}
//}else{
//$_SESSION['my_error_no'] = 'Unexpected Payment Info in DoExpressCheckoutPayment';
//header("Location: APIError.php");
//}
} else {
//Redirecting to APIError.php to display errors.
$_SESSION['my_error_no'] = 'Unexpected ACK in GetExpressCheckoutDetails';
header("Location: APIError.php");
}
}
} else {
//recurring payment with express checkout
if (!isset($_REQUEST['token'])) {
//total amount checking
if ($v_total < 0.1 || $_SESSION["warehousing_web"]["discounted_price"] < 0.1) {
echo "<script>alert('".$total_amount_zero_text."'); window.location.href='../".$langcode."/index.php';</script>";
exit;
}
$serverName = $_SERVER['SERVER_NAME'];
$serverPort = $_SERVER['SERVER_PORT'];
$url = dirname('http://' . $serverName . ':' . $serverPort . $_SERVER['REQUEST_URI']);
$nvpstr .= "&L_BILLINGTYPE0=" . urlencode("RecurringPayments");
$nvpstr .= "&L_BILLINGAGREEMENTDESCRIPTION0=" . urlencode($recurring_payment_text);
$nvpstr .= "&NOSHIPPING=1";
$nvpstr .= "&LOCALECODE=" . urlencode($LOCALECODE);
$currency = "HKD";
$nvpstr .= "&CURRENCYCODE=" . urlencode($currency);
$nvpstr .= "&ITEMAMT=" . urlencode($subtotal);
$nvpstr .= "&AMT=" . urlencode($v_total);
$nvpstr .= "&PAYMENTACTION=Sale";
$nvpstr .= "&ReturnUrl=" . urlencode($url . "/ReviewOrder.php");
$nvpstr .= "&cancelURL=" . urlencode($url . $cancelurl);
$resArray = hash_call("SetExpressCheckout", $nvpstr);
if (!empty($resArray["TOKEN"])) {
$token = urldecode($resArray["TOKEN"]);
$payPalURL = PAYPAL_URL . $token;
header("Location: " . $payPalURL);
}
} else {
/* At this point, the buyer has completed in authorizing payment
at PayPal. The script will now call PayPal with the details
of the authorization, incuding any shipping information of the
buyer. Remember, the authorization is not a completed transaction
at this state - the buyer still needs an additional step to finalize
the transaction
*/
$token = urlencode($_REQUEST['token']);
/* Build a second API request to PayPal, using the token as the
ID to get the details on the payment authorization
*/
$nvpstr = "&TOKEN=" . $token;
/* Make the API call and store the results in an array. If the
call was a success, show the authorization details, and provide
an action to complete the payment. If failed, show the error
*/
$resArray = hash_call("GetExpressCheckoutDetails", $nvpstr);
$ack = strtoupper($resArray["ACK"]);
if ($ack == 'SUCCESS' || $ack == 'SUCCESSWITHWARNING') {
ini_set('session.bug_compat_42', 0);
ini_set('session.bug_compat_warn', 0);
$serverName = $_SERVER['SERVER_NAME'];
$nvpstr .= "";
$serverName = $_SERVER['SERVER_NAME'];
$serverPort = $_SERVER['SERVER_PORT'];
$url = dirname('http://' . $serverName . ':' . $serverPort . $_SERVER['REQUEST_URI']);
$nvpstr .= "&TOKEN=" . urlencode($_REQUEST['token']);
$nvpstr .= "&INITAMT=" . urlencode($resArray["AMT"]);
$nvpstr .= "&PROFILESTARTDATE=" . urlencode($recurring_payment_start_date."T00:00:00Z");
$nvpstr .= "&DESC=" . urlencode($recurring_payment_text);
$nvpstr .= "&BILLINGPERIOD=" . urlencode("Month");
$nvpstr .= "&BILLINGFREQUENCY=" . urlencode("1");
$nvpstr .= "&TOTALBILLINGCYCLES=" . urlencode(($_SESSION["warehousing_web"]["rent_month"]-1));
$nvpstr .= "&AMT=" . urlencode($_SESSION["warehousing_web"]["discounted_price"]);
$nvpstr .= "&CURRENCYCODE=" . urlencode("HKD");
$nvpstr .= "&ReturnUrl=" . urlencode($url . "/ReviewOrder.php");
$nvpstr .= "&cancelURL=" . urlencode($url . $cancelurl);
$resArray = hash_call("CreateRecurringPaymentsProfile", $nvpstr);
$ack = strtoupper($resArray["ACK"]);
if ($ack == 'SUCCESS' || $ack == 'SUCCESSWITHWARNING') {
ini_set('session.bug_compat_42', 0);
ini_set('session.bug_compat_warn', 0);
$data = array(
"order_id" => 1,
"customer_id" => 1,
"profileid" => $resArray["PROFILEID"],
"profilestatus" => $resArray["PROFILESTATUS"],
"timestamp" => $resArray["TIMESTAMP"],
"correlationid" => $resArray["CORRELATIONID"],
"ack" => $resArray["ACK"],
"session_id" => $session_id,
"_result" => json_encode($resArray),
"_nvp" => $nvpstr,
"_session" => json_encode($session_data),
"_request" => json_encode($_REQUEST),
"_server" => json_encode($_SERVER),
"createdate" => $nowdate,
);
$result = insert_record("paypal_recurring_payment", $data);
$_SESSION["paystatus"] = 1;
//create recurring payment success
header("Location: ../".$langcode."/rent_email.php");
exit;
} else {
$data = array(
"order_id" => 1,
"customer_id" => 1,
"profileid" => "",
"profilestatus" => "",
"timestamp" => "",
"correlationid" => "",
"ack" => $resArray["ACK"],
"session_id" => $session_id,
"_result" => json_encode($resArray),
"_nvp" => $nvpstr,
"_session" => json_encode($session_data),
"_request" => json_encode($_REQUEST),
"_server" => json_encode($_SERVER),
"createdate" => $nowdate,
);
$result = insert_record("paypal_recurring_payment", $data);
//Redirecting to APIError.php to display errors.
$_SESSION['my_error_no'] = 'Unexpected ACK in GetExpressCheckoutDetails';
header("Location: APIError.php");
}
} else {
$data = array(
"order_id" => 1,
"customer_id" => 1,
"profileid" => "",
"profilestatus" => "",
"timestamp" => "",
"correlationid" => "",
"ack" => $resArray["ACK"],
"session_id" => $session_id,
"_result" => json_encode($resArray),
"_nvp" => $nvpstr,
"_session" => json_encode($session_data),
"_request" => json_encode($_REQUEST),
"_server" => json_encode($_SERVER),
"createdate" => $nowdate,
);
$result = insert_record("paypal_recurring_payment", $data);
//Redirecting to APIError.php to display errors.
$_SESSION['my_error_no'] = 'Unexpected ACK in GetExpressCheckoutDetails';
header("Location: APIError.php");
}
}
}