-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
203 additions
and
131 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,51 +1,94 @@ | ||
<?php | ||
|
||
namespace Omnipay\Pelecard\Message; | ||
|
||
use Omnipay\Common\Message\AbstractResponse; | ||
use Omnipay\Common\Message\RequestInterface; | ||
|
||
/** | ||
* Response | ||
*/ | ||
class Response extends AbstractResponse | ||
{ | ||
public function __construct(RequestInterface $request, $data) | ||
{ | ||
$this->request = $request; | ||
$this->data = $data; | ||
} | ||
|
||
public function isSuccessful() | ||
{ | ||
return $this->data['Error']['ErrCode'] == 0; | ||
} | ||
|
||
public function getTransactionReference() | ||
{ | ||
if (isset($this->data['ConfirmationKey'])) { | ||
return $this->data['ConfirmationKey']; | ||
} | ||
} | ||
|
||
public function getRedirectUrl() | ||
{ | ||
if (isset($this->data['URL'])) { | ||
return $this->data['URL']; | ||
} | ||
} | ||
|
||
public function isRedirect() | ||
{ | ||
if (isset($this->data['URL']) && !empty($this->data['URL'])) { | ||
return true; | ||
} | ||
return false; | ||
} | ||
|
||
public function getMessage() | ||
{ | ||
return $this->data['Error']['ErrMsg']; | ||
} | ||
|
||
<?php | ||
namespace Omnipay\Pelecard\Message; | ||
|
||
use Omnipay\Common\Message\AbstractResponse; | ||
use Omnipay\Common\Message\RequestInterface; | ||
use Guzzle\Http\ClientInterface; | ||
use Guzzle\Http\Client as HttpClient; | ||
|
||
/** | ||
* Response | ||
*/ | ||
class Response extends AbstractResponse | ||
{ | ||
|
||
public function __construct(RequestInterface $request, $data) | ||
{ | ||
$this->request = $request; | ||
$this->data = $data; | ||
} | ||
|
||
public function isSuccessful() | ||
{ | ||
if (isset($this->data['StatusCode']) && $this->data['StatusCode'] === '000') { | ||
// do confirmation as suggested by the api documentation ValidateByUniqueKey. | ||
$url = 'https://gateway20.pelecard.biz/PaymentGW/ValidateByUniqueKey'; | ||
//The parameter name in the confirmation JSON is UniqueKey because in case there is no UserKey (was not sent in the initial JSON) you can perform confirmation using TransactionId instead. | ||
$request = [ | ||
"ConfirmationKey" => $this->data['ResultData']['ConfirmationKey'], | ||
"UniqueKey" => $this->request->getTransactionId()?$this->request->getTransactionId():$this->data['ResultData']['TransactionId'], | ||
"TotalX100" => $this->data['ResultData']['DebitTotal'] | ||
]; | ||
$httpClient = new HttpClient('', array( | ||
'curl.options' => array( | ||
CURLOPT_CONNECTTIMEOUT => 60 | ||
) | ||
)); | ||
$httpRequest = $httpClient->post($url, [ | ||
'Content-Type' => 'application/json; charset=utf-8', | ||
'Accept' => 'application/json', | ||
'json' => json_encode($request) | ||
], json_encode($request)); | ||
$httpResponse = $httpRequest->send(); | ||
return $httpResponse->json() == 1; | ||
} else | ||
return false; | ||
} | ||
|
||
public function isCancelled() | ||
{ | ||
if (isset($this->data['StatusCode']) && $this->data['StatusCode'] === '000') { | ||
return false; | ||
} | ||
return true; | ||
} | ||
|
||
public function isPending() | ||
{ | ||
return false; | ||
} | ||
|
||
public function getTransactionReference() | ||
{ | ||
if (isset($this->data['URL']) && ! empty($this->data['URL'])) { | ||
$url = parse_url($this->data['URL']); | ||
if (! empty($url['query'])) { | ||
parse_str($url['query'], $query); | ||
if (! empty($query['transactionId'])) { | ||
return $query['transactionId']; | ||
} | ||
} | ||
} | ||
throw new \Exception('Unable to parse query to extract transaction reference.'); | ||
} | ||
|
||
public function getRedirectUrl() | ||
{ | ||
if (isset($this->data['URL'])) { | ||
return $this->data['URL']; | ||
} | ||
} | ||
|
||
public function isRedirect() | ||
{ | ||
if (isset($this->data['URL']) && ! empty($this->data['URL'])) { | ||
return true; | ||
} | ||
return false; | ||
} | ||
|
||
public function getMessage() | ||
{ | ||
return $this->data['Error']['ErrMsg']; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
namespace Omnipay\Pelecard\Message; | ||
/** | ||
* Status Request | ||
* | ||
* @method Response send() | ||
*/ | ||
class StatusRequest extends AbstractRequest | ||
{ | ||
|
||
protected $liveEndpoint = 'https://gateway20.pelecard.biz/PaymentGW/GetTransaction'; | ||
|
||
public function getData() | ||
{ | ||
$data = parent::getData(); | ||
$data['QAResultStatus']='000'; | ||
$data['TransactionId'] = $this->getTransactionReference(); | ||
return $data; | ||
} | ||
|
||
} |