ÿØÿà JFIF H H ÿÛ C ÿÛ Cÿ " ÿÄ ÿÄ ÿÚ ±5¬€ ÿÄ àÿÚ ÿÄ ÀÿÚ ? ÿÄ ÀÿÚ ? ÿÄ àÿÚ ? ÿÄ àÿÚ ?! ÿÚ ÿÄ ÀÿÚ ? ÿÄ ÀÿÚ ? ÿÄ àÿÚ ? ÿÙ
| Server IP : 160.25.81.117 / Your IP : 216.73.216.137 Web Server : Apache/2 System : Linux sv05.hilab.cloud 3.10.0-1160.119.1.el7.x86_64 #1 SMP Tue Jun 4 14:43:51 UTC 2024 x86_64 User : bellizen ( 1045) PHP Version : 7.2.34 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : OFF | Perl : OFF | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : /home/bellizen/public_html/app/Http/Controllers/ |
Upload File : |
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Http\Requests\UsersRequest;
use App\Providers\ProductView;
use Illuminate\Support\Facades\Auth;
use Carbon\Carbon;
use App\Products;
use App\NewsLetter;
use App\OrderDetail;
use App\Orders;
use App\Users;
use Input, File;
use DB,Cache,Mail,Session,Cart,Hash;
error_reporting(0);
class NL_CheckOutV3 extends Controller {
// public $url_api ='https://www.nganluong.vn/checkout.api.nganluong.post.php';
// public $merchant_id = '45434';
// public $merchant_password = '3baf1254a095ba540480948a1df362ce';
// public $receiver_email = 'duydoan.nina@gmail.com';
//pass: mua365.123123 / mua365.12345678
public $cur_code = 'vnd';
public function __construct()
{
$this->version ='3.1';
// $this->url_api ='https://www.nganluong.vn/checkout.api.nganluong.post.php';
// $this->merchant_id = '52865';
// $this->merchant_password = 'ea9c264187e8b63ae11795ff878e5a65';
// $this->receiver_email = 'duydoan.webdesign@gmail.com';
$this->url_api ='https://sandbox.nganluong.vn:8088/nl30/checkout.api.nganluong.post.php';
$this->merchant_id = '45504';
$this->merchant_password = '5f6193a9c535c1d902d18dc962e08ba0';
$this->receiver_email = 'nguyennhan091@gmail.com';
$this->cur_code = 'vnd';
}
public function postCheckoutBank(Request $request){
session_start();
$product_cart= Cart::content()->toArray();
$nlcheckout= new NL_CheckOutV3(MERCHANT_ID,MERCHANT_PASS,RECEIVER,URL_API);
$total_amount=$request->total_amount;
$array_items[0]= array('item_name1' => 'Product name',
'item_quantity1' => 1,
'item_amount1' => $total_amount,
'item_url1' => 'http://nganluong.vn/');
//$array_items=array();
$array_items=$product_cart;
// foreach($product_cart as $k=>$item){
// $array_items[$k] = array('name' => $item->name,
// 'qty' => $item->qty,
// 'price' => $item->price*$item->qty,
// 'url' => 'fsd');
// }
// }
$payment_method =$request->option_payment;
$bank_code = $request->bankcode;
$order_code ="bankcode_".time();
$payment_type ='';
$discount_amount =0;
$order_description='';
$tax_amount=0;
$fee_shipping=0;
$return_url ='http://www.bellizeno.vn/payment-success';
$cancel_url =urlencode('http://www.bellizeno.vn/checkout-bank?orderid='.$order_code);
$buyer_fullname = $_REQUEST['txtname'];
$buyer_email = $_REQUEST['txtemail'];
$buyer_mobile = $_REQUEST['txtphone'];
$buyer_address = $_REQUEST['txtaddress'];
// ngoà i
if($payment_method =="3"){
$cart = Cart::content();
$order = new Orders;
$order->name = $request->txtname;
$order->email = $request->txtemail;
$order->address = $request->txtaddress;
$order->phone = $request->txtphone;
$order->total = $request->totalPrice;
$order->code = 'COD';
$order->save();
foreach ($cart as $key => $value) {
$order_detail = new OrderDetail;
$order_detail->id_order = $order->id;
$order_detail->id_product = $value->id;
$order_detail->qty = $value->qty;
// add thêm nhiá»u thông số
$order_detail->chatlieu1 = $value->options->chatlieu1;
$order_detail->chatlieu2 = $value->options->chatlieu2;
$order_detail->chatlieu3 = $value->options->chatlieu3;
$order_detail->size1 = $value->options->size1;
$order_detail->size2 = $value->options->size2;
$order_detail->size3 = $value->options->size3;
$order_detail->mau1 = $value->options->mau1;
$order_detail->mau2 = $value->options->mau2;
$order_detail->mau3 = $value->options->mau3;
$order_detail->rem1 = $value->options->rem1;
$order_detail->rem2 = $value->options->rem2;
$order_detail->chatlieusale0 = $value->options->chatlieusale0;
$order_detail->chatlieusale1 = $value->options->chatlieusale1;
$order_detail->sizesale0 = $value->options->sizesale0;
$order_detail->sizesale1 = $value->options->sizesale1;
$order_detail->colorsale0 = $value->options->colorsale0;
$order_detail->colorsale1 = $value->options->colorsale1;
$order_detail->pricesale0 = $value->options->pricesale0;
$order_detail->pricesale1 = $value->options->pricesale1;
$order_detail->ids0 = $value->options->ids0;
$order_detail->ids1 = $value->options->ids1;
$order_detail->chatlieu4 = $value->options->chatlieu4;
$order_detail->chatlieu5 = $value->options->chatlieu5;
$order_detail->size4 = $value->options->size4;
$order_detail->size5 = $value->options->size5;
$order_detail->mau4 = $value->options->mau4;
$order_detail->mau5 = $value->options->mau5;
$order_detail->rem3 = $value->options->rem3;
$order_detail->rem4 = $value->options->rem4;
//goicao
$order_detail->chatlieu6 = $value->options->chatlieu6;
$order_detail->size6 = $value->options->size6;
$order_detail->mau6 = $value->options->mau6;
// end add them thong so
$order_detail->totalprice = ($value->price*$value->qty);
$order_detail->save();
}
Session::forget('cart');
return redirect('/')->with([
'toastr_lvl' => 'success',
'toastr_msg' => 'Äặt hà ng thà nh công'
]);
} else {
// End ngoà i
if($payment_method !='' && $buyer_email !="" && $buyer_mobile !="" && $buyer_fullname !="" && filter_var( $buyer_email, FILTER_VALIDATE_EMAIL ) ){
if($payment_method =="VISA"){
$nl_result= $nlcheckout->VisaCheckout($order_code,$total_amount,$payment_type,$order_description,$tax_amount,$fee_shipping,$discount_amount,$return_url,$cancel_url,$buyer_fullname,$buyer_email,$buyer_mobile, $buyer_address,$array_items,$bank_code);
}elseif($payment_method =="NL"){
$nl_result= $nlcheckout->NLCheckout($order_code,$total_amount,$payment_type,$order_description,$tax_amount,$fee_shipping,$discount_amount,$return_url,$cancel_url,$buyer_fullname,$buyer_email,$buyer_mobile, $buyer_address,$array_items);
}elseif($payment_method =="ATM_ONLINE" && $bank_code !='' ){
$nl_result= $nlcheckout->BankCheckout($order_code,$total_amount,$bank_code,$payment_type,$order_description,$tax_amount,$fee_shipping,$discount_amount,$return_url,$cancel_url,$buyer_fullname,$buyer_email,$buyer_mobile,
$buyer_address,$array_items) ;
}
elseif($payment_method =="NH_OFFLINE"){
$nl_result= $nlcheckout->officeBankCheckout($order_code, $total_amount, $bank_code, $payment_type, $order_description, $tax_amount, $fee_shipping, $discount_amount, $return_url, $cancel_url, $buyer_fullname, $buyer_email, $buyer_mobile, $buyer_address, $array_items);
}
elseif($payment_method =="ATM_OFFLINE"){
$nl_result= $nlcheckout->BankOfflineCheckout($order_code, $total_amount, $bank_code, $payment_type, $order_description, $tax_amount, $fee_shipping, $discount_amount, $return_url, $cancel_url, $buyer_fullname, $buyer_email, $buyer_mobile, $buyer_address, $array_items);
}
elseif($payment_method =="IB_ONLINE"){
$nl_result= $nlcheckout->IBCheckout($order_code, $total_amount, $bank_code, $payment_type, $order_description, $tax_amount, $fee_shipping, $discount_amount, $return_url, $cancel_url, $buyer_fullname, $buyer_email, $buyer_mobile, $buyer_address, $array_items);
}
elseif ($payment_method == "CREDIT_CARD_PREPAID") {
$nl_result = $nlcheckout->PrepaidVisaCheckout($order_code, $total_amount, $payment_type, $order_description, $tax_amount, $fee_shipping, $discount_amount, $return_url, $cancel_url, $buyer_fullname, $buyer_email, $buyer_mobile, $buyer_address, $array_items, $bank_code);
}
//var_dump($nl_result); die;
if ($nl_result->error_code =='00'){
$cart = Cart::content();
$order = new Orders;
$order->code = $order_code;
$order->name = $_REQUEST['txtname'];
$order->email = $_REQUEST['txtphone'];
$order->address = $_REQUEST['address_thongtin'];
$order->phone = $_REQUEST['txtaddress'];
$buyer_fullname = $_REQUEST['txtname'];
$order->id_user = $request->id_user;
$tongtien=0;
$tongthanhtoan=0;
foreach($cart as $item){
$tongtien+= $item->price*$item->qty;
}
$tongthanhtoan=$tongtien;
$order->total = $tongthanhtoan;
$order->payment_method = $payment_method;
$order->bank_code = $bank_code;
$order->hinhthuc = 1;
$order->save();
foreach ($cart as $key => $value) {
$order_detail = new OrderDetail;
$order_detail->id_order = $order->id;
$order_detail->id_product = $value->id;
$order_detail->qty = $value->qty;
// add thêm nhiá»u thông số
$order_detail->chatlieu1 = $value->options->chatlieu1;
$order_detail->chatlieu2 = $value->options->chatlieu2;
$order_detail->chatlieu3 = $value->options->chatlieu3;
$order_detail->size1 = $value->options->size1;
$order_detail->size2 = $value->options->size2;
$order_detail->size3 = $value->options->size3;
$order_detail->mau1 = $value->options->mau1;
$order_detail->mau2 = $value->options->mau2;
$order_detail->mau3 = $value->options->mau3;
$order_detail->rem1 = $value->options->rem1;
$order_detail->rem2 = $value->options->rem2;
$order_detail->chatlieusale0 = $value->options->chatlieusale0;
$order_detail->chatlieusale1 = $value->options->chatlieusale1;
$order_detail->sizesale0 = $value->options->sizesale0;
$order_detail->sizesale1 = $value->options->sizesale1;
$order_detail->colorsale0 = $value->options->colorsale0;
$order_detail->colorsale1 = $value->options->colorsale1;
$order_detail->pricesale0 = $value->options->pricesale0;
$order_detail->pricesale1 = $value->options->pricesale1;
$order_detail->ids0 = $value->options->ids0;
$order_detail->ids1 = $value->options->ids1;
$order_detail->chatlieu4 = $value->options->chatlieu4;
$order_detail->chatlieu5 = $value->options->chatlieu5;
$order_detail->size4 = $value->options->size4;
$order_detail->size5 = $value->options->size5;
$order_detail->mau4 = $value->options->mau4;
$order_detail->mau5 = $value->options->mau5;
$order_detail->rem3 = $value->options->rem3;
$order_detail->rem4 = $value->options->rem4;
//goicao
$order_detail->chatlieu6 = $value->options->chatlieu6;
$order_detail->size6 = $value->options->size6;
$order_detail->mau6 = $value->options->mau6;
// end add them thong so
$order_detail->totalprice = ($value->price*$value->qty);
$order_detail->save();
}
//Cáºp nhât order vá»›i token $nl_result->token để sá» dụng check hoà n thà nh sau nà y
?>
<script type="text/javascript">
<!--
window.location = "<?php echo(string)$nl_result->checkout_url; // .'&lang=en' chuyển mặc định tiếng anh ?>"
//-->
</script>
<?php
}else{
echo $nl_result->error_message;
}
}else{
$thongbao='Bạn chưa nháºp đủ thông tin thanh toán';
// Cấu hình SEO
$title = "Kết quả thanh toán";
$keyword = "Kết quả thanh toán";
$description = "Kết quả thanh toán";
$img_share = '';
//End cấu hình SEO
return view('templates.payment_success_tpl', compact('thongbao','keyword','description','title','img_share'));
}
} // end code thuong
}
public function getPaymentSuccess(){
// Cấu hình SEO
$title = "Kết quả thanh toán";
$keyword = "Kết quả thanh toán";
$description = "Kết quả thanh toán";
$img_share = '';
//End cấu hình SEO
return view('templates.payment_success_tpl', compact('keyword','description','title','img_share'));
}
public function getCheckoutBank(){
return redirect()->route('index');
}
public function GetTransactionDetail($token){
###################### BEGIN #####################
$params = array(
'merchant_id' => $this->merchant_id ,
'merchant_password' => MD5($this->merchant_password),
'version' => $this->version,
'function' => 'GetTransactionDetail',
'token' => $token
);
// $params = array(
// 'merchant_id' => $this->merchant_id ,
// 'merchant_password' => MD5($this->merchant_password),
// 'version' => $this->version,
// 'function' => 'GetTransactionDetail',
// 'token' => $token
// );
$post_field = '';
foreach ($params as $key => $value){
if ($post_field != '') $post_field .= '&';
$post_field .= $key."=".$value;
}
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$this->url_api);
curl_setopt($ch, CURLOPT_ENCODING , 'UTF-8');
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_field);
$result = curl_exec($ch);
$status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
$error = curl_error($ch);
if ($result != '' && $status==200){
$nl_result = simplexml_load_string($result);
return $nl_result;
}
return false;
###################### END #####################
}
/*
Hà m lấy link thanh toán bằng thẻ visa
===============================
Tham số truyá»n và o bắt buá»™c phải có
order_code
total_amount
payment_method
buyer_fullname
buyer_email
buyer_mobile
===============================
$array_items mảng danh sách các item name theo quy tắc
item_name1
item_quantity1
item_amount1
item_url1
.....
payment_type Kiểu giao dịch: 1 - Ngay; 2 - Tạm giữ; Nếu không truyá»n hoặc bằng rá»—ng thì lấy theo chÃnh sách cá»§a NganLuong.vn
*/
public function VisaCheckout($order_code,$total_amount,$payment_type,$order_description,$tax_amount,
$fee_shipping,$discount_amount,$return_url,$cancel_url,$buyer_fullname,$buyer_email,$buyer_mobile,
$buyer_address,$array_items,$bank_code)
{
$params = array(
'cur_code' => $this->cur_code,
'function' => 'SetExpressCheckout',
'version' => $this->version,
'merchant_id' => $this->merchant_id, //Mã merchant khai báo tại NganLuong.vn
'receiver_email' => $this->receiver_email,
'merchant_password' => MD5($this->merchant_password), //MD5(Máºt khẩu kết nối giữa merchant và NganLuong.vn)
'order_code' => $order_code, //Mã hóa đơn do website bán hà ng sinh ra
'total_amount' => $total_amount, //Tổng số tiá»n cá»§a hóa đơn
'payment_method' => 'VISA', //Phương thức thanh toán, nháºn má»™t trong các giá trị 'VISA','ATM_ONLINE', 'ATM_OFFLINE' hoặc 'NH_OFFLINE'
'bank_code' => $bank_code, //Phương thức thanh toán, nháºn má»™t trong các giá trị 'VISA','ATM_ONLINE', 'ATM_OFFLINE' hoặc 'NH_OFFLINE'
'payment_type' => $payment_type, //Kiểu giao dịch: 1 - Ngay; 2 - Tạm giữ; Nếu không truyá»n hoặc bằng rá»—ng thì lấy theo chÃnh sách cá»§a NganLuong.vn
'order_description' => $order_description, //Mô tả đơn hà ng
'tax_amount' => $tax_amount, //Tổng số tiá»n thuế
'fee_shipping' => $fee_shipping, //Phà váºn chuyển
'discount_amount' => $discount_amount, //Số tiá»n giảm giá
'return_url' => $return_url, //Äịa chỉ website nháºn thông báo giao dịch thà nh công
'cancel_url' => $cancel_url, //Äịa chỉ website nháºn "Há»§y giao dịch"
'buyer_fullname' => $buyer_fullname, //Tên ngưá»i mua hà ng
'buyer_email' => $buyer_email, //Äịa chỉ Email ngưá»i mua
'buyer_mobile' => $buyer_mobile, //Äiện thoại ngưá»i mua
'buyer_address' => $buyer_address, //Äịa chỉ ngưá»i mua hà ng
'total_item' => count($array_items)
);
$post_field = '';
foreach ($params as $key => $value){
if ($post_field != '') $post_field .= '&';
$post_field .= $key."=".$value;
}
if(count($array_items)>0){
foreach($array_items as $array_item){
foreach ($array_item as $key => $value){
if ($post_field != '') $post_field .= '&';
$post_field .= $key."=".$value;
}
}
}
//die($post_field);
$nl_result=$this->CheckoutCall($post_field);
return $nl_result;
}
function PrepaidVisaCheckout($order_code, $total_amount, $payment_type, $order_description, $tax_amount, $fee_shipping, $discount_amount, $return_url, $cancel_url, $buyer_fullname, $buyer_email, $buyer_mobile, $buyer_address, $array_items, $bank_code) {
$params = array(
'cur_code' => $this->cur_code,
'function' => Config::$_FUNCTION,
'version' => Config::$_VERSION,
'merchant_id' => $this->merchant_id, //Mã merchant khai báo tại NganLuong.vn
'receiver_email' => $this->receiver_email,
'merchant_password' => MD5($this->merchant_password), //MD5(Máºt khẩu kết nối giữa merchant và NganLuong.vn)
'order_code' => $order_code, //Mã hóa đơn do website bán hà ng sinh ra
'total_amount' => $total_amount, //Tổng số tiá»n cá»§a hóa đơn
'payment_method' => 'CREDIT_CARD_PREPAID', //Phương thức thanh toán, nháºn má»™t trong các giá trị 'VISA','ATM_ONLINE', 'ATM_OFFLINE' hoặc 'NH_OFFLINE'
'bank_code' => $bank_code, //Phương thức thanh toán, nháºn má»™t trong các giá trị 'VISA','ATM_ONLINE', 'ATM_OFFLINE' hoặc 'NH_OFFLINE'
'payment_type' => $payment_type, //Kiểu giao dịch: 1 - Ngay; 2 - Tạm giữ; Nếu không truyá»n hoặc bằng rá»—ng thì lấy theo chÃnh sách cá»§a NganLuong.vn
'order_description' => $order_description, //Mô tả đơn hà ng
'tax_amount' => $tax_amount, //Tổng số tiá»n thuế
'fee_shipping' => $fee_shipping, //Phà váºn chuyển
'discount_amount' => $discount_amount, //Số tiá»n giảm giá
'return_url' => $return_url, //Äịa chỉ website nháºn thông báo giao dịch thà nh công
'cancel_url' => $cancel_url, //Äịa chỉ website nháºn "Há»§y giao dịch"
'buyer_fullname' => $buyer_fullname, //Tên ngưá»i mua hà ng
'buyer_email' => $buyer_email, //Äịa chỉ Email ngưá»i mua
'buyer_mobile' => $buyer_mobile, //Äiện thoại ngưá»i mua
'buyer_address' => $buyer_address, //Äịa chỉ ngưá»i mua hà ng
'total_item' => count($array_items)
);
//var_dump($params); exit;
$post_field = '';
foreach ($params as $key => $value) {
if ($post_field != '')
$post_field .= '&';
$post_field .= $key . "=" . $value;
}
if (count($array_items) > 0) {
foreach ($array_items as $array_item) {
foreach ($array_item as $key => $value) {
if ($post_field != '')
$post_field .= '&';
$post_field .= $key . "=" . $value;
}
}
}
//die($post_field);
$nl_result = $this->CheckoutCall($post_field);
return $nl_result;
}
/*
Hà m lấy link thanh toán qua ngân hà ng
===============================
Tham số truyá»n và o bắt buá»™c phải có
order_code
total_amount
bank_code // Theo bảng mã ngân hà ng
buyer_fullname
buyer_email
buyer_mobile
===============================
$array_items mảng danh sách các item name theo quy tắc
item_name1
item_quantity1
item_amount1
item_url1
.....
payment_type Kiểu giao dịch: 1 - Ngay; 2 - Tạm giữ; Nếu không truyá»n hoặc bằng rá»—ng thì lấy theo chÃnh sách cá»§a NganLuong.vn
*/
public function BankCheckout($order_code,$total_amount,$bank_code,$payment_type,$order_description,$tax_amount,$fee_shipping,$discount_amount,$return_url,$cancel_url,$buyer_fullname,$buyer_email,$buyer_mobile, $buyer_address,$array_items)
{
$params = array(
'cur_code' => $this->cur_code,
'function' => 'SetExpressCheckout',
'version' => $this->version,
'merchant_id' => $this->merchant_id, //Mã merchant khai báo tại NganLuong.vn
'receiver_email' => $this->receiver_email,
'merchant_password' => MD5($this->merchant_password), //MD5(Máºt khẩu kết nối giữa merchant và NganLuong.vn)
'order_code' => $order_code, //Mã hóa đơn do website bán hà ng sinh ra
'total_amount' => $total_amount, //Tổng số tiá»n cá»§a hóa đơn
'payment_method' => 'ATM_ONLINE', //Phương thức thanh toán, nháºn má»™t trong các giá trị 'ATM_ONLINE', 'ATM_OFFLINE' hoặc 'NH_OFFLINE'
'bank_code' => $bank_code, //Mã Ngân hà ng
'payment_type' => $payment_type, //Kiểu giao dịch: 1 - Ngay; 2 - Tạm giữ; Nếu không truyá»n hoặc bằng rá»—ng thì lấy theo chÃnh sách cá»§a NganLuong.vn
'order_description' => $order_description, //Mô tả đơn hà ng
'tax_amount' => $tax_amount, //Tổng số tiá»n thuế
'fee_shipping' => $fee_shipping, //Phà váºn chuyển
'discount_amount' => $discount_amount, //Số tiá»n giảm giá
'return_url' => $return_url, //Äịa chỉ website nháºn thông báo giao dịch thà nh công
'cancel_url' => $cancel_url, //Äịa chỉ website nháºn "Há»§y giao dịch"
'buyer_fullname' => $buyer_fullname, //Tên ngưá»i mua hà ng
'buyer_email' => $buyer_email, //Äịa chỉ Email ngưá»i mua
'buyer_mobile' => $buyer_mobile, //Äiện thoại ngưá»i mua
'buyer_address' => $buyer_address, //Äịa chỉ ngưá»i mua hà ng
'total_item' => count($array_items)
);
$post_field = '';
foreach ($params as $key => $value){
if ($post_field != '') $post_field .= '&';
$post_field .= $key."=".$value;
}
if(count($array_items)>0){
foreach($array_items as $array_item){
foreach ($array_item as $key => $value){
if ($post_field != '') $post_field .= '&';
$post_field .= $key."=".$value;
}
}
}
//$post_field="function=SetExpressCheckout&version=3.1&merchant_id=24338&receiver_email=payment@hellochao.com&merchant_password=5b39df2b8f3275d1c8d1ea982b51b775&order_code=macode_oerder123&total_amount=2000&payment_method=ATM_ONLINE&bank_code=ICB&payment_type=&order_description=&tax_amount=0&fee_shipping=0&discount_amount=0&return_url=http://localhost/testcode/nganluong.vn/checkoutv3/payment_success.php&cancel_url=http://nganluong.vn&buyer_fullname=Test&buyer_email=saritvn@gmail.com&buyer_mobile=0909224002&buyer_address=&total_item=1&item_name1=Product name&item_quantity1=1&item_amount1=2000&item_url1=http://nganluong.vn/" ;
//echo $post_field;
// die;
$nl_result=$this->CheckoutCall($post_field);
return $nl_result;
}
public function BankOfflineCheckout($order_code,$total_amount,$bank_code,$payment_type,$order_description,$tax_amount,
$fee_shipping,$discount_amount,$return_url,$cancel_url,$buyer_fullname,$buyer_email,$buyer_mobile,
$buyer_address,$array_items)
{
$params = array(
'cur_code' => $this->cur_code,
'function' => 'SetExpressCheckout',
'version' => $this->version,
'merchant_id' => $this->merchant_id, //Mã merchant khai báo tại NganLuong.vn
'receiver_email' => $this->receiver_email,
'merchant_password' => MD5($this->merchant_password), //MD5(Máºt khẩu kết nối giữa merchant và NganLuong.vn)
'order_code' => $order_code, //Mã hóa đơn do website bán hà ng sinh ra
'total_amount' => $total_amount, //Tổng số tiá»n cá»§a hóa đơn
'payment_method' => 'ATM_OFFLINE', //Phương thức thanh toán, nháºn má»™t trong các giá trị 'ATM_ONLINE', 'ATM_OFFLINE' hoặc 'NH_OFFLINE'
'bank_code' => $bank_code, //Mã Ngân hà ng
'payment_type' => $payment_type, //Kiểu giao dịch: 1 - Ngay; 2 - Tạm giữ; Nếu không truyá»n hoặc bằng rá»—ng thì lấy theo chÃnh sách cá»§a NganLuong.vn
'order_description' => $order_description, //Mô tả đơn hà ng
'tax_amount' => $tax_amount, //Tổng số tiá»n thuế
'fee_shipping' => $fee_shipping, //Phà váºn chuyển
'discount_amount' => $discount_amount, //Số tiá»n giảm giá
'return_url' => $return_url, //Äịa chỉ website nháºn thông báo giao dịch thà nh công
'cancel_url' => $cancel_url, //Äịa chỉ website nháºn "Há»§y giao dịch"
'buyer_fullname' => $buyer_fullname, //Tên ngưá»i mua hà ng
'buyer_email' => $buyer_email, //Äịa chỉ Email ngưá»i mua
'buyer_mobile' => $buyer_mobile, //Äiện thoại ngưá»i mua
'buyer_address' => $buyer_address, //Äịa chỉ ngưá»i mua hà ng
'total_item' => count($array_items)
);
$post_field = '';
foreach ($params as $key => $value){
if ($post_field != '') $post_field .= '&';
$post_field .= $key."=".$value;
}
if(count($array_items)>0){
foreach($array_items as $array_item){
foreach ($array_item as $key => $value){
if ($post_field != '') $post_field .= '&';
$post_field .= $key."=".$value;
}
}
}
//$post_field="function=SetExpressCheckout&version=3.1&merchant_id=24338&receiver_email=payment@hellochao.com&merchant_password=5b39df2b8f3275d1c8d1ea982b51b775&order_code=macode_oerder123&total_amount=2000&payment_method=ATM_ONLINE&bank_code=ICB&payment_type=&order_description=&tax_amount=0&fee_shipping=0&discount_amount=0&return_url=http://localhost/testcode/nganluong.vn/checkoutv3/payment_success.php&cancel_url=http://nganluong.vn&buyer_fullname=Test&buyer_email=saritvn@gmail.com&buyer_mobile=0909224002&buyer_address=&total_item=1&item_name1=Product name&item_quantity1=1&item_amount1=2000&item_url1=http://nganluong.vn/" ;
//echo $post_field;
//die;
$nl_result=$this->CheckoutCall($post_field);
return $nl_result;
}
public function officeBankCheckout($order_code,$total_amount,$bank_code,$payment_type,$order_description,$tax_amount,
$fee_shipping,$discount_amount,$return_url,$cancel_url,$buyer_fullname,$buyer_email,$buyer_mobile,
$buyer_address,$array_items)
{
$params = array(
'cur_code' => $this->cur_code,
'function' => 'SetExpressCheckout',
'version' => $this->version,
'merchant_id' => $this->merchant_id, //Mã merchant khai báo tại NganLuong.vn
'receiver_email' => $this->receiver_email,
'merchant_password' => MD5($this->merchant_password), //MD5(Máºt khẩu kết nối giữa merchant và NganLuong.vn)
'order_code' => $order_code, //Mã hóa đơn do website bán hà ng sinh ra
'total_amount' => $total_amount, //Tổng số tiá»n cá»§a hóa đơn
'payment_method' => 'NH_OFFLINE', //Phương thức thanh toán, nháºn má»™t trong các giá trị 'ATM_ONLINE', 'ATM_OFFLINE' hoặc 'NH_OFFLINE'
'bank_code' => $bank_code, //Mã Ngân hà ng
'payment_type' => $payment_type, //Kiểu giao dịch: 1 - Ngay; 2 - Tạm giữ; Nếu không truyá»n hoặc bằng rá»—ng thì lấy theo chÃnh sách cá»§a NganLuong.vn
'order_description' => $order_description, //Mô tả đơn hà ng
'tax_amount' => $tax_amount, //Tổng số tiá»n thuế
'fee_shipping' => $fee_shipping, //Phà váºn chuyển
'discount_amount' => $discount_amount, //Số tiá»n giảm giá
'return_url' => $return_url, //Äịa chỉ website nháºn thông báo giao dịch thà nh công
'cancel_url' => $cancel_url, //Äịa chỉ website nháºn "Há»§y giao dịch"
'buyer_fullname' => $buyer_fullname, //Tên ngưá»i mua hà ng
'buyer_email' => $buyer_email, //Äịa chỉ Email ngưá»i mua
'buyer_mobile' => $buyer_mobile, //Äiện thoại ngưá»i mua
'buyer_address' => $buyer_address, //Äịa chỉ ngưá»i mua hà ng
'total_item' => count($array_items)
);
$post_field = '';
foreach ($params as $key => $value){
if ($post_field != '') $post_field .= '&';
$post_field .= $key."=".$value;
}
if(count($array_items)>0){
foreach($array_items as $array_item){
foreach ($array_item as $key => $value){
if ($post_field != '') $post_field .= '&';
$post_field .= $key."=".$value;
}
}
}
//$post_field="function=SetExpressCheckout&version=3.1&merchant_id=24338&receiver_email=payment@hellochao.com&merchant_password=5b39df2b8f3275d1c8d1ea982b51b775&order_code=macode_oerder123&total_amount=2000&payment_method=ATM_ONLINE&bank_code=ICB&payment_type=&order_description=&tax_amount=0&fee_shipping=0&discount_amount=0&return_url=http://localhost/testcode/nganluong.vn/checkoutv3/payment_success.php&cancel_url=http://nganluong.vn&buyer_fullname=Test&buyer_email=saritvn@gmail.com&buyer_mobile=0909224002&buyer_address=&total_item=1&item_name1=Product name&item_quantity1=1&item_amount1=2000&item_url1=http://nganluong.vn/" ;
//echo $post_field;
//die;
$nl_result=$this->CheckoutCall($post_field);
return $nl_result;
}
/*
Hà m lấy link thanh toán tại văn phòng ngân lượng
===============================
Tham số truyá»n và o bắt buá»™c phải có
order_code
total_amount
bank_code // HN hoặc HCM
buyer_fullname
buyer_email
buyer_mobile
===============================
$array_items mảng danh sách các item name theo quy tắc
item_name1
item_quantity1
item_amount1
item_url1
.....
payment_type Kiểu giao dịch: 1 - Ngay; 2 - Tạm giữ; Nếu không truyá»n hoặc bằng rá»—ng thì lấy theo chÃnh sách cá»§a NganLuong.vn
*/
function TTVPCheckout($order_code,$total_amount,$bank_code,$payment_type,$order_description,$tax_amount,
$fee_shipping,$discount_amount,$return_url,$cancel_url,$buyer_fullname,$buyer_email,$buyer_mobile,
$buyer_address,$array_items)
{
$params = array(
'cur_code' => $this->cur_code,
'function' => 'SetExpressCheckout',
'version' => $this->version,
'merchant_id' => $this->merchant_id, //Mã merchant khai báo tại NganLuong.vn
'receiver_email' => $this->receiver_email,
'merchant_password' => MD5($this->merchant_password), //MD5(Máºt khẩu kết nối giữa merchant và NganLuong.vn)
'order_code' => $order_code, //Mã hóa đơn do website bán hà ng sinh ra
'total_amount' => $total_amount, //Tổng số tiá»n cá»§a hóa đơn
'payment_method' => 'ATM_ONLINE', //Phương thức thanh toán, nháºn má»™t trong các giá trị 'ATM_ONLINE', 'ATM_OFFLINE' hoặc 'NH_OFFLINE'
'bank_code' => $bank_code, //Mã Ngân hà ng
'payment_type' => $payment_type, //Kiểu giao dịch: 1 - Ngay; 2 - Tạm giữ; Nếu không truyá»n hoặc bằng rá»—ng thì lấy theo chÃnh sách cá»§a NganLuong.vn
'order_description' => $order_description, //Mô tả đơn hà ng
'tax_amount' => $tax_amount, //Tổng số tiá»n thuế
'fee_shipping' => $fee_shipping, //Phà váºn chuyển
'discount_amount' => $discount_amount, //Số tiá»n giảm giá
'return_url' => $return_url, //Äịa chỉ website nháºn thông báo giao dịch thà nh công
'cancel_url' => $cancel_url, //Äịa chỉ website nháºn "Há»§y giao dịch"
'buyer_fullname' => $buyer_fullname, //Tên ngưá»i mua hà ng
'buyer_email' => $buyer_email, //Äịa chỉ Email ngưá»i mua
'buyer_mobile' => $buyer_mobile, //Äiện thoại ngưá»i mua
'buyer_address' => $buyer_address, //Äịa chỉ ngưá»i mua hà ng
'total_item' => count($array_items)
);
$post_field = '';
foreach ($params as $key => $value){
if ($post_field != '') $post_field .= '&';
$post_field .= $key."=".$value;
}
if(count($array_items)>0){
foreach($array_items as $array_item){
foreach ($array_item as $key => $value){
if ($post_field != '') $post_field .= '&';
$post_field .= $key."=".$value;
}
}
}
$nl_result=$this->CheckoutCall($post_field);
return $nl_result;
}
/*
Hà m lấy link thanh toán dùng số dư và ngân lượng
===============================
Tham số truyá»n và o bắt buá»™c phải có
order_code
total_amount
payment_method
buyer_fullname
buyer_email
buyer_mobile
===============================
$array_items mảng danh sách các item name theo quy tắc
item_name1
item_quantity1
item_amount1
item_url1
.....
payment_type Kiểu giao dịch: 1 - Ngay; 2 - Tạm giữ; Nếu không truyá»n hoặc bằng rá»—ng thì lấy theo chÃnh sách cá»§a NganLuong.vn
*/
public function NLCheckout($order_code,$total_amount,$payment_type,$order_description,$tax_amount,
$fee_shipping,$discount_amount,$return_url,$cancel_url,$buyer_fullname,$buyer_email,$buyer_mobile,
$buyer_address,$array_items)
{
$params = array(
'cur_code' => $this->cur_code,
'function' => 'SetExpressCheckout',
'version' => $this->version,
'merchant_id' => $this->merchant_id, //Mã merchant khai báo tại NganLuong.vn
'receiver_email' => $this->receiver_email,
'merchant_password' => MD5($this->merchant_password), //MD5(Máºt khẩu kết nối giữa merchant và NganLuong.vn)
'order_code' => $order_code, //Mã hóa đơn do website bán hà ng sinh ra
'total_amount' => $total_amount, //Tổng số tiá»n cá»§a hóa đơn
'payment_method' => 'NL', //Phương thức thanh toán
'payment_type' => $payment_type, //Kiểu giao dịch: 1 - Ngay; 2 - Tạm giữ; Nếu không truyá»n hoặc bằng rá»—ng thì lấy theo chÃnh sách cá»§a NganLuong.vn
'order_description' => $order_description, //Mô tả đơn hà ng
'tax_amount' => $tax_amount, //Tổng số tiá»n thuế
'fee_shipping' => $fee_shipping, //Phà váºn chuyển
'discount_amount' => $discount_amount, //Số tiá»n giảm giá
'return_url' => $return_url, //Äịa chỉ website nháºn thông báo giao dịch thà nh công
'cancel_url' => $cancel_url, //Äịa chỉ website nháºn "Há»§y giao dịch"
'buyer_fullname' => $buyer_fullname, //Tên ngưá»i mua hà ng
'buyer_email' => $buyer_email, //Äịa chỉ Email ngưá»i mua
'buyer_mobile' => $buyer_mobile, //Äiện thoại ngưá»i mua
'buyer_address' => $buyer_address, //Äịa chỉ ngưá»i mua hà ng
'total_item' => count($array_items) //Tổng số sản phẩm trong đơn hà ng
);
$post_field = '';
foreach ($params as $key => $value){
if ($post_field != '') $post_field .= '&';
$post_field .= $key."=".$value;
}
if(count($array_items)>0){
foreach($array_items as $array_item){
foreach ($array_item as $key => $value){
if ($post_field != '') $post_field .= '&';
$post_field .= $key."=".$value;
}
}
}
//die($post_field);
$nl_result=$this->CheckoutCall($post_field);
return $nl_result;
}
function IBCheckout($order_code, $total_amount, $bank_code, $payment_type, $order_description, $tax_amount, $fee_shipping, $discount_amount, $return_url, $cancel_url, $buyer_fullname, $buyer_email, $buyer_mobile, $buyer_address, $array_items) {
$params = array(
'cur_code' => $this->cur_code,
'function' => 'SetExpressCheckout',
'version' => $this->version,
'merchant_id' => $this->merchant_id, //Mã merchant khai báo tại NganLuong.vn
'receiver_email' => $this->receiver_email,
'merchant_password' => MD5($this->merchant_password), //MD5(Máºt khẩu kết nối giữa merchant và NganLuong.vn)
'order_code' => $order_code, //Mã hóa đơn do website bán hà ng sinh ra
'total_amount' => $total_amount, //Tổng số tiá»n cá»§a hóa đơn
'payment_method' => 'IB_ONLINE', //Phương thức thanh toán
'bank_code' => $bank_code,
'payment_type' => $payment_type, //Kiểu giao dịch: 1 - Ngay; 2 - Tạm giữ; Nếu không truyá»n hoặc bằng rá»—ng thì lấy theo chÃnh sách cá»§a NganLuong.vn
'order_description' => $order_description, //Mô tả đơn hà ng
'tax_amount' => $tax_amount, //Tổng số tiá»n thuế
'fee_shipping' => $fee_shipping, //Phà váºn chuyển
'discount_amount' => $discount_amount, //Số tiá»n giảm giá
'return_url' => $return_url, //Äịa chỉ website nháºn thông báo giao dịch thà nh công
'cancel_url' => $cancel_url, //Äịa chỉ website nháºn "Há»§y giao dịch"
'buyer_fullname' => $buyer_fullname, //Tên ngưá»i mua hà ng
'buyer_email' => $buyer_email, //Äịa chỉ Email ngưá»i mua
'buyer_mobile' => $buyer_mobile, //Äiện thoại ngưá»i mua
'buyer_address' => $buyer_address, //Äịa chỉ ngưá»i mua hà ng
'total_item' => count($array_items) //Tổng số sản phẩm trong đơn hà ng
);
$post_field = '';
foreach ($params as $key => $value) {
if ($post_field != '')
$post_field .= '&';
$post_field .= $key . "=" . $value;
}
if (count($array_items) > 0) {
foreach ($array_items as $array_item) {
foreach ($array_item as $key => $value) {
if ($post_field != '')
$post_field .= '&';
$post_field .= $key . "=" . $value;
}
}
}
//die($post_field);
$nl_result = $this->CheckoutCall($post_field);
return $nl_result;
}
function CheckoutCall($post_field){
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$this->url_api);
curl_setopt($ch, CURLOPT_ENCODING , 'UTF-8');
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_field);
$result = curl_exec($ch);
$status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
$error = curl_error($ch);
if ($result != '' && $status==200){
$xml_result = str_replace('&','&',(string)$result);
$nl_result = simplexml_load_string($xml_result);
$nl_result->error_message = $this->GetErrorMessage($nl_result->error_code);
}
else $nl_result->error_message = $error;
return $nl_result;
}
function GetErrorMessage($error_code) {
$arrCode = array(
'00' => 'Thà nh công',
'99' => 'Lỗi chưa xác minh',
'06' => 'Mã merchant không tồn tại hoặc bị khóa',
'02' => 'Äịa chỉ IP truy cáºp bị từ chối',
'03' => 'Mã checksum không chÃnh xác, truy cáºp bị từ chối',
'04' => 'Tên hà m API do merchant gá»i tá»›i không hợp lệ (không tồn tại)',
'05' => 'Sai version cá»§a API',
'07' => 'Sai máºt khẩu cá»§a merchant',
'08' => 'Äịa chỉ email tà i khoản nháºn tiá»n không tồn tại',
'09' => 'Tà i khoản nháºn tiá»n Ä‘ang bị phong tá»a giao dịch',
'10' => 'Mã đơn hà ng không hợp lệ',
'11' => 'Số tiá»n giao dịch lá»›n hÆ¡n hoặc nhá» hÆ¡n quy định',
'12' => 'Loại tiá»n tệ không hợp lệ',
'29' => 'Token không tồn tại',
'80' => 'Không thêm được đơn hà ng',
'81' => 'ÄÆ¡n hà ng chưa được thanh toán',
'110' => 'Äịa chỉ email tà i khoản nháºn tiá»n không phải email chÃnh',
'111' => 'Tà i khoản nháºn tiá»n Ä‘ang bị khóa',
'113' => 'Tà i khoản nháºn tiá»n chưa cấu hình là ngưá»i bán ná»™i dung số',
'114' => 'Giao dịch đang thực hiện, chưa kết thúc',
'115' => 'Giao dịch bị hủy',
'118' => 'tax_amount không hợp lệ',
'119' => 'discount_amount không hợp lệ',
'120' => 'fee_shipping không hợp lệ',
'121' => 'return_url không hợp lệ',
'122' => 'cancel_url không hợp lệ',
'123' => 'items không hợp lệ',
'124' => 'transaction_info không hợp lệ',
'125' => 'quantity không hợp lệ',
'126' => 'order_description không hợp lệ',
'127' => 'affiliate_code không hợp lệ',
'128' => 'time_limit không hợp lệ',
'129' => 'buyer_fullname không hợp lệ',
'130' => 'buyer_email không hợp lệ',
'131' => 'buyer_mobile không hợp lệ',
'132' => 'buyer_address không hợp lệ',
'133' => 'total_item không hợp lệ',
'134' => 'payment_method, bank_code không hợp lệ',
'135' => 'Lỗi kết nối tới hệ thống ngân hà ng',
'140' => 'ÄÆ¡n hà ng không há»— trợ thanh toán trả góp',);
return $arrCode[(string)$error_code];
}
}
?>