-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #21 from slogsdon/add-auth-mobile
add auth-mobile transaction type
- Loading branch information
Showing
3 changed files
with
208 additions
and
1 deletion.
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
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; | ||
} | ||
} |
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,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 ''; | ||
} | ||
} |
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