33namespace Omnipay \AuthorizeNet \Message ;
44
55use 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