<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Cart extends CI_Controller {
public function __construct()
{
parent::__construct();
$this->load->library("common_lib");
$this->load->model('commonm');
}
public function index(){
$data = array();
$data['inner_template'] = "cart/cart";
$this->load->view('layout/layout_main.php',$data);
}
public function user_exist($str){
return $this->common_lib->check_user_exist($str);
}
public function email_exist($str){
return $this->common_lib->check_email_exist($str);
}
public function createprofile(){
if($this->common_lib->run_register_validation(true)){
$user_data = array();
$username = $this->common_lib->get_post('rg_username',true);
$password = $this->common_lib->get_post('rg_password',true);
$password = $this->common_lib->one_way_encrypt($password);
if($this->common_lib->get_n_post("rg_shipping_detail") == 1){
$personal_fields = $this->common_lib->user_form_personal_fields(true);
}else{
$personal_fields = $this->common_lib->user_form_personal_fields();
}
$user_data['is_active'] = 1;
$user_data['username'] = $username;
$user_data['password'] = $password;
$user_data = array_merge($user_data,$personal_fields);
$this->load->model('userm');
$user_id = $this->userm->_insert($user_data);
$sdata = array(
'sess_username' => $this->common_lib->encode($username),
'sess_uid' => $this->common_lib->encode($user_id),
'sess_display_name' => $this->common_lib->encode($personal_fields['first_name']),
'sess_lastlogin' => $data['lastlogin'],
'sess_signature' => $this->common_lib->encode($user_id.$username)
);
$this->common_lib->set_session($sdata);
$this->userm->_update($user_id, time());
redirect("cart/checkout");
}else{
$this->common_lib->set_session(array("danger-msg" => validation_errors()));
}
}
public function update_shipping(){
if($this->common_lib->run_shipping_validation()){
$user_data = array();
$user_data = $this->common_lib->user_form_shipping_fields();
$this->load->model('userm');
$this->userm->_up_profile($this->common_lib->get_login_id(),$user_data);
//$this->common_lib->set_session(array("success-msg" => "Shipping Detail updated successfully"));
redirect("cart/checkout");
}else{
$this->common_lib->set_session(array("danger-msg" => validation_errors()));
}
}
public function update_order(){
$payment_mode = $this->common_lib->get_post("checkout_payment_method");
$bValidateCardInfo = false;
if($payment_mode == "CC"){
$checkout_credit_card_type = $this->common_lib->get_n_post("checkout_credit_card_type");
$checkout_credit_card_number = $this->common_lib->get_n_post("checkout_credit_card_number");
$checkout_cvv_number = $this->common_lib->get_n_post("checkout_cvv_number");
$checkout_expiry_month = $this->common_lib->get_n_post("checkout_expiry_month");
$checkout_expiry_year = $this->common_lib->get_n_post("checkout_expiry_year");
$bValidateCardInfo = true;
}
if($bValidateCardInfo){
//echo "A";exit;
}
if($this->common_lib->run_payment_validation($bValidateCardInfo)){
if($this->common_lib->get_session("current_order_id") > 0){
$this->commonm->_delete_rows("order_items",array("order_id" => $this->common_lib->get_session("current_order_id")));
}
$user_login_detail = $this->common_lib->get_login_detail();
if($bValidateCardInfo){
$total_amount = $this->common_lib->insert_update_order();
$pazeey = false;
$authorized = false;
if($pazeey && false){
$this->load->library('payeezy');
$card_holder_name = $user_login_detail['first_name'];
$card_number = $checkout_credit_card_number;
$card_type = "Visa";
$card_cvv = $checkout_cvv_number;
$card_expiry = $checkout_expiry_month.substr($checkout_expiry_year,-2);
$amount = $total_amount;
$currency_code = "USD";
$merchant_ref = "Astonishing-Sale";
$primaryTxPayload = array(
"amount"=> $amount,
"card_number" => $card_number,
"card_type" => $card_type,
"card_holder_name" => $card_holder_name,
"card_cvv" => $card_cvv,
"card_expiry" => $card_expiry,
"merchant_ref" => $merchant_ref,
"currency_code" => $currency_code,
);
$credential['api_key'] = PZ_API_KEY;
$credential['token'] = PZ_TOKEN;
$credential['api_secret'] = PZ_API_SECRET;
$this->payeezy->initialize($credential,"sandbox");
$pz_res = $this->payeezy->processPayment($primaryTxPayload);
$pz_res_arr = json_decode($pz_res);
$bank_code = $pz_res_arr->bank_resp_code;
$response_code = 0;
if($bank_code=="100" || $bank_code=="101" || $bank_code=="102" || $bank_code=="103" || $bank_code=="104" || $bank_code=="105" || $bank_code=="106" || $bank_code=="107" || $bank_code=="108" || $bank_code=="109" || $bank_code=="110" || $bank_code=="111" || $bank_code=="164"){
$payment_status = "D";
$authorization_code = $pz_res_arr->bank_resp_code;
$response_description = $pz_res_arr->bank_message;
$transaction_id = $pz_res_arr->transaction_id;
$response_code = 1;
}else{
$payment_status = "P";
$response_description = $pz_res_arr->Error->messages[0]->description;
$response = 'Some error occured during transaction, Please try again! ('.$response_description.')';
$payment_status = "P";
}
}
if($authorized && false){
$this->load->library('authorize_net');
$param['card_num'] = $checkout_credit_card_number;
$param['exp_date'] = $checkout_expiry_month.'/'.$checkout_expiry_year;
$param['desc'] = '';
$param['amount'] = $total_amount;
$param['first_name'] = $user_login_detail['first_name'];
$param['last_name'] = $user_login_detail['last_name'];
$param['address'] = $user_login_detail['address'];
$param['city'] = $user_login_detail['city'];
$param['state'] = $user_login_detail['punjab'];
$param['country'] = $user_login_detail['country'];
$param['zipcode'] = $user_login_detail['zipcode'];
$param['ip'] = $this->input->server("REMOTE_ADDR");
$param['order_id'] = $this->common_lib->get_session("current_order_id");
$param['user_id'] = $user_login_detail['user_id'];
$param['birth_month'] = '';
$param['birth_day'] = '';
$param['birth_year'] = '';
$param['code'] = $checkout_cvv_number;
$result = $this->authorize_net->authorize($param);
$result_arr = explode("|", $result);
$response_code = $result_arr[0];// 1 = Approved, 2 = Declined, 3 = Error, 4 = Held for Review
$response_description = $result_arr[3];// Description
$transaction_id = $result_arr[6];// Transaction ID
$authorization_code = $result_arr[4];// Authorization Code
}else{
$this->load->library("paypal_lib");
$firstName = urlencode($user_login_detail['first_name']);
$creditCardType = urlencode($checkout_credit_card_type); //Visa
$creditCardNumber = base64_encode(urlencode($checkout_credit_card_number)); //4269344632025581
$expDateMonth = $checkout_expiry_month; //02
$padDateMonth = urlencode(str_pad($expDateMonth, 2, '0', STR_PAD_LEFT));
$expDateYear = urlencode($checkout_expiry_year); //2014
$cvv2Number = urlencode($checkout_credit_card_number); //962
$address1 = urlencode($user_login_detail['address']); //address1
$address2 = urlencode("address2"); //address2
$city = urlencode($user_login_detail['city']); //phagwara
$state = urlencode($user_login_detail['punjab']); //punjab
$country = urlencode($user_login_detail['country']); //US // US or other valid country code
$amount = urlencode($total_amount); //100
$currencyID = urlencode('USD'); // or other currency ('GBP', 'EUR', 'JPY', 'CAD', 'AUD')
$prod_price = "";
$nvpStr = "&PAYMENTACTION=$paymentType&AMT=$amount&CREDITCARDTYPE=$creditCardType&ACCT=$creditCardNumber".
"&EXPDATE=$padDateMonth$expDateYear&CVV2=$cvv2Number&FIRSTNAME=$firstName".
"&STREET=$address1&CITY=$city&STATE=$state&CURRENCYCODE=$currencyID";
$httpParsedResponseAr = $this->PPHttpPost('DoDirectPayment', $nvpStr);
}
/* if($response_code == 1 && $authorized){
$response = '';
$payment_status = "D";
$order_data = array();
$order_data['payment_status'] = $payment_status;
$order_data['payment_desc'] = $response_description." ".$authorization_code;
$order_data['transaction_id'] = $transaction_id;
$this->commonm->db_update($order_data,"orders","order_id",$this->common_lib->get_session("current_order_id"));
}*/
if($httpParsedResponseAr['ACK'] == "Success")
{
$response = '';
$payment_status = "D";
$order_data = array();
$order_data['payment_status'] = $payment_status;
// $order_data['payment_desc'] = $response_description." ".$authorization_code;
$order_data['transaction_id'] = $httpParsedResponseAr['TRANSACTIONID'];
$this->commonm->db_update($order_data,"orders","order_id",$this->common_lib->get_session("current_order_id"));
}else{
$response = 'Some error occured during transaction, Please try again 1!';
$payment_status = "P";
}
}
if($payment_status == "D" || $payment_mode == "COD" || $payment_mode == "PP"){
redirect("cart/orderconfirmed");
exit;
}else{
$this->common_lib->set_session(array("danger-msg" => $response));
}
}else{
$this->common_lib->set_session(array("danger-msg" => validation_errors()));
}
}
public function update_coupon(){
$coupon_code = $this->common_lib->get_post("checkout_coupon_code");
if($coupon_code != ""){
$coupon_detail = $this->commonm->get_all("coupons",array("is_active" => 1));
if(count($coupon_detail) == 0){
$this->common_lib->set_session(array("danger-msg" => "Please enter valid coupon code!"));
}else{
$coupon_detail = $coupon_detail[0];
$discount_amount = $coupon_detail->discount_value;
if($coupon_detail->discount_percent == 1){
$cart_total = $this->cart->total();
$discount_amount = $this->common_lib->currency_price( ($coupon_detail->discount_value/100) * $cart_total);
}
$this->common_lib->set_session(array("coupon_code" => $coupon_code));
$this->common_lib->set_session(array("success-msg" => "Coupon Applied Successfully"));
}
}else{
$this->common_lib->set_session(array("danger-msg" => "Please enter valid coupon code!"));
}
}
public function checkout(){
if($this->cart->total_items() == 0){
redirect("cart");
exit;
}
$this->common_lib->set_session(array("validation-1" => ""));
$this->common_lib->set_session(array("validation-2" => ""));
$this->common_lib->set_session(array("validation-3" => ""));
$this->common_lib->set_session(array("validation-4" => ""));
$this->common_lib->set_session(array("validation-5" => ""));
if($this->common_lib->get_session("panel-mode") == ""){
$this->common_lib->set_session(array("validation-1" => 1));
}else{
$this->common_lib->set_session(array($this->common_lib->get_session("panel-mode") => 1));
}
if($this->common_lib->get_post("checkout_mode") == "registration"){
$this->common_lib->set_session(array("validation-2" => 1));
$this->common_lib->set_session(array("panel-mode" => "validation-2"));
$this->createprofile();
}
if($this->common_lib->get_post("checkout_mode") == "profile_update"){
$this->common_lib->set_session(array("validation-2" => 1));
$this->common_lib->set_session(array("panel-mode" => "validation-2"));
if($this->common_lib->run_profile_validation()){
$user_data = array();
if($this->common_lib->get_n_post("rg_shipping_detail") == 1){
$user_data = $this->common_lib->user_form_personal_fields(true);
}else{
$user_data = $this->common_lib->user_form_personal_fields();
}
$this->load->model('userm');
$this->userm->_up_profile($this->common_lib->get_login_id(),$user_data);
}else{
$this->common_lib->set_session(array("danger-msg" => validation_errors()));
}
}
if($this->common_lib->get_post("checkout_mode") == "update_shipping"){
$this->common_lib->set_session(array("validation-3" => "1"));
$this->common_lib->set_session(array("panel-mode" => "validation-3"));
$this->update_shipping();
}
if($this->common_lib->get_post("checkout_mode") == "update_shipping_method"){
$ups_shipping_service = $this->common_lib->get_post("ups_shipping_service");
$ups_shipping_service = $this->common_lib->decode($ups_shipping_service);
$ups_shipping_service = explode("~~",$ups_shipping_service);
$this->common_lib->set_session(array("ups_shipping_price" => $ups_shipping_service[0]));
$this->common_lib->set_session(array("ups_shipping_service" => $ups_shipping_service[1]));
$this->common_lib->set_session(array("validation-4" => "1"));
$this->common_lib->set_session(array("panel-mode" => "validation-4"));
redirect("cart/checkout");
}
if($this->common_lib->get_post("checkout_mode") == "apply_coupon"){
$this->common_lib->set_session(array("validation-4" => "1"));
$this->common_lib->set_session(array("panel-mode" => "validation-4"));
$this->update_coupon();
}
if($this->common_lib->get_post("checkout_mode") == "payment_process"){
$this->common_lib->set_session(array("validation-4" => "1"));
$this->common_lib->set_session(array("panel-mode" => "validation-4"));
$this->update_order();
}
if($this->common_lib->get_post("checkout_mode") == "login"){
$login_status = $this->common_lib->do_login("cart/checkout");
if($login_status){
$this->common_lib->set_session(array("validation-1" => 1));
$this->common_lib->set_session(array("panel-mode" => "validation-1"));
}
}
$checkout_steps = array("login","");
$data = array();
$user_login_detail = $this->common_lib->get_login_detail();
$data['user_login_detail'] = $user_login_detail;
$data['country_list'] = $this->commonm->get_all("countries",array(),array(),"country");
$data['inner_template'] = "cart/checkout";
$this->load->view('layout/layout_main.php',$data);
}
public function orderconfirmed(){
$data = array();
$order_id = $this->common_lib->get_session("current_order_id");
if($order_id > 0){
$user_login_detail = $this->common_lib->get_login_detail();
$user_order_detail = $this->common_lib->get_order_summary($order_id);
$data['user_order_detail'] = $user_order_detail;
$order_detail_template = $this->common_lib->get_order_detail_template($order_id);
$this->common_lib->clear_cart_session();
$this->common_lib->send_order_email($order_id,$user_login_detail['email'],$order_detail_template);
$data['inner_template'] = "cart/orderconfirmed";
$this->load->view('layout/layout_main.php',$data);
}else{
redirect("cart");
exit;
}
}
function PPHttpPost($methodName_, $nvpStr_) {
$environment = "live";
$api_username = "kohlicards_api1.yahoo.com";
$api_password = "QBLV4QNB99BN376N";
$api_signature = "ANKBS4Huglqyo.--Mu7vmux6JcWbAnn80KdQOC41d9Tvd5hQEj7Sh6N9";
$API_UserName = urlencode($api_username);
$API_Password = urlencode($api_password);
$API_Signature = urlencode($api_signature);
$API_Endpoint = "https://api-3t.paypal.com/nvp";
if("sandbox" === $environment || "beta-sandbox" === $environment ){
$API_Endpoint = "https://api-3t.$environment.paypal.com/nvp";
}
$version = urlencode('51.0');
// Set the curl parameters.
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $API_Endpoint);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
// Turn off the server and peer verification (TrustManager Concept).
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);
// Set the API operation, version, and API signature in the request.
$nvpreq = "METHOD=$methodName_&VERSION=$version&PWD=$API_Password&USER=$API_UserName&SIGNATURE=$API_Signature$nvpStr_";
// Set the request as a POST FIELD for curl.
curl_setopt($ch, CURLOPT_POSTFIELDS, $nvpreq);
// Get response from the server.
$httpResponse = curl_exec($ch);
if(!$httpResponse) {
exit("$methodName_ failed: ".curl_error($ch).'('.curl_errno($ch).')');
}
// Extract the response details.
$httpResponseAr = explode("&", $httpResponse);
$httpParsedResponseAr = array();
foreach ($httpResponseAr as $i => $value) {
$tmpAr = explode("=", $value);
if(sizeof($tmpAr) > 1) {
$httpParsedResponseAr[$tmpAr[0]] = $tmpAr[1];
}
}
if((0 == sizeof($httpParsedResponseAr)) || !array_key_exists('ACK', $httpParsedResponseAr)) {
exit("Invalid HTTP Response for POST request($nvpreq) to $API_Endpoint.");
}
return $httpParsedResponseAr;
}
}
/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */
@KyuuKazami