Commit 9752e130 by Tobin

dc

parent 7b08f979
...@@ -53,7 +53,7 @@ class Api extends CI_Controller { ...@@ -53,7 +53,7 @@ class Api extends CI_Controller {
'message' => 'Success', 'message' => 'Success',
'responseResult' =>$data 'responseResult' =>$data
); );
print json_encode($result); print json_encode($result);exit;
} }
public function errorResponse($errorCode, $errorDesc) { public function errorResponse($errorCode, $errorDesc) {
...@@ -63,7 +63,7 @@ class Api extends CI_Controller { ...@@ -63,7 +63,7 @@ class Api extends CI_Controller {
'errorCode'=> $errorCode, 'errorCode'=> $errorCode,
'errorDesc'=> $errorDesc 'errorDesc'=> $errorDesc
); );
print json_encode($result); print json_encode($result);exit;
} }
public function login(){ public function login(){
...@@ -561,5 +561,71 @@ class Api extends CI_Controller { ...@@ -561,5 +561,71 @@ class Api extends CI_Controller {
$this->errorResponse($res['code'],$res['message']); $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);
}
} }
?> ?>
...@@ -109,8 +109,8 @@ ...@@ -109,8 +109,8 @@
$QR = imagecreatefrompng('https://chart.googleapis.com/chart?cht=qr&chld=H|1&chs=500x500&chl='.$qr_id); $QR = imagecreatefrompng('https://chart.googleapis.com/chart?cht=qr&chld=H|1&chs=500x500&chl='.$qr_id);
$logo = imagecreatefromstring(file_get_contents($logo)); $logo = imagecreatefromstring(file_get_contents($logo));
$qrWidth = imagesx($QR)/2; $qrWidth = imagesx($QR)/2.5;
$qrHeight = imagesy($QR)/2; $qrHeight = imagesy($QR)/2.5;
$logoWidth = imagesx($logo); $logoWidth = imagesx($logo);
$logoHeight = imagesy($logo); $logoHeight = imagesy($logo);
...@@ -119,7 +119,7 @@ ...@@ -119,7 +119,7 @@
$imgWidth = $qrWidth; $imgWidth = $qrWidth;
$imgHeight = $logoHeight/$scale; $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); imagepng($QR, $savePath);
return $savePath; return $savePath;
......
...@@ -389,14 +389,25 @@ class Validation_model extends CI_Model { ...@@ -389,14 +389,25 @@ class Validation_model extends CI_Model {
'message' => 'checker ID is null or empty' '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(){ public function _consruct(){
parent::_construct(); parent::_construct();
} }
public function validation_check($method_name, $parms) { public function validation_check($method_name, $parms) {
...@@ -407,7 +418,7 @@ class Validation_model extends CI_Model { ...@@ -407,7 +418,7 @@ class Validation_model extends CI_Model {
foreach ($value as $keys => $values) { foreach ($value as $keys => $values) {
switch ($keys) { switch ($keys) {
case 'required': case 'required':
if(!isset($parms[$key]) || $parms[$key]=='' || $parms[$key]== null){ if(!isset($parms[$key]) || $parms[$key] == '' || $parms[$key] == null){
$state = 1; $state = 1;
$error_key = $values; $error_key = $values;
} }
...@@ -416,28 +427,22 @@ class Validation_model extends CI_Model { ...@@ -416,28 +427,22 @@ class Validation_model extends CI_Model {
if (isset($parms[$key]) && !filter_var($parms[$key], FILTER_VALIDATE_EMAIL)) { if (isset($parms[$key]) && !filter_var($parms[$key], FILTER_VALIDATE_EMAIL)) {
$state = 1; $state = 1;
$error_key = $values; $error_key = $values;
} }
break; break;
case 'phone': case 'phone':
if(isset($parms[$key])){ 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) { if (strlen($phone) <= 9 && strlen($phone) >= 13) {
$state = 1; $state = 1;
$error_key = $values; $error_key = $values;
} }
} }
break;
default:
# code...
break; break;
default: break;
} }
if($state==1){ if($state==1) break;
break;
}
}
if($state==1){
break;
} }
if($state==1) break;
} }
return array('state'=>$state,'response'=>$error_key); return array('state'=>$state,'response'=>$error_key);
} }
......
assets/uploads/user/CUST_QR_173.png

46.9 KB | W: | H:

assets/uploads/user/CUST_QR_173.png

33.3 KB | W: | H:

assets/uploads/user/CUST_QR_173.png
assets/uploads/user/CUST_QR_173.png
assets/uploads/user/CUST_QR_173.png
assets/uploads/user/CUST_QR_173.png
  • 2-up
  • Swipe
  • Onion skin
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