Skip to content

Commit 56e1cec

Browse files
committed
Issue thephpleague#22 and Issue thephpleague#16 implementation
1 parent 152959c commit 56e1cec

File tree

2 files changed

+76
-4
lines changed

2 files changed

+76
-4
lines changed

src/Message/SIMAuthorizeRequest.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,13 @@ class SIMAuthorizeRequest extends AbstractRequest
1111

1212
public function getData()
1313
{
14-
$this->validate('amount', 'returnUrl');
14+
$this->validate('amount');
15+
16+
// Either the nodifyUrl or the returnUrl can be provided.
17+
// The returnUrl is deprecated, as strictly this is a notifyUrl.
18+
if (!$this->getNotifyUrl()) {
19+
$this->validate('returnUrl');
20+
}
1521

1622
$data = array();
1723
$data['x_login'] = $this->getApiLoginId();
@@ -30,7 +36,9 @@ public function getData()
3036

3137
// The returnUrl MUST be whitelisted in Authorize.net admin panel under
3238
// "Response/Receipt URLs".
33-
$data['x_relay_url'] = $this->getReturnUrl();
39+
// Use the notifyUrl if available, as that is strictly what this is.
40+
// Fall back to returnUrl for BC support.
41+
$data['x_relay_url'] = $this->getNotifyUrl() ?: $this->getReturnUrl();
3442
$data['x_cancel_url'] = $this->getCancelUrl();
3543

3644
if ($this->getCustomerId() !== null) {

src/Message/SIMCompleteAuthorizeResponse.php

Lines changed: 66 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@
33
namespace Omnipay\AuthorizeNet\Message;
44

55
use Omnipay\Common\Message\AbstractResponse;
6+
use Omnipay\Common\Message\RedirectResponseInterface;
7+
use Symfony\Component\HttpFoundation\Response as HttpResponse;
68

79
/**
810
* Authorize.Net SIM Complete Authorize Response
911
*/
10-
class SIMCompleteAuthorizeResponse extends AbstractResponse
12+
class SIMCompleteAuthorizeResponse extends AbstractResponse implements RedirectResponseInterface
1113
{
1214
// Response codes returned by Authorize.Net
1315

@@ -18,7 +20,7 @@ class SIMCompleteAuthorizeResponse extends AbstractResponse
1820

1921
public function isSuccessful()
2022
{
21-
return isset($this->data['x_response_code']) && static::RESPONSE_CODE_APPROVED === $this->data['x_response_code'];
23+
return static::RESPONSE_CODE_APPROVED === $this->getCode();
2224
}
2325

2426
public function getTransactionReference()
@@ -40,4 +42,66 @@ public function getCode()
4042
{
4143
return isset($this->data['x_response_code']) ? $this->data['x_response_code'] : null;
4244
}
45+
46+
/**
47+
* This message is handled in a notify, where a HTML redirect must be performed.
48+
*/
49+
public function isRedirect()
50+
{
51+
return true;
52+
}
53+
54+
/**
55+
* The merchant site notify handler needs to set the returnUrl in the complete request.
56+
*/
57+
public function getRedirectUrl()
58+
{
59+
return $this->request->getReturnUrl();
60+
}
61+
62+
public function getRedirectMethod()
63+
{
64+
return 'GET';
65+
}
66+
67+
/**
68+
* There is no redirect data to send; the aim is just to get the user to a URL
69+
* by delivering a HTML page.
70+
*/
71+
public function getRedirectData()
72+
{
73+
return array();
74+
}
75+
76+
/**
77+
* Authorize.Net requires a redirect in a HTML page.
78+
* The OmniPay redirect helper will only provide a HTML page for the POST method
79+
* and then implements that through a self-sbmitting form. This will generate
80+
* browser warnings if returning to a non-SSL page.
81+
*/
82+
public function getRedirectResponse()
83+
{
84+
$output = <<<ENDHTML
85+
<!DOCTYPE html>
86+
<html>
87+
<head>
88+
<title>Redirecting...</title>
89+
<meta http-equiv="refresh" content="0;url=%1\$s" />
90+
</head>
91+
<body>
92+
<p>Redirecting to <a href="%1\$s">payment complete page</a>...</p>
93+
<script type="text/javascript" charset="utf-8">
94+
window.location="%1\$s";
95+
</script>
96+
</body>
97+
</html>
98+
ENDHTML;
99+
100+
$output = sprintf(
101+
$output,
102+
htmlentities($this->getRedirectUrl(), ENT_QUOTES, 'UTF-8', false)
103+
);
104+
105+
return HttpResponse::create($output);
106+
}
43107
}

0 commit comments

Comments
 (0)