Skip to content

Commit

Permalink
progress
Browse files Browse the repository at this point in the history
  • Loading branch information
busgurlu committed Jun 14, 2018
1 parent baddf56 commit a59706b
Show file tree
Hide file tree
Showing 7 changed files with 203 additions and 131 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ The following gateways are provided by this package:

For general usage instructions, please see the main [Omnipay](https://github.com/thephpleague/omnipay) repository.

There isn't a seperate test gateway but there are test users. Enabling test mode sets the user to a test user.

The outcome of a result can be changed by using the QAResultStatus parameter. Set to '000' to get a positive result.

## Support

If you are having general issues with Omnipay, we suggest posting on
Expand Down
21 changes: 18 additions & 3 deletions src/IframeGateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ class IframeGateway extends AbstractGateway

public function getName()
{
return 'Iframe';
return 'Pelecard Iframe Gateway';
}

public function getDefaultParameters()
{
return array(
Expand Down Expand Up @@ -102,6 +102,21 @@ public function setTerminal($value)
*/
public function authorize(array $parameters = array())
{
return $this->createRequest('\Omnipay\Pelecard\Message\InitializeRequest', $parameters);
return $this->createRequest('\Omnipay\Pelecard\Message\AuthorizeRequest', $parameters);
}

public function status(array $parameters = array())
{
return $this->createRequest('\Omnipay\Pelecard\Message\StatusRequest', $parameters);
}

public function acceptNotification(array $parameters = array())
{
return $this->createRequest('\Omnipay\Pelecard\Message\StatusRequest', $parameters);
}

public function extendedStatus(array $parameters = array())
{
return $this->createRequest('\Omnipay\Pelecard\Message\StatusRequest', $parameters);
}
}
35 changes: 12 additions & 23 deletions src/Message/AbstractRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ abstract class AbstractRequest extends BaseAbstractRequest

protected $liveEndpoint = 'https://gateway20.pelecard.biz/PaymentGW/init';

protected $testEndpoint = 'https://gateway20.pelecard.biz/PaymentGW/init';

protected $request = [];

/**
Expand All @@ -25,10 +23,17 @@ abstract class AbstractRequest extends BaseAbstractRequest
public function getData()
{
$this->request = array();
$this->request['user'] = $this->getParameter('user');
$this->request['password'] = $this->getParameter('password');
$this->request['terminal'] = $this->getParameter('terminal');
$this->request['Language'] = $this->getParameter('Language');
if($this->getTestMode()){
$this->request['user'] = 'testpelecard3';
$this->request['password'] = 'Q3EJB8Ah';
$this->request['terminal'] = '0962210';
}
else{
$this->request['user'] = $this->getParameter('user');
$this->request['password'] = $this->getParameter('password');
$this->request['terminal'] = $this->getParameter('terminal');
}


return $this->request;
}
Expand Down Expand Up @@ -145,25 +150,9 @@ public function setCurrency($value)
throw new RuntimeException('Unknown currency');
}

/**
* Sets the language code.
*
* @param string $value
*/
public function setLanguage($value)
{
if ($value !== null) {
$value = strtoupper($value);
}
if(!in_array($value, ['HE','EN','RU'])) {
throw new RuntimeException('Unknown language');
}
return $this->setParameter('Language', $value);
}

protected function getEndpoint()
{
return $this->getTestMode() ? $this->testEndpoint : $this->liveEndpoint;
return $this->liveEndpoint;
}

protected function createResponse($data)
Expand Down
57 changes: 55 additions & 2 deletions src/Message/AuthorizeRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,61 @@ class AuthorizeRequest extends AbstractRequest
public function getData()
{
$this->validate('amount', 'card');
$this->getCard()->validate();
$data = $this->getBaseData();
//$this->getCard()->validate();
$data = parent::getData();
$data['UserKey'] = $this->getTransactionId();
$data['Total'] = $this->getAmountInteger();
$data['Currency'] = $this->getCurrency();
$data['GoodURL'] = $this->getReturnUrl();
$data['ErrorURL'] = $this->getReturnUrl();
$data['CancelURL'] = $this->getCancelUrl();
$data['CardHolderName'] = $this->getCard()->getName();
$data['CustomerAddressField'] = implode(' ',[$this->getCard()->getAddress1(),$this->getCard()->getAddress2()]);
$data['CustomerCityField'] = $this->getCard()->getCity();
$data['CustomerIndexField'] = $this->getCard()->getPostcode();
$data['CustomerCountryField'] = $this->getCard()->getCountry();
$data['EmailField'] = $this->getCard()->getEmail();
if($this->getParameter('Language')) $data['Language'] = $this->getParameter('Language');
if($this->getParameter('QAResultStatus')) $data['QAResultStatus'] = $this->getParameter('QAResultStatus');
return $data;
}

/**
* Get GoodURL
*
* @return string
*/
public function getReturnUrl()
{
if (empty($this->getParameter('returnUrl'))) {
throw new InvalidRequestException('returnUrl must be set.');
}
return $this->getParameter('returnUrl');
}

/**
* Set GoodURL
*
* @param string $value
*/
public function setReturnUrl($value)
{
return $this->setParameter('returnUrl', $value);
}

/**
* Sets the language code.
*
* @param string $value
*/
public function setLanguage($value)
{
if ($value !== null) {
$value = strtoupper($value);
}
if(!in_array($value, ['HE','EN','RU'])) {
throw new RuntimeException('Unknown language');
}
return $this->setParameter('Language', $value);
}
}
53 changes: 0 additions & 53 deletions src/Message/InitializeRequest.php

This file was deleted.

143 changes: 93 additions & 50 deletions src/Message/Response.php
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'];
}
}
21 changes: 21 additions & 0 deletions src/Message/StatusRequest.php
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;
}

}

0 comments on commit a59706b

Please sign in to comment.