Commit d862c06e by Jansa Jose

change in payment gateway api

parent ff69c537
...@@ -1515,6 +1515,7 @@ ...@@ -1515,6 +1515,7 @@
//Payment Integration of Mechanic Booking //Payment Integration of Mechanic Booking
public function payNow($transId=''){ public function payNow($transId=''){
//pr($transId);
if(empty($transId)){ if(empty($transId)){
$this->fail(); $this->fail();
} }
...@@ -1527,7 +1528,7 @@ ...@@ -1527,7 +1528,7 @@
'reference' => $transId, 'reference' => $transId,
'callback_url' => $callback); 'callback_url' => $callback);
$this->payStackPayment($postdata); $this->payStackPayment($postdata,1);
} }
//Payment Integration of Order Booking //Payment Integration of Order Booking
...@@ -1544,11 +1545,11 @@ ...@@ -1544,11 +1545,11 @@
'amount' => $amount, 'amount' => $amount,
'reference' => $orderId, 'reference' => $orderId,
'callback_url' => $callback); 'callback_url' => $callback);
$this->payStackPayment($postdata); $this->payStackPayment($postdata,2);
} }
} }
public function payStackPayment($postdata=array()) { public function payStackPayment($postdata=array(),$payFor='1') {
$url = "https://api.paystack.co/transaction/initialize"; $url = "https://api.paystack.co/transaction/initialize";
$ch = curl_init(); $ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url); curl_setopt($ch, CURLOPT_URL,$url);
...@@ -1566,14 +1567,17 @@ ...@@ -1566,14 +1567,17 @@
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$request = curl_exec($ch); $request = curl_exec($ch);
curl_close ($ch); curl_close ($ch);
if(!empty($result = json_decode($request,true)) &&
$result = array(); isset($result['data']) && !empty($result['data']) &&
if ($request) { isset($result['data']['authorization_url']) &&
$result = json_decode($request, true); !empty($result['data']['authorization_url'])){
}
$redir = $result['data']['authorization_url']; $redir = $result['data']['authorization_url'];
header("Location: ".$redir); header("Location: ".$redir);
} }
//pr($result);
$status = $this->Webservice_model->transactionResp($postdata['reference'],$result,$payFor);
$this->fail();
}
public function verify_payment($ref='',$payFor='1') { public function verify_payment($ref='',$payFor='1') {
if(empty($ref)){ if(empty($ref)){
......
...@@ -651,7 +651,7 @@ class Webservice_model extends CI_Model { ...@@ -651,7 +651,7 @@ class Webservice_model extends CI_Model {
return $respArr; return $respArr;
} }
public function getMechAmount($transId){ public function getMechAmount($transId=''){
$respArr = array('status'=>'error'); $respArr = array('status'=>'error');
if(empty($transId)){ if(empty($transId)){
return $respArr; return $respArr;
...@@ -667,35 +667,41 @@ class Webservice_model extends CI_Model { ...@@ -667,35 +667,41 @@ class Webservice_model extends CI_Model {
return $respArr; return $respArr;
} }
public function transactionResp($transId,$result,$payfor){ public function transactionResp($transId='',$result=array(),$payfor='1'){
$status = 0; $status = 0;
if($result['data']['status'] == 'success'){ $odrStat = 9;
$trancRef = '';
$respJson = (!empty($result))?json_encode($result):'';
if(!empty($result) && isset($result['data']) && !empty($result['data'])){
$trancReference = $result['data']['id'];
if(isset($result['data']['status']) && $result['data']['status'] == 'success'){
$status = 1; $status = 1;
$odrStat = ($payfor == '2')?2:$odrStat;
} }
$odr_status = 9;
if($result['data']['status'] == 'success' && $payfor == '2'){
$odr_status = 2;
} }
$this->db->update('transaction',array('transaction_response'=>json_encode($result),'transaction_reference'=>$result['data']['id'],'status'=>$status),array('id'=>$transId));
$bookData = $this->db->get_where('transaction',array('id'=>$transId))->row();
$this->db->update('bookings',array('status'=>'1'),array('booking_id'=>$bookData->booking_id));
if($payfor == '2'){ $this->db->update('transaction',array('transaction_response'=>$respJson,'transaction_reference'=>$trancRef,'status'=>$status),array('id'=>$transId));
$this->db->query("UPDATE orders JOIN transaction ON transaction.booking_id = orders.order_id SET orders.status = $odr_status WHERE transaction.id = $transId");
if($payfor == '1'){
$this->db->query("UPDATE bookings
JOIN transaction ON transaction.booking_id=bookings.booking_id
SET bookings.status = $status WHERE transaction.id = $transId");
} else if($payfor == '2'){
$this->db->query("UPDATE orders
JOIN transaction ON transaction.booking_id = orders.order_id
SET orders.status = $odrStat WHERE transaction.id = $transId");
} }
return 1; return 1;
} }
public function transactionRespApi($transId,$result,$payfor){ public function transactionRespApi($transId='',$result=array(),$payfor='1'){
$status = 0; $status = 0;
if($result['data']['status'] == 'success'){
$status = 1;
}
$odr_status = 9; $odr_status = 9;
if($result['data']['status'] == 'success' && $payfor == '2'){ if(!empty($result) && isset($result['data']) && !empty($result['data']) &&
$odr_status = 2; isset($result['data']['status']) && $result['data']['status'] == 'success'){
$status = 1;
$odr_status = ($payfor == '2')?2:$odr_status;
} }
$bookData = $this->db->get_where('transaction',array('id'=>$transId))->row(); $bookData = $this->db->get_where('transaction',array('id'=>$transId))->row();
......
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