Commit f00c9ece by Tobin

dc

parent 9752e130
...@@ -20,7 +20,7 @@ if ($_SERVER['REQUEST_METHOD'] == 'OPTIONS') { ...@@ -20,7 +20,7 @@ if ($_SERVER['REQUEST_METHOD'] == 'OPTIONS') {
class Api extends CI_Controller { class Api extends CI_Controller {
var $auth_token; var $auth_token;
private $cipher = "AES-256-CBC";
public function __construct() { public function __construct() {
parent::__construct(); parent::__construct();
date_default_timezone_set("Asia/Riyadh"); date_default_timezone_set("Asia/Riyadh");
...@@ -319,7 +319,7 @@ class Api extends CI_Controller { ...@@ -319,7 +319,7 @@ class Api extends CI_Controller {
} }
} }
public function payNow($auth_token='',$amount=0,$booking_id='',$event_id=''){ public function payNow($auth_token='',$amount=0,$booking_id='',$event_id='',$cardData=''){
$settings = getSettings(); $settings = getSettings();
$redUrl = $settings['web_base_url']; $redUrl = $settings['web_base_url'];
...@@ -330,32 +330,42 @@ class Api extends CI_Controller { ...@@ -330,32 +330,42 @@ class Api extends CI_Controller {
$res = $this->Api_model->payNow($payData); $res = $this->Api_model->payNow($payData);
if($res['status']==1){ if($res['status']==1){
$this->paymentGateway($amount,$res['transaction_id'],$event_id,$booking_id,$res['custData']); $this->paymentGateway($amount,$res['transaction_id'],$event_id,$booking_id,$res['custData'],$cardData);
} }
else{ else{
redirect($redUrl.'failure?event_id='.$eventid); redirect($redUrl.'failure?event_id='.$eventid);
} }
} }
public function paymentGateway($amount='0',$last_id='0',$event_id='0',$booking_id='0',$custData=array()){ public function paymentGateway($amount='0',$last_id='0',$event_id='0',$booking_id='0',
$custData=array(),$cardData=''){
$customerName = array();
if(isset($custData->name) && !empty($custData->name)){
$customerName = explode(' ',$custData->name);
}
$amount = $amount; $amount = $amount;
$phone = (isset($custData->phone))?$custData->phone:''; $phone = (isset($custData->phone))?$custData->phone:'';
$email = (isset($custData->email))?$custData->email:''; $email = (isset($custData->email))?$custData->email:'';
$userId = (isset($custData->userId))?$custData->userId:''; $userId = (isset($custData->userId))?$custData->userId:'';
$f_Name = (isset($custData->name))?$custData->name:''; $f_Name = (isset($customerName[0]))?$customerName[0]:'';
$l_Name = 'T'; $l_Name = (isset($customerName[1]))?$customerName[1]:'T';
$add1 = 'Mumbai'; $add1 = $add2 = $city = $state = 'Saudi Arabia';
$add2 = 'Mumbai'; $pincode = '61961';
$city = 'Mumbai';
$state = 'Maharashtra';
$pincode = '123456';
$holder = 'Basanta Mahunta';
$cardType = 'MasterCard';
$cardNo = '5111111111111118'; $cardNo = '5111111111111118';
$cvv = '100';
$expMonth = '06'; $expMonth = '06';
$expYear = '2022'; $expYear = '2022';
$cvv = '100'; // if(!empty($cardData)){
$holder = 'Basanta Mahunta'; // if(isset($cardData['tocken'])){
$cardType = 'MasterCard';
// } else {
// }
// }
$failureUrl = base_url('Api/paymentFailureUrl'); $failureUrl = base_url('Api/paymentFailureUrl');
$successUrl = base_url('Api/paymentSuccessUrl'); $successUrl = base_url('Api/paymentSuccessUrl');
...@@ -369,10 +379,10 @@ class Api extends CI_Controller { ...@@ -369,10 +379,10 @@ class Api extends CI_Controller {
$colabId = $settings['collaborator_id']; $colabId = $settings['collaborator_id'];
$requestUrl = $settings['payment_gateway_url']; $requestUrl = $settings['payment_gateway_url'];
$size = openssl_cipher_iv_length('AES-256-CBC'); $size = openssl_cipher_iv_length($this->cipher);
$pad = $size - (strlen($pText) % $size); $pad = $size - (strlen($pText) % $size);
$painText = $pText . str_repeat(chr($pad), $pad); $painText = $pText . str_repeat(chr($pad), $pad);
$painText = base64_encode(openssl_encrypt($painText, 'AES-256-CBC', base64_decode($mKey), OPENSSL_RAW_DATA | OPENSSL_ZERO_PADDING, $iv)); $painText = base64_encode(openssl_encrypt($painText,$this->cipher,base64_decode($mKey), OPENSSL_RAW_DATA | OPENSSL_ZERO_PADDING, $iv));
$this->load->view('payment/payment',array('rUrl'=>$requestUrl,'mId'=>$mId,'colabId'=>$colabId, $this->load->view('payment/payment',array('rUrl'=>$requestUrl,'mId'=>$mId,'colabId'=>$colabId,
'requestParam'=>$mId.'||'.$colabId.'||'.$painText)); 'requestParam'=>$mId.'||'.$colabId.'||'.$painText));
...@@ -392,7 +402,7 @@ class Api extends CI_Controller { ...@@ -392,7 +402,7 @@ class Api extends CI_Controller {
} }
$enctext = base64_decode($response[1]); $enctext = base64_decode($response[1]);
$padtext = openssl_decrypt($enctext,'AES-256-CBC', base64_decode($mKey),OPENSSL_RAW_DATA | OPENSSL_ZERO_PADDING, $iv); $padtext = openssl_decrypt($enctext,$this->cipher, base64_decode($mKey),OPENSSL_RAW_DATA | OPENSSL_ZERO_PADDING, $iv);
$pad = ord($padtext{strlen($padtext) - 1}); $pad = ord($padtext{strlen($padtext) - 1});
if($pad > strlen($padtext)){ if($pad > strlen($padtext)){
redirect($redUrl.'failure'); redirect($redUrl.'failure');
...@@ -452,7 +462,7 @@ class Api extends CI_Controller { ...@@ -452,7 +462,7 @@ class Api extends CI_Controller {
redirect($redUrl.'failure'); redirect($redUrl.'failure');
} }
$enctext = base64_decode($response[1]); $enctext = base64_decode($response[1]);
$padtext = openssl_decrypt($enctext,'AES-256-CBC', base64_decode($mKey),OPENSSL_RAW_DATA | OPENSSL_ZERO_PADDING, $iv); $padtext = openssl_decrypt($enctext,$this->cipher, base64_decode($mKey),OPENSSL_RAW_DATA | OPENSSL_ZERO_PADDING, $iv);
$pad = ord($padtext{strlen($padtext) - 1}); $pad = ord($padtext{strlen($padtext) - 1});
if($pad > strlen($padtext)){ if($pad > strlen($padtext)){
redirect($redUrl.'failure'); redirect($redUrl.'failure');
...@@ -484,27 +494,6 @@ class Api extends CI_Controller { ...@@ -484,27 +494,6 @@ class Api extends CI_Controller {
redirect($redUrl.'failure'); redirect($redUrl.'failure');
} }
public function checker_bookingDetails(){
$data = (array) json_decode(file_get_contents('php://input'));
$res = $this->Api_model->checkerbookingdetails($data);
if($res['status']!=0){
$this->response($res['data']);
}
else{
$this->errorResponse($res['code'],$res['message']);
}
}
public function checker_login(){
$data = (array) json_decode(file_get_contents('php://input'));
$res = $this->Api_model->checker_login($data);
if($res['status']!=0){
$this->response($res['data']);
} else {
$this->errorResponse($res['code'],$res['message']);
}
}
public function reset_password(){ public function reset_password(){
$data = (array) json_decode(file_get_contents('php://input')); $data = (array) json_decode(file_get_contents('php://input'));
$res = $this->Api_model->reset_password($data); $res = $this->Api_model->reset_password($data);
...@@ -551,17 +540,6 @@ class Api extends CI_Controller { ...@@ -551,17 +540,6 @@ class Api extends CI_Controller {
print json_encode($result);exit; print json_encode($result);exit;
} }
public function getCheckerBookList(){
$data = (array) json_decode(file_get_contents('php://input'));
$res = $this->Api_model->getCheckerBookList($data);
if(isset($res['data']) && !empty($res['data'])){
$this->response($res['data']);
}
else{
$this->errorResponse($res['code'],$res['message']);
}
}
public function getSavedCards(){ public function getSavedCards(){
$data = (array) json_decode(file_get_contents('php://input')); $data = (array) json_decode(file_get_contents('php://input'));
$cust_id = $this->Api_model->auth_token_get($this->auth_token); $cust_id = $this->Api_model->auth_token_get($this->auth_token);
...@@ -602,7 +580,7 @@ class Api extends CI_Controller { ...@@ -602,7 +580,7 @@ class Api extends CI_Controller {
if(empty($merchant_iv) || empty($merchant_key) || empty($plainText)){ if(empty($merchant_iv) || empty($merchant_key) || empty($plainText)){
return false; return false;
} }
$key = 'AES-256-CBC'; $key = $this->cipher;
$size = openssl_cipher_iv_length($key); $size = openssl_cipher_iv_length($key);
$mKey = base64_decode($merchant_key); $mKey = base64_decode($merchant_key);
$padDat = $size - (strlen($plainText) % $size); $padDat = $size - (strlen($plainText) % $size);
...@@ -615,7 +593,7 @@ class Api extends CI_Controller { ...@@ -615,7 +593,7 @@ class Api extends CI_Controller {
if(empty($merchant_iv) || empty($merchant_key) || empty($encText)){ if(empty($merchant_iv) || empty($merchant_key) || empty($encText)){
return false; return false;
} }
$key = 'AES-256-CBC'; $key = $this->cipher;
$mKey = base64_decode($merchant_key); $mKey = base64_decode($merchant_key);
$encText = base64_decode($encText); $encText = base64_decode($encText);
$padtext = openssl_decrypt($encText,$key,$mKey,OPENSSL_RAW_DATA | OPENSSL_ZERO_PADDING, $merchant_iv); $padtext = openssl_decrypt($encText,$key,$mKey,OPENSSL_RAW_DATA | OPENSSL_ZERO_PADDING, $merchant_iv);
...@@ -627,5 +605,72 @@ class Api extends CI_Controller { ...@@ -627,5 +605,72 @@ class Api extends CI_Controller {
$response = substr($padtext,0,-1*$padData); $response = substr($padtext,0,-1*$padData);
return json_decode($response); return json_decode($response);
} }
public function encrypt($plainText='',$mKey='',$mIv='') {
if(empty($plainText) || empty($mKey) || empty($mIv)){
return '';
}
if (in_array($this->cipher, openssl_get_cipher_methods())) {
$ciphertext = openssl_encrypt($plainText, $this->cipher, $this->key, $options=0, $this->iv);
return $ciphertext;
}
}
public function decrypt($encText='',$mKey='',$mIv='') {
if(empty($plainText) || empty($mKey) || empty($mIv)){
return '';
}
if (in_array($this->cipher, openssl_get_cipher_methods())) {
$original_plaintext = openssl_decrypt($encText, $this->cipher, $this->key, $options=0, $this->iv);
return $original_plaintext;
}
}
/*================ START : Checker API ================*/
public function checker_bookingDetails(){
$data = (array) json_decode(file_get_contents('php://input'));
$res = $this->Api_model->checkerbookingdetails($data);
if($res['status']!=0){
$this->response($res['data']);
}
else{
$this->errorResponse($res['code'],$res['message']);
}
}
public function checker_login(){
$data = (array) json_decode(file_get_contents('php://input'));
$res = $this->Api_model->checker_login($data);
if($res['status']!=0){
$this->response($res['data']);
} else {
$this->errorResponse($res['code'],$res['message']);
}
}
public function getCheckerBookList(){
$data = (array) json_decode(file_get_contents('php://input'));
$res = $this->Api_model->getCheckerBookList($data);
if(isset($res['data']) && !empty($res['data'])){
$this->response($res['data']);
}
else{
$this->errorResponse($res['code'],$res['message']);
}
}
public function getCheckerEventList(){
$data = (array) json_decode(file_get_contents('php://input'));
$res = $this->Api_model->getCheckerBookList($data);
if(isset($res['data']) && !empty($res['data'])){
$this->response($res['data']);
}
else{
$this->errorResponse($res['code'],$res['message']);
}
}
/*================ END : Checker API ================*/
} }
?> ?>
...@@ -1444,67 +1444,6 @@ class Api_model extends CI_Model { ...@@ -1444,67 +1444,6 @@ class Api_model extends CI_Model {
return $res; return $res;
} }
public function checker_login($data){
try{
$this->db->where('status',1);
$this->db->where('password',md5($data['password']));
$this->db->where('username',$data['email']);
$this->db->from('checker');
$result = $this->db->get()->row();
if($result){
$res = array('status'=>1,'data'=>array('checker_id'=>$result->id));
} else {
$res = array('status'=>0,'message'=>'Invalid Email Id / Password','code'=>'ER05');
}
} catch(Exception $e) {
$res = array('status'=>0,'message'=>'Ohh No!! Something went South!!','code'=>'ER06');
}
return $res;
}
function checkerbookingdetails($data) {
try {
$count = $this->db->get_where('checker',array('id'=>$data['checker_id']))->num_rows();
if($count > 0){
$result = $this->db
->select('booking.id AS book_id,booking.bookId,customer.name AS customer_name,
booking.status,booking.no_of_ticket,booking.qrcode,
booking.ticket_details,event_date_time.date AS booking_date')
->where('booking.bookId',$data['qr_pin'])
->from('booking')
->join('events','booking.event_id = events.event_id')
->join('event_date_time','booking.event_date_id = event_date_time.id')
->join('venue', 'venue.id = events.venue_id')
->join('event_gallery', 'events.event_id = event_gallery.event_id', 'LEFT')
->join('customer','customer.customer_id = booking.customer_id')
->join('host_categories', 'venue.host_cat_id = host_categories.host_cat_id')
->group_by('booking.bookId')->get()->row();
if(count($result)>0){
$result->seat_class = '';
if(!empty($ticketDetls = json_decode($result->ticket_details))){
if(is_array($ticketDetls) && isset($ticketDetls[0]) && isset($ticketDetls[0]->color)){
$result->seat_class = $ticketDetls[0]->color;
} else if (isset($ticketDetls->color)){
$result->seat_class = $ticketDetls->color;
}
}
$this->db->insert('checker_bookings',
array('checker_id'=>$data['checker_id'],'booking_id'=>$data['qr_pin'],
'checked_time'=>date('Y-m-d H:i:s')));
$res = array('status'=>1,'data'=>$result);
} else {
$res = array('status'=>0,'message'=>'Invalid booking code','code'=>'ER24');
}
}else{
$res = array('status'=>0,'message'=>'Checker Doesnot Exist','code'=>'ER24');
}
} catch(Exception $e) {
$res = array('status'=>0,'message'=>'Ohh No!! Something went South!!','code'=>'ER06');
}
return $res;
}
public function reset_password($data){ public function reset_password($data){
try{ try{
$cust = $this->db->query("SELECT CUST.customer_id FROM customer AS CUST $cust = $this->db->query("SELECT CUST.customer_id FROM customer AS CUST
...@@ -1752,6 +1691,69 @@ class Api_model extends CI_Model { ...@@ -1752,6 +1691,69 @@ class Api_model extends CI_Model {
} }
} }
/*================ START : Checker API ================*/
public function checker_login($data){
try{
$this->db->where('status',1);
$this->db->where('password',md5($data['password']));
$this->db->where('username',$data['email']);
$this->db->from('checker');
$result = $this->db->get()->row();
if($result){
$res = array('status'=>1,'data'=>array('checker_id'=>$result->id));
} else {
$res = array('status'=>0,'message'=>'Invalid Email Id / Password','code'=>'ER05');
}
} catch(Exception $e) {
$res = array('status'=>0,'message'=>'Ohh No!! Something went South!!','code'=>'ER06');
}
return $res;
}
function checkerbookingdetails($data) {
try {
$count = $this->db->get_where('checker',array('id'=>$data['checker_id']))->num_rows();
if($count > 0){
$result = $this->db
->select('booking.id AS book_id,booking.bookId,customer.name AS customer_name,
booking.status,booking.no_of_ticket,booking.qrcode,
booking.ticket_details,event_date_time.date AS booking_date')
->where('booking.bookId',$data['qr_pin'])
->from('booking')
->join('events','booking.event_id = events.event_id')
->join('event_date_time','booking.event_date_id = event_date_time.id')
->join('venue', 'venue.id = events.venue_id')
->join('event_gallery', 'events.event_id = event_gallery.event_id', 'LEFT')
->join('customer','customer.customer_id = booking.customer_id')
->join('host_categories', 'venue.host_cat_id = host_categories.host_cat_id')
->group_by('booking.bookId')->get()->row();
if(count($result)>0){
$result->seat_class = '';
if(!empty($ticketDetls = json_decode($result->ticket_details))){
if(is_array($ticketDetls) && isset($ticketDetls[0]) && isset($ticketDetls[0]->color)){
$result->seat_class = $ticketDetls[0]->color;
} else if (isset($ticketDetls->color)){
$result->seat_class = $ticketDetls->color;
}
}
$this->db->insert('checker_bookings',
array('checker_id'=>$data['checker_id'],'booking_id'=>$data['qr_pin'],
'checked_time'=>date('Y-m-d H:i:s')));
$res = array('status'=>1,'data'=>$result);
} else {
$res = array('status'=>0,'message'=>'Invalid booking code','code'=>'ER24');
}
}else{
$res = array('status'=>0,'message'=>'Checker Doesnot Exist','code'=>'ER24');
}
} catch(Exception $e) {
$res = array('status'=>0,'message'=>'Ohh No!! Something went South!!','code'=>'ER06');
}
return $res;
}
function getCheckerBookList($data) { function getCheckerBookList($data) {
try { try {
$checker_id = $data['checker_id']; $checker_id = $data['checker_id'];
...@@ -1759,8 +1761,12 @@ class Api_model extends CI_Model { ...@@ -1759,8 +1761,12 @@ class Api_model extends CI_Model {
if($count > 0){ if($count > 0){
$sql = "SELECT BOOK.bookId AS booking_id $sql = "SELECT BOOK.bookId AS booking_id
FROM checker_bookings AS CBOOK FROM checker_bookings AS CBOOK
INNER JOIN checker AS CHK ON (CHK.id=CBOOK.checker_id)
INNER JOIN booking AS BOOK ON (BOOK.bookId=CBOOK.booking_id) INNER JOIN booking AS BOOK ON (BOOK.bookId=CBOOK.booking_id)
INNER JOIN events AS EVT ON (EVT.event_id=BOOK.event_id AND
EVT.provider_id=CHK.provider_id)
WHERE CBOOK.checker_id='$checker_id' AND BOOK.status='1'"; WHERE CBOOK.checker_id='$checker_id' AND BOOK.status='1'";
pr($sql);
$count = $this->db->query($sql)->num_rows(); $count = $this->db->query($sql)->num_rows();
if($count > 0) { if($count > 0) {
...@@ -1774,8 +1780,10 @@ class Api_model extends CI_Model { ...@@ -1774,8 +1780,10 @@ class Api_model extends CI_Model {
$sql = "SELECT TEVT.event_name,TCAT.category_name,CUST.name,EDATE.date, $sql = "SELECT TEVT.event_name,TCAT.category_name,CUST.name,EDATE.date,
EDATE.time,BOOK.amount,BOOK.bookId AS booking_id EDATE.time,BOOK.amount,BOOK.bookId AS booking_id
FROM checker_bookings AS CBOOK FROM checker_bookings AS CBOOK
INNER JOIN checker AS CHK ON (CHK.id=CBOOK.checker_id)
INNER JOIN booking AS BOOK ON (BOOK.bookId=CBOOK.booking_id) INNER JOIN booking AS BOOK ON (BOOK.bookId=CBOOK.booking_id)
INNER JOIN events AS EVT ON (EVT.event_id=BOOK.event_id) INNER JOIN events AS EVT ON (EVT.event_id=BOOK.event_id AND
EVT.provider_id=CHK.provider_id)
INNER JOIN event_date_time AS EDATE ON (EDATE.event_id=EVT.event_id) INNER JOIN event_date_time AS EDATE ON (EDATE.event_id=EVT.event_id)
INNER JOIN event_category AS CAT ON (CAT.cat_id=EVT.category_id) INNER JOIN event_category AS CAT ON (CAT.cat_id=EVT.category_id)
INNER JOIN customer AS CUST ON (CUST.customer_id=BOOK.customer_id) INNER JOIN customer AS CUST ON (CUST.customer_id=BOOK.customer_id)
...@@ -1802,5 +1810,6 @@ class Api_model extends CI_Model { ...@@ -1802,5 +1810,6 @@ class Api_model extends CI_Model {
} }
return $res; return $res;
} }
}
?> /*================ END : Checker API ================*/
} ?>
...@@ -59,14 +59,6 @@ ...@@ -59,14 +59,6 @@
<input type="text" name="service_charge" class="form-control required" placeholder="Enter Service Charge" value="<?= $data['service_charge'] ?>"> <input type="text" name="service_charge" class="form-control required" placeholder="Enter Service Charge" value="<?= $data['service_charge'] ?>">
</div> </div>
<div class="form-group col-xs-6"> <div class="form-group col-xs-6">
<label>BayanPay Merchant Key</label>
<input type="text" name="merchant_key" class="form-control required" placeholder="Enter Merchant Key" value="<?= $data['merchant_key'] ?>">
</div>
<div class="form-group col-xs-6">
<label>BayanPay Merchant ID</label>
<input type="text" name="merchant_id" class="form-control required" placeholder="Enter Merchant ID" value="<?= $data['merchant_id'] ?>">
</div>
<div class="form-group col-xs-6">
<label>Admin Email-ID</label> <label>Admin Email-ID</label>
<input type="email" name="admin_mail_id" class="form-control required" placeholder="Admin Email-ID" value="<?= $data['admin_mail_id'] ?>"> <input type="email" name="admin_mail_id" class="form-control required" placeholder="Admin Email-ID" value="<?= $data['admin_mail_id'] ?>">
</div> </div>
...@@ -96,7 +88,35 @@ ...@@ -96,7 +88,35 @@
</div> </div>
</div> </div>
</div> </div>
<div class="box-header with-border">
<div class="col-md-6">
<h3 class="box-title">Payment Gateway Details</h3>
</div>
</div>
<div class="box-body">
<div class="form-group col-xs-12">
<div class="form-group col-xs-4">
<label>BayanPay Merchant ID</label>
<input type="text" name="merchant_id" class="form-control required" placeholder="Enter Merchant ID" value="<?= $data['merchant_id'] ?>">
</div>
<div class="form-group col-xs-4">
<label>BayanPay Merchant IV</label>
<input type="text" name="merchant_iv" class="form-control required" placeholder="Enter Merchant IV" value="<?= $data['merchant_iv'] ?>">
</div>
<div class="form-group col-xs-4">
<label>BayanPay Merchant Key</label>
<input type="text" name="merchant_key" class="form-control required" placeholder="Enter Merchant Key" value="<?= $data['merchant_key'] ?>">
</div>
<div class="form-group col-xs-4">
<label>BayanPay Collaborator ID</label>
<input type="text" name="collaborator_id" class="form-control required" placeholder="Enter Collaborator ID" value="<?= $data['collaborator_id'] ?>">
</div>
<div class="form-group col-xs-8">
<label>BayanPay Gateway URL</label>
<input type="text" name="payment_gateway_url" class="form-control required" placeholder="Enter Gateway URL" value="<?= $data['payment_gateway_url'] ?>">
</div>
</div>
</div>
<div class="box-header with-border"> <div class="box-header with-border">
<div class="col-md-6"> <div class="col-md-6">
<h3 class="box-title">APP Details</h3> <h3 class="box-title">APP Details</h3>
......
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