public function updatestatusAction() { $id = $this->params()->fromPost('id_oder'); $status = $this->params()->fromPost('status'); $data = array('status_oder' => $status); $obj = new Oder(); $obj->exchangeArray($data); $this->getOrderAdtTable()->update_status($id, $obj); echo 'Change status successful bill'; die; }
public function checkoutpaypalAction() { $this->layout('layout/lazadacheckout'); $container = new Container('shopcart_lazada'); $arraycart = $container->cart_lazada; $name = addslashes(trim($this->params()->fromPost('name'))); $mail = addslashes(trim($this->params()->fromPost('email'))); $phone = addslashes(trim($this->params()->fromPost('phone'))); $address = addslashes(trim($this->params()->fromPost('address'))); $checkout = addslashes(trim($this->params()->fromPost('checkout'))); $id_us = addslashes(trim($this->params()->fromPost('idus'))); //$total_price = addslashes(trim($this->params()->fromPost('totalprice'))); //$time = addslashes(trim($this->params()->fromPost('time'))); $paypalmode = PayPalMode == 'sandbox' ? '.sandbox' : ''; $PayPalCurrencyCode = 'USD'; //Paypal Currency Code $PayPalReturnURL = WEBPATH . '/shoppingcart/lazada/checkoutpaypal'; //Point to process.php page $PayPalCancelURL = WEBPATH . '/shoppingcart/lazada/cancel'; //Cancel URL if user clicks cancel foreach ($arraycart as $key => $value) { $arrayproduct[] = $key; } $listproduct_cat = $this->getProductAdtTable()->product_viewcart($arrayproduct); foreach ($listproduct_cat as $key1 => $value1) { $qty = $arraycart[$value1['id']]; if ($value1['sale_products'] == 1) { $price = $value1['price'] - $value1['price'] * $value1['promotions'] / 100; } else { $price = $value1['price']; } $total_price += $qty * $price; } $customer = array('id_user' => $id_us, 'customer' => $name, 'email' => $mail, 'address' => $address, 'phone' => $phone, 'time' => '', 'totalprice' => $total_price, 'type' => $checkout); $post = $this->getRequest(); if ($post->isPost()) { $TotalTaxAmount = 2.58; //Sum of tax for all items in this order. $HandalingCost = 2.0; //Handling cost for this order. $InsuranceCost = 1.0; //shipping insurance cost for this order. $ShippinDiscount = -3.0; //Shipping discount for this order. Specify this as negative number. $ShippinCost = 3.0; $paypal_data = ''; $ItemTotalPrice = 0; foreach ($listproduct_cat as $key => $itmname) { $Qty = $arraycart[$itmname['id']]; if ($itmname['sale_products'] == 1) { $price_s = $itmname['price'] - $itmname['price'] * $itmname['promotions'] / 100; } else { $price_s = $itmname['price']; } $paypal_data .= '&L_PAYMENTREQUEST_0_NAME' . $key . '=' . urlencode($itmname['name']); $paypal_data .= '&L_PAYMENTREQUEST_0_NUMBER' . $key . '=' . urlencode($itmname['id']); $paypal_data .= '&L_PAYMENTREQUEST_0_AMT' . $key . '=' . urlencode($price_s); $paypal_data .= '&L_PAYMENTREQUEST_0_QTY' . $key . '=' . urlencode($Qty); // item price X quantity $subtotal = $Qty * $price_s; //total price $ItemTotalPrice = $ItemTotalPrice + $subtotal; //create items for session $paypal_product['items'][] = array('name' => $itmname['name'], 'Qty' => $Qty, 'price' => $price_s, 'id' => $itmname['id']); } //Grand total including all tax, insurance, shipping cost and discount $GrandTotal = $ItemTotalPrice + $TotalTaxAmount + $HandalingCost + $InsuranceCost + $ShippinCost + $ShippinDiscount; $paypal_product['assets'] = array('tax_total' => $TotalTaxAmount, 'handaling_cost' => $HandalingCost, 'insurance_cost' => $InsuranceCost, 'shippin_discount' => $ShippinDiscount, 'shippin_cost' => $ShippinCost, 'grand_total' => $GrandTotal); $session_paypal_products = new Container('paypal_products'); $session_paypal_products->paypal_products = $paypal_product; $session_customer = new Container('customer'); $session_customer->customer = $customer; //Parameters for SetExpressCheckout, which will be sent to PayPal $padata = '&METHOD=SetExpressCheckout' . '&RETURNURL=' . urlencode($PayPalReturnURL) . '&CANCELURL=' . urlencode($PayPalCancelURL) . '&PAYMENTREQUEST_0_PAYMENTACTION=' . urlencode("SALE") . $paypal_data . '&NOSHIPPING=0' . '&PAYMENTREQUEST_0_ITEMAMT=' . urlencode($ItemTotalPrice) . '&PAYMENTREQUEST_0_TAXAMT=' . urlencode($TotalTaxAmount) . '&PAYMENTREQUEST_0_SHIPPINGAMT=' . urlencode($ShippinCost) . '&PAYMENTREQUEST_0_HANDLINGAMT=' . urlencode($HandalingCost) . '&PAYMENTREQUEST_0_SHIPDISCAMT=' . urlencode($ShippinDiscount) . '&PAYMENTREQUEST_0_INSURANCEAMT=' . urlencode($InsuranceCost) . '&PAYMENTREQUEST_0_AMT=' . urlencode($GrandTotal) . '&PAYMENTREQUEST_0_CURRENCYCODE=' . urlencode($PayPalCurrencyCode) . '&LOCALECODE=GB' . '&LOGOIMG=http://s11.bestmediainvestgroup.eu/public/advhtml/image/logo.png' . '&CARTBORDERCOLOR=FFFFFF' . '&ALLOWNOTE=1'; /* echo "padata :<pre>"; print_r($padata); echo "</pre>"; die; */ //We need to execute the "SetExpressCheckOut" method to obtain paypal token $paypal = new MyPayPal(); $httpParsedResponseAr = $paypal->PPHttpPost('SetExpressCheckout', $padata, PayPalApiUsername, PayPalApiPassword, PayPalApiSignature, PayPalMode); //Respond according to message we receive from Paypal if ("SUCCESS" == strtoupper($httpParsedResponseAr["ACK"]) || "SUCCESSWITHWARNING" == strtoupper($httpParsedResponseAr["ACK"])) { //Redirect user to PayPal store with Token received. $paypalurl = 'https://www' . $paypalmode . '.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token=' . $httpParsedResponseAr["TOKEN"] . ''; $this->redirect()->toUrl($paypalurl); //header('Location: '.$paypalurl); } else { //Show error message echo '<div style="color:red"><b>Error : </b>' . urldecode($httpParsedResponseAr["L_LONGMESSAGE0"]) . '</div>'; echo '<pre>'; print_r($httpParsedResponseAr); echo '</pre>'; } } //Paypal redirects back to this page using ReturnURL, We should receive TOKEN and Payer ID if (isset($_GET["token"]) && isset($_GET["PayerID"])) { $token = $_GET["token"]; $payer_id = $_GET["PayerID"]; $session_customer_new = new Container('customer'); $paypal_productrts = $session_customer_new->customer; $session_paypal_products = new Container('paypal_products'); $paypal_productrt = $session_paypal_products->paypal_products; $paypal_datan = ''; $ItemTotalPrice2 = 0; if (!empty($paypal_productrt)) { $j = 0; foreach ($paypal_productrt['items'] as $key => $p_item) { if ($p_item['sale_products'] == 1) { $price_s1 = $p_item['price'] - $p_item['price'] * $p_item['promotions'] / 100; } else { $price_s1 = $p_item['price']; } $Qty = $arraycart[$p_item['id']]; $paypal_datan .= '&L_PAYMENTREQUEST_0_NAME' . $j . '=' . urlencode($p_item['name']); $paypal_datan .= '&L_PAYMENTREQUEST_0_NUMBER' . $j . '=' . urlencode($p_item['id']); $paypal_datan .= '&L_PAYMENTREQUEST_0_AMT' . $j . '=' . urlencode($price_s1); $paypal_datan .= '&L_PAYMENTREQUEST_0_QTY' . $j . '=' . urlencode($Qty); // item price X quantity $subtotal2 = $Qty * $price_s1; //total price $ItemTotalPrice2 = $ItemTotalPrice2 + $subtotal2; $j++; } } $padatan = '&TOKEN=' . urlencode($token) . '&PAYERID=' . urlencode($payer_id) . '&PAYMENTREQUEST_0_PAYMENTACTION=' . urlencode("SALE") . $paypal_datan . '&PAYMENTREQUEST_0_ITEMAMT=' . urlencode($ItemTotalPrice2) . '&PAYMENTREQUEST_0_TAXAMT=' . urlencode($paypal_productrt['assets']['tax_total']) . '&PAYMENTREQUEST_0_SHIPPINGAMT=' . urlencode($paypal_productrt['assets']['shippin_cost']) . '&PAYMENTREQUEST_0_HANDLINGAMT=' . urlencode($paypal_productrt['assets']['handaling_cost']) . '&PAYMENTREQUEST_0_SHIPDISCAMT=' . urlencode($paypal_productrt['assets']['shippin_discount']) . '&PAYMENTREQUEST_0_INSURANCEAMT=' . urlencode($paypal_productrt['assets']['insurance_cost']) . '&PAYMENTREQUEST_0_AMT=' . urlencode($paypal_productrt['assets']['grand_total']) . '&PAYMENTREQUEST_0_CURRENCYCODE=' . urlencode($PayPalCurrencyCode); //$oder_id_n = $paypal_productrt['assets']['oder']; //We need to execute the "DoExpressCheckoutPayment" at this point to Receive payment from user. $paypal = new MyPayPal(); $httpParsedResponseAr = $paypal->PPHttpPost('DoExpressCheckoutPayment', $padatan, PayPalApiUsername, PayPalApiPassword, PayPalApiSignature, PayPalMode); //Check if everything went ok.. if ("SUCCESS" == strtoupper($httpParsedResponseAr["ACK"]) || "SUCCESSWITHWARNING" == strtoupper($httpParsedResponseAr["ACK"])) { //echo '<h2>Success</h2>'; //echo 'Your Transaction ID : ' . urldecode($httpParsedResponseAr["PAYMENTINFO_0_TRANSACTIONID"]); //Lưu lại ID paypal để lưu vào db $_SESSION['id_paypal'] = urldecode($httpParsedResponseAr["PAYMENTINFO_0_TRANSACTIONID"]); /* //Sometimes Payment are kept pending even when transaction is complete. //hence we need to notify user about it and ask him manually approve the transiction */ if ('Completed' == $httpParsedResponseAr["PAYMENTINFO_0_PAYMENTSTATUS"]) { //echo '<div style="color:green">Payment Received! Your product will be sent to you very soon!</div>'; } elseif ('Pending' == $httpParsedResponseAr["PAYMENTINFO_0_PAYMENTSTATUS"]) { echo '<div style="color:red">Transaction Complete, but payment is still pending! ' . 'You need to manually authorize this payment in your <a target="_new" href="http://www.paypal.com">Paypal Account</a></div>'; } $padata = '&TOKEN=' . urlencode($token); $paypal = new MyPayPal(); $httpParsedResponseAr = $paypal->PPHttpPost('GetExpressCheckoutDetails', $padata, PayPalApiUsername, PayPalApiPassword, PayPalApiSignature, PayPalMode); if ("SUCCESS" == strtoupper($httpParsedResponseAr["ACK"]) || "SUCCESSWITHWARNING" == strtoupper($httpParsedResponseAr["ACK"])) { $buyerName = urldecode($httpParsedResponseAr["FIRSTNAME"]) . ' ' . urldecode($httpParsedResponseAr["LASTNAME"]); $buyerEmail = urldecode($httpParsedResponseAr["EMAIL"]); //echo '<pr>'; // echo $buyerName . '<br/>'; //echo $buyerEmail . '<br/>'; $session_customer_new = new Container('customer'); $customer_add = $session_customer_new->customer; //print_r($customer_add);die; // Lưu thông tin hóa đơn vào database $dataoder = array('customer' => $customer_add['customer'], 'email' => $customer_add['email'], 'address' => $customer_add['address'], 'phone' => $customer_add['phone'], 'time' => $customer_add['time'], 'totalprice' => $customer_add['totalprice'], 'type' => $customer_add['type']); $obj = new Oder(); $obj->exchangeArray($dataoder); $this->getOrderAdtTable()->addoder($obj); //Add oder detail $get_odernew = $this->getOrderAdtTable()->getoder_new(); $id_odernew = $get_odernew['id']; foreach ($arraycart as $key => $value) { $arrayproduct[] = $key; } $listproduct_cat = $this->getProductAdtTable()->product_viewcart($arrayproduct); foreach ($listproduct_cat as $key1 => $value1) { $qty = $arraycart[$value1['id']]; $id_product = $value1['id']; if ($value1['sale_products'] == 1) { $price_product = $value1['price'] - $value1['price'] * $value1['promotions'] / 100; } else { $price_product = $value1['price']; } $datadetail = array('oder_id' => $id_odernew, 'quantity' => $qty, 'id_product' => $id_product, 'price_product' => $price_product); $objdetail = new Oderdetail(); $objdetail->exchangeArray($datadetail); $this->getOrderdetailAdtTable()->addoder_detail($objdetail); } $container = new Container('shopcart_lazada'); $arraycart = $container->cart_lazada; unset($arraycart); $container->cart_lazada = $arraycart; //print_r($session_customer->name); //echo '<pre>'; // print_r($httpParsedResponseAr); //echo '</pre>'; } else { echo '<div style="color:red"><b>GetTransactionDetails failed:</b>' . urldecode($httpParsedResponseAr["L_LONGMESSAGE0"]) . '</div>'; echo '<pre>'; print_r($httpParsedResponseAr); echo '</pre>'; } } else { echo '<div style="color:red"><b>Error : </b>' . urldecode($httpParsedResponseAr["L_LONGMESSAGE0"]) . '</div>'; echo '<pre>'; print_r($httpParsedResponseAr); echo '</pre>'; } } return array('listproduct' => $listproduct_cat); //}// End Post Data }