Trustly - Version 2.0.8

Version Notes

Download this release

Release Info

Developer Trustly
Extension Trustly
Version 2.0.8
Comparing to
See all releases


Code changes from version 2.0.7 to 2.0.8

Files changed (27) hide show
  1. app/code/community/Trustly/Trustly/Model/Mysql4/Ordermappings.php +6 -6
  2. app/code/community/Trustly/Trustly/Model/Ordermappings.php +2 -2
  3. app/code/community/Trustly/Trustly/Model/Standard.php +4 -4
  4. app/code/community/Trustly/Trustly/controllers/PaymentController.php +32 -30
  5. app/code/community/Trustly/Trustly/etc/config.xml +1 -1
  6. app/code/community/Trustly/Trustly/lib/Trustly.php +7 -6
  7. app/code/community/Trustly/Trustly/lib/Trustly/Api/api.php +72 -31
  8. app/code/community/Trustly/Trustly/lib/Trustly/Api/ecommerce.php +17 -18
  9. app/code/community/Trustly/Trustly/lib/Trustly/Api/signed.php +59 -57
  10. app/code/community/Trustly/Trustly/lib/Trustly/Api/unsigned.php +31 -31
  11. app/code/community/Trustly/Trustly/lib/Trustly/Data/data.php +12 -13
  12. app/code/community/Trustly/Trustly/lib/Trustly/Data/jsonrpcnotificationrequest.php +6 -7
  13. app/code/community/Trustly/Trustly/lib/Trustly/Data/jsonrpcnotificationresponse.php +6 -8
  14. app/code/community/Trustly/Trustly/lib/Trustly/Data/jsonrpcrequest.php +9 -9
  15. app/code/community/Trustly/Trustly/lib/Trustly/Data/jsonrpcresponse.php +33 -31
  16. app/code/community/Trustly/Trustly/lib/Trustly/Data/jsonrpcsignedresponse.php +102 -0
  17. app/code/community/Trustly/Trustly/lib/Trustly/Data/request.php +6 -7
  18. app/code/community/Trustly/Trustly/lib/Trustly/Data/response.php +12 -13
  19. app/code/community/Trustly/Trustly/lib/Trustly/exceptions.php +6 -6
  20. app/code/community/Trustly/Trustly/sql/trustly_setup/install-2.0.4.php +2 -2
  21. app/code/community/Trustly/Trustly/sql/trustly_setup/upgrade-1.0.5-2.0.0.php +2 -2
  22. app/code/community/Trustly/Trustly/sql/trustly_setup/upgrade-2.0.3-2.0.4.php +4 -4
  23. app/design/frontend/base/default/template/trustly/iframe.phtml +1 -1
  24. app/design/frontend/base/default/template/trustly/mark.phtml +1 -1
  25. package.xml +27 -36
  26. skin/frontend/base/default/images/trustly-big.png +0 -0
  27. skin/frontend/base/default/images/trustly-small.png +0 -0
app/code/community/Trustly/Trustly/Model/Mysql4/Ordermappings.php CHANGED
@@ -28,12 +28,12 @@ class Trustly_Trustly_Model_Mysql4_Ordermappings extends Mage_Core_Model_Mysql4_
28
 
29
  protected function _construct()
30
  {
31
- # This is a bit silly, I would ragther here use the
32
- # truslty_order_id as the primary key for this table, but as magento
33
- # will promptly do an update rather then an insert if the primary key
34
- # for the table is set (as it will be when we insert new records) i
35
- # need to invent a dummy id that is generated and never used. It also
36
- # borks the ->load method as useless for me. Thank you for this
37
  # abstraction...
38
  $this->_init('trustly/ordermappings', 'id');
39
  }
28
 
29
  protected function _construct()
30
  {
31
+ # This is a bit silly, I would ragther here use the
32
+ # truslty_order_id as the primary key for this table, but as magento
33
+ # will promptly do an update rather then an insert if the primary key
34
+ # for the table is set (as it will be when we insert new records) i
35
+ # need to invent a dummy id that is generated and never used. It also
36
+ # borks the ->load method as useless for me. Thank you for this
37
  # abstraction...
38
  $this->_init('trustly/ordermappings', 'id');
39
  }
app/code/community/Trustly/Trustly/Model/Ordermappings.php CHANGED
@@ -24,12 +24,12 @@
24
  *
25
  */
26
 
27
- class Trustly_Trustly_Model_Ordermappings extends Mage_Core_Model_Abstract
28
  {
29
  protected function _construct()
30
  {
31
  $this->_init('trustly/ordermappings');
32
- }
33
 
34
  public function loadByTrustlyOrderId($trustlyOrderId)
35
  {
24
  *
25
  */
26
 
27
+ class Trustly_Trustly_Model_Ordermappings extends Mage_Core_Model_Abstract
28
  {
29
  protected function _construct()
30
  {
31
  $this->_init('trustly/ordermappings');
32
+ }
33
 
34
  public function loadByTrustlyOrderId($trustlyOrderId)
35
  {
app/code/community/Trustly/Trustly/Model/Standard.php CHANGED
@@ -144,8 +144,8 @@ class Trustly_Trustly_Model_Standard extends Mage_Payment_Model_Method_Abstract
144
  $orderlines = array();
145
  foreach ($order->getAllItems() as $item) {
146
  if (!$item->getParentItem()) {
147
- /* The EAN code here is really not standard and there is no
148
- * standard field. But if present (with the guessed name) we will
149
  * get it and fetching a non-existant one will not blow up, simply return null. */
150
  $orderline = $api->createOrderline(
151
  $item->getName(),
@@ -182,7 +182,7 @@ class Trustly_Trustly_Model_Standard extends Mage_Payment_Model_Method_Abstract
182
 
183
  $endUserId = strtolower($order->getCustomerEmail());
184
 
185
- $messageId = $order->getRealOrderId();
186
 
187
  $billingAddress = $order->getBillingAddress();
188
  $shippingAddress = $order->getShippingAddress();
@@ -243,7 +243,7 @@ class Trustly_Trustly_Model_Standard extends Mage_Payment_Model_Method_Abstract
243
  $incrementId = $order->getIncrementId();
244
  $orderMapping = Mage::getModel('trustly/ordermappings');
245
  $omData = array(
246
- 'trustly_order_id' => $trustlyOrderId,
247
  'magento_increment_id' => $incrementId,
248
  'datestamp' => Varien_Date::now(),
249
  );
144
  $orderlines = array();
145
  foreach ($order->getAllItems() as $item) {
146
  if (!$item->getParentItem()) {
147
+ /* The EAN code here is really not standard and there is no
148
+ * standard field. But if present (with the guessed name) we will
149
  * get it and fetching a non-existant one will not blow up, simply return null. */
150
  $orderline = $api->createOrderline(
151
  $item->getName(),
182
 
183
  $endUserId = strtolower($order->getCustomerEmail());
184
 
185
+ $messageId = uniqid($order->getRealOrderId().'-', true);
186
 
187
  $billingAddress = $order->getBillingAddress();
188
  $shippingAddress = $order->getShippingAddress();
243
  $incrementId = $order->getIncrementId();
244
  $orderMapping = Mage::getModel('trustly/ordermappings');
245
  $omData = array(
246
+ 'trustly_order_id' => $trustlyOrderId,
247
  'magento_increment_id' => $incrementId,
248
  'datestamp' => Varien_Date::now(),
249
  );
app/code/community/Trustly/Trustly/controllers/PaymentController.php CHANGED
@@ -58,6 +58,8 @@ class Trustly_Trustly_PaymentController extends Mage_Core_Controller_Front_Actio
58
  $session->setTrustlyQuoteId($session->getQuoteId());
59
 
60
  $session->unsUrlTrustly();
 
 
61
 
62
  $standard = Mage::getModel('trustly/standard');
63
  $redirectError = NULL;
@@ -156,9 +158,9 @@ class Trustly_Trustly_PaymentController extends Mage_Core_Controller_Front_Actio
156
  if($orderMapping) {
157
  $incrementId = $orderMapping->getMagentoIncrementId();
158
  }else {
159
- # If we cannot find the mapping here, check to see if the
160
- # enduserid seems to be a valid incrment id, in old code this
161
- # used to be the case. So to handle the transition between the
162
  # old module and this one, allow for this.
163
  # We always use email for enduserid, so we will not match something by accident.
164
  $enduserid = $notification->getData('enduserid');
@@ -180,13 +182,13 @@ class Trustly_Trustly_PaymentController extends Mage_Core_Controller_Front_Actio
180
  return;
181
  }
182
 
183
- /* Due to race conditions we need to handle the processing
184
- * for this order one at a time only. Otherwise we might
185
- * end up processing the credit and pending
186
  * notifications at the same time. */
187
  $increment_lockid = $orderMapping->lockIncrementForProcessing($incrementId);
188
  if($increment_lockid === false) {
189
- /* If we cannot lock this increment abort now, respond
190
  * nothing we will get a new attempt later */
191
  Mage::log("Attempt to process already locked magento increment $incrementId", Zend_Log::DEBUG, self::LOG_FILE);
192
  session_write_close();
@@ -250,7 +252,7 @@ class Trustly_Trustly_PaymentController extends Mage_Core_Controller_Front_Actio
250
  }
251
  }
252
 
253
- /* Check if we have processed this transaction before, if so
254
  * say we did fine, we obviously managed to save it... */
255
  if(isset($notification_transaction)) {
256
  Mage::helper('trustly')->sendResponseNotification($notification, true);
@@ -269,11 +271,11 @@ class Trustly_Trustly_PaymentController extends Mage_Core_Controller_Front_Actio
269
 
270
  $transactionSave = Mage::getModel('core/resource_transaction');
271
 
272
- /* We should always have a payment with the trustly method, if
273
  * we do not have one, create it we will need this regardless of the method for the notification */
274
  if(is_null($trustly_payment) || is_null($trustly_payment->getTxnType())) {
275
- /* Create a payment with our TrustlyOrderId as the
276
- * TransactionId, we will later add the current
277
  * notification as a child payment for this payment */
278
  $trustly_payment->resetTransactionAdditionalInfo();
279
  $trustly_payment->setTransactionId($trustlyOrderId);
@@ -285,8 +287,8 @@ class Trustly_Trustly_PaymentController extends Mage_Core_Controller_Front_Actio
285
  ->addObject($trustly_payment);
286
  }
287
 
288
- # Check to see if we have invoiced this order already, if
289
- # so do not do it again. We might be getting the same
290
  # notification over again.
291
  if(($_method == 'pending' || $_method == 'credit') && isset($order_invoice)) {
292
  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);
@@ -296,16 +298,16 @@ class Trustly_Trustly_PaymentController extends Mage_Core_Controller_Front_Actio
296
  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);
297
  }
298
 
299
- /* A credit notification without an invoice can mean one of two
300
- * things, either the invoice has been removed or we did not
301
- * receive the pending notification for this order. At this
302
- * point we cannot really reject the money, a payment has been
303
  * done, so create a new invoice and attach this payment to that invoice. */
304
 
305
- /* When we get the pending notification the user has
306
- * completed his end of the payment. The payment can
307
- * still fail and we are yet to be credited any funds.
308
- * Create an invoice, but do not set it as paid just
309
  * yet. */
310
 
311
  $order_invoice = $order->prepareInvoice()
@@ -339,10 +341,10 @@ class Trustly_Trustly_PaymentController extends Mage_Core_Controller_Front_Actio
339
 
340
 
341
  if($_method == 'pending') {
342
- /* We have no authorize for the payment (As we would simply
343
- * abort if we have gotten the pending before) so create
344
  * an authorization for the payment here and append */
345
- $notification_transaction = $this->addChildTransaction($trustly_payment,
346
  $trustlyNotificationId, $trustlyOrderId,
347
  Mage_Sales_Model_Order_Payment_Transaction::TYPE_AUTH, true);
348
 
@@ -443,7 +445,7 @@ class Trustly_Trustly_PaymentController extends Mage_Core_Controller_Front_Actio
443
  $comment .= "<br />" . Mage::helper('trustly')->__('Notification id: %s', $notification->getData('notificationid'));
444
  $comment .= "<br />" . Mage::helper('trustly')->__('Debit amount: %s %s', $_amount, $_currency);
445
 
446
- /* Normally the only debit amount that should be received is
447
  * the full amount, but you never know.... */
448
  if ($order->getGrandTotal() == $_amount) {
449
  $creditmemo = Mage::getModel('sales/service_order', $order)
@@ -457,7 +459,7 @@ class Trustly_Trustly_PaymentController extends Mage_Core_Controller_Front_Actio
457
  }
458
 
459
  /* Add a child transaction to the original payment issuing a refund for the order. */
460
- $notification_transaction = $this->addChildTransaction($trustly_payment, $trustlyNotificationId, $trustlyOrderId,
461
  Mage_Sales_Model_Order_Payment_Transaction::TYPE_REFUND, true);
462
 
463
  $order->setState($order->getStatus(), true, $comment);
@@ -468,12 +470,12 @@ class Trustly_Trustly_PaymentController extends Mage_Core_Controller_Front_Actio
468
  Mage::log("Recieved debit for order with increment $incrementId of $_amount $_currency", Zend_Log::INFO, self::LOG_FILE);
469
  }elseif($_method == 'cancel') {
470
 
471
- /* Cancel will be sent when the payment will not be completed.
472
- * The cancel method will always be sent in conjunction with a
473
- * debit notification, in the debit notification we handle the
474
  * montary changeback and cancel of the invoices */
475
 
476
- $notification_transaction = $this->addChildTransaction($trustly_payment, $trustlyNotificationId, $trustlyOrderId,
477
  Mage_Sales_Model_Order_Payment_Transaction::TYPE_VOID, true);
478
 
479
  $orderStatus = Mage_Sales_Model_Order::STATE_CANCELED;
58
  $session->setTrustlyQuoteId($session->getQuoteId());
59
 
60
  $session->unsUrlTrustly();
61
+ /* Clear all the error messages before we checkout, or previous errors might linger on */
62
+ $session->getMessages(true);
63
 
64
  $standard = Mage::getModel('trustly/standard');
65
  $redirectError = NULL;
158
  if($orderMapping) {
159
  $incrementId = $orderMapping->getMagentoIncrementId();
160
  }else {
161
+ # If we cannot find the mapping here, check to see if the
162
+ # enduserid seems to be a valid incrment id, in old code this
163
+ # used to be the case. So to handle the transition between the
164
  # old module and this one, allow for this.
165
  # We always use email for enduserid, so we will not match something by accident.
166
  $enduserid = $notification->getData('enduserid');
182
  return;
183
  }
184
 
185
+ /* Due to race conditions we need to handle the processing
186
+ * for this order one at a time only. Otherwise we might
187
+ * end up processing the credit and pending
188
  * notifications at the same time. */
189
  $increment_lockid = $orderMapping->lockIncrementForProcessing($incrementId);
190
  if($increment_lockid === false) {
191
+ /* If we cannot lock this increment abort now, respond
192
  * nothing we will get a new attempt later */
193
  Mage::log("Attempt to process already locked magento increment $incrementId", Zend_Log::DEBUG, self::LOG_FILE);
194
  session_write_close();
252
  }
253
  }
254
 
255
+ /* Check if we have processed this transaction before, if so
256
  * say we did fine, we obviously managed to save it... */
257
  if(isset($notification_transaction)) {
258
  Mage::helper('trustly')->sendResponseNotification($notification, true);
271
 
272
  $transactionSave = Mage::getModel('core/resource_transaction');
273
 
274
+ /* We should always have a payment with the trustly method, if
275
  * we do not have one, create it we will need this regardless of the method for the notification */
276
  if(is_null($trustly_payment) || is_null($trustly_payment->getTxnType())) {
277
+ /* Create a payment with our TrustlyOrderId as the
278
+ * TransactionId, we will later add the current
279
  * notification as a child payment for this payment */
280
  $trustly_payment->resetTransactionAdditionalInfo();
281
  $trustly_payment->setTransactionId($trustlyOrderId);
287
  ->addObject($trustly_payment);
288
  }
289
 
290
+ # Check to see if we have invoiced this order already, if
291
+ # so do not do it again. We might be getting the same
292
  # notification over again.
293
  if(($_method == 'pending' || $_method == 'credit') && isset($order_invoice)) {
294
  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);
298
  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);
299
  }
300
 
301
+ /* A credit notification without an invoice can mean one of two
302
+ * things, either the invoice has been removed or we did not
303
+ * receive the pending notification for this order. At this
304
+ * point we cannot really reject the money, a payment has been
305
  * done, so create a new invoice and attach this payment to that invoice. */
306
 
307
+ /* When we get the pending notification the user has
308
+ * completed his end of the payment. The payment can
309
+ * still fail and we are yet to be credited any funds.
310
+ * Create an invoice, but do not set it as paid just
311
  * yet. */
312
 
313
  $order_invoice = $order->prepareInvoice()
341
 
342
 
343
  if($_method == 'pending') {
344
+ /* We have no authorize for the payment (As we would simply
345
+ * abort if we have gotten the pending before) so create
346
  * an authorization for the payment here and append */
347
+ $notification_transaction = $this->addChildTransaction($trustly_payment,
348
  $trustlyNotificationId, $trustlyOrderId,
349
  Mage_Sales_Model_Order_Payment_Transaction::TYPE_AUTH, true);
350
 
445
  $comment .= "<br />" . Mage::helper('trustly')->__('Notification id: %s', $notification->getData('notificationid'));
446
  $comment .= "<br />" . Mage::helper('trustly')->__('Debit amount: %s %s', $_amount, $_currency);
447
 
448
+ /* Normally the only debit amount that should be received is
449
  * the full amount, but you never know.... */
450
  if ($order->getGrandTotal() == $_amount) {
451
  $creditmemo = Mage::getModel('sales/service_order', $order)
459
  }
460
 
461
  /* Add a child transaction to the original payment issuing a refund for the order. */
462
+ $notification_transaction = $this->addChildTransaction($trustly_payment, $trustlyNotificationId, $trustlyOrderId,
463
  Mage_Sales_Model_Order_Payment_Transaction::TYPE_REFUND, true);
464
 
465
  $order->setState($order->getStatus(), true, $comment);
470
  Mage::log("Recieved debit for order with increment $incrementId of $_amount $_currency", Zend_Log::INFO, self::LOG_FILE);
471
  }elseif($_method == 'cancel') {
472
 
473
+ /* Cancel will be sent when the payment will not be completed.
474
+ * The cancel method will always be sent in conjunction with a
475
+ * debit notification, in the debit notification we handle the
476
  * montary changeback and cancel of the invoices */
477
 
478
+ $notification_transaction = $this->addChildTransaction($trustly_payment, $trustlyNotificationId, $trustlyOrderId,
479
  Mage_Sales_Model_Order_Payment_Transaction::TYPE_VOID, true);
480
 
481
  $orderStatus = Mage_Sales_Model_Order::STATE_CANCELED;
app/code/community/Trustly/Trustly/etc/config.xml CHANGED
@@ -2,7 +2,7 @@
2
  <config>
3
  <modules>
4
  <Trustly_Trustly>
5
- <version>2.0.7</version>
6
  </Trustly_Trustly>
7
  </modules>
8
  <global>
2
  <config>
3
  <modules>
4
  <Trustly_Trustly>
5
+ <version>2.0.8</version>
6
  </Trustly_Trustly>
7
  </modules>
8
  <global>
app/code/community/Trustly/Trustly/lib/Trustly.php CHANGED
@@ -1,19 +1,19 @@
1
  <?php
2
- /*
3
  * The MIT License (MIT)
4
- *
5
  * Copyright (c) 2014 Trustly Group AB
6
- *
7
  * Permission is hereby granted, free of charge, to any person obtaining a copy
8
  * of this software and associated documentation files (the "Software"), to deal
9
  * in the Software without restriction, including without limitation the rights
10
  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
  * copies of the Software, and to permit persons to whom the Software is
12
  * furnished to do so, subject to the following conditions:
13
- *
14
  * The above copyright notice and this permission notice shall be included in
15
  * all copies or substantial portions of the Software.
16
- *
17
  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
@@ -29,6 +29,7 @@ require_once('Trustly/Data/request.php');
29
  require_once('Trustly/Data/jsonrpcrequest.php');
30
  require_once('Trustly/Data/response.php');
31
  require_once('Trustly/Data/jsonrpcresponse.php');
 
32
  require_once('Trustly/Data/jsonrpcnotificationrequest.php');
33
  require_once('Trustly/Data/jsonrpcnotificationresponse.php');
34
 
@@ -36,4 +37,4 @@ require_once('Trustly/Api/api.php');
36
  require_once('Trustly/Api/signed.php');
37
  require_once('Trustly/Api/unsigned.php');
38
  require_once('Trustly/Api/ecommerce.php');
39
- ?>
1
  <?php
2
+ /**
3
  * The MIT License (MIT)
4
+ *
5
  * Copyright (c) 2014 Trustly Group AB
6
+ *
7
  * Permission is hereby granted, free of charge, to any person obtaining a copy
8
  * of this software and associated documentation files (the "Software"), to deal
9
  * in the Software without restriction, including without limitation the rights
10
  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
  * copies of the Software, and to permit persons to whom the Software is
12
  * furnished to do so, subject to the following conditions:
13
+ *
14
  * The above copyright notice and this permission notice shall be included in
15
  * all copies or substantial portions of the Software.
16
+ *
17
  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
29
  require_once('Trustly/Data/jsonrpcrequest.php');
30
  require_once('Trustly/Data/response.php');
31
  require_once('Trustly/Data/jsonrpcresponse.php');
32
+ require_once('Trustly/Data/jsonrpcsignedresponse.php');
33
  require_once('Trustly/Data/jsonrpcnotificationrequest.php');
34
  require_once('Trustly/Data/jsonrpcnotificationresponse.php');
35
 
37
  require_once('Trustly/Api/signed.php');
38
  require_once('Trustly/Api/unsigned.php');
39
  require_once('Trustly/Api/ecommerce.php');
40
+ /* vim: set noet cindent ts=4 ts=4 sw=4: */
app/code/community/Trustly/Trustly/lib/Trustly/Api/api.php CHANGED
@@ -1,19 +1,19 @@
1
  <?php
2
- /*
3
  * The MIT License (MIT)
4
- *
5
  * Copyright (c) 2014 Trustly Group AB
6
- *
7
  * Permission is hereby granted, free of charge, to any person obtaining a copy
8
  * of this software and associated documentation files (the "Software"), to deal
9
  * in the Software without restriction, including without limitation the rights
10
  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
  * copies of the Software, and to permit persons to whom the Software is
12
  * furnished to do so, subject to the following conditions:
13
- *
14
  * The above copyright notice and this permission notice shall be included in
15
  * all copies or substantial portions of the Software.
16
- *
17
  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
@@ -32,7 +32,7 @@ abstract class Trustly_Api {
32
  /* The data of the last request performed. */
33
  var $last_request = NULL;
34
 
35
- function __construct($host, $port, $is_https) {
36
  $this->api_host = $host;
37
  $this->api_port = $port;
38
  $this->api_is_https = $is_https;
@@ -48,8 +48,8 @@ abstract class Trustly_Api {
48
  }
49
  }
50
 
51
- /* Load the public key used for for verifying incoming data responses from
52
- * trustly. The keys are distributed as a part of the source code package
53
  * and should be named to match the host under $PWD/HOSTNAME.public.pem */
54
  public function loadTrustlyPublicKey() {
55
  $filename = sprintf('%s/keys/%s.public.pem', realpath(dirname(__FILE__)), $this->api_host);
@@ -82,7 +82,7 @@ abstract class Trustly_Api {
82
  }
83
  }
84
 
85
- /* Given all the components to verify and work with, check if the given
86
  * signature has been used to sign the data */
87
  protected function verifyTrustlySignedData($method, $uuid, $signature, $data) {
88
  if($method === NULL) {
@@ -105,23 +105,20 @@ abstract class Trustly_Api {
105
  }
106
  }
107
 
108
- /* Check to make sure that the given response (instance of
109
- * Trustly_Data_Response) has been signed with the correct key when
110
  * originating from the host */
111
  public function verifyTrustlySignedResponse($response) {
112
  $method = $response->getMethod();
113
  $uuid = $response->getUUID();
114
  $signature = $response->getSignature();
115
- $data = $response->getResult();
116
- if($data !== NULL) {
117
- $data = $data['data'];
118
- }
119
 
120
  return $this->verifyTrustlySignedData($method, $uuid, $signature, $data);
121
  }
122
 
123
- /* Check to make sure that the given notification (instance of
124
- * Trustly_Data_JSONRPCNotificationRequest) has been signed with the
125
  * correct key originating from the host */
126
  public function verifyTrustlySignedNotification($notification) {
127
  $method = $notification->getMethod();
@@ -149,9 +146,9 @@ abstract class Trustly_Api {
149
  }
150
  }
151
 
152
- /* Do note that that if you are going to POST JSON you need to set the
153
- * content-type of the transfer AFTER you set the postfields, this is done
154
- * if you provide the postdata here, if not, take care to do it or the
155
  * content-type will be wrong */
156
  public function connect($url=NULL, $postdata=NULL) {
157
  $cu = curl_init();
@@ -176,8 +173,8 @@ abstract class Trustly_Api {
176
  if(isset($postdata)) {
177
  curl_setopt($cu, CURLOPT_POSTFIELDS, $postdata);
178
  }
179
- curl_setopt($cu, CURLOPT_HTTPHEADER, array('Content-Type: application/json; charset=utf-8'));
180
- curl_setopt($cu, CURLOPT_CUSTOMREQUEST, "POST");
181
  curl_setopt($cu, CURLOPT_URL, $url);
182
  return $cu;
183
  }
@@ -199,10 +196,10 @@ abstract class Trustly_Api {
199
  return $this->last_request;
200
  }
201
 
202
- /* Given the http body of an (presumed) notification from trustly. Verify
203
- * signatures and build a Trustly_Data_JSONRPCNotificationRequest object
204
- * from the incoming data. This should ALWAYS be the first steps when
205
- * accessing data in the notification, a noficiation with a poor or invalid
206
  * signature should be discarded. */
207
  public function handleNotification($httpbody) {
208
  $request = new Trustly_Data_JSONRPCNotificationRequest($httpbody);
@@ -215,7 +212,7 @@ abstract class Trustly_Api {
215
  }
216
 
217
 
218
- /* Given an object from an incoming notification request build a response
219
  * object that can be used to respond to trustly with */
220
  public function notificationResponse($request, $success=TRUE) {
221
  $response = new Trustly_Data_JSONRPCNotificationResponse($request, $success);
@@ -234,7 +231,6 @@ abstract class Trustly_Api {
234
  $url = $this->url($request);
235
  $curl = $this->connect($url, $jsonstr);
236
 
237
-
238
  $body = curl_exec($curl);
239
  if($body === FALSE) {
240
  $error = curl_error($curl);
@@ -245,7 +241,53 @@ abstract class Trustly_Api {
245
  }
246
 
247
  if($this->api_is_https) {
248
- $ssl_result = curl_getinfo($curl, CURLINFO_SSL_VERIFYRESULT); #FIXME
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
249
  }
250
  $result = $this->handleResponse($request, $body, $curl);
251
  curl_close($curl);
@@ -270,5 +312,4 @@ abstract class Trustly_Api {
270
  abstract public function insertCredentials($request);
271
 
272
  }
273
-
274
- ?>
1
  <?php
2
+ /**
3
  * The MIT License (MIT)
4
+ *
5
  * Copyright (c) 2014 Trustly Group AB
6
+ *
7
  * Permission is hereby granted, free of charge, to any person obtaining a copy
8
  * of this software and associated documentation files (the "Software"), to deal
9
  * in the Software without restriction, including without limitation the rights
10
  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
  * copies of the Software, and to permit persons to whom the Software is
12
  * furnished to do so, subject to the following conditions:
13
+ *
14
  * The above copyright notice and this permission notice shall be included in
15
  * all copies or substantial portions of the Software.
16
+ *
17
  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
32
  /* The data of the last request performed. */
33
  var $last_request = NULL;
34
 
35
+ public function __construct($host, $port, $is_https) {
36
  $this->api_host = $host;
37
  $this->api_port = $port;
38
  $this->api_is_https = $is_https;
48
  }
49
  }
50
 
51
+ /* Load the public key used for for verifying incoming data responses from
52
+ * trustly. The keys are distributed as a part of the source code package
53
  * and should be named to match the host under $PWD/HOSTNAME.public.pem */
54
  public function loadTrustlyPublicKey() {
55
  $filename = sprintf('%s/keys/%s.public.pem', realpath(dirname(__FILE__)), $this->api_host);
82
  }
83
  }
84
 
85
+ /* Given all the components to verify and work with, check if the given
86
  * signature has been used to sign the data */
87
  protected function verifyTrustlySignedData($method, $uuid, $signature, $data) {
88
  if($method === NULL) {
105
  }
106
  }
107
 
108
+ /* Check to make sure that the given response (instance of
109
+ * Trustly_Data_Response) has been signed with the correct key when
110
  * originating from the host */
111
  public function verifyTrustlySignedResponse($response) {
112
  $method = $response->getMethod();
113
  $uuid = $response->getUUID();
114
  $signature = $response->getSignature();
115
+ $data = $response->getData();
 
 
 
116
 
117
  return $this->verifyTrustlySignedData($method, $uuid, $signature, $data);
118
  }
119
 
120
+ /* Check to make sure that the given notification (instance of
121
+ * Trustly_Data_JSONRPCNotificationRequest) has been signed with the
122
  * correct key originating from the host */
123
  public function verifyTrustlySignedNotification($notification) {
124
  $method = $notification->getMethod();
146
  }
147
  }
148
 
149
+ /* Do note that that if you are going to POST JSON you need to set the
150
+ * content-type of the transfer AFTER you set the postfields, this is done
151
+ * if you provide the postdata here, if not, take care to do it or the
152
  * content-type will be wrong */
153
  public function connect($url=NULL, $postdata=NULL) {
154
  $cu = curl_init();
173
  if(isset($postdata)) {
174
  curl_setopt($cu, CURLOPT_POSTFIELDS, $postdata);
175
  }
176
+ curl_setopt($cu, CURLOPT_HTTPHEADER, array('Content-Type: application/json; charset=utf-8'));
177
+ curl_setopt($cu, CURLOPT_CUSTOMREQUEST, 'POST');
178
  curl_setopt($cu, CURLOPT_URL, $url);
179
  return $cu;
180
  }
196
  return $this->last_request;
197
  }
198
 
199
+ /* Given the http body of an (presumed) notification from trustly. Verify
200
+ * signatures and build a Trustly_Data_JSONRPCNotificationRequest object
201
+ * from the incoming data. This should ALWAYS be the first steps when
202
+ * accessing data in the notification, a noficiation with a poor or invalid
203
  * signature should be discarded. */
204
  public function handleNotification($httpbody) {
205
  $request = new Trustly_Data_JSONRPCNotificationRequest($httpbody);
212
  }
213
 
214
 
215
+ /* Given an object from an incoming notification request build a response
216
  * object that can be used to respond to trustly with */
217
  public function notificationResponse($request, $success=TRUE) {
218
  $response = new Trustly_Data_JSONRPCNotificationResponse($request, $success);
231
  $url = $this->url($request);
232
  $curl = $this->connect($url, $jsonstr);
233
 
 
234
  $body = curl_exec($curl);
235
  if($body === FALSE) {
236
  $error = curl_error($curl);
241
  }
242
 
243
  if($this->api_is_https) {
244
+ $ssl_result = curl_getinfo($curl, CURLINFO_SSL_VERIFYRESULT);
245
+ if($ssl_result !== 0) {
246
+
247
+ $curl_x509_errors = array(
248
+ '0' => 'X509_V_OK',
249
+ '2' => 'X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT',
250
+ '3' => 'X509_V_ERR_UNABLE_TO_GET_CRL',
251
+ '4' => 'X509_V_ERR_UNABLE_TO_DECRYPT_CERT_SIGNATURE',
252
+ '5' => 'X509_V_ERR_UNABLE_TO_DECRYPT_CRL_SIGNATURE',
253
+ '6' => 'X509_V_ERR_UNABLE_TO_DECODE_ISSUER_PUBLIC_KEY',
254
+ '7' => 'X509_V_ERR_CERT_SIGNATURE_FAILURE',
255
+ '8' => 'X509_V_ERR_CRL_SIGNATURE_FAILURE',
256
+ '9' => 'X509_V_ERR_CERT_NOT_YET_VALID',
257
+ '10' => 'X509_V_ERR_CERT_HAS_EXPIRED',
258
+ '11' => 'X509_V_ERR_CRL_NOT_YET_VALID',
259
+ '12' => 'X509_V_ERR_CRL_HAS_EXPIRED',
260
+ '13' => 'X509_V_ERR_ERROR_IN_CERT_NOT_BEFORE_FIELD',
261
+ '14' => 'X509_V_ERR_ERROR_IN_CERT_NOT_AFTER_FIELD',
262
+ '15' => 'X509_V_ERR_ERROR_IN_CRL_LAST_UPDATE_FIELD',
263
+ '16' => 'X509_V_ERR_ERROR_IN_CRL_NEXT_UPDATE_FIELD',
264
+ '17' => 'X509_V_ERR_OUT_OF_MEM',
265
+ '18' => 'X509_V_ERR_DEPTH_ZERO_SELF_SIGNED_CERT',
266
+ '19' => 'X509_V_ERR_SELF_SIGNED_CERT_IN_CHAIN',
267
+ '20' => 'X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT_LOCALLY',
268
+ '21' => 'X509_V_ERR_UNABLE_TO_VERIFY_LEAF_SIGNATURE',
269
+ '22' => 'X509_V_ERR_CERT_CHAIN_TOO_LONG',
270
+ '23' => 'X509_V_ERR_CERT_REVOKED',
271
+ '24' => 'X509_V_ERR_INVALID_CA',
272
+ '25' => 'X509_V_ERR_PATH_LENGTH_EXCEEDED',
273
+ '26' => 'X509_V_ERR_INVALID_PURPOSE',
274
+ '27' => 'X509_V_ERR_CERT_UNTRUSTED',
275
+ '28' => 'X509_V_ERR_CERT_REJECTED',
276
+ '29' => 'X509_V_ERR_SUBJECT_ISSUER_MISMATCH',
277
+ '30' => 'X509_V_ERR_AKID_SKID_MISMATCH',
278
+ '31' => 'X509_V_ERR_AKID_ISSUER_SERIAL_MISMATCH',
279
+ '32' => 'X509_V_ERR_KEYUSAGE_NO_CERTSIGN',
280
+ '50' => 'X509_V_ERR_APPLICATION_VERIFICATION'
281
+ );
282
+
283
+ $ssl_error_str = null;
284
+ if(isset($curl_x509_errors[$ssl_result])) {
285
+ $ssl_error_str = $curl_x509_errors[$ssl_result];
286
+ }
287
+
288
+ $error = 'Failed to connect to the Trusly API. SSL Verification error #' . $ssl_result . ($ssl_error_str?': ' . $ssl_error_str:'');
289
+ throw new Trustly_ConnectionException($error);
290
+ }
291
  }
292
  $result = $this->handleResponse($request, $body, $curl);
293
  curl_close($curl);
312
  abstract public function insertCredentials($request);
313
 
314
  }
315
+ /* vim: set noet cindent ts=4 ts=4 sw=4: */
 
app/code/community/Trustly/Trustly/lib/Trustly/Api/ecommerce.php CHANGED
@@ -1,19 +1,19 @@
1
  <?php
2
- /*
3
  * The MIT License (MIT)
4
- *
5
  * Copyright (c) 2014 Trustly Group AB
6
- *
7
  * Permission is hereby granted, free of charge, to any person obtaining a copy
8
  * of this software and associated documentation files (the "Software"), to deal
9
  * in the Software without restriction, including without limitation the rights
10
  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
  * copies of the Software, and to permit persons to whom the Software is
12
  * furnished to do so, subject to the following conditions:
13
- *
14
  * The above copyright notice and this permission notice shall be included in
15
  * all copies or substantial portions of the Software.
16
- *
17
  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
@@ -50,8 +50,8 @@ class Trustly_Api_ECommerce extends Trustly_Api {
50
  $signature = $response->getSignature();
51
  $data = $response->getResult();
52
 
53
- /* As the data in the ecommerce responses are flat, all the uuid,
54
- * signatures, method information is on the same level as the data
55
  * response. Remove theese from the data before checking the signature. */
56
  unset($data['uuid']);
57
  unset($data['signature']);
@@ -75,8 +75,8 @@ class Trustly_Api_ECommerce extends Trustly_Api {
75
  return TRUE;
76
  }
77
 
78
- /* Build an orderline suitable for the payment call using the supplied
79
- * information. Call once for each line of the order and stuff into an
80
  * array that is later supplied to the pay() call.
81
  *
82
  * Typically:
@@ -86,7 +86,7 @@ class Trustly_Api_ECommerce extends Trustly_Api {
86
  * ...
87
  * $result = $api->pay(..., $orderlines);
88
  * */
89
- public function createOrderline($description=NULL, $amount=NULL,
90
  $currency=NULL, $vat=NULL, $quantity=1, $eancode=NULL) {
91
 
92
  $orderline = array();
@@ -118,11 +118,11 @@ class Trustly_Api_ECommerce extends Trustly_Api {
118
  return $orderline;
119
  }
120
 
121
- public function pay($notificationurl, $enduserid, $messageid,
122
- $locale=NULL, $amount=NULL, $currency=NULL, $country=NULL, $host=NULL,
123
- $returnurl=NULL, $templateurl=NULL, $urltarget=NULL,
124
- $email=NULL, $firstname=NULL, $lastname=NULL, $integrationmodule=NULL,
125
- $orderlines=NULL) {
126
 
127
  $request = new Trustly_Data_Request('Pay',
128
  array(
@@ -147,7 +147,7 @@ class Trustly_Api_ECommerce extends Trustly_Api {
147
  return $this->call($request);
148
  }
149
 
150
- public function repay($orderid, $amount, $currency) {
151
 
152
  $request = new Trustly_Data_Request('Repay',
153
  array(
@@ -165,5 +165,4 @@ class Trustly_Api_ECommerce extends Trustly_Api {
165
  return $this->call($request);
166
  }
167
  }
168
-
169
- ?>
1
  <?php
2
+ /**
3
  * The MIT License (MIT)
4
+ *
5
  * Copyright (c) 2014 Trustly Group AB
6
+ *
7
  * Permission is hereby granted, free of charge, to any person obtaining a copy
8
  * of this software and associated documentation files (the "Software"), to deal
9
  * in the Software without restriction, including without limitation the rights
10
  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
  * copies of the Software, and to permit persons to whom the Software is
12
  * furnished to do so, subject to the following conditions:
13
+ *
14
  * The above copyright notice and this permission notice shall be included in
15
  * all copies or substantial portions of the Software.
16
+ *
17
  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
50
  $signature = $response->getSignature();
51
  $data = $response->getResult();
52
 
53
+ /* As the data in the ecommerce responses are flat, all the uuid,
54
+ * signatures, method information is on the same level as the data
55
  * response. Remove theese from the data before checking the signature. */
56
  unset($data['uuid']);
57
  unset($data['signature']);
75
  return TRUE;
76
  }
77
 
78
+ /* Build an orderline suitable for the payment call using the supplied
79
+ * information. Call once for each line of the order and stuff into an
80
  * array that is later supplied to the pay() call.
81
  *
82
  * Typically:
86
  * ...
87
  * $result = $api->pay(..., $orderlines);
88
  * */
89
+ public function createOrderline($description=NULL, $amount=NULL,
90
  $currency=NULL, $vat=NULL, $quantity=1, $eancode=NULL) {
91
 
92
  $orderline = array();
118
  return $orderline;
119
  }
120
 
121
+ public function pay($notificationurl, $enduserid, $messageid,
122
+ $locale=NULL, $amount=NULL, $currency=NULL, $country=NULL, $host=NULL,
123
+ $returnurl=NULL, $templateurl=NULL, $urltarget=NULL,
124
+ $email=NULL, $firstname=NULL, $lastname=NULL, $integrationmodule=NULL,
125
+ $orderlines=NULL) {
126
 
127
  $request = new Trustly_Data_Request('Pay',
128
  array(
147
  return $this->call($request);
148
  }
149
 
150
+ public function repay($orderid, $amount, $currency) {
151
 
152
  $request = new Trustly_Data_Request('Repay',
153
  array(
165
  return $this->call($request);
166
  }
167
  }
168
+ /* vim: set noet cindent ts=4 ts=4 sw=4: */
 
app/code/community/Trustly/Trustly/lib/Trustly/Api/signed.php CHANGED
@@ -1,19 +1,19 @@
1
  <?php
2
- /*
3
  * The MIT License (MIT)
4
- *
5
  * Copyright (c) 2014 Trustly Group AB
6
- *
7
  * Permission is hereby granted, free of charge, to any person obtaining a copy
8
  * of this software and associated documentation files (the "Software"), to deal
9
  * in the Software without restriction, including without limitation the rights
10
  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
  * copies of the Software, and to permit persons to whom the Software is
12
  * furnished to do so, subject to the following conditions:
13
- *
14
  * The above copyright notice and this permission notice shall be included in
15
  * all copies or substantial portions of the Software.
16
- *
17
  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
@@ -26,7 +26,7 @@
26
  class Trustly_Api_Signed extends Trustly_Api {
27
  var $merchant_privatekey = NULL;
28
 
29
- function __construct($merchant_privatekeyfile, $username, $password, $host='trustly.com', $port=443, $is_https=TRUE) {
30
 
31
  parent::__construct($host, $port, $is_https);
32
 
@@ -40,7 +40,7 @@ class Trustly_Api_Signed extends Trustly_Api {
40
  }
41
  }
42
 
43
- /* Load up the merchants key for signing data from the supplied filename.
44
  * Inializes the internal openssl certificate needed for the signing */
45
  public function loadMerchantPrivateKey($filename) {
46
  $cert = @file_get_contents($filename);
@@ -55,7 +55,7 @@ class Trustly_Api_Signed extends Trustly_Api {
55
  return FALSE;
56
  }
57
 
58
- /* Create a signature string suitable for including as the signature in an
59
  * outgoing request */
60
  public function signMerchantRequest($request) {
61
  if(!isset($this->merchant_privatekey)) {
@@ -82,8 +82,6 @@ class Trustly_Api_Signed extends Trustly_Api {
82
  }
83
 
84
  throw new Trustly_SignatureException('Failed to sign the outgoing merchant request. '. openssl_error_string());
85
-
86
- return FALSE;
87
  }
88
 
89
  public function insertCredentials($request) {
@@ -100,14 +98,14 @@ class Trustly_Api_Signed extends Trustly_Api {
100
  }
101
 
102
  public function handleResponse($request, $body, $curl) {
103
- $response = new Trustly_Data_JSONRPCResponse($body, $curl);
104
 
105
  if($this->verifyTrustlySignedResponse($response) !== TRUE) {
106
  throw new Trustly_SignatureException('Incomming message signature is not valid', $response);
107
  }
108
 
109
  if($response->getUUID() !== $request->getUUID()) {
110
- throw new Trustly_DataError('Incoming message is not related to request. UUID mismatch');
111
  }
112
 
113
  return $response;
@@ -131,24 +129,24 @@ class Trustly_Api_Signed extends Trustly_Api {
131
  }
132
 
133
  private function clearOpenSSLError() {
134
- /* Not really my favourite part of this library implementation. As
135
- * openssl queues error messages a single call to openssl_error_string
136
- * after a fail might get another "queued" message from before. And as
137
- * there is no way to clear the buffer... we will iterate until we will
138
  * get no more errors. Brilliant. */
139
  while ($err = openssl_error_string());
140
  }
141
 
142
  protected function generateUUID() {
143
- /* Not the classiest implementation, but to reduce the dependency of
144
- * non standard libraries we build it this way. The risk of
145
  * collisions is low enough with a MD5 */
146
  $md5 = md5(uniqid('', true));
147
  return substr($md5, 0, 8).'-'.substr($md5, 8, 4).'-'.substr($md5, 12, 4).'-'.substr($md5, 16, 4).'-'.substr($md5, 20, 12);
148
  }
149
 
150
  public function call($request) {
151
- $uuid = $request->getUUID();
152
  if($uuid === NULL) {
153
  $request->setUUID($this->generateUUID());
154
  }
@@ -156,9 +154,9 @@ class Trustly_Api_Signed extends Trustly_Api {
156
  }
157
 
158
  /* Make a deposit call */
159
- public function deposit($notificationurl, $enduserid, $messageid,
160
- $locale=NULL, $amount=NULL, $currency=NULL, $country=NULL,
161
- $mobilephone=NULL, $firstname=NULL, $lastname=NULL,
162
  $nationalidentificationnumber=NULL, $shopperstatement=NULL,
163
  $ip=NULL, $successurl=NULL, $failurl=NULL, $templateurl=NULL,
164
  $urltarget=NULL, $suggestedminamount=NULL, $suggestedmaxamount=NULL,
@@ -171,17 +169,17 @@ class Trustly_Api_Signed extends Trustly_Api {
171
  );
172
 
173
  $attributes = array(
174
- 'Locale' => $locale,
175
  'Amount' => $amount,
176
  'Currency' => $currency,
177
- 'Country' => $country,
178
  'MobilePhone' => $mobilephone,
179
- 'Firstname' => $firstname,
180
- 'Lastname' => $lastname,
181
- 'NationalIdentificationNumber' => $nationalidentificationnumber,
182
  'ShopperStatement' => $shopperstatement,
183
  'IP' => $ip,
184
- 'SuccessURL' => $successurl,
185
  'FailURL' => $failurl,
186
  'TemplateURL' => $templateurl,
187
  'URLTarget' => $urltarget,
@@ -192,7 +190,7 @@ class Trustly_Api_Signed extends Trustly_Api {
192
 
193
  $request = new Trustly_Data_JSONRPCRequest('Deposit', $data, $attributes);
194
  return $this->call($request);
195
- }
196
 
197
  /* Make a refund call */
198
  public function refund($orderid, $amount, $currency) {
@@ -208,9 +206,9 @@ class Trustly_Api_Signed extends Trustly_Api {
208
  }
209
 
210
  /* Make a withdraw call */
211
- public function withdraw($notificationurl, $enduserid, $messageid,
212
- $locale=NULL, $currency=NULL, $country=NULL,
213
- $mobilephone=NULL, $firstname=NULL, $lastname=NULL,
214
  $nationalidentificationnumber=NULL, $clearinghouse=NULL,
215
  $banknumber=NULL, $accountnumber=NULL) {
216
 
@@ -223,12 +221,12 @@ class Trustly_Api_Signed extends Trustly_Api {
223
  );
224
 
225
  $attributes = array(
226
- 'Locale' => $locale,
227
- 'Country' => $country,
228
  'MobilePhone' => $mobilephone,
229
- 'Firstname' => $firstname,
230
- 'Lastname' => $lastname,
231
- 'NationalIdentificationNumber' => $nationalidentificationnumber,
232
  'ClearingHouse' => $clearinghouse,
233
  'BankNumber' => $banknumber,
234
  'AccountNumber' => $accountnumber,
@@ -236,7 +234,7 @@ class Trustly_Api_Signed extends Trustly_Api {
236
 
237
  $request = new Trustly_Data_JSONRPCRequest('Withdraw', $data, $attributes);
238
  return $this->call($request);
239
- }
240
 
241
  /* Make an approvewithdrawal call */
242
  public function approveWithdrawal($orderid) {
@@ -261,8 +259,9 @@ class Trustly_Api_Signed extends Trustly_Api {
261
  }
262
 
263
  /* Make a select account call */
264
- public function selectAccount($notificationurl, $enduserid, $messageid,
265
- $locale=NULL, $country=NULL, $firstname=NULL, $lastname=NULL) {
 
266
 
267
  $data = array(
268
  'NotificationURL' => $notificationurl,
@@ -271,18 +270,22 @@ class Trustly_Api_Signed extends Trustly_Api {
271
  );
272
 
273
  $attributes = array(
274
- 'Locale' => $locale,
275
- 'Country' => $country,
276
- 'Firstname' => $firstname,
277
- 'Lastname' => $lastname,
 
 
 
 
278
  );
279
 
280
  $request = new Trustly_Data_JSONRPCRequest('SelectAccount', $data, $attributes);
281
  return $this->call($request);
282
  }
283
 
284
- public function registerAccount($enduserid, $clearinghouse, $banknumber,
285
- $accountnumber, $firstname, $lastname, $mobilephone=NULL,
286
  $nationalidentificationnumber=NULL, $address=NULL) {
287
 
288
  $data = array(
@@ -290,13 +293,13 @@ class Trustly_Api_Signed extends Trustly_Api {
290
  'ClearingHouse' => $clearinghouse,
291
  'BankNumber' => $banknumber,
292
  'AccountNumber' => $accountnumber,
293
- 'Firstname' => $firstname,
294
- 'Lastname' => $lastname,
295
  );
296
 
297
  $attributes = array(
298
- 'MobilePhone' => $mobilephone,
299
- 'NationalIdentificationNumber' => $nationalidentificationnumber,
300
  'Address' => $address
301
  );
302
 
@@ -304,7 +307,7 @@ class Trustly_Api_Signed extends Trustly_Api {
304
  return $this->call($request);
305
  }
306
 
307
- public function accountPayout($notificationurl, $accountid, $enduserid,
308
  $messageid, $amount, $currency) {
309
 
310
  $data = array(
@@ -312,8 +315,8 @@ class Trustly_Api_Signed extends Trustly_Api {
312
  'EndUserID' => $enduserid,
313
  'MessageID' => $messageid,
314
  'AccountID' => $accountid,
315
- 'Amount' => $amount,
316
- 'Currency' => $currency,
317
  );
318
 
319
  $attributes = array(
@@ -324,7 +327,7 @@ class Trustly_Api_Signed extends Trustly_Api {
324
  }
325
 
326
  public function p2p($notificationurl, $enduserid, $messageid, $ip,
327
- $authorizeonly=NULL, $templatedata=NULL, $successurl=NULL,
328
  $method=NULL, $lastname=NULL, $firstname=NULL, $urltarget=NULL,
329
  $locale=NULL, $amount=NULL, $currency=NULL, $templateurl=NULL,
330
  $displaycurrency=NULL) {
@@ -355,7 +358,7 @@ class Trustly_Api_Signed extends Trustly_Api {
355
 
356
  $request = new Trustly_Data_JSONRPCRequest('P2P', $data, $attributes);
357
  return $this->call($request);
358
- }
359
 
360
  public function capture($orderid, $amount, $currency) {
361
 
@@ -391,5 +394,4 @@ class Trustly_Api_Signed extends Trustly_Api {
391
  return $api->hello();
392
  }
393
  }
394
-
395
- ?>
1
  <?php
2
+ /**
3
  * The MIT License (MIT)
4
+ *
5
  * Copyright (c) 2014 Trustly Group AB
6
+ *
7
  * Permission is hereby granted, free of charge, to any person obtaining a copy
8
  * of this software and associated documentation files (the "Software"), to deal
9
  * in the Software without restriction, including without limitation the rights
10
  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
  * copies of the Software, and to permit persons to whom the Software is
12
  * furnished to do so, subject to the following conditions:
13
+ *
14
  * The above copyright notice and this permission notice shall be included in
15
  * all copies or substantial portions of the Software.
16
+ *
17
  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
26
  class Trustly_Api_Signed extends Trustly_Api {
27
  var $merchant_privatekey = NULL;
28
 
29
+ public function __construct($merchant_privatekeyfile, $username, $password, $host='trustly.com', $port=443, $is_https=TRUE) {
30
 
31
  parent::__construct($host, $port, $is_https);
32
 
40
  }
41
  }
42
 
43
+ /* Load up the merchants key for signing data from the supplied filename.
44
  * Inializes the internal openssl certificate needed for the signing */
45
  public function loadMerchantPrivateKey($filename) {
46
  $cert = @file_get_contents($filename);
55
  return FALSE;
56
  }
57
 
58
+ /* Create a signature string suitable for including as the signature in an
59
  * outgoing request */
60
  public function signMerchantRequest($request) {
61
  if(!isset($this->merchant_privatekey)) {
82
  }
83
 
84
  throw new Trustly_SignatureException('Failed to sign the outgoing merchant request. '. openssl_error_string());
 
 
85
  }
86
 
87
  public function insertCredentials($request) {
98
  }
99
 
100
  public function handleResponse($request, $body, $curl) {
101
+ $response = new Trustly_Data_JSONRPCSignedResponse($body, $curl);
102
 
103
  if($this->verifyTrustlySignedResponse($response) !== TRUE) {
104
  throw new Trustly_SignatureException('Incomming message signature is not valid', $response);
105
  }
106
 
107
  if($response->getUUID() !== $request->getUUID()) {
108
+ throw new Trustly_DataException('Incoming message is not related to request. UUID mismatch');
109
  }
110
 
111
  return $response;
129
  }
130
 
131
  private function clearOpenSSLError() {
132
+ /* Not really my favourite part of this library implementation. As
133
+ * openssl queues error messages a single call to openssl_error_string
134
+ * after a fail might get another "queued" message from before. And as
135
+ * there is no way to clear the buffer... we will iterate until we will
136
  * get no more errors. Brilliant. */
137
  while ($err = openssl_error_string());
138
  }
139
 
140
  protected function generateUUID() {
141
+ /* Not the classiest implementation, but to reduce the dependency of
142
+ * non standard libraries we build it this way. The risk of
143
  * collisions is low enough with a MD5 */
144
  $md5 = md5(uniqid('', true));
145
  return substr($md5, 0, 8).'-'.substr($md5, 8, 4).'-'.substr($md5, 12, 4).'-'.substr($md5, 16, 4).'-'.substr($md5, 20, 12);
146
  }
147
 
148
  public function call($request) {
149
+ $uuid = $request->getUUID();
150
  if($uuid === NULL) {
151
  $request->setUUID($this->generateUUID());
152
  }
154
  }
155
 
156
  /* Make a deposit call */
157
+ public function deposit($notificationurl, $enduserid, $messageid,
158
+ $locale=NULL, $amount=NULL, $currency=NULL, $country=NULL,
159
+ $mobilephone=NULL, $firstname=NULL, $lastname=NULL,
160
  $nationalidentificationnumber=NULL, $shopperstatement=NULL,
161
  $ip=NULL, $successurl=NULL, $failurl=NULL, $templateurl=NULL,
162
  $urltarget=NULL, $suggestedminamount=NULL, $suggestedmaxamount=NULL,
169
  );
170
 
171
  $attributes = array(
172
+ 'Locale' => $locale,
173
  'Amount' => $amount,
174
  'Currency' => $currency,
175
+ 'Country' => $country,
176
  'MobilePhone' => $mobilephone,
177
+ 'Firstname' => $firstname,
178
+ 'Lastname' => $lastname,
179
+ 'NationalIdentificationNumber' => $nationalidentificationnumber,
180
  'ShopperStatement' => $shopperstatement,
181
  'IP' => $ip,
182
+ 'SuccessURL' => $successurl,
183
  'FailURL' => $failurl,
184
  'TemplateURL' => $templateurl,
185
  'URLTarget' => $urltarget,
190
 
191
  $request = new Trustly_Data_JSONRPCRequest('Deposit', $data, $attributes);
192
  return $this->call($request);
193
+ }
194
 
195
  /* Make a refund call */
196
  public function refund($orderid, $amount, $currency) {
206
  }
207
 
208
  /* Make a withdraw call */
209
+ public function withdraw($notificationurl, $enduserid, $messageid,
210
+ $locale=NULL, $currency=NULL, $country=NULL,
211
+ $mobilephone=NULL, $firstname=NULL, $lastname=NULL,
212
  $nationalidentificationnumber=NULL, $clearinghouse=NULL,
213
  $banknumber=NULL, $accountnumber=NULL) {
214
 
221
  );
222
 
223
  $attributes = array(
224
+ 'Locale' => $locale,
225
+ 'Country' => $country,
226
  'MobilePhone' => $mobilephone,
227
+ 'Firstname' => $firstname,
228
+ 'Lastname' => $lastname,
229
+ 'NationalIdentificationNumber' => $nationalidentificationnumber,
230
  'ClearingHouse' => $clearinghouse,
231
  'BankNumber' => $banknumber,
232
  'AccountNumber' => $accountnumber,
234
 
235
  $request = new Trustly_Data_JSONRPCRequest('Withdraw', $data, $attributes);
236
  return $this->call($request);
237
+ }
238
 
239
  /* Make an approvewithdrawal call */
240
  public function approveWithdrawal($orderid) {
259
  }
260
 
261
  /* Make a select account call */
262
+ public function selectAccount($notificationurl, $enduserid, $messageid,
263
+ $locale=NULL, $country=NULL, $ip=NULL, $successurl=NULL, $urltarget=NULL,
264
+ $mobilephone=NULL, $firstname=NULL, $lastname=NULL) {
265
 
266
  $data = array(
267
  'NotificationURL' => $notificationurl,
270
  );
271
 
272
  $attributes = array(
273
+ 'Locale' => $locale,
274
+ 'Country' => $country,
275
+ 'IP' => $ip,
276
+ 'SuccessURL' => $successurl,
277
+ 'URLTarget' => $urltarget,
278
+ 'MobilePhone' => $mobilephone,
279
+ 'Firstname' => $firstname,
280
+ 'Lastname' => $lastname,
281
  );
282
 
283
  $request = new Trustly_Data_JSONRPCRequest('SelectAccount', $data, $attributes);
284
  return $this->call($request);
285
  }
286
 
287
+ public function registerAccount($enduserid, $clearinghouse, $banknumber,
288
+ $accountnumber, $firstname, $lastname, $mobilephone=NULL,
289
  $nationalidentificationnumber=NULL, $address=NULL) {
290
 
291
  $data = array(
293
  'ClearingHouse' => $clearinghouse,
294
  'BankNumber' => $banknumber,
295
  'AccountNumber' => $accountnumber,
296
+ 'Firstname' => $firstname,
297
+ 'Lastname' => $lastname,
298
  );
299
 
300
  $attributes = array(
301
+ 'MobilePhone' => $mobilephone,
302
+ 'NationalIdentificationNumber' => $nationalidentificationnumber,
303
  'Address' => $address
304
  );
305
 
307
  return $this->call($request);
308
  }
309
 
310
+ public function accountPayout($notificationurl, $accountid, $enduserid,
311
  $messageid, $amount, $currency) {
312
 
313
  $data = array(
315
  'EndUserID' => $enduserid,
316
  'MessageID' => $messageid,
317
  'AccountID' => $accountid,
318
+ 'Amount' => $amount,
319
+ 'Currency' => $currency,
320
  );
321
 
322
  $attributes = array(
327
  }
328
 
329
  public function p2p($notificationurl, $enduserid, $messageid, $ip,
330
+ $authorizeonly=NULL, $templatedata=NULL, $successurl=NULL,
331
  $method=NULL, $lastname=NULL, $firstname=NULL, $urltarget=NULL,
332
  $locale=NULL, $amount=NULL, $currency=NULL, $templateurl=NULL,
333
  $displaycurrency=NULL) {
358
 
359
  $request = new Trustly_Data_JSONRPCRequest('P2P', $data, $attributes);
360
  return $this->call($request);
361
+ }
362
 
363
  public function capture($orderid, $amount, $currency) {
364
 
394
  return $api->hello();
395
  }
396
  }
397
+ /* vim: set noet cindent ts=4 ts=4 sw=4: */
 
app/code/community/Trustly/Trustly/lib/Trustly/Api/unsigned.php CHANGED
@@ -1,19 +1,19 @@
1
  <?php
2
- /*
3
  * The MIT License (MIT)
4
- *
5
  * Copyright (c) 2014 Trustly Group AB
6
- *
7
  * Permission is hereby granted, free of charge, to any person obtaining a copy
8
  * of this software and associated documentation files (the "Software"), to deal
9
  * in the Software without restriction, including without limitation the rights
10
  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
  * copies of the Software, and to permit persons to whom the Software is
12
  * furnished to do so, subject to the following conditions:
13
- *
14
  * The above copyright notice and this permission notice shall be included in
15
  * all copies or substantial portions of the Software.
16
- *
17
  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
@@ -24,8 +24,8 @@
24
  */
25
 
26
  class Trustly_Api_Unsigned extends Trustly_Api {
27
- /* Login criterias when using the unsigned API. Only used by the
28
- * newSessionCookie() call which is called automatically before the
29
  * first call */
30
  var $api_username = NULL;
31
  var $api_password = NULL;
@@ -45,7 +45,7 @@ class Trustly_Api_Unsigned extends Trustly_Api {
45
 
46
  public function handleResponse($request, $body, $curl) {
47
  /* No signature here, just build the response object */
48
- return new Trustly_Data_JSONRPCResponse($body, $curl);
49
  }
50
 
51
  public function insertCredentials($request) {
@@ -62,15 +62,15 @@ class Trustly_Api_Unsigned extends Trustly_Api {
62
  return (bool)isset($this->session_uuid);
63
  }
64
 
65
- /* Call NewSessionCookie to obtain a session cookie we can use for the rest
66
- * of our calls. This is automatically called when doing a call if we do
67
- * not have a session. Call manually if needed at session timeout etc.
68
  * */
69
  public function newSessionCookie() {
70
  $this->session_uuid = NULL;
71
 
72
  $request = new Trustly_Data_JSONRPCRequest('NewSessionCookie');
73
- /* Call parent directly here as we will attempt to detect the
74
  * missing session uuid here and call this function if it is not set */
75
  $response = parent::call($request);
76
 
@@ -85,29 +85,29 @@ class Trustly_Api_Unsigned extends Trustly_Api {
85
  return $response;
86
  }
87
 
88
- /* Utility wrapper around a call() to GetViewStable to simply getting data
89
  * from a view. */
90
- public function getViewStable($viewname, $dateorder=NULL, $datestamp=NULL,
91
- $filterkeys=NULL, $limit=100, $offset=0, $params=NULL, $sortby=NULL,
92
  $sortorder=NULL) {
93
 
94
  return $this->call('GetViewStable', array(
95
- DateOrder => $dateorder,
96
- Datestamp => $datestamp,
97
- FilterKeys => $filterkeys,
98
- Limit => $limit,
99
- Offset => $offset,
100
- Params => $params,
101
- SortBy => $sortby,
102
- SortOrder => $sortorder,
103
- ViewName => $viewname,
104
  ));
105
  }
106
 
107
- /* Issue an unsigned API call. As the unsigned API contains a huge array of
108
- * functions we will use the call() method directly for the majority of
109
- * operations. The data in params will be matched into the parameters of
110
- * the outgoing call. Take care when supplying the arguments for the call
111
  * so they match the function prototype properly. */
112
  public function call($method, $params=NULL) {
113
  $request = new Trustly_Data_JSONRPCRequest($method);
@@ -127,12 +127,12 @@ class Trustly_Api_Unsigned extends Trustly_Api {
127
 
128
  public function hello() {
129
  $request = new Trustly_Data_JSONRPCRequest('Hello');
130
- /* Call parent directly here we never want to get a new session
131
- * uuid for just this single call, if we have it use it, but
132
  * otherwise just live happliy */
133
  $response = parent::call($request);
134
 
135
  return $response;
136
  }
137
  }
138
- ?>
1
  <?php
2
+ /**
3
  * The MIT License (MIT)
4
+ *
5
  * Copyright (c) 2014 Trustly Group AB
6
+ *
7
  * Permission is hereby granted, free of charge, to any person obtaining a copy
8
  * of this software and associated documentation files (the "Software"), to deal
9
  * in the Software without restriction, including without limitation the rights
10
  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
  * copies of the Software, and to permit persons to whom the Software is
12
  * furnished to do so, subject to the following conditions:
13
+ *
14
  * The above copyright notice and this permission notice shall be included in
15
  * all copies or substantial portions of the Software.
16
+ *
17
  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
24
  */
25
 
26
  class Trustly_Api_Unsigned extends Trustly_Api {
27
+ /* Login criterias when using the unsigned API. Only used by the
28
+ * newSessionCookie() call which is called automatically before the
29
  * first call */
30
  var $api_username = NULL;
31
  var $api_password = NULL;
45
 
46
  public function handleResponse($request, $body, $curl) {
47
  /* No signature here, just build the response object */
48
+ return new Trustly_Data_JSONRPCResponse($body, $curl);
49
  }
50
 
51
  public function insertCredentials($request) {
62
  return (bool)isset($this->session_uuid);
63
  }
64
 
65
+ /* Call NewSessionCookie to obtain a session cookie we can use for the rest
66
+ * of our calls. This is automatically called when doing a call if we do
67
+ * not have a session. Call manually if needed at session timeout etc.
68
  * */
69
  public function newSessionCookie() {
70
  $this->session_uuid = NULL;
71
 
72
  $request = new Trustly_Data_JSONRPCRequest('NewSessionCookie');
73
+ /* Call parent directly here as we will attempt to detect the
74
  * missing session uuid here and call this function if it is not set */
75
  $response = parent::call($request);
76
 
85
  return $response;
86
  }
87
 
88
+ /* Utility wrapper around a call() to GetViewStable to simply getting data
89
  * from a view. */
90
+ public function getViewStable($viewname, $dateorder=NULL, $datestamp=NULL,
91
+ $filterkeys=NULL, $limit=100, $offset=0, $params=NULL, $sortby=NULL,
92
  $sortorder=NULL) {
93
 
94
  return $this->call('GetViewStable', array(
95
+ 'DateOrder' => $dateorder,
96
+ 'Datestamp' => $datestamp,
97
+ 'FilterKeys' => $filterkeys,
98
+ 'Limit' => $limit,
99
+ 'Offset' => $offset,
100
+ 'Params' => $params,
101
+ 'SortBy' => $sortby,
102
+ 'SortOrder' => $sortorder,
103
+ 'ViewName' => $viewname,
104
  ));
105
  }
106
 
107
+ /* Issue an unsigned API call. As the unsigned API contains a huge array of
108
+ * functions we will use the call() method directly for the majority of
109
+ * operations. The data in params will be matched into the parameters of
110
+ * the outgoing call. Take care when supplying the arguments for the call
111
  * so they match the function prototype properly. */
112
  public function call($method, $params=NULL) {
113
  $request = new Trustly_Data_JSONRPCRequest($method);
127
 
128
  public function hello() {
129
  $request = new Trustly_Data_JSONRPCRequest('Hello');
130
+ /* Call parent directly here we never want to get a new session
131
+ * uuid for just this single call, if we have it use it, but
132
  * otherwise just live happliy */
133
  $response = parent::call($request);
134
 
135
  return $response;
136
  }
137
  }
138
+ /* vim: set noet cindent ts=4 ts=4 sw=4: */
app/code/community/Trustly/Trustly/lib/Trustly/Data/data.php CHANGED
@@ -1,19 +1,19 @@
1
  <?php
2
- /*
3
  * The MIT License (MIT)
4
- *
5
  * Copyright (c) 2014 Trustly Group AB
6
- *
7
  * Permission is hereby granted, free of charge, to any person obtaining a copy
8
  * of this software and associated documentation files (the "Software"), to deal
9
  * in the Software without restriction, including without limitation the rights
10
  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
  * copies of the Software, and to permit persons to whom the Software is
12
  * furnished to do so, subject to the following conditions:
13
- *
14
  * The above copyright notice and this permission notice shall be included in
15
  * all copies or substantial portions of the Software.
16
- *
17
  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
@@ -35,8 +35,8 @@ class Trustly_Data {
35
  }
36
  }
37
 
38
- /* Utility function to vacuum the supplied data end remove unset
39
- * values. This is used to keep the requests cleaner rather then
40
  * supplying NULL values in the payload */
41
  public function vacuum($data) {
42
  if(is_null($data)) {
@@ -58,7 +58,7 @@ class Trustly_Data {
58
  }
59
  }
60
 
61
- /* Get the specific data value from the payload or the full payload if
62
  * no value is supplied */
63
  public function get($name=NULL) {
64
  if($name === NULL) {
@@ -71,7 +71,7 @@ class Trustly_Data {
71
  return NULL;
72
  }
73
 
74
- /* Funciton to ensure that the given value is in UTF8. Used to make sure
75
  * all outgoing data is properly encoded in the call */
76
  public static function ensureUTF8($str) {
77
  if($str == NULL) {
@@ -112,8 +112,8 @@ class Trustly_Data {
112
  }
113
  }
114
 
115
- /* Extremely naivly done and does not by far handle all cases, but
116
- * handles the case it should, i.e. sort the data for the json
117
  * pretty printer */
118
  private function sortRecursive(&$data) {
119
  if(is_array($data)) {
@@ -128,5 +128,4 @@ class Trustly_Data {
128
  }
129
 
130
  }
131
-
132
- ?>
1
  <?php
2
+ /**
3
  * The MIT License (MIT)
4
+ *
5
  * Copyright (c) 2014 Trustly Group AB
6
+ *
7
  * Permission is hereby granted, free of charge, to any person obtaining a copy
8
  * of this software and associated documentation files (the "Software"), to deal
9
  * in the Software without restriction, including without limitation the rights
10
  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
  * copies of the Software, and to permit persons to whom the Software is
12
  * furnished to do so, subject to the following conditions:
13
+ *
14
  * The above copyright notice and this permission notice shall be included in
15
  * all copies or substantial portions of the Software.
16
+ *
17
  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
35
  }
36
  }
37
 
38
+ /* Utility function to vacuum the supplied data end remove unset
39
+ * values. This is used to keep the requests cleaner rather then
40
  * supplying NULL values in the payload */
41
  public function vacuum($data) {
42
  if(is_null($data)) {
58
  }
59
  }
60
 
61
+ /* Get the specific data value from the payload or the full payload if
62
  * no value is supplied */
63
  public function get($name=NULL) {
64
  if($name === NULL) {
71
  return NULL;
72
  }
73
 
74
+ /* Funciton to ensure that the given value is in UTF8. Used to make sure
75
  * all outgoing data is properly encoded in the call */
76
  public static function ensureUTF8($str) {
77
  if($str == NULL) {
112
  }
113
  }
114
 
115
+ /* Extremely naivly done and does not by far handle all cases, but
116
+ * handles the case it should, i.e. sort the data for the json
117
  * pretty printer */
118
  private function sortRecursive(&$data) {
119
  if(is_array($data)) {
128
  }
129
 
130
  }
131
+ /* vim: set noet cindent ts=4 ts=4 sw=4: */
 
app/code/community/Trustly/Trustly/lib/Trustly/Data/jsonrpcnotificationrequest.php CHANGED
@@ -1,19 +1,19 @@
1
  <?php
2
- /*
3
  * The MIT License (MIT)
4
- *
5
  * Copyright (c) 2014 Trustly Group AB
6
- *
7
  * Permission is hereby granted, free of charge, to any person obtaining a copy
8
  * of this software and associated documentation files (the "Software"), to deal
9
  * in the Software without restriction, including without limitation the rights
10
  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
  * copies of the Software, and to permit persons to whom the Software is
12
  * furnished to do so, subject to the following conditions:
13
- *
14
  * The above copyright notice and this permission notice shall be included in
15
  * all copies or substantial portions of the Software.
16
- *
17
  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
@@ -84,5 +84,4 @@ class Trustly_Data_JSONRPCNotificationRequest extends Trustly_Data {
84
  return $this->get('version');
85
  }
86
  }
87
-
88
- ?>
1
  <?php
2
+ /**
3
  * The MIT License (MIT)
4
+ *
5
  * Copyright (c) 2014 Trustly Group AB
6
+ *
7
  * Permission is hereby granted, free of charge, to any person obtaining a copy
8
  * of this software and associated documentation files (the "Software"), to deal
9
  * in the Software without restriction, including without limitation the rights
10
  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
  * copies of the Software, and to permit persons to whom the Software is
12
  * furnished to do so, subject to the following conditions:
13
+ *
14
  * The above copyright notice and this permission notice shall be included in
15
  * all copies or substantial portions of the Software.
16
+ *
17
  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
84
  return $this->get('version');
85
  }
86
  }
87
+ /* vim: set noet cindent ts=4 ts=4 sw=4: */
 
app/code/community/Trustly/Trustly/lib/Trustly/Data/jsonrpcnotificationresponse.php CHANGED
@@ -1,19 +1,19 @@
1
  <?php
2
- /*
3
  * The MIT License (MIT)
4
- *
5
  * Copyright (c) 2014 Trustly Group AB
6
- *
7
  * Permission is hereby granted, free of charge, to any person obtaining a copy
8
  * of this software and associated documentation files (the "Software"), to deal
9
  * in the Software without restriction, including without limitation the rights
10
  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
  * copies of the Software, and to permit persons to whom the Software is
12
  * furnished to do so, subject to the following conditions:
13
- *
14
  * The above copyright notice and this permission notice shall be included in
15
  * all copies or substantial portions of the Software.
16
- *
17
  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
@@ -122,6 +122,4 @@ class Trustly_Data_JSONRPCNotificationResponse extends Trustly_Data {
122
  return $this->getResult('uuid');
123
  }
124
  }
125
-
126
-
127
- ?>
1
  <?php
2
+ /**
3
  * The MIT License (MIT)
4
+ *
5
  * Copyright (c) 2014 Trustly Group AB
6
+ *
7
  * Permission is hereby granted, free of charge, to any person obtaining a copy
8
  * of this software and associated documentation files (the "Software"), to deal
9
  * in the Software without restriction, including without limitation the rights
10
  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
  * copies of the Software, and to permit persons to whom the Software is
12
  * furnished to do so, subject to the following conditions:
13
+ *
14
  * The above copyright notice and this permission notice shall be included in
15
  * all copies or substantial portions of the Software.
16
+ *
17
  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
122
  return $this->getResult('uuid');
123
  }
124
  }
125
+ /* vim: set noet cindent ts=4 ts=4 sw=4: */
 
 
app/code/community/Trustly/Trustly/lib/Trustly/Data/jsonrpcrequest.php CHANGED
@@ -1,19 +1,19 @@
1
  <?php
2
- /*
3
  * The MIT License (MIT)
4
- *
5
  * Copyright (c) 2014 Trustly Group AB
6
- *
7
  * Permission is hereby granted, free of charge, to any person obtaining a copy
8
  * of this software and associated documentation files (the "Software"), to deal
9
  * in the Software without restriction, including without limitation the rights
10
  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
  * copies of the Software, and to permit persons to whom the Software is
12
  * furnished to do so, subject to the following conditions:
13
- *
14
  * The above copyright notice and this permission notice shall be included in
15
  * all copies or substantial portions of the Software.
16
- *
17
  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
@@ -60,7 +60,7 @@ class Trustly_Data_JSONRPCRequest extends Trustly_Data_Request {
60
 
61
  }
62
 
63
- /* Three functions for getting, setting, or getting and removing value
64
  * in the 'params' section of the request payload */
65
  public function setParam($name, $value) {
66
  $this->payload['params'][$name] = Trustly_Data::ensureUTF8($value);
@@ -103,7 +103,7 @@ class Trustly_Data_JSONRPCRequest extends Trustly_Data_Request {
103
  return $this->get('method');
104
  }
105
 
106
- /* Two utility function for setting or getting data from the
107
  * 'params'->'Data' part of the payload. */
108
  public function setData($name, $value) {
109
  if(!isset($this->payload['params']['Data'])) {
@@ -126,7 +126,7 @@ class Trustly_Data_JSONRPCRequest extends Trustly_Data_Request {
126
  return NULL;
127
  }
128
 
129
- /* Two utility function for setting or getting data from the
130
  * 'params'->'Data'->'Attributes' part of the payload. */
131
  public function setAttribute($name, $value) {
132
  if(!isset($this->payload['params']['Data'])) {
@@ -147,4 +147,4 @@ class Trustly_Data_JSONRPCRequest extends Trustly_Data_Request {
147
  return NULL;
148
  }
149
  }
150
- ?>
1
  <?php
2
+ /**
3
  * The MIT License (MIT)
4
+ *
5
  * Copyright (c) 2014 Trustly Group AB
6
+ *
7
  * Permission is hereby granted, free of charge, to any person obtaining a copy
8
  * of this software and associated documentation files (the "Software"), to deal
9
  * in the Software without restriction, including without limitation the rights
10
  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
  * copies of the Software, and to permit persons to whom the Software is
12
  * furnished to do so, subject to the following conditions:
13
+ *
14
  * The above copyright notice and this permission notice shall be included in
15
  * all copies or substantial portions of the Software.
16
+ *
17
  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
60
 
61
  }
62
 
63
+ /* Three functions for getting, setting, or getting and removing value
64
  * in the 'params' section of the request payload */
65
  public function setParam($name, $value) {
66
  $this->payload['params'][$name] = Trustly_Data::ensureUTF8($value);
103
  return $this->get('method');
104
  }
105
 
106
+ /* Two utility function for setting or getting data from the
107
  * 'params'->'Data' part of the payload. */
108
  public function setData($name, $value) {
109
  if(!isset($this->payload['params']['Data'])) {
126
  return NULL;
127
  }
128
 
129
+ /* Two utility function for setting or getting data from the
130
  * 'params'->'Data'->'Attributes' part of the payload. */
131
  public function setAttribute($name, $value) {
132
  if(!isset($this->payload['params']['Data'])) {
147
  return NULL;
148
  }
149
  }
150
+ /* vim: set noet cindent ts=4 ts=4 sw=4: */
app/code/community/Trustly/Trustly/lib/Trustly/Data/jsonrpcresponse.php CHANGED
@@ -1,19 +1,19 @@
1
  <?php
2
- /*
3
  * The MIT License (MIT)
4
- *
5
  * Copyright (c) 2014 Trustly Group AB
6
- *
7
  * Permission is hereby granted, free of charge, to any person obtaining a copy
8
  * of this software and associated documentation files (the "Software"), to deal
9
  * in the Software without restriction, including without limitation the rights
10
  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
  * copies of the Software, and to permit persons to whom the Software is
12
  * furnished to do so, subject to the following conditions:
13
- *
14
  * The above copyright notice and this permission notice shall be included in
15
  * all copies or substantial portions of the Software.
16
- *
17
  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
@@ -33,41 +33,43 @@ class Trustly_Data_JSONRPCResponse extends Trustly_Data_Response {
33
  throw new Trustly_JSONRPCVersionException("JSON RPC Version $version is not supported. " . json_encode($this->payload));
34
  }
35
 
36
- if($this->isError()) {
37
- $this->response_result = $this->response_result['error'];
38
- }
39
- }
40
-
41
- public function getData($name=NULL) {
42
- $data = NULL;
43
- if(isset($this->payload['result']['data'])) {
44
- $data = $this->payload['result']['data'];
45
- }else {
46
- return NULL;
47
- }
48
-
49
- if(isset($name)) {
50
- if(isset($data[$name])) {
51
- return $data[$name];
52
- }
53
- } else {
54
- return $data;
55
- }
 
 
 
56
  }
57
 
58
  public function getErrorCode() {
59
- if($this->isError() && isset($this->response_result['data']['code'])) {
60
- return $this->response_result['data']['code'];
61
  }
62
  return NULL;
63
  }
64
 
65
  public function getErrorMessage() {
66
- if($this->isError() && isset($this->response_result['data']['message'])) {
67
- return $this->response_result['data']['message'];
68
  }
69
  return NULL;
70
  }
71
  }
72
-
73
- ?>
1
  <?php
2
+ /**
3
  * The MIT License (MIT)
4
+ *
5
  * Copyright (c) 2014 Trustly Group AB
6
+ *
7
  * Permission is hereby granted, free of charge, to any person obtaining a copy
8
  * of this software and associated documentation files (the "Software"), to deal
9
  * in the Software without restriction, including without limitation the rights
10
  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
  * copies of the Software, and to permit persons to whom the Software is
12
  * furnished to do so, subject to the following conditions:
13
+ *
14
  * The above copyright notice and this permission notice shall be included in
15
  * all copies or substantial portions of the Software.
16
+ *
17
  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
33
  throw new Trustly_JSONRPCVersionException("JSON RPC Version $version is not supported. " . json_encode($this->payload));
34
  }
35
 
36
+ /* An unsigned JSON RPC Error result basically looks like this:
37
+ * {
38
+ * "version": "1.1",
39
+ * "error": {
40
+ * "name": "JSONRPCError",
41
+ * "code": 620,
42
+ * "message": "ERROR_UNKNOWN"
43
+ * }
44
+ * }
45
+ *
46
+ * And a unsigned result will be on the form:
47
+ * {
48
+ * "version": "1.1",
49
+ * "result": {
50
+ * "now": "...",
51
+ * "data": []
52
+ * }
53
+ * }
54
+ *
55
+ * We want response_result to always be the result of the
56
+ * operation, The Trustly_Data will point response_result /result
57
+ * or /error respectivly, we need to do nothing extra here
58
+ * */
59
  }
60
 
61
  public function getErrorCode() {
62
+ if($this->isError() && isset($this->response_result['code'])) {
63
+ return $this->response_result['code'];
64
  }
65
  return NULL;
66
  }
67
 
68
  public function getErrorMessage() {
69
+ if($this->isError() && isset($this->response_result['message'])) {
70
+ return $this->response_result['message'];
71
  }
72
  return NULL;
73
  }
74
  }
75
+ /* vim: set noet cindent ts=4 ts=4 sw=4: */
 
app/code/community/Trustly/Trustly/lib/Trustly/Data/jsonrpcsignedresponse.php ADDED
@@ -0,0 +1,102 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ * The MIT License (MIT)
4
+ *
5
+ * Copyright (c) 2014 Trustly Group AB
6
+ *
7
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
8
+ * of this software and associated documentation files (the "Software"), to deal
9
+ * in the Software without restriction, including without limitation the rights
10
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
+ * copies of the Software, and to permit persons to whom the Software is
12
+ * furnished to do so, subject to the following conditions:
13
+ *
14
+ * The above copyright notice and this permission notice shall be included in
15
+ * all copies or substantial portions of the Software.
16
+ *
17
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23
+ * THE SOFTWARE.
24
+ */
25
+
26
+ class Trustly_Data_JSONRPCSignedResponse extends Trustly_Data_JSONRPCResponse {
27
+ public function __construct($response_body, $curl) {
28
+ parent::__construct($response_body, $curl);
29
+
30
+ /* A signed JSON RPC Error result basically looks like this:
31
+ * {
32
+ * "version": "1.1",
33
+ * "error": {
34
+ * "error": {
35
+ * "signature": "...",
36
+ * "data": {
37
+ * "code": 620,
38
+ * "message": "ERROR_UNKNOWN"
39
+ * },
40
+ * "method": "...",
41
+ * "uuid": "..."
42
+ * },
43
+ * "name": "JSONRPCError",
44
+ * "code": 620,
45
+ * "message": "ERROR_UNKNOWN"
46
+ * }
47
+ * }
48
+ *
49
+ * A good signed result will be on the form:
50
+ * {
51
+ * "version": "1.1",
52
+ * "result": {
53
+ * "signature": "...",
54
+ * "method": "...",
55
+ * "data": {
56
+ * "url": "...",
57
+ * "orderid": "..."
58
+ * },
59
+ * "uuid": "...",
60
+ * }
61
+ * }
62
+ *
63
+ * The Trustly_Data will point response_result /result or /error respectivly, we need to take care of the signed part here only.
64
+ * */
65
+ if($this->isError()) {
66
+ $this->response_result = $this->response_result['error'];
67
+ }
68
+ }
69
+
70
+ public function getData($name=NULL) {
71
+ $data = NULL;
72
+
73
+ if(isset($this->response_result['data'])) {
74
+ $data = $this->response_result['data'];
75
+ }else {
76
+ return NULL;
77
+ }
78
+
79
+ if(isset($name)) {
80
+ if(isset($data[$name])) {
81
+ return $data[$name];
82
+ }
83
+ } else {
84
+ return $data;
85
+ }
86
+ }
87
+
88
+ public function getErrorCode() {
89
+ if($this->isError() && isset($this->response_result['data']['code'])) {
90
+ return $this->response_result['data']['code'];
91
+ }
92
+ return NULL;
93
+ }
94
+
95
+ public function getErrorMessage() {
96
+ if($this->isError() && isset($this->response_result['data']['message'])) {
97
+ return $this->response_result['data']['message'];
98
+ }
99
+ return NULL;
100
+ }
101
+ }
102
+ /* vim: set noet cindent ts=4 ts=4 sw=4: */
app/code/community/Trustly/Trustly/lib/Trustly/Data/request.php CHANGED
@@ -1,19 +1,19 @@
1
  <?php
2
- /*
3
  * The MIT License (MIT)
4
- *
5
  * Copyright (c) 2014 Trustly Group AB
6
- *
7
  * Permission is hereby granted, free of charge, to any person obtaining a copy
8
  * of this software and associated documentation files (the "Software"), to deal
9
  * in the Software without restriction, including without limitation the rights
10
  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
  * copies of the Software, and to permit persons to whom the Software is
12
  * furnished to do so, subject to the following conditions:
13
- *
14
  * The above copyright notice and this permission notice shall be included in
15
  * all copies or substantial portions of the Software.
16
- *
17
  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
@@ -53,5 +53,4 @@ class Trustly_Data_Request extends Trustly_Data {
53
  $this->method = $method;
54
  }
55
  }
56
-
57
- ?>
1
  <?php
2
+ /**
3
  * The MIT License (MIT)
4
+ *
5
  * Copyright (c) 2014 Trustly Group AB
6
+ *
7
  * Permission is hereby granted, free of charge, to any person obtaining a copy
8
  * of this software and associated documentation files (the "Software"), to deal
9
  * in the Software without restriction, including without limitation the rights
10
  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
  * copies of the Software, and to permit persons to whom the Software is
12
  * furnished to do so, subject to the following conditions:
13
+ *
14
  * The above copyright notice and this permission notice shall be included in
15
  * all copies or substantial portions of the Software.
16
+ *
17
  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
53
  $this->method = $method;
54
  }
55
  }
56
+ /* vim: set noet cindent ts=4 ts=4 sw=4: */
 
app/code/community/Trustly/Trustly/lib/Trustly/Data/response.php CHANGED
@@ -1,19 +1,19 @@
1
  <?php
2
- /*
3
  * The MIT License (MIT)
4
- *
5
  * Copyright (c) 2014 Trustly Group AB
6
- *
7
  * Permission is hereby granted, free of charge, to any person obtaining a copy
8
  * of this software and associated documentation files (the "Software"), to deal
9
  * in the Software without restriction, including without limitation the rights
10
  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
  * copies of the Software, and to permit persons to whom the Software is
12
  * furnished to do so, subject to the following conditions:
13
- *
14
  * The above copyright notice and this permission notice shall be included in
15
  * all copies or substantial portions of the Software.
16
- *
17
  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
@@ -28,19 +28,19 @@ class Trustly_Data_Response extends Trustly_Data {
28
  var $response_body = NULL;
29
  /* The response HTTP code */
30
  var $response_code = NULL;
31
- /* Shortcut to the part of the result being actually interesting. The
32
  * guts will contain all returned data. */
33
  var $response_result = NULL;
34
 
35
  public function __construct($response_body, $curl) {
36
 
37
- $this->response_code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
38
  $this->response_body = $response_body;
39
 
40
  $payload = json_decode($response_body, TRUE);
41
  if($payload === FALSE) {
42
- /* Only throw the connection error exception here if we did not
43
- * receive a valid JSON response, if we did recive one we will use
44
  * the error information in that response instead. */
45
  if($this->response_code !== 200) {
46
  throw new Trustly_ConnectionException('HTTP ' . $this->response_code);
@@ -50,8 +50,8 @@ class Trustly_Data_Response extends Trustly_Data {
50
  }
51
  parent::__construct($payload);
52
 
53
- /* Attempt to detect the type of the response. A successful call
54
- * will have a 'result' on toplevel in the payload, while an
55
  * failure will have a 'error' on the tyoplevel */
56
  $this->response_result = &$this->payload['result'];
57
  if($this->response_result === NULL) {
@@ -128,5 +128,4 @@ class Trustly_Data_Response extends Trustly_Data {
128
  return NULL;
129
  }
130
  }
131
-
132
- ?>
1
  <?php
2
+ /**
3
  * The MIT License (MIT)
4
+ *
5
  * Copyright (c) 2014 Trustly Group AB
6
+ *
7
  * Permission is hereby granted, free of charge, to any person obtaining a copy
8
  * of this software and associated documentation files (the "Software"), to deal
9
  * in the Software without restriction, including without limitation the rights
10
  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
  * copies of the Software, and to permit persons to whom the Software is
12
  * furnished to do so, subject to the following conditions:
13
+ *
14
  * The above copyright notice and this permission notice shall be included in
15
  * all copies or substantial portions of the Software.
16
+ *
17
  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
28
  var $response_body = NULL;
29
  /* The response HTTP code */
30
  var $response_code = NULL;
31
+ /* Shortcut to the part of the result being actually interesting. The
32
  * guts will contain all returned data. */
33
  var $response_result = NULL;
34
 
35
  public function __construct($response_body, $curl) {
36
 
37
+ $this->response_code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
38
  $this->response_body = $response_body;
39
 
40
  $payload = json_decode($response_body, TRUE);
41
  if($payload === FALSE) {
42
+ /* Only throw the connection error exception here if we did not
43
+ * receive a valid JSON response, if we did recive one we will use
44
  * the error information in that response instead. */
45
  if($this->response_code !== 200) {
46
  throw new Trustly_ConnectionException('HTTP ' . $this->response_code);
50
  }
51
  parent::__construct($payload);
52
 
53
+ /* Attempt to detect the type of the response. A successful call
54
+ * will have a 'result' on toplevel in the payload, while an
55
  * failure will have a 'error' on the tyoplevel */
56
  $this->response_result = &$this->payload['result'];
57
  if($this->response_result === NULL) {
128
  return NULL;
129
  }
130
  }
131
+ /* vim: set noet cindent ts=4 ts=4 sw=4: */
 
app/code/community/Trustly/Trustly/lib/Trustly/exceptions.php CHANGED
@@ -1,19 +1,19 @@
1
  <?php
2
- /*
3
  * The MIT License (MIT)
4
- *
5
  * Copyright (c) 2014 Trustly Group AB
6
- *
7
  * Permission is hereby granted, free of charge, to any person obtaining a copy
8
  * of this software and associated documentation files (the "Software"), to deal
9
  * in the Software without restriction, including without limitation the rights
10
  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
  * copies of the Software, and to permit persons to whom the Software is
12
  * furnished to do so, subject to the following conditions:
13
- *
14
  * The above copyright notice and this permission notice shall be included in
15
  * all copies or substantial portions of the Software.
16
- *
17
  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
@@ -43,4 +43,4 @@ class Trustly_DataException extends Exception { }
43
 
44
  class Trustly_AuthentificationException extends Exception { }
45
 
46
- ?>
1
  <?php
2
+ /**
3
  * The MIT License (MIT)
4
+ *
5
  * Copyright (c) 2014 Trustly Group AB
6
+ *
7
  * Permission is hereby granted, free of charge, to any person obtaining a copy
8
  * of this software and associated documentation files (the "Software"), to deal
9
  * in the Software without restriction, including without limitation the rights
10
  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
  * copies of the Software, and to permit persons to whom the Software is
12
  * furnished to do so, subject to the following conditions:
13
+ *
14
  * The above copyright notice and this permission notice shall be included in
15
  * all copies or substantial portions of the Software.
16
+ *
17
  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
43
 
44
  class Trustly_AuthentificationException extends Exception { }
45
 
46
+ /* vim: set noet cindent ts=4 ts=4 sw=4: */
app/code/community/Trustly/Trustly/sql/trustly_setup/install-2.0.4.php CHANGED
@@ -14,8 +14,8 @@ if(!$installer->getConnection()->isTableExists($installer->getTable('trustly/ord
14
  $installer->getTable('trustly/ordermappings'),
15
  array('trustly_order_id'),
16
  Varien_Db_Adapter_Interface::INDEX_TYPE_INDEX
17
- ),
18
- array('trustly_order_id'),
19
  array('type' => Varien_Db_Adapter_Interface::INDEX_TYPE_INDEX)
20
  );
21
  $installer->getConnection()->createTable($table);
14
  $installer->getTable('trustly/ordermappings'),
15
  array('trustly_order_id'),
16
  Varien_Db_Adapter_Interface::INDEX_TYPE_INDEX
17
+ ),
18
+ array('trustly_order_id'),
19
  array('type' => Varien_Db_Adapter_Interface::INDEX_TYPE_INDEX)
20
  );
21
  $installer->getConnection()->createTable($table);
app/code/community/Trustly/Trustly/sql/trustly_setup/upgrade-1.0.5-2.0.0.php CHANGED
@@ -11,8 +11,8 @@ $table = $installer->getConnection()->newTable($installer->getTable('trustly/ord
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);
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);
app/code/community/Trustly/Trustly/sql/trustly_setup/upgrade-2.0.3-2.0.4.php CHANGED
@@ -18,9 +18,9 @@ $connection->modifyColumn(
18
 
19
  $connection->addColumn(
20
  $ordermappingstable,
21
- 'lock_timestamp',
22
  array(
23
- 'type' => Varien_Db_Ddl_Table::TYPE_TIMESTAMP,
24
  'nullable' => true,
25
  'comment' => 'Lock timestamp'
26
  )
@@ -28,9 +28,9 @@ $connection->addColumn(
28
 
29
  $connection->addColumn(
30
  $ordermappingstable,
31
- 'lock_id',
32
  array(
33
- 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER,
34
  'unsigned' => true,
35
  'nullable' => true,
36
  'comment' => 'Lock process id'
18
 
19
  $connection->addColumn(
20
  $ordermappingstable,
21
+ 'lock_timestamp',
22
  array(
23
+ 'type' => Varien_Db_Ddl_Table::TYPE_TIMESTAMP,
24
  'nullable' => true,
25
  'comment' => 'Lock timestamp'
26
  )
28
 
29
  $connection->addColumn(
30
  $ordermappingstable,
31
+ 'lock_id',
32
  array(
33
+ 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER,
34
  'unsigned' => true,
35
  'nullable' => true,
36
  'comment' => 'Lock process id'
app/design/frontend/base/default/template/trustly/iframe.phtml CHANGED
@@ -1,7 +1,7 @@
1
  <div class="page-title">
2
  <h1><?php echo Mage::helper('trustly')->__('Direct banking') ?></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>
1
  <div class="page-title">
2
  <h1><?php echo Mage::helper('trustly')->__('Direct banking') ?></h1>
3
  </div>
4
+ <p class="trustly_image"><img src="https://static.trustly.com/logotype/footer/trustly_140.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>
app/design/frontend/base/default/template/trustly/mark.phtml CHANGED
@@ -1,4 +1,4 @@
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>
1
+ <img src="https://static.trustly.com/logotype/checkout/trustly_73.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>
package.xml CHANGED
@@ -1,7 +1,7 @@
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>Trustly</name>
4
- <version>2.0.7</version>
5
  <stability>stable</stability>
6
  <license uri="http://www.gnu.org/copyleft/gpl.html">GPL 3</license>
7
  <channel>community</channel>
@@ -16,8 +16,8 @@
16
  <email>info@trustly.com</email>
17
  </author>
18
  </authors>
19
- <date>2014-08-19</date>
20
- <time>11:19:51</time>
21
  <contents>
22
  <target name="magelocale">
23
  <dir name="da_DK">
@@ -59,16 +59,16 @@
59
  </dir>
60
  <dir name="Model">
61
  <dir name="Mysql4">
62
- <file name="Ordermappings.php" hash="5372011caf25ca770d8c43922925c563"/>
63
  </dir>
64
- <file name="Ordermappings.php" hash="e1053123e3f2ba61b0d1a52b1fd2c831"/>
65
- <file name="Standard.php" hash="abee6ee1a3415bbccf38e3972bc91279"/>
66
  </dir>
67
  <dir name="controllers">
68
- <file name="PaymentController.php" hash="12ad7101ec3e5778660eee8df4ab8cc7"/>
69
  </dir>
70
  <dir name="etc">
71
- <file name="config.xml" hash="478fb0941166e90bba3447d1f2419fd4"/>
72
  <file name="system.xml" hash="d92061e410e4e923eb39fa59f2e00927"/>
73
  </dir>
74
  <dir name="lib">
@@ -78,30 +78,31 @@
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="5afb8836cf39828eaf685c6db6166b5c"/>
82
- <file name="ecommerce.php" hash="54e3b19bba389956afb71b5e31c6c1c8"/>
83
- <file name="signed.php" hash="47db2a74779ae5c554d4b7439d9751e3"/>
84
- <file name="unsigned.php" hash="5d667d0863cb5e84fe0365da95e7b6c4"/>
85
  </dir>
86
  <dir name="Data">
87
- <file name="data.php" hash="fce249eeec0ecaebc5052fb77b6631c5"/>
88
- <file name="jsonrpcnotificationrequest.php" hash="723ba8d9ec08bb8a988dcb1c3918776f"/>
89
- <file name="jsonrpcnotificationresponse.php" hash="d4c5d350380ff149e74e6855dc10123d"/>
90
- <file name="jsonrpcrequest.php" hash="a72ee040fac312a5ef124de4af7ccb8f"/>
91
- <file name="jsonrpcresponse.php" hash="617fef3a4e029d9320f7426502e6a5c8"/>
92
- <file name="request.php" hash="44822805f50a4520f53a4b1a2722295a"/>
93
- <file name="response.php" hash="39433a754c395a863aaa76f1bbba4527"/>
 
94
  </dir>
95
- <file name="exceptions.php" hash="e583e378d6f3f6e4fe2eadcf9b3f6ee4"/>
96
  </dir>
97
  <file name="LICENCE" hash="8713032dd477873c84ed4ff4b7da5f70"/>
98
- <file name="Trustly.php" hash="e7115c7872a87c2191b4f90b0dc0e97a"/>
99
  </dir>
100
  <dir name="sql">
101
  <dir name="trustly_setup">
102
- <file name="install-2.0.4.php" hash="ca6855a238407e68356568c9c5a380ee"/>
103
- <file name="upgrade-1.0.5-2.0.0.php" hash="2badbe7703f9416f88f0a9cf458a8b5e"/>
104
- <file name="upgrade-2.0.3-2.0.4.php" hash="1e826daddf5f2204e14142d6cac6d2a4"/>
105
  </dir>
106
  </dir>
107
  </dir>
@@ -113,16 +114,6 @@
113
  </dir>
114
  </target>
115
  <target name="mageskin">
116
- <dir name="frontend">
117
- <dir name="base">
118
- <dir name="default">
119
- <dir name="images">
120
- <file name="trustly-big.png" hash="ace4a2fcd8306b7e5835076340c7877b"/>
121
- <file name="trustly-small.png" hash="f99283dadd49b60e6a68962eda43f83f"/>
122
- </dir>
123
- </dir>
124
- </dir>
125
- </dir>
126
  </target>
127
  <target name="magedesign">
128
  <dir name="frontend">
@@ -134,8 +125,8 @@
134
  <dir name="template">
135
  <dir name="trustly">
136
  <file name="form.phtml" hash="f37a2b86d35eea0a8cd6ec176d466424"/>
137
- <file name="iframe.phtml" hash="be80b2c6cf1d74f134624444447a7e8d"/>
138
- <file name="mark.phtml" hash="76011840449ff5067311d2f2987bdd7d"/>
139
  </dir>
140
  </dir>
141
  </dir>
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>Trustly</name>
4
+ <version>2.0.8</version>
5
  <stability>stable</stability>
6
  <license uri="http://www.gnu.org/copyleft/gpl.html">GPL 3</license>
7
  <channel>community</channel>
16
  <email>info@trustly.com</email>
17
  </author>
18
  </authors>
19
+ <date>2014-12-01</date>
20
+ <time>11:19:54</time>
21
  <contents>
22
  <target name="magelocale">
23
  <dir name="da_DK">
59
  </dir>
60
  <dir name="Model">
61
  <dir name="Mysql4">
62
+ <file name="Ordermappings.php" hash="9a20e6607ef45773b1fd3beca10dc47c"/>
63
  </dir>
64
+ <file name="Ordermappings.php" hash="b2871d0594151a48e329bc950d09ab76"/>
65
+ <file name="Standard.php" hash="50ff94700a51c7ad89be88f1b99bfc76"/>
66
  </dir>
67
  <dir name="controllers">
68
+ <file name="PaymentController.php" hash="a3dfc93ea5209f7fa8cb73876ae5b32d"/>
69
  </dir>
70
  <dir name="etc">
71
+ <file name="config.xml" hash="d4f5ca9a2f47ea0b58b77d653512ed0d"/>
72
  <file name="system.xml" hash="d92061e410e4e923eb39fa59f2e00927"/>
73
  </dir>
74
  <dir name="lib">
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="9a4f82b8d7cad47841f304307d2d5846"/>
82
+ <file name="ecommerce.php" hash="c1a08d59a379ab34a40d707dbc59e51d"/>
83
+ <file name="signed.php" hash="48b6a27776ab5c5e8bad8658d7c33769"/>
84
+ <file name="unsigned.php" hash="c3a60853757caf73f5fda798be931e2c"/>
85
  </dir>
86
  <dir name="Data">
87
+ <file name="data.php" hash="3219d091f894cffe9dce55c24c64af7f"/>
88
+ <file name="jsonrpcnotificationrequest.php" hash="00a29b82d7fbbdbc823534cf7b024840"/>
89
+ <file name="jsonrpcnotificationresponse.php" hash="9ffc52a8a52b03a7f737144d7c651946"/>
90
+ <file name="jsonrpcrequest.php" hash="ad057f824143361c629575e355a168ff"/>
91
+ <file name="jsonrpcresponse.php" hash="45c31a0a6642b42d1f4b3f3887a39203"/>
92
+ <file name="jsonrpcsignedresponse.php" hash="0fdcb9de9f5c6d2600c64852c4eaad79"/>
93
+ <file name="request.php" hash="34a0927f88912ed9fdee247a28e74c57"/>
94
+ <file name="response.php" hash="879837bdd13dfd75d812f170ea4918e7"/>
95
  </dir>
96
+ <file name="exceptions.php" hash="76824da93a3bb855a248ec3f27f84fe8"/>
97
  </dir>
98
  <file name="LICENCE" hash="8713032dd477873c84ed4ff4b7da5f70"/>
99
+ <file name="Trustly.php" hash="c2d7e9268b03e89699ad17047dd78bc3"/>
100
  </dir>
101
  <dir name="sql">
102
  <dir name="trustly_setup">
103
+ <file name="install-2.0.4.php" hash="8adab66e05093992264374b613c8f796"/>
104
+ <file name="upgrade-1.0.5-2.0.0.php" hash="305e6535758a1da91b107a4a6b5b33d5"/>
105
+ <file name="upgrade-2.0.3-2.0.4.php" hash="cb345308065dbac8985db01ebc61f628"/>
106
  </dir>
107
  </dir>
108
  </dir>
114
  </dir>
115
  </target>
116
  <target name="mageskin">
 
 
 
 
 
 
 
 
 
 
117
  </target>
118
  <target name="magedesign">
119
  <dir name="frontend">
125
  <dir name="template">
126
  <dir name="trustly">
127
  <file name="form.phtml" hash="f37a2b86d35eea0a8cd6ec176d466424"/>
128
+ <file name="iframe.phtml" hash="eb8fe39d00643f27c392845f5b535a44"/>
129
+ <file name="mark.phtml" hash="247201e74fde66ffdca19045a28ff667"/>
130
  </dir>
131
  </dir>
132
  </dir>
skin/frontend/base/default/images/trustly-big.png DELETED
Binary file
skin/frontend/base/default/images/trustly-small.png DELETED
Binary file