Skip to content

Commit

Permalink
Merge pull request #21 from slogsdon/add-auth-mobile
Browse files Browse the repository at this point in the history
add auth-mobile transaction type
  • Loading branch information
Andy Coates authored Dec 19, 2017
2 parents 4d1c5bf + 0b432c9 commit eb9d4c8
Show file tree
Hide file tree
Showing 3 changed files with 208 additions and 1 deletion.
123 changes: 123 additions & 0 deletions src/Omnipay/Realex/Message/AuthMobileRequest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
<?php

namespace Omnipay\Realex\Message;

use Omnipay\Common\Exception\InvalidRequestException;
use Omnipay\Common\Message\AbstractRequest;

/**
* Realex Auth-Mobile Request
*
* Example:
*
* ```
* $response = $gateway->purchase([
* 'mobileType' => 'apple-pay',
* // payload from mobile transaction
* // example below has been truncated and formatted
* 'token' => '{
* "version":"EC_v1",
* "data":"Ft+dvmdfgnsdfnbg+zerKtkh/RW[...]d/QAAAAAAAA==",
* "header": {
* "ephemeralPublicKey":"MFkwEwYHKoZIzj0CA[...]Z+telY/G1+YSoaCbR57bdGA==",
* "transactionId":"fd88874954acdb29976g[....]G3fd4ebc22a864398684198644c3",
* "publicKeyHash":"h7njghUJVz2gmpTSkHqETOWsskhsdfjj4mgf3sPTS2cBxgrk="
* }
* }',
* ])->send();
* ```
*/
class AuthMobileRequest extends RemoteAbstractRequest
{
protected $endpoint = 'https://epage.payandshop.com/epage-remote.cgi';

public function getMobileType()
{
return $this->getParameter('mobileType');
}

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

public function getToken()
{
return $this->getParameter('token');
}

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

/**
* Get the XML registration string to be sent to the gateway
*
* @return string
*/
public function getData()
{
$this->validate('mobileType', 'token', 'transactionId');

// Create the hash
$timestamp = strftime("%Y%m%d%H%M%S");
$merchantId = $this->getMerchantId();
$orderId = $this->getTransactionId();
$token = $this->getToken();
$secret = $this->getSecret();
$tmp = "$timestamp.$merchantId.$orderId...$token";
$sha1hash = sha1($tmp);
$tmp2 = "$sha1hash.$secret";
$sha1hash = sha1($tmp2);

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

// root element
$root = $domTree->createElement('request');
$root->setAttribute('type', 'auth-mobile');
$root->setAttribute('timestamp', $timestamp);
$root = $domTree->appendChild($root);

// merchant ID
$merchantEl = $domTree->createElement('merchantid', $merchantId);
$root->appendChild($merchantEl);

// account
$merchantEl = $domTree->createElement('account', $this->getAccount());
$root->appendChild($merchantEl);

// order ID
$merchantEl = $domTree->createElement('orderid', $orderId);
$root->appendChild($merchantEl);

$settleEl = $domTree->createElement('autosettle');
$settleEl->setAttribute('flag', 1);
$root->appendChild($settleEl);

$mobileEl = $domTree->createElement('mobile', $this->getMobileType());
$root->appendChild($mobileEl);

$tokenEl = $domTree->createElement('token', $token);
$root->appendChild($tokenEl);

// TODO: add comments

$sha1El = $domTree->createElement('sha1hash', $sha1hash);
$root->appendChild($sha1El);

$xmlString = $domTree->saveXML($root);

return $xmlString;
}

protected function createResponse($data)
{
return $this->response = new AuthMobileResponse($this, $data);
}

public function getEndpoint()
{
return $this->endpoint;
}
}
82 changes: 82 additions & 0 deletions src/Omnipay/Realex/Message/AuthMobileResponse.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
<?php

namespace Omnipay\Realex\Message;

use Omnipay\Common\Exception\InvalidRequestException;
use Omnipay\Common\Exception\InvalidResponseException;
use Omnipay\Common\Message\AbstractResponse;
use Omnipay\Common\Message\RedirectResponseInterface;

/**
* Realex Auth-Mobile Response
*/
class AuthMobileResponse extends RemoteAbstractResponse implements RedirectResponseInterface
{
public function isSuccessful()
{
return ($this->xml->result == '00');
}

public function isDecline()
{
return (substr($this->xml->result, 0, 1) == '1');
}

public function isBankSystemError()
{
return (substr($this->xml->result, 0, 1) == '2');
}

public function isRealexSystemError()
{
return (substr($this->xml->result, 0, 1) == '3');
}

public function getMessage()
{
return (string)$this->xml->message;
}

public function getTransactionId()
{
return ($this->xml->orderid) ? (string)$this->xml->orderid : null;
}

public function getTransactionReference()
{
return ($this->xml->pasref) ? (string)$this->xml->pasref : null;
}

public function getAuthCode()
{
return ($this->xml->authcode) ? (string)$this->xml->authcode : null;
}

public function getBatchId()
{
return ($this->xml->batchid) ? (string)$this->xml->batchid : null;
}

public function isRedirect()
{
return false;
}

public function getRedirectMethod()
{
return 'GET';
}

public function getRedirectData()
{
return null;
}

/**
* Gets the redirect target url.
*/
public function getRedirectUrl()
{
return '';
}
}
4 changes: 3 additions & 1 deletion src/Omnipay/Realex/RemoteGateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,9 @@ public function set3dSecure($value)

public function purchase(array $parameters = array())
{
if (array_key_exists('cardReference', $parameters)) {
if (array_key_exists('mobileType', $parameters)) {
return $this->createRequest('\Omnipay\Realex\Message\AuthMobileRequest', $parameters);
} elseif (array_key_exists('cardReference', $parameters)) {
return $this->createRequest('\Omnipay\Realex\Message\SavedAuthRequest', $parameters);
} elseif ($this->get3dSecure()) {
return $this->createRequest('\Omnipay\Realex\Message\EnrolmentRequest', $parameters);
Expand Down

0 comments on commit eb9d4c8

Please sign in to comment.