diff --git a/application/config/config.php b/application/config/config.php index 15e8f98..a69dc72 100644 --- a/application/config/config.php +++ b/application/config/config.php @@ -23,7 +23,7 @@ defined('BASEPATH') OR exit('No direct script access allowed'); | a PHP script and you can easily do that on your own. | */ -$config['base_url'] = "https://".$_SERVER['HTTP_HOST'].dirname($_SERVER['SCRIPT_NAME']); +$config['base_url'] = "http://".$_SERVER['HTTP_HOST'].dirname($_SERVER['SCRIPT_NAME']); /* |-------------------------------------------------------------------------- diff --git a/application/config/database.php b/application/config/database.php index 3231536..a85845d 100644 --- a/application/config/database.php +++ b/application/config/database.php @@ -88,7 +88,7 @@ $db['default'] = array( 'char_set' => 'utf8', 'dbcollat' => 'utf8_general_ci', 'swap_pre' => '', - 'encrypt' => FALSE, + 'encrypt' => FALSE, 'compress' => FALSE, 'stricton' => FALSE, 'failover' => array(), diff --git a/application/controllers/Api.php b/application/controllers/Api.php index e53b379..5a59fd3 100644 --- a/application/controllers/Api.php +++ b/application/controllers/Api.php @@ -53,7 +53,7 @@ class Api extends CI_Controller { 'message' => 'Success', 'responseResult' =>$data ); - print json_encode($result); + print json_encode($result);exit; } public function errorResponse($errorCode, $errorDesc) { @@ -63,7 +63,7 @@ class Api extends CI_Controller { 'errorCode'=> $errorCode, 'errorDesc'=> $errorDesc ); - print json_encode($result); + print json_encode($result);exit; } public function login(){ @@ -561,5 +561,71 @@ class Api extends CI_Controller { $this->errorResponse($res['code'],$res['message']); } } + + public function getSavedCards(){ + $data = (array) json_decode(file_get_contents('php://input')); + $cust_id = $this->Api_model->auth_token_get($this->auth_token); + 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']; + $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.'","emailId":"'.$email.'"}'; + $plainText = $this->encryptePayData($merchant_iv,$merchant_key,$reqData); + $plainText = $merchant_id.'|'.$plainText; + + $ch = curl_init(); + curl_setopt($ch,CURLOPT_URL,'https://staging.bayanpay.sa/direcpay/secure/PaymentsMerchStoredCardDtlsAPI'); + curl_setopt($ch,CURLOPT_RETURNTRANSFER,1); + curl_setopt($ch,CURLOPT_POST,1); + curl_setopt($ch,CURLOPT_POSTFIELDS,$plainText); + 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'); + } + $resp = $this->decryptePayData($merchant_iv,$merchant_key,$result); + if(empty($resp) || !isset($resp->txnCardDetails) || + empty($resp->txnCardDetails) || count($resp->txnCardDetails) <= 0){ + $this->errorResponse('893','No Data Found'); + } + $this->response(array('saved_cards'=>$resp->txnCardDetails)); + } + + function encryptePayData($merchant_iv='',$merchant_key='',$plainText='') { + if(empty($merchant_iv) || empty($merchant_key) || empty($plainText)){ + return false; + } + $key = 'AES-256-CBC'; + $size = openssl_cipher_iv_length($key); + $mKey = base64_decode($merchant_key); + $padDat = $size - (strlen($plainText) % $size); + $padtext = $plainText . str_repeat(chr($padDat), $padDat); + $encText = openssl_encrypt($padtext,$key,$mKey,OPENSSL_RAW_DATA | OPENSSL_ZERO_PADDING,$merchant_iv); + return base64_encode($encText); + } + + function decryptePayData($merchant_iv='',$merchant_key='',$encText='') { + if(empty($merchant_iv) || empty($merchant_key) || empty($encText)){ + return false; + } + $key = 'AES-256-CBC'; + $mKey = base64_decode($merchant_key); + $encText = base64_decode($encText); + $padtext = openssl_decrypt($encText,$key,$mKey,OPENSSL_RAW_DATA | OPENSSL_ZERO_PADDING, $merchant_iv); + $padData = ord($padtext{strlen($padtext) - 1}); + + if ($padData > strlen($padtext)) return false; + if (strspn($padtext,$padtext{strlen($padtext)-1},strlen($padtext)-$padData)!=$padData) return false; + + $response = substr($padtext,0,-1*$padData); + return json_decode($response); + } } ?> diff --git a/application/helpers/generals_helper.php b/application/helpers/generals_helper.php index e50790c..ea4c0ad 100644 --- a/application/helpers/generals_helper.php +++ b/application/helpers/generals_helper.php @@ -109,8 +109,8 @@ $QR = imagecreatefrompng('https://chart.googleapis.com/chart?cht=qr&chld=H|1&chs=500x500&chl='.$qr_id); $logo = imagecreatefromstring(file_get_contents($logo)); - $qrWidth = imagesx($QR)/2; - $qrHeight = imagesy($QR)/2; + $qrWidth = imagesx($QR)/2.5; + $qrHeight = imagesy($QR)/2.5; $logoWidth = imagesx($logo); $logoHeight = imagesy($logo); @@ -119,7 +119,7 @@ $imgWidth = $qrWidth; $imgHeight = $logoHeight/$scale; - imagecopyresampled($QR,$logo,125,120,0,0,$imgWidth,$imgHeight,$logoWidth,$logoHeight); + imagecopyresampled($QR,$logo,155,150,0,0,$imgWidth,$imgHeight,$logoWidth,$logoHeight); imagepng($QR, $savePath); return $savePath; diff --git a/application/models/Validation_model.php b/application/models/Validation_model.php index c2eb5c9..9ab3890 100644 --- a/application/models/Validation_model.php +++ b/application/models/Validation_model.php @@ -389,14 +389,25 @@ class Validation_model extends CI_Model { 'message' => 'checker ID is null or empty' ) ) + ), + 'getSavedCards'=>array( + 'email' => array( + 'required' => array( + 'code' => 'ER18', + 'message' => 'Customer Email ID is null or empty' + ) + ), + 'auth_token' => array( + 'required' => array( + 'code' => 'ER19', + 'message' => 'User Id is null or empty' + ) + ) ) ); - - public function _consruct(){ parent::_construct(); - } public function validation_check($method_name, $parms) { @@ -407,7 +418,7 @@ class Validation_model extends CI_Model { foreach ($value as $keys => $values) { switch ($keys) { case 'required': - if(!isset($parms[$key]) || $parms[$key]=='' || $parms[$key]== null){ + if(!isset($parms[$key]) || $parms[$key] == '' || $parms[$key] == null){ $state = 1; $error_key = $values; } @@ -416,28 +427,22 @@ class Validation_model extends CI_Model { if (isset($parms[$key]) && !filter_var($parms[$key], FILTER_VALIDATE_EMAIL)) { $state = 1; $error_key = $values; - } + } break; case 'phone': if(isset($parms[$key])){ - $phone = preg_replace('/[^0-9]/', '', $parms[$key]); + $phone = preg_replace('/[^0-9]/', '', $parms[$key]); if (strlen($phone) <= 9 && strlen($phone) >= 13) { - $state = 1; + $state = 1; $error_key = $values; - } - } - break; - default: - # code... + } + } break; + default: break; } - if($state==1){ - break; - } - } - if($state==1){ - break; + if($state==1) break; } + if($state==1) break; } return array('state'=>$state,'response'=>$error_key); } diff --git a/assets/uploads/qrcode/bookCode_1558433578.png b/assets/uploads/qrcode/bookCode_1558433578.png deleted file mode 100644 index d4cae02..0000000 Binary files a/assets/uploads/qrcode/bookCode_1558433578.png and /dev/null differ diff --git a/assets/uploads/qrcode/bookCode_1570602365.png b/assets/uploads/qrcode/bookCode_1570602365.png new file mode 100644 index 0000000..66d80ec Binary files /dev/null and b/assets/uploads/qrcode/bookCode_1570602365.png differ diff --git a/assets/uploads/user/CUST_QR_173.png b/assets/uploads/user/CUST_QR_173.png index dbb7433..3fbf077 100644 Binary files a/assets/uploads/user/CUST_QR_173.png and b/assets/uploads/user/CUST_QR_173.png differ