Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@
}
],
"autoload": {
"psr-0": { "Omnipay\\Realex\\" : "src/" }
"psr-4": { "Omnipay\\Realex\\" : "src/" }
},
"require": {
"omnipay/common": "~2.0"
"omnipay/common": "^3"
},
"require-dev": {
"squizlabs/php_codesniffer": "~1.4.4"
"squizlabs/php_codesniffer": "^3"
}
}
66 changes: 35 additions & 31 deletions src/Omnipay/Realex/Message/AuthRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,31 +12,16 @@ class AuthRequest extends RemoteAbstractRequest
{
protected $endpoint = 'https://epage.payandshop.com/epage-remote.cgi';

public function getCavv()
{
return $this->getParameter('cavv');
}

public function setCavv($value)
{
return $this->setParameter('cavv', $value);
}

public function getEci()
{
return $this->getParameter('eci');
}

public function setEci($value)
{
return $this->setParameter('eci', $value);
}

public function getXid()
{
return $this->getParameter('xid');
}

public function setXid($value)
{
return $this->setParameter('xid', $value);
Expand All @@ -52,17 +37,18 @@ public function getData()
$this->validate('amount', 'currency', 'transactionId');

// Create the hash
$timestamp = strftime("%Y%m%d%H%M%S");
$timestamp = strftime("%Y%m%d%H%M%S");
$merchantId = $this->getMerchantId();
$orderId = $this->getTransactionId();
$amount = $this->getAmountInteger();
$currency = $this->getCurrency();
$orderId = $this->getTransactionId();
$amount = $this->getAmountInteger();
$currency = $this->getCurrency();
$cardNumber = $this->getCard()->getNumber();
$secret = $this->getSecret();
$tmp = "$timestamp.$merchantId.$orderId.$amount.$currency.$cardNumber";
$sha1hash = sha1($tmp);
$tmp2 = "$sha1hash.$secret";
$sha1hash = sha1($tmp2);
$secret = $this->getSecret();
$tmp = "$timestamp.$merchantId.$orderId.$amount.$currency.$cardNumber";
$sha1hash = sha1($tmp);
$tmp2 = "$sha1hash.$secret";
$sha1hash = sha1($tmp2);


$domTree = new \DOMDocument('1.0', 'UTF-8');

Expand Down Expand Up @@ -93,6 +79,7 @@ public function getData()
* @var \Omnipay\Common\CreditCard $card
*/
$card = $this->getCard();
$this->setCode($card->getBillingPostcode(), $card->getBillingAddress1());

// Card details
$cardEl = $domTree->createElement('card');
Expand Down Expand Up @@ -129,10 +116,10 @@ public function getData()
$root->appendChild($settleEl);

// 3D Secure section
$mpiEl = $domTree->createElement('mpi');
$mpiEl = $domTree->createElement('mpi');
$cavvEl = $domTree->createElement('cavv', $this->getCavv());
$xidEl = $domTree->createElement('xid', $this->getXid());
$eciEl = $domTree->createElement('eci', $this->getEci());
$xidEl = $domTree->createElement('xid', $this->getXid());
$eciEl = $domTree->createElement('eci', $this->getEci());
$mpiEl->appendChild($cavvEl);
$mpiEl->appendChild($xidEl);
$mpiEl->appendChild($eciEl);
Expand All @@ -141,11 +128,13 @@ public function getData()
$sha1El = $domTree->createElement('sha1hash', $sha1hash);
$root->appendChild($sha1El);

$tssEl = $domTree->createElement('tssinfo');
$tssEl = $domTree->createElement('tssinfo');
$addressEl = $domTree->createElement('address');
$addressEl->setAttribute('type', 'billing');
$countryEl = $domTree->createElement('country', $card->getBillingCountry());
$countryEl = $domTree->createElement('country', $card->getBillingCountry());
$postcodeEl = $domTree->createElement('code', $this->getCode());
$addressEl->appendChild($countryEl);
$addressEl->appendChild($postcodeEl);
$tssEl->appendChild($addressEl);
$root->appendChild($tssEl);

Expand All @@ -154,13 +143,28 @@ public function getData()
return $xmlString;
}

protected function createResponse($data)
public function getCavv()
{
return $this->response = new AuthResponse($this, $data);
return $this->getParameter('cavv');
}

public function getXid()
{
return $this->getParameter('xid');
}

public function getEci()
{
return $this->getParameter('eci');
}

public function getEndpoint()
{
return $this->endpoint;
}

protected function createResponse($data)
{
return $this->response = new AuthResponse($this, $data);
}
}
65 changes: 43 additions & 22 deletions src/Omnipay/Realex/Message/RemoteAbstractRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,26 @@
abstract class RemoteAbstractRequest extends AbstractRequest
{
protected $cardBrandMap = array(
'mastercard' => 'mc',
'diners_club' => 'diners'
'mastercard' => 'mc',
'diners_club' => 'diners',
);

/**
* Override some of the default Omnipay card brand names
*
* @return mixed
*/
protected function getCardBrand()
public function getCode()
{
$brand = $this->getCard()->getBrand();
return $this->getParameter('code');
}

if (isset($this->cardBrandMap[$brand])) {
$brand = $this->cardBrandMap[$brand];
}
public function setCode($postcode, $billingAddressLine1)
{
$postcode = $this->stripNonNumeric($postcode);
$billingAddressLine1 = $this->stripNonNumeric($billingAddressLine1);

return strtoupper($brand);
return $this->setParameter('code', $postcode . '|' . $billingAddressLine1);
}

public function stripNonNumeric($value)
{
return preg_replace("/[^0-9]/", "", $value);
}

public function getMerchantId()
Expand Down Expand Up @@ -74,20 +76,39 @@ public function setReturnUrl($value)
public function sendData($data)
{
// register the payment
$this->httpClient->setConfig(
array(
'curl.options' => array(
'CURLOPT_SSLVERSION' => 1,
'CURLOPT_SSL_VERIFYPEER' => false
)
)
$headers = array(
'curl' => array(
CURLOPT_SSLVERSION => 1,
CURLOPT_SSL_VERIFYPEER => false,
),
);
$httpResponse = $this->httpClient->post($this->getEndpoint(), null, $data)->send();

return $this->createResponse($httpResponse->getBody(true));
if (is_array($data)) {
$data = http_build_query($data);
}

$httpResponse = $this->httpClient->request('POST', $this->getEndpoint(), $headers, $data);

return $this->createResponse($httpResponse->getBody()->getContents());
}

abstract public function getEndpoint();

abstract protected function createResponse($data);

/**
* Override some of the default Omnipay card brand names
*
* @return mixed
*/
protected function getCardBrand()
{
$brand = $this->getCard()->getBrand();

if (isset($this->cardBrandMap[ $brand ])) {
$brand = $this->cardBrandMap[ $brand ];
}

return strtoupper($brand);
}
}