Skip to content

Commit

Permalink
Merge pull request #147 from ruudk/multisafepay-fix
Browse files Browse the repository at this point in the history
MultiSafepay: Fixed wrong gateway node and added support for direct transactions
  • Loading branch information
amacneil committed Oct 18, 2013
2 parents 77de4bc + 69838b7 commit e73f6ee
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 22 deletions.
19 changes: 12 additions & 7 deletions src/Omnipay/MultiSafepay/Message/PurchaseRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,12 @@ public function getData()
{
$this->validate('transactionId', 'amount', 'currency', 'description', 'clientIp', 'card');

$data = new SimpleXMLElement('<?xml version="1.0" encoding="UTF-8"?><redirecttransaction/>');
if ('IDEAL' === $this->getGateway() && $this->getIssuer()) {
$data = new SimpleXMLElement('<?xml version="1.0" encoding="UTF-8"?><directtransaction/>');
} else {
$data = new SimpleXMLElement('<?xml version="1.0" encoding="UTF-8"?><redirecttransaction/>');
}

$data->addAttribute('ua', $this->userAgent);

$merchant = $data->addChild('merchant');
Expand All @@ -104,12 +109,6 @@ public function getData()
$merchant->addChild('notification_url', htmlspecialchars($this->getNotifyUrl()));
$merchant->addChild('cancel_url', htmlspecialchars($this->getCancelUrl()));
$merchant->addChild('redirect_url', htmlspecialchars($this->getReturnUrl()));
$merchant->addChild('gateway', $this->getGateway());

if ('IDEAL' === $this->getGateway() && $this->getIssuer()) {
$gatewayInfo = $data->addChild('gatewayinfo');
$gatewayInfo->addChild('issuerid', $this->getIssuer());
}

/** @var CreditCard $card */
$card = $this->getCard();
Expand Down Expand Up @@ -137,6 +136,12 @@ public function getData()
$transaction->addChild('var2', $this->getExtraData2());
$transaction->addChild('var3', $this->getExtraData3());
$transaction->addChild('items', $this->getItems());
$transaction->addChild('gateway', $this->getGateway());

if ('IDEAL' === $this->getGateway() && $this->getIssuer()) {
$gatewayInfo = $data->addChild('gatewayinfo');
$gatewayInfo->addChild('issuerid', $this->getIssuer());
}

$data->addChild('signature', $this->generateSignature());

Expand Down
10 changes: 8 additions & 2 deletions src/Omnipay/MultiSafepay/Message/PurchaseResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,21 @@ public function isSuccessful()
*/
public function isRedirect()
{
return isset($this->data->transaction->payment_url);
return isset($this->data->transaction->payment_url) || isset($this->data->gatewayinfo->redirecturl);
}

/**
* {@inheritdoc}
*/
public function getRedirectUrl()
{
return $this->isRedirect() ? (string) $this->data->transaction->payment_url : null;
if (isset($this->data->gatewayinfo->redirecturl)) {
return (string) $this->data->gatewayinfo->redirecturl;
} elseif (isset($this->data->transaction->payment_url)) {
return (string) $this->data->transaction->payment_url;
}

return null;
}

/**
Expand Down
26 changes: 13 additions & 13 deletions tests/Omnipay/MultiSafepay/Message/PurchaseRequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,19 +134,15 @@ public function allDataProvider()
{
$xml = <<<EOF
<?xml version="1.0" encoding="UTF-8"?>
<redirecttransaction ua="Omnipay">
<directtransaction ua="Omnipay">
<merchant>
<account>111111</account>
<site_id>222222</site_id>
<site_secure_code>333333</site_secure_code>
<notification_url>http://localhost/notify</notification_url>
<cancel_url>http://localhost/cancel</cancel_url>
<redirect_url>http://localhost/return</redirect_url>
<gateway>IDEAL</gateway>
</merchant>
<gatewayinfo>
<issuerid>issuer</issuerid>
</gatewayinfo>
<customer>
<ipaddress>127.0.0.1</ipaddress>
<locale>a language</locale>
Expand All @@ -170,9 +166,13 @@ public function allDataProvider()
<var2>extra 2</var2>
<var3>extra 3</var3>
<items>the items</items>
<gateway>IDEAL</gateway>
</transaction>
<gatewayinfo>
<issuerid>issuer</issuerid>
</gatewayinfo>
<signature>ad447bab87b8597853432c891e341db1</signature>
</redirecttransaction>
</directtransaction>
EOF;

Expand All @@ -193,7 +193,6 @@ public function noIssuerDataProvider()
<notification_url>http://localhost/notify</notification_url>
<cancel_url>http://localhost/cancel</cancel_url>
<redirect_url>http://localhost/return</redirect_url>
<gateway>another</gateway>
</merchant>
<customer>
<ipaddress>127.0.0.1</ipaddress>
Expand All @@ -218,6 +217,7 @@ public function noIssuerDataProvider()
<var2>extra 2</var2>
<var3>extra 3</var3>
<items>the items</items>
<gateway>another</gateway>
</transaction>
<signature>ad447bab87b8597853432c891e341db1</signature>
</redirecttransaction>
Expand All @@ -233,19 +233,15 @@ public function specialCharsDataProvider()
{
$xml = <<<EOF
<?xml version="1.0" encoding="UTF-8"?>
<redirecttransaction ua="Omnipay">
<directtransaction ua="Omnipay">
<merchant>
<account>111111</account>
<site_id>222222</site_id>
<site_secure_code>333333</site_secure_code>
<notification_url>http://localhost/?one=1&amp;two=2</notification_url>
<cancel_url>http://localhost/?one=1&amp;two=2</cancel_url>
<redirect_url>http://localhost/?one=1&amp;two=2</redirect_url>
<gateway>IDEAL</gateway>
</merchant>
<gatewayinfo>
<issuerid>issuer</issuerid>
</gatewayinfo>
<customer>
<ipaddress>127.0.0.1</ipaddress>
<locale>a language</locale>
Expand All @@ -269,9 +265,13 @@ public function specialCharsDataProvider()
<var2>extra 2</var2>
<var3>extra 3</var3>
<items>the items</items>
<gateway>IDEAL</gateway>
</transaction>
<gatewayinfo>
<issuerid>issuer</issuerid>
</gatewayinfo>
<signature>ad447bab87b8597853432c891e341db1</signature>
</redirecttransaction>
</directtransaction>
EOF;

Expand Down

0 comments on commit e73f6ee

Please sign in to comment.