Trustly - Version 2.0.2

Version Notes

Download this release

Release Info

Developer Trustly
Extension Trustly
Version 2.0.2
Comparing to
See all releases


Version 2.0.2

Files changed (42) hide show
  1. app/code/local/Trustly/Trustly/Block/Form.php +23 -0
  2. app/code/local/Trustly/Trustly/Block/Redirect.php +16 -0
  3. app/code/local/Trustly/Trustly/Block/System/Config/About.php +14 -0
  4. app/code/local/Trustly/Trustly/Helper/Data.php +179 -0
  5. app/code/local/Trustly/Trustly/Model/Mysql4/Ordermappings.php +16 -0
  6. app/code/local/Trustly/Trustly/Model/Ordermappings.php +14 -0
  7. app/code/local/Trustly/Trustly/Model/Standard.php +250 -0
  8. app/code/local/Trustly/Trustly/controllers/PaymentController.php +507 -0
  9. app/code/local/Trustly/Trustly/etc/config.xml +115 -0
  10. app/code/local/Trustly/Trustly/etc/system.xml +144 -0
  11. app/code/local/Trustly/Trustly/lib/Trustly.php +15 -0
  12. app/code/local/Trustly/Trustly/lib/Trustly/Api/api.php +251 -0
  13. app/code/local/Trustly/Trustly/lib/Trustly/Api/ecommerce.php +146 -0
  14. app/code/local/Trustly/Trustly/lib/Trustly/Api/keys/test.trustly.com.public.pem +9 -0
  15. app/code/local/Trustly/Trustly/lib/Trustly/Api/keys/trustly.com.public.pem +9 -0
  16. app/code/local/Trustly/Trustly/lib/Trustly/Api/signed.php +372 -0
  17. app/code/local/Trustly/Trustly/lib/Trustly/Api/unsigned.php +115 -0
  18. app/code/local/Trustly/Trustly/lib/Trustly/Data/data.php +109 -0
  19. app/code/local/Trustly/Trustly/lib/Trustly/Data/jsonrpcnotificationrequest.php +65 -0
  20. app/code/local/Trustly/Trustly/lib/Trustly/Data/jsonrpcnotificationresponse.php +104 -0
  21. app/code/local/Trustly/Trustly/lib/Trustly/Data/jsonrpcrequest.php +127 -0
  22. app/code/local/Trustly/Trustly/lib/Trustly/Data/jsonrpcresponse.php +50 -0
  23. app/code/local/Trustly/Trustly/lib/Trustly/Data/request.php +34 -0
  24. app/code/local/Trustly/Trustly/lib/Trustly/Data/response.php +109 -0
  25. app/code/local/Trustly/Trustly/lib/Trustly/exceptions.php +23 -0
  26. app/code/local/Trustly/Trustly/sql/trustly_setup/install-2.0.0.php +22 -0
  27. app/code/local/Trustly/Trustly/sql/trustly_setup/upgrade-1.0.4-2.0.0.php +21 -0
  28. app/design/frontend/base/default/layout/trustly.xml +10 -0
  29. app/design/frontend/base/default/template/trustly/form.phtml +8 -0
  30. app/design/frontend/base/default/template/trustly/iframe.phtml +14 -0
  31. app/design/frontend/base/default/template/trustly/mark.phtml +5 -0
  32. app/etc/modules/Trustly_Trustly.xml +12 -0
  33. app/locale/da_DK/Trustly_Trustly.csv +34 -0
  34. app/locale/en_US/Trustly_Trustly.csv +34 -0
  35. app/locale/es_ES/Trustly_Trustly.csv +34 -0
  36. app/locale/et_EE/Trustly_Trustly.csv +34 -0
  37. app/locale/fi_FI/Trustly_Trustly.csv +34 -0
  38. app/locale/pl_PL/Trustly_Trustly.csv +34 -0
  39. app/locale/sv_SE/Trustly_Trustly.csv +34 -0
  40. package.xml +178 -0
  41. skin/frontend/default/default/images/trustly-big.png +0 -0
  42. skin/frontend/default/default/images/trustly-small.png +0 -0
app/code/local/Trustly/Trustly/Block/Form.php ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * information at checkout within the payment method
5
+ */
6
+ class Trustly_Trustly_Block_Form extends Mage_Payment_Block_Form
7
+ {
8
+
9
+ protected function _construct()
10
+ {
11
+ $locale = Mage::app()->getLocale();
12
+ $mark = Mage::getConfig()->getBlockClassName('core/template');
13
+ $mark = new $mark;
14
+ $mark->setTemplate('trustly/mark.phtml')
15
+ ->setPaymentAcceptanceMarkHref('https://trustly.com/whatistrustly/');
16
+ $this->setTemplate('trustly/form.phtml')
17
+ ->setMethodTitle('')
18
+ ->setMethodLabelAfterHtml($mark->toHtml())
19
+ ;
20
+ return parent::_construct();
21
+ }
22
+
23
+ }
app/code/local/Trustly/Trustly/Block/Redirect.php ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Trustly_Trustly_Block_Redirect extends Mage_Core_Block_Template
4
+ {
5
+ public function getIframe()
6
+ {
7
+ $session = Mage::getSingleton('checkout/session');
8
+ $url = $session->getUrlTrustly();
9
+
10
+ if (!isset($url) || empty($url)) {
11
+ return false;
12
+ } else {
13
+ return $url;
14
+ }
15
+ }
16
+ }
app/code/local/Trustly/Trustly/Block/System/Config/About.php ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Trustly_Trustly_Block_System_Config_About extends Mage_Adminhtml_Block_Abstract implements Varien_Data_Form_Element_Renderer_Interface
4
+ {
5
+
6
+ public function render(Varien_Data_Form_Element_Abstract $element)
7
+ {
8
+ $html = '<div style="margin-bottom:10px; padding:10px 5px 5px 10px; height: 400px; ">
9
+ <div><iframe src="https://trustly.com/magentosignup" style="width: 100%; height: 400px; border: 1px solid #D6D6D6;"></iframe></div>
10
+ </div>';
11
+
12
+ return $html;
13
+ }
14
+ }
app/code/local/Trustly/Trustly/Helper/Data.php ADDED
@@ -0,0 +1,179 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ require_once (Mage::getModuleDir('', 'Trustly_Trustly') . DS . 'lib' . DS .'Trustly.php');
4
+
5
+ /**
6
+ *
7
+ */
8
+ class Trustly_Trustly_Helper_Data extends Mage_Core_Helper_Abstract
9
+ {
10
+ private $trustlyAPI = NULL;
11
+
12
+ public function __construct(){
13
+ }
14
+
15
+
16
+ public function getTrustlyAPIHost()
17
+ {
18
+ if($this->getTrustlyIsLive()) {
19
+ return 'trustly.com';
20
+ }else{
21
+ return 'test.trustly.com';
22
+ }
23
+ }
24
+
25
+
26
+ public function getTrustlyIsLive()
27
+ {
28
+ if (Mage::getStoreConfigFlag('payment/trustly/urltrustly') == '1') {
29
+ return TRUE;
30
+ }else{
31
+ return FALSE;
32
+ }
33
+ }
34
+
35
+ public function getTrustlySecureNotifications()
36
+ {
37
+ if (Mage::getStoreConfigFlag('payment/trustly/httpnotifications') == '1') {
38
+ return FALSE;
39
+ }else{
40
+ return TRUE;
41
+ }
42
+ }
43
+
44
+
45
+ private function internalIPAdress($ip)
46
+ {
47
+
48
+ if (!empty($ip) && ip2long($ip)!=-1) {
49
+ $reserved_ips = array (
50
+ array('0.0.0.0','2.255.255.255'),
51
+ array('10.0.0.0','10.255.255.255'),
52
+ array('127.0.0.0','127.255.255.255'),
53
+ array('169.254.0.0','169.254.255.255'),
54
+ array('172.16.0.0','172.31.255.255'),
55
+ array('192.0.2.0','192.0.2.255'),
56
+ array('192.168.0.0','192.168.255.255'),
57
+ array('255.255.255.0','255.255.255.255')
58
+ );
59
+
60
+ foreach ($reserved_ips as $r) {
61
+ $min = ip2long($r[0]);
62
+ $max = ip2long($r[1]);
63
+ if ((ip2long($ip) >= $min) && (ip2long($ip) <= $max)) {
64
+ return true;
65
+ }
66
+ }
67
+
68
+ return false;
69
+ } else {
70
+ return true;
71
+ }
72
+ }
73
+
74
+
75
+ public function getCustomerIp()
76
+ {
77
+
78
+ if (!$this->internalIPAdress(@$_SERVER["HTTP_CLIENT_IP"])) {
79
+ return $_SERVER["HTTP_CLIENT_IP"];
80
+ }
81
+
82
+ foreach (explode(",",@$_SERVER["HTTP_X_FORWARDED_FOR"]) as $ip) {
83
+ if (!$this->internalIPAdress(trim($ip))) {
84
+ return $ip;
85
+ }
86
+ }
87
+
88
+ if (!$this->internalIPAdress(@$_SERVER["HTTP_X_FORWARDED"])) {
89
+ return $_SERVER["HTTP_X_FORWARDED"];
90
+ } elseif (!$this->internalIPAdress(@$_SERVER["HTTP_FORWARDED_FOR"])) {
91
+ return $_SERVER["HTTP_FORWARDED_FOR"];
92
+ } elseif (!$this->internalIPAdress(@$_SERVER["HTTP_FORWARDED"])) {
93
+ return $_SERVER["HTTP_FORWARDED"];
94
+ } elseif (!$this->internalIPAdress(@$_SERVER["HTTP_X_FORWARDED"])) {
95
+ return $_SERVER["HTTP_X_FORWARDED"];
96
+ } else {
97
+ return $_SERVER["REMOTE_ADDR"];
98
+ }
99
+ }
100
+
101
+
102
+ public function getModuleDir()
103
+ {
104
+ return Mage::getModuleDir('', 'Trustly_Trustly');
105
+ }
106
+
107
+
108
+ public function getErrorMsg ($message, $number)
109
+ {
110
+ return $message . " (" . $number . ")";
111
+ }
112
+
113
+
114
+ public function getTrustlyAPI()
115
+ {
116
+ if(!isset($this->trustlyAPI)) {
117
+ if($this->getTrustlyUsername() && $this->getTrustlyPassword() &&
118
+ $this->getTrustlyPrivateKey()) {
119
+
120
+ $this->trustlyAPI = new Trustly_Api_Signed(
121
+ NULL,
122
+ $this->getTrustlyUsername(),
123
+ $this->getTrustlyPassword(),
124
+ $this->getTrustlyAPIHost(),
125
+ 443,
126
+ true);
127
+ $this->trustlyAPI->useMerchantPrivateKey($this->getTrustlyPrivateKey());
128
+ }
129
+ }
130
+ return $this->trustlyAPI;
131
+ }
132
+
133
+
134
+ public function getTrustlyPrivateKey()
135
+ {
136
+ if($this->getTrustlyIsLive()) {
137
+ return Mage::getModel('trustly/standard')->getConfigData('merchantkey');
138
+ } else {
139
+ return Mage::getModel('trustly/standard')->getConfigData('merchantkeytest');
140
+ }
141
+ }
142
+
143
+
144
+ public function getTrustlyUsername()
145
+ {
146
+ if($this->getTrustlyIsLive()) {
147
+ return Mage::getModel('trustly/standard')->getConfigData('merchantusername');
148
+ } else {
149
+ return Mage::getModel('trustly/standard')->getConfigData('merchantusernametest');
150
+ }
151
+ }
152
+
153
+
154
+ public function getTrustlyPassword()
155
+ {
156
+ if($this->getTrustlyIsLive()) {
157
+ return Mage::getModel('trustly/standard')->getConfigData('merchantpassword');
158
+ } else {
159
+ return Mage::getModel('trustly/standard')->getConfigData('merchantpasswordtest');
160
+ }
161
+ }
162
+
163
+
164
+ public function sendResponseNotification($notification, $success)
165
+ {
166
+ $api = $this->getTrustlyAPI();
167
+
168
+ $response = $api->notificationResponse($notification, $success);
169
+ header('Cache-Control: no-cache, must-revalidate');
170
+ header('Content-type: application/json');
171
+ echo $response->json();
172
+ }
173
+
174
+
175
+ public function getExtensionVersion()
176
+ {
177
+ return (string) Mage::getConfig()->getNode()->modules->Trustly_Trustly->version;
178
+ }
179
+ }
app/code/local/Trustly/Trustly/Model/Mysql4/Ordermappings.php ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Trustly_Trustly_Model_Mysql4_Ordermappings extends Mage_Core_Model_Mysql4_Abstract{
3
+
4
+ protected function _construct()
5
+ {
6
+ # This is a bit silly, I would ragther here use the
7
+ # truslty_order_id as the primary key for this table, but as magento
8
+ # will promptly do an update rather then an insert if the primary key
9
+ # for the table is set (as it will be when we insert new records) i
10
+ # need to invent a dummy id that is generated and never used. It also
11
+ # borks the ->load method as useless for me. Thank you for this
12
+ # abstraction...
13
+ $this->_init('trustly/ordermappings', 'id');
14
+ }
15
+ }
16
+ ?>
app/code/local/Trustly/Trustly/Model/Ordermappings.php ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Trustly_Trustly_Model_Ordermappings extends Mage_Core_Model_Abstract
3
+ {
4
+ protected function _construct()
5
+ {
6
+ $this->_init('trustly/ordermappings');
7
+ }
8
+
9
+ public function loadByTrustlyOrderId($trustlyOrderId)
10
+ {
11
+ return $this->load($trustlyOrderId, 'trustly_order_id');
12
+ }
13
+ }
14
+ ?>
app/code/local/Trustly/Trustly/Model/Standard.php ADDED
@@ -0,0 +1,250 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+
4
+ class Trustly_Trustly_Model_Standard extends Mage_Payment_Model_Method_Abstract
5
+ {
6
+ const LOG_FILE = 'trustly.log';
7
+
8
+ /**
9
+ * unique internal payment method identifier
10
+ *
11
+ * @var string [a-z0-9_]
12
+ */
13
+
14
+ protected $_code = 'trustly';
15
+
16
+ /**
17
+ * Is this payment method a gateway (online auth/charge) ?
18
+ */
19
+ protected $_isGateway = true;
20
+
21
+ /**
22
+ * Can authorize online?
23
+ */
24
+ protected $_canAuthorize = true;
25
+
26
+ /**
27
+ * Can capture funds online?
28
+ */
29
+ protected $_canCapture = true;
30
+
31
+ /**
32
+ * Can capture partial amounts online?
33
+ */
34
+ protected $_canCapturePartial = true;
35
+
36
+ /**
37
+ * Can refund online?
38
+ */
39
+ protected $_canRefund = true;
40
+
41
+ /**
42
+ * Can void transactions online?
43
+ */
44
+ protected $_canVoid = true;
45
+
46
+ /**
47
+ * Can use this payment method in administration panel?
48
+ */
49
+ protected $_canUseInternal = true;
50
+
51
+ /**
52
+ * Can show this payment method as an option on checkout payment page?
53
+ */
54
+ protected $_canUseCheckout = true;
55
+
56
+ /**
57
+ * Is this payment method suitable for multi-shipping checkout?
58
+ */
59
+ protected $_canUseForMultishipping = false;
60
+
61
+ /**
62
+ * Can save credit card information for future processing?
63
+ */
64
+ protected $_canSaveCc = false;
65
+
66
+ protected $_formBlockType = 'trustly/form';
67
+
68
+
69
+ const PAYMENT_TYPE_AUTH = 'AUTHORIZATION';
70
+ const PAYMENT_TYPE_SALE = 'SALE';
71
+ const CODE_REFUND = '3';
72
+
73
+
74
+
75
+ public function authorize(varien_object $payment, $amount)
76
+ {
77
+ }
78
+
79
+
80
+ public function capture (Varien_Object $payment, $amount)
81
+ {
82
+ }
83
+
84
+
85
+ /**
86
+ * Get session namespace
87
+ */
88
+ public function getSession()
89
+ {
90
+ return Mage::getSingleton('trustly/session');
91
+ }
92
+
93
+
94
+ /**
95
+ * Get checkout namespace
96
+ */
97
+ public function getCheckout()
98
+ {
99
+ return Mage::getSingleton('checkout/session');
100
+ }
101
+
102
+
103
+ /**
104
+ * Get actual quote
105
+ */
106
+ public function getQuote()
107
+ {
108
+ return $this->getCheckout()->getQuote();
109
+ }
110
+
111
+
112
+ public function getOrderPlaceRedirectUrl()
113
+ {
114
+ return Mage::getUrl('trustly/payment/redirect', array('_secure' => true));
115
+ }
116
+
117
+
118
+ private function _getOrderLines($api, $order)
119
+ {
120
+ $orderlines = array();
121
+ foreach ($order->getAllItems() as $item) {
122
+ if (!$item->getParentItem()) {
123
+ /* The EAN code here is really not standard and there is no
124
+ * standard field. But if present (with the guessed name) we will
125
+ * get it and fetching a non-existant one will not blow up, simply return null. */
126
+ $orderline = $api->createOrderline(
127
+ $item->getName(),
128
+ $item->getPrice(),
129
+ $order->getBaseCurrencyCode(),
130
+ $item->getBaseTaxAmount(),
131
+ $item->getQtyOrdered(),
132
+ $item->getEan());
133
+ $orderlines[] = $orderline;
134
+ }
135
+ }
136
+
137
+ return $orderlines;
138
+ }
139
+
140
+
141
+ public function redirectProcess()
142
+ {
143
+ Mage::log("redirectProcess()", Zend_Log::DEBUG, self::LOG_FILE);
144
+ $api = Mage::helper('trustly')->getTrustlyAPI();
145
+
146
+ if(!isset($api)) {
147
+ Mage::log("Attempting to process a payment, but the Trustly module is not properly configured yet", Zend_Log::ERR, self::LOG_FILE);
148
+ Mage::getSingleton('core/session')->addError(Mage::helper('trustly')->__('Trustly payment module has not been configured.'));
149
+ return false;
150
+ }
151
+
152
+ $orderId = $this->getCheckout()->getLastRealOrderId();
153
+ $order = Mage::getModel('sales/order')->loadByIncrementId($orderId);
154
+
155
+ $session = Mage::getSingleton('checkout/session');
156
+
157
+ $notificationUrl = Mage::getUrl('trustly/payment/update');
158
+
159
+ $endUserId = strtolower($order->getCustomerEmail());
160
+
161
+ $messageId = $order->getRealOrderId();
162
+
163
+ $billingAddress = $order->getBillingAddress();
164
+ $shippingAddress = $order->getShippingAddress();
165
+
166
+ $telephone = $billingAddress->getTelephone();
167
+ if(!$telephone) {
168
+ $telephone = $shippingAddress->getTelephone();
169
+ }
170
+
171
+ // Country is is the ISO 3166-1 country codes
172
+ $countryId = $billingAddress->getCountryId();
173
+ if(!$countryId) {
174
+ $countryId = $shippingAddress->getCountryId();
175
+ }
176
+
177
+ $versionString = sprintf("Magento %s/%s %s",
178
+ Mage::getVersion(), Mage::app()->getFrontController()->getRequest()->getModuleName(),
179
+ Mage::helper('trustly')->getExtensionVersion());
180
+
181
+ $successurl = Mage::getUrl('trustly/payment/success');
182
+ $failurl = Mage::getUrl('trustly/payment/fail');
183
+
184
+ $response = $api->deposit(
185
+ $notificationUrl,
186
+ $endUserId,
187
+ $messageId,
188
+ Mage::app()->getLocale()->getLocaleCode(),
189
+ number_format($order->getBaseGrandTotal() ,2 ,"." ,""),
190
+ $order->getBaseCurrencyCode(),
191
+ $countryId,
192
+ $billingAddress->getTelephone(),
193
+ $order->getCustomerFirstname(),
194
+ $order->getCustomerLastname(),
195
+ NULL, //NationalIdentificationNumber
196
+ $order->getStore()->getWebsite()->getName(),
197
+ Mage::helper('trustly')->getCustomerIp(),
198
+ $successurl,
199
+ $failurl,
200
+ NULL, //TemplateURL
201
+ '_top',
202
+ NULL, //SuggestedMinAmount
203
+ NULL, //SuggestedMaxAmount
204
+ $versionString
205
+ );
206
+
207
+ if (!isset($response)) {
208
+ Mage::log("Could not connect to Trustly (no response)", Zend_Log::WARN, self::LOG_FILE);
209
+ Mage::getSingleton('core/session')->addError(Mage::helper('trustly')->__('Could not connect to Trustly.'));
210
+ return false;
211
+ } elseif (isset($response) && $response->isSuccess()) {
212
+ $url = $response->getData('url');
213
+ $trustlyOrderId = $response->getData('orderid');
214
+
215
+ Mage::log("Got response with orderid $trustlyOrderId from Trustly, redirecting user to url: $url", Zend_Log::DEBUG, self::LOG_FILE);
216
+
217
+ Mage::getSingleton('checkout/session')->setData('orderid_trustly', $trustlyOrderId);
218
+
219
+ $incrementId = $order->getIncrementId();
220
+ $orderMapping = Mage::getModel('trustly/ordermappings');
221
+ $omData = array(
222
+ 'trustly_order_id' => $trustlyOrderId,
223
+ 'magento_increment_id' => $incrementId,
224
+ 'datestamp' => Varien_Date::now(),
225
+ );
226
+ $orderMapping->setData($omData);
227
+ $orderMapping->save();
228
+ Mage::log("Saved mapping between Trustly orderid $trustlyOrderId and increment id $incrementId", Zend_Log::DEBUG, self::LOG_FILE);
229
+
230
+ return $url;
231
+ } else {
232
+ $code = $response->getErrorCode();
233
+ $message = $response->getErrorMessage();
234
+
235
+ if ($message) {
236
+ Mage::log(sprintf("Trustly pay call failed: %s - %s", $code, $message), Zend_Log::WARN, self::LOG_FILE);
237
+ $_msjError = Mage::helper('trustly')->getErrorMsg($message, $code);
238
+ Mage::getSingleton('core/session')->addError(Mage::helper('trustly')->__($_msjError));
239
+ return false;
240
+ } else {
241
+ Mage::log("Trustly pay call failed without returning a proper error", Zend_Log::WARN, self::LOG_FILE);
242
+ Mage::getSingleton('core/session')->addError(Mage::helper('trustly')->__('Error processing Trustly communication.'));
243
+ return false;
244
+ }
245
+ }
246
+
247
+ Mage::log("Trustly pay call failed without returning a proper error", Zend_Log::WARN, self::LOG_FILE);
248
+ return false;
249
+ }
250
+ }
app/code/local/Trustly/Trustly/controllers/PaymentController.php ADDED
@@ -0,0 +1,507 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Trustly_Trustly_PaymentController extends Mage_Core_Controller_Front_Action
4
+ {
5
+ const LOG_FILE = 'trustly.log';
6
+
7
+ public function getStandard()
8
+ {
9
+ return Mage::getSingleton('trustly/standard');
10
+ }
11
+
12
+ protected function _getCheckout() {
13
+
14
+ return Mage::getSingleton('order/checkout');
15
+ }
16
+
17
+
18
+ public function _expireSession()
19
+ {
20
+ if(!Mage::getSingleton('customer/session')->isLoggedIn()) {
21
+ $this->_redirect('customer/account', array('_secure'=>Mage::app()->getStore()->isCurrentlySecure()));
22
+ return true;
23
+ }
24
+
25
+ return false;
26
+ }
27
+
28
+
29
+ public function redirectAction()
30
+ {
31
+
32
+ Mage::log("redirectAction()", Zend_Log::DEBUG, self::LOG_FILE);
33
+ $session = Mage::getSingleton('checkout/session');
34
+ $session->setTrustlyQuoteId($session->getQuoteId());
35
+
36
+ $session->unsUrlTrustly();
37
+
38
+ $standard = Mage::getModel('trustly/standard');
39
+ $redirectError = NULL;
40
+ $response = NULL;
41
+ try {
42
+ $response = $standard->redirectProcess();
43
+ } catch(Trustly_DataException $e) {
44
+ Mage::log("Got Trustly_DataException when communicating with Trustly: " . (string)$e, Zend_Log::DEBUG, self::LOG_FILE);
45
+ Mage::logException($e);
46
+ $redirectError = Mage::helper('trustly')->__("Failed to communicate with Trustly.");
47
+ } catch(Trustly_ConnectionException $e) {
48
+ Mage::log("Got Trustly_ConnectionException when communicating with Trustly: " . (string)$e, Zend_Log::DEBUG, self::LOG_FILE);
49
+ Mage::logException($e);
50
+ $redirectError = Mage::helper('trustly')->__("Cannot connect to Trustly services.");
51
+ } catch(Trustly_SignatureException $e) {
52
+ Mage::log("Got Trustly_SignatureException when communicating with Trustly: " . (string)$e, Zend_Log::DEBUG, self::LOG_FILE);
53
+ Mage::logException($e);
54
+ $redirectError = Mage::helper('trustly')->__("Cannot verify the authenticity of Trustly communication.");
55
+ }
56
+
57
+ if (!isset($response)) {
58
+ Mage::log("No response from redirectProcess()", Zend_Log::DEBUG, self::LOG_FILE);
59
+ if(!isset($redirectError)) {
60
+ $redirectError = Mage::helper('trustly')->__("Failed to communicate with Trustly.");
61
+ }
62
+ }
63
+
64
+ if($redirectError) {
65
+ $session->addError($redirectError);
66
+ } else {
67
+ $session->setUrlTrustly($response);
68
+ $session->setOrderTrustly($session->getLastOrderId());
69
+ }
70
+
71
+ $this->loadLayout();
72
+ try {
73
+ $this->getLayout()->getBlock('head')->setTitle($this->__('Trustly payment'));
74
+ $this->_initLayoutMessages('customer/session');
75
+ $this->getLayout()->getBlock('content')->append($this->getLayout()->createBlock('trustly/redirect','trustly_iframe', array('template' => 'trustly/iframe.phtml')));
76
+ } catch (Mage_Payment_Exception $e) {
77
+ if ($e->getFields()) {
78
+ $result['fields'] = $e->getFields();
79
+ }
80
+ $result['error'] = $e->getMessage();
81
+ } catch (Mage_Core_Exception $e) {
82
+ $result['error'] = $e->getMessage();
83
+ } catch (Exception $e) {
84
+ $result['error'] = $this->__('Unable to set payment method.');
85
+ }
86
+ if(isset($result['error'])) {
87
+ Mage::log("Failed to load layload in redirectAction(): " . $result['error'], Zend_Log::WARN, self::LOG_FILE);
88
+
89
+ throw new Mage_Payment_Model_Info_Exception($result['error']);
90
+ }
91
+
92
+ $session->unsQuoteId();
93
+ $session->unsRedirectUrl();
94
+
95
+ $this->renderLayout();
96
+ }
97
+
98
+
99
+ public function updateAction()
100
+ {
101
+
102
+ $api = Mage::helper('trustly')->getTrustlyAPI();
103
+
104
+ if(!isset($api)) {
105
+ Mage::log("Attempting to process a payment notification, but the Trustly module is not properly configured", Zend_Log::ERR, self::LOG_FILE);
106
+ return ;
107
+ }
108
+
109
+ // Invoming Trustly request
110
+ $httpBody = file_get_contents('php://input');
111
+
112
+ try {
113
+ $notification = $api->handleNotification($httpBody);
114
+ } catch(Trustly_JSONRPCVersionException $e) {
115
+ Mage::log("Got incoming notification with invalid json rpc version (".$e."), message was ".$e->getBadData(), Zend_Log::WARN, self::LOG_FILE);
116
+ return ;
117
+ } catch(Trustly_SignatureException $e) {
118
+ Mage::log("Got incoming notification with invalid signature (".$e."), message was ".$e->getBadData(), Zend_Log::WARN, self::LOG_FILE);
119
+ return ;
120
+ }
121
+
122
+ if(isset($notification)) {
123
+
124
+ $standard = Mage::getModel('trustly/standard');
125
+
126
+ $order = Mage::getModel('sales/order');
127
+ $orderMapping = Mage::getModel('trustly/ordermappings');
128
+
129
+ $trustlyOrderId = $notification->getData('orderid');
130
+ $trustlyNotificationId = $notification->getData('notificationid');
131
+ $orderMapping->loadByTrustlyOrderId($trustlyOrderId);
132
+ if($orderMapping) {
133
+ $incrementId = $orderMapping->getMagentoIncrementId();
134
+ }else {
135
+ # If we cannot find the mapping here, check to see if the
136
+ # enduserid seems to be a valid incrment id, in old code this
137
+ # used to be the case. So to handle the transition between the
138
+ # old module and this one, allow for this.
139
+ # We always use email for enduserid, so we will not match something by accident.
140
+ $enduserid = $notification->getData('enduserid');
141
+
142
+ if(preg_match('/^[0-9]+$/', $enduserid)) {
143
+ Mage::log("Falling back to using enduserid as the incrmentid for enduserid $enduserid", Zend_Log::WARN, self::LOG_FILE);
144
+ $incrementId = $enduserid;
145
+ }
146
+ }
147
+
148
+ if(!$incrementId) {
149
+ Mage::helper('trustly')->sendResponseNotification($notification, true);
150
+
151
+ Mage::getSingleton('checkout/session')->addError(Mage::helper('trustly')->__("Cannot find the relation of Trustly orderid %s for user %s.", $trustlyOrderId, $notification->getData('enduserid')));
152
+ session_write_close();
153
+
154
+ Mage::log("Could not find the mapping of Trustly orderid $trustlyOrderId in the incoming notification. incrmentid $incrementId Enduser is ".$notification->getData('enduserid'), Zend_Log::WARN, self::LOG_FILE);
155
+ $this->_redirect('checkout/cart', array('_secure'=>Mage::app()->getStore()->isCurrentlySecure()));
156
+
157
+ return;
158
+ }
159
+
160
+ $order->loadByIncrementId($incrementId);
161
+ $realOrderId = $order->getRealOrderId();
162
+
163
+ if (!$realOrderId) {
164
+ Mage::helper('trustly')->sendResponseNotification($notification, true);
165
+
166
+ Mage::getSingleton('checkout/session')->addError(Mage::helper('trustly')->__("Cannot find the order %s.", $orderId));
167
+ session_write_close();
168
+
169
+ Mage::log("Could not find the order with increment $incrementId (Trustly orderid $trustlyOrderId) in the incoming notification", Zend_Log::WARN, self::LOG_FILE);
170
+ $this->_redirect('checkout/cart', array('_secure'=>Mage::app()->getStore()->isCurrentlySecure()));
171
+
172
+ return;
173
+ }
174
+
175
+
176
+ $_method = $notification->getMethod();
177
+ $_amount = $notification->getData('amount');
178
+ $_currency = $notification->getData('currency');
179
+
180
+ $_totalData = $order->getData();
181
+ $_grandTotal = $_totalData['base_grand_total'];
182
+ $_order_currency_code = $_totalData['base_currency_code'];
183
+
184
+ $trustly_payment = NULL;
185
+ foreach ($order->getPaymentsCollection() as $_payment) {
186
+
187
+ # We will add a transaction with the TxnID set to the Trustly OrderID, this will be the payment that is paid
188
+ # We will also add a transaction for the pending notification (authorize)
189
+ # We will also add a transaction for the credit notification (capture)
190
+ if(!$_payment->isDeleted() and $_payment->getMethod() == 'trustly') {
191
+ $trustly_payment = $_payment;
192
+ break;
193
+ }
194
+ }
195
+
196
+ if (is_null($trustly_payment)) {
197
+ Mage::helper('trustly')->sendResponseNotification($notification, true);
198
+ Mage::log(sprintf("Recieved payment notification for order %s, but payment method is %s, not Trustly", $incrementId, $trustly_payment->getMethod()), Zend_Log::WARN, self::LOG_FILE);
199
+ return ;
200
+ }
201
+
202
+ $order_transaction = $trustly_payment->getTransaction($trustlyOrderId);
203
+ $notification_transaction = NULL;
204
+ if(isset($order_transaction) && $order_transaction !== FALSE) {
205
+ $order_trans_children = $order_transaction->getChildTransactions();
206
+ if(isset($order_trans_children)) {
207
+ foreach($order_trans_children as $tc) {
208
+ if($tc->getTxnId() == $trustlyNotificationId) {
209
+ $notification_transaction = $tc;
210
+ break;
211
+ }
212
+ }
213
+ }
214
+ }
215
+
216
+ /* Check if we have processed this transaction before, if so
217
+ * say we did fine, we obviously managed to save it... */
218
+ if(isset($notification_transaction)) {
219
+ Mage::helper('trustly')->sendResponseNotification($notification, true);
220
+ Mage::log(sprintf("Received notification %s already processed", $trustlyNotificationId), Zend_Log::DEBUG, self::LOG_FILE);
221
+ return ;
222
+ }
223
+
224
+ $order_invoice = NULL;
225
+ foreach ( $order->getInvoiceCollection() as $invoice) {
226
+ if($invoice->getTransactionId() == $trustlyOrderId) {
227
+ $order_invoice = $invoice;
228
+ break;
229
+ }
230
+ }
231
+
232
+ $transactionSave = Mage::getModel('core/resource_transaction');
233
+
234
+ /* We should always have a payment with the trustly method, if
235
+ * we do not have one, create it we will need this regardless of the method for the notification */
236
+ if(is_null($trustly_payment) || is_null($trustly_payment->getTxnType())) {
237
+ /* Create a payment with our TrustlyOrderId as the
238
+ * TransactionId, we will later add the current
239
+ * notification as a child payment for this payment */
240
+ $trustly_payment->resetTransactionAdditionalInfo();
241
+ $trustly_payment->setTransactionId($trustlyOrderId);
242
+ $trustly_payment->setParentTransactionId(NULL);
243
+ $trustly_payment->setIsTransactionClosed(false);
244
+ $trustly_payment->setTransactionAdditionalInfo(Mage_Sales_Model_Order_Payment_Transaction::RAW_DETAILS, array('OrderId' => $trustlyOrderId));
245
+ $order_transaction = $trustly_payment->addTransaction(Mage_Sales_Model_Order_Payment_Transaction::TYPE_ORDER);
246
+ $transactionSave->addObject($order_transaction)
247
+ ->addObject($trustly_payment);
248
+ }
249
+
250
+ # Check to see if we have invoiced this order already, if
251
+ # so do not do it again. We might be getting the same
252
+ # notification over again.
253
+ if(($_method == 'pending' || $_method == 'credit') && isset($order_invoice)) {
254
+ Mage::log(sprintf("Recieved $_method notification for order with increment %s for orderid %s, but order already had an invoice, nothing done", $incrementId, $trustlyOrderId), Zend_Log::DEBUG, self::LOG_FILE);
255
+
256
+ } elseif(($_method == 'pending' || $_method == 'credit') && !isset($order_invoice)) {
257
+ if($_method == 'credit') {
258
+ Mage::log(sprintf("Recieved a %s notification, no previous invoice could be found for Trustly orderid %s, magento order %s. No pending notification send before?! Creating one now", $_method, $trustlyOrderId, $incrementId), Zend_Log::WARN, self::LOG_FILE);
259
+ }
260
+
261
+ /* A credit notification without an invoice can mean one of two
262
+ * things, either the invoice has been removed or we did not
263
+ * receive the pending notification for this order. At this
264
+ * point we cannot really reject the money, a payment has been
265
+ * done, so create a new invoice and attach this payment to that invoice. */
266
+
267
+ /* When we get the pending notification the user has
268
+ * completed his end of the payment. The payment can
269
+ * still fail and we are yet to be credited any funds.
270
+ * Create an invoice, but do not set it as paid just
271
+ * yet. */
272
+
273
+ $order_invoice = $order->prepareInvoice()
274
+ ->setTransactionId($trustlyOrderId)
275
+ ->addComment(Mage::helper('trustly')->__("Invoiced from Trustly payment"))
276
+ ->register();
277
+
278
+ $order->addRelatedObject($order_invoice);
279
+ $trustly_payment->setCreatedInvoice($order_invoice);
280
+
281
+ $comment = Mage::helper('trustly')->__('Pending payment.');
282
+ $comment .= '<br />' . Mage::helper('trustly')->__('Invoice for Trustly OrderId #%s created', $trustlyOrderId);
283
+
284
+ $orderStatus = Mage_Sales_Model_Order::STATE_PENDING_PAYMENT;
285
+
286
+ $order->setState($orderStatus, true, $comment, false);
287
+
288
+ $transactionSave->addObject($order_invoice)
289
+ ->addObject($order)
290
+ ->addObject($trustly_payment);
291
+
292
+ $trustly_payment->unsCreatedInvoice();
293
+
294
+ Mage::log(sprintf("Recieved %s notification for order with increment %s for orderid %s", $_method, $incrementId, $trustlyOrderId), Zend_Log::DEBUG, self::LOG_FILE);
295
+
296
+ if (((int)Mage::getModel('trustly/standard')->getConfigData('sendmailorderconfirmation')) == 1) {
297
+ Mage::log('Sending new order email', Zend_Log::DEBUG, self::LOG_FILE);
298
+ $order->sendNewOrderEmail();
299
+ }
300
+ }
301
+
302
+
303
+ if($_method == 'pending') {
304
+ /* We have no authorize for the payment (As we would simply
305
+ * abort if we have gotten the pending before) so create
306
+ * an authorization for the payment here and append */
307
+ $notification_transaction = $this->addChildTransaction($trustly_payment,
308
+ $trustlyNotificationId, $trustlyOrderId,
309
+ Mage_Sales_Model_Order_Payment_Transaction::TYPE_AUTH, true);
310
+
311
+ $transactionSave->addObject($notification_transaction)
312
+ ->addObject($trustly_payment);
313
+ } elseif($_method == 'credit') {
314
+ /**
315
+ * verify the amount sent and the currency_code, to prevent improper payments
316
+ */
317
+
318
+ $_fmtExpectedAmount = Mage::helper('core')->currency($_grandTotal, true, false);
319
+ $_fmtReceivedAmount = Mage::helper('core')->currency($_amount, true, false);
320
+ if ($_fmtExpectedAmount != $_fmtExpectedAmount || $_order_currency_code != $_currency) {
321
+
322
+ $comment = Mage::helper('trustly')->__('Invalid payment.');
323
+ $comment .= "<br />" . Mage::helper('trustly')->__('Trustly orderid: %s', $notification->getData('orderid'));
324
+ $comment .= "<br />" . Mage::helper('trustly')->__('Invoice: %s', $order_invoice->getIncrementId());
325
+ $comment .= "<br />" . Mage::helper('trustly')->__('Amount received: %s %s', $_amount, $_currency);
326
+ $comment .= "<br />" . Mage::helper('trustly')->__('Amount expected: %s %s', $_fmtExpectedAmount, $_order_currency_code);
327
+ $comment .= "<br />" . Mage::helper('trustly')->__('Date of transaction: %s', date('Y-m-d H:i:s', strtotime($notification->getData('timestamp'))));
328
+
329
+ $orderStatus = Mage_Sales_Model_Order::STATE_CANCELED;
330
+ $order->setState($orderStatus, true, $comment, false);
331
+ $transactionSave->addObject($order);
332
+ $transactionSave->save();
333
+
334
+ Mage::log(sprintf("Recieved invalid payment for order %s, got amount %s %s", $incrementId, $_amount, $_currency), Zend_Log::WARN, self::LOG_FILE);
335
+
336
+ /* The response is wether or not the notification we
337
+ * recived and handled properly, not if we liked the
338
+ * contents of it */
339
+ Mage::helper('trustly')->sendResponseNotification($notification, true);
340
+
341
+ return;
342
+ }
343
+
344
+ $trustly_payment->setAmountCharged($_amount);
345
+ $order->setIsInProcess(true);
346
+
347
+ $comment = Mage::helper('trustly')->__('Authorized payment.');
348
+ $comment .= "<br />" . Mage::helper('trustly')->__('Trustly orderid: %s', $notification->getData('orderid'));
349
+ $comment .= "<br />" . Mage::helper('trustly')->__('Invoice: %s', $order_invoice->getIncrementId());
350
+ $comment .= "<br />" . Mage::helper('trustly')->__('Date of transaction: %s', date('Y-m-d H:i:s', strtotime($notification->getData('timestamp'))));
351
+ $comment .= "<br />" . Mage::helper('trustly')->__('Notification id: %s', $notification->getData('notificationid'));
352
+ $comment .= "<br />" . Mage::helper('trustly')->__('Payment amount: %s %s', $_amount, $_currency);
353
+
354
+ /* Funds are credited to merchant account, we call this captured */
355
+ $notification_transaction = $this->addChildTransaction($trustly_payment, $trustlyNotificationId, $trustlyOrderId,
356
+ Mage_Sales_Model_Order_Payment_Transaction::TYPE_CAPTURE, true);
357
+
358
+ /* Lookup an invoice connected to this order with the amount we
359
+ * have gotten paid with, mark as paid, there should really be
360
+ * only one */
361
+ $open = Mage_Sales_Model_Order_Invoice::STATE_OPEN;
362
+ if ($order_invoice->getState() == $open && $order_invoice->getBaseGrandTotal() == $_amount) {
363
+ $trustly_payment->capture($order_invoice);
364
+ if ($order_invoice->getIsPaid()) {
365
+ $order_invoice->pay();
366
+ }
367
+ /* Set the transaction ID again here, if we fiddle with
368
+ * the invoice it will change the txnid to this
369
+ * transaction otherwise */
370
+ $order_invoice->setTransactionId($trustlyOrderId);
371
+
372
+ /* There is an interesting feature in the Order Payment, if
373
+ * we created the payment in this notification (i.e.
374
+ * credit notification is the first one to arrive) then
375
+ * the lookup of parent transaction will fail as
376
+ * addTransaction() always looks up the transaction id
377
+ * given and the lookup is cached (and it does not exist
378
+ * so non-existance is cached. So... in this case,
379
+ * workaround by loading parent manually and close it. */
380
+
381
+ }
382
+
383
+ $orderStatus = Mage_Sales_Model_Order::STATE_PROCESSING;
384
+ $order->setState($orderStatus, true, $comment, false);
385
+
386
+ $transactionSave->addObject($order_invoice)
387
+ ->addObject($order)
388
+ ->addObject($trustly_payment);
389
+
390
+
391
+ Mage::log("Recieved payment for order with increment $incrementId", Zend_Log::INFO, self::LOG_FILE);
392
+
393
+ }elseif($_method == 'debit') {
394
+ $comment = Mage::helper('trustly')->__('Payment failed, debit received.');
395
+ $comment .= "<br />" . Mage::helper('trustly')->__('Trustly orderid: %s', $notification->getData('orderid'));
396
+ $comment .= "<br />" . Mage::helper('trustly')->__('Date of transaction: %s', date('Y-m-d H:i:s', strtotime($notification->getData('timestamp'))));
397
+ $comment .= "<br />" . Mage::helper('trustly')->__('Notification id: %s', $notification->getData('notificationid'));
398
+ $comment .= "<br />" . Mage::helper('trustly')->__('Debit amount: %s %s', $_amount, $_currency);
399
+
400
+ /* Normally the only debit amount that should be received is
401
+ * the full amount, but you never know.... */
402
+ if ($order->getBaseGrandTotal() == $_amount) {
403
+ $creditmemo = Mage::getModel('sales/service_order', $order)
404
+ ->prepareCreditmemo()
405
+ ->setPaymentRefundDisallowed(true)
406
+ ->setAutomaticallyCreated(true)
407
+ ->register();
408
+
409
+ $creditmemo->addComment($this->__('Credit memo has been created automatically'));
410
+ $transactionSave->addObject($creditmemo);
411
+ }
412
+
413
+ /* Add a child transaction to the original payment issuing a refund for the order. */
414
+ $notification_transaction = $this->addChildTransaction($trustly_payment, $trustlyNotificationId, $trustlyOrderId,
415
+ Mage_Sales_Model_Order_Payment_Transaction::TYPE_REFUND, true);
416
+
417
+ $order->setState($order->getStatus(), true, $comment);
418
+
419
+ $transactionSave->addObject($order)
420
+ ->addObject($trustly_payment);
421
+
422
+ Mage::log("Recieved debit for order with increment $incrementId of $_amount $_currency", Zend_Log::INFO, self::LOG_FILE);
423
+ }elseif($_method == 'cancel') {
424
+
425
+ /* Cancel will be sent when the payment will not be completed.
426
+ * The cancel method will always be sent in conjunction with a
427
+ * debit notification, in the debit notification we handle the
428
+ * montary changeback and cancel of the invoices */
429
+
430
+ $notification_transaction = $this->addChildTransaction($trustly_payment, $trustlyNotificationId, $trustlyOrderId,
431
+ Mage_Sales_Model_Order_Payment_Transaction::TYPE_VOID, true);
432
+
433
+ $orderStatus = Mage_Sales_Model_Order::STATE_CANCELED;
434
+ $order->setState($orderStatus, true, NULL, false);
435
+
436
+ $transactionSave->addObject($order)
437
+ ->addObject($trustly_payment);
438
+
439
+ Mage::log("Recieved cancel for order with increment $incrementId", Zend_Log::INFO, self::LOG_FILE);
440
+ }
441
+
442
+ if(isset($notification_transaction)) {
443
+ if($notification_transaction->getShouldCloseParentTransaction()) {
444
+
445
+ $parent_transaction = Mage::getModel('sales/order_payment_transaction')
446
+ ->setOrderPaymentObject($trustly_payment)
447
+ ->loadByTxnId($notification_transaction->getParentTransactionId());
448
+ if(isset($parent_transaction) && $parent_transaction !== FALSE && $parent_transaction->getId()) {
449
+ if (!$parent_transaction->getIsClosed()) {
450
+ $parent_transaction->isFailsafe(false)->close(false);
451
+
452
+ $transactionSave->addObject($parent_transaction);
453
+ }
454
+ }
455
+ }
456
+ }
457
+
458
+ $transactionSave->save();
459
+ Mage::helper('trustly')->sendResponseNotification($notification, true);
460
+ }
461
+ }
462
+
463
+
464
+ protected function addChildTransaction($payment, $trustlyNotificationId, $trustlyOrderId, $typeTarget, $closed = false)
465
+ {
466
+ $payment->resetTransactionAdditionalInfo();
467
+ $payment->setTransactionId($trustlyNotificationId);
468
+ $payment->setParentTransactionId($trustlyOrderId);
469
+ $payment->setIsTransactionClosed($closed);
470
+ return $payment->addTransaction($typeTarget);
471
+ }
472
+
473
+
474
+ public function successAction()
475
+ {
476
+ Mage::log("successAction()", Zend_Log::DEBUG, self::LOG_FILE);
477
+
478
+ $this->_redirect('checkout/onepage/success', array('_secure'=>true));
479
+ }
480
+
481
+
482
+ public function failAction()
483
+ {
484
+ Mage::log("failAction()", Zend_Log::DEBUG, self::LOG_FILE);
485
+
486
+ $orderId = Mage::getSingleton('checkout/session')->getData('orderid_trustly');
487
+ $order = Mage::getModel('sales/order')->load($orderId);
488
+
489
+ if ($order) {
490
+ $order->cancel()->save();
491
+ }
492
+ $this->_redirect('checkout/cart', array('_secure'=>Mage::app()->getStore()->isCurrentlySecure()));
493
+ }
494
+
495
+ public function cancelAction()
496
+ {
497
+ Mage::log("cancelAction()", Zend_Log::DEBUG, self::LOG_FILE);
498
+
499
+ $orderId = Mage::getSingleton('checkout/session')->getData('orderid_trustly');
500
+ $order = Mage::getModel('sales/order')->load($orderId);
501
+
502
+ if ($order) {
503
+ $order->cancel()->save();
504
+ }
505
+ $this->_redirect('checkout/cart', array('_secure'=>Mage::app()->getStore()->isCurrentlySecure()));
506
+ }
507
+ }
app/code/local/Trustly/Trustly/etc/config.xml ADDED
@@ -0,0 +1,115 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <modules>
4
+ <Trustly_Trustly>
5
+ <version>2.0.2</version>
6
+ </Trustly_Trustly>
7
+ </modules>
8
+ <global>
9
+ <models>
10
+ <trustly>
11
+ <class>Trustly_Trustly_Model</class>
12
+ <resourceModel>trustly_mysql4</resourceModel>
13
+ </trustly>
14
+ <trustly_mysql4>
15
+ <class>Trustly_Trustly_Model_Mysql4</class>
16
+ <entities>
17
+ <ordermappings>
18
+ <table>trustly_ordermappings</table>
19
+ </ordermappings>
20
+ </entities>
21
+ </trustly_mysql4>
22
+ </models>
23
+ <resources>
24
+ <trustly_setup>
25
+ <setup>
26
+ <module>Trustly_Trustly</module>
27
+ </setup>
28
+ <connection>
29
+ <use>core_setup</use>
30
+ </connection>
31
+ </trustly_setup>
32
+ <trustly_write>
33
+ <connection>
34
+ <use>core_write</use>
35
+ </connection>
36
+ </trustly_write>
37
+ <trustly_read>
38
+ <connection>
39
+ <use>core_read</use>
40
+ </connection>
41
+ </trustly_read>
42
+ </resources>
43
+ <helpers>
44
+ <trustly>
45
+ <class>Trustly_Trustly_Helper</class>
46
+ </trustly>
47
+ </helpers>
48
+ <blocks>
49
+ <trustly>
50
+ <class>Trustly_Trustly_Block</class>
51
+ </trustly>
52
+ </blocks>
53
+ <sales>
54
+ <order>
55
+ <states>
56
+ <pending_payment translate="label">
57
+ <visible_on_front>1</visible_on_front>
58
+ </pending_payment>
59
+ </states>
60
+ </order>
61
+ </sales>
62
+ </global>
63
+ <admin>
64
+ <routers>
65
+ <trustly>
66
+ <use>admin</use>
67
+ <args>
68
+ <module>Trustly_Trustly</module>
69
+ </args>
70
+ </trustly>
71
+ </routers>
72
+ </admin>
73
+ <frontend>
74
+ <secure_url>
75
+ <trustly>/trustly</trustly>
76
+ </secure_url>
77
+ <routers>
78
+ <trustly>
79
+ <use>standard</use>
80
+ <args>
81
+ <module>Trustly_Trustly</module>
82
+ <frontName>trustly</frontName>
83
+ </args>
84
+ </trustly>
85
+ </routers>
86
+ <layout>
87
+ <updates>
88
+ <Trustly>
89
+ <file>trustly.xml</file>
90
+ </Trustly>
91
+ </updates>
92
+ </layout>
93
+ <translate>
94
+ <modules>
95
+ <Trustly_Trustly>
96
+ <files>
97
+ <default>Trustly_Trustly.csv</default>
98
+ </files>
99
+ </Trustly_Trustly>
100
+ </modules>
101
+ </translate>
102
+ </frontend>
103
+ <default>
104
+ <payment>
105
+ <trustly>
106
+ <active>0</active>
107
+ <model>trustly/standard</model>
108
+ <title>Trustly - Direct bank e-Payments</title>
109
+ <urltrustly>0</urltrustly>
110
+ <allowspecific>0</allowspecific>
111
+ <sendmailorderconfirmation>1</sendmailorderconfirmation>
112
+ </trustly>
113
+ </payment>
114
+ </default>
115
+ </config>
app/code/local/Trustly/Trustly/etc/system.xml ADDED
@@ -0,0 +1,144 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <sections>
4
+ <payment>
5
+ <groups>
6
+ <trustly translate="label" module="trustly">
7
+ <label>Trustly - Direct bank e-Payments</label>
8
+ <frontend_type>text</frontend_type>
9
+ <sort_order>1</sort_order>
10
+ <show_in_default>1</show_in_default>
11
+ <show_in_website>1</show_in_website>
12
+ <show_in_store>1</show_in_store>
13
+ <fields>
14
+ <about>
15
+ <frontend_model>trustly/system_config_about</frontend_model>
16
+ <sort_order>0</sort_order>
17
+ <show_in_default>1</show_in_default>
18
+ <show_in_website>1</show_in_website>
19
+ <show_in_store>1</show_in_store>
20
+ </about>
21
+ <active translate="label" module="payment">
22
+ <label>Enabled</label>
23
+ <frontend_type>select</frontend_type>
24
+ <source_model>adminhtml/system_config_source_yesno</source_model>
25
+ <sort_order>10</sort_order>
26
+ <show_in_default>1</show_in_default>
27
+ <show_in_website>1</show_in_website>
28
+ <show_in_store>1</show_in_store>
29
+ </active>
30
+ <urltrustly translate="label comment">
31
+ <label>Live enviroment</label>
32
+ <comment><![CDATA[Trustly test Backoffice: <br /><a href="https://test.trustly.com/backoffice/" target="_blank">https://test.trustly.com/backoffice/</a><br /> Trustly live Backoffice: <br /><a href="https://trustly.com/backoffice/" target="_blank">https://trustly.com/backoffice/</a>]]></comment>
33
+ <frontend_type>select</frontend_type>
34
+ <source_model>adminhtml/system_config_source_yesno</source_model>
35
+ <sort_order>100</sort_order>
36
+ <show_in_default>1</show_in_default>
37
+ <show_in_website>1</show_in_website>
38
+ <show_in_store>1</show_in_store>
39
+ </urltrustly>
40
+ <merchantusername translate="label">
41
+ <label><![CDATA[Username <b>Live enviroment</b>]]></label>
42
+ <frontend_type>text</frontend_type>
43
+ <sort_order>110</sort_order>
44
+ <show_in_default>1</show_in_default>
45
+ <show_in_website>0</show_in_website>
46
+ <show_in_store>0</show_in_store>
47
+ <depends><urltrustly>1</urltrustly></depends>
48
+ </merchantusername>
49
+ <merchantpassword translate="label">
50
+ <label><![CDATA[Password <b>Live enviroment</b>]]></label>
51
+ <frontend_type>password</frontend_type>
52
+ <sort_order>120</sort_order>
53
+ <show_in_default>1</show_in_default>
54
+ <show_in_website>0</show_in_website>
55
+ <show_in_store>0</show_in_store>
56
+ <depends><urltrustly>1</urltrustly></depends>
57
+ </merchantpassword>
58
+ <merchantkey translate="label">
59
+ <label><![CDATA[Private key <b>Live enviroment</b>]]></label>
60
+ <frontend_type>textarea</frontend_type>
61
+ <sort_order>125</sort_order>
62
+ <show_in_default>1</show_in_default>
63
+ <show_in_website>1</show_in_website>
64
+ <show_in_store>1</show_in_store>
65
+ <depends><urltrustly>1</urltrustly></depends>
66
+ </merchantkey>
67
+ <merchantusernametest translate="label">
68
+ <label><![CDATA[Username <b>Test enviroment</b>]]></label>
69
+ <frontend_type>text</frontend_type>
70
+ <sort_order>110</sort_order>
71
+ <show_in_default>1</show_in_default>
72
+ <show_in_website>0</show_in_website>
73
+ <show_in_store>0</show_in_store>
74
+ <depends><urltrustly>0</urltrustly></depends>
75
+ </merchantusernametest>
76
+ <merchantpasswordtest translate="label">
77
+ <label><![CDATA[Password <b>Test enviroment</b>]]></label>
78
+ <frontend_type>password</frontend_type>
79
+ <sort_order>120</sort_order>
80
+ <show_in_default>1</show_in_default>
81
+ <show_in_website>0</show_in_website>
82
+ <show_in_store>0</show_in_store>
83
+ <depends><urltrustly>0</urltrustly></depends>
84
+ </merchantpasswordtest>
85
+ <merchantkeytest translate="label">
86
+ <label><![CDATA[Private key <b>Test enviroment</b>]]></label>
87
+ <frontend_type>textarea</frontend_type>
88
+ <sort_order>125</sort_order>
89
+ <show_in_default>1</show_in_default>
90
+ <show_in_website>1</show_in_website>
91
+ <show_in_store>1</show_in_store>
92
+ <depends><urltrustly>0</urltrustly></depends>
93
+ </merchantkeytest>
94
+ <sendmailorderconfirmation translate="label">
95
+ <label>Send confirmation email</label>
96
+ <frontend_type>Select</frontend_type>
97
+ <sort_order>290</sort_order>
98
+ <source_model>adminhtml/system_config_source_yesno</source_model>
99
+ <show_in_default>1</show_in_default>
100
+ <show_in_website>1</show_in_website>
101
+ <show_in_store>1</show_in_store>
102
+ </sendmailorderconfirmation>
103
+ <httpnotifications translate="label">
104
+ <label>Notifications over HTTP</label>
105
+ <frontend_type>Select</frontend_type>
106
+ <sort_order>295</sort_order>
107
+ <source_model>adminhtml/system_config_source_yesno</source_model>
108
+ <show_in_default>1</show_in_default>
109
+ <show_in_website>1</show_in_website>
110
+ <show_in_store>1</show_in_store>
111
+ </httpnotifications>
112
+ <allowspecific translate="label" module="payment">
113
+ <label>Limit the allowed countries to</label>
114
+ <frontend_type>allowspecific</frontend_type>
115
+ <sort_order>300</sort_order>
116
+ <source_model>adminhtml/system_config_source_payment_allspecificcountries</source_model>
117
+ <show_in_default>1</show_in_default>
118
+ <show_in_website>1</show_in_website>
119
+ <show_in_store>1</show_in_store>
120
+ </allowspecific>
121
+ <specificcountry translate="label" module="payment">
122
+ <label>Payment from Specific Countries</label>
123
+ <frontend_type>multiselect</frontend_type>
124
+ <sort_order>310</sort_order>
125
+ <source_model>adminhtml/system_config_source_country</source_model>
126
+ <show_in_default>1</show_in_default>
127
+ <show_in_website>1</show_in_website>
128
+ <show_in_store>1</show_in_store>
129
+ </specificcountry>
130
+ <sort_order translate="label">
131
+ <label>Sort Order</label>
132
+ <frontend_type>text</frontend_type>
133
+ <sort_order>320</sort_order>
134
+ <show_in_default>1</show_in_default>
135
+ <show_in_website>1</show_in_website>
136
+ <show_in_store>0</show_in_store>
137
+ <frontend_class>validate-number</frontend_class>
138
+ </sort_order>
139
+ </fields>
140
+ </trustly>
141
+ </groups>
142
+ </payment>
143
+ </sections>
144
+ </config>
app/code/local/Trustly/Trustly/lib/Trustly.php ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ require_once('Trustly/exceptions.php');
3
+ require_once('Trustly/Data/data.php');
4
+ require_once('Trustly/Data/request.php');
5
+ require_once('Trustly/Data/jsonrpcrequest.php');
6
+ require_once('Trustly/Data/response.php');
7
+ require_once('Trustly/Data/jsonrpcresponse.php');
8
+ require_once('Trustly/Data/jsonrpcnotificationrequest.php');
9
+ require_once('Trustly/Data/jsonrpcnotificationresponse.php');
10
+
11
+ require_once('Trustly/Api/api.php');
12
+ require_once('Trustly/Api/signed.php');
13
+ require_once('Trustly/Api/unsigned.php');
14
+ require_once('Trustly/Api/ecommerce.php');
15
+ ?>
app/code/local/Trustly/Trustly/lib/Trustly/Api/api.php ADDED
@@ -0,0 +1,251 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ abstract class Trustly_Api {
4
+ /* Hostname, port and protocol information about how to reach the API */
5
+ var $api_host = NULL;
6
+ var $api_port = NULL;
7
+ var $api_is_https = TRUE;
8
+
9
+ /* The data of the last request performed. */
10
+ var $last_request = NULL;
11
+
12
+ function __construct($host, $port, $is_https) {
13
+ $this->api_host = $host;
14
+ $this->api_port = $port;
15
+ $this->api_is_https = $is_https;
16
+
17
+ if($this->loadTrustlyPublicKey() === FALSE) {
18
+ $error = openssl_error_string();
19
+ throw new InvalidArgumentException("Cannot load Trustly public key file for host $host".(isset($error)?", error $error":''));
20
+ }
21
+
22
+ /* Make sure the curl extension is loaded so we can open URL's */
23
+ if(!in_array('curl', get_loaded_extensions())) {
24
+ throw new Trustly_ConnectionException('curl is not installed. We cannot call the API, bailing');
25
+ }
26
+ }
27
+
28
+ /* Load the public key used for for verifying incoming data responses from
29
+ * trustly. The keys are distributed as a part of the source code package
30
+ * and should be named to match the host under $PWD/HOSTNAME.public.pem */
31
+ public function loadTrustlyPublicKey() {
32
+ $filename = sprintf('%s/keys/%s.public.pem', realpath(dirname(__FILE__)), $this->api_host);
33
+
34
+ $cert = @file_get_contents($filename);
35
+ if($cert !== FALSE) {
36
+ $this->trustly_publickey = openssl_pkey_get_public($cert);
37
+ if(!$this->trustly_publickey) {
38
+ return FALSE;
39
+ }
40
+ return TRUE;
41
+ }
42
+ return FALSE;
43
+ }
44
+
45
+ public function serializeData($data) {
46
+ if(is_array($data)) {
47
+ ksort($data);
48
+ $return = '';
49
+ foreach($data as $key => $value) {
50
+ if(is_numeric($key)) {
51
+ $return .= $this->serializeData($value);
52
+ } else {
53
+ $return .= $key . $this->serializeData($value);
54
+ }
55
+ }
56
+ return $return;
57
+ } else {
58
+ return (string)$data;
59
+ }
60
+ }
61
+
62
+ /* Given all the components to verify and work with, check if the given
63
+ * signature has been used to sign the data */
64
+ protected function verifyTrustlySignedData($method, $uuid, $signature, $data) {
65
+ if($method === NULL) {
66
+ $method = '';
67
+ }
68
+ if($uuid === NULL) {
69
+ $uuid = '';
70
+ }
71
+
72
+ if(!isset($signature)) {
73
+ return FALSE;
74
+ }
75
+
76
+ $serial_data = $method . $uuid . $this->serializeData($data);
77
+ $raw_signature = base64_decode($signature);
78
+ if (version_compare(phpversion(), '5.2.0', '<')) {
79
+ return (boolean)openssl_verify($serial_data, $raw_signature, $this->trustly_publickey);
80
+ } else {
81
+ return (boolean)openssl_verify($serial_data, $raw_signature, $this->trustly_publickey, OPENSSL_ALGO_SHA1);
82
+ }
83
+ }
84
+
85
+ /* Check to make sure that the given response (instance of
86
+ * Trustly_Data_Response) has been signed with the correct key when
87
+ * originating from the host */
88
+ public function verifyTrustlySignedResponse($response) {
89
+ $method = $response->getMethod();
90
+ $uuid = $response->getUUID();
91
+ $signature = $response->getSignature();
92
+ $data = $response->getResult();
93
+ if($data !== NULL) {
94
+ $data = $data['data'];
95
+ }
96
+
97
+ return $this->verifyTrustlySignedData($method, $uuid, $signature, $data);
98
+ }
99
+
100
+ /* Check to make sure that the given notification (instance of
101
+ * Trustly_Data_JSONRPCNotificationRequest) has been signed with the
102
+ * correct key originating from the host */
103
+ public function verifyTrustlySignedNotification($notification) {
104
+ $method = $notification->getMethod();
105
+ $uuid = $notification->getUUID();
106
+ $signature = $notification->getSignature();
107
+ $data = $notification->getData();
108
+
109
+ return $this->verifyTrustlySignedData($method, $uuid, $signature, $data);
110
+ }
111
+
112
+ /* Update the current host settings, leave out any parameter to leave as is */
113
+ public function setHost($host=NULL, $port=NULL, $is_https=NULL) {
114
+ if(isset($host)) {
115
+ $this->api_host = $host;
116
+ if($this->loadTrustlyPublicKey() === FALSE) {
117
+ $error = openssl_error_string();
118
+ throw new InvalidArgumentException("Cannot load Trustly public key file for host $host".(isset($error)?", error $error":''));
119
+ }
120
+ }
121
+ if(isset($port)) {
122
+ $this->api_port = $port;
123
+ }
124
+ if(isset($is_https)) {
125
+ $this->api_is_https = $is_https;
126
+ }
127
+ }
128
+
129
+ /* Do note that that if you are going to POST JSON you need to set the
130
+ * content-type of the transfer AFTER you set the postfields, this is done
131
+ * if you provide the postdata here, if not, take care to do it or the
132
+ * content-type will be wrong */
133
+ public function connect($url=NULL, $postdata=NULL) {
134
+ $cu = curl_init();
135
+ curl_setopt($cu, CURLOPT_FAILONERROR, FALSE);
136
+ curl_setopt($cu, CURLOPT_FOLLOWLOCATION, FALSE);
137
+ curl_setopt($cu, CURLOPT_RETURNTRANSFER, TRUE);
138
+ curl_setopt($cu, CURLOPT_CONNECTTIMEOUT, 5);
139
+ curl_setopt($cu, CURLOPT_TIMEOUT, 30);
140
+ curl_setopt($cu, CURLOPT_PORT, $this->api_port);
141
+
142
+ if($this->api_is_https) {
143
+ if(@CURLOPT_PROTOCOLS != 'CURLOPT_PROTOCOLS') {
144
+ curl_setopt($cu, CURLOPT_PROTOCOLS, CURLPROTO_HTTPS);
145
+ }
146
+ curl_setopt($cu, CURLOPT_SSL_VERIFYHOST, 2);
147
+ curl_setopt($cu, CURLOPT_SSL_VERIFYPEER, TRUE);
148
+ } else {
149
+ if(@CURLOPT_PROTOCOLS != 'CURLOPT_PROTOCOLS') {
150
+ curl_setopt($cu, CURLOPT_PROTOCOLS, CURLPROTO_HTTP);
151
+ }
152
+ }
153
+ if(isset($postdata)) {
154
+ curl_setopt($cu, CURLOPT_POSTFIELDS, $postdata);
155
+ }
156
+ curl_setopt($cu, CURLOPT_HTTPHEADER, array('Content-Type: application/json; charset=utf-8'));
157
+ curl_setopt($cu, CURLOPT_CUSTOMREQUEST, "POST");
158
+ curl_setopt($cu, CURLOPT_URL, $url);
159
+ return $cu;
160
+ }
161
+
162
+ public function baseURL() {
163
+ if($this->api_is_https) {
164
+ $url = 'https://' . $this->api_host . ($this->api_port != 443?':'.$this->api_port:'');
165
+ } else {
166
+ $url = 'http://' . $this->api_host . ($this->api_port != 80?':'.$this->api_port:'');
167
+ }
168
+ return $url;
169
+ }
170
+
171
+ public function url($request=NULL) {
172
+ return $this->baseURL() . $this->urlPath($request);
173
+ }
174
+
175
+ public function getLastRequest() {
176
+ return $this->last_request;
177
+ }
178
+
179
+ /* Given the http body of an (presumed) notification from trustly. Verify
180
+ * signatures and build a Trustly_Data_JSONRPCNotificationRequest object
181
+ * from the incoming data. This should ALWAYS be the first steps when
182
+ * accessing data in the notification, a noficiation with a poor or invalid
183
+ * signature should be discarded. */
184
+ public function handleNotification($httpbody) {
185
+ $request = new Trustly_Data_JSONRPCNotificationRequest($httpbody);
186
+
187
+ if($this->verifyTrustlySignedNotification($request) !== TRUE) {
188
+ throw new Trustly_SignatureException('Incomming notification signature is not valid', $httpbody);
189
+ }
190
+
191
+ return $request;
192
+ }
193
+
194
+
195
+ /* Given an object from an incoming notification request build a response
196
+ * object that can be used to respond to trustly with */
197
+ public function notificationResponse($request, $success=TRUE) {
198
+ $response = new Trustly_Data_JSONRPCNotificationResponse($request, $success);
199
+ return $response;
200
+ }
201
+
202
+ /* Call the trustly API with the given request. */
203
+ public function call($request) {
204
+ if($this->insertCredentials($request) !== TRUE) {
205
+ throw new Trustly_DataException('Unable to add authorization criterias to outgoing request');
206
+ }
207
+ $this->last_request = $request;
208
+
209
+ $jsonstr = $request->json();
210
+
211
+ $url = $this->url($request);
212
+ $curl = $this->connect($url, $jsonstr);
213
+
214
+
215
+ $body = curl_exec($curl);
216
+ if($body === FALSE) {
217
+ $error = curl_error($curl);
218
+ if($error === NULL) {
219
+ $error = 'Failed to connect to the Trusly API';
220
+ }
221
+ throw new Trustly_ConnectionException($error);
222
+ }
223
+
224
+ if($this->api_is_https) {
225
+ $ssl_result = curl_getinfo($curl, CURLINFO_SSL_VERIFYRESULT); #FIXME
226
+ }
227
+ $result = $this->handleResponse($request, $body, $curl);
228
+ curl_close($curl);
229
+ return $result;
230
+ }
231
+
232
+ protected function apiBool($value) {
233
+ if(isset($value)) {
234
+ if($value) {
235
+ return '1';
236
+ } else {
237
+ return '0';
238
+ }
239
+ }
240
+ return NULL;
241
+ }
242
+
243
+ abstract public function urlPath($request=NULL);
244
+
245
+ abstract public function handleResponse($request, $body, $curl);
246
+
247
+ abstract public function insertCredentials($request);
248
+
249
+ }
250
+
251
+ ?>
app/code/local/Trustly/Trustly/lib/Trustly/Api/ecommerce.php ADDED
@@ -0,0 +1,146 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Trustly_Api_ECommerce extends Trustly_Api {
4
+ var $api_apikey = NULL;
5
+
6
+ public function __construct($host, $port, $is_https, $apikey) {
7
+ parent::__construct($host, $port, $is_https);
8
+
9
+ $this->api_apikey = $apikey;
10
+ }
11
+
12
+ public function urlPath($request=NULL) {
13
+ $url = '/api/ECom';
14
+
15
+ if(isset($request)) {
16
+ $method = $request->getMethod();
17
+ if(isset($method)) {
18
+ $url .= '/' . $method;
19
+ }
20
+ }
21
+ return $url;
22
+ }
23
+
24
+ public function verifyTrustlySignedResponse($response) {
25
+ $method = $response->getMethod();
26
+ $uuid = $response->getUUID();
27
+ $signature = $response->getSignature();
28
+ $data = $response->getResult();
29
+
30
+ /* As the data in the ecommerce responses are flat, all the uuid,
31
+ * signatures, method information is on the same level as the data
32
+ * response. Remove theese from the data before checking the signature. */
33
+ unset($data['uuid']);
34
+ unset($data['signature']);
35
+ unset($data['method']);
36
+
37
+ return $this->verifyTrustlySignedData($method, $uuid, $signature, $data);
38
+ }
39
+
40
+ public function handleResponse($request, $body, $curl) {
41
+ $response = new Trustly_Data_Response($body, $curl);
42
+
43
+ if($this->verifyTrustlySignedResponse($response) !== TRUE) {
44
+ throw new Trustly_SignatureException('Incomming message signature is not valid', $response);
45
+ }
46
+
47
+ return $response;
48
+ }
49
+
50
+ public function insertCredentials($request) {
51
+ $request->set('apikey', $this->api_apikey);
52
+ return TRUE;
53
+ }
54
+
55
+ /* Build an orderline suitable for the payment call using the supplied
56
+ * information. Call once for each line of the order and stuff into an
57
+ * array that is later supplied to the pay() call.
58
+ *
59
+ * Typically:
60
+ * $orderlines = array();
61
+ * $orderlines[] = $api->createOrderline(...);
62
+ * $orderlines[] = $api->createOrderline(...);
63
+ * ...
64
+ * $result = $api->pay(..., $orderlines);
65
+ * */
66
+ public function createOrderline($description=NULL, $amount=NULL,
67
+ $currency=NULL, $vat=NULL, $quantity=1, $eancode=NULL) {
68
+
69
+ $orderline = array();
70
+
71
+ if(isset($description) && strlen($description)) {
72
+ $orderline['description'] = Trustly_Data::ensureUTF8($description);
73
+ }
74
+ if(isset($amount)) {
75
+ $orderline['amount'] = Trustly_Data::ensureUTF8($amount);
76
+ }
77
+ if(isset($currency) && strlen($currency)) {
78
+ $orderline['currency'] = Trustly_Data::ensureUTF8($currency);
79
+ }
80
+ if(isset($vat)) {
81
+ $orderline['vat'] = Trustly_Data::ensureUTF8($vat);
82
+ }
83
+ if(isset($quantity)) {
84
+ $orderline['quantity'] = Trustly_Data::ensureUTF8($quantity);
85
+ }
86
+ if(isset($eancode) && strlen($eancode)) {
87
+ $orderline['eancode'] = Trustly_Data::ensureUTF8($eancode);
88
+ }
89
+
90
+ /* No point in adding a orderline unless we have any usable data */
91
+ if(count($orderline) == 0) {
92
+ return NULL;
93
+ }
94
+
95
+ return $orderline;
96
+ }
97
+
98
+ public function pay($notificationurl, $enduserid, $messageid,
99
+ $locale=NULL, $amount=NULL, $currency=NULL, $country=NULL, $host=NULL,
100
+ $returnurl=NULL, $templateurl=NULL, $urltarget=NULL,
101
+ $email=NULL, $firstname=NULL, $lastname=NULL, $integrationmodule=NULL,
102
+ $orderlines=NULL) {
103
+
104
+ $request = new Trustly_Data_Request('Pay',
105
+ array(
106
+ 'notificationurl' => $notificationurl,
107
+ 'enduserid' => $enduserid,
108
+ 'messageid' => $messageid,
109
+ 'locale' => $locale,
110
+ 'amount' => $amount,
111
+ 'currency' => $currency,
112
+ 'country' => $country,
113
+ 'host' => $host,
114
+ 'returnurl' => $returnurl,
115
+ 'templateurl' => $templateurl,
116
+ 'urltarget' => $urltarget,
117
+ 'email' => $email,
118
+ 'firstname' => $firstname,
119
+ 'lastname' => $lastname,
120
+ 'orderline' => $orderlines,
121
+ 'integrationmodule' => $integrationmodule
122
+ )
123
+ );
124
+ return $this->call($request);
125
+ }
126
+
127
+ public function repay($orderid, $amount, $currency) {
128
+
129
+ $request = new Trustly_Data_Request('Repay',
130
+ array(
131
+ 'orderid' => $orderid,
132
+ 'amount' => $amount,
133
+ 'currency' => $currency
134
+ )
135
+ );
136
+
137
+ return $this->call($request);
138
+ }
139
+
140
+ public function hello() {
141
+ $request = new Trustly_Data_Request('Hello');
142
+ return $this->call($request);
143
+ }
144
+ }
145
+
146
+ ?>
app/code/local/Trustly/Trustly/lib/Trustly/Api/keys/test.trustly.com.public.pem ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
1
+ -----BEGIN PUBLIC KEY-----
2
+ MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAy7h/yX8DEA2m588SrWye
3
+ AC8rTMbErwHt2hoTiP9fte/iOo0FXIZSmNsNu422L+iJyvZQu19ebeL7XgB0UXqt
4
+ zA6KtXBMXIKwuMCZhbdeR8sb7OKbX2nlWM+e2Hmrr9CTfkZkFBeSC+iN9fAU6PoR
5
+ X0i5PWm0uZnaoWXcZnk5CxQCgnfYgsx7xsd8Au+mrqE8SHeT8zi/Inw0Xp6ba25G
6
+ YsZhHfIPD2rcZQOpWbmHRS4Jk4aGzSOBHbAZhKlP97PxoVfUcPI3iCA1+3jMs1l2
7
+ PYsHUbP60NMVwkGPjFOTv4m1a1wKsue0mhspDdvswZUeKE+POGOuewqTQJ+gIhXw
8
+ mQIDAQAB
9
+ -----END PUBLIC KEY-----
app/code/local/Trustly/Trustly/lib/Trustly/Api/keys/trustly.com.public.pem ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
1
+ -----BEGIN PUBLIC KEY-----
2
+ MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAoZhnqiELeoX3QNSg7jpU
3
+ kbLV4BU32LoSMuABAaPdxhpZaccFYud2z4QUlMq/j46vdVDpaCFaCZ+qNT5+tHbQ
4
+ BFgcrx82u7r+aMHvKy4FEczT5aev0NxRlQKHmNQygvp3hNkqeOw4nJy3PoD4cgCp
5
+ SlLTiPOBy2ZsWUHQpSVJdDUiLwAQfNV90jMqa3zq1nTfmTBmd6NR1XAjg5eS6SWr
6
+ to1nVS1b7XKGv7Cc1kt0RVd54tWqoCMDHwEiU0st66BCKdYk3r5woDZxGZUUjVdm
7
+ g9O2xpqRRDcdJGm8HIOVHGSNT9R7LMucH/PGwrfpdWmBDjy0BkuDlssuBgh731l2
8
+ cwIDAQAB
9
+ -----END PUBLIC KEY-----
app/code/local/Trustly/Trustly/lib/Trustly/Api/signed.php ADDED
@@ -0,0 +1,372 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Trustly_Api_Signed extends Trustly_Api {
4
+ var $merchant_privatekey = NULL;
5
+
6
+ function __construct($merchant_privatekeyfile, $username, $password, $host='trustly.com', $port=443, $is_https=TRUE) {
7
+
8
+ parent::__construct($host, $port, $is_https);
9
+
10
+ $this->api_username = $username;
11
+ $this->api_password = $password;
12
+ if($merchant_privatekeyfile != NULL) {
13
+ if($this->loadMerchantPrivateKey($merchant_privatekeyfile) === FALSE) {
14
+
15
+ throw new InvalidArgumentException('Cannot load merchant private key file ' . $merchant_privatekeyfile);
16
+ }
17
+ }
18
+ }
19
+
20
+ /* Load up the merchants key for signing data from the supplied filename.
21
+ * Inializes the internal openssl certificate needed for the signing */
22
+ public function loadMerchantPrivateKey($filename) {
23
+ $cert = @file_get_contents($filename);
24
+ return $this->useMerchantPrivateKey($cert);
25
+ }
26
+
27
+ public function useMerchantPrivateKey($cert) {
28
+ if($cert !== FALSE) {
29
+ $this->merchant_privatekey = openssl_pkey_get_private($cert);
30
+ return TRUE;
31
+ }
32
+ return FALSE;
33
+ }
34
+
35
+ /* Create a signature string suitable for including as the signature in an
36
+ * outgoing request */
37
+ public function signMerchantRequest($request) {
38
+ if(!isset($this->merchant_privatekey)) {
39
+ throw new Trustly_SignatureException('No private key has been loaded for signing');
40
+ }
41
+
42
+ $method = $request->getMethod();
43
+ if($method === NULL) {
44
+ $method = '';
45
+ }
46
+ $uuid = $request->getUUID();
47
+ if($uuid === NULL) {
48
+ $uuid = '';
49
+ }
50
+
51
+ $data = $request->getData();
52
+
53
+ $serial_data = $method . $uuid . $this->serializeData($data);
54
+ $raw_signature = '';
55
+
56
+ $this->clearOpenSSLError();
57
+ if(openssl_sign($serial_data, $raw_signature, $this->merchant_privatekey, OPENSSL_ALGO_SHA1) === TRUE) {
58
+ return base64_encode($raw_signature);
59
+ }
60
+
61
+ throw new Trustly_SignatureException('Failed to sign the outgoing merchant request. '. openssl_error_string());
62
+
63
+ return FALSE;
64
+ }
65
+
66
+ public function insertCredentials($request) {
67
+ $request->setData('Username', $this->api_username);
68
+ $request->setData('Password', $this->api_password);
69
+
70
+ $signature = $this->signMerchantRequest($request);
71
+ if($signature === FALSE) {
72
+ return FALSE;
73
+ }
74
+ $request->setParam('Signature', $signature);
75
+
76
+ return TRUE;
77
+ }
78
+
79
+ public function handleResponse($request, $body, $curl) {
80
+ $response = new Trustly_Data_JSONRPCResponse($body, $curl);
81
+
82
+ if($this->verifyTrustlySignedResponse($response) !== TRUE) {
83
+ throw new Trustly_SignatureException('Incomming message signature is not valid', $response);
84
+ }
85
+
86
+ if($response->getUUID() !== $request->getUUID()) {
87
+ throw new Trustly_DataError('Incoming message is not related to request. UUID mismatch');
88
+ }
89
+
90
+ return $response;
91
+ }
92
+
93
+ public function notificationResponse($request, $success=TRUE) {
94
+ $response = new Trustly_Data_JSONRPCNotificationResponse($request, $success);
95
+
96
+ $signature = $this->signMerchantRequest($response);
97
+ if($signature === FALSE) {
98
+ return FALSE;
99
+ }
100
+ $response->setSignature($signature);
101
+
102
+ return $response;
103
+ }
104
+
105
+ public function urlPath($request=NULL) {
106
+ $url = '/api/1';
107
+ return $url;
108
+ }
109
+
110
+ private function clearOpenSSLError() {
111
+ /* Not really my favourite part of this library implementation. As
112
+ * openssl queues error messages a single call to openssl_error_string
113
+ * after a fail might get another "queued" message from before. And as
114
+ * there is no way to clear the buffer... we will iterate until we will
115
+ * get no more errors. Brilliant. */
116
+ while ($err = openssl_error_string());
117
+ }
118
+
119
+ protected function generateUUID() {
120
+ /* Not the classiest implementation, but to reduce the dependency of
121
+ * non standard libraries we build it this way. The risk of
122
+ * collisions is low enough with a MD5 */
123
+ $md5 = md5(uniqid('', true));
124
+ return substr($md5, 0, 8).'-'.substr($md5, 8, 4).'-'.substr($md5, 12, 4).'-'.substr($md5, 16, 4).'-'.substr($md5, 20, 12);
125
+ }
126
+
127
+ public function call($request) {
128
+ $uuid = $request->getUUID();
129
+ if($uuid === NULL) {
130
+ $request->setUUID($this->generateUUID());
131
+ }
132
+ return parent::call($request);
133
+ }
134
+
135
+ /* Make a deposit call */
136
+ public function deposit($notificationurl, $enduserid, $messageid,
137
+ $locale=NULL, $amount=NULL, $currency=NULL, $country=NULL,
138
+ $mobilephone=NULL, $firstname=NULL, $lastname=NULL,
139
+ $nationalidentificationnumber=NULL, $shopperstatement=NULL,
140
+ $ip=NULL, $successurl=NULL, $failurl=NULL, $templateurl=NULL,
141
+ $urltarget=NULL, $suggestedminamount=NULL, $suggestedmaxamount=NULL,
142
+ $integrationmodule=NULL) {
143
+
144
+ $data = array(
145
+ 'NotificationURL' => $notificationurl,
146
+ 'EndUserID' => $enduserid,
147
+ 'MessageID' => $messageid,
148
+ );
149
+
150
+ $attributes = array(
151
+ 'Locale' => $locale,
152
+ 'Amount' => $amount,
153
+ 'Currency' => $currency,
154
+ 'Country' => $country,
155
+ 'MobilePhone' => $mobilephone,
156
+ 'Firstname' => $firstname,
157
+ 'Lastname' => $lastname,
158
+ 'NationalIdentificationNumber' => $nationalidentificationnumber,
159
+ 'ShopperStatement' => $shopperstatement,
160
+ 'IP' => $ip,
161
+ 'SuccessURL' => $successurl,
162
+ 'FailURL' => $failurl,
163
+ 'TemplateURL' => $templateurl,
164
+ 'URLTarget' => $urltarget,
165
+ 'SuggestedMinAmount' => $suggestedminamount,
166
+ 'SuggestedMaxAmount' => $suggestedmaxamount,
167
+ 'IntegrationModule' => $integrationmodule
168
+ );
169
+
170
+ $request = new Trustly_Data_JSONRPCRequest('Deposit', $data, $attributes);
171
+ return $this->call($request);
172
+ }
173
+
174
+ /* Make a refund call */
175
+ public function refund($orderid, $amount, $currency) {
176
+
177
+ $data = array(
178
+ 'OrderID' => $orderid,
179
+ 'Amount' => $amount,
180
+ 'Currency' => $currency,
181
+ );
182
+
183
+ $request = new Trustly_Data_JSONRPCRequest('Refund', $data);
184
+ return $this->call($request);
185
+ }
186
+
187
+ /* Make a withdraw call */
188
+ public function withdraw($notificationurl, $enduserid, $messageid,
189
+ $locale=NULL, $currency=NULL, $country=NULL,
190
+ $mobilephone=NULL, $firstname=NULL, $lastname=NULL,
191
+ $nationalidentificationnumber=NULL, $clearinghouse=NULL,
192
+ $banknumber=NULL, $accountnumber=NULL) {
193
+
194
+ $data = array(
195
+ 'NotificationURL' => $notificationurl,
196
+ 'EndUserID' => $enduserid,
197
+ 'MessageID' => $messageid,
198
+ 'Currency' => $currency,
199
+ 'Amount' => null
200
+ );
201
+
202
+ $attributes = array(
203
+ 'Locale' => $locale,
204
+ 'Country' => $country,
205
+ 'MobilePhone' => $mobilephone,
206
+ 'Firstname' => $firstname,
207
+ 'Lastname' => $lastname,
208
+ 'NationalIdentificationNumber' => $nationalidentificationnumber,
209
+ 'ClearingHouse' => $clearinghouse,
210
+ 'BankNumber' => $banknumber,
211
+ 'AccountNumber' => $accountnumber,
212
+ );
213
+
214
+ $request = new Trustly_Data_JSONRPCRequest('Withdraw', $data, $attributes);
215
+ return $this->call($request);
216
+ }
217
+
218
+ /* Make an approvewithdrawal call */
219
+ public function approveWithdrawal($orderid) {
220
+
221
+ $data = array(
222
+ 'OrderID' => $orderid,
223
+ );
224
+
225
+ $request = new Trustly_Data_JSONRPCRequest('ApproveWithdrawal', $data);
226
+ return $this->call($request);
227
+ }
228
+
229
+ /* Make an denywithdrawal call */
230
+ public function denyWithdrawal($orderid) {
231
+
232
+ $data = array(
233
+ 'OrderID' => $orderid,
234
+ );
235
+
236
+ $request = new Trustly_Data_JSONRPCRequest('DenyWithdrawal', $data);
237
+ return $this->call($request);
238
+ }
239
+
240
+ /* Make a select account call */
241
+ public function selectAccount($notificationurl, $enduserid, $messageid,
242
+ $locale=NULL, $country=NULL, $firstname=NULL, $lastname=NULL) {
243
+
244
+ $data = array(
245
+ 'NotificationURL' => $notificationurl,
246
+ 'EndUserID' => $enduserid,
247
+ 'MessageID' => $messageid,
248
+ );
249
+
250
+ $attributes = array(
251
+ 'Locale' => $locale,
252
+ 'Country' => $country,
253
+ 'Firstname' => $firstname,
254
+ 'Lastname' => $lastname,
255
+ );
256
+
257
+ $request = new Trustly_Data_JSONRPCRequest('SelectAccount', $data, $attributes);
258
+ return $this->call($request);
259
+ }
260
+
261
+ public function registerAccount($enduserid, $clearinghouse, $banknumber,
262
+ $accountnumber, $firstname, $lastname, $mobilephone=NULL,
263
+ $nationalidentificationnumber=NULL, $address=NULL) {
264
+
265
+ $data = array(
266
+ 'EndUserID' => $enduserid,
267
+ 'ClearingHouse' => $clearinghouse,
268
+ 'BankNumber' => $banknumber,
269
+ 'AccountNumber' => $accountnumber,
270
+ 'Firstname' => $firstname,
271
+ 'Lastname' => $lastname,
272
+ );
273
+
274
+ $attributes = array(
275
+ 'MobilePhone' => $mobilephone,
276
+ 'NationalIdentificationNumber' => $nationalidentificationnumber,
277
+ 'Address' => $address
278
+ );
279
+
280
+ $request = new Trustly_Data_JSONRPCRequest('RegisterAccount', $data, $attributes);
281
+ return $this->call($request);
282
+ }
283
+
284
+ public function accountPayout($notificationurl, $accountid, $enduserid,
285
+ $messageid, $amount, $currency) {
286
+
287
+ $data = array(
288
+ 'NotificationURL' => $notificationurl,
289
+ 'EndUserID' => $enduserid,
290
+ 'MessageID' => $messageid,
291
+ 'AccountID' => $accountid,
292
+ 'Amount' => $amount,
293
+ 'Currency' => $currency,
294
+ );
295
+
296
+ $attributes = array(
297
+ );
298
+
299
+ $request = new Trustly_Data_JSONRPCRequest('AccountPayout', $data, $attributes);
300
+ return $this->call($request);
301
+ }
302
+
303
+ public function p2p($notificationurl, $enduserid, $messageid, $ip,
304
+ $authorizeonly=NULL, $templatedata=NULL, $successurl=NULL,
305
+ $method=NULL, $lastname=NULL, $firstname=NULL, $urltarget=NULL,
306
+ $locale=NULL, $amount=NULL, $currency=NULL, $templateurl=NULL,
307
+ $displaycurrency=NULL) {
308
+
309
+ $data = array(
310
+ 'NotificationURL' => $notificationurl,
311
+ 'EndUserID' => $enduserid,
312
+ 'MessageID' => $messageid
313
+ );
314
+
315
+ $authorizeonly = $this->apiBool($authorizeonly);
316
+
317
+ $attributes = array(
318
+ 'AuthorizeOnly' => $authorizeonly,
319
+ 'TemplateData' => $templatedata,
320
+ 'SuccessURL' => $successurl,
321
+ 'Method' => $method,
322
+ 'Lastname' => $lastname,
323
+ 'Firstname' => $firstname,
324
+ 'URLTarget' => $urltarget,
325
+ 'Locale' => $locale,
326
+ 'Amount' => $amount,
327
+ 'TemplateURL' => $templateurl,
328
+ 'Currency' => $currency,
329
+ 'DisplayCurrency' => $displaycurrency,
330
+ 'IP' => $ip
331
+ );
332
+
333
+ $request = new Trustly_Data_JSONRPCRequest('P2P', $data, $attributes);
334
+ return $this->call($request);
335
+ }
336
+
337
+ public function capture($orderid, $amount, $currency) {
338
+
339
+ $data = array(
340
+ 'OrderID' => $orderid,
341
+ 'Amount' => $amount,
342
+ 'Currency' => $currency
343
+ );
344
+
345
+ $attributes = array(
346
+ );
347
+
348
+ $request = new Trustly_Data_JSONRPCRequest('Capture', $data, $attributes);
349
+ return $this->call($request);
350
+ }
351
+
352
+ public function void($orderid) {
353
+
354
+ $data = array(
355
+ 'OrderID' => $orderid
356
+ );
357
+
358
+ $attributes = array(
359
+ );
360
+
361
+ $request = new Trustly_Data_JSONRPCRequest('Void', $data, $attributes);
362
+ return $this->call($request);
363
+ }
364
+
365
+ public function hello() {
366
+ # The hello call is not signed, use an unsigned API to do the request and then void it
367
+ $api = new Trustly_Api_Unsigned($this->api_username, $this->api_password, $this->api_host, $this->api_port, $this->api_is_https);
368
+ return $api->hello();
369
+ }
370
+ }
371
+
372
+ ?>
app/code/local/Trustly/Trustly/lib/Trustly/Api/unsigned.php ADDED
@@ -0,0 +1,115 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Trustly_Api_Unsigned extends Trustly_Api {
4
+ /* Login criterias when using the unsigned API. Only used by the
5
+ * newSessionCookie() call which is called automatically before the
6
+ * first call */
7
+ var $api_username = NULL;
8
+ var $api_password = NULL;
9
+
10
+ var $session_uuid = NULL;
11
+
12
+ public function __construct($username, $password, $host='trustly.com', $port=443, $is_https=TRUE) {
13
+ parent::__construct($host, $port, $is_https);
14
+
15
+ $this->api_username = $username;
16
+ $this->api_password = $password;
17
+ }
18
+
19
+ public function urlPath($request=NULL) {
20
+ return '/api/Legacy';
21
+ }
22
+
23
+ public function handleResponse($request, $body, $curl) {
24
+ /* No signature here, just build the response object */
25
+ return new Trustly_Data_JSONRPCResponse($body, $curl);
26
+ }
27
+
28
+ public function insertCredentials($request) {
29
+ $request->setParam('Username', $this->api_username);
30
+ if(isset($this->session_uuid)) {
31
+ $request->setParam('Password', $this->session_uuid);
32
+ } else {
33
+ $request->setParam('Password', $this->api_password);
34
+ }
35
+ return TRUE;
36
+ }
37
+
38
+ protected function hasSessionUUID() {
39
+ return (bool)isset($this->session_uuid);
40
+ }
41
+
42
+ /* Call NewSessionCookie to obtain a session cookie we can use for the rest
43
+ * of our calls. This is automatically called when doing a call if we do
44
+ * not have a session. Call manually if needed at session timeout etc.
45
+ * */
46
+ public function newSessionCookie() {
47
+ $this->session_uuid = NULL;
48
+
49
+ $request = new Trustly_Data_JSONRPCRequest('NewSessionCookie');
50
+ /* Call parent directly here as we will attempt to detect the
51
+ * missing session uuid here and call this function if it is not set */
52
+ $response = parent::call($request);
53
+
54
+ if(isset($response)) {
55
+ if($response->isSuccess()) {
56
+ $this->session_uuid = $response->getResult('sessionuuid');
57
+ }
58
+ }
59
+ if(!isset($this->session_uuid)) {
60
+ throw new Trustly_AuthentificationException();
61
+ }
62
+ return $response;
63
+ }
64
+
65
+ /* Utility wrapper around a call() to GetViewStable to simply getting data
66
+ * from a view. */
67
+ public function getViewStable($viewname, $dateorder=NULL, $datestamp=NULL,
68
+ $filterkeys=NULL, $limit=100, $offset=0, $params=NULL, $sortby=NULL,
69
+ $sortorder=NULL) {
70
+
71
+ return $this->call('GetViewStable', array(
72
+ DateOrder => $dateorder,
73
+ Datestamp => $datestamp,
74
+ FilterKeys => $filterkeys,
75
+ Limit => $limit,
76
+ Offset => $offset,
77
+ Params => $params,
78
+ SortBy => $sortby,
79
+ SortOrder => $sortorder,
80
+ ViewName => $viewname,
81
+ ));
82
+ }
83
+
84
+ /* Issue an unsigned API call. As the unsigned API contains a huge array of
85
+ * functions we will use the call() method directly for the majority of
86
+ * operations. The data in params will be matched into the parameters of
87
+ * the outgoing call. Take care when supplying the arguments for the call
88
+ * so they match the function prototype properly. */
89
+ public function call($method, $params=NULL) {
90
+ $request = new Trustly_Data_JSONRPCRequest($method);
91
+
92
+ if(isset($params)) {
93
+ foreach($params as $key => $value) {
94
+ $request->setParam($key, $value);
95
+ }
96
+ }
97
+
98
+ if(!$this->hasSessionUUID()) {
99
+ $this->newSessionCookie();
100
+ }
101
+
102
+ return parent::call($request);
103
+ }
104
+
105
+ public function hello() {
106
+ $request = new Trustly_Data_JSONRPCRequest('Hello');
107
+ /* Call parent directly here we never want to get a new session
108
+ * uuid for just this single call, if we have it use it, but
109
+ * otherwise just live happliy */
110
+ $response = parent::call($request);
111
+
112
+ return $response;
113
+ }
114
+ }
115
+ ?>
app/code/local/Trustly/Trustly/lib/Trustly/Data/data.php ADDED
@@ -0,0 +1,109 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Trustly_Data {
4
+ var $payload = NULL;
5
+
6
+ public function __construct($payload=NULL) {
7
+
8
+ $this->payload = $this->vacuum($payload);
9
+
10
+ if($this->payload === NULL) {
11
+ $this->payload = array();
12
+ }
13
+ }
14
+
15
+ /* Utility function to vacuum the supplied data end remove unset
16
+ * values. This is used to keep the requests cleaner rather then
17
+ * supplying NULL values in the payload */
18
+ public function vacuum($data) {
19
+ if(is_null($data)) {
20
+ return NULL;
21
+ } elseif(is_array($data)) {
22
+ $ret = array();
23
+ foreach($data as $k => $v) {
24
+ $nv = $this->vacuum($v);
25
+ if(isset($nv)) {
26
+ $ret[$k] = $nv;
27
+ }
28
+ }
29
+ if(count($ret)) {
30
+ return $ret;
31
+ }
32
+ return NULL;
33
+ } else {
34
+ return $data;
35
+ }
36
+ }
37
+
38
+ /* Get the specific data value from the payload or the full payload if
39
+ * no value is supplied */
40
+ public function get($name=NULL) {
41
+ if($name === NULL) {
42
+ return $this->payload;
43
+ } else {
44
+ if(isset($this->payload[$name])) {
45
+ return $this->payload[$name];
46
+ }
47
+ }
48
+ return NULL;
49
+ }
50
+
51
+ /* Funciton to ensure that the given value is in UTF8. Used to make sure
52
+ * all outgoing data is properly encoded in the call */
53
+ public static function ensureUTF8($str) {
54
+ if($str == NULL) {
55
+ return NULL;
56
+ }
57
+ $enc = mb_detect_encoding($str, array('ISO-8859-1', 'ISO-8859-15', 'UTF-8', 'ASCII'));
58
+ if($enc !== FALSE) {
59
+ if($enc == 'ISO-8859-1' || $enc == 'ISO-8859-15') {
60
+ $str = mb_convert_encoding($str, 'UTF-8', $enc);
61
+ }
62
+ }
63
+ return $str;
64
+ }
65
+
66
+ /* Set a value in the payload to a given value */
67
+ public function set($name, $value) {
68
+ $this->payload[$name] = Trustly_Data::ensureUTF8($value);
69
+ }
70
+
71
+ /* Get and remove a value from the payload. */
72
+ public function pop($name) {
73
+ $v = NULL;
74
+ if(isset($this->payload[$name])) {
75
+ $v = $this->payload[$name];
76
+ }
77
+ unset($this->payload[$name]);
78
+ return $v;
79
+ }
80
+
81
+ /* Get JSON copy of the payload */
82
+ public function json($pretty=FALSE) {
83
+ if($pretty) {
84
+ $sorted = $this->payload;
85
+ $this->sortRecursive($sorted);
86
+ return json_encode($sorted, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
87
+ } else {
88
+ return json_encode($this->payload);
89
+ }
90
+ }
91
+
92
+ /* Extremely naivly done and does not by far handle all cases, but
93
+ * handles the case it should, i.e. sort the data for the json
94
+ * pretty printer */
95
+ private function sortRecursive(&$data) {
96
+ if(is_array($data)) {
97
+ foreach($data as $k => $v) {
98
+ if(is_array($v)) {
99
+ $this->sortRecursive($v);
100
+ $data[$k] = $v;
101
+ }
102
+ }
103
+ ksort($data);
104
+ }
105
+ }
106
+
107
+ }
108
+
109
+ ?>
app/code/local/Trustly/Trustly/lib/Trustly/Data/jsonrpcnotificationrequest.php ADDED
@@ -0,0 +1,65 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Trustly_Data_JSONRPCNotificationRequest extends Trustly_Data {
4
+ var $notification_body = NULL;
5
+
6
+ public function __construct($notification_body) {
7
+
8
+ $this->notification_body = $notification_body;
9
+ $payload = json_decode($notification_body, TRUE);
10
+
11
+ parent::__construct($payload);
12
+
13
+ if($this->getVersion() != '1.1') {
14
+ throw new Trustly_JSONRPCVersionException('JSON RPC Version '. $this->getVersion() .'is not supported');
15
+ }
16
+ }
17
+
18
+ public function getParams($name=NULL) {
19
+ if(!isset($this->payload['params'])) {
20
+ return NULL;
21
+ }
22
+ $params = $this->payload['params'];
23
+ if(isset($name)) {
24
+ if(isset($params[$name])) {
25
+ return $params[$name];
26
+ }
27
+ } else {
28
+ return $params;
29
+ }
30
+ return NULL;
31
+ }
32
+
33
+ public function getData($name=NULL) {
34
+ if(!isset($this->payload['params']['data'])) {
35
+ return NULL;
36
+ }
37
+ $data = $this->payload['params']['data'];
38
+ if(isset($name)) {
39
+ if(isset($data[$name])) {
40
+ return $data[$name];
41
+ }
42
+ } else {
43
+ return $data;
44
+ }
45
+ return NULL;
46
+ }
47
+
48
+ public function getUUID() {
49
+ return $this->getParams('uuid');
50
+ }
51
+
52
+ public function getMethod() {
53
+ return $this->get('method');
54
+ }
55
+
56
+ public function getSignature() {
57
+ return $this->getParams('signature');
58
+ }
59
+
60
+ public function getVersion() {
61
+ return $this->get('version');
62
+ }
63
+ }
64
+
65
+ ?>
app/code/local/Trustly/Trustly/lib/Trustly/Data/jsonrpcnotificationresponse.php ADDED
@@ -0,0 +1,104 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Trustly_Data_JSONRPCNotificationResponse extends Trustly_Data {
4
+
5
+ public function __construct($request, $success=NULL) {
6
+
7
+ parent::__construct();
8
+
9
+ $uuid = $request->getUUID();
10
+ $method = $request->getMethod();
11
+
12
+ if(isset($uuid)) {
13
+ $this->setResult('uuid', $uuid);
14
+ }
15
+ if(isset($method)) {
16
+ $this->setResult('method', $method);
17
+ }
18
+
19
+ if(isset($success)) {
20
+ $this->setSuccess($success);
21
+ }
22
+
23
+ $this->set('version', '1.1');
24
+ }
25
+
26
+ public function setSuccess($success=NULL) {
27
+ $status = 'OK';
28
+
29
+ if(isset($success) && $success !== TRUE) {
30
+ $status = 'FAILURE';
31
+ }
32
+ $this->setData('status', $status);
33
+ return $success;
34
+ }
35
+
36
+ public function setSignature($signature) {
37
+ $this->setResult('signature', $signature);
38
+ }
39
+
40
+ public function setResult($name, $value) {
41
+ if(!isset($this->payload['result'])) {
42
+ $this->payload['result'] = array();
43
+ }
44
+ $this->payload['result'][$name] = $value;
45
+ return $value;
46
+ }
47
+
48
+ public function getResult($name=NULL) {
49
+ $result = NULL;
50
+ if(isset($this->payload['result'])) {
51
+ $result = $this->payload['result'];
52
+ } else {
53
+ return NULL;
54
+ }
55
+
56
+ if(isset($name)) {
57
+ if(isset($result[$name])) {
58
+ return $result[$name];
59
+ }
60
+ } else {
61
+ return $result;
62
+ }
63
+ }
64
+
65
+ public function getData($name=NULL) {
66
+ $data = NULL;
67
+ if(isset($this->payload['result']['data'])) {
68
+ $data = $this->payload['result']['data'];
69
+ }else {
70
+ return NULL;
71
+ }
72
+
73
+ if(isset($name)) {
74
+ if(isset($data[$name])) {
75
+ return $data[$name];
76
+ }
77
+ } else {
78
+ return $data;
79
+ }
80
+ }
81
+
82
+ public function setData($name, $value) {
83
+ if(!isset($this->payload['result'])) {
84
+ $this->payload['result'] = array();
85
+ }
86
+ if(!isset($this->payload['result']['data'])) {
87
+ $this->payload['result']['data'] = array($name => $value);
88
+ } else {
89
+ $this->payload['result']['data'][$name] = $value;
90
+ }
91
+ return $value;
92
+ }
93
+
94
+ public function getMethod() {
95
+ return $this->getResult('method');
96
+ }
97
+
98
+ public function getUUID() {
99
+ return $this->getResult('uuid');
100
+ }
101
+ }
102
+
103
+
104
+ ?>
app/code/local/Trustly/Trustly/lib/Trustly/Data/jsonrpcrequest.php ADDED
@@ -0,0 +1,127 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Trustly_Data_JSONRPCRequest extends Trustly_Data_Request {
4
+
5
+ public function __construct($method=NULL, $data=NULL, $attributes=NULL) {
6
+ $payload = NULL;
7
+
8
+ if(isset($data) || isset($attributes)) {
9
+ $payload = array('params' => array());
10
+
11
+ if(isset($data)) {
12
+ if(!is_array($data) && isset($attributes)) {
13
+ throw new Trustly_DataException('Data must be array if attributes is provided');
14
+ }
15
+ $payload['params']['Data'] = $data;
16
+ }
17
+
18
+ if(isset($attributes)) {
19
+ if(!isset($payload['params']['Data'])) {
20
+ $payload['params']['Data'] = array();
21
+ }
22
+ $payload['params']['Data']['Attributes'] = $attributes;
23
+ }
24
+ }
25
+
26
+ parent::__construct($method, $payload);
27
+
28
+ if(isset($method)) {
29
+ $this->payload['method'] = $method;
30
+ }
31
+
32
+ if(!isset($this->payload['params'])) {
33
+ $this->payload['params'] = array();
34
+ }
35
+
36
+ $this->set('version', '1.1');
37
+
38
+ }
39
+
40
+ /* Three functions for getting, setting, or getting and removing value
41
+ * in the 'params' section of the request payload */
42
+ public function setParam($name, $value) {
43
+ $this->payload['params'][$name] = Trustly_Data::ensureUTF8($value);
44
+ return $value;
45
+ }
46
+
47
+ public function getParam($name) {
48
+ if(isset($this->payload['params'][$name])) {
49
+ return $this->payload['params'][$name];
50
+ }
51
+ return NULL;
52
+ }
53
+
54
+ public function popParam($name) {
55
+ $v = NULL;
56
+ if(isset($this->payload['params'][$name])) {
57
+ $v = $this->payload['params'][$name];
58
+ }
59
+ unset($this->payload['params'][$name]);
60
+ return $v;
61
+ }
62
+
63
+ public function setUUID($uuid) {
64
+ $this->payload['params']['UUID'] = Trustly_Data::ensureUTF8($uuid);
65
+ return $uuid;
66
+ }
67
+
68
+ public function getUUID() {
69
+ if(isset($this->payload['params']['UUID'])) {
70
+ return $this->payload['params']['UUID'];
71
+ }
72
+ return NULL;
73
+ }
74
+
75
+ public function setMethod($method) {
76
+ return $this->set('method', $method);
77
+ }
78
+
79
+ public function getMethod() {
80
+ return $this->get('method');
81
+ }
82
+
83
+ /* Two utility function for setting or getting data from the
84
+ * 'params'->'Data' part of the payload. */
85
+ public function setData($name, $value) {
86
+ if(!isset($this->payload['params']['Data'])) {
87
+ $this->payload['params']['Data'] = array();
88
+ }
89
+ $this->payload['params']['Data'][$name] = Trustly_Data::ensureUTF8($value);
90
+ return $value;
91
+ }
92
+
93
+ public function getData($name=NULL) {
94
+ if(isset($name)) {
95
+ if(isset($this->payload['params']['Data'][$name])) {
96
+ return $this->payload['params']['Data'][$name];
97
+ }
98
+ } else {
99
+ if(isset($this->payload['params']['Data'])) {
100
+ return $this->payload['params']['Data'];
101
+ }
102
+ }
103
+ return NULL;
104
+ }
105
+
106
+ /* Two utility function for setting or getting data from the
107
+ * 'params'->'Data'->'Attributes' part of the payload. */
108
+ public function setAttribute($name, $value) {
109
+ if(!isset($this->payload['params']['Data'])) {
110
+ $this->payload['params']['Data'] = array();
111
+ }
112
+
113
+ if(!isset($this->payload['params']['Data']['Attributes'])) {
114
+ $this->payload['params']['Data']['Attributes'] = array();
115
+ }
116
+ $this->payload['params']['Data']['Attributes'][$name] = Trustly_Data::ensureUTF8($value);
117
+ return $value;
118
+ }
119
+
120
+ public function getAttribute($name) {
121
+ if(isset($this->payload['params']['Data']['Attributes'][$name])) {
122
+ return $this->payload['params']['Data']['Attributes'][$name];
123
+ }
124
+ return NULL;
125
+ }
126
+ }
127
+ ?>
app/code/local/Trustly/Trustly/lib/Trustly/Data/jsonrpcresponse.php ADDED
@@ -0,0 +1,50 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Trustly_Data_JSONRPCResponse extends Trustly_Data_Response {
4
+
5
+ public function __construct($response_body, $curl) {
6
+ parent::__construct($response_body, $curl);
7
+
8
+ $version = (string)$this->get('version');
9
+ if($version !== '1.1') {
10
+ throw new Trustly_JSONRPCVersionException("JSON RPC Version $version is not supported. " . json_encode($this->payload));
11
+ }
12
+
13
+ if($this->isError()) {
14
+ $this->response_result = $this->response_result['error'];
15
+ }
16
+ }
17
+
18
+ public function getData($name=NULL) {
19
+ $data = NULL;
20
+ if(isset($this->payload['result']['data'])) {
21
+ $data = $this->payload['result']['data'];
22
+ }else {
23
+ return NULL;
24
+ }
25
+
26
+ if(isset($name)) {
27
+ if(isset($data[$name])) {
28
+ return $data[$name];
29
+ }
30
+ } else {
31
+ return $data;
32
+ }
33
+ }
34
+
35
+ public function getErrorCode() {
36
+ if($this->isError() && isset($this->response_result['data']['code'])) {
37
+ return $this->response_result['data']['code'];
38
+ }
39
+ return NULL;
40
+ }
41
+
42
+ public function getErrorMessage() {
43
+ if($this->isError() && isset($this->response_result['data']['message'])) {
44
+ return $this->response_result['data']['message'];
45
+ }
46
+ return NULL;
47
+ }
48
+ }
49
+
50
+ ?>
app/code/local/Trustly/Trustly/lib/Trustly/Data/request.php ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Trustly_Data_Request extends Trustly_Data {
4
+
5
+ var $method = NULL;
6
+
7
+ public function __construct($method=NULL, $payload=NULL) {
8
+
9
+ parent::__construct($payload);
10
+
11
+ $this->method = $method;
12
+ }
13
+
14
+ public function getUUID() {
15
+ if(isset($this->payload['uuid'])) {
16
+ return $this->payload['uuid'];
17
+ }
18
+ return NULL;
19
+ }
20
+
21
+ public function setUUID($uuid) {
22
+ $this->set('uuid', $uuid);
23
+ }
24
+
25
+ public function getMethod() {
26
+ return $this->method;
27
+ }
28
+
29
+ public function setMethod($method) {
30
+ $this->method = $method;
31
+ }
32
+ }
33
+
34
+ ?>
app/code/local/Trustly/Trustly/lib/Trustly/Data/response.php ADDED
@@ -0,0 +1,109 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Trustly_Data_Response extends Trustly_Data {
4
+ /* Raw copy of the incoming response body */
5
+ var $response_body = NULL;
6
+ /* The response HTTP code */
7
+ var $response_code = NULL;
8
+ /* Shortcut to the part of the result being actually interesting. The
9
+ * guts will contain all returned data. */
10
+ var $response_result = NULL;
11
+
12
+ public function __construct($response_body, $curl) {
13
+
14
+ $this->response_code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
15
+ $this->response_body = $response_body;
16
+
17
+ $payload = json_decode($response_body, TRUE);
18
+ if($payload === FALSE) {
19
+ /* Only throw the connection error exception here if we did not
20
+ * receive a valid JSON response, if we did recive one we will use
21
+ * the error information in that response instead. */
22
+ if($this->response_code !== 200) {
23
+ throw new Trustly_ConnectionException('HTTP ' . $this->response_code);
24
+ } else {
25
+ throw new Trustly_DataException('Failed to decode response JSON, reason code ' . json_last_error());
26
+ }
27
+ }
28
+ parent::__construct($payload);
29
+
30
+ /* Attempt to detect the type of the response. A successful call
31
+ * will have a 'result' on toplevel in the payload, while an
32
+ * failure will have a 'error' on the tyoplevel */
33
+ $this->response_result = &$this->payload['result'];
34
+ if($this->response_result === NULL) {
35
+ $this->response_result = &$this->payload['error'];
36
+ if($this->response_result === NULL) {
37
+ throw new Trustly_DataException('No result or error in response');
38
+ }
39
+ }
40
+ }
41
+
42
+ public function isError() {
43
+ if($this->get('error') === NULL) {
44
+ return FALSE;
45
+ }
46
+ return TRUE;
47
+ }
48
+
49
+ public function isSuccess() {
50
+ if($this->get('result') === NULL) {
51
+ return FALSE;
52
+ }
53
+ return TRUE;
54
+ }
55
+
56
+ public function getErrorMessage() {
57
+ if($this->isError()) {
58
+ if(isset($this->response_result['message'])) {
59
+ return $this->response_result['message'];
60
+ }
61
+ }
62
+ return NULL;
63
+ }
64
+
65
+ public function getErrorCode() {
66
+ if($this->isError()) {
67
+ if(isset($this->response_result['code'])) {
68
+ return $this->response_result['code'];
69
+ }
70
+ }
71
+ return NULL;
72
+ }
73
+
74
+ public function getResult($name=NULL) {
75
+ if($name === NULL) {
76
+ # An array is always copied
77
+ return $this->response_result;
78
+ }
79
+
80
+ if(is_array($this->response_result) && isset($this->response_result[$name])) {
81
+ return $this->response_result[$name];
82
+ }
83
+
84
+ return NULL;
85
+ }
86
+
87
+ public function getUUID() {
88
+ if(isset($this->response_result['uuid'])) {
89
+ return $this->response_result['uuid'];
90
+ }
91
+ return NULL;
92
+ }
93
+
94
+ public function getMethod() {
95
+ if(isset($this->response_result['method'])) {
96
+ return $this->response_result['method'];
97
+ }
98
+ return NULL;
99
+ }
100
+
101
+ public function getSignature() {
102
+ if(isset($this->response_result['signature'])) {
103
+ return $this->response_result['signature'];
104
+ }
105
+ return NULL;
106
+ }
107
+ }
108
+
109
+ ?>
app/code/local/Trustly/Trustly/lib/Trustly/exceptions.php ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Trustly_ConnectionException extends Exception { }
4
+
5
+ class Trustly_JSONRPCVersionException extends Exception { }
6
+
7
+ class Trustly_SignatureException extends Exception {
8
+
9
+ public function __construct($message, $data=NULL) {
10
+ parent::__construct($message);
11
+ $this->signature_data = $data;
12
+ }
13
+
14
+ public function getBadData() {
15
+ return $this->signature_data;
16
+ }
17
+ }
18
+
19
+ class Trustly_DataException extends Exception { }
20
+
21
+ class Trustly_AuthentificationException extends Exception { }
22
+
23
+ ?>
app/code/local/Trustly/Trustly/sql/trustly_setup/install-2.0.0.php ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ $installer = $this;
3
+ $installer->startSetup();
4
+ if(!$installer->getConnection()->isTableExists($installer->getTable('trustly/ordermappings'))) {
5
+ $table = $installer->getConnection()->newTable($installer->getTable('trustly/ordermappings'))
6
+ ->addColumn('id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array('unsigned' => true, 'nullable' => false, 'primary' => true, 'identity' => true), 'Dummy id')
7
+ ->addColumn('trustly_order_id', Varien_Db_Ddl_Table::TYPE_BIGINT, null, array('unsigned' => true, 'nullable' => false), 'Trustly Orderid')
8
+ ->addColumn('magento_increment_id', Varien_Db_Ddl_Table::TYPE_BIGINT, null, array('unsigned' => true, 'nullable' => false), 'Magento Increment id')
9
+ ->addColumn('datestamp', Varien_Db_Ddl_Table::TYPE_TIMESTAMP, null, array(), 'Timestamp')
10
+ ->setComment('Mapping between trustly OrderId information and the Magento orders')
11
+ ->addIndex($installer->getIdxName(
12
+ $installer->getTable('trustly/ordermappings'),
13
+ array('trustly_order_id'),
14
+ Varien_Db_Adapter_Interface::INDEX_TYPE_INDEX
15
+ ),
16
+ array('trustly_order_id'),
17
+ array('type' => Varien_Db_Adapter_Interface::INDEX_TYPE_INDEX)
18
+ );
19
+ $installer->getConnection()->createTable($table);
20
+ }
21
+ $installer->endSetup();
22
+ ?>
app/code/local/Trustly/Trustly/sql/trustly_setup/upgrade-1.0.4-2.0.0.php ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ $installer = $this;
3
+ $installer->startSetup();
4
+ $table = $installer->getConnection()->newTable($installer->getTable('trustly/ordermappings'))
5
+ ->addColumn('id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array('unsigned' => true, 'nullable' => false, 'primary' => true, 'identity' => true), 'Dummy id')
6
+ ->addColumn('trustly_order_id', Varien_Db_Ddl_Table::TYPE_BIGINT, null, array('unsigned' => true, 'nullable' => false), 'Trustly Orderid')
7
+ ->addColumn('magento_increment_id', Varien_Db_Ddl_Table::TYPE_BIGINT, null, array('unsigned' => true, 'nullable' => false), 'Magento Increment id')
8
+ ->addColumn('datestamp', Varien_Db_Ddl_Table::TYPE_TIMESTAMP, null, array(), 'Timestamp')
9
+ ->setComment('Mapping between trustly OrderId information and the Magento orders')
10
+ ->addIndex($installer->getIdxName(
11
+ $installer->getTable('trustly/ordermappings'),
12
+ array('trustly_order_id'),
13
+ Varien_Db_Adapter_Interface::INDEX_TYPE_INDEX
14
+ ),
15
+ array('trustly_order_id'),
16
+ array('type' => Varien_Db_Adapter_Interface::INDEX_TYPE_INDEX)
17
+ );
18
+ $installer->getConnection()->createTable($table);
19
+
20
+ $installer->endSetup();
21
+ ?>
app/design/frontend/base/default/layout/trustly.xml ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <layout version="0.1.0">
3
+ <trustly_payment_redirect>
4
+ <reference name="root">
5
+ <action method="setTemplate">
6
+ <template>page/1column.phtml</template>
7
+ </action>
8
+ </reference>
9
+ </trustly_payment_redirect>
10
+ </layout>
app/design/frontend/base/default/template/trustly/form.phtml ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
1
+ <fieldset class="form-list">
2
+ <?php $_code=$this->getMethodCode() ?>
3
+ </fieldset>
4
+ <div id="payment_form_<?php echo $_code ?>" style="display:none;">
5
+ <p class="trustly_title" style="padding-left: 20px; padding-top: 8px; ">
6
+ <?php echo $this->helper('trustly')->__('Trustly is a payment method that allows you to pay with your online bank account. All you need is your regular online bank credentials. It\'s fast, easy and secure!') ?>
7
+ </p>
8
+ </div>
app/design/frontend/base/default/template/trustly/iframe.phtml ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <div class="page-title">
2
+ <h1><?php echo Mage::helper('trustly')->__('Direct bank e-Payments') ?></h1>
3
+ </div>
4
+ <p class="trustly_image"><img src="<?php echo $this->getSkinUrl('images/trustly-big.png'); ?>" alt="Trustly" /><p>
5
+
6
+ <?php if (!$this->getIframe()): ?>
7
+ <p class="note-msg"><?php echo Mage::helper('trustly')->__('Failed to display the payment method.') ?></p>
8
+ <?php else: ?>
9
+ <iframe src="<?php echo $this->getIframe(); ?>" style="min-height: 600px; border: 0; width: 100%; "></iframe>
10
+ <?php endif; ?>
11
+
12
+ <div class="buttons-set">
13
+ <button type="button" title="<?php echo Mage::helper('trustly')->__('Cancel payment') ?>" class="button btn-continue" onclick="setLocation('<?php echo $this->getUrl('trustly/payment/cancel') ?>')"><span><span><?php echo Mage::helper('trustly')->__('Cancel payment') ?></span></span></button>
14
+ </div>
app/design/frontend/base/default/template/trustly/mark.phtml ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
1
+ <img src="<?php echo $this->getSkinUrl('images/trustly-small.png'); ?>" alt="<?php echo Mage::helper('trustly')->__('Trustly') ?>" class="v-middle" />&nbsp;
2
+ <span style="position: relative; top: 3px;">
3
+ <?php echo $this->__('Direct banking') ?>
4
+ <a style="margin-left: 5px;" href="<?php echo $this->getPaymentAcceptanceMarkHref()?>" onclick="javascript:window.open('<?php echo $this->getPaymentAcceptanceMarkHref()?>','whatistrustly','toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=yes, ,left=0, top=0, width=400, height=350'); return false;"><?php echo Mage::helper('trustly')->__('What is Trustly?') ?></a>
5
+ </span>
app/etc/modules/Trustly_Trustly.xml ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <modules>
4
+ <Trustly_Trustly>
5
+ <active>true</active>
6
+ <codePool>local</codePool>
7
+ <depends>
8
+ <Mage_Payment/>
9
+ </depends>
10
+ </Trustly_Trustly>
11
+ </modules>
12
+ </config>
app/locale/da_DK/Trustly_Trustly.csv ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ "Amount expected: %s %s","Amount expected: %s %s"
2
+ "Amount received: %s %s","Amount received: %s %s"
3
+ "Authorized payment.","Authorized payment."
4
+ "Cancel payment","Cancel payment"
5
+ "Cannot connect to Trustly services.","Cannot connect to Trustly services."
6
+ "Cannot find the order %s.","Cannot find the order %s."
7
+ "Cannot find the relation of Trustly order %s for user %s.","Cannot find the relation of Trustly order %s for user %s."
8
+ "Cannot verify the authenticity of Trustly communication.","Cannot verify the authenticity of Trustly communication."
9
+ "Could not connect to Trustly.","Could not connect to Trustly."
10
+ "Credit memo has been created automatically","Credit memo has been created automatically"
11
+ "Date of transaction: %s","Date of transaction: %s"
12
+ "Debit amount: %s %s","Debit amount: %s %s"
13
+ "Direct banking", "Netbank betalinger"
14
+ "Error processing Trustly communication.","Error processing Trustly communication."
15
+ "Example of banks that Trustly can be used with: <br />BBVA, La Caixa, Bankia, Santander, Banco Popular, Sabadell and Banco Pastor","Example of banks that Trustly can be used with: <br />BBVA, La Caixa, Bankia, Santander, Banco Popular, Sabadell and Banco Pastor"
16
+ "Failed to communicate with Trustly.","Failed to communicate with Trustly."
17
+ "Failed to display the payment method.","Failed to display the payment method."
18
+ "Invalid payment.","Invalid payment."
19
+ "Invoiced from Trustly payment","Invoiced from Trustly payment"
20
+ "Invoice for Trustly OrderId #%s created","Invoice for Trustly OrderId #%s created"
21
+ "Invoice: %s","Invoice: %s"
22
+ "It is free and you don’t have to register. You have to have your login details to your online bank to pay with Trustly.","It is free and you don’t have to register. You have to have your login details to your online bank to pay with Trustly."
23
+ "New payment method!","New payment method!"
24
+ "Notification id: %s","Notification id: %s"
25
+ "Payment amount: %s %s","Payment amount: %s %s"
26
+ "Payment failed, debit received.","Payment failed, debit received."
27
+ "Pending payment.","Pending payment."
28
+ "Trustly is a payment method that allows you to pay with your online bank account. All you need is your regular online bank credentials. It's fast, easy and secure!", "Trustly er en betalingsmetode, der gør det muligt for dig at betale med din netbank. Det eneste du har brug for er dine almindelige brugeroplysninger. Det er hurtigt, nemt og sikkert!"
29
+ "Trustly orderid: %s","Trustly orderid: %s"
30
+ "Trustly payment module has not been configured.","Trustly payment module has not been configured."
31
+ "Trustly payment","Trustly payment"
32
+ "Trustly","Trustly"
33
+ "Unable to set payment method.","Unable to set payment method."
34
+ "What is Trustly?","Hvad er Trustly?"
app/locale/en_US/Trustly_Trustly.csv ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ "Amount expected: %s %s","Amount expected: %s %s"
2
+ "Amount received: %s %s","Amount received: %s %s"
3
+ "Authorized payment.","Authorized payment."
4
+ "Cancel payment","Cancel payment"
5
+ "Cannot connect to Trustly services.","Cannot connect to Trustly services."
6
+ "Cannot find the order %s.","Cannot find the order %s."
7
+ "Cannot find the relation of Trustly order %s for user %s.","Cannot find the relation of Trustly order %s for user %s."
8
+ "Cannot verify the authenticity of Trustly communication.","Cannot verify the authenticity of Trustly communication."
9
+ "Could not connect to Trustly.","Could not connect to Trustly."
10
+ "Credit memo has been created automatically","Credit memo has been created automatically"
11
+ "Date of transaction: %s","Date of transaction: %s"
12
+ "Debit amount: %s %s","Debit amount: %s %s"
13
+ "Direct banking", "Direct banking"
14
+ "Error processing Trustly communication.","Error processing Trustly communication."
15
+ "Example of banks that Trustly can be used with: <br />BBVA, La Caixa, Bankia, Santander, Banco Popular, Sabadell and Banco Pastor","Example of banks that Trustly can be used with: <br />BBVA, La Caixa, Bankia, Santander, Banco Popular, Sabadell and Banco Pastor"
16
+ "Failed to communicate with Trustly.","Failed to communicate with Trustly."
17
+ "Failed to display the payment method.","Failed to display the payment method."
18
+ "Invalid payment.","Invalid payment."
19
+ "Invoiced from Trustly payment","Invoiced from Trustly payment"
20
+ "Invoice for Trustly OrderId #%s created","Invoice for Trustly OrderId #%s created"
21
+ "Invoice: %s","Invoice: %s"
22
+ "It is free and you don’t have to register. You have to have your login details to your online bank to pay with Trustly.","It is free and you don’t have to register. You have to have your login details to your online bank to pay with Trustly."
23
+ "New payment method!","New payment method!"
24
+ "Notification id: %s","Notification id: %s"
25
+ "Payment amount: %s %s","Payment amount: %s %s"
26
+ "Payment failed, debit received.","Payment failed, debit received."
27
+ "Pending payment.","Pending payment."
28
+ "Trustly is a payment method that allows you to pay with your online bank account. All you need is your regular online bank credentials. It's fast, easy and secure!", "Trustly is a payment method that allows you to pay with your online bank account. All you need is your regular online bank credentials. It's fast, easy and secure!"
29
+ "Trustly orderid: %s","Trustly orderid: %s"
30
+ "Trustly payment module has not been configured.","Trustly payment module has not been configured."
31
+ "Trustly payment","Trustly payment"
32
+ "Trustly","Trustly"
33
+ "Unable to set payment method.","Unable to set payment method."
34
+ "What is Trustly?","What is Trustly?"
app/locale/es_ES/Trustly_Trustly.csv ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ "Amount expected: %s %s","Cantidad esperada: %s %s"
2
+ "Amount received: %s %s", "Cantidad recibida: %s %s"
3
+ "Authorized payment.", "Pago autorizado."
4
+ "Cancel payment", "Cancelar pago"
5
+ "Cannot connect to Trustly services.","No se puede conectar a Trustly."
6
+ "Cannot find the order %s.", "No se ha encontrado el pedido %s."
7
+ "Cannot find the relation of Trustly order %s for user %s.","No se puede encontrar la relación de la orden de Trustly %s para el usuario %s."
8
+ "Cannot verify the authenticity of Trustly communication.","No se puede verificar la autenticidad de la comunicación con Trustly."
9
+ "Could not connect to Trustly.", "No se ha podido conectar con Trustly."
10
+ "Credit memo has been created automatically","La nota de crédito ha sido creado de forma automática"
11
+ "Date of transaction: %s", "Fecha de operación: %s"
12
+ "Debit amount: %s %s","Cantidad abonada: %s %s"
13
+ "Direct banking", "Transferencia online"
14
+ "Error processing Trustly communication.", "Error en el proceso."
15
+ "Example of banks that Trustly can be used with: <br />BBVA, La Caixa, Bankia, Santander, Banco Popular, Sabadell and Banco Pastor", "Ejemplos de bancos disponibles con Trustly: <br /> BBVA, Santander, La Caixa, Bankia, Sabadell, Banco Popular y Banco Pastor."
16
+ "Failed to communicate with Trustly.","Error al comunicarse con Trustly."
17
+ "Failed to display the payment method.", "Ha ocurrido un error al mostrar el m&eacute;todo de pago."
18
+ "Invalid payment.", "Pago no v&aacute;lido."
19
+ "Invoiced from Trustly payment","Facturado con Trustly"
20
+ "Invoice for Trustly OrderId #%s created","Factura para la OrderId #%s de Trustly creada"
21
+ "Invoice: %s","Factura: %s"
22
+ "It is free and you don’t have to register. You have to have your login details to your online bank to pay with Trustly.", "Servicio gratuito y sin necesidad de registrarse. Necesitas tus datos de acceso a tu banca online para pagar con Trustly."
23
+ "New payment method!", "&iexcl;Nuevo m&eacute;todo de pago!"
24
+ "Notification id: %s","Identificador de la notificación: %s"
25
+ "Payment amount: %s %s", "Cantidad transferida: %s %s"
26
+ "Payment failed, debit received.","Error en el pago, abono recibido."
27
+ "Pending payment.","Pago pendiente."
28
+ "Trustly is a payment method that allows you to pay with your online bank account. All you need is your regular online bank credentials. It's fast, easy and secure!", "Trustly es el método de pago seguro que te permite pagar directamente desde tu banca online. Todo lo que necesitas son las contraseñas habituales de tu cuenta. ¡Es fácil, rapido y seguro!"
29
+ "Trustly","Trustly"
30
+ "Trustly orderid: %s","Trustly orderid: %s"
31
+ "Trustly payment","Pago con Trustly"
32
+ "Trustly payment module has not been configured.","El módulo de pago de Trustly no se ha configurado."
33
+ "Unable to set payment method.","No se puede establecer la forma de pago."
34
+ "What is Trustly?", "¿Qué es Trustly?"
app/locale/et_EE/Trustly_Trustly.csv ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ "Amount expected: %s %s","Amount expected: %s %s"
2
+ "Amount received: %s %s","Amount received: %s %s"
3
+ "Authorized payment.","Authorized payment."
4
+ "Cancel payment","Cancel payment"
5
+ "Cannot connect to Trustly services.","Cannot connect to Trustly services."
6
+ "Cannot find the order %s.","Cannot find the order %s."
7
+ "Cannot find the relation of Trustly order %s for user %s.","Cannot find the relation of Trustly order %s for user %s."
8
+ "Cannot verify the authenticity of Trustly communication.","Cannot verify the authenticity of Trustly communication."
9
+ "Could not connect to Trustly.","Could not connect to Trustly."
10
+ "Credit memo has been created automatically","Credit memo has been created automatically"
11
+ "Date of transaction: %s","Date of transaction: %s"
12
+ "Debit amount: %s %s","Debit amount: %s %s"
13
+ "Direct banking", "Otsepangandus"
14
+ "Error processing Trustly communication.","Error processing Trustly communication."
15
+ "Example of banks that Trustly can be used with: <br />BBVA, La Caixa, Bankia, Santander, Banco Popular, Sabadell and Banco Pastor","Example of banks that Trustly can be used with: <br />BBVA, La Caixa, Bankia, Santander, Banco Popular, Sabadell and Banco Pastor"
16
+ "Failed to communicate with Trustly.","Failed to communicate with Trustly."
17
+ "Failed to display the payment method.","Failed to display the payment method."
18
+ "Invalid payment.","Invalid payment."
19
+ "Invoiced from Trustly payment","Invoiced from Trustly payment"
20
+ "Invoice for Trustly OrderId #%s created","Invoice for Trustly OrderId #%s created"
21
+ "Invoice: %s","Invoice: %s"
22
+ "It is free and you don’t have to register. You have to have your login details to your online bank to pay with Trustly.","It is free and you don’t have to register. You have to have your login details to your online bank to pay with Trustly."
23
+ "New payment method!","New payment method!"
24
+ "Notification id: %s","Notification id: %s"
25
+ "Payment amount: %s %s","Payment amount: %s %s"
26
+ "Payment failed, debit received.","Payment failed, debit received."
27
+ "Pending payment.","Pending payment."
28
+ "Trustly is a payment method that allows you to pay with your online bank account. All you need is your regular online bank credentials. It's fast, easy and secure!", "Trustly on maksemeetod, mis võimaldab teil oma internetipanga kontolt otse maksta. Kõik, mida vajate, on internetipanga tavalised kasutajatunnused. See on kiire, lihtne ja turvaline!"
29
+ "Trustly orderid: %s","Trustly orderid: %s"
30
+ "Trustly payment module has not been configured.","Trustly payment module has not been configured."
31
+ "Trustly payment","Trustly payment"
32
+ "Trustly","Trustly"
33
+ "Unable to set payment method.","Unable to set payment method."
34
+ "What is Trustly?","Mis on Trustly?"
app/locale/fi_FI/Trustly_Trustly.csv ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ "Amount expected: %s %s","Amount expected: %s %s"
2
+ "Amount received: %s %s","Amount received: %s %s"
3
+ "Authorized payment.","Authorized payment."
4
+ "Cancel payment","Cancel payment"
5
+ "Cannot connect to Trustly services.","Cannot connect to Trustly services."
6
+ "Cannot find the order %s.","Cannot find the order %s."
7
+ "Cannot find the relation of Trustly order %s for user %s.","Cannot find the relation of Trustly order %s for user %s."
8
+ "Cannot verify the authenticity of Trustly communication.","Cannot verify the authenticity of Trustly communication."
9
+ "Could not connect to Trustly.","Could not connect to Trustly."
10
+ "Credit memo has been created automatically","Credit memo has been created automatically"
11
+ "Date of transaction: %s","Date of transaction: %s"
12
+ "Debit amount: %s %s","Debit amount: %s %s"
13
+ "Direct banking", "Verkkopankkimaksu"
14
+ "Error processing Trustly communication.","Error processing Trustly communication."
15
+ "Example of banks that Trustly can be used with: <br />BBVA, La Caixa, Bankia, Santander, Banco Popular, Sabadell and Banco Pastor","Example of banks that Trustly can be used with: <br />BBVA, La Caixa, Bankia, Santander, Banco Popular, Sabadell and Banco Pastor"
16
+ "Failed to communicate with Trustly.","Failed to communicate with Trustly."
17
+ "Failed to display the payment method.","Failed to display the payment method."
18
+ "Invalid payment.","Invalid payment."
19
+ "Invoiced from Trustly payment","Invoiced from Trustly payment"
20
+ "Invoice for Trustly OrderId #%s created","Invoice for Trustly OrderId #%s created"
21
+ "Invoice: %s","Invoice: %s"
22
+ "It is free and you don’t have to register. You have to have your login details to your online bank to pay with Trustly.","It is free and you don’t have to register. You have to have your login details to your online bank to pay with Trustly."
23
+ "New payment method!","New payment method!"
24
+ "Notification id: %s","Notification id: %s"
25
+ "Payment amount: %s %s","Payment amount: %s %s"
26
+ "Payment failed, debit received.","Payment failed, debit received."
27
+ "Pending payment.","Pending payment."
28
+ "Trustly is a payment method that allows you to pay with your online bank account. All you need is your regular online bank credentials. It's fast, easy and secure!", "Trustly on maksutapa, joka mahdollistaa maksamisen nettipankillasi. Tarvitset vain tavalliset sisäänkirjautumistietosi. Maksaminen on nopeaa, helppoa ja turvallista!"
29
+ "Trustly orderid: %s","Trustly orderid: %s"
30
+ "Trustly payment module has not been configured.","Trustly payment module has not been configured."
31
+ "Trustly payment","Trustly payment"
32
+ "Trustly","Trustly"
33
+ "Unable to set payment method.","Unable to set payment method."
34
+ "What is Trustly?","Mikä on Trustly?"
app/locale/pl_PL/Trustly_Trustly.csv ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ "Amount expected: %s %s","Amount expected: %s %s"
2
+ "Amount received: %s %s","Amount received: %s %s"
3
+ "Authorized payment.","Authorized payment."
4
+ "Cancel payment","Cancel payment"
5
+ "Cannot connect to Trustly services.","Cannot connect to Trustly services."
6
+ "Cannot find the order %s.","Cannot find the order %s."
7
+ "Cannot find the relation of Trustly order %s for user %s.","Cannot find the relation of Trustly order %s for user %s."
8
+ "Cannot verify the authenticity of Trustly communication.","Cannot verify the authenticity of Trustly communication."
9
+ "Could not connect to Trustly.","Could not connect to Trustly."
10
+ "Credit memo has been created automatically","Credit memo has been created automatically"
11
+ "Date of transaction: %s","Date of transaction: %s"
12
+ "Debit amount: %s %s","Debit amount: %s %s"
13
+ "Direct banking", "Bezposredni przelew przez bank"
14
+ "Error processing Trustly communication.","Error processing Trustly communication."
15
+ "Example of banks that Trustly can be used with: <br />BBVA, La Caixa, Bankia, Santander, Banco Popular, Sabadell and Banco Pastor","Example of banks that Trustly can be used with: <br />BBVA, La Caixa, Bankia, Santander, Banco Popular, Sabadell and Banco Pastor"
16
+ "Failed to communicate with Trustly.","Failed to communicate with Trustly."
17
+ "Failed to display the payment method.","Failed to display the payment method."
18
+ "Invalid payment.","Invalid payment."
19
+ "Invoiced from Trustly payment","Invoiced from Trustly payment"
20
+ "Invoice for Trustly OrderId #%s created","Invoice for Trustly OrderId #%s created"
21
+ "Invoice: %s","Invoice: %s"
22
+ "It is free and you don’t have to register. You have to have your login details to your online bank to pay with Trustly.","It is free and you don’t have to register. You have to have your login details to your online bank to pay with Trustly."
23
+ "New payment method!","New payment method!"
24
+ "Notification id: %s","Notification id: %s"
25
+ "Payment amount: %s %s","Payment amount: %s %s"
26
+ "Payment failed, debit received.","Payment failed, debit received."
27
+ "Pending payment.","Pending payment."
28
+ "Trustly is a payment method that allows you to pay with your online bank account. All you need is your regular online bank credentials. It's fast, easy and secure!", "Trastly jest to wygodna forma oplaty przez internetbank. Jedyne, co konieczne to zalogowanie sie. Jest to szybkie, latwe i bezpieczne!"
29
+ "Trustly orderid: %s","Trustly orderid: %s"
30
+ "Trustly payment module has not been configured.","Trustly payment module has not been configured."
31
+ "Trustly payment","Trustly payment"
32
+ "Trustly","Trustly"
33
+ "Unable to set payment method.","Unable to set payment method."
34
+ "What is Trustly?","Co to jest Trustly?"
app/locale/sv_SE/Trustly_Trustly.csv ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ "Amount expected: %s %s", "Förväntad summa: %s %s"
2
+ "Amount received: %s", "Mottagen betalning: %s %s"
3
+ "Authorized payment.", "Godkänd betalning."
4
+ "Cancel payment", "Avbryt betalningen"
5
+ "Cannot connect to Trustly services.", "Kan inte ansluta till Trustly's tjänster."
6
+ "Cannot find the order %s.", "Kunde inte hitta order %s"
7
+ "Cannot find the relation of Trustly order %s for user %s.", "Kan inte hitta en relation till Trustly's order %s för användaren %s"
8
+ "Cannot verify the authenticity of Trustly communication.", "Kan inte säkerställa äktheten i svaren från Trustly."
9
+ "Could not connect to Trustly.", "Kunde inte ansluta till Trustly"
10
+ "Credit memo has been created automatically", "Kredit-memo har skapats automatiskt"
11
+ "Date of transaction: %s", "Transaktionsdatum: %s"
12
+ "Debit amount: %s %s", "Debit summa: %s %s"
13
+ "Direct banking", "Direktbank"
14
+ "Error processing Trustly communication.", "Kunde inte tolka kommunikationen från Trustly"
15
+ "Example of banks that Trustly can be used with: <br />BBVA, La Caixa, Bankia, Santander, Banco Popular, Sabadell and Banco Pastor", "Exempel på banker som Trustly kan användas med: <br />Swedbank, Handelsbanken, SEB, Forex och Icabanken."
16
+ "Failed to communicate with Trustly.", "Misslyckades att kommunicera med Trustly."
17
+ "Failed to display the payment method.", "Kunde inte visa betalningsmetoden."
18
+ "Invalid payment.", "Ogiltig betalning"
19
+ "Invoiced from Trustly payment", "Fakturerad från Trustly betalning."
20
+ "Invoice for Trustly OrderId #%s created", "Faktura för Trustly OrderId #%s skapad"
21
+ "Invoice: %s", "Faktura: %s"
22
+ "It is free and you don’t have to register. You have to have your login details to your online bank to pay with Trustly.", "Det är gratis och du behöver inte registrera dig. Du måste ha dina inloggningsuppgifter till din Internetbank för att betala med Trustly."
23
+ "New payment method!", "Ny betalnings metod!"
24
+ "Notification id: %s", "Notifieringsid: %s"
25
+ "Payment amount: %s", "Betalning: %s %s"
26
+ "Payment failed, debit received.", "Betalningen misslyckades, debitering mottagen."
27
+ "Pending payment.", "Inkommande betalning."
28
+ "Trustly is a payment method that allows you to pay with your online bank account. All you need is your regular online bank credentials. It's fast, easy and secure!", "Trustly är en betalningsmetod som gör det möjligt att betala med din internetbank. Allt du behöver är dina vanliga inloggningsuppgifter. Det är snabbt, enkelt och säkert!"
29
+ "Trustly orderid: %s", "Trustly OrderId: %s"
30
+ "Trustly payment module has not been configured.","Betalningsmodulen för Trustly har inte blivit konfigurerad."
31
+ "Trustly payment", "Trustly betalning"
32
+ "Trustly", "Trustly"
33
+ "Unable to set payment method.", "Kan inte aktivera betalningsmetoden"
34
+ "What is Trustly?", "Vad är Trustly?"
package.xml ADDED
@@ -0,0 +1,178 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <package>
3
+ <name>Trustly</name>
4
+ <version>2.0.2</version>
5
+ <stability>stable</stability>
6
+ <license uri="http://www.gnu.org/copyleft/gpl.html">GPL 3</license>
7
+ <channel>community</channel>
8
+ <extends/>
9
+ <summary>Magento module for integration of the Trustly payment method.</summary>
10
+ <description>Magento module for integration of the Trustly payment method.</description>
11
+ <notes></notes>
12
+ <authors>
13
+ <author>
14
+ <name>Trustly</name>
15
+ <user>Trustly</user>
16
+ <email>info@trustly.com</email>
17
+ </author>
18
+ </authors>
19
+ <date>2014-05-27</date>
20
+ <time>10:29:14</time>
21
+ <contents>
22
+ <target name="magelocale">
23
+ <dir name="da_DK">
24
+ <file name="Trustly_Trustly.csv" hash="bdd0d2cbbffee4ab2f268e90de6178a4"/>
25
+ </dir>
26
+ <dir name="en_US">
27
+ <file name="Trustly_Trustly.csv" hash="bb2c3acdfadaa8bab74f6b934501c70e"/>
28
+ </dir>
29
+ <dir name="es_ES">
30
+ <file name="Trustly_Trustly.csv" hash="37f85a0f00431a0d4095b8e29faaf7fb"/>
31
+ </dir>
32
+ <dir name="et_EE">
33
+ <file name="Trustly_Trustly.csv" hash="5ac7fbc6a05c01ae4d87c3116b828c11"/>
34
+ </dir>
35
+ <dir name="fi_FI">
36
+ <file name="Trustly_Trustly.csv" hash="e6d83466916e8e9c3710a943d0b386d3"/>
37
+ </dir>
38
+ <dir name="pl_PL">
39
+ <file name="Trustly_Trustly.csv" hash="4f05bfa243336c0622bb76f8d3e190e9"/>
40
+ </dir>
41
+ <dir name="sv_SE">
42
+ <file name="Trustly_Trustly.csv" hash="ad3a76426cbb097590ed90b53052391d"/>
43
+ </dir>
44
+ </target>
45
+ <target name="magelocal">
46
+ <dir name="Trustly">
47
+ <dir name="Trustly">
48
+ <dir name="Block">
49
+ <dir name="System">
50
+ <dir name="Config">
51
+ <file name="About.php" hash="4a3f439de6a55140019c06ceebe478e7"/>
52
+ </dir>
53
+ </dir>
54
+ <file name="Form.php" hash="b39bb8b1c64a5b85ce9efafd67c9be93"/>
55
+ <file name="Redirect.php" hash="26a0edaf05b92587a7496295eeabd459"/>
56
+ </dir>
57
+ <dir name="Helper">
58
+ <file name="Data.php" hash="7d3cd49f938d49e96aabfb9aaff90948"/>
59
+ </dir>
60
+ <dir name="Model">
61
+ <dir name="Mysql4">
62
+ <file name="Ordermappings.php" hash="c9dd983701fc530c449fd291752a3fe7"/>
63
+ </dir>
64
+ <file name="Ordermappings.php" hash="e6c2780307ea63c1572b2851ec5664d8"/>
65
+ <file name="Standard.php" hash="3cdbe677cb889c86f14c2522579133b1"/>
66
+ </dir>
67
+ <dir name="controllers">
68
+ <file name="PaymentController.php" hash="e00d81b479dd16a68b90a71cc810bf92"/>
69
+ </dir>
70
+ <dir name="etc">
71
+ <file name="config.xml" hash="e6bb8b50f799aca2d4e61887216b07de"/>
72
+ <file name="system.xml" hash="28993e0c9c79829b12cbcea209967be4"/>
73
+ </dir>
74
+ <dir name="lib">
75
+ <dir name="Trustly">
76
+ <dir name="Api">
77
+ <dir name="keys">
78
+ <file name="test.trustly.com.public.pem" hash="e61b3f9fc1e3893282fe2d575dc5571a"/>
79
+ <file name="trustly.com.public.pem" hash="b2c821ad10c085a40b6c4e36ee6b8c9e"/>
80
+ </dir>
81
+ <file name="api.php" hash="2ea7e226b2e13f0f4bee7048d2ac9d88"/>
82
+ <file name="ecommerce.php" hash="6a52360de0ae7aaf313058e141f0cdae"/>
83
+ <file name="signed.php" hash="3f8b3206f6050bf9d1c9d2b22c6f7ed6"/>
84
+ <file name="unsigned.php" hash="2f25273f6aa94e776c5b01486eaf1450"/>
85
+ </dir>
86
+ <dir name="Data">
87
+ <file name="data.php" hash="6d30d0f50d65a63ea41ce450011c4c90"/>
88
+ <file name="jsonrpcnotificationrequest.php" hash="c73767f1c08074d88e91b74172708685"/>
89
+ <file name="jsonrpcnotificationresponse.php" hash="c1742dda1252c218c59b43d97f331aa2"/>
90
+ <file name="jsonrpcrequest.php" hash="0d8a0019eea8d4a1f2fe8cd3b4c92318"/>
91
+ <file name="jsonrpcresponse.php" hash="49928cfd29327e0107dc5b8dca5a030b"/>
92
+ <file name="request.php" hash="c3641942bd271784485a91de68390f59"/>
93
+ <file name="response.php" hash="c4d2ef0fc91fc49a111dbcfa28135138"/>
94
+ </dir>
95
+ <file name="exceptions.php" hash="7a51e14965e1c0b1998d347a1638bf68"/>
96
+ </dir>
97
+ <file name="Trustly.php" hash="84ab59b5cd271ec5d3c94f103e556c7f"/>
98
+ </dir>
99
+ <dir name="sql">
100
+ <dir name="trustly_setup">
101
+ <file name="install-2.0.0.php" hash="65bd1283d4a04825428b27a7c48a3b14"/>
102
+ <file name="upgrade-1.0.4-2.0.0.php" hash="2badbe7703f9416f88f0a9cf458a8b5e"/>
103
+ </dir>
104
+ </dir>
105
+ </dir>
106
+ </dir>
107
+ </target>
108
+ <target name="mageetc">
109
+ <dir name="modules">
110
+ <file name="Trustly_Trustly.xml" hash="f1b375e9b2b81c89f37bd041b4762317"/>
111
+ </dir>
112
+ </target>
113
+ <target name="mageskin">
114
+ <dir name="frontend">
115
+ <dir name="default">
116
+ <dir name="default">
117
+ <dir name="images">
118
+ <file name="trustly-big.png" hash="ace4a2fcd8306b7e5835076340c7877b"/>
119
+ <file name="trustly-small.png" hash="f99283dadd49b60e6a68962eda43f83f"/>
120
+ </dir>
121
+ </dir>
122
+ </dir>
123
+ </dir>
124
+ </target>
125
+ <target name="magedesign">
126
+ <dir name="frontend">
127
+ <dir name="base">
128
+ <dir name="default">
129
+ <dir name="layout">
130
+ <file name="trustly.xml" hash="defb5e5450f4f02d4bf8c53fd7fac3ef"/>
131
+ </dir>
132
+ <dir name="template">
133
+ <dir name="trustly">
134
+ <file name="form.phtml" hash="f37a2b86d35eea0a8cd6ec176d466424"/>
135
+ <file name="iframe.phtml" hash="65aaad9584f8ba4344f3b836ca08c6de"/>
136
+ <file name="mark.phtml" hash="76011840449ff5067311d2f2987bdd7d"/>
137
+ </dir>
138
+ </dir>
139
+ </dir>
140
+ </dir>
141
+ </dir>
142
+ </target>
143
+ </contents>
144
+ <compatible/>
145
+ <dependencies>
146
+ <required>
147
+ <php>
148
+ <min>5.2.0</min>
149
+ <max>6.0.0</max>
150
+ </php>
151
+ <extension>
152
+ <name>curl</name>
153
+ <min/>
154
+ <max/>
155
+ </extension>
156
+ <extension>
157
+ <name>openssl</name>
158
+ <min/>
159
+ <max/>
160
+ </extension>
161
+ <extension>
162
+ <name>mbstring</name>
163
+ <min/>
164
+ <max/>
165
+ </extension>
166
+ <extension>
167
+ <name>bcmath</name>
168
+ <min/>
169
+ <max/>
170
+ </extension>
171
+ <extension>
172
+ <name>json</name>
173
+ <min/>
174
+ <max/>
175
+ </extension>
176
+ </required>
177
+ </dependencies>
178
+ </package>
skin/frontend/default/default/images/trustly-big.png ADDED
Binary file
skin/frontend/default/default/images/trustly-small.png ADDED
Binary file