Commit 256bcd4f by Tobin

dc

parent 2bb57c97
...@@ -371,7 +371,9 @@ class Api extends CI_Controller { ...@@ -371,7 +371,9 @@ class Api extends CI_Controller {
redirect($redUrl.'failure'); redirect($redUrl.'failure');
} }
$payData = array('auth_token'=>$auth_token,'amount'=>$amount,'booking_id'=>$booking_id); $callback_url = (isset($reqData['callback_url']))?$reqData['callback_url']:'';
$payData = array('auth_token'=>$auth_token,'amount'=>$amount,
'booking_id'=>$booking_id,'callback_url'=>$callback_url);
$res = $this->Api_model->payNow($payData); $res = $this->Api_model->payNow($payData);
if($res['status']==1){ if($res['status']==1){
...@@ -533,12 +535,16 @@ class Api extends CI_Controller { ...@@ -533,12 +535,16 @@ class Api extends CI_Controller {
} }
if(!empty($transaction_id) && !empty($last_id)){ if(!empty($transaction_id) && !empty($last_id)){
$this->Api_model->update_payment($response,$transaction_id,$last_id,'1',$eventid); $resp = $this->Api_model->update_payment($response,$transaction_id,$last_id,'1',$eventid);
$customData = $this->txnManager($eventid,array('tnx_id'=>$booking_id,'status'=>'1')); $customData = $this->txnManager($eventid,array('tnx_id'=>$booking_id,'status'=>'1'));
} }
if(!empty($booking_id)){ if(!empty($booking_id)){
redirect($redUrl.'bookingdetails?booking_id='.$booking_id); $callback_url = $redUrl.'bookingdetails?booking_id=';
if(isset($resp['callback_url']) && !empty($resp['callback_url'])){
$callback_url = $redUrl.$resp['callback_url'];
}
redirect($callback_url.$booking_id);
} }
} }
redirect($redUrl.'failure'); redirect($redUrl.'failure');
...@@ -581,7 +587,7 @@ class Api extends CI_Controller { ...@@ -581,7 +587,7 @@ class Api extends CI_Controller {
$last_id = $data[1]; $last_id = $data[1];
$eventid = $data[2]; $eventid = $data[2];
$booking_id = $data[3]; $booking_id = $data[3];
$this->Api_model->update_payment($response,'',$last_id,'0',$eventid); $resp = $this->Api_model->update_payment($response,'',$last_id,'0',$eventid);
$customData = $this->txnManager($eventid,array('tnx_id'=>$booking_id,'status'=>'2')); $customData = $this->txnManager($eventid,array('tnx_id'=>$booking_id,'status'=>'2'));
$sql = "SELECT BOK.event_id FROM transaction AS TX $sql = "SELECT BOK.event_id FROM transaction AS TX
...@@ -589,7 +595,11 @@ class Api extends CI_Controller { ...@@ -589,7 +595,11 @@ class Api extends CI_Controller {
WHERE TX.id='$last_id'"; WHERE TX.id='$last_id'";
$trxData = $this->db->query($sql)->row_array(); $trxData = $this->db->query($sql)->row_array();
if(!empty($trxData) && isset($trxData['event_id']) && !empty($trxData['event_id'])){ if(!empty($trxData) && isset($trxData['event_id']) && !empty($trxData['event_id'])){
redirect($redUrl.'failure?event_id='.$trxData['event_id']); $callback_url = $redUrl.'failure?event_id=';
if(isset($resp['callback_url']) && !empty($resp['callback_url'])){
$callback_url = $redUrl.$resp['callback_url'];
}
redirect($callback_url.$trxData['event_id']);
} }
} }
} }
...@@ -601,8 +611,7 @@ class Api extends CI_Controller { ...@@ -601,8 +611,7 @@ class Api extends CI_Controller {
$res = $this->Api_model->reset_password($data); $res = $this->Api_model->reset_password($data);
if($res['status']!=0){ if($res['status']!=0){
$this->response($res['data']); $this->response($res['data']);
} }else{
else{
$this->errorResponse($res['code'],$res['message']); $this->errorResponse($res['code'],$res['message']);
} }
} }
...@@ -617,8 +626,7 @@ class Api extends CI_Controller { ...@@ -617,8 +626,7 @@ class Api extends CI_Controller {
$res = $this->Api_model->checkSeatAvailability($data); $res = $this->Api_model->checkSeatAvailability($data);
if($res['status']!=0){ if($res['status']!=0){
$this->response($res['data']); $this->response($res['data']);
} }else{
else{
$this->errorResponse($res['code'],$res['message']); $this->errorResponse($res['code'],$res['message']);
} }
} }
...@@ -627,8 +635,7 @@ class Api extends CI_Controller { ...@@ -627,8 +635,7 @@ class Api extends CI_Controller {
$res = $this->Api_model->getCountry(); $res = $this->Api_model->getCountry();
if($res['status']!=0){ if($res['status']!=0){
$this->response($res['data']); $this->response($res['data']);
} }else{
else{
$this->errorResponse($res['code'],$res['message']); $this->errorResponse($res['code'],$res['message']);
} }
} }
...@@ -643,44 +650,48 @@ class Api extends CI_Controller { ...@@ -643,44 +650,48 @@ class Api extends CI_Controller {
} }
public function getSavedCards(){ public function getSavedCards(){
$data = (array) json_decode(file_get_contents('php://input')); try{
$cust_id = $this->Api_model->auth_token_get($this->auth_token); $data = (array) json_decode(file_get_contents('php://input'));
if(empty($cust_id) || empty($data) || !isset($data['email']) || empty($email = $data['email'])){ $cust_id = $this->Api_model->auth_token_get($this->auth_token);
$this->errorResponse('891','Invalid User'); if(empty($cust_id) || empty($data) || !isset($data['email']) || empty($email = $data['email'])){
} $this->errorResponse('891','Invalid User');
}
$settings = getSettings();
$merchant_iv = $settings['merchant_iv']; $settings = getSettings();
$merchant_id = $settings['merchant_id']; $merchant_iv = $settings['merchant_iv'];
$merchant_key = $settings['merchant_key']; $merchant_id = $settings['merchant_id'];
$merchant_key = $settings['merchant_key'];
$ses_id = time().rand(100000,999999);
$reqData = '{"sessionId":"'.$ses_id.'","merchantId":"'.$merchant_id.'","custId":"'.$cust_id. $ses_id = time().rand(100000,999999);
'","emailId":"'.$email.'"}'; $reqData = '{"sessionId":"'.$ses_id.'","merchantId":"'.$merchant_id.'","custId":"'.$cust_id.
$plainText = $this->encryptePayData($merchant_iv,$merchant_key,$reqData); '","emailId":"'.$email.'"}';
$plainText = $merchant_id.'|'.$plainText; $plainText = $this->encryptePayData($merchant_iv,$merchant_key,$reqData);
$env = (strpos($settings['payment_gateway_url'],'staging') !==false )?'staging':'payments'; $plainText = $merchant_id.'|'.$plainText;
$env = (strpos($settings['payment_gateway_url'],'staging') !==false )?'staging':'payments';
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL,"https://$env.bayanpay.sa/direcpay/secure/PaymentsMerchStoredCardDtlsAPI"); $ch = curl_init();
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1); curl_setopt($ch,CURLOPT_URL,"https://$env.bayanpay.sa/direcpay/secure/PaymentsMerchStoredCardDtlsAPI");
curl_setopt($ch,CURLOPT_POST,1); curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch,CURLOPT_POSTFIELDS,$plainText); curl_setopt($ch,CURLOPT_POST,1);
curl_setopt($ch,CURLOPT_HTTPHEADER,array('Content-Type: text/plain')); curl_setopt($ch,CURLOPT_POSTFIELDS,$plainText);
$result = curl_exec($ch); curl_setopt($ch,CURLOPT_HTTPHEADER,array('Content-Type: text/plain'));
$result = curl_exec($ch);
if(empty($result)){
$this->errorResponse('892','Something went wrong, Please try again'); if(empty($result)){
} $this->errorResponse('892','Something went wrong, Please try again');
$resp = $this->decryptePayData($merchant_iv,$merchant_key,$result); }
if(empty($resp) || !isset($resp->txnCardDetails) || $resp = $this->decryptePayData($merchant_iv,$merchant_key,$result);
empty($resp->txnCardDetails) || count($resp->txnCardDetails) <= 0){ if(empty($resp) || !isset($resp->txnCardDetails) ||
$this->errorResponse('893','No Data Found'); empty($resp->txnCardDetails) || count($resp->txnCardDetails) <= 0){
} $this->errorResponse('893','No Data Found');
}
$cardData = json_encode(json_decode(json_encode($resp->txnCardDetails),true));
$resp = $this->encrypt($cardData,$this->local_key,$this->local_iv); $cardData = json_encode(json_decode(json_encode($resp->txnCardDetails),true));
$this->response(array('saved_cards'=>$resp)); $resp = $this->encrypt($cardData,$this->local_key,$this->local_iv);
$this->response(array('saved_cards'=>$resp));
} catch(Exception $e) {
$this->errorResponse('894','Something went wrong, Please try again');
}
} }
function encryptePayData($merchant_iv='',$merchant_key='',$plainText='') { function encryptePayData($merchant_iv='',$merchant_key='',$plainText='') {
...@@ -761,5 +772,27 @@ class Api extends CI_Controller { ...@@ -761,5 +772,27 @@ class Api extends CI_Controller {
redirect($redUrl.'failure'); redirect($redUrl.'failure');
} }
} }
function hotelBooking(){
try{
$data = (array) json_decode(file_get_contents('php://input'));
$cust_id = $this->Api_model->auth_token_get($this->auth_token);
if(empty($cust_id)){
$this->errorResponse('891','Invalid User');
}
if(empty($data) || !isset($data['request_data']) || empty($request_data = $data['request_data'])){
$this->errorResponse('892','Request Data Missing');
}
pre($request_data);
$reqData = $this->encrypt(json_encode($request_data),$this->local_key,$this->local_iv);
$reqData = urlencode(base64_encode($reqData));
$res['data']['reqData'] = $reqData;
$this->response($res['data']);
} catch(Exception $e) {
$this->errorResponse('894','Something went wrong, Please try again');
}
}
} }
?> ?>
...@@ -1341,7 +1341,11 @@ class Api_model extends CI_Model { ...@@ -1341,7 +1341,11 @@ class Api_model extends CI_Model {
try{ try{
$user_id = $this->auth_token_get($data['auth_token']); $user_id = $this->auth_token_get($data['auth_token']);
if($user_id > 0) { if($user_id > 0) {
$this->db->insert('transaction',array('customer_id'=>$user_id,'booking_id'=>$data['booking_id'],'datetime'=>date('Y-m-d h:i:s'),'amount'=>$data['amount'])); $callback_url = (isset($data['callback_url']))?$data['callback_url']:'';
$insertData = array('customer_id'=>$user_id,'booking_id'=>$data['booking_id'],
'datetime'=>date('Y-m-d h:i:s'),'amount'=>$data['amount'],
'callback_url'=>$callback_url);
$this->db->insert('transaction',$insertData);
$last_id = $this->db->insert_id(); $last_id = $this->db->insert_id();
$custData = $this->getUserData($user_id); $custData = $this->getUserData($user_id);
...@@ -1404,8 +1408,10 @@ class Api_model extends CI_Model { ...@@ -1404,8 +1408,10 @@ class Api_model extends CI_Model {
$this->db->update('transaction',array('transaction_id'=>$transactionid,'status'=>$status, $this->db->update('transaction',array('transaction_id'=>$transactionid,'status'=>$status,
'transaction_response'=>json_encode($response)), 'transaction_response'=>json_encode($response)),
array('id'=>$last_id)); array('id'=>$last_id));
if(!empty($eventid)){ $callback_url = '';
$transResp = $this->db->get_where('transaction',array('id'=>$last_id))->row_array();
if(!empty($transResp)){
$callback_url = $transResp['callback_url'];
} }
if($status == 1){ if($status == 1){
$trBook = $this->db->get_where('transaction',array('id'=>$last_id))->row_array(); $trBook = $this->db->get_where('transaction',array('id'=>$last_id))->row_array();
...@@ -1460,9 +1466,9 @@ class Api_model extends CI_Model { ...@@ -1460,9 +1466,9 @@ class Api_model extends CI_Model {
$this->db->update('event_invites',array('status'=>'1'),array('book_id'=>$book_id)); $this->db->update('event_invites',array('status'=>'1'),array('book_id'=>$book_id));
$this->db->update('promocode_used',array('status'=>'1'),array('booking_id'=>$book_id)); $this->db->update('promocode_used',array('status'=>'1'),array('booking_id'=>$book_id));
} }
$res = array('status'=>1); $res = array('status'=>1,'callback_url'=>$callback_url);
}catch(Exception $e){ }catch(Exception $e){
$res = array('status'=>0,'message'=>'Ohh No!! Something went South!!','code'=>'ER06'); $res = array('status'=>0,'callback_url'=>$callback_url);
} }
return $res; return $res;
} }
......
...@@ -333,6 +333,20 @@ class Validation_model extends CI_Model { ...@@ -333,6 +333,20 @@ class Validation_model extends CI_Model {
) )
) , ) ,
'payNow' => array(), 'payNow' => array(),
'hotelBooking' => array(
'auth_token' => array(
'required' => array(
'code' => 'ER16',
'message' => 'User Id is null or empty'
)
) ,
'request_data' => array(
'required' => array(
'code' => 'ER18',
'message' => 'Booking Data is null or empty'
) ,
)
),
'searchEvent' => array(), 'searchEvent' => array(),
'validate_promo_code' => array( 'validate_promo_code' => array(
'promo_code' => array( 'promo_code' => array(
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment