Skip to content

Commit

Permalink
Added ability to fetch payment transaction details
Browse files Browse the repository at this point in the history
  • Loading branch information
kingsleyudenewu authored Jul 18, 2018
1 parent a59a0c1 commit 9deb44a
Showing 1 changed file with 53 additions and 0 deletions.
53 changes: 53 additions & 0 deletions src/Voguepay.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@

class Voguepay
{
/**
* The preferred method for server-server connections
* @var connection_type;
*/
protected $connection_type;

/**
* Instance of Client from GuzzleHttp
* @var Client
Expand Down Expand Up @@ -98,6 +104,7 @@ public function __construct()
$this->setSuccessUrl();
$this->setFailUrl();
$this->setBaseUrl();
$this->setConnectionType();
}

/**
Expand All @@ -115,6 +122,14 @@ private function setRequestOptions()
]
);
}

/**
* @param string $v_merchant_id
*/
public function setConnectionType()
{
$this->connection_type = 'curl';
}

/**
* @param string $v_merchant_id
Expand Down Expand Up @@ -303,6 +318,44 @@ private function extractNeededTransactionData($transactionData, $allowedFields)
}
return $redefinedTransactionData;
}

private function getPaymentDetails($transaction_id,$type="json")
{
//currently only json format is supported. But XML would be added soon.
$url = "https://voguepay.com/?v_transaction_id={$transaction_id}&type={$type}";
if($this->connection_type =="curl")
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
if($this->proxy)
{
curl_setopt($ch, CURLOPT_PROXY, $this->proxy);
//curl_setopt($ch, CURLOPT_PROXYUSERPWD, $proxyauth);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
}
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windowos NT 5.1; en-NG; rv:1.8.1.13) Gecko/20080311 Firefox/2.0.0.13 Vyren Media-VoguePay API Ver 1.0");
if(curl_errno($ch)){ curl_error($ch)." - [Called In getPaymentDetails() CURL]"; }
$output = curl_exec($ch);
curl_close($ch);
}
if($this->connection_type =="fgc")
{
$output = file_get_contents($url);
if(!$output) {$output = "Failed To Get JSON Data - [Called In getPaymentDetails() FGC]"; }
}
return $output;
}

public function verifyPayment($transaction_id)
{
$details = json_decode($this->getPaymentDetails($transaction_id,"json"));
if(!$details){ return json_encode(array("state"=>"error","msg"=>"Failed Getting Transaction Details - [Called In verifyPayment()]"));}
if($details->total < 1) return json_encode(array("state"=>"error","msg"=>"Invalid Transaction"));
if($details->status != 'Approved') return json_encode(array("state"=>"error","msg"=>"Transaction {$details->status}"));
return json_encode(array("state"=>"success","msg"=>"Transaction Approved"));
}



Expand Down

0 comments on commit 9deb44a

Please sign in to comment.