-
Notifications
You must be signed in to change notification settings - Fork 3
/
dpmHandler.php
143 lines (121 loc) · 4.24 KB
/
dpmHandler.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
<?php
/**
* Isotope eCommerce for Contao Open Source CMS
*
* Copyright (C) 2009-2014 terminal42 gmbh & Isotope eCommerce Workgroup
*
* @package Isotope
* @link http://isotopeecommerce.org
* @license http://opensource.org/licenses/lgpl-3.0.html
*/
namespace HBAgency;
use Isotope\Model\Payment;
use Haste\Http\Response\Response;
/**
* Initialize the system
*/
define('TL_MODE', 'FE');
define('BYPASS_TOKEN_CHECK', true);
require '../../initialize.php';
//Import Auth.net SDK
require_once TL_ROOT . '/system/modules/isotope_authorizedotnet/vendor/anet_php_sdk/AuthorizeNet.php';
/**
* Class dpmHandler
*
* Handle Auth.net response
* @copyright HB Agency 2014
* @author Blair Winans <[email protected]>
* @author Adam Fisher <[email protected]>
*/
class dpmHandler extends \Frontend
{
/**
* Initialize the object (do not remove)
*/
public function __construct()
{
parent::__construct();
// Contao Hooks are not save to be run on the postsale script (e.g. parseFrontendTemplate)
unset($GLOBALS['TL_HOOKS']);
}
/**
* Run the controller
*/
public function run()
{
try
{
if( count($_POST) && \Input::post('iso_module_id') && \Input::post('iso_redirect_url'))
{
$objModule = Payment::findByPk(\Input::post('iso_module_id'));
$strUrl = html_entity_decode(\Input::post('iso_redirect_url'));
$strMD5Hash = \Encryption::decrypt($objModule->authorize_md5_hash);
$strLogin = \Encryption::decrypt($objModule->authorize_login);
$response = new \AuthorizeNetSIM( $strLogin, $strMD5Hash);
$strTransHash = $response->generateHash();
if ($response->isAuthorizeNet())
{
if ($response->approved)
{
// Do your processing here.
$redirect_url = $strUrl . '?response_code=1&transaction_id=' . $response->transaction_id . '&transaction_hash=' . urlencode($strTransHash);
$redirect_url .= '&card_type=' . $response->card_type; //Custom add card type
$redirect_url .= '&account_number=' . $response->account_number; //Custom add card last 4
}
else
{
// Redirect to error page.
$redirect_url = $strUrl . '?response_code='.$response->response_code . '&reason=' . $response->response_reason_text . '&reason_code=' . $response->response_reason_code;
}
}
else
{
$redirect_url = $strUrl . '?response_code='.$response->response_code . '&reason=' . $response->response_reason_text . '&reason_code=' . $response->response_reason_code;
}
// Send the Javascript back to AuthorizeNet, which will redirect user back to your site.
echo $this->getRelayResponseSnippet($redirect_url);
}
} catch (\Exception $e) {
\System::log(
sprintf('Exception in dpmHandler request in file "%s" on line "%s" with message "%s".',
$e->getFile(),
$e->getLine(),
$e->getMessage()
), __METHOD__, TL_ERROR);
$objResponse = new Response('Internal Server Error', 500);
$objResponse->send();
}
}
/**
* A snippet to send to AuthorizeNet to redirect the user back to the
* merchant's server. Use this on your relay response page.
*
* @param string $redirect_url Where to redirect the user.
*
* @return string
*/
protected function getRelayResponseSnippet($redirect_url)
{
$this->loadLanguageFile('default');
return "<html><head><script language=\"javascript\">
<!--
try
{
window.location=\"{$redirect_url}\";
}
catch (err)
{
alert('An error has occurred! ' + err.message);
}
//-->
</script>
</head><body>
<a href=\"{$redirect_url}\">" . $GLOBALS['ISO_LANG']['MSC']['authnet_dpm_msg'] . "</a>
</body></html>";
}
}
/**
* Instantiate controller
*/
$objDPM = new dpmHandler();
$objDPM->run();