Subversion Repositories SmartDukaan

Rev

Rev 18662 | Rev 18718 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
17793 naman 1
<?php
2
App::uses('AppController', 'Controller');
3
/**
4
 * Exceptionalnlcs Controller
5
 *
6
 * @property Exceptionalnlc $Exceptionalnlc
7
 * @property PaginatorComponent $Paginator
8
 */
9
class ShippingsController extends AppController {
10
 
11
/**
12
 * Components
13
 *
14
 * @var array
15
 */
16
	public $components = array('Paginator');
17
 
18
	public function beforeFilter() {
19
		parent::beforeFilter();
20
		$this->apihost = Configure::read('pythonapihost');
21
		$this->mobileapihost = Configure::read('saholicapihost');
17838 manish.sha 22
		$this->Auth->allow('isServicable');
17793 naman 23
	}
24
 
25
 
26
	public function index(){
27
		$userId = $this->Auth->User('id');
17838 manish.sha 28
		$dataGiven = json_decode($this->request->data['cart_details']);
17793 naman 29
		if ($this->request->is('post')) {
30
			$data = $this->request->data;
31
		}
17871 manish.sha 32
 
17838 manish.sha 33
		$suserId = base64_decode($_COOKIE['s_id']);
17871 manish.sha 34
		$scartId = base64_decode($_COOKIE['s_cart']);
35
		$semailId = base64_decode($_COOKIE['s_email']);
36
 
37
		$pincode = 0;
38
 
39
		if($pincode==0 && isset($_COOKIE['s_pincode'])){
40
			$pincode = base64_decode($_COOKIE['s_pincode']);
17793 naman 41
		}
17838 manish.sha 42
 
17871 manish.sha 43
		$cartItems = array();
44
 
45
		foreach ($dataGiven->cartItems as $key=>$obj) {
46
		    $itemobj = array(
47
					'itemId'   => $key,
48
		    		'quantity' => $obj->quantity);
49
			array_push($cartItems, $itemobj);
17838 manish.sha 50
		}
17871 manish.sha 51
		$postData = array(
52
					'cartItems'	=>	$cartItems
53
					);
54
 
55
		$params = array(
56
				'cartMap' => urlencode(json_encode($postData)));
17838 manish.sha 57
 
17871 manish.sha 58
		$this->layout = 'cartinnerpages';
59
		$url = Configure::read('saholicapihost').'cart!validateCart?isLoggedIn=true&privateDealUser=true&userId='.$suserId.'&id='.$scartId.'&email='.$semailId;
60
		if($pincode!='0'){
61
			$url = $url.'&pinCode='.$pincode;
62
		}
63
		$cartskus = $this->post_cartinfo_request($url,$params);
64
		if(isset($cartskus['response']) && $cartskus['response']=='error'){
65
			$this->set(compact('cartskus'));
66
			$this->render('/Users/cartdetails');
67
 
68
		}elseif(isset($cartskus['cartMessages']) && count($cartskus['cartMessages'])>0){
69
			setcookie('s_pincode', base64_encode($cartskus['pincode']), -1, '/');
70
			$this->set(compact('cartskus'));
71
			$this->render('/Users/cartdetails');
72
		}else{
73
			$totalPayable = intval($dataGiven->totalCartValue) + intval($dataGiven->shippingCharges);
74
			$this->Session->write('totalPayable', $totalPayable);
75
			$this->layout = 'innerpages';
17882 naman 76
			$url = Configure::read ( 'saholicapihost' ) . 'address?isLoggedIn=true&privateDealUser=true&userId=' . $suserId;
77
			$response = $this->make_request ( $url, null );
78
			$user_name = "";
79
			$user_contact = "";
17871 manish.sha 80
 
17947 manish.sha 81
			$codAvailable = $cartskus['cod'];
82
			$this->Session->write('cod', $codAvailable);
18699 manish.sha 83
			$creditTicketSize = 0;
17947 manish.sha 84
 
18633 manish.sha 85
			$creditorAssociated = $response ['creditorAssociated'];
86
			if(empty($response ['userSanctions'])){
87
				$creditLimit = 0;
88
			}else{
89
				$creditLimit = 0;
18699 manish.sha 90
				$creditTicketSize = intval($response ['userSanctions'][0]['ticket_size']);
18633 manish.sha 91
				foreach ( $response ['userSanctions'] as $key => $value ) {
18699 manish.sha 92
					$creditLimit = $creditLimit + intval($value ['credit_limit']) - (intval($value['credit_blocked'])+intval($value['loan']));
18633 manish.sha 93
				}
94
			}
95
			$this->Session->write('creditorAssociated', $creditorAssociated);
96
			$this->Session->write('creditLimit', $creditLimit);
18699 manish.sha 97
			$this->Session->write('creditTicketSize', $creditTicketSize);
18633 manish.sha 98
			$addressEditable = $response ['addressEditable'];
99
			$this->Session->write('addressEditable', $addressEditable);
100
 
17882 naman 101
			if(empty($response ['addresses'])){
102
				$this->redirect ( array (
103
						'action' => 'add' 
104
				));
17793 naman 105
			}
17871 manish.sha 106
 
17882 naman 107
			$firstshowaddress = array ();
108
			$findedaddress = array ();
109
			$moreshowaddress = array ();
110
			$current_address_id = - 1;
111
			$defaultpin = - 1;
112
			$defaultcookiepin = - 1;
113
			$defaultcheckedaddress = - 1;
114
			$defaultpinaddress = - 1;
18633 manish.sha 115
 
17882 naman 116
			foreach ( $response ['addresses'] as $key => $value ) {
117
 
118
				if ($value ['id'] == intval ( $response ['defaultAddress'] ) && intval ( $value ['pin'] ) == $pincode) {
119
					$defaultcookiepin = $key;
120
					$user_name = $value ['name'];
121
					$user_contact = $value ['phone'];
122
					if ($defaultcheckedaddress == - 1) {
123
						$defaultcheckedaddress = $value ['id'];
124
					}
125
				} else if (intval ( $value ['pin'] ) == $pincode) {
126
					$current_address_id = $key;
127
					array_push ( $findedaddress, $key );
128
					if ($defaultpinaddress == - 1) {
129
						$defaultpinaddress = $value ['id'];
130
					}
131
				} else if ($value ['id'] == intval ( $response ['defaultAddress'] )) {
132
					$defaultpin = $key;
133
					$user_name = $value ['name'];
134
					$user_contact = $value ['phone'];
135
				} else {
136
					array_push ( $moreshowaddress, $key );
17871 manish.sha 137
				}
138
			}
17882 naman 139
 
140
			$defaultselectedaddress = - 1;
141
			if ($defaultpinaddress != - 1) {
142
				$defaultselectedaddress = $defaultpinaddress;
17793 naman 143
			}
17882 naman 144
			if ($defaultcheckedaddress != - 1) {
145
				$defaultselectedaddress = $defaultcheckedaddress;
17871 manish.sha 146
			}
17882 naman 147
 
148
			if ($defaultcookiepin != - 1) {
149
				array_push ( $firstshowaddress, $defaultcookiepin );
17871 manish.sha 150
			}
17882 naman 151
 
152
			for($i = 0; $i < count ( $findedaddress ); $i ++) {
153
				array_push ( $firstshowaddress, $findedaddress [$i] );
17871 manish.sha 154
			}
155
 
17882 naman 156
			if ($defaultpin != - 1) {
157
				array_push ( $firstshowaddress, $defaultpin );
158
			}
159
 
160
			for($i = 0; $i < count ( $moreshowaddress ); $i ++) {
161
				array_push ( $firstshowaddress, $moreshowaddress [$i] );
162
			}
163
 
164
			$this->set ( 'address', $response );
165
 
18699 manish.sha 166
			$this->set ( compact ( 'firstshowaddress', 'totalPayable', 'user_name', 'user_contact', 'pincode', 'defaultselectedaddress', 'message', 'codAvailable', 'addressEditable', 'creditorAssociated', 'creditLimit', 'creditTicketSize') );
17793 naman 167
		}
17882 naman 168
	}
169
	public function add($user_name = null, $user_contact = null) {
170
		$this->layout = 'cartinnerpages';
17793 naman 171
 
17882 naman 172
		$totalPayable = $_SESSION ['totalPayable'];
17947 manish.sha 173
		$codAvailable = $_SESSION ['cod'];
18633 manish.sha 174
		$creditLimit = $_SESSION ['creditLimit'];
175
		$creditorAssociated = $_SESSION ['creditorAssociated'];
18699 manish.sha 176
		$creditTicketSize = $_SESSION ['creditTicketSize'];
18039 amit.gupta 177
		//$pinval = base64_decode ( $_COOKIE ['s_pincode'] );
178
		$pinval='';
17882 naman 179
		$suserId = base64_decode ( $_COOKIE ['s_id'] );
180
		$scart = base64_decode ( $_COOKIE ['s_cart'] );
181
 
182
		if ($this->request->is ( 'post' )) {
17793 naman 183
			$data = $this->request->data;
17882 naman 184
 
185
			$senddata ['name'] = $data ['name'];
186
			$senddata ['line1'] = $data ['line1'];
187
			$senddata ['line2'] = "";
188
			$senddata ['city'] = $data ['city'];
189
			$senddata ['state'] = $data ['state'];
190
			$senddata ['pin'] = $data ['pin'];
191
			$senddata ['phone'] = $data ['phone'];
192
			$senddata ['country'] = 'India';
193
			$url = Configure::read ( 'saholicapihost' ) . "address?userId=" . $suserId . "&isLoggedIn=true&cartId=" . $scart . "&isPrivateDealUser=true";
194
 
195
			$response = $this->post_request ( $url, $senddata );
196
 
197
			$scartId = base64_decode ( $_COOKIE ['s_cart'] );
198
			$semailId = base64_decode ( $_COOKIE ['s_email'] );
199
			$blank = array ();
200
			$postData = array (
201
					'cartItems' => $blank 
202
			);
203
 
204
			$params = array (
205
					'cartMap' => urlencode ( json_encode ( $postData ) ) 
206
			);
207
			$url = Configure::read ( 'saholicapihost' ) . 'cart!validateCart?isLoggedIn=true&privateDealUser=true&userId=' . $suserId . '&id=' . $scartId . '&email=' . $semailId;
208
			// if($pin!='0'){
209
			$url = $url . '&pinCode=' . $data ['pin'];
210
			// }
211
			$cartskus = $this->post_cartinfo_request ( $url, $params );
212
			$checkestimate = 'true';
213
			if ($cartskus ['maxEstimate'] == - 1) {
214
				$checkestimate = 'false';
215
			} else {
216
				for($i = 0; $i < count ( $cartskus ['cartItems'] ); $i ++) {
17904 amit.gupta 217
					if(array_key_exists('estimate',$cartskus ['cartItems'] [$i])){
218
						continue;
219
					}
220
					$estimate = $cartskus ['cartItems'] [$i] ['estimate'];
221
					if ($estimate==-1) {
17882 naman 222
						$checkestimate = 'false';
223
						break;
224
					}
225
				}
17793 naman 226
			}
227
 
17882 naman 228
			if ($checkestimate == 'false') {
229
				// debug("I am here");
230
				$this->Session->setFlash ( "Address is not serviceable", 'default', array (
231
						'class' => 'alert alert-danger custom_class' 
232
				) );
233
				// $this->Session->setFlash('Address is not serviceable');
234
				return $this->redirect ( array (
235
						'action' => 'index' 
236
				) );
237
			} else {
238
				$this->Session->setFlash ( "Address is  serviceable" );
17793 naman 239
			}
240
		}
241
 
17882 naman 242
		$url = $this->apihost . "pincodeValidation/" . $pinval;
243
		$getstate = $this->make_request ( $url, null );
17844 naman 244
		// debug($getstate);
17793 naman 245
		$getstateval = "";
17882 naman 246
		if ($getstate != "{}") {
247
			$getstateval = ucwords ( strtolower ( $getstate ['state'] ) );
17793 naman 248
		}
18699 manish.sha 249
		$this->set(compact('getstateval', 'user_name', 'user_contact', 'pinval', 'totalPayable', 'codAvailable', 'creditorAssociated', 'creditLimit', 'creditTicketSize'));
17793 naman 250
	}
17882 naman 251
	public function submitcheck() {
252
		$this->autoRender = false;
253
		$this->request->onlyAllow ( 'ajax' );
254
 
17899 amit.gupta 255
		$suserId = base64_decode($_COOKIE['s_id']);
256
		$scartId = base64_decode($_COOKIE['s_cart']);
257
		$semailId = base64_decode($_COOKIE['s_email']);
258
 
17882 naman 259
		$data = $this->request->data;
260
 
261
		$senddata ['name'] = $data ['name'];
262
		$senddata ['line1'] = $data ['line1'];
263
		$senddata ['line2'] = "";
264
		$senddata ['city'] = $data ['city'];
265
		$senddata ['state'] = $data ['state'];
266
		$senddata ['pin'] = $data ['pin'];
267
		$senddata ['phone'] = $data ['phone'];
268
		$senddata ['country'] = 'India';
17899 amit.gupta 269
		$url = Configure::read ( 'saholicapihost' ) . "address?userId=" . $suserId . "&isLoggedIn=true&cartId=" . $scartId . "&isPrivateDealUser=true";
17882 naman 270
 
17899 amit.gupta 271
		$response = $this->post_cartinfo_request($url,$senddata);
17882 naman 272
		$suserId = base64_decode ( $_COOKIE ['s_id'] );
273
 
274
		$scartId = base64_decode ( $_COOKIE ['s_cart'] );
275
		$semailId = base64_decode ( $_COOKIE ['s_email'] );
276
		$blank = array ();
277
		$postData = array (
278
				'cartItems' => $blank 
279
		);
280
 
281
		$params = array (
282
				'cartMap' => urlencode ( json_encode ( $postData ) ) 
283
		);
284
		$url = Configure::read ( 'saholicapihost' ) . 'cart!validateCart?isLoggedIn=true&privateDealUser=true&userId=' . $suserId . '&id=' . $scartId . '&email=' . $semailId;
285
		// if($pin!='0'){
286
		$url = $url . '&pinCode=' . $data ['pin'];
287
		// }
288
		$cartskus = $this->post_cartinfo_request ( $url, $params );
17893 amit.gupta 289
		$checkestimate = $response ['defaultAddress'];
17882 naman 290
		if ($cartskus ['maxEstimate'] == - 1) {
17893 amit.gupta 291
			$checkestimate = '';
17882 naman 292
		} else {
293
			for($i = 0; $i < count ( $cartskus ['cartItems'] ); $i ++) {
17904 amit.gupta 294
				if(array_key_exists('estimate',$cartskus ['cartItems'] [$i])){
295
					continue;
296
				}
297
				$estimate = $cartskus ['cartItems'] [$i] ['estimate'];
298
				if ($estimate==-1) {
17893 amit.gupta 299
					$checkestimate = '';
17882 naman 300
					break;
301
				}
302
			}
303
		}
304
 
305
		return $checkestimate;
306
	}
307
	public function getstate($pin_val) {
308
		$this->autoRender = false;
309
		$this->request->onlyAllow ( 'ajax' );
310
		$url = $this->apihost . "pincodeValidation/" . $pin_val;
311
		$getstate = $this->make_request ( $url, null );
312
		// $getstate['state'] = ucwords(strtolower($getstate['state']));
17844 naman 313
		$nothing = "nothing";
17882 naman 314
		if ($getstate != "{}") {
315
			$getstate ['state'] = ucwords ( strtolower ( $getstate ['state'] ) );
17844 naman 316
		}
17882 naman 317
		return json_encode ( $getstate );
318
	}
319
	public function isServicable($pin) {
320
		$this->autoRender = false;
321
		$this->request->onlyAllow ( 'ajax' );
17793 naman 322
		// $url = "http://shop2020.in:8080/mobileapi/address!serviceable?pincode=".$pin;
323
		// $response = $this->make_request($url,null);
17882 naman 324
 
325
		$scartId = base64_decode ( $_COOKIE ['s_cart'] );
326
		$suserId = base64_decode ( $_COOKIE ['s_id'] );
327
		$semailId = base64_decode ( $_COOKIE ['s_email'] );
328
		$blank = array ();
329
		$postData = array (
330
				'cartItems' => $blank 
331
		);
332
 
333
		$params = array (
334
				'cartMap' => urlencode ( json_encode ( $postData ) ) 
335
		);
336
		$url = Configure::read ( 'saholicapihost' ) . 'cart!validateCart?isLoggedIn=true&privateDealUser=true&userId=' . $suserId . '&id=' . $scartId . '&email=' . $semailId;
337
		$url = $url . '&pinCode=' . $pin;
338
		$cartskus = $this->post_cartinfo_request ( $url, $params );
339
		$checkestimate = 'true';
340
		if ($cartskus ['maxEstimate'] == - 1) {
341
			$checkestimate = 'false';
342
		} else {
343
			for($i = 0; $i < count ( $cartskus ['cartItems'] ); $i ++) {
17904 amit.gupta 344
				if(array_key_exists('estimate',$cartskus ['cartItems'] [$i])){
345
					continue;
346
				}
347
				$estimate = $cartskus ['cartItems'] [$i] ['estimate'];
348
				if ($estimate==-1) {
17882 naman 349
					$checkestimate = 'false';
350
					break;
351
				}
352
			}
353
		}
354
 
355
		return $checkestimate;
356
	}
357
 
17871 manish.sha 358
	 public function checkout(){
18662 manish.sha 359
	 	$addressid = $this->request->data['addressid'];
17846 manish.sha 360
	 	$pincode = 0;
17871 manish.sha 361
		$cod = $this->request->query('cod');
17846 manish.sha 362
		$userId = $this->request->query('user_id');
363
 
18619 amit.gupta 364
		//Added token validation to ensure only user 
365
	 	$tokenValidated = !Configure::read ( 'requireusercheck' ) || $this->checkToken($userId);
366
		if(!empty($userId) && $tokenValidated==1){			
367
			$url = $this->getAutoLoginUrl($userId,$url);
368
 
369
			if(isset($this->request->data->pincode)){
370
				$pincode = $this->request->data->pincode;
17871 manish.sha 371
			}
18619 amit.gupta 372
			if($pincode==0 && isset($_COOKIE['s_pincode'])){
373
				$pincode = base64_decode($_COOKIE['s_pincode']);
374
			}
375
 
376
			$suserId = base64_decode($_COOKIE['s_id']);
377
			$scartId = base64_decode($_COOKIE['s_cart']);
378
			$semailId = base64_decode($_COOKIE['s_email']);
379
 
380
			if(isset($_COOKIE['txn_comp'])) {
381
				unset($_COOKIE['txn_comp']);
382
			}
383
 
384
			if($cod==1){
385
				$url = Configure::read('saholicapihost').'order?payment_option=3000&isLoggedIn=true&privateDealUser=true&userId='.$suserId.'&id='.$scartId.'&email='.$semailId.'&addressid='.$addressid;
386
			 	if($pincode!='0'){
387
					$url = $url.'&pinCode='.$pincode;
388
				}
389
				$orderCreationResponse = $this->post_cartinfo_request($url, null);
390
				//{"response":{"success":true,"redirectUrl":"pay-success?paymentId=998593"}}
391
				$redirecturl = $orderCreationResponse['response']['redirectUrl'];
392
				if (strpos($redirecturl,'pay-success') === false) {
393
				    setcookie('txn_comp', 'no', -1, '/');
394
				} else {
395
					$order_det = array();
396
					$this->loadModel('Order');
397
					$order_det['user_id'] = $this->Auth->User('id');
398
					$order_det['store_id'] = 4;
399
					$str = Configure::read('saholicauthurl');
18633 manish.sha 400
					$orderDetailsArgs = explode('/autologin/',$str);
401
					$order_det['order_url'] = $orderDetailsArgs[0]."/".$redirecturl;
18619 amit.gupta 402
					$this->log(print_r($order_det,1),'ordersdet');
403
					$this->Order->create();
18613 naman 404
 
18619 amit.gupta 405
					if ($this->Order->save($order_det)) {
406
						$id = $this->Order->getLastInsertID();
407
						$order = $this->Order->find('first',array('conditions'=>array('id'=>$id),'recursive'=>-1));
408
						$apihost = Configure::read('pythonapihost');
409
						$url = $apihost."storeorder";
410
 
411
						$this->log(print_r($url,1),'ordersdet');
412
 
413
						$this->log(print_r($order,1),'ordersdet');
414
						$response = array();
415
	// 					$params = array('sourceId'=>$order['Order']['store_id'],'orderId'=>$order['Order']['id'],'subTagId'=>$order['Order']['sub_tag'],'userId'=>$order['Order']['user_id'],'rawHtml'=>$order['Order']['rawhtml'],'orderSuccessUrl'=>$order['Order']['order_url']);
416
						if(!empty($order)) {
417
							$params = array('sourceId'=>$order['Order']['store_id'],'orderId'=>$order['Order']['id'],'subTagId'=>$order['Order']['sub_tag'],'userId'=>$order['Order']['user_id'],'rawHtml'=>$order['Order']['rawhtml'],'orderSuccessUrl'=>$order['Order']['order_url']);
418
							$jsonVar = json_encode($params);
419
							$response =  $this->make_request($url,$jsonVar);
420
						}else{
421
							$result = array('success'=>false,'message'=>'Empty order array');
422
							$response = $result;
423
						}
424
						$this->log(print_r('response',1),'ordersdet');
425
						$this->log(print_r($response,1),'ordersdet');
426
						if(!empty($response) && $response['result']) {
427
							if($response['htmlRequired'] == 1) {
428
								$this->loadModel('Rawhtml');
429
								$data = array('order_id' => $order['Order']['id'],'url' => $response['url'], 'status' => 'new');
430
								$this->Rawhtml->create();
431
								$this->Rawhtml->save($data);
432
								$this->log(print_r('insideif',1),'ordersdet');
433
								$result =  $response;
434
								$sql = "UPDATE orders SET status = '".$response['result']."' WHERE id = ".$order['Order']['id'];
435
							}
436
							else {
437
								$result =array('success'=>true,'message'=> $response['result']);
438
								$sql = "UPDATE orders SET status = '".$response['result']."' WHERE id = ".$order['Order']['id'];
439
								$this->log(print_r('insideelse',1),'ordersdet');
440
							}
441
							$this->log(print_r($sql,1),'ordersdet');
442
							$this->Order->query($sql);
443
 
444
						}					
18613 naman 445
					}
446
				}
18619 amit.gupta 447
				$this->layout = 'innerpages';
448
				$next = $redirecturl;					
449
				$redirectUrl = $this->getAutoLoginUrl($userId,$next);
450
				$this->log($redirectUrl,'headers');
451
				$this->set(compact('redirectUrl','next'));
452
			}else{
453
				$dataGiven = json_decode($this->request->data['cart_details']);
18662 manish.sha 454
				$payMethod = $this->request->data['paymethod'];
18633 manish.sha 455
				if(isset($payMethod) && $payMethod=='cap_float'){
456
					$url = Configure::read('saholicapihost').'order?payment_option=456789&isLoggedIn=true&privateDealUser=true&userId='.$suserId.'&id='.$scartId.'&email='.$semailId.'&addressid='.$addressid;
457
				 	if($pincode!='0'){
458
						$url = $url.'&pinCode='.$pincode;
459
					}
460
					$orderCreationResponse = $this->post_cartinfo_request($url, null);
461
					//{"response":{"success":true,"redirectUrl":"pay-success?paymentId=998593"}}
462
					$redirecturl = $orderCreationResponse['response']['redirectUrl'];
463
					if (strpos($redirecturl,'pay-success') === false) {
464
					    setcookie('txn_comp', 'no', -1, '/');
465
					} else {
466
						$order_det = array();
467
						$this->loadModel('Order');
468
						$order_det['user_id'] = $this->Auth->User('id');
469
						$order_det['store_id'] = 4;
470
						$str = Configure::read('saholicauthurl');
471
						$orderDetailsArgs = explode('/autologin/',$str);
472
						$order_det['order_url'] = $orderDetailsArgs[0]."/".$redirecturl;
473
						$this->log(print_r($order_det,1),'ordersdet');
474
						$this->Order->create();
475
 
476
						if ($this->Order->save($order_det)) {
477
							$id = $this->Order->getLastInsertID();
478
							$order = $this->Order->find('first',array('conditions'=>array('id'=>$id),'recursive'=>-1));
479
							$apihost = Configure::read('pythonapihost');
480
							$url = $apihost."storeorder";
481
 
482
							$this->log(print_r($url,1),'ordersdet');
483
 
484
							$this->log(print_r($order,1),'ordersdet');
485
							$response = array();
486
							if(!empty($order)) {
487
								$params = array('sourceId'=>$order['Order']['store_id'],'orderId'=>$order['Order']['id'],'subTagId'=>$order['Order']['sub_tag'],'userId'=>$order['Order']['user_id'],'rawHtml'=>$order['Order']['rawhtml'],'orderSuccessUrl'=>$order['Order']['order_url']);
488
								$jsonVar = json_encode($params);
489
								$response =  $this->make_request($url,$jsonVar);
490
							}else{
491
								$result = array('success'=>false,'message'=>'Empty order array');
492
								$response = $result;
493
							}
494
							$this->log(print_r('response',1),'ordersdet');
495
							$this->log(print_r($response,1),'ordersdet');
496
							if(!empty($response) && $response['result']) {
497
								if($response['htmlRequired'] == 1) {
498
									$this->loadModel('Rawhtml');
499
									$data = array('order_id' => $order['Order']['id'],'url' => $response['url'], 'status' => 'new');
500
									$this->Rawhtml->create();
501
									$this->Rawhtml->save($data);
502
									$this->log(print_r('insideif',1),'ordersdet');
503
									$result =  $response;
504
									$sql = "UPDATE orders SET status = '".$response['result']."' WHERE id = ".$order['Order']['id'];
505
								}
506
								else {
507
									$result =array('success'=>true,'message'=> $response['result']);
508
									$sql = "UPDATE orders SET status = '".$response['result']."' WHERE id = ".$order['Order']['id'];
509
									$this->log(print_r('insideelse',1),'ordersdet');
510
								}
511
								$this->log(print_r($sql,1),'ordersdet');
512
								$this->Order->query($sql);
513
 
514
							}					
515
						}
516
					}
517
					$this->layout = 'innerpages';
518
					$next = $redirecturl;					
519
					$redirectUrl = $this->getAutoLoginUrl($userId,$next);
520
					$this->log($redirectUrl,'headers');
521
					$this->set(compact('redirectUrl','next'));
522
				}else{
523
					$totalSkus= intval($dataGiven->totalSkus);
524
					setcookie('txn_comp', 'no', -1, '/');
525
					$this->layout = 'innerpages';
526
					$next = "payment?cq=".$totalSkus.'&addressid='.$addressid;					
527
					$redirectUrl = $this->getAutoLoginUrl($userId,$next);
528
					$this->log($redirectUrl,'headers');
529
					$this->set(compact('redirectUrl','next'));
530
				}
17871 manish.sha 531
			}
18619 amit.gupta 532
		} else {
533
			if($tokenValidated == 0){
534
				$url = '/special/native/login';
535
			}elseif($tokenValidated == -1){
536
				$url = '/abouts/askforupdate';
537
			}
538
			$this->redirect($url);
17871 manish.sha 539
		}
540
	 }
17793 naman 541
}