Subversion Repositories SmartDukaan

Rev

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