klarnapayments - Version 5.2.0

Version Notes

This version is not compatible with any Klarna module version of 4.x or earlier.

Download this release

Release Info

Developer Klarna
Extension klarnapayments
Version 5.2.0
Comparing to
See all releases


Code changes from version 5.1.7 to 5.2.0

Files changed (136) hide show
  1. app/code/community/Vaimo/Klarna/Block/Adminhtml/Pclass/List.php +4 -4
  2. app/code/community/Vaimo/Klarna/Block/Catalog/Product/Pricewidget.php +16 -6
  3. app/code/community/Vaimo/Klarna/Block/Checkout/Top.php +3 -3
  4. app/code/community/Vaimo/Klarna/Block/Form/Abstract.php +58 -48
  5. app/code/community/Vaimo/Klarna/Block/Form/Address/Search.php +3 -3
  6. app/code/community/Vaimo/Klarna/Block/Form/Checkout.php +83 -0
  7. app/code/community/Vaimo/Klarna/Block/Info/Abstract.php +24 -10
  8. app/code/community/Vaimo/Klarna/{Model/Klarna/Info.php → Block/Info/Checkout.php} +35 -34
  9. app/code/community/Vaimo/Klarna/Block/Klarnacheckout/Autofill.php +64 -0
  10. app/code/community/Vaimo/Klarna/Block/Klarnacheckout/Customer/Balance.php +72 -0
  11. app/code/community/Vaimo/Klarna/Block/Klarnacheckout/Discount.php +43 -0
  12. app/code/community/Vaimo/Klarna/Block/Klarnacheckout/Ga.php +103 -0
  13. app/code/community/Vaimo/Klarna/{Model/Klarna/Form.php → Block/Klarnacheckout/Klarnacheckout.php} +20 -16
  14. app/code/community/Vaimo/Klarna/Block/Klarnacheckout/Newsletter.php +74 -0
  15. app/code/community/Vaimo/Klarna/Block/Klarnacheckout/Othermethod.php +89 -0
  16. app/code/community/Vaimo/Klarna/Block/Klarnacheckout/Reward.php +81 -0
  17. app/code/community/Vaimo/Klarna/{Model/Klarna/Widget.php → Block/Klarnacheckout/Success.php} +15 -12
  18. app/code/community/Vaimo/Klarna/Block/Page/Html/Logo.php +34 -13
  19. app/code/community/Vaimo/Klarna/Helper/Data.php +238 -18
  20. app/code/community/Vaimo/Klarna/Model/Api.php +104 -0
  21. app/code/community/Vaimo/Klarna/{Tests/TestCase.php → Model/Api/Abstract.php} +29 -17
  22. app/code/community/Vaimo/Klarna/Model/Api/Kco.php +495 -0
  23. app/code/community/Vaimo/Klarna/Model/Api/Rest.php +848 -0
  24. app/code/community/Vaimo/Klarna/Model/{Klarna/Api.php → Api/Xmlrpc.php} +643 -611
  25. app/code/community/Vaimo/Klarna/Model/Creditmemo/Tax.php +20 -1
  26. app/code/community/Vaimo/Klarna/Model/Creditmemo/Total.php +33 -4
  27. app/code/community/Vaimo/Klarna/Model/Invoice/Pdf/Total.php +50 -4
  28. app/code/community/Vaimo/Klarna/Model/Invoice/Tax.php +22 -2
  29. app/code/community/Vaimo/Klarna/Model/Invoice/Total.php +22 -2
  30. app/code/community/Vaimo/Klarna/Model/Klarna.php +586 -0
  31. app/code/community/Vaimo/Klarna/Model/Klarna/Abstract.php +1096 -0
  32. app/code/community/Vaimo/Klarna/Model/Klarna/Assign.php +0 -352
  33. app/code/community/Vaimo/Klarna/Model/Klarna/Authorize.php +0 -81
  34. app/code/community/Vaimo/Klarna/Model/Klarna/Tools/Address.php +0 -183
  35. app/code/community/Vaimo/Klarna/Model/Klarna/Tools/Api.php +0 -744
  36. app/code/community/Vaimo/Klarna/Model/Klarna/Validate.php +0 -161
  37. app/code/community/Vaimo/Klarna/Model/Klarnacheckout.php +425 -0
  38. app/code/community/Vaimo/Klarna/Model/Klarnacheckout/Abstract.php +192 -0
  39. app/code/community/Vaimo/Klarna/Model/Observer.php +56 -8
  40. app/code/community/Vaimo/Klarna/Model/Payment/Abstract.php +196 -114
  41. app/code/community/Vaimo/Klarna/Model/Payment/Account.php +4 -5
  42. app/code/community/Vaimo/Klarna/Model/Payment/Checkout.php +67 -0
  43. app/code/community/Vaimo/Klarna/Model/Payment/Invoice.php +5 -6
  44. app/code/community/Vaimo/Klarna/Model/Payment/Special.php +4 -5
  45. app/code/community/Vaimo/Klarna/Model/Quote/Tax.php +60 -8
  46. app/code/community/Vaimo/Klarna/Model/Quote/Total.php +24 -7
  47. app/code/community/Vaimo/Klarna/Model/{Klarna/Capture.php → Source/Abstract.php} +36 -31
  48. app/code/community/Vaimo/Klarna/Model/Source/Allspecificcountries.php +3 -3
  49. app/code/community/Vaimo/Klarna/Model/{Klarna/Pclass.php → Source/Apiversion.php} +24 -11
  50. app/code/community/Vaimo/Klarna/Model/Source/Capture.php +3 -3
  51. app/code/community/Vaimo/Klarna/Model/Source/Country.php +8 -8
  52. app/code/community/Vaimo/Klarna/Model/{Klarna/Refund.php → Source/Customergroup.php} +31 -20
  53. app/code/community/Vaimo/Klarna/Model/Source/Language.php +8 -8
  54. app/code/community/Vaimo/Klarna/Model/Source/Newsletter.php +36 -0
  55. app/code/community/Vaimo/Klarna/Model/Source/Servermode.php +3 -3
  56. app/code/community/Vaimo/Klarna/Model/Source/Taxclass.php +2 -3
  57. app/code/community/Vaimo/Klarna/Model/Source/Yesnodefault.php +36 -0
  58. app/code/community/Vaimo/Klarna/Model/Tax/Config.php +25 -11
  59. app/code/community/Vaimo/Klarna/Model/{Klarna/Tools → Transport}/Abstract.php +232 -180
  60. app/code/community/Vaimo/Klarna/Tests/Model/Klarna/ApiTest.php +0 -62
  61. app/code/community/Vaimo/Klarna/Tests/Model/Klarna/ValidateTest.php +0 -183
  62. app/code/community/Vaimo/Klarna/controllers/AddressController.php +3 -3
  63. app/code/community/Vaimo/Klarna/controllers/Adminhtml/Klarna/PclassController.php +4 -4
  64. app/code/community/Vaimo/Klarna/controllers/Checkout/KlarnaController.php +671 -0
  65. app/code/community/Vaimo/Klarna/controllers/PaymentplanController.php +3 -3
  66. app/code/community/Vaimo/Klarna/etc/config.xml +72 -7
  67. app/code/community/Vaimo/Klarna/etc/system.xml +254 -3
  68. app/code/community/Vaimo/Klarna/sql/klarna_setup/mysql4-upgrade-5.1.6-5.1.7.php +72 -0
  69. app/design/adminhtml/default/default/template/vaimo/klarna/info/account.phtml +4 -1
  70. app/design/adminhtml/default/default/template/vaimo/klarna/info/checkout.phtml +43 -0
  71. app/design/adminhtml/default/default/template/vaimo/klarna/info/children/invoices.phtml +9 -3
  72. app/design/adminhtml/default/default/template/vaimo/klarna/info/children/reference.phtml +38 -0
  73. app/design/adminhtml/default/default/template/vaimo/klarna/info/children/reservation.phtml +1 -1
  74. app/design/adminhtml/default/default/template/vaimo/klarna/info/invoice.phtml +4 -1
  75. app/design/adminhtml/default/default/template/vaimo/klarna/info/special.phtml +4 -1
  76. app/design/frontend/base/default/layout/vaimo_klarna.xml +125 -0
  77. app/design/frontend/base/default/template/vaimo/klarna/form/address/search.phtml +2 -0
  78. app/design/frontend/base/default/template/vaimo/klarna/form/checkout.phtml +45 -0
  79. app/design/frontend/base/default/template/vaimo/klarna/info/checkout.phtml +34 -0
  80. app/design/frontend/base/default/template/vaimo/klarna/klarnacheckout/autofill.phtml +30 -0
  81. app/design/frontend/base/default/template/vaimo/klarna/klarnacheckout/cart.phtml +107 -0
  82. app/design/frontend/base/default/template/vaimo/klarna/klarnacheckout/cart/item/default.phtml +282 -0
  83. app/design/frontend/base/default/template/vaimo/klarna/klarnacheckout/cart/totals.phtml +57 -0
  84. app/design/frontend/base/default/template/vaimo/klarna/klarnacheckout/customer/balance.phtml +43 -0
  85. app/{code/community/Vaimo/Klarna/Model/Klarna/Addresssearch.php → design/frontend/base/default/template/vaimo/klarna/klarnacheckout/discount.phtml} +9 -8
  86. app/design/frontend/base/default/template/vaimo/klarna/klarnacheckout/discount/coupon.phtml +47 -0
  87. app/design/frontend/base/default/template/vaimo/klarna/klarnacheckout/discount/giftcardaccount.phtml +71 -0
  88. app/design/frontend/base/default/template/vaimo/klarna/klarnacheckout/header.phtml +35 -0
  89. app/{code/community/Vaimo/Klarna/Model/Klarna/Cancel.php → design/frontend/base/default/template/vaimo/klarna/klarnacheckout/klarnacheckout.phtml} +2 -10
  90. app/{code/community/Vaimo/Klarna/Model/Klarna/Available.php → design/frontend/base/default/template/vaimo/klarna/klarnacheckout/msg.phtml} +2 -9
  91. app/design/frontend/base/default/template/vaimo/klarna/klarnacheckout/newsletter.phtml +36 -0
  92. app/{code/community/Vaimo/Klarna/Tests/bootstrap.php → design/frontend/base/default/template/vaimo/klarna/klarnacheckout/othermethod.phtml} +10 -13
  93. app/design/frontend/base/default/template/vaimo/klarna/klarnacheckout/reward.phtml +37 -0
  94. app/design/frontend/base/default/template/vaimo/klarna/klarnacheckout/shipping_method.phtml +38 -0
  95. app/design/frontend/base/default/template/vaimo/klarna/klarnacheckout/shipping_method/available.phtml +63 -0
  96. app/design/frontend/base/default/template/vaimo/klarna/klarnacheckout/success.phtml +29 -0
  97. app/design/frontend/base/default/template/vaimo/klarna/page/html/logo.phtml +1 -1
  98. app/locale/da_DK/Vaimo_Klarna.csv +50 -6
  99. app/locale/de_AT/Vaimo_Klarna.csv +44 -0
  100. app/locale/de_DE/Vaimo_Klarna.csv +44 -0
  101. app/locale/fi_FI/Vaimo_Klarna.csv +50 -6
  102. app/locale/nb_NO/Vaimo_Klarna.csv +44 -0
  103. app/locale/nl_NL/Vaimo_Klarna.csv +44 -0
  104. app/locale/nn_NO/Vaimo_Klarna.csv +45 -1
  105. app/locale/sv_SE/Vaimo_Klarna.csv +46 -2
  106. js/vaimo/klarna/klarna.js +5 -2
  107. js/vaimo/klarna/klarnacheckout.js +675 -0
  108. lib/Klarna/Changelog-Vaimo.txt +19 -0
  109. lib/Klarna/Checkout.php +50 -0
  110. lib/Klarna/Checkout/BasicConnector.php +345 -0
  111. lib/Klarna/Checkout/ConnectionErrorException.php +43 -0
  112. lib/Klarna/Checkout/Connector.php +64 -0
  113. lib/Klarna/Checkout/ConnectorException.php +43 -0
  114. lib/Klarna/Checkout/ConnectorInterface.php +64 -0
  115. lib/Klarna/Checkout/Digest.php +54 -0
  116. lib/Klarna/Checkout/Exception.php +44 -0
  117. lib/Klarna/Checkout/HTTP/CURLFactory.php +52 -0
  118. lib/Klarna/Checkout/HTTP/CURLHandle.php +105 -0
  119. lib/Klarna/Checkout/HTTP/CURLHandleInterface.php +73 -0
  120. lib/Klarna/Checkout/HTTP/CURLHeaders.php +95 -0
  121. lib/Klarna/Checkout/HTTP/CURLTransport.php +182 -0
  122. lib/Klarna/Checkout/HTTP/Request.php +185 -0
  123. lib/Klarna/Checkout/HTTP/Response.php +142 -0
  124. lib/Klarna/Checkout/HTTP/Transport.php +54 -0
  125. lib/Klarna/Checkout/HTTP/TransportInterface.php +83 -0
  126. lib/Klarna/Checkout/Order.php +259 -0
  127. lib/Klarna/Checkout/ResourceInterface.php +81 -0
  128. lib/Klarna/Checkout/UserAgent.php +104 -0
  129. lib/Klarna/Klarna.php +3 -3
  130. lib/Klarna/{checkout → checkoutkpm}/checkouthtml.intf.php +0 -0
  131. lib/Klarna/{checkout → checkoutkpm}/threatmetrix.class.php +0 -0
  132. package.xml +6 -6
  133. skin/frontend/base/default/css/vaimo/klarna/checkout.css +40 -0
  134. skin/frontend/base/default/css/vaimo/klarna/checkout_osc.css +40 -0
  135. skin/frontend/base/default/css/vaimo/klarna/klarnacheckout.css +445 -0
  136. skin/frontend/base/default/images/vaimo/klarna/icons.png +0 -0
app/code/community/Vaimo/Klarna/Block/Adminhtml/Pclass/List.php CHANGED
@@ -60,10 +60,10 @@ class Vaimo_Klarna_Block_Adminhtml_Pclass_List extends Mage_Adminhtml_Block_Syst
60
  {
61
  try {
62
  $res = array();
63
- $klarnaPClass = Mage::getModel('klarna/klarna_pclass');
64
- $klarnaPClass->setMethod(Vaimo_Klarna_Helper_Data::KLARNA_METHOD_ACCOUNT);
65
- $klarnaPClass->setStoreInformation(NULL);
66
- $res = $klarnaPClass->getDisplayAllPClasses();
67
  } catch (Mage_Core_Exception $e) {
68
  $res['error'] = $e->getMessage();
69
  }
60
  {
61
  try {
62
  $res = array();
63
+ $klarna = Mage::getModel('klarna/klarna');
64
+ $klarna->setStoreInformation();
65
+ $klarna->setMethod(Vaimo_Klarna_Helper_Data::KLARNA_METHOD_ACCOUNT);
66
+ $res = $klarna->getDisplayAllPClasses();
67
  } catch (Mage_Core_Exception $e) {
68
  $res['error'] = $e->getMessage();
69
  }
app/code/community/Vaimo/Klarna/Block/Catalog/Product/Pricewidget.php CHANGED
@@ -57,12 +57,22 @@ class Vaimo_Klarna_Block_Catalog_Product_Pricewidget extends Mage_Core_Block_Tem
57
  */
58
  public function getWidgetParameters()
59
  {
60
- $klarnaWidget = Mage::getModel('klarna/klarna_widget');
61
- $klarnaWidget->setQuote($this->getQuote(), Vaimo_Klarna_Helper_Data::KLARNA_METHOD_ACCOUNT);
62
- $klarnaSetup = $klarnaWidget->getKlarnaSetup();
63
- if ($klarnaSetup) {
64
- if($klarnaSetup->getCountryCode() != 'NL' && $klarnaSetup->getCountryCode() != 'AT') {
65
- return $klarnaSetup;
 
 
 
 
 
 
 
 
 
 
66
  }
67
  }
68
  return NULL;
57
  */
58
  public function getWidgetParameters()
59
  {
60
+ $activef = true;
61
+ $klarna = Mage::getModel('klarna/klarna');
62
+ $klarna->setQuote($this->getQuote(), Vaimo_Klarna_Helper_Data::KLARNA_METHOD_CHECKOUT);
63
+ if ($klarna->getConfigData('disable_product_widget')) {
64
+ $activef = false;
65
+ }
66
+ $klarna->setQuote($this->getQuote(), Vaimo_Klarna_Helper_Data::KLARNA_METHOD_ACCOUNT);
67
+ if ($klarna->getConfigData('disable_product_widget')) {
68
+ $activef = false;
69
+ }
70
+ if ($activef) {
71
+ $klarnaSetup = $klarna->getKlarnaSetup();
72
+ if ($klarnaSetup) {
73
+ if($klarnaSetup->getCountryCode() != 'NL' && $klarnaSetup->getCountryCode() != 'AT') {
74
+ return $klarnaSetup;
75
+ }
76
  }
77
  }
78
  return NULL;
app/code/community/Vaimo/Klarna/Block/Checkout/Top.php CHANGED
@@ -27,9 +27,9 @@ class Vaimo_Klarna_Block_Checkout_Top extends Mage_Checkout_Block_Cart_Abstract
27
  {
28
  public function getKlarnaSetup($method)
29
  {
30
- $klarnaForm = Mage::getModel('klarna/klarna_form');
31
- $klarnaForm->setQuote($this->getQuote(), $method);
32
- return $klarnaForm->getKlarnaSetup();
33
  }
34
 
35
  public function getKlarnaInvoiceFeeInfo()
27
  {
28
  public function getKlarnaSetup($method)
29
  {
30
+ $klarna = Mage::getModel('klarna/klarna');
31
+ $klarna->setQuote($this->getQuote(), $method);
32
+ return $klarna->getKlarnaSetup();
33
  }
34
 
35
  public function getKlarnaInvoiceFeeInfo()
app/code/community/Vaimo/Klarna/Block/Form/Abstract.php CHANGED
@@ -49,10 +49,9 @@ class Vaimo_Klarna_Block_Form_Abstract extends Mage_Payment_Block_Form
49
  if (isset($this->_pclasses[$method])) {
50
  return $this->_pclasses[$method];
51
  }
52
- $klarnaPClass = Mage::getModel('klarna/klarna_pclass');
53
- $klarnaPClass->setQuote($this->getQuote(), $method);
54
- $klarnaPClass->setPClassTypes($method);
55
- $res = $klarnaPClass->getValidCheckoutPClasses();
56
  $data = $this->getMethod()->getInfoInstance();
57
  if ($data) {
58
  $id = $data->getAdditionalInformation(Vaimo_Klarna_Helper_Data::KLARNA_INFO_FIELD_PAYMENT_PLAN);
@@ -68,7 +67,7 @@ class Vaimo_Klarna_Block_Form_Abstract extends Mage_Payment_Block_Form
68
  }
69
  $this->_pclasses[$method] = $res;
70
  } catch (Mage_Core_Exception $e) {
71
- if ($klarnaPClass) $klarnaPClass->logKlarnaException($e);
72
  $res = NULL;
73
  }
74
  return $res;
@@ -78,11 +77,11 @@ class Vaimo_Klarna_Block_Form_Abstract extends Mage_Payment_Block_Form
78
  {
79
  try {
80
  $method = $this->getMethod()->getCode();
81
- $klarnaForm = Mage::getModel('klarna/klarna_form');
82
- $klarnaForm->setQuote($this->getQuote(), $method);
83
- $res = $klarnaForm->useGetAddresses();
84
  } catch (Mage_Core_Exception $e) {
85
- if ($klarnaForm) $klarnaForm->logKlarnaException($e);
86
  $res = false;
87
  }
88
  return $res;
@@ -92,11 +91,11 @@ class Vaimo_Klarna_Block_Form_Abstract extends Mage_Payment_Block_Form
92
  {
93
  try {
94
  $method = $this->getMethod()->getCode();
95
- $klarnaForm = Mage::getModel('klarna/klarna_form');
96
- $klarnaForm->setQuote($this->getQuote(), $method);
97
- $res = $klarnaForm->needDateOfBirth();
98
  } catch (Mage_Core_Exception $e) {
99
- if ($klarnaForm) $klarnaForm->logKlarnaException($e);
100
  $res = false;
101
  }
102
  return $res;
@@ -106,11 +105,11 @@ class Vaimo_Klarna_Block_Form_Abstract extends Mage_Payment_Block_Form
106
  {
107
  try {
108
  $method = $this->getMethod()->getCode();
109
- $klarnaForm = Mage::getModel('klarna/klarna_form');
110
- $klarnaForm->setQuote($this->getQuote(), $method);
111
- $res = $klarnaForm->needGender();
112
  } catch (Mage_Core_Exception $e) {
113
- if ($klarnaForm) $klarnaForm->logKlarnaException($e);
114
  $res = false;
115
  }
116
  return $res;
@@ -120,11 +119,11 @@ class Vaimo_Klarna_Block_Form_Abstract extends Mage_Payment_Block_Form
120
  {
121
  try {
122
  $method = $this->getMethod()->getCode();
123
- $klarnaForm = Mage::getModel('klarna/klarna_form');
124
- $klarnaForm->setQuote($this->getQuote(), $method);
125
- $res = $klarnaForm->needConsent();
126
  } catch (Mage_Core_Exception $e) {
127
- if ($klarnaForm) $klarnaForm->logKlarnaException($e);
128
  $res = false;
129
  }
130
  return $res;
@@ -134,17 +133,17 @@ class Vaimo_Klarna_Block_Form_Abstract extends Mage_Payment_Block_Form
134
  {
135
  try {
136
  $method = $this->getMethod()->getCode();
137
- $klarnaForm = Mage::getModel('klarna/klarna_form');
138
- $klarnaForm->setQuote($this->getQuote(), $method);
139
- $res = $klarnaForm->needExtraPaymentPlanInformaton();
140
  } catch (Mage_Core_Exception $e) {
141
- if ($klarnaForm) $klarnaForm->logKlarnaException($e);
142
  $res = false;
143
  }
144
  return $res;
145
  }
146
 
147
- private function _getCurrentField($field, $default = '')
148
  {
149
  try {
150
  $res = $default;
@@ -260,7 +259,7 @@ class Vaimo_Klarna_Block_Form_Abstract extends Mage_Payment_Block_Form
260
  */
261
  public function getAjaxAddressSearchUrl()
262
  {
263
- return Mage::getSingleton('core/url')->getUrl('klarna/address/search');
264
  }
265
 
266
  /**
@@ -270,36 +269,37 @@ class Vaimo_Klarna_Block_Form_Abstract extends Mage_Payment_Block_Form
270
  */
271
  public function getAjaxPaymentPlanInformationUrl()
272
  {
273
- return Mage::getSingleton('core/url')->getUrl('klarna/paymentplan/information');
274
  }
275
 
276
  public function getKlarnaLogotype($width)
277
  {
278
  $method = $this->getMethod()->getCode();
279
- $klarnaForm = Mage::getModel('klarna/klarna_form');
280
- $klarnaForm->setQuote($this->getQuote(), $method);
281
- return $klarnaForm->getKlarnaLogotype($width, Vaimo_Klarna_Helper_Data::KLARNA_LOGOTYPE_POSITION_CHECKOUT);
282
  }
283
 
284
  public function getKlarnaSetup()
285
  {
286
  $method = $this->getMethod()->getCode();
287
- $klarnaForm = Mage::getModel('klarna/klarna_form');
288
- $klarnaForm->setQuote($this->getQuote(), $method);
289
- return $klarnaForm->getKlarnaSetup();
290
  }
291
 
292
  public function getDefaultPaymentPlanInformation($method)
293
  {
294
  $res = NULL;
295
  try {
296
- $klarnaPClass = Mage::getModel('klarna/klarna_pclass');
297
- $klarnaPClass->setQuote($this->getQuote(), $method);
298
- $klarnaPClass->setPClassTypes($method);
299
- $pclasses = $klarnaPClass->getValidCheckoutPClasses();
300
- foreach ($pclasses as $pclass) {
301
- if ($pclass['default']) {
302
- $res = $klarnaPClass->getPClassDetails($pclass['id']);
 
303
  }
304
  }
305
  } catch (Mage_Core_Exception $e) {
@@ -328,9 +328,19 @@ class Vaimo_Klarna_Block_Form_Abstract extends Mage_Payment_Block_Form
328
  public function getTermsUrlLink()
329
  {
330
  $method = $this->getMethod()->getCode();
331
- $klarnaForm = Mage::getModel('klarna/klarna_form');
332
- $klarnaForm->setQuote($this->getQuote(), $method);
333
- return $klarnaForm->getTermsUrlLink();
 
 
 
 
 
 
 
 
 
 
334
  }
335
 
336
  /**
@@ -344,11 +354,11 @@ class Vaimo_Klarna_Block_Form_Abstract extends Mage_Payment_Block_Form
344
  {
345
  $str = "";
346
  $method = $this->getMethod()->getCode();
347
- $klarnaForm = Mage::getModel('klarna/klarna_form');
348
- $klarnaForm->setQuote($this->getQuote(), $method);
349
  if (Mage::helper('klarna')->showTitleAsTextOnly()==false) {
350
- $str = '<img src="'.$klarnaForm->getKlarnaLogotype(75, Vaimo_Klarna_Helper_Data::KLARNA_LOGOTYPE_POSITION_CHECKOUT).'" alt="" title="" />';
351
- $str .= $klarnaForm->getMethodTitle();
352
  }
353
  return $str;
354
  }
49
  if (isset($this->_pclasses[$method])) {
50
  return $this->_pclasses[$method];
51
  }
52
+ $klarna = Mage::getModel('klarna/klarna');
53
+ $klarna->setQuote($this->getQuote(), $method);
54
+ $res = $klarna->getValidCheckoutPClasses($method);
 
55
  $data = $this->getMethod()->getInfoInstance();
56
  if ($data) {
57
  $id = $data->getAdditionalInformation(Vaimo_Klarna_Helper_Data::KLARNA_INFO_FIELD_PAYMENT_PLAN);
67
  }
68
  $this->_pclasses[$method] = $res;
69
  } catch (Mage_Core_Exception $e) {
70
+ if ($klarna) $klarna->logKlarnaException($e);
71
  $res = NULL;
72
  }
73
  return $res;
77
  {
78
  try {
79
  $method = $this->getMethod()->getCode();
80
+ $klarna = Mage::getModel('klarna/klarna');
81
+ $klarna->setQuote($this->getQuote(), $method);
82
+ $res = $klarna->useGetAddresses();
83
  } catch (Mage_Core_Exception $e) {
84
+ if ($klarna) $klarna->logKlarnaException($e);
85
  $res = false;
86
  }
87
  return $res;
91
  {
92
  try {
93
  $method = $this->getMethod()->getCode();
94
+ $klarna = Mage::getModel('klarna/klarna');
95
+ $klarna->setQuote($this->getQuote(), $method);
96
+ $res = $klarna->needDateOfBirth();
97
  } catch (Mage_Core_Exception $e) {
98
+ if ($klarna) $klarna->logKlarnaException($e);
99
  $res = false;
100
  }
101
  return $res;
105
  {
106
  try {
107
  $method = $this->getMethod()->getCode();
108
+ $klarna = Mage::getModel('klarna/klarna');
109
+ $klarna->setQuote($this->getQuote(), $method);
110
+ $res = $klarna->needGender();
111
  } catch (Mage_Core_Exception $e) {
112
+ if ($klarna) $klarna->logKlarnaException($e);
113
  $res = false;
114
  }
115
  return $res;
119
  {
120
  try {
121
  $method = $this->getMethod()->getCode();
122
+ $klarna = Mage::getModel('klarna/klarna');
123
+ $klarna->setQuote($this->getQuote(), $method);
124
+ $res = $klarna->needConsent();
125
  } catch (Mage_Core_Exception $e) {
126
+ if ($klarna) $klarna->logKlarnaException($e);
127
  $res = false;
128
  }
129
  return $res;
133
  {
134
  try {
135
  $method = $this->getMethod()->getCode();
136
+ $klarna = Mage::getModel('klarna/klarna');
137
+ $klarna->setQuote($this->getQuote(), $method);
138
+ $res = $klarna->needExtraPaymentPlanInformaton();
139
  } catch (Mage_Core_Exception $e) {
140
+ if ($klarna) $klarna->logKlarnaException($e);
141
  $res = false;
142
  }
143
  return $res;
144
  }
145
 
146
+ protected function _getCurrentField($field, $default = '')
147
  {
148
  try {
149
  $res = $default;
259
  */
260
  public function getAjaxAddressSearchUrl()
261
  {
262
+ return Mage::getSingleton('core/url')->getUrl('klarna/address/search', array('_secure' => true));
263
  }
264
 
265
  /**
269
  */
270
  public function getAjaxPaymentPlanInformationUrl()
271
  {
272
+ return Mage::getSingleton('core/url')->getUrl('klarna/paymentplan/information', array('_secure' => true));
273
  }
274
 
275
  public function getKlarnaLogotype($width)
276
  {
277
  $method = $this->getMethod()->getCode();
278
+ $klarna = Mage::getModel('klarna/klarna');
279
+ $klarna->setQuote($this->getQuote(), $method);
280
+ return $klarna->getKlarnaLogotype($width, Vaimo_Klarna_Helper_Data::KLARNA_LOGOTYPE_POSITION_CHECKOUT);
281
  }
282
 
283
  public function getKlarnaSetup()
284
  {
285
  $method = $this->getMethod()->getCode();
286
+ $klarna = Mage::getModel('klarna/klarna');
287
+ $klarna->setQuote($this->getQuote(), $method);
288
+ return $klarna->getKlarnaSetup();
289
  }
290
 
291
  public function getDefaultPaymentPlanInformation($method)
292
  {
293
  $res = NULL;
294
  try {
295
+ $klarna = Mage::getModel('klarna/klarna');
296
+ $klarna->setQuote($this->getQuote(), $method);
297
+ $pclasses = $klarna->getValidCheckoutPClasses($method);
298
+ if ($pclasses) {
299
+ foreach ($pclasses as $pclass) {
300
+ if ($pclass['default']) {
301
+ $res = $klarna->getPClassDetails($pclass['id']);
302
+ }
303
  }
304
  }
305
  } catch (Mage_Core_Exception $e) {
328
  public function getTermsUrlLink()
329
  {
330
  $method = $this->getMethod()->getCode();
331
+ $klarna = Mage::getModel('klarna/klarna');
332
+ $klarna->setQuote($this->getQuote(), $method);
333
+ $url = $klarna->getConfigData("terms_url");
334
+ if ($url) {
335
+ if (stristr($url, 'http')) {
336
+ $_termsLink = '<a href="' . $url . '" target="_blank">' . Mage::helper('klarna')->__('terms and conditions') . '</a>';
337
+ } else {
338
+ $_termsLink = '<a href="' . Mage::getSingleton('core/url')->getUrl($url) . '" target="_blank">' . Mage::helper('klarna')->__('terms and conditions') . '</a>';
339
+ }
340
+ } else {
341
+ $_termsLink = '<a href="#" target="_blank">' . Mage::helper('klarna')->__('terms and conditions') . '</a>';
342
+ }
343
+ return $_termsLink;
344
  }
345
 
346
  /**
354
  {
355
  $str = "";
356
  $method = $this->getMethod()->getCode();
357
+ $klarna = Mage::getModel('klarna/klarna');
358
+ $klarna->setQuote($this->getQuote(), $method);
359
  if (Mage::helper('klarna')->showTitleAsTextOnly()==false) {
360
+ $str = '<img src="'.$klarna->getKlarnaLogotype(75, Vaimo_Klarna_Helper_Data::KLARNA_LOGOTYPE_POSITION_CHECKOUT).'" alt="" title="" />';
361
+ $str .= $klarna->getMethodTitleWithFee(Mage::helper('klarna')->getVaimoKlarnaFeeInclVat($this->getQuote(), false));
362
  }
363
  return $str;
364
  }
app/code/community/Vaimo/Klarna/Block/Form/Address/Search.php CHANGED
@@ -52,9 +52,9 @@ class Vaimo_Klarna_Block_Form_Address_Search extends Mage_Core_Block_Template
52
  public function shippingSameAsBilling()
53
  {
54
  $method = $this->getMethodCode();
55
- $klarnaForm = Mage::getModel('klarna/klarna_form');
56
- $klarnaForm->setQuote($this->getQuote(), $method);
57
- $res = $klarnaForm->shippingSameAsBilling();
58
  return $res;
59
  }
60
 
52
  public function shippingSameAsBilling()
53
  {
54
  $method = $this->getMethodCode();
55
+ $klarna = Mage::getModel('klarna/klarna');
56
+ $klarna->setQuote($this->getQuote(), $method);
57
+ $res = $klarna->shippingSameAsBilling();
58
  return $res;
59
  }
60
 
app/code/community/Vaimo/Klarna/Block/Form/Checkout.php ADDED
@@ -0,0 +1,83 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Copyright (c) 2009-2014 Vaimo AB
4
+ *
5
+ * Vaimo reserves all rights in the Program as delivered. The Program
6
+ * or any portion thereof may not be reproduced in any form whatsoever without
7
+ * the written consent of Vaimo, except as provided by licence. A licence
8
+ * under Vaimo's rights in the Program may be available directly from
9
+ * Vaimo.
10
+ *
11
+ * Disclaimer:
12
+ * THIS NOTICE MAY NOT BE REMOVED FROM THE PROGRAM BY ANY USER THEREOF.
13
+ * THE PROGRAM IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
14
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
16
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ * OUT OF OR IN CONNECTION WITH THE PROGRAM OR THE USE OR OTHER DEALINGS
19
+ * IN THE PROGRAM.
20
+ *
21
+ * @category Vaimo
22
+ * @package Vaimo_Klarna
23
+ * @copyright Copyright (c) 2009-2014 Vaimo AB
24
+ */
25
+
26
+ class Vaimo_Klarna_Block_Form_Checkout extends Vaimo_Klarna_Block_Form_Abstract
27
+ {
28
+
29
+ public function __construct()
30
+ {
31
+ parent::__construct();
32
+ $this->setTemplate('vaimo/klarna/form/checkout.phtml');
33
+ }
34
+
35
+ /*
36
+ * Should perhaps be isButtonNameImage... But this is ok as well
37
+ *
38
+ */
39
+ public function isButtonNameUrl($name)
40
+ {
41
+ try {
42
+ $res = false;
43
+ if ($name) {
44
+ if (stristr($name, 'http')) {
45
+ $res = true;
46
+ }
47
+ }
48
+ } catch (Exception $e) {
49
+ }
50
+
51
+ return $res;
52
+ }
53
+
54
+ public function getBackButtonName()
55
+ {
56
+ try {
57
+ $klarna = Mage::getModel('klarna/klarnacheckout');
58
+ $klarna->setQuote($this->getQuote(), Vaimo_Klarna_Helper_Data::KLARNA_METHOD_CHECKOUT);
59
+ $res = $klarna->getConfigData('label_back_button');
60
+ if (!$res) {
61
+ $res = Mage::helper('klarna')->__('Go to Klarna Checkout');
62
+ }
63
+ } catch (Exception $e) {
64
+ $res = Mage::helper('klarna')->__('Go to Klarna Checkout');
65
+ }
66
+
67
+ return $res;
68
+ }
69
+
70
+ public function isButtonEnabled()
71
+ {
72
+ try {
73
+ $klarna = Mage::getModel('klarna/klarnacheckout');
74
+ $klarna->setQuote($this->getQuote(), Vaimo_Klarna_Helper_Data::KLARNA_METHOD_CHECKOUT);
75
+ $res = $klarna->getConfigData('enable_other_button');
76
+ } catch (Exception $e) {
77
+ $res = true;
78
+ }
79
+
80
+ return $res;
81
+ }
82
+ }
83
+
app/code/community/Vaimo/Klarna/Block/Info/Abstract.php CHANGED
@@ -51,18 +51,20 @@ class Vaimo_Klarna_Block_Info_Abstract extends Mage_Payment_Block_Info
51
 
52
  public function getMethodTitle()
53
  {
 
54
  $data = $this->getMethod()->getInfoInstance();
55
  if ($data) {
56
- $klarnaInfo = Mage::getModel('klarna/klarna_info');
57
  $method = $data->getAdditionalInformation('method');
58
  if ($data->getOrder()) {
59
- $klarnaInfo->setOrder($data->getOrder());
 
60
  } else {
61
- $klarnaInfo->setQuote($this->getQuote(), $method);
 
62
  }
63
- return $klarnaInfo->getMethodTitle();
64
  }
65
- return '';
66
  }
67
 
68
  public function getKlarnaFeeLabel()
@@ -148,6 +150,12 @@ class Vaimo_Klarna_Block_Info_Abstract extends Mage_Payment_Block_Info
148
  return $this->toHtml();
149
  }
150
 
 
 
 
 
 
 
151
  public function getPaymentPlanHtml()
152
  {
153
  $this->setTemplate('vaimo/klarna/info/children/paymentplan.phtml');
@@ -157,18 +165,24 @@ class Vaimo_Klarna_Block_Info_Abstract extends Mage_Payment_Block_Info
157
  public function getKlarnaLogotype($width)
158
  {
159
  $method = $this->getMethod()->getCode();
160
- $klarnaInfo = Mage::getModel('klarna/klarna_info');
161
  $data = $this->getMethod()->getInfoInstance();
162
  if ($data) {
163
  if ($data->getOrder()) {
164
- $klarnaInfo->setOrder($data->getOrder(), $method);
165
  } else {
166
- $klarnaInfo->setQuote($data->getQuote(), $method);
167
  }
168
  } else {
169
- $klarnaInfo->setQuote($this->getQuote(), $method);
170
  }
171
- return $klarnaInfo->getKlarnaLogotype($width, Vaimo_Klarna_Helper_Data::KLARNA_LOGOTYPE_POSITION_FRONTEND);
172
  }
 
 
 
 
 
 
173
  }
174
 
51
 
52
  public function getMethodTitle()
53
  {
54
+ $res = '';
55
  $data = $this->getMethod()->getInfoInstance();
56
  if ($data) {
57
+ $klarna = Mage::getModel('klarna/klarna');
58
  $method = $data->getAdditionalInformation('method');
59
  if ($data->getOrder()) {
60
+ $klarna->setOrder($data->getOrder());
61
+ $res = $klarna->getMethodTitleWithFee();
62
  } else {
63
+ $klarna->setQuote($this->getQuote(), $method);
64
+ $res = $klarna->getMethodTitleWithFee(Mage::helper('klarna')->getVaimoKlarnaFeeInclVat($this->getQuote(), false));
65
  }
 
66
  }
67
+ return $res;
68
  }
69
 
70
  public function getKlarnaFeeLabel()
150
  return $this->toHtml();
151
  }
152
 
153
+ public function getReferenceHtml()
154
+ {
155
+ $this->setTemplate('vaimo/klarna/info/children/reference.phtml');
156
+ return $this->toHtml();
157
+ }
158
+
159
  public function getPaymentPlanHtml()
160
  {
161
  $this->setTemplate('vaimo/klarna/info/children/paymentplan.phtml');
165
  public function getKlarnaLogotype($width)
166
  {
167
  $method = $this->getMethod()->getCode();
168
+ $klarna = Mage::getModel('klarna/klarna');
169
  $data = $this->getMethod()->getInfoInstance();
170
  if ($data) {
171
  if ($data->getOrder()) {
172
+ $klarna->setOrder($data->getOrder(), $method);
173
  } else {
174
+ $klarna->setQuote($data->getQuote(), $method);
175
  }
176
  } else {
177
+ $klarna->setQuote($this->getQuote(), $method);
178
  }
179
+ return $klarna->getKlarnaLogotype($width, Vaimo_Klarna_Helper_Data::KLARNA_LOGOTYPE_POSITION_FRONTEND);
180
  }
181
+
182
+ public function getMethodCode()
183
+ {
184
+ return $this->getMethod()->getCode();
185
+ }
186
+
187
  }
188
 
app/code/community/Vaimo/Klarna/{Model/Klarna/Info.php → Block/Info/Checkout.php} RENAMED
@@ -1,34 +1,35 @@
1
- <?php
2
- /**
3
- * Copyright (c) 2009-2014 Vaimo AB
4
- *
5
- * Vaimo reserves all rights in the Program as delivered. The Program
6
- * or any portion thereof may not be reproduced in any form whatsoever without
7
- * the written consent of Vaimo, except as provided by licence. A licence
8
- * under Vaimo's rights in the Program may be available directly from
9
- * Vaimo.
10
- *
11
- * Disclaimer:
12
- * THIS NOTICE MAY NOT BE REMOVED FROM THE PROGRAM BY ANY USER THEREOF.
13
- * THE PROGRAM IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
14
- * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
16
- * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
- * OUT OF OR IN CONNECTION WITH THE PROGRAM OR THE USE OR OTHER DEALINGS
19
- * IN THE PROGRAM.
20
- *
21
- * @category Vaimo
22
- * @package Vaimo_Klarna
23
- * @copyright Copyright (c) 2009-2014 Vaimo AB
24
- */
25
-
26
- class Vaimo_Klarna_Model_Klarna_Info extends Vaimo_Klarna_Model_Klarna_Tools_Address
27
- {
28
- public function __construct()
29
- {
30
- parent::__construct();
31
- $this->_setFunctionName('info');
32
- }
33
-
34
- }
 
1
+ <?php
2
+ /**
3
+ * Copyright (c) 2009-2014 Vaimo AB
4
+ *
5
+ * Vaimo reserves all rights in the Program as delivered. The Program
6
+ * or any portion thereof may not be reproduced in any form whatsoever without
7
+ * the written consent of Vaimo, except as provided by licence. A licence
8
+ * under Vaimo's rights in the Program may be available directly from
9
+ * Vaimo.
10
+ *
11
+ * Disclaimer:
12
+ * THIS NOTICE MAY NOT BE REMOVED FROM THE PROGRAM BY ANY USER THEREOF.
13
+ * THE PROGRAM IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
14
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
16
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ * OUT OF OR IN CONNECTION WITH THE PROGRAM OR THE USE OR OTHER DEALINGS
19
+ * IN THE PROGRAM.
20
+ *
21
+ * @category Vaimo
22
+ * @package Vaimo_Klarna
23
+ * @copyright Copyright (c) 2009-2014 Vaimo AB
24
+ */
25
+
26
+ class Vaimo_Klarna_Block_Info_Checkout extends Vaimo_Klarna_Block_Info_Abstract
27
+ {
28
+ public function __construct()
29
+ {
30
+ parent::__construct();
31
+ $this->setTemplate('vaimo/klarna/info/checkout.phtml');
32
+ }
33
+
34
+ }
35
+
app/code/community/Vaimo/Klarna/Block/Klarnacheckout/Autofill.php ADDED
@@ -0,0 +1,64 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Copyright (c) 2009-2014 Vaimo AB
4
+ *
5
+ * Vaimo reserves all rights in the Program as delivered. The Program
6
+ * or any portion thereof may not be reproduced in any form whatsoever without
7
+ * the written consent of Vaimo, except as provided by licence. A licence
8
+ * under Vaimo's rights in the Program may be available directly from
9
+ * Vaimo.
10
+ *
11
+ * Disclaimer:
12
+ * THIS NOTICE MAY NOT BE REMOVED FROM THE PROGRAM BY ANY USER THEREOF.
13
+ * THE PROGRAM IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
14
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
16
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ * OUT OF OR IN CONNECTION WITH THE PROGRAM OR THE USE OR OTHER DEALINGS
19
+ * IN THE PROGRAM.
20
+ *
21
+ * @category Vaimo
22
+ * @package Vaimo_Klarna
23
+ * @copyright Copyright (c) 2009-2014 Vaimo AB
24
+ */
25
+
26
+ class Vaimo_Klarna_Block_Klarnacheckout_Autofill extends Mage_Core_Block_Template
27
+ {
28
+ public function getCheckout()
29
+ {
30
+ return Mage::getSingleton('checkout/session');
31
+ }
32
+
33
+ public function getQuote()
34
+ {
35
+ return $this->getCheckout()->getQuote();
36
+ }
37
+
38
+ public function getDisplayAutofill()
39
+ {
40
+ try {
41
+ $res = true;
42
+ $klarna = Mage::getModel('klarna/klarnacheckout');
43
+ $klarna->setQuote($this->getQuote(), Vaimo_Klarna_Helper_Data::KLARNA_METHOD_CHECKOUT);
44
+ $res = $klarna->shouldDisplayAutofillWarning();
45
+ } catch (Exception $e) {
46
+ $res = false;
47
+ }
48
+ return $res;
49
+ }
50
+ public function getTermsLink()
51
+ {
52
+ try {
53
+ $klarna = Mage::getModel('klarna/klarnacheckout');
54
+ $klarna->setQuote($this->getQuote(), Vaimo_Klarna_Helper_Data::KLARNA_METHOD_CHECKOUT);
55
+ $merchantId = $klarna->getKlarnaSetup()->getMerchantId();
56
+ $lnk = 'https://cdn.klarna.com/1.0/shared/content/legal/terms/' . $merchantId .'/de_de/checkout';
57
+ $res = '<a href="' . $lnk . '">' . $this->helper('klarna')->__('Nutzungsbedingungen') . '</a>';
58
+ } catch (Exception $e) {
59
+ $res = $this->helper('klarna')->__('Nutzungsbedingungen');
60
+ }
61
+ return $res;
62
+ }
63
+
64
+ }
app/code/community/Vaimo/Klarna/Block/Klarnacheckout/Customer/Balance.php ADDED
@@ -0,0 +1,72 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Copyright (c) 2009-2014 Vaimo AB
4
+ *
5
+ * Vaimo reserves all rights in the Program as delivered. The Program
6
+ * or any portion thereof may not be reproduced in any form whatsoever without
7
+ * the written consent of Vaimo, except as provided by licence. A licence
8
+ * under Vaimo's rights in the Program may be available directly from
9
+ * Vaimo.
10
+ *
11
+ * Disclaimer:
12
+ * THIS NOTICE MAY NOT BE REMOVED FROM THE PROGRAM BY ANY USER THEREOF.
13
+ * THE PROGRAM IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
14
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
16
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ * OUT OF OR IN CONNECTION WITH THE PROGRAM OR THE USE OR OTHER DEALINGS
19
+ * IN THE PROGRAM.
20
+ *
21
+ * @category Vaimo
22
+ * @package Vaimo_Klarna
23
+ * @copyright Copyright (c) 2009-2014 Vaimo AB
24
+ */
25
+
26
+ class Vaimo_Klarna_Block_Klarnacheckout_Customer_Balance extends Mage_Core_Block_Template
27
+ {
28
+ protected $_balanceBlock;
29
+
30
+ /**
31
+ * @return bool|Enterprise_CustomerBalance_Block_Checkout_Onepage_Payment_Additional
32
+ */
33
+ protected function _getBalanceBlock()
34
+ {
35
+ if ($this->_balanceBlock == null) {
36
+ if (Mage::helper('core')->isModuleEnabled('Enterprise_CustomerBalance')) {
37
+ $this->_balanceBlock = $this->getLayout()->getBlockSingleton('enterprise_customerbalance/checkout_onepage_payment_additional');
38
+ } else {
39
+ $this->_balanceBlock = false;
40
+ }
41
+ }
42
+
43
+ return $this->_balanceBlock;
44
+ }
45
+
46
+ public function isDisplayContainer()
47
+ {
48
+ if ($block = $this->_getBalanceBlock()) {
49
+ return $block->isDisplayContainer();
50
+ }
51
+
52
+ return false;
53
+ }
54
+
55
+ public function isCustomerBalanceUsed()
56
+ {
57
+ if ($block = $this->_getBalanceBlock()) {
58
+ return $block->isCustomerBalanceUsed();
59
+ }
60
+
61
+ return false;
62
+ }
63
+
64
+ public function getBalance()
65
+ {
66
+ if ($block = $this->_getBalanceBlock()) {
67
+ return $block->getBalance();
68
+ }
69
+
70
+ return 0;
71
+ }
72
+ }
app/code/community/Vaimo/Klarna/Block/Klarnacheckout/Discount.php ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Copyright (c) 2009-2014 Vaimo AB
4
+ *
5
+ * Vaimo reserves all rights in the Program as delivered. The Program
6
+ * or any portion thereof may not be reproduced in any form whatsoever without
7
+ * the written consent of Vaimo, except as provided by licence. A licence
8
+ * under Vaimo's rights in the Program may be available directly from
9
+ * Vaimo.
10
+ *
11
+ * Disclaimer:
12
+ * THIS NOTICE MAY NOT BE REMOVED FROM THE PROGRAM BY ANY USER THEREOF.
13
+ * THE PROGRAM IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
14
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
16
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ * OUT OF OR IN CONNECTION WITH THE PROGRAM OR THE USE OR OTHER DEALINGS
19
+ * IN THE PROGRAM.
20
+ *
21
+ * @category Vaimo
22
+ * @package Vaimo_Klarna
23
+ * @copyright Copyright (c) 2009-2014 Vaimo AB
24
+ */
25
+
26
+ class Vaimo_Klarna_Block_Klarnacheckout_Discount extends Mage_Core_Block_Template
27
+ {
28
+ public function _beforeToHtml()
29
+ {
30
+ parent::_beforeToHtml();
31
+ if (class_exists('Enterprise_GiftCard_Model_Giftcard', true)) {
32
+ /** @var Mage_Core_Block_Template $giftCardAccountBlock */
33
+ $giftCardAccountBlock = $this->getLayout()->createBlock(
34
+ 'enterprise_giftcardaccount/checkout_cart_giftcardaccount', 'checkout.cart.giftcardaccount'
35
+ );
36
+ if ($giftCardAccountBlock) {
37
+ $giftCardAccountBlock->setTemplate('vaimo/klarna/klarnacheckout/discount/giftcardaccount.phtml');
38
+ $this->setChild('giftcards', $giftCardAccountBlock);
39
+ }
40
+ }
41
+ return $this;
42
+ }
43
+ }
app/code/community/Vaimo/Klarna/Block/Klarnacheckout/Ga.php ADDED
@@ -0,0 +1,103 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Copyright (c) 2009-2014 Vaimo AB
4
+ *
5
+ * Vaimo reserves all rights in the Program as delivered. The Program
6
+ * or any portion thereof may not be reproduced in any form whatsoever without
7
+ * the written consent of Vaimo, except as provided by licence. A licence
8
+ * under Vaimo's rights in the Program may be available directly from
9
+ * Vaimo.
10
+ *
11
+ * Disclaimer:
12
+ * THIS NOTICE MAY NOT BE REMOVED FROM THE PROGRAM BY ANY USER THEREOF.
13
+ * THE PROGRAM IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
14
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
16
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ * OUT OF OR IN CONNECTION WITH THE PROGRAM OR THE USE OR OTHER DEALINGS
19
+ * IN THE PROGRAM.
20
+ *
21
+ * @category Vaimo
22
+ * @package Vaimo_Klarna
23
+ * @copyright Copyright (c) 2009-2014 Vaimo AB
24
+ */
25
+
26
+ class Vaimo_Klarna_Block_Klarnacheckout_Ga extends Mage_GoogleAnalytics_Block_Ga
27
+ {
28
+ /**
29
+ * Render information about specified orders and their items
30
+ *
31
+ * @link http://code.google.com/apis/analytics/docs/gaJS/gaJSApiEcommerce.html#_gat.GA_Tracker_._addTrans
32
+ * @return string
33
+ */
34
+ protected function _getOrdersTrackingCode()
35
+ {
36
+ $result = parent::_getOrdersTrackingCode();
37
+
38
+ /** @var Klarna_Checkout_Order $klarnaOrder */
39
+ // This call should not exist! We need to prepare the data, so this function
40
+ // can use it without getting hold of and use the actual KlarnaOrder
41
+ if ($klarnaOrder = $this->getKlarnaCheckoutOrder()) {
42
+ $klarnaCode = array();
43
+
44
+ $transactionId = $klarnaOrder->offsetExists('reservation') ? $klarnaOrder->offsetGet('reservation') : '';
45
+ $cart = $klarnaOrder->offsetExists('cart') ? $klarnaOrder->offsetGet('cart') : array();
46
+ $items = (isset($cart['items']) && is_array($cart['items'])) ? $cart['items'] : array();
47
+ $grandTotal = isset($cart['total_price_excluding_tax']) ? $cart['total_price_excluding_tax'] / 100 : 0;
48
+ $taxAmount = isset($cart['total_tax_amount']) ? $cart['total_tax_amount'] / 100 : 0;
49
+ $shippingAmount = 0;
50
+
51
+ foreach ($items as $item) {
52
+ if (isset($item['type']) && $item['type'] == 'shipping_fee' && isset($item['total_price_including_tax'])) {
53
+ $shippingAmount += $item['total_price_including_tax'] / 100;
54
+ $grandTotal -= $item['total_price_including_tax'] / 100;
55
+ }
56
+ }
57
+
58
+ $address = $klarnaOrder->offsetExists('shipping_address') ? $klarnaOrder->offsetGet('shipping_address') : array();
59
+ $city = isset($address['city']) ? $address['city'] : '';
60
+ $region = '';
61
+ $country = isset($address['country']) ? $address['country'] : '';
62
+
63
+ $klarnaCode[] = sprintf("_gaq.push(['_addTrans', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s']);",
64
+ $transactionId,
65
+ Mage::app()->getStore()->getFrontendName(),
66
+ $grandTotal,
67
+ $taxAmount,
68
+ $shippingAmount,
69
+ $this->jsQuoteEscape($city),
70
+ $this->jsQuoteEscape($region),
71
+ $this->jsQuoteEscape($country)
72
+ );
73
+
74
+ foreach ($items as $item) {
75
+ if (isset($item['type']) && $item['type'] == 'physical') {
76
+ $sku = isset($item['reference']) ? $item['reference'] : '';
77
+ $name = isset($item['name']) ? $item['name'] : '';
78
+ $price = isset($item['unit_price']) ? $item['unit_price'] / 100 : '';
79
+ $quantity = isset($item['quantity']) ? $item['quantity'] : '';
80
+
81
+ $klarnaCode[] = sprintf("_gaq.push(['_addItem', '%s', '%s', '%s', '%s', '%s', '%s']);",
82
+ $transactionId,
83
+ $this->jsQuoteEscape($sku),
84
+ $this->jsQuoteEscape($name),
85
+ null, // there is no "category" defined for the order item
86
+ $price,
87
+ $quantity
88
+ );
89
+ }
90
+ }
91
+
92
+ $klarnaCode[] = "_gaq.push(['_trackTrans']);";
93
+
94
+ if ($result) {
95
+ $result .= implode("\n", $klarnaCode);
96
+ } else {
97
+ $result = implode("\n", $klarnaCode);
98
+ }
99
+ }
100
+
101
+ return $result;
102
+ }
103
+ }
app/code/community/Vaimo/Klarna/{Model/Klarna/Form.php → Block/Klarnacheckout/Klarnacheckout.php} RENAMED
@@ -23,27 +23,31 @@
23
  * @copyright Copyright (c) 2009-2014 Vaimo AB
24
  */
25
 
26
- class Vaimo_Klarna_Model_Klarna_Form extends Vaimo_Klarna_Model_Klarna_Tools_Address
27
  {
28
- public function __construct()
29
  {
30
- parent::__construct();
31
- $this->_setFunctionName('form');
32
  }
33
 
34
- public function getTermsUrlLink()
35
  {
36
- $url = $this->_getConfigData("terms_url");
37
- if ($url) {
38
- if (stristr($url, 'http')) {
39
- $_termsLink = '<a href="' . $url . '" target="_blank">' . Mage::helper('klarna')->__('terms and conditions') . '</a>';
40
- } else {
41
- $_termsLink = '<a href="' . Mage::getSingleton('core/url')->getUrl($url) . '" target="_blank">' . Mage::helper('klarna')->__('terms and conditions') . '</a>';
 
 
 
 
 
 
 
42
  }
43
- } else {
44
- $_termsLink = '<a href="#" target="_blank">' . Mage::helper('klarna')->__('terms and conditions') . '</a>';
45
  }
46
- return $_termsLink;
47
- }
48
 
49
- }
 
 
23
  * @copyright Copyright (c) 2009-2014 Vaimo AB
24
  */
25
 
26
+ class Vaimo_Klarna_Block_Klarnacheckout_Klarnacheckout extends Mage_Core_Block_Template
27
  {
28
+ public function getCheckout()
29
  {
30
+ return Mage::getSingleton('checkout/session');
 
31
  }
32
 
33
+ public function getQuote()
34
  {
35
+ return $this->getCheckout()->getQuote();
36
+ }
37
+
38
+ public function getKlarnaHtml()
39
+ {
40
+ try {
41
+ $klarna = Mage::getModel('klarna/klarnacheckout');
42
+ $klarna->setQuote($this->getQuote(), Vaimo_Klarna_Helper_Data::KLARNA_METHOD_CHECKOUT);
43
+ $html = $klarna->getKlarnaOrderHtml(null, true, true);
44
+ } catch (Exception $e) {
45
+ $html = $e->getMessage();
46
+ if (!$html) {
47
+ $html = Mage::helper('klarna')->__('Klarna Checkout is not responding properly. Please try again in a while or choose another payment method.');
48
  }
 
 
49
  }
 
 
50
 
51
+ return $html;
52
+ }
53
+ }
app/code/community/Vaimo/Klarna/Block/Klarnacheckout/Newsletter.php ADDED
@@ -0,0 +1,74 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Copyright (c) 2009-2014 Vaimo AB
4
+ *
5
+ * Vaimo reserves all rights in the Program as delivered. The Program
6
+ * or any portion thereof may not be reproduced in any form whatsoever without
7
+ * the written consent of Vaimo, except as provided by licence. A licence
8
+ * under Vaimo's rights in the Program may be available directly from
9
+ * Vaimo.
10
+ *
11
+ * Disclaimer:
12
+ * THIS NOTICE MAY NOT BE REMOVED FROM THE PROGRAM BY ANY USER THEREOF.
13
+ * THE PROGRAM IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
14
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
16
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ * OUT OF OR IN CONNECTION WITH THE PROGRAM OR THE USE OR OTHER DEALINGS
19
+ * IN THE PROGRAM.
20
+ *
21
+ * @category Vaimo
22
+ * @package Vaimo_Klarna
23
+ * @copyright Copyright (c) 2009-2014 Vaimo AB
24
+ */
25
+
26
+ class Vaimo_Klarna_Block_Klarnacheckout_Newsletter extends Mage_Core_Block_Template
27
+ {
28
+ /**
29
+ * Checks if newsletter subscribe is enabled.
30
+ * More as a backwards compatibility, getType does the same
31
+ *
32
+ * @return bool
33
+ */
34
+ public function isEnabled()
35
+ {
36
+ return (bool)Mage::getStoreConfig(Vaimo_Klarna_Helper_Data::KLARNA_CHECKOUT_ENABLE_NEWSLETTER) > 0;
37
+ }
38
+
39
+ /**
40
+ * Gets the newsletter subscribe type; Subscribe or Don't subscribe
41
+ *
42
+ * @return int
43
+ */
44
+ public function getType()
45
+ {
46
+ return (int)Mage::getStoreConfig(Vaimo_Klarna_Helper_Data::KLARNA_CHECKOUT_ENABLE_NEWSLETTER);
47
+ }
48
+
49
+ public function getLabel()
50
+ {
51
+ switch ($this->getType()) {
52
+ case Vaimo_Klarna_Helper_Data::KLARNA_CHECKOUT_NEWSLETTER_SUBSCRIBE:
53
+ return $this->__('Subscribe to newsletter');
54
+ case Vaimo_Klarna_Helper_Data::KLARNA_CHECKOUT_NEWSLETTER_DONT_SUBSCRIBE:
55
+ return $this->__('Don\'t subscribe to newsletter');
56
+ }
57
+
58
+ return '';
59
+ }
60
+
61
+ public function isChecked()
62
+ {
63
+ $quote = Mage::getSingleton('checkout/cart')->getQuote();
64
+
65
+ switch ($this->getType()) {
66
+ case Vaimo_Klarna_Helper_Data::KLARNA_CHECKOUT_NEWSLETTER_SUBSCRIBE:
67
+ return (bool)$quote->getKlarnaCheckoutNewsletter();
68
+ case Vaimo_Klarna_Helper_Data::KLARNA_CHECKOUT_NEWSLETTER_DONT_SUBSCRIBE:
69
+ return (bool)!$quote->getKlarnaCheckoutNewsletter();
70
+ }
71
+
72
+ return false;
73
+ }
74
+ }
app/code/community/Vaimo/Klarna/Block/Klarnacheckout/Othermethod.php ADDED
@@ -0,0 +1,89 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Copyright (c) 2009-2014 Vaimo AB
4
+ *
5
+ * Vaimo reserves all rights in the Program as delivered. The Program
6
+ * or any portion thereof may not be reproduced in any form whatsoever without
7
+ * the written consent of Vaimo, except as provided by licence. A licence
8
+ * under Vaimo's rights in the Program may be available directly from
9
+ * Vaimo.
10
+ *
11
+ * Disclaimer:
12
+ * THIS NOTICE MAY NOT BE REMOVED FROM THE PROGRAM BY ANY USER THEREOF.
13
+ * THE PROGRAM IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
14
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
16
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ * OUT OF OR IN CONNECTION WITH THE PROGRAM OR THE USE OR OTHER DEALINGS
19
+ * IN THE PROGRAM.
20
+ *
21
+ * @category Vaimo
22
+ * @package Vaimo_Klarna
23
+ * @copyright Copyright (c) 2009-2014 Vaimo AB
24
+ */
25
+
26
+ class Vaimo_Klarna_Block_Klarnacheckout_Othermethod extends Mage_Core_Block_Template
27
+ {
28
+ public function getCheckout()
29
+ {
30
+ return Mage::getSingleton('checkout/session');
31
+ }
32
+
33
+ public function getQuote()
34
+ {
35
+ return $this->getCheckout()->getQuote();
36
+ }
37
+
38
+ /*
39
+ * Should perhaps be isButtonNameImage... But this is ok as well
40
+ *
41
+ */
42
+ public function isButtonNameUrl($name)
43
+ {
44
+ try {
45
+ $res = false;
46
+ if ($name) {
47
+ $arr = explode(':', $name);
48
+ foreach ($arr as $a) {
49
+ if ($a=='http') {
50
+ $res = true;
51
+ }
52
+ break;
53
+ }
54
+ }
55
+ } catch (Exception $e) {
56
+ }
57
+
58
+ return $res;
59
+ }
60
+
61
+ public function getOthermethodButtonName()
62
+ {
63
+ try {
64
+ $klarna = Mage::getModel('klarna/klarnacheckout');
65
+ $klarna->setQuote($this->getQuote(), Vaimo_Klarna_Helper_Data::KLARNA_METHOD_CHECKOUT);
66
+ $res = $klarna->getConfigData('label_other_button');
67
+ if (!$res) {
68
+ $res = Mage::helper('klarna')->__('Other Payment Methods');
69
+ }
70
+ } catch (Exception $e) {
71
+ $res = Mage::helper('klarna')->__('Other Payment Methods');
72
+ }
73
+
74
+ return $res;
75
+ }
76
+
77
+ public function isButtonEnabled()
78
+ {
79
+ try {
80
+ $klarna = Mage::getModel('klarna/klarnacheckout');
81
+ $klarna->setQuote($this->getQuote(), Vaimo_Klarna_Helper_Data::KLARNA_METHOD_CHECKOUT);
82
+ $res = $klarna->getConfigData('enable_other_button');
83
+ } catch (Exception $e) {
84
+ $res = true;
85
+ }
86
+
87
+ return $res;
88
+ }
89
+ }
app/code/community/Vaimo/Klarna/Block/Klarnacheckout/Reward.php ADDED
@@ -0,0 +1,81 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Copyright (c) 2009-2014 Vaimo AB
4
+ *
5
+ * Vaimo reserves all rights in the Program as delivered. The Program
6
+ * or any portion thereof may not be reproduced in any form whatsoever without
7
+ * the written consent of Vaimo, except as provided by licence. A licence
8
+ * under Vaimo's rights in the Program may be available directly from
9
+ * Vaimo.
10
+ *
11
+ * Disclaimer:
12
+ * THIS NOTICE MAY NOT BE REMOVED FROM THE PROGRAM BY ANY USER THEREOF.
13
+ * THE PROGRAM IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
14
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
16
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ * OUT OF OR IN CONNECTION WITH THE PROGRAM OR THE USE OR OTHER DEALINGS
19
+ * IN THE PROGRAM.
20
+ *
21
+ * @category Vaimo
22
+ * @package Vaimo_Klarna
23
+ * @copyright Copyright (c) 2009-2014 Vaimo AB
24
+ */
25
+
26
+ class Vaimo_Klarna_Block_Klarnacheckout_Reward extends Mage_Core_Block_Template
27
+ {
28
+ protected $_rewardBlock = null;
29
+
30
+ /**
31
+ * @return bool|Enterprise_Reward_Block_Checkout_Payment_Additional
32
+ */
33
+ protected function _getRewardBlock()
34
+ {
35
+ if ($this->_rewardBlock == null) {
36
+ if (Mage::helper('core')->isModuleEnabled('Enterprise_Reward')) {
37
+ $this->_rewardBlock = $this->getLayout()->getBlockSingleton('enterprise_reward/checkout_payment_additional');
38
+ } else {
39
+ $this->_rewardBlock = false;
40
+ }
41
+ }
42
+
43
+ return $this->_rewardBlock;
44
+ }
45
+
46
+ public function getCanUseRewardPoints()
47
+ {
48
+ if ($block = $this->_getRewardBlock()) {
49
+ return $block->getCanUseRewardPoints();
50
+ }
51
+
52
+ return false;
53
+ }
54
+
55
+ public function useRewardPoints()
56
+ {
57
+ if ($block = $this->_getRewardBlock()) {
58
+ return $block->useRewardPoints();
59
+ }
60
+
61
+ return false;
62
+ }
63
+
64
+ public function getPointsBalance()
65
+ {
66
+ if ($block = $this->_getRewardBlock()) {
67
+ return $block->getReward()->getPointsBalance();
68
+ }
69
+
70
+ return 0;
71
+ }
72
+
73
+ public function getCurrencyAmount()
74
+ {
75
+ if ($block = $this->_getRewardBlock()) {
76
+ return $block->getReward()->getCurrencyAmount();
77
+ }
78
+
79
+ return 0;
80
+ }
81
+ }
app/code/community/Vaimo/Klarna/{Model/Klarna/Widget.php → Block/Klarnacheckout/Success.php} RENAMED
@@ -23,20 +23,23 @@
23
  * @copyright Copyright (c) 2009-2014 Vaimo AB
24
  */
25
 
26
- class Vaimo_Klarna_Model_Klarna_Widget extends Vaimo_Klarna_Model_Klarna_Tools_Address
27
  {
28
- public function __construct()
29
  {
30
- parent::__construct();
31
- $this->_setFunctionName('widget');
32
- }
33
 
34
- public function getKlarnaSetup()
35
- {
36
- if (!$this->_getConfigData('disable_product_widget')) {
37
- return parent::getKlarnaSetup();
38
- } else {
39
- return NULL;
 
 
40
  }
 
 
41
  }
42
- }
23
  * @copyright Copyright (c) 2009-2014 Vaimo AB
24
  */
25
 
26
+ class Vaimo_Klarna_Block_Klarnacheckout_Success extends Mage_Core_Block_Template
27
  {
28
+ public function getKlarnaHtml()
29
  {
30
+ try {
31
+ $checkoutId = Mage::getSingleton('checkout/session')->getKlarnaCheckoutId();
 
32
 
33
+ /** @var Vaimo_Klarna_Model_Klarnacheckout $klarna */
34
+ $klarna = Mage::getModel('klarna/klarnacheckout');
35
+ $klarna->setStoreInformation();
36
+ // Klarna model must know the correct store at this point, which we can not...
37
+ $klarna->setMethod(Vaimo_Klarna_Helper_Data::KLARNA_METHOD_CHECKOUT);
38
+ $html = $klarna->getKlarnaOrderHtml($checkoutId, false, false);
39
+ } catch (Exception $e) {
40
+ $html = $e->getMessage();
41
  }
42
+
43
+ return $html;
44
  }
45
+ }
app/code/community/Vaimo/Klarna/Block/Page/Html/Logo.php CHANGED
@@ -21,7 +21,6 @@
21
  * @category Vaimo
22
  * @package Vaimo_Klarna
23
  * @copyright Copyright (c) 2009-2014 Vaimo AB
24
- * @author
25
  */
26
 
27
  class Vaimo_Klarna_Block_Page_Html_Logo extends Mage_Core_Block_Template
@@ -43,9 +42,9 @@ class Vaimo_Klarna_Block_Page_Html_Logo extends Mage_Core_Block_Template
43
 
44
  public function getAvailableMethods()
45
  {
46
- $klarnaWidget = Mage::getModel('klarna/klarna_widget');
47
- $klarnaWidget->setQuote($this->getQuote());
48
- $res = $klarnaWidget->getAvailableMethods();
49
  return $res;
50
  }
51
 
@@ -54,27 +53,49 @@ class Vaimo_Klarna_Block_Page_Html_Logo extends Mage_Core_Block_Template
54
  $res = array();
55
  $invoice_found = false;
56
  $account_found = false;
 
57
  $logoPosition = Vaimo_Klarna_Helper_Data::KLARNA_LOGOTYPE_POSITION_FRONTEND;
58
- $klarnaWidget = Mage::getModel('klarna/klarna_widget');
59
- $klarnaWidget->setQuote($this->getQuote());
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
60
  foreach ($methods as $method) {
61
- $klarnaWidget->setMethod($method);
62
  if ($method==Vaimo_Klarna_Helper_Data::KLARNA_METHOD_INVOICE) {
63
  $logoType = Vaimo_Klarna_Helper_Data::KLARNA_LOGOTYPE_TYPE_INVOICE;
64
  $invoice_found = true;
65
  } elseif ($method==Vaimo_Klarna_Helper_Data::KLARNA_METHOD_ACCOUNT) {
66
  $logoType = Vaimo_Klarna_Helper_Data::KLARNA_LOGOTYPE_TYPE_ACCOUNT;
67
  $account_found = true;
 
 
 
68
  } else {
69
  continue;
70
  }
71
- if ($invoice_found && $account_found && $useBoth) {
72
- $res = array($klarnaWidget->getKlarnaLogotype($width, $logoPosition, Vaimo_Klarna_Helper_Data::KLARNA_LOGOTYPE_TYPE_BOTH));
73
- break;
74
- } else {
75
- $res[] = $klarnaWidget->getKlarnaLogotype($width, $logoPosition, $logoType);
76
- }
77
  }
 
 
78
  return $res;
79
  }
80
  }
21
  * @category Vaimo
22
  * @package Vaimo_Klarna
23
  * @copyright Copyright (c) 2009-2014 Vaimo AB
 
24
  */
25
 
26
  class Vaimo_Klarna_Block_Page_Html_Logo extends Mage_Core_Block_Template
42
 
43
  public function getAvailableMethods()
44
  {
45
+ $klarna = Mage::getModel('klarna/klarna');
46
+ $klarna->setQuote($this->getQuote());
47
+ $res = $klarna->getAvailableMethods();
48
  return $res;
49
  }
50
 
53
  $res = array();
54
  $invoice_found = false;
55
  $account_found = false;
56
+ $checkout_found = false;
57
  $logoPosition = Vaimo_Klarna_Helper_Data::KLARNA_LOGOTYPE_POSITION_FRONTEND;
58
+ $klarna = Mage::getModel('klarna/klarna');
59
+ $klarna->setQuote($this->getQuote());
60
+
61
+ // Branding change, always show same logotype, except for Klarna Checkout
62
+ foreach ($methods as $method) {
63
+ if ($method==Vaimo_Klarna_Helper_Data::KLARNA_METHOD_CHECKOUT) {
64
+ $checkout_found = true;
65
+ } else {
66
+ $invoice_found = true;
67
+ }
68
+ }
69
+ if ($checkout_found) {
70
+ $res = array($klarna->getKlarnaLogotype($width, $logoPosition, Vaimo_Klarna_Helper_Data::KLARNA_LOGOTYPE_TYPE_CHECKOUT));
71
+ } elseif ($invoice_found) {
72
+ $res = array($klarna->getKlarnaLogotype($width, $logoPosition, Vaimo_Klarna_Helper_Data::KLARNA_LOGOTYPE_TYPE_BASIC));
73
+ }
74
+
75
+ /*
76
  foreach ($methods as $method) {
77
+ $klarna->setMethod($method);
78
  if ($method==Vaimo_Klarna_Helper_Data::KLARNA_METHOD_INVOICE) {
79
  $logoType = Vaimo_Klarna_Helper_Data::KLARNA_LOGOTYPE_TYPE_INVOICE;
80
  $invoice_found = true;
81
  } elseif ($method==Vaimo_Klarna_Helper_Data::KLARNA_METHOD_ACCOUNT) {
82
  $logoType = Vaimo_Klarna_Helper_Data::KLARNA_LOGOTYPE_TYPE_ACCOUNT;
83
  $account_found = true;
84
+ } elseif ($method==Vaimo_Klarna_Helper_Data::KLARNA_METHOD_CHECKOUT) {
85
+ $logoType = Vaimo_Klarna_Helper_Data::KLARNA_LOGOTYPE_TYPE_CHECKOUT;
86
+ $checkout_found = true;
87
  } else {
88
  continue;
89
  }
90
+ $res[] = $klarna->getKlarnaLogotype($width, $logoPosition, $logoType);
91
+ }
92
+ if ($checkout_found) {
93
+ $res = array($klarna->getKlarnaLogotype($width, $logoPosition, Vaimo_Klarna_Helper_Data::KLARNA_LOGOTYPE_TYPE_CHECKOUT));
94
+ } elseif ($invoice_found && $account_found && $useBoth) {
95
+ $res = array($klarna->getKlarnaLogotype($width, $logoPosition, Vaimo_Klarna_Helper_Data::KLARNA_LOGOTYPE_TYPE_BOTH));
96
  }
97
+ */
98
+
99
  return $res;
100
  }
101
  }
app/code/community/Vaimo/Klarna/Helper/Data.php CHANGED
@@ -25,9 +25,21 @@
25
 
26
  class Vaimo_Klarna_Helper_Data extends Mage_Core_Helper_Abstract
27
  {
28
- const KLARNA_METHOD_INVOICE = 'vaimo_klarna_invoice';
29
- const KLARNA_METHOD_ACCOUNT = 'vaimo_klarna_account';
30
- const KLARNA_METHOD_SPECIAL = 'vaimo_klarna_special';
 
 
 
 
 
 
 
 
 
 
 
 
31
 
32
  const KLARNA_STATUS_ACCEPTED = 'accepted';
33
  const KLARNA_STATUS_PENDING = 'pending';
@@ -43,9 +55,12 @@ class Vaimo_Klarna_Helper_Data extends Mage_Core_Helper_Abstract
43
  const KLARNA_INFO_FIELD_RESERVATION_STATUS = 'klarna_reservation_status';
44
  const KLARNA_INFO_FIELD_RESERVATION_ID = 'klarna_reservation_id';
45
  const KLARNA_INFO_FIELD_CANCELED_DATE = 'klarna_reservation_canceled_date';
 
 
46
  const KLARNA_INFO_FIELD_INVOICE_LIST = 'klarna_invoice_list';
47
  const KLARNA_INFO_FIELD_INVOICE_LIST_STATUS = 'invoice_status';
48
  const KLARNA_INFO_FIELD_INVOICE_LIST_ID = 'invoice_id';
 
49
  const KLARNA_INFO_FIELD_HOST = 'klarna_reservation_host';
50
  const KLARNA_INFO_FIELD_MERCHANT_ID = 'merchant_id';
51
 
@@ -72,21 +87,38 @@ class Vaimo_Klarna_Helper_Data extends Mage_Core_Helper_Abstract
72
  const KLARNA_API_RESPONSE_TRANSACTION_ID = 'response_transaction_id';
73
  const KLARNA_API_RESPONSE_FEE_REFUNDED = 'response_fee_refunded';
74
  const KLARNA_API_RESPONSE_FEE_CAPTURED = 'response_fee_captured';
 
 
75
 
76
- const KLARNA_LOGOTYPE_TYPE_INVOICE = 'invoice';
77
- const KLARNA_LOGOTYPE_TYPE_ACCOUNT = 'account';
78
- const KLARNA_LOGOTYPE_TYPE_BOTH = 'unified';
79
- const KLARNA_LOGOTYPE_TYPE_BASIC = 'basic';
 
 
 
 
 
 
 
 
 
80
 
81
  const KLARNA_LOGOTYPE_POSITION_FRONTEND = 'frontend';
82
  const KLARNA_LOGOTYPE_POSITION_PRODUCT = 'product';
83
  const KLARNA_LOGOTYPE_POSITION_CHECKOUT = 'checkout';
 
 
 
 
 
84
 
85
  protected $_supportedMethods = array(
86
- Vaimo_Klarna_Helper_Data::KLARNA_METHOD_INVOICE,
87
- Vaimo_Klarna_Helper_Data::KLARNA_METHOD_ACCOUNT,
88
- Vaimo_Klarna_Helper_Data::KLARNA_METHOD_SPECIAL
89
- );
 
90
 
91
  protected $_klarnaFields = array(
92
  self::KLARNA_INFO_FIELD_FEE,
@@ -99,6 +131,8 @@ class Vaimo_Klarna_Helper_Data extends Mage_Core_Helper_Abstract
99
  self::KLARNA_INFO_FIELD_RESERVATION_STATUS,
100
  self::KLARNA_INFO_FIELD_RESERVATION_ID,
101
  self::KLARNA_INFO_FIELD_CANCELED_DATE,
 
 
102
  self::KLARNA_INFO_FIELD_INVOICE_LIST,
103
  self::KLARNA_INFO_FIELD_INVOICE_LIST_STATUS,
104
  self::KLARNA_INFO_FIELD_INVOICE_LIST_ID,
@@ -123,17 +157,71 @@ class Vaimo_Klarna_Helper_Data extends Mage_Core_Helper_Abstract
123
  self::KLARNA_FORM_FIELD_CONSENT,
124
  self::KLARNA_FORM_FIELD_GENDER,
125
  self::KLARNA_FORM_FIELD_EMAIL,
126
-
127
  );
128
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
129
  public function getSupportedMethods()
130
  {
131
  return $this->_supportedMethods;
132
  }
133
 
134
- public function getKlarnaFields()
135
  {
136
- return $this->_klarnaFields;
137
  }
138
 
139
  public function isMethodKlarna($method)
@@ -176,10 +264,11 @@ class Vaimo_Klarna_Helper_Data extends Mage_Core_Helper_Abstract
176
  $res = false;
177
  if (Mage::getStoreConfig('onestepcheckout/general/rewrite_checkout_links', $store)) {
178
  $res = true;
179
- if (isset($_SERVER['REQUEST_URI'])) {
180
- if (stristr($_SERVER['REQUEST_URI'],'checkout/onepage')) {
181
- $res = false;
182
- }
 
183
  }
184
  }
185
  return $res;
@@ -412,4 +501,135 @@ class Vaimo_Klarna_Helper_Data extends Mage_Core_Helper_Abstract
412
  return false;
413
  }
414
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
415
  }
25
 
26
  class Vaimo_Klarna_Helper_Data extends Mage_Core_Helper_Abstract
27
  {
28
+ const KLARNA_METHOD_INVOICE = 'vaimo_klarna_invoice';
29
+ const KLARNA_METHOD_ACCOUNT = 'vaimo_klarna_account';
30
+ const KLARNA_METHOD_SPECIAL = 'vaimo_klarna_special';
31
+ const KLARNA_METHOD_CHECKOUT = 'vaimo_klarna_checkout';
32
+
33
+ const KLARNA_API_CALL_RESERVE = 'reserve';
34
+ const KLARNA_API_CALL_CAPTURE = 'capture';
35
+ const KLARNA_API_CALL_REFUND = 'refund';
36
+ const KLARNA_API_CALL_CANCEL = 'cancel';
37
+ const KLARNA_API_CALL_CHECKSTATUS = 'check_status';
38
+ const KLARNA_API_CALL_ADDRESSES = 'addresses';
39
+ const KLARNA_API_CALL_PCLASSES = 'pclasses';
40
+
41
+ const KLARNA_API_CALL_KCODISPLAY_ORDER = 'kco_display_order';
42
+ const KLARNA_API_CALL_KCOCREATE_ORDER = 'kco_create_order';
43
 
44
  const KLARNA_STATUS_ACCEPTED = 'accepted';
45
  const KLARNA_STATUS_PENDING = 'pending';
55
  const KLARNA_INFO_FIELD_RESERVATION_STATUS = 'klarna_reservation_status';
56
  const KLARNA_INFO_FIELD_RESERVATION_ID = 'klarna_reservation_id';
57
  const KLARNA_INFO_FIELD_CANCELED_DATE = 'klarna_reservation_canceled_date';
58
+ const KLARNA_INFO_FIELD_REFERENCE = 'klarna_reservation_reference';
59
+ const KLARNA_INFO_FIELD_ORDER_ID = 'klarna_reservation_order_id';
60
  const KLARNA_INFO_FIELD_INVOICE_LIST = 'klarna_invoice_list';
61
  const KLARNA_INFO_FIELD_INVOICE_LIST_STATUS = 'invoice_status';
62
  const KLARNA_INFO_FIELD_INVOICE_LIST_ID = 'invoice_id';
63
+ const KLARNA_INFO_FIELD_INVOICE_LIST_KCO_ID = 'invoice_kco_id';
64
  const KLARNA_INFO_FIELD_HOST = 'klarna_reservation_host';
65
  const KLARNA_INFO_FIELD_MERCHANT_ID = 'merchant_id';
66
 
87
  const KLARNA_API_RESPONSE_TRANSACTION_ID = 'response_transaction_id';
88
  const KLARNA_API_RESPONSE_FEE_REFUNDED = 'response_fee_refunded';
89
  const KLARNA_API_RESPONSE_FEE_CAPTURED = 'response_fee_captured';
90
+ const KLARNA_API_RESPONSE_KCO_CAPTURE_ID = 'response_kco_capture_id';
91
+ const KLARNA_API_RESPONSE_KCO_LOCATION = 'response_kco_location';
92
 
93
+ const KLARNA_LOGOTYPE_TYPE_INVOICE = 'invoice';
94
+ const KLARNA_LOGOTYPE_TYPE_ACCOUNT = 'account';
95
+ const KLARNA_LOGOTYPE_TYPE_CHECKOUT = 'checkout';
96
+ const KLARNA_LOGOTYPE_TYPE_BOTH = 'unified';
97
+ const KLARNA_LOGOTYPE_TYPE_BASIC = 'basic';
98
+
99
+ const KLARNA_FLAG_ITEM_NORMAL = "normal";
100
+ const KLARNA_FLAG_ITEM_SHIPPING_FEE = "shipping";
101
+ const KLARNA_FLAG_ITEM_HANDLING_FEE = "handling";
102
+
103
+ const KLARNA_REFUND_METHOD_FULL = "full";
104
+ const KLARNA_REFUND_METHOD_PART = "part";
105
+ const KLARNA_REFUND_METHOD_AMOUNT = "amount";
106
 
107
  const KLARNA_LOGOTYPE_POSITION_FRONTEND = 'frontend';
108
  const KLARNA_LOGOTYPE_POSITION_PRODUCT = 'product';
109
  const KLARNA_LOGOTYPE_POSITION_CHECKOUT = 'checkout';
110
+
111
+ const KLARNA_DISPATCH_RESERVED = 'vaimo_paymentmethod_order_reserved';
112
+ const KLARNA_DISPATCH_CAPTURED = 'vaimo_paymentmethod_order_captured';
113
+ const KLARNA_DISPATCH_REFUNDED = 'vaimo_paymentmethod_order_refunded';
114
+ const KLARNA_DISPATCH_CANCELED = 'vaimo_paymentmethod_order_canceled';
115
 
116
  protected $_supportedMethods = array(
117
+ Vaimo_Klarna_Helper_Data::KLARNA_METHOD_INVOICE,
118
+ Vaimo_Klarna_Helper_Data::KLARNA_METHOD_ACCOUNT,
119
+ Vaimo_Klarna_Helper_Data::KLARNA_METHOD_SPECIAL,
120
+ Vaimo_Klarna_Helper_Data::KLARNA_METHOD_CHECKOUT
121
+ );
122
 
123
  protected $_klarnaFields = array(
124
  self::KLARNA_INFO_FIELD_FEE,
131
  self::KLARNA_INFO_FIELD_RESERVATION_STATUS,
132
  self::KLARNA_INFO_FIELD_RESERVATION_ID,
133
  self::KLARNA_INFO_FIELD_CANCELED_DATE,
134
+ self::KLARNA_INFO_FIELD_REFERENCE,
135
+ self::KLARNA_INFO_FIELD_ORDER_ID,
136
  self::KLARNA_INFO_FIELD_INVOICE_LIST,
137
  self::KLARNA_INFO_FIELD_INVOICE_LIST_STATUS,
138
  self::KLARNA_INFO_FIELD_INVOICE_LIST_ID,
157
  self::KLARNA_FORM_FIELD_CONSENT,
158
  self::KLARNA_FORM_FIELD_GENDER,
159
  self::KLARNA_FORM_FIELD_EMAIL,
160
+
161
  );
162
 
163
+ const KLARNA_CHECKOUT_ENABLE_NEWSLETTER = 'payment/vaimo_klarna_checkout/enable_newsletter';
164
+ const KLARNA_CHECKOUT_EXTRA_ORDER_ATTRIBUTE = 'payment/vaimo_klarna_checkout/extra_order_attribute';
165
+ const KLARNA_CHECKOUT_ENABLE_CART_ABOVE_KCO = 'payment/vaimo_klarna_checkout/enable_cart_above_kco';
166
+
167
+ const KLARNA_CHECKOUT_NEWSLETTER_DISABLED = 0;
168
+ const KLARNA_CHECKOUT_NEWSLETTER_SUBSCRIBE = 1;
169
+ const KLARNA_CHECKOUT_NEWSLETTER_DONT_SUBSCRIBE = 2;
170
+
171
+ const KLARNA_CHECKOUT_ALLOW_ALL_GROUP_ID = 99;
172
+
173
+ const ENCODING_MAGENTO = 'UTF-8';
174
+ const ENCODING_KLARNA = 'ISO-8859-1';
175
+
176
+
177
+ /**
178
+ * Encode the string to klarna encoding
179
+ *
180
+ * @param string $str string to encode
181
+ * @param string $from from encoding
182
+ * @param string $to target encoding
183
+ *
184
+ * @return string
185
+ */
186
+ public function encode($str, $from = null, $to = null)
187
+ {
188
+ if ($from === null) {
189
+ $from = self::ENCODING_MAGENTO;
190
+ }
191
+ if ($to === null) {
192
+ $to = self::ENCODING_KLARNA;
193
+ }
194
+ return iconv($from, $to, $str);
195
+ }
196
+
197
+ /**
198
+ * Decode the string to the Magento encoding
199
+ *
200
+ * @param string $str string to decode
201
+ * @param string $from from encoding
202
+ * @param string $to target encoding
203
+ *
204
+ * @return string
205
+ */
206
+ public function decode($str, $from = null, $to = null)
207
+ {
208
+ if ($from === null) {
209
+ $from = self::ENCODING_KLARNA;
210
+ }
211
+ if ($to === null) {
212
+ $to = self::ENCODING_MAGENTO;
213
+ }
214
+ return iconv($from, $to, $str);
215
+ }
216
+
217
  public function getSupportedMethods()
218
  {
219
  return $this->_supportedMethods;
220
  }
221
 
222
+ public function isKlarnaField($key)
223
  {
224
+ return (in_array($key,$this->_klarnaFields));
225
  }
226
 
227
  public function isMethodKlarna($method)
264
  $res = false;
265
  if (Mage::getStoreConfig('onestepcheckout/general/rewrite_checkout_links', $store)) {
266
  $res = true;
267
+ $request = Mage::app()->getRequest();
268
+ $requestedRouteName = $request->getRequestedRouteName();
269
+ $requestedControllerName = $request->getRequestedControllerName();
270
+ if ($requestedRouteName == 'checkout' && $requestedControllerName == 'onepage') {
271
+ $res = false;
272
  }
273
  }
274
  return $res;
501
  return false;
502
  }
503
  }
504
+
505
+
506
+ // KLARNA CHECKOUT FROM NOW
507
+
508
+ protected function _addressMatch(array $address1, array $address2)
509
+ {
510
+ $compareFields = array(
511
+ 'firstname',
512
+ 'lastname',
513
+ 'company',
514
+ 'street',
515
+ 'postcode',
516
+ 'city',
517
+ 'telephone',
518
+ 'country_id',
519
+ );
520
+
521
+ // fix street address: sometimes street is array
522
+ if (isset($address1['street']) && is_array($address1['street'])) {
523
+ $address1['street'] = implode("\n", $address1['street']);
524
+ }
525
+
526
+ if (isset($address2['street']) && is_array($address2['street'])) {
527
+ $address2['street'] = implode("\n", $address2['street']);
528
+ }
529
+
530
+ foreach ($compareFields as $field) {
531
+ $field1 = (isset($address1[$field]) ? $address1[$field] : '');
532
+ $field2 = (isset($address2[$field]) ? $address2[$field] : '');
533
+
534
+ if ($field1 != $field2) {
535
+ return false;
536
+ }
537
+ }
538
+
539
+ return true;
540
+ }
541
+
542
+ public function getCustomerAddressId($customer, $addressData)
543
+ {
544
+ if (!$customer) {
545
+ return false;
546
+ }
547
+
548
+ $billingAddress = $customer->getDefaultBillingAddress();
549
+
550
+ if ($this->_addressMatch($addressData, $billingAddress->getData())) {
551
+ return $billingAddress->getEntityId();
552
+ }
553
+
554
+ $shippingAddress = $customer->getDefaultShippingAddress();
555
+
556
+ if ($this->_addressMatch($addressData, $shippingAddress->getData())) {
557
+ return $shippingAddress->getEntityId();
558
+ }
559
+
560
+ $additionalAddresses = $customer->getAdditionalAddresses();
561
+
562
+ foreach ($additionalAddresses as $additionalAddress) {
563
+ if ($this->_addressMatch($addressData, $additionalAddress->getData())) {
564
+ return $additionalAddress->getEntityId();
565
+ }
566
+ }
567
+
568
+ return false;
569
+ }
570
+
571
+ public function getExtraOrderAttributeCode()
572
+ {
573
+ return Mage::getStoreConfig(self::KLARNA_CHECKOUT_EXTRA_ORDER_ATTRIBUTE);
574
+ }
575
+
576
+ public function excludeCartInKlarnaCheckout()
577
+ {
578
+ if (Mage::getStoreConfig(self::KLARNA_CHECKOUT_ENABLE_CART_ABOVE_KCO)) {
579
+ $res = false;
580
+ } else {
581
+ $res = true;
582
+ }
583
+ return $res;
584
+ }
585
+
586
+ /*
587
+ * This function might be removed
588
+ *
589
+ */
590
+ public function dispatchReserveInfo($order, $pno)
591
+ {
592
+ Mage::dispatchEvent( 'vaimo_klarna_pno_used_to_reserve', array(
593
+ 'store_id' => $order->getStoreId(),
594
+ 'order_id' => $order->getIncrementId(),
595
+ 'customer_id' => $order->getCustomerId(),
596
+ 'pno' => $pno
597
+ ));
598
+ }
599
+
600
+ /*
601
+ * Whenever a refund, capture, reserve or cancel is performed, we send out an event
602
+ * This can be listened to for financial reconciliation
603
+ *
604
+ * @return void
605
+ */
606
+ public function dispatchMethodEvent($order, $eventcode, $amount, $method)
607
+ {
608
+ Mage::dispatchEvent( $eventcode, array(
609
+ 'store_id' => $order->getStoreId(),
610
+ 'order_id' => $order->getIncrementId(),
611
+ 'method' => $method,
612
+ 'amount' => $amount
613
+ ));
614
+
615
+ // Vaimo specific dispatch
616
+ $event_name = NULL;
617
+ switch ($eventcode) {
618
+ case self::KLARNA_DISPATCH_RESERVED:
619
+ $event_name = 'ic_order_success';
620
+ break;
621
+ case self::KLARNA_DISPATCH_CAPTURED:
622
+ $event_name = 'ic_order_captured';
623
+ break;
624
+ case self::KLARNA_DISPATCH_REFUNDED:
625
+ break;
626
+ case self::KLARNA_DISPATCH_CANCELED:
627
+ $event_name = 'ic_order_cancel';
628
+ break;
629
+ }
630
+ if ($event_name) {
631
+ Mage::dispatchEvent( $event_name, array("order" => $order) );
632
+ }
633
+ }
634
+
635
  }
app/code/community/Vaimo/Klarna/Model/Api.php ADDED
@@ -0,0 +1,104 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Copyright (c) 2009-2014 Vaimo AB
4
+ *
5
+ * Vaimo reserves all rights in the Program as delivered. The Program
6
+ * or any portion thereof may not be reproduced in any form whatsoever without
7
+ * the written consent of Vaimo, except as provided by licence. A licence
8
+ * under Vaimo's rights in the Program may be available directly from
9
+ * Vaimo.
10
+ *
11
+ * Disclaimer:
12
+ * THIS NOTICE MAY NOT BE REMOVED FROM THE PROGRAM BY ANY USER THEREOF.
13
+ * THE PROGRAM IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
14
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
16
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ * OUT OF OR IN CONNECTION WITH THE PROGRAM OR THE USE OR OTHER DEALINGS
19
+ * IN THE PROGRAM.
20
+ *
21
+ * @category Vaimo
22
+ * @package Vaimo_Klarna
23
+ * @copyright Copyright (c) 2009-2014 Vaimo AB
24
+ */
25
+
26
+ /**
27
+ * This is the only file in the module that loads and uses the Klarna library folder
28
+ * It should never be instantiated by itself, it can, but for readability one should not
29
+ * No Klarna specific variables, constants or functions should be used outside this class
30
+ *
31
+ * @class Vaimo_Klarna_Model_Api
32
+ */
33
+ class Vaimo_Klarna_Model_Api extends Varien_Object
34
+ {
35
+ /**
36
+ * @return Vaimo_Klarna_Model_Api_Xmlrpc
37
+ */
38
+ protected function _getKlarnaPaymentMethodXmlRpcApi()
39
+ {
40
+ return Mage::getSingleton('klarna/api_xmlrpc');
41
+ }
42
+
43
+ /**
44
+ * @return Vaimo_Klarna_Model_Api_Rest
45
+ */
46
+ protected function _getKlarnaCheckOutRestApiForUK()
47
+ {
48
+ return Mage::getSingleton('klarna/api_rest');
49
+ }
50
+
51
+ /**
52
+ * @return Vaimo_Klarna_Model_Api_Kco
53
+ */
54
+ protected function _getKlarnaCheckOutOriginalApi()
55
+ {
56
+ return Mage::getSingleton('klarna/api_kco');
57
+ }
58
+
59
+ /**
60
+ * @param string|int $storeId
61
+ *
62
+ * @return string|bool
63
+ */
64
+ protected function _getKlarnaCheckOutApiVersion($storeId)
65
+ {
66
+ return Mage::getStoreConfig('payment/vaimo_klarna_checkout/api_version', $storeId);
67
+ }
68
+
69
+ /**
70
+ * @param string|int $storeId
71
+ * @param string $method
72
+ * @param null|string $call
73
+ *
74
+ * @return null|Vaimo_Klarna_Model_Api_Kco|Vaimo_Klarna_Model_Api_Rest|Vaimo_Klarna_Model_Api_Xmlrpc
75
+ */
76
+ public function getApiInstance($storeId, $method, $call = NULL)
77
+ {
78
+ switch ($method) {
79
+ case Vaimo_Klarna_Helper_Data::KLARNA_METHOD_INVOICE:
80
+ case Vaimo_Klarna_Helper_Data::KLARNA_METHOD_ACCOUNT:
81
+ case Vaimo_Klarna_Helper_Data::KLARNA_METHOD_SPECIAL:
82
+ return $this->_getKlarnaPaymentMethodXmlRpcApi();
83
+ break;
84
+ case Vaimo_Klarna_Helper_Data::KLARNA_METHOD_CHECKOUT:
85
+ if ($this->_getKlarnaCheckOutApiVersion($storeId) == 3) {
86
+ return $this->_getKlarnaCheckOutRestApiForUK();
87
+ } else {
88
+ switch ($call) {
89
+ case Vaimo_Klarna_Helper_Data::KLARNA_API_CALL_RESERVE:
90
+ case Vaimo_Klarna_Helper_Data::KLARNA_API_CALL_KCODISPLAY_ORDER:
91
+ case Vaimo_Klarna_Helper_Data::KLARNA_API_CALL_KCOCREATE_ORDER:
92
+ return $this->_getKlarnaCheckOutOriginalApi();
93
+ break;
94
+ default:
95
+ return $this->_getKlarnaPaymentMethodXmlRpcApi();
96
+ break;
97
+ }
98
+ }
99
+ break;
100
+ }
101
+
102
+ return null;
103
+ }
104
+ }
app/code/community/Vaimo/Klarna/{Tests/TestCase.php → Model/Api/Abstract.php} RENAMED
@@ -23,28 +23,40 @@
23
  * @copyright Copyright (c) 2009-2014 Vaimo AB
24
  */
25
 
26
- class Vaimo_Klarna_Tests_TestCase extends PHPUnit_Framework_TestCase
27
  {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
28
  /**
29
- * A helper function to be able to test private functions.
30
- * Only works on PHP version >= 5.3.2
31
  *
32
- * @param $obj
33
- * @param $name
34
- * @param array $args
35
- * @throws Exception
36
- * @return mixed
37
  */
38
- protected function _callMethod($obj, $name, array $args)
39
  {
40
- if (!(strnatcmp(phpversion(), '5.3.2') >= 0)) {
41
- throw new Exception('callMethod requires PHP version >= 5.3.2');
42
- }
43
 
44
- $class = new \ReflectionClass($obj);
45
- $method = $class->getMethod($name);
46
- $method->setAccessible(true);
 
 
 
47
 
48
- return $method->invokeArgs($obj, $args);
49
  }
50
- }
 
23
  * @copyright Copyright (c) 2009-2014 Vaimo AB
24
  */
25
 
26
+ abstract class Vaimo_Klarna_Model_Api_Abstract extends Varien_Object
27
  {
28
+ protected $_klarnaSetup = NULL;
29
+
30
+ protected $_transport = NULL;
31
+
32
+ public function setTransport($model)
33
+ {
34
+ $this->_transport = $model;
35
+ }
36
+
37
+ protected function _getTransport()
38
+ {
39
+ return $this->_transport;
40
+ }
41
+
42
  /**
43
+ * Get current active quote instance
 
44
  *
45
+ * @return Mage_Sales_Model_Quote
 
 
 
 
46
  */
47
+ protected function _getQuote()
48
  {
49
+ return Mage::getSingleton('checkout/cart')->getQuote();
50
+ }
 
51
 
52
+ protected function _isMobile()
53
+ {
54
+ if (@class_exists('Mobile_Detect')) {
55
+ $detect = new Mobile_Detect();
56
+ return $detect->isMobile();
57
+ }
58
 
59
+ return false;
60
  }
61
+
62
+ }
app/code/community/Vaimo/Klarna/Model/Api/Kco.php ADDED
@@ -0,0 +1,495 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Copyright (c) 2009-2014 Vaimo AB
4
+ *
5
+ * Vaimo reserves all rights in the Program as delivered. The Program
6
+ * or any portion thereof may not be reproduced in any form whatsoever without
7
+ * the written consent of Vaimo, except as provided by licence. A licence
8
+ * under Vaimo's rights in the Program may be available directly from
9
+ * Vaimo.
10
+ *
11
+ * Disclaimer:
12
+ * THIS NOTICE MAY NOT BE REMOVED FROM THE PROGRAM BY ANY USER THEREOF.
13
+ * THE PROGRAM IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
14
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
16
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ * OUT OF OR IN CONNECTION WITH THE PROGRAM OR THE USE OR OTHER DEALINGS
19
+ * IN THE PROGRAM.
20
+ *
21
+ * @category Vaimo
22
+ * @package Vaimo_Klarna
23
+ * @copyright Copyright (c) 2009-2014 Vaimo AB
24
+ */
25
+
26
+ /*
27
+ *
28
+ * This is the only file in the module that loads and uses the Klarna library folder
29
+ * It should never be instantiated by itself, it can, but for readability one should not
30
+ * No Klarna specific variables, constants or functions should be used outside this class
31
+ *
32
+ */
33
+
34
+ class Vaimo_Klarna_Model_Api_Kco extends Vaimo_Klarna_Model_Api_Abstract
35
+ {
36
+ protected $_klarnaOrder = NULL;
37
+
38
+ /**
39
+ * Get current active quote instance
40
+ *
41
+ * @return Mage_Sales_Model_Quote
42
+ */
43
+ protected function _getQuote()
44
+ {
45
+ return Mage::getSingleton('checkout/cart')->getQuote();
46
+ }
47
+
48
+ /**
49
+ * Get active Klarna checkout id
50
+ *
51
+ * @return string
52
+ */
53
+ protected function _getKlarnaCheckoutId()
54
+ {
55
+ return $this->_getQuote()->getKlarnaCheckoutId();
56
+ }
57
+
58
+ /**
59
+ * Put Klarna checkout id to quote
60
+ *
61
+ * @param $checkoutId string
62
+ */
63
+ protected function _setKlarnaCheckoutId($checkoutId)
64
+ {
65
+ $quote = $this->_getQuote();
66
+
67
+ if ($quote->getKlarnaCheckoutId() != $checkoutId) {
68
+ $this->_getTransport()->logDebugInfo('SET checkout id: ' . $checkoutId);
69
+ $this->_getTransport()->logDebugInfo('Quote Id: ' . $quote->getId());
70
+ $quote->setKlarnaCheckoutId($checkoutId);
71
+ $quote->save();
72
+ }
73
+
74
+ Mage::getSingleton('checkout/session')->setKlarnaCheckoutId($checkoutId);
75
+ }
76
+
77
+ /**
78
+ * Get quote items and totals
79
+ *
80
+ * @return array
81
+ */
82
+ protected function _getCartItems()
83
+ {
84
+ $quote = $this->_getQuote();
85
+ $items = array();
86
+
87
+ foreach ($quote->getAllVisibleItems() as $quoteItem) {
88
+ if ($quoteItem->getTaxPercent() > 0) {
89
+ $taxRate = $quoteItem->getTaxPercent();
90
+ } else {
91
+ $taxRate = $quoteItem->getTaxAmount() / $quoteItem->getRowTotal() * 100;
92
+ }
93
+ $items[] = array(
94
+ 'reference' => $quoteItem->getSku(),
95
+ 'name' => $quoteItem->getName(),
96
+ 'quantity' => round($quoteItem->getQty()),
97
+ 'unit_price' => round($quoteItem->getPriceInclTax() * 100),
98
+ // 'discount_rate' => round($quoteItem->getDiscountPercent() * 100),
99
+ 'tax_rate' => round($taxRate * 100),
100
+ );
101
+ }
102
+
103
+ foreach ($quote->getTotals() as $key => $total) {
104
+ switch ($key) {
105
+ case 'shipping':
106
+ if ($total->getValue() != 0) {
107
+ $amount_incl_tax = $total->getAddress()->getShippingInclTax();
108
+ if (false && $amount_incl_tax) {
109
+ $taxAmount = $total->getAddress()->getShippingTaxAmount();
110
+ $amount = $amount_incl_tax - $taxAmount;
111
+ } else {
112
+ $amount = $total->getAddress()->getShippingAmount();
113
+ $taxAmount = $total->getAddress()->getShippingTaxAmount();
114
+ }
115
+ $hiddenTaxAmount = $total->getAddress()->getShippingHiddenTaxAmount();
116
+ $taxRate = ($taxAmount + $hiddenTaxAmount) / $amount * 100;
117
+ $amount_incl_tax = $amount + $taxAmount + $hiddenTaxAmount;
118
+ $items[] = array(
119
+ 'type' => 'shipping_fee',
120
+ 'reference' => Mage::helper('klarna')->__('shipping'), // $total->getCode()
121
+ 'name' => $total->getTitle(),
122
+ 'quantity' => 1,
123
+ 'unit_price' => round(($amount_incl_tax) * 100),
124
+ 'discount_rate' => 0,
125
+ 'tax_rate' => round($taxRate * 100),
126
+ );
127
+ }
128
+ break;
129
+ case 'discount':
130
+ if ($total->getValue() != 0) {
131
+ // ok, this is a bit shaky here, i know...
132
+ // but i don't have discount tax anywhere but in hidden_tax_amount field :(
133
+ // and I have to send discount also with tax rate to klarna
134
+ // otherwise the total tax wouldn't match
135
+ $taxAmount = $total->getAddress()->getHiddenTaxAmount();
136
+ $amount = -$total->getAddress()->getDiscountAmount() - $taxAmount;
137
+ $taxRate = $taxAmount / $amount * 100;
138
+ $items[] = array(
139
+ 'type' => 'discount',
140
+ 'reference' => Mage::helper('klarna')->__('discount'), // $total->getCode()
141
+ 'name' => $total->getTitle(),
142
+ 'quantity' => 1,
143
+ 'unit_price' => -round(($amount + $taxAmount) * 100),
144
+ 'discount_rate' => 0,
145
+ 'tax_rate' => round($taxRate * 100),
146
+ );
147
+ }
148
+ break;
149
+ case 'giftcardaccount':
150
+ if ($total->getValue() != 0) {
151
+ $items[] = array(
152
+ 'type' => 'discount',
153
+ 'reference' => Mage::helper('klarna')->__('gift_card'), // $total->getCode()
154
+ 'name' => $total->getTitle(),
155
+ 'quantity' => 1,
156
+ 'unit_price' => round($total->getValue() * 100),
157
+ 'discount_rate' => 0,
158
+ 'tax_rate' => 0,
159
+ );
160
+ }
161
+ break;
162
+ case 'ugiftcert':
163
+ if ($total->getValue() != 0) {
164
+ $items[] = array(
165
+ 'type' => 'discount',
166
+ 'reference' => Mage::helper('klarna')->__('gift_card'), // $total->getCode()
167
+ 'name' => $total->getTitle(),
168
+ 'quantity' => 1,
169
+ 'unit_price' => -round($total->getValue() * 100),
170
+ 'discount_rate' => 0,
171
+ 'tax_rate' => 0,
172
+ );
173
+ }
174
+ break;
175
+ case 'reward':
176
+ if ($total->getValue() != 0) {
177
+ $items[] = array(
178
+ 'type' => 'discount',
179
+ 'reference' => Mage::helper('klarna')->__('reward'), // $total->getCode()
180
+ 'name' => $total->getTitle(),
181
+ 'quantity' => 1,
182
+ 'unit_price' => round($total->getValue() * 100),
183
+ 'discount_rate' => 0,
184
+ 'tax_rate' => 0,
185
+ );
186
+ }
187
+ break;
188
+ case 'customerbalance':
189
+ if ($total->getValue() != 0) {
190
+ $items[] = array(
191
+ 'type' => 'discount',
192
+ 'reference' => Mage::helper('klarna')->__('customer_balance'), // $total->getCode()
193
+ 'name' => $total->getTitle(),
194
+ 'quantity' => 1,
195
+ 'unit_price' => round($total->getValue() * 100),
196
+ 'discount_rate' => 0,
197
+ 'tax_rate' => 0,
198
+ );
199
+ }
200
+ break;
201
+ }
202
+ }
203
+
204
+ return $items;
205
+ }
206
+
207
+ /**
208
+ * Get create request
209
+ *
210
+ * @return array
211
+ */
212
+ protected function _getCreateRequest()
213
+ {
214
+ $create = array();
215
+ if (version_compare(Mage::getVersion(), '1.6.2', '>=')) {
216
+ $create['purchase_country'] = Mage::helper('core')->getDefaultCountry();
217
+ } else {
218
+ $create['purchase_country'] = Mage::getStoreConfig('general/country/default');
219
+ }
220
+ $create['purchase_currency'] = $this->_getQuote()->getQuoteCurrencyCode();
221
+ $create['locale'] = str_replace('_', '-', Mage::app()->getLocale()->getLocaleCode());
222
+ $create['merchant']['id'] = $this->_klarnaSetup->getMerchantId();
223
+ $create['merchant']['terms_uri'] = Mage::getUrl($this->_getTransport()->getConfigData("terms_url"));
224
+ $create['merchant']['checkout_uri'] = Mage::getUrl('checkout/klarna');
225
+ $create['merchant']['confirmation_uri'] = Mage::getUrl('checkout/klarna/success');
226
+ $create['gui']['layout'] = $this->_isMobile() ? 'mobile' : 'desktop';
227
+ if ($this->_getTransport()->getConfigData("enable_auto_focus")==false) {
228
+ $create['gui']['options'] = array('disable_autofocus');
229
+ }
230
+ if ($this->_getTransport()->AllowSeparateAddress()) {
231
+ $create['options']['allow_separate_shipping_address'] = true;
232
+ }
233
+ if ($this->_getTransport()->getConfigData("force_phonenumber")) {
234
+ $create['options']['phone_mandatory'] = true;
235
+ }
236
+ if ($this->_getTransport()->getConfigData("packstation_enabled")) {
237
+ $create['options']['packstation_enabled'] = true;
238
+ }
239
+
240
+ $pushUrl = Mage::getUrl('checkout/klarna/push?klarna_order={checkout.order.uri}', array('_nosid' => true));
241
+ if (substr($pushUrl, -1, 1) == '/') {
242
+ $pushUrl = substr($pushUrl, 0, strlen($pushUrl) - 1);
243
+ }
244
+
245
+ $create['merchant']['push_uri'] = $pushUrl;
246
+
247
+ $validateUrl = Mage::getUrl('checkout/klarna/validate?klarna_order={checkout.order.uri}', array('_nosid' => true));
248
+ if (substr($validateUrl, -1, 1) == '/') {
249
+ $validateUrl = substr($validateUrl, 0, strlen($validateUrl) - 1);
250
+ }
251
+ if (substr($validateUrl, 0, 5) == 'https') {
252
+ $create['merchant']['validation_uri'] = $validateUrl;
253
+ }
254
+
255
+ $create['cart']['items'] = $this->_getCartItems();
256
+
257
+ if ($data = $this->_getBillingAddressData()) {
258
+ $create['shipping_address'] = $data;
259
+ }
260
+
261
+ $this->_getTransport()->logDebugInfo('_getCreateRequest', $create);
262
+ $request = new Varien_Object($create);
263
+ Mage::dispatchEvent('klarnacheckout_get_create_request', array('request' => $request));
264
+
265
+ return $request->getData();
266
+ }
267
+
268
+ /**
269
+ * Get update request
270
+ *
271
+ * @return array
272
+ */
273
+ protected function _getUpdateRequest()
274
+ {
275
+ $update = array();
276
+ $update['cart']['items'] = $this->_getCartItems();
277
+ // $update['gui']['layout'] = 'desktop';
278
+
279
+ if ($data = $this->_getBillingAddressData()) {
280
+ $update['shipping_address'] = $data;
281
+ }
282
+
283
+ $this->_getTransport()->logDebugInfo('_getUpdateRequest', $update);
284
+ $request = new Varien_Object($update);
285
+ Mage::dispatchEvent('klarnacheckout_get_update_request', array('request' => $request));
286
+
287
+ return $request->getData();
288
+ }
289
+
290
+ protected function _getBillingAddressData()
291
+ {
292
+ if (!$this->_getTransport()->getConfigData("auto_prefil")) return NULL;
293
+
294
+ /** @var $session Mage_Customer_Model_Session */
295
+ $session = Mage::getSingleton('customer/session');
296
+ if ($session->isLoggedIn()) {
297
+ $address = $session->getCustomer()->getPrimaryBillingAddress();
298
+ $result = array(
299
+ 'email' => $session->getCustomer()->getEmail(),
300
+ 'postal_code' => $address ? $address->getPostcode() : '',
301
+ );
302
+ return $result;
303
+ }
304
+
305
+ return array();
306
+ }
307
+
308
+ public function init($klarnaSetup)
309
+ {
310
+ $this->_klarnaSetup = $klarnaSetup;
311
+ if ($this->_klarnaSetup->getHost()=='LIVE') {
312
+ Klarna_Checkout_Order::$baseUri = 'https://checkout.klarna.com/checkout/orders';
313
+ } else {
314
+ Klarna_Checkout_Order::$baseUri = 'https://checkout.testdrive.klarna.com/checkout/orders';
315
+ }
316
+ Klarna_Checkout_Order::$contentType = "application/vnd.klarna.checkout.aggregated-order-v2+json";
317
+ }
318
+
319
+ /**
320
+ * Get connector
321
+ *
322
+ * @return Klarna_Checkout_Connector
323
+ */
324
+ protected function _getConnector()
325
+ {
326
+ $secret = $this->_klarnaSetup->getSharedSecret();
327
+
328
+ if (method_exists('Mage', 'getEdition')) {
329
+ $magentoEdition = Mage::getEdition();
330
+ } else {
331
+ if (class_exists("Enterprise_UrlRewrite_Model_Redirect", false)) {
332
+ $magentoEdition = "Enterprise";
333
+ } else {
334
+ $magentoEdition = "Community";
335
+ }
336
+ }
337
+ $magentoVersion = Mage::getVersion();
338
+ $module = (string)Mage::getConfig()->getNode()->modules->Vaimo_Klarna->name;
339
+ $version = (string)Mage::getConfig()->getNode()->modules->Vaimo_Klarna->version;
340
+ $module_info = array('Application' => array(
341
+ 'name' => 'Magento ' . '_' . $magentoEdition,
342
+ 'version' => $magentoVersion),
343
+ 'Module' => array(
344
+ 'name' => $module,
345
+ 'version' => $version),
346
+ );
347
+ return Klarna_Checkout_Connector::create($secret, $module_info);
348
+ }
349
+
350
+ /**
351
+ * Get Klarna checkout order
352
+ *
353
+ * @param null $checkoutId
354
+ * @param bool $createIfNotExists
355
+ * @param bool $updateItems
356
+ * @return Klarna_Checkout_Order|null
357
+ */
358
+ public function initKlarnaOrder($checkoutId = null, $createIfNotExists = false, $updateItems = false)
359
+ {
360
+ if ($checkoutId) {
361
+ $this->_getTransport()->logKlarnaApi('initKlarnaOrder checkout id: ' . $checkoutId);
362
+ $this->_klarnaOrder = new Klarna_Checkout_Order($this->_getConnector(), $checkoutId);
363
+ $this->_klarnaOrder->fetch();
364
+ $res = $this->_klarnaOrder!=NULL;
365
+ if ($res) {
366
+ if ($this->_klarnaOrder->getLocation()) {
367
+ $this->_setKlarnaCheckoutId($this->_klarnaOrder->getLocation());
368
+ }
369
+ }
370
+ $this->_getTransport()->logKlarnaApi('initKlarnaOrder res: ' . $res);
371
+ return $res;
372
+ }
373
+
374
+ if ($klarnaCheckoutId = $this->_getKlarnaCheckoutId()) {
375
+ try {
376
+ $this->_getTransport()->logKlarnaApi('initKlarnaOrder klarnaCheckoutId id: ' . $klarnaCheckoutId);
377
+ $this->_klarnaOrder = new Klarna_Checkout_Order($this->_getConnector(), $klarnaCheckoutId);
378
+ if ($updateItems) {
379
+ $this->_klarnaOrder->update($this->_getUpdateRequest());
380
+ }
381
+ $this->_klarnaOrder->fetch();
382
+ $res = $this->_klarnaOrder!=NULL;
383
+ if ($res) {
384
+ if ($this->_klarnaOrder->getLocation()) {
385
+ $this->_setKlarnaCheckoutId($this->_klarnaOrder->getLocation());
386
+ }
387
+ }
388
+ $this->_getTransport()->logKlarnaApi('initKlarnaOrder res: ' . $res);
389
+ return $res;
390
+ } catch (Exception $e) {
391
+ // when checkout in Klarna was expired, then exception, so we just ignore and create new
392
+ $this->_getTransport()->logKlarnaException($e);
393
+ }
394
+ }
395
+
396
+ if ($createIfNotExists) {
397
+ $this->_getTransport()->logKlarnaApi('initKlarnaOrder create');
398
+ $this->_klarnaOrder = new Klarna_Checkout_Order($this->_getConnector());
399
+ $this->_klarnaOrder->create($this->_getCreateRequest());
400
+ $this->_klarnaOrder->fetch();
401
+ $res = $this->_klarnaOrder!=NULL;
402
+ if ($res) {
403
+ if ($this->_klarnaOrder->getLocation()) {
404
+ $this->_setKlarnaCheckoutId($this->_klarnaOrder->getLocation());
405
+ }
406
+ }
407
+ $this->_getTransport()->logKlarnaApi('initKlarnaOrder res: ' . $res);
408
+ return $res;
409
+ }
410
+
411
+ return false;
412
+ }
413
+
414
+ /*
415
+ * This function MUST BE DELETED, the code calling it and using the result must be
416
+ * rewritten!
417
+ *
418
+ */
419
+ public function getActualKlarnaOrder()
420
+ {
421
+ if ($this->_klarnaOrder) {
422
+ return $this->_klarnaOrder;
423
+ }
424
+ return NULL;
425
+ }
426
+
427
+ public function getKlarnaCheckoutGui()
428
+ {
429
+ if ($this->_klarnaOrder) {
430
+ if ($this->_klarnaOrder->offsetExists('gui')) {
431
+ $gui = $this->_klarnaOrder->offsetGet('gui');
432
+ return isset($gui['snippet']) ? $gui['snippet'] : '';
433
+ }
434
+ }
435
+ return '';
436
+ }
437
+
438
+ public function getKlarnaCheckoutStatus()
439
+ {
440
+ if ($this->_klarnaOrder) {
441
+ if ($this->_klarnaOrder->offsetExists('status')) {
442
+ return $this->_klarnaOrder->offsetGet('status');
443
+ }
444
+ }
445
+ return '';
446
+ }
447
+
448
+ public function loadQuote()
449
+ {
450
+ if ($this->_klarnaOrder) {
451
+ /** @var $quote Mage_Sales_Model_Quote */
452
+ $quote = Mage::getModel('sales/quote')->load($this->_klarnaOrder->getLocation(), 'klarna_checkout_id');
453
+ if ($quote->getId()) {
454
+ return $quote;
455
+ }
456
+ }
457
+ return NULL;
458
+ }
459
+
460
+ public function initVarienOrder()
461
+ {
462
+ if ($this->_klarnaOrder) {
463
+ $order = new Varien_Object($this->_klarnaOrder->marshal());
464
+ if ($order) {
465
+ return $order;
466
+ }
467
+ }
468
+ return NULL;
469
+ }
470
+
471
+ public function updateKlarnaOrder($order)
472
+ {
473
+ if ($this->_klarnaOrder) {
474
+ $this->_getTransport()->logKlarnaApi('updateKlarnaOrder order no: ' . $order->getIncrementId());
475
+ // Update Klarna
476
+ $update = array(
477
+ 'status' => 'created',
478
+ 'merchant_reference' => array('orderid1' => $order->getIncrementId()),
479
+ );
480
+
481
+ // Add extra attribute to order
482
+ $orderid2Code = trim($this->_getTransport()->getConfigData('extra_order_attribute'));
483
+ if($orderid2Code && $orderid2Code!='' && $order->getData($orderid2Code)) {
484
+ $orderid2Value = $order->getData($orderid2Code);
485
+ $update['merchant_reference']['orderid2'] = $orderid2Value;
486
+ }
487
+
488
+ $this->_klarnaOrder->update($update);
489
+ $this->_getTransport()->logKlarnaApi('updateKlarnaOrder success');
490
+ return true;
491
+ }
492
+ return false;
493
+ }
494
+
495
+ }
app/code/community/Vaimo/Klarna/Model/Api/Rest.php ADDED
@@ -0,0 +1,848 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Copyright (c) 2009-2014 Vaimo AB
4
+ *
5
+ * Vaimo reserves all rights in the Program as delivered. The Program
6
+ * or any portion thereof may not be reproduced in any form whatsoever without
7
+ * the written consent of Vaimo, except as provided by licence. A licence
8
+ * under Vaimo's rights in the Program may be available directly from
9
+ * Vaimo.
10
+ *
11
+ * Disclaimer:
12
+ * THIS NOTICE MAY NOT BE REMOVED FROM THE PROGRAM BY ANY USER THEREOF.
13
+ * THE PROGRAM IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
14
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
16
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ * OUT OF OR IN CONNECTION WITH THE PROGRAM OR THE USE OR OTHER DEALINGS
19
+ * IN THE PROGRAM.
20
+ *
21
+ * @category Vaimo
22
+ * @package Vaimo_Klarna
23
+ * @copyright Copyright (c) 2009-2014 Vaimo AB
24
+ */
25
+
26
+ class Vaimo_Klarna_Model_Api_Rest extends Vaimo_Klarna_Model_Api_Abstract
27
+ {
28
+ protected $_url = NULL;
29
+
30
+ protected $_curlHeaders;
31
+ protected $_klarnaOrder = null;
32
+ protected $_request = NULL;
33
+
34
+ public function init($klarnaSetup)
35
+ {
36
+ $this->_klarnaSetup = $klarnaSetup;
37
+ if ($this->_klarnaSetup->getHost() == 'BETA') {
38
+ $this->_url = 'https://api.playground.klarna.com';
39
+ } else {
40
+ $this->_url = 'https://api.klarna.com';
41
+ }
42
+ }
43
+
44
+ protected function _getUrl()
45
+ {
46
+ return $this->_url;
47
+ }
48
+
49
+ public function curlHeader($ch, $str)
50
+ {
51
+ $this->_getTransport()->logDebugInfo('curlHeader rest str = ' . $str);
52
+ if (strpos($str, ': ') !== false) {
53
+ list($key, $value) = explode(': ', $str, 2);
54
+ $this->_curlHeaders[$key] = trim($value);
55
+ }
56
+
57
+ return strlen($str);
58
+ }
59
+
60
+ protected function _getBillingAddressData()
61
+ {
62
+ if (!$this->_getTransport()->getConfigData("auto_prefil")) return NULL;
63
+
64
+ /** @var $session Mage_Customer_Model_Session */
65
+ $session = Mage::getSingleton('customer/session');
66
+ if ($session->isLoggedIn()) {
67
+ $address = $session->getCustomer()->getPrimaryBillingAddress();
68
+ return array(
69
+ 'email' => $session->getCustomer()->getEmail(),
70
+ 'postal_code' => $address ? $address->getPostcode() : '',
71
+ );
72
+ }
73
+
74
+ return array();
75
+ }
76
+
77
+ /**
78
+ * Get active Klarna checkout id
79
+ *
80
+ * @return string
81
+ */
82
+ protected function _getKlarnaCheckoutId()
83
+ {
84
+ return $this->_getQuote()->getKlarnaCheckoutId();
85
+ }
86
+
87
+ /**
88
+ * Put Klarna checkout id to quote
89
+ *
90
+ * @param $checkoutId string
91
+ */
92
+ protected function _setKlarnaCheckoutId($checkoutId)
93
+ {
94
+ $quote = $this->_getQuote();
95
+
96
+ if ($quote->getKlarnaCheckoutId() != $checkoutId) {
97
+ $this->_getTransport()->logDebugInfo('SET checkout id rest: ' . $checkoutId);
98
+ $this->_getTransport()->logDebugInfo('Quote Id rest: ' . $quote->getId());
99
+ $quote->setKlarnaCheckoutId($checkoutId);
100
+ $quote->save();
101
+ }
102
+
103
+ Mage::getSingleton('checkout/session')->setKlarnaCheckoutId($checkoutId);
104
+ }
105
+
106
+ protected function _getCartItems()
107
+ {
108
+ $quote = $this->_getQuote();
109
+ $items = array();
110
+ $calculator = Mage::getSingleton('tax/calculation');
111
+
112
+ foreach ($quote->getAllVisibleItems() as $quoteItem) {
113
+ if ($quoteItem->getTaxPercent() > 0) {
114
+ $taxRate = $quoteItem->getTaxPercent();
115
+ } else {
116
+ $taxRate = $quoteItem->getTaxAmount() / $quoteItem->getRowTotal() * 100;
117
+ }
118
+ $taxAmount = $calculator->calcTaxAmount($quoteItem->getRowTotalInclTax(), $taxRate, true, true);
119
+ $items[] = array(
120
+ 'type' => 'physical',
121
+ 'reference' => $quoteItem->getSku(),
122
+ 'name' => $quoteItem->getName(),
123
+ 'quantity' => round($quoteItem->getQty()),
124
+ 'quantity_unit' => 'pcs',
125
+ 'unit_price' => round($quoteItem->getPriceInclTax() * 100),
126
+ // 'discount_rate' => round($quoteItem->getDiscountPercent() * 100),
127
+ 'tax_rate' => round($taxRate * 100),
128
+ 'total_amount' => round($quoteItem->getRowTotalInclTax() * 100),
129
+ 'total_tax_amount' => round($taxAmount * 100),
130
+ );
131
+ }
132
+
133
+ foreach ($quote->getTotals() as $key => $total) {
134
+ switch ($key) {
135
+ case 'shipping':
136
+ if ($total->getValue() != 0) {
137
+ $amount = $total->getAddress()->getShippingAmount();
138
+ $taxAmount = $total->getAddress()->getShippingTaxAmount();
139
+ $hiddenTaxAmount = $total->getAddress()->getShippingHiddenTaxAmount();
140
+ $taxRate = ($taxAmount + $hiddenTaxAmount) / $amount * 100;
141
+ $items[] = array(
142
+ 'type' => 'shipping_fee',
143
+ 'reference' => $total->getCode(),
144
+ 'name' => $total->getTitle(),
145
+ 'quantity' => 1,
146
+ 'unit_price' => round(($amount + $taxAmount + $hiddenTaxAmount) * 100),
147
+ 'discount_rate' => 0,
148
+ 'tax_rate' => round($taxRate * 100),
149
+ 'total_amount' => round(($amount + $taxAmount + $hiddenTaxAmount) * 100),
150
+ 'total_tax_amount' => round($taxAmount * 100),
151
+ );
152
+ }
153
+ break;
154
+ case 'discount':
155
+ if ($total->getValue() != 0) {
156
+ // ok, this is a bit shaky here, i know...
157
+ // but i don't have discount tax anywhere but in hidden_tax_amount field :(
158
+ // and I have to send discount also with tax rate to klarna
159
+ // otherwise the total tax wouldn't match
160
+ $taxAmount = $total->getAddress()->getHiddenTaxAmount();
161
+ $amount = -$total->getAddress()->getDiscountAmount() - $taxAmount;
162
+ $taxRate = $taxAmount / $amount * 100;
163
+ $items[] = array(
164
+ 'type' => 'discount',
165
+ 'reference' => $total->getCode(),
166
+ 'name' => $total->getTitle(),
167
+ 'quantity' => 1,
168
+ 'unit_price' => -round(($amount + $taxAmount) * 100),
169
+ 'discount_rate' => 0,
170
+ 'tax_rate' => round($taxRate * 100),
171
+ 'total_amount' => -round(($amount + $taxAmount) * 100),
172
+ 'total_tax_amount' => -round($taxAmount * 100),
173
+ );
174
+ }
175
+ break;
176
+ case 'giftcardaccount':
177
+ if ($total->getValue() != 0) {
178
+ $items[] = array(
179
+ 'type' => 'discount',
180
+ 'reference' => $total->getCode(),
181
+ 'name' => $total->getTitle(),
182
+ 'quantity' => 1,
183
+ 'unit_price' => round($total->getValue() * 100),
184
+ 'discount_rate' => 0,
185
+ 'tax_rate' => 0,
186
+ 'total_amount' => round($total->getValue() * 100),
187
+ 'total_tax_amount' => 0,
188
+ );
189
+ }
190
+ break;
191
+ case 'ugiftcert':
192
+ if ($total->getValue() != 0) {
193
+ $items[] = array(
194
+ 'type' => 'discount',
195
+ 'reference' => $total->getCode(),
196
+ 'name' => $total->getTitle(),
197
+ 'quantity' => 1,
198
+ 'unit_price' => -round($total->getValue() * 100),
199
+ 'discount_rate' => 0,
200
+ 'tax_rate' => 0,
201
+ 'total_amount' => round($total->getValue() * 100),
202
+ 'total_tax_amount' => 0,
203
+ );
204
+ }
205
+ break;
206
+ case 'reward':
207
+ if ($total->getValue() != 0) {
208
+ $items[] = array(
209
+ 'type' => 'discount',
210
+ 'reference' => $total->getCode(),
211
+ 'name' => $total->getTitle(),
212
+ 'quantity' => 1,
213
+ 'unit_price' => round($total->getValue() * 100),
214
+ 'discount_rate' => 0,
215
+ 'tax_rate' => 0,
216
+ 'total_amount' => round($total->getValue() * 100),
217
+ 'total_tax_amount' => 0,
218
+ );
219
+ }
220
+ break;
221
+ case 'customerbalance':
222
+ if ($total->getValue() != 0) {
223
+ $items[] = array(
224
+ 'type' => 'discount',
225
+ 'reference' => $total->getCode(),
226
+ 'name' => $total->getTitle(),
227
+ 'quantity' => 1,
228
+ 'unit_price' => round($total->getValue() * 100),
229
+ 'discount_rate' => 0,
230
+ 'tax_rate' => 0,
231
+ 'total_amount' => round($total->getValue() * 100),
232
+ 'total_tax_amount' => 0,
233
+ );
234
+ }
235
+ break;
236
+ }
237
+ }
238
+
239
+ return $items;
240
+ }
241
+
242
+ protected function _getCreateRequest()
243
+ {
244
+ $create = array();
245
+ if (version_compare(Mage::getVersion(), '1.6.2', '>=')) {
246
+ $create['purchase_country'] = Mage::helper('core')->getDefaultCountry();
247
+ } else {
248
+ $create['purchase_country'] = Mage::getStoreConfig('general/country/default');
249
+ }
250
+ $create['purchase_currency'] = $this->_getQuote()->getQuoteCurrencyCode();
251
+ $create['locale'] = str_replace('_', '-', Mage::app()->getLocale()->getLocaleCode());
252
+
253
+ $create['gui']['layout'] = $this->_isMobile() ? 'mobile' : 'desktop';
254
+ if ($this->_getTransport()->getConfigData("enable_auto_focus")==false) {
255
+ $create['gui']['options'] = array('disable_autofocus');
256
+ }
257
+ if ($this->_getTransport()->AllowSeparateAddress()) {
258
+ $create['options']['allow_separate_shipping_address'] = true;
259
+ }
260
+ if ($this->_getTransport()->getConfigData("force_phonenumber")) {
261
+ $create['options']['phone_mandatory'] = true;
262
+ }
263
+ if ($this->_getTransport()->getConfigData("packstation_enabled")) {
264
+ $create['options']['packstation_enabled'] = true;
265
+ }
266
+
267
+
268
+ if ($data = $this->_getBillingAddressData()) {
269
+ $create['billing_address'] = $data;
270
+ }
271
+
272
+ $create['order_amount'] = round($this->_getQuote()->getGrandTotal() * 100);
273
+ $create['order_tax_amount'] = 0;
274
+ $create['order_lines'] = $this->_getCartItems();
275
+
276
+ foreach ($create['order_lines'] as $line) {
277
+ $create['order_tax_amount'] += $line['total_tax_amount'];
278
+ }
279
+
280
+ $pushUrl = Mage::getUrl('checkout/klarna/push?klarna_order={checkout.order.uri}', array('_nosid' => true));
281
+ if (substr($pushUrl, -1, 1) == '/') {
282
+ $pushUrl = substr($pushUrl, 0, strlen($pushUrl) - 1);
283
+ }
284
+
285
+ $create['merchant_urls']['terms'] = Mage::getUrl(Mage::getStoreConfig('payment/vaimo_klarna_checkout/terms_url'));
286
+ $create['merchant_urls']['checkout'] = Mage::getUrl('checkout/klarna');
287
+ $create['merchant_urls']['confirmation'] = Mage::getUrl('checkout/klarna/success');
288
+ $create['merchant_urls']['push'] = $pushUrl;
289
+
290
+ $validateUrl = Mage::getUrl('checkout/klarna/validate?klarna_order={checkout.order.uri}', array('_nosid' => true));
291
+ if (substr($validateUrl, -1, 1) == '/') {
292
+ $validateUrl = substr($validateUrl, 0, strlen($validateUrl) - 1);
293
+ }
294
+ if (substr($validateUrl, 0, 5) == 'https') {
295
+ $create['merchant']['validation_uri'] = $validateUrl;
296
+ }
297
+
298
+ $this->_getTransport()->logDebugInfo('_getCreateRequest rest', $create);
299
+
300
+ $request = new Varien_Object($create);
301
+ Mage::dispatchEvent('klarnacheckout_get_create_request', array('request' => $request));
302
+
303
+ return $request->getData();
304
+ }
305
+
306
+ protected function _getUpdateRequest()
307
+ {
308
+ $update = array();
309
+
310
+ if ($data = $this->_getBillingAddressData()) {
311
+ $update['billing_address'] = $data;
312
+ }
313
+
314
+ $update['order_amount'] = round($this->_getQuote()->getGrandTotal() * 100);
315
+ $update['order_tax_amount'] = 0;
316
+ $update['order_lines'] = $this->_getCartItems();
317
+
318
+ foreach ($update['order_lines'] as $line) {
319
+ $update['order_tax_amount'] += $line['total_tax_amount'];
320
+ }
321
+
322
+ $this->_getTransport()->logDebugInfo('_getUpdateRequest rest', $update);
323
+
324
+ $request = new Varien_Object($update);
325
+ Mage::dispatchEvent('klarnacheckout_get_update_request', array('request' => $request));
326
+
327
+ return $request->getData();
328
+ }
329
+
330
+ protected function _createOrder()
331
+ {
332
+ $this->_curlHeaders = array();
333
+
334
+ $request = $this->_getCreateRequest();
335
+
336
+ $ch = curl_init();
337
+ curl_setopt($ch, CURLOPT_URL, $this->_getUrl() . '/checkout/v3/orders');
338
+ curl_setopt($ch, CURLOPT_USERPWD, $this->_getTransport()->getConfigData('merchant_id') . ':' . $this->_getTransport()->getConfigData('shared_secret'));
339
+ curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
340
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
341
+ curl_setopt($ch, CURLOPT_HEADERFUNCTION, array($this, 'curlHeader'));
342
+ curl_setopt($ch, CURLOPT_HEADER, true);
343
+ curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
344
+ curl_setopt($ch, CURLOPT_POST, true);
345
+ curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($request));
346
+ $response = curl_exec($ch);
347
+ $status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
348
+ curl_close($ch);
349
+
350
+ if ($status != 201) {
351
+ Mage::throwException('Error creating order: ' . $status);
352
+ }
353
+
354
+ $this->_getTransport()->logDebugInfo('_createOrder rest response = ' . $response . ' status = ' . $status);
355
+
356
+ if (isset($this->_curlHeaders['Location'])) {
357
+ return $this->_curlHeaders['Location'];
358
+ }
359
+
360
+ return false;
361
+ }
362
+
363
+ protected function _fetchOrder($location)
364
+ {
365
+ $ch = curl_init();
366
+ curl_setopt($ch, CURLOPT_URL, $location);
367
+ curl_setopt($ch, CURLOPT_USERPWD, $this->_getTransport()->getConfigData('merchant_id') . ':' . $this->_getTransport()->getConfigData('shared_secret'));
368
+ curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
369
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
370
+ curl_setopt($ch, CURLOPT_HEADERFUNCTION, array($this, 'curlHeader'));
371
+ curl_setopt($ch, CURLOPT_HEADER, false);
372
+ $response = curl_exec($ch);
373
+ $status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
374
+ curl_close($ch);
375
+
376
+ if ($status != 200) {
377
+ Mage::throwException('Error fetching order: ' . $status);
378
+ }
379
+
380
+ $this->_getTransport()->logDebugInfo('_fetchOrder rest response = ' . $response . ' status = ' . $status);
381
+
382
+ $this->_klarnaOrder = new Varien_Object(json_decode($response, true));
383
+ $this->_klarnaOrder->setLocation($location);
384
+ }
385
+
386
+ protected function _updateOrder($location)
387
+ {
388
+ $ch = curl_init();
389
+ curl_setopt($ch, CURLOPT_URL, $location);
390
+ curl_setopt($ch, CURLOPT_USERPWD, $this->_getTransport()->getConfigData('merchant_id') . ':' . $this->_getTransport()->getConfigData('shared_secret'));
391
+ curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
392
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
393
+ curl_setopt($ch, CURLOPT_HEADERFUNCTION, array($this, 'curlHeader'));
394
+ curl_setopt($ch, CURLOPT_HEADER, false);
395
+ curl_setopt($ch, CURLOPT_POST, true);
396
+ curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($this->_getCreateRequest()));
397
+ curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
398
+ $response = curl_exec($ch);
399
+ $status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
400
+ curl_close($ch);
401
+
402
+ if ($status != 200) {
403
+ Mage::throwException('Error updating order: ' . $status);
404
+ }
405
+
406
+ $this->_getTransport()->logDebugInfo('_updateOrder rest response = ' . $response . ' status = ' . $status);
407
+
408
+ $this->_klarnaOrder = new Varien_Object(json_decode($response, true));
409
+ $this->_klarnaOrder->setLocation($location);
410
+ }
411
+
412
+ protected function _retrieveOrder($orderId)
413
+ {
414
+ $ch = curl_init();
415
+ curl_setopt($ch, CURLOPT_URL, $this->_getUrl() . '/ordermanagement/v1/orders/' . $orderId);
416
+ curl_setopt($ch, CURLOPT_USERPWD, $this->_getTransport()->getConfigData('merchant_id') . ':' . $this->_getTransport()->getConfigData('shared_secret'));
417
+ curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
418
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
419
+ curl_setopt($ch, CURLOPT_HEADERFUNCTION, array($this, 'curlHeader'));
420
+ curl_setopt($ch, CURLOPT_HEADER, false);
421
+ $response = curl_exec($ch);
422
+ $status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
423
+ curl_close($ch);
424
+
425
+ $this->_getTransport()->logDebugInfo('_retrieveOrder rest response = ' . $response . ' status = ' . $status);
426
+
427
+ return new Varien_Object(json_decode($response, true));
428
+ }
429
+
430
+ protected function _acknowledgeOrder($orderId)
431
+ {
432
+ $ch = curl_init();
433
+ curl_setopt($ch, CURLOPT_URL, $this->_getUrl() . '/ordermanagement/v1/orders/' . $orderId . '/acknowledge');
434
+ curl_setopt($ch, CURLOPT_USERPWD, $this->_getTransport()->getConfigData('merchant_id') . ':' . $this->_getTransport()->getConfigData('shared_secret'));
435
+ curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
436
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
437
+ curl_setopt($ch, CURLOPT_HEADERFUNCTION, array($this, 'curlHeader'));
438
+ curl_setopt($ch, CURLOPT_HEADER, false);
439
+ curl_setopt($ch, CURLOPT_POST, true);
440
+ curl_setopt($ch, CURLOPT_POSTFIELDS, '{}');
441
+ curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
442
+ $response = curl_exec($ch);
443
+ $status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
444
+ curl_close($ch);
445
+
446
+ $this->_getTransport()->logDebugInfo('_acknowledgeOrder rest response = ' . $response . ' status = ' . $status);
447
+ }
448
+
449
+ protected function _updateMerchantReferences($orderId, $reference1, $reference2 = null)
450
+ {
451
+ $request = array(
452
+ 'merchant_reference1' => $reference1
453
+ );
454
+
455
+ if ($reference2) {
456
+ $request['merchant_reference2'] = $reference2;
457
+ }
458
+
459
+ $ch = curl_init();
460
+ curl_setopt($ch, CURLOPT_URL, $this->_getUrl() . '/ordermanagement/v1/orders/' . $orderId . '/merchant-references');
461
+ curl_setopt($ch, CURLOPT_USERPWD, $this->_getTransport()->getConfigData('merchant_id') . ':' . $this->_getTransport()->getConfigData('shared_secret'));
462
+ curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
463
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
464
+ curl_setopt($ch, CURLOPT_HEADERFUNCTION, array($this, 'curlHeader'));
465
+ curl_setopt($ch, CURLOPT_HEADER, false);
466
+ curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PATCH');
467
+ curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($request));
468
+ curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
469
+ $response = curl_exec($ch);
470
+ $status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
471
+ curl_close($ch);
472
+
473
+ $this->_getTransport()->logDebugInfo('_updateMerchantReferences rest response = ' . $response . ' status = ' . $status);
474
+ }
475
+
476
+ public function capture($orderId, $amount, $sendEmailf)
477
+ {
478
+ $ch = curl_init();
479
+ curl_setopt($ch, CURLOPT_URL, $this->_getUrl() . '/ordermanagement/v1/orders/' . $orderId . '/captures');
480
+ curl_setopt($ch, CURLOPT_USERPWD, $this->_getTransport()->getConfigData('merchant_id') . ':' . $this->_getTransport()->getConfigData('shared_secret'));
481
+ curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
482
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
483
+ curl_setopt($ch, CURLOPT_HEADERFUNCTION, array($this, 'curlHeader'));
484
+ curl_setopt($ch, CURLOPT_HEADER, false);
485
+ curl_setopt($ch, CURLOPT_POST, true);
486
+ curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($this->_request));
487
+ curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
488
+ $response = curl_exec($ch);
489
+ $status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
490
+ curl_close($ch);
491
+
492
+ $this->_getTransport()->logDebugInfo('capture rest response = ' . $response . ' status = ' . $status);
493
+
494
+ if ($status != 201) {
495
+ $response = json_decode($response, true);
496
+ $message = 'Error capturing order: ' . $status;
497
+ if (isset($response['error_code'])) {
498
+ $message .= '; Code: ' . $response['error_code'];
499
+ }
500
+ if (isset($response['error_messages']) && is_array($response['error_messages'])) {
501
+ foreach ($response['error_messages'] as $value) {
502
+ $message .= '; ' . $value;
503
+ }
504
+ }
505
+ Mage::throwException($message);
506
+ }
507
+
508
+ $location = "";
509
+ $capture_id = "";
510
+ if (isset($this->_curlHeaders['Location'])) {
511
+ $location = $this->_curlHeaders['Location'];
512
+ $parts = explode('/', $location);
513
+ $prev_part = "";
514
+ foreach ($parts as $part) {
515
+ if ($prev_part=='captures') {
516
+ $capture_id = $part;
517
+ break;
518
+ }
519
+ $prev_part = $part;
520
+ }
521
+ }
522
+
523
+ $res = array(
524
+ Vaimo_Klarna_Helper_Data::KLARNA_API_RESPONSE_STATUS => $status,
525
+ Vaimo_Klarna_Helper_Data::KLARNA_API_RESPONSE_TRANSACTION_ID => $orderId,
526
+ Vaimo_Klarna_Helper_Data::KLARNA_API_RESPONSE_KCO_CAPTURE_ID => $capture_id,
527
+ );
528
+ return $res;
529
+ }
530
+
531
+ public function refund($amount, $reservation_no)
532
+ {
533
+ $tmp = explode('/', $reservation_no);
534
+ if (sizeof($tmp)>0) {
535
+ $orderId = $tmp[0];
536
+ } else {
537
+ $orderId = $reservation_no;
538
+ }
539
+ $this->_setGoodsListRefund($amount);
540
+ $ch = curl_init();
541
+ curl_setopt($ch, CURLOPT_URL, $this->_getUrl() . '/ordermanagement/v1/orders/' . $orderId . '/refunds');
542
+ curl_setopt($ch, CURLOPT_USERPWD, $this->_getTransport()->getConfigData('merchant_id') . ':' . $this->_getTransport()->getConfigData('shared_secret'));
543
+ curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
544
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
545
+ curl_setopt($ch, CURLOPT_HEADERFUNCTION, array($this, 'curlHeader'));
546
+ curl_setopt($ch, CURLOPT_HEADER, false);
547
+ curl_setopt($ch, CURLOPT_POST, true);
548
+ curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($this->_request));
549
+ curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
550
+ $response = curl_exec($ch);
551
+ $status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
552
+ curl_close($ch);
553
+
554
+ $this->_getTransport()->logDebugInfo('refund rest response = ' . $response . ' status = ' . $status);
555
+
556
+ if ($status != 204) {
557
+ $response = json_decode($response, true);
558
+ $message = 'Error refunding order: ' . $status;
559
+ if (isset($response['error_code'])) {
560
+ $message .= '; Code: ' . $response['error_code'];
561
+ }
562
+ if (isset($response['error_messages']) && is_array($response['error_messages'])) {
563
+ foreach ($response['error_messages'] as $value) {
564
+ $message .= '; ' . $value;
565
+ }
566
+ }
567
+ Mage::throwException($message);
568
+ }
569
+ $res = array(
570
+ Vaimo_Klarna_Helper_Data::KLARNA_API_RESPONSE_STATUS => $status,
571
+ Vaimo_Klarna_Helper_Data::KLARNA_API_RESPONSE_TRANSACTION_ID => $reservation_no,
572
+ );
573
+ return $res;
574
+ }
575
+
576
+ /**
577
+ * Cancel an authorized order. For a cancellation to be successful, there must be no captures on the order.
578
+ * The authorized amount will be released and no further updates to the order will be allowed.
579
+ *
580
+ * @param $orderId
581
+ */
582
+ public function cancel($orderId)
583
+ {
584
+ $ch = curl_init();
585
+ curl_setopt($ch, CURLOPT_URL, $this->_getUrl() . '/ordermanagement/v1/orders/' . $orderId . '/cancel');
586
+ curl_setopt($ch, CURLOPT_USERPWD, $this->_getTransport()->getConfigData('merchant_id') . ':' . $this->_getTransport()->getConfigData('shared_secret'));
587
+ curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
588
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
589
+ curl_setopt($ch, CURLOPT_HEADERFUNCTION, array($this, 'curlHeader'));
590
+ curl_setopt($ch, CURLOPT_HEADER, false);
591
+ curl_setopt($ch, CURLOPT_POST, true);
592
+ curl_setopt($ch, CURLOPT_POSTFIELDS, '{}');
593
+ curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
594
+ $response = curl_exec($ch);
595
+ $status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
596
+ curl_close($ch);
597
+
598
+ $this->_getTransport()->logDebugInfo('cancel rest response = ' . $response . ' status = ' . $status);
599
+
600
+ if ($status != 204) {
601
+ $response = json_decode($response, true);
602
+ $message = 'Error canceling order: ' . $status;
603
+ if (isset($response['error_code'])) {
604
+ $message .= '; Code: ' . $response['error_code'];
605
+ }
606
+ if (isset($response['error_messages']) && is_array($response['error_messages'])) {
607
+ foreach ($response['error_messages'] as $value) {
608
+ $message .= '; ' . $value;
609
+ }
610
+ }
611
+ Mage::throwException($message);
612
+ }
613
+ $res = array(
614
+ Vaimo_Klarna_Helper_Data::KLARNA_API_RESPONSE_STATUS => $status,
615
+ Vaimo_Klarna_Helper_Data::KLARNA_API_RESPONSE_TRANSACTION_ID => $orderId,
616
+ );
617
+ return $res;
618
+ }
619
+
620
+ /**
621
+ * Signal that there is no intention to perform further captures.
622
+ *
623
+ * @param $orderId
624
+ */
625
+ public function release($orderId)
626
+ {
627
+ $ch = curl_init();
628
+ curl_setopt($ch, CURLOPT_URL, $this->_getUrl() . '/ordermanagement/v1/orders/' . $orderId . '/release-remaining-authorization');
629
+ curl_setopt($ch, CURLOPT_USERPWD, $this->_getTransport()->getConfigData('merchant_id') . ':' . $this->_getTransport()->getConfigData('shared_secret'));
630
+ curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
631
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
632
+ curl_setopt($ch, CURLOPT_HEADERFUNCTION, array($this, 'curlHeader'));
633
+ curl_setopt($ch, CURLOPT_HEADER, false);
634
+ curl_setopt($ch, CURLOPT_POST, true);
635
+ curl_setopt($ch, CURLOPT_POSTFIELDS, '{}');
636
+ curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
637
+ $response = curl_exec($ch);
638
+ $status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
639
+ curl_close($ch);
640
+
641
+ $this->_getTransport()->logDebugInfo('release rest response = ' . $response . ' status = ' . $status);
642
+
643
+ if ($status != 204) {
644
+ $response = json_decode($response, true);
645
+ $message = 'Error canceling order: ' . $status;
646
+ if (isset($response['error_code'])) {
647
+ $message .= '; Code: ' . $response['error_code'];
648
+ }
649
+ if (isset($response['error_messages']) && is_array($response['error_messages'])) {
650
+ foreach ($response['error_messages'] as $value) {
651
+ $message .= '; ' . $value;
652
+ }
653
+ }
654
+ Mage::throwException($message);
655
+ }
656
+ $res = array(
657
+ Vaimo_Klarna_Helper_Data::KLARNA_API_RESPONSE_STATUS => $status,
658
+ Vaimo_Klarna_Helper_Data::KLARNA_API_RESPONSE_TRANSACTION_ID => $orderId,
659
+ );
660
+ return $res;
661
+ }
662
+
663
+ public function initKlarnaOrder($checkoutId = null, $createIfNotExists = false, $updateItems = false)
664
+ {
665
+ if ($checkoutId) {
666
+ $this->_getTransport()->logKlarnaApi('initKlarnaOrder rest checkout id: ' . $checkoutId);
667
+ $this->_fetchOrder($checkoutId);
668
+ $res = $this->_klarnaOrder!=NULL;
669
+ if ($res) {
670
+ if ($this->_klarnaOrder->getLocation()) {
671
+ $this->_setKlarnaCheckoutId($this->_klarnaOrder->getLocation());
672
+ }
673
+ }
674
+ $this->_getTransport()->logKlarnaApi('initKlarnaOrder rest true');
675
+ return $res;
676
+ }
677
+
678
+ if ($klarnaCheckoutId = $this->_getKlarnaCheckoutId()) {
679
+ try {
680
+ $this->_getTransport()->logKlarnaApi('initKlarnaOrder rest klarnaCheckoutId id: ' . $klarnaCheckoutId);
681
+ if ($updateItems) {
682
+ $this->_updateOrder($klarnaCheckoutId);
683
+ } else {
684
+ $this->_fetchOrder($klarnaCheckoutId);
685
+ }
686
+ $res = $this->_klarnaOrder!=NULL;
687
+ if ($res) {
688
+ if ($this->_klarnaOrder->getLocation()) {
689
+ $this->_setKlarnaCheckoutId($this->_klarnaOrder->getLocation());
690
+ }
691
+ }
692
+ $this->_getTransport()->logKlarnaApi('initKlarnaOrder rest true');
693
+ return $res;
694
+ } catch (Exception $e) {
695
+ // when checkout in Klarna was expired, then exception, so we just ignore and create new
696
+ $this->_getTransport()->logKlarnaException($e);
697
+ }
698
+ }
699
+
700
+ if ($createIfNotExists) {
701
+ if ($location = $this->_createOrder()) {
702
+ $this->_fetchOrder($location);
703
+ $res = $this->_klarnaOrder!=NULL;
704
+ if ($res) {
705
+ if ($this->_klarnaOrder->getLocation()) {
706
+ $this->_setKlarnaCheckoutId($location);
707
+ }
708
+ }
709
+ return $res;
710
+ }
711
+ }
712
+
713
+ return false;
714
+ }
715
+
716
+ public function getKlarnaCheckoutGui()
717
+ {
718
+ if ($this->_klarnaOrder) {
719
+ return $this->_klarnaOrder->getHtmlSnippet();
720
+ }
721
+
722
+ return '';
723
+ }
724
+
725
+ public function getKlarnaCheckoutStatus()
726
+ {
727
+ if ($this->_klarnaOrder) {
728
+ return $this->_klarnaOrder->getStatus();
729
+ }
730
+
731
+ return '';
732
+ }
733
+
734
+ public function loadQuote()
735
+ {
736
+ if ($this->_klarnaOrder) {
737
+ /** @var $quote Mage_Sales_Model_Quote */
738
+ $quote = Mage::getModel('sales/quote')->load($this->_klarnaOrder->getLocation(), 'klarna_checkout_id');
739
+ if ($quote->getId()) {
740
+ return $quote;
741
+ }
742
+ }
743
+ return NULL;
744
+ }
745
+
746
+ public function initVarienOrder()
747
+ {
748
+ if ($this->_klarnaOrder) {
749
+ $order = $this->_retrieveOrder($this->_klarnaOrder->getOrderId());
750
+ $this->_klarnaOrder->setKlarnaReference($order->getKlarnaReference());
751
+ }
752
+ return $this->_klarnaOrder;
753
+ }
754
+
755
+ /**
756
+ * @param Mage_Sales_Model_Order $order
757
+ * @return bool
758
+ */
759
+ public function updateKlarnaOrder($order)
760
+ {
761
+ if ($this->_klarnaOrder) {
762
+ $this->_getTransport()->logKlarnaApi('updateKlarnaOrder rest order no: ' . $order->getIncrementId());
763
+ $this->_acknowledgeOrder($this->_klarnaOrder->getOrderId());
764
+ $this->_updateMerchantReferences($this->_klarnaOrder->getOrderId(), $order->getIncrementId());
765
+ $this->_getTransport()->logKlarnaApi('updateKlarnaOrder rest success');
766
+ return true;
767
+ }
768
+
769
+ return false;
770
+ }
771
+
772
+ protected function _setRequestList()
773
+ {
774
+ $default = array(
775
+ "qty" => 0,
776
+ "sku" => "",
777
+ "name" => "",
778
+ "price" => 0,
779
+ "total_amount" => 0,
780
+ "total_tax_amount" => 0,
781
+ "tax" => 0,
782
+ "discount" => 0,
783
+ "quantity_unit" => 'pcs',
784
+ );
785
+
786
+ foreach ($this->_getTransport()->getGoodsList() as $array) {
787
+ $values = array_merge($default, array_filter($array));
788
+ $this->_request['order_lines'][] = array(
789
+ 'reference' => $values["sku"],
790
+ 'type' => 'physical',
791
+ 'name' => $values["name"],
792
+ 'unit_price' => round($values["price"] * 100),
793
+ 'quantity' => round($values["qty"]),
794
+ 'total_amount' => round($values["total_amount"] * 100),
795
+ 'tax_rate' => round($values["tax"] * 100),
796
+ 'total_tax_amount' => round($values["total_tax_amount"] * 100),
797
+ 'quantity_unit' => $values["quantity_unit"],
798
+ );
799
+ }
800
+ foreach ($this->_getTransport()->getExtras() as $array) {
801
+ $values = array_merge($default, array_filter($array));
802
+ $this->_request['order_lines'][] = array(
803
+ 'reference' => $values["sku"],
804
+ 'type' => 'physical',
805
+ 'name' => $values["name"],
806
+ 'unit_price' => round($values["price"] * 100),
807
+ 'quantity' => round($values["qty"]),
808
+ 'total_amount' => round($values["total_amount"] * 100),
809
+ 'tax_rate' => round($values["tax"] * 100),
810
+ 'total_tax_amount' => round($values["total_tax_amount"] * 100),
811
+ 'quantity_unit' => $values["quantity_unit"],
812
+ );
813
+ }
814
+ }
815
+
816
+ /**
817
+ * Set the goods list for Capture
818
+ * Klarna seems to switch the order of the items in capture, so we simply add them backwards.
819
+ *
820
+ * @return void
821
+ */
822
+ public function setGoodsListCapture($amount)
823
+ {
824
+ $this->_request = array(
825
+ 'captured_amount' => round($amount * 100),
826
+ );
827
+
828
+ $this->_setRequestList();
829
+ }
830
+
831
+ /**
832
+ * Set the goods list for Refund
833
+ *
834
+ * @return void
835
+ */
836
+ protected function _setGoodsListRefund($amount)
837
+ {
838
+ $this->_request = array(
839
+ 'refunded_amount' => round($amount * 100),
840
+ );
841
+
842
+ $this->_setRequestList();
843
+ }
844
+
845
+ public function setAddresses($billingAddress, $shippingAddress, $data)
846
+ {
847
+ }
848
+ }
app/code/community/Vaimo/Klarna/Model/{Klarna/Api.php → Api/Xmlrpc.php} RENAMED
@@ -23,30 +23,18 @@
23
  * @copyright Copyright (c) 2009-2014 Vaimo AB
24
  */
25
 
26
- /*
27
- *
28
- * This is the only file in the module that loads and uses the Klarna library folder
29
- * It should never be instantiated by itself, it can, but for readability one should not
30
- * No Klarna specific variables, constants or functions should be used outside this class
31
- *
32
- */
33
  require_once Mage::getBaseDir('lib') . '/Klarna/transport/xmlrpc-3.0.0.beta/lib/xmlrpc.inc';
34
  require_once Mage::getBaseDir('lib') . '/Klarna/Klarna.php';
35
  require_once Mage::getBaseDir('lib') . '/Klarna/pclasses/mysqlstorage.class.php';
36
 
37
 
38
- class Vaimo_Klarna_Model_Klarna_Api extends Vaimo_Klarna_Model_Klarna_Tools_Api
39
  {
40
  protected $_klarnaApi = NULL;
41
 
42
- protected static $_session_key = 'klarna_address';
43
-
44
- public function __construct($klarnaApi = null, $payment = null)
45
  {
46
  parent::__construct();
47
- $this->_setFunctionName('api');
48
-
49
- $this->_payment = $payment;
50
 
51
  $this->_klarnaApi = $klarnaApi;
52
  if ($this->_klarnaApi == null) {
@@ -55,26 +43,485 @@ class Vaimo_Klarna_Model_Klarna_Api extends Vaimo_Klarna_Model_Klarna_Tools_Api
55
  }
56
 
57
  /**
58
- * Init funcition
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
59
  *
60
- * @todo If storeid is null, we need to find first store where Klarna is active, not just trust that default store has it active...
 
 
61
  */
62
- protected function _init($functionName)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
63
  {
64
- $this->_setFunctionName($this->_getFunctionName() . '-' . $functionName);
65
- $klarnaSetup = $this->getKlarnaSetup();
66
- $host = $klarnaSetup->getHost();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
67
  if ($host == 'LIVE') {
68
  $mode = Klarna::LIVE;
69
  } else {
70
  $mode = Klarna::BETA;
71
  }
72
  $this->_klarnaApi->config(
73
- $klarnaSetup->getMerchantId(),
74
- $this->_getConfigData("shared_secret"),
75
- $klarnaSetup->getCountryCode(),
76
- $klarnaSetup->getLanguageCode(),
77
- $klarnaSetup->getCurrencyCode(),
78
  $mode, // Live / Beta
79
  'mysql', // pcStorage
80
  $this->_getPCURI(), // pclasses.json
@@ -97,24 +544,16 @@ class Vaimo_Klarna_Model_Klarna_Api extends Vaimo_Klarna_Model_Klarna_Tools_Api
97
  $this->_klarnaApi->setVersion('PHP_' . 'Magento ' . $magentoEdition . '_' . $magentoVersion . '_' . $module . '_' . $version);
98
  }
99
 
100
- public function reserve($amount)
101
  {
102
  try {
103
- $this->_init('reserveAmount');
104
- $this->_setAdditionalInformation($this->getPayment()->getAdditionalInformation());
105
- $items = $this->getPayment()->getKlarnaItemList();
106
- $this->_createGoodsList($items);
107
- $this->_setGoodsListReserve();
108
- $this->_setAddresses();
109
- $this->_logKlarnaApi('Call with personal ID ' . $this->_getPNO());
110
-
111
- $this->_klarnaApi->setEstoreInfo($this->getOrder()->getIncrementId());
112
  $result = $this->_klarnaApi->reserveAmount(
113
- $this->_getPNO(),
114
- $this->_getGender(),
115
- $this->getOrder()->getTotalDue(),
116
  KlarnaFlags::NO_FLAG,
117
- $this->_getPaymentPlan()
118
  );
119
 
120
  $res = array(
@@ -122,475 +561,225 @@ class Vaimo_Klarna_Model_Klarna_Api extends Vaimo_Klarna_Model_Klarna_Tools_Api
122
  Vaimo_Klarna_Helper_Data::KLARNA_API_RESPONSE_STATUS => $this->_klarnaReservationStatusToCode($result[1])
123
  );
124
 
125
- $this->_logKlarnaApi('Response ' . $res[Vaimo_Klarna_Helper_Data::KLARNA_API_RESPONSE_STATUS] . ' - ' . $res[Vaimo_Klarna_Helper_Data::KLARNA_API_RESPONSE_TRANSACTION_ID]);
126
- if ($res[Vaimo_Klarna_Helper_Data::KLARNA_API_RESPONSE_STATUS]==Vaimo_Klarna_Helper_Data::KLARNA_STATUS_PENDING) {
127
- if ($this->_getConfigData("pending_status_action")) {
128
- $this->cancel($res[Vaimo_Klarna_Helper_Data::KLARNA_API_RESPONSE_TRANSACTION_ID]);
129
- Mage::throwException(Mage::helper('klarna')->__('Unable to pay with Klarna, please choose another payment method'));
130
- }
131
- }
132
-
133
- $this->_sendMethodEvent('vaimo_paymentmethod_order_reserved', $this->getOrder()->getTotalDue());
134
-
135
- $this->_cleanAdditionalInfo();
136
-
137
  } catch (KlarnaException $e) {
138
- $this->_logKlarnaApi('Response Error Code = ' . $e->getCode());
139
- $this->logKlarnaException($e);
140
- Mage::throwException($this->_decode($e->getMessage()));
141
  }
142
  return $res;
143
  }
144
 
145
- public function capture($amount)
146
  {
147
  try {
148
- $this->_init('capture');
149
- $this->_setAdditionalInformation($this->getPayment()->getAdditionalInformation());
150
- $items = $this->getPayment()->getKlarnaItemList();
151
- $this->_createGoodsList($items);
152
- $this->_setGoodsListCapture();
153
- $this->_setAddresses();
154
-
155
- $rno = $this->_getAdditionalInformation(Vaimo_Klarna_Helper_Data::KLARNA_INFO_FIELD_RESERVATION_ID);
156
- $this->_logKlarnaApi('Call with reservation ID ' . $rno);
157
-
158
- $this->_klarnaApi->setEstoreInfo($this->getOrder()->getIncrementId());
159
- $this->_klarnaApi->setActivateInfo('orderid1', strval($this->getOrder()->getIncrementId()));
160
 
161
  $ocr = NULL;
162
- $flags = $this->_setCaptureFlags();
163
 
164
- $result = $this->_klarnaApi->activate($rno, $ocr, $flags);
165
 
166
  $res = array(
167
  Vaimo_Klarna_Helper_Data::KLARNA_API_RESPONSE_STATUS => $result[0],
168
- Vaimo_Klarna_Helper_Data::KLARNA_API_RESPONSE_TRANSACTION_ID => $result[1],
169
- Vaimo_Klarna_Helper_Data::KLARNA_API_RESPONSE_FEE_CAPTURED => $this->_feeAmountIncluded()
170
  );
171
-
172
- $this->_sendMethodEvent('vaimo_paymentmethod_order_captured', $this->getOrder()->getTotalDue());
173
-
174
- $this->_logKlarnaApi('Response ' . $res[Vaimo_Klarna_Helper_Data::KLARNA_API_RESPONSE_STATUS] . ' - ' . $res[Vaimo_Klarna_Helper_Data::KLARNA_API_RESPONSE_TRANSACTION_ID]);
175
  } catch (KlarnaException $e) {
176
- $this->_logKlarnaApi('Response Error Code = ' . $e->getCode());
177
- $this->logKlarnaException($e);
178
- Mage::throwException($this->_decode($e->getMessage()));
179
  }
180
  return $res;
181
  }
182
 
183
- public function refund($amount)
184
  {
185
  try {
186
- $this->_init('refund');
187
- $invno = $this->getInfoInstance()->getParentTransactionId();
188
- $this->_setAdditionalInformation($this->getInfoInstance()->getAdditionalInformation());
189
- $items = $this->getPayment()->getKlarnaItemList();
190
- $this->_createRefundGoodsList($items);
191
-
192
- switch ($this->_decideRefundMethod($amount)) {
193
- case self::REFUND_METHOD_FULL:
194
- $this->_logKlarnaApi('Full with invoice ID ' . $invno);
195
- $result = $this->_klarnaApi->creditInvoice($invno);
196
  break;
197
- case self::REFUND_METHOD_AMOUNT:
198
  $taxRate = 0;
199
- foreach ($this->_getGoodsList() as $item) {
200
  if (isset($item['tax'])) {
201
  $taxRate = $item['tax'];
202
  break;
203
  }
204
  }
205
- // $amountExclDiscount = $amount - $this->getCreditmemo()->getDiscountAmount();
206
- $this->_logKlarnaApi('Amount with invoice ID ' . $invno);
207
- $result = $this->_klarnaApi->returnAmount($invno, $amount, $taxRate);
208
  break;
209
- default: // self::REFUND_METHOD_PART
210
- $this->_logKlarnaApi('Part with invoice ID ' . $invno);
211
- $this->_setGoodsListRefund();
212
- $result = $this->_klarnaApi->creditPart($invno);
213
  break;
214
  }
215
 
216
  $res = array(
217
  Vaimo_Klarna_Helper_Data::KLARNA_API_RESPONSE_STATUS => 'OK',
218
- Vaimo_Klarna_Helper_Data::KLARNA_API_RESPONSE_TRANSACTION_ID => $result,
219
- Vaimo_Klarna_Helper_Data::KLARNA_API_RESPONSE_FEE_REFUNDED => $this->_feeAmountIncluded()
220
  );
221
 
222
- $this->_sendMethodEvent('vaimo_paymentmethod_order_refunded', $amount);
223
-
224
- $this->_logKlarnaApi('Response ' . $res[Vaimo_Klarna_Helper_Data::KLARNA_API_RESPONSE_STATUS] . ' - ' . $res[Vaimo_Klarna_Helper_Data::KLARNA_API_RESPONSE_TRANSACTION_ID]);
225
  } catch (KlarnaException $e) {
226
- $this->_logKlarnaApi('Response Error Code = ' . $e->getCode());
227
- $this->logKlarnaException($e);
228
- Mage::throwException($this->_decode($e->getMessage()));
229
  }
230
  return $res;
231
  }
232
 
233
- public function cancel($direct_rno = NULL)
234
  {
235
  try {
236
- $this->_init('cancel');
237
- $this->_setAdditionalInformation($this->getPayment()->getAdditionalInformation());
238
-
239
- if ($direct_rno) {
240
- $rno = $direct_rno;
241
- } else {
242
- $rno = $this->_getAdditionalInformation(Vaimo_Klarna_Helper_Data::KLARNA_INFO_FIELD_RESERVATION_ID);
243
- }
244
- $this->_logKlarnaApi('Call with reservation ID ' . $rno);
245
-
246
- $result = $this->_klarnaApi->cancelReservation($rno);
247
 
248
  $res = array(
249
  Vaimo_Klarna_Helper_Data::KLARNA_API_RESPONSE_STATUS => $result,
250
  );
251
 
252
- $this->_sendMethodEvent('vaimo_paymentmethod_order_canceled', $this->getOrder()->getTotalDue());
253
-
254
- $this->_logKlarnaApi('Response ' . $res[Vaimo_Klarna_Helper_Data::KLARNA_API_RESPONSE_STATUS]);
255
  } catch (KlarnaException $e) {
256
- $this->_logKlarnaApi('Response Error Code = ' . $e->getCode());
257
- $this->logKlarnaException($e);
258
- Mage::throwException($this->_decode($e->getMessage()));
259
  }
260
  return $res;
261
  }
262
 
263
- public function checkStatus()
264
  {
265
- try {
266
- $this->_init('check_status');
267
- $this->_setAdditionalInformation($this->getPayment()->getAdditionalInformation());
268
-
269
- $rno = $this->_getAdditionalInformation(Vaimo_Klarna_Helper_Data::KLARNA_INFO_FIELD_RESERVATION_ID);
270
- $this->_logKlarnaApi('Call with reservation ID ' . $rno);
271
-
272
- $result = $this->_klarnaApi->checkOrderStatus($rno);
273
-
274
- $res = array(
275
- Vaimo_Klarna_Helper_Data::KLARNA_API_RESPONSE_STATUS => $this->_klarnaReservationStatusToCode($result),
276
- );
277
-
278
- $this->_logKlarnaApi('Response ' . $res[Vaimo_Klarna_Helper_Data::KLARNA_API_RESPONSE_STATUS]);
279
- } catch (KlarnaException $e) {
280
- $this->_logKlarnaApi('Response Error Code = ' . $e->getCode());
281
- $this->logKlarnaException($e);
282
- Mage::throwException($this->_decode($e->getMessage()));
283
- }
284
- return $res;
285
  }
286
 
287
- protected function _klarnaReservationStatusToCode($status)
288
- {
289
- switch ($status) {
290
- case KlarnaFlags::ACCEPTED:
291
- $res = Vaimo_Klarna_Helper_Data::KLARNA_STATUS_ACCEPTED;
292
- break;
293
- case KlarnaFlags::PENDING:
294
- $res = Vaimo_Klarna_Helper_Data::KLARNA_STATUS_PENDING;
295
- break;
296
- case KlarnaFlags::DENIED:
297
- $res = Vaimo_Klarna_Helper_Data::KLARNA_STATUS_DENIED;
298
- break;
299
- default:
300
- $res = 'unknown_' . $status;
301
- break;
302
- }
303
- return $res;
304
- }
305
-
306
- /*
307
- * I have copied the cache function from previous Klarna module, it's only for this session
308
- *
309
- * @return array
310
- */
311
- public function getAddresses($pno)
312
- {
313
-
314
- $res = array();
315
- try {
316
- $cache = array();
317
-
318
- if (array_key_exists(self::$_session_key, $_SESSION)) {
319
- $cache = unserialize( base64_decode($_SESSION[self::$_session_key]) );
320
- }
321
- if (array_key_exists($pno, $cache)) {
322
- return $cache[$pno];
323
- }
324
-
325
- $this->_init('address');
326
- $this->_logKlarnaApi('Call with Personal ID ' . $pno);
327
-
328
- $result = $this->_klarnaApi->getAddresses($pno);
329
- foreach ($result as $klarnaAddr) {
330
- $res[] = array(
331
- 'company_name' => $this->_decode($klarnaAddr->getCompanyName()),
332
- 'first_name' => $this->_decode($klarnaAddr->getFirstName()),
333
- 'last_name' => $this->_decode($klarnaAddr->getLastName()),
334
- 'street' => $this->_decode($klarnaAddr->getStreet()),
335
- 'zip' => $this->_decode($klarnaAddr->getZipCode()),
336
- 'city' => $this->_decode($klarnaAddr->getCity()),
337
- 'house_number' => $this->_decode($klarnaAddr->getHouseNumber()),
338
- 'house_extension' => $this->_decode($klarnaAddr->getHouseExt()),
339
- 'country_code' => $klarnaAddr->getCountryCode(),
340
- 'id' => $this->getAddressKey($klarnaAddr)
341
- );
342
- }
343
-
344
-
345
- $this->_logKlarnaApi('Response ' .'OK');
346
-
347
- $cache[$pno] = $res;
348
- $_SESSION[self::$_session_key] = base64_encode( serialize($cache) );
349
-
350
- } catch (KlarnaException $e) {
351
- $this->_logKlarnaApi('Response Error Code = ' . $e->getCode());
352
- $this->logKlarnaException($e);
353
- Mage::throwException($this->_decode($e->getMessage()));
354
- }
355
- return $res;
356
- }
357
-
358
- /**
359
- * Get a matching address using getAddresses
360
- *
361
- * @return array
362
- */
363
- protected function _getSelectedAddress($pno, $address_id)
364
- {
365
- try {
366
- $addresses = $this->getAddresses($pno);
367
- foreach ($addresses as $address) {
368
- if ($address['id']==$address_id) {
369
- return $address;
370
- }
371
- }
372
- } catch (Mage_Core_Exception $e) {
373
- $this->logKlarnaException($e);
374
- return NULL;
375
- }
376
- return NULL;
377
- }
378
-
379
- public function reloadAllPClasses()
380
- {
381
- try {
382
- $countries = $this->_getKlarnaActiveStores();
383
-
384
- $this->_init('get-all-pclasses');
385
-
386
- $this->_logKlarnaApi('Call clear');
387
- $this->_klarnaApi->clearPClasses();
388
- $this->_logKlarnaApi('Call clear OK');
389
-
390
- } catch (KlarnaException $e) {
391
- $this->_logKlarnaApi('Response Error Code = ' . $e->getCode());
392
- $this->logKlarnaException($e);
393
- Mage::throwException($this->_decode($e->getMessage()));
394
- }
395
-
396
- foreach ($countries as $storeId) {
397
- try {
398
- $this->setStoreInformation($storeId);
399
- $this->_init('get-all-pclasses');
400
-
401
- $this->_logKlarnaApi('Call fetch all');
402
- $this->_klarnaApi->fetchPClasses($this->_getCountryCode(), $this->_getLanguageCode(), $this->_getCurrencyCode());
403
- $this->_logKlarnaApi('Call fetch all OK');
404
-
405
- } catch (KlarnaException $e) {
406
- $this->_logKlarnaApi('Response Error Code = ' . $e->getCode());
407
- $this->logKlarnaException($e);
408
- Mage::getSingleton('adminhtml/session')->addError(
409
- Mage::helper('klarna')->__('Fetching PClasses failed for store %s. Error: %s - %s', Mage::app()->getStore($storeId)->getName(), $e->getCode(), $e->getMessage())
410
- );
411
- }
412
- }
413
- }
414
-
415
- protected function _getAllPClasses($onlyCurrentStore = false)
416
  {
417
  try {
418
- $res = array();
419
-
420
- $this->_init('get-all-pclasses');
421
-
422
- $this->_logKlarnaApi('Call get all');
423
- $pclasses = $this->_klarnaApi->getAllPClasses();
424
- if (is_array($pclasses)) {
425
- foreach ($pclasses as $pclass) {
426
- if ($onlyCurrentStore) {
427
- if ($this->_getCountryCode()!=KlarnaCountry::getCode($pclass->getCountry())) {
428
- continue;
429
- }
430
- }
431
- $res[] = $pclass;
432
- }
433
- }
434
- $this->_logKlarnaApi('Response OK');
435
- } catch (KlarnaException $e) {
436
- $this->_logKlarnaApi('Response Error Code = ' . $e->getCode());
437
- $this->logKlarnaException($e);
438
- Mage::throwException($this->_decode($e->getMessage()));
439
- }
440
- return $res;
441
- }
442
-
443
- protected function _filterPClasses($pclasses, $page, $amount)
444
- {
445
- foreach ($pclasses as $id => $pclass) {
446
- $type = $pclass->getType();
447
- $monthlyCost = -1;
448
-
449
- if (!in_array($pclass->getType(), $this->_getPClassTypes())) {
450
- unset($pclasses[$id]);
451
- continue;
452
- }
453
-
454
- if ($pclass->getMinAmount()) {
455
- if ($amount < $pclass->getMinAmount()) {
456
- unset($pclasses[$id]);
457
- continue;
458
- }
459
- }
460
 
 
461
 
462
- if (in_array($type, array(KlarnaPClass::FIXED, KlarnaPClass::DELAY, KlarnaPClass::SPECIAL))) {
463
- if ($page == KlarnaFlags::PRODUCT_PAGE) {
464
- unset($pclasses[$id]);
465
- continue;
466
- }
467
- } else {
468
- $lowestPayment = KlarnaCalc::get_lowest_payment_for_account( $pclass->getCountry() );
469
- $monthlyCost = KlarnaCalc::calc_monthly_cost( $amount, $pclass, $page );
470
- if ($monthlyCost < 0.01) {
471
- unset($pclasses[$id]);
472
- continue;
473
- }
474
 
475
- if ($monthlyCost < $lowestPayment) {
476
- if ($type == KlarnaPClass::CAMPAIGN) {
477
- unset($pclasses[$id]);
478
- continue;
479
- }
480
- if ($page == KlarnaFlags::CHECKOUT_PAGE && $type == KlarnaPClass::ACCOUNT) {
481
- $monthlyCost = $lowestPayment;
482
- }
483
- }
484
- }
485
  }
486
- return $pclasses;
487
  }
488
 
489
- /*
490
- * Same logic as function above, but it's easier to read if these functions are split...
491
- *
492
- */
493
- protected function _getPClassMinimum($pclasses, $page, $amount)
494
  {
495
- $minimum = NULL;
496
- $minval = NULL;
497
- foreach ($pclasses as $pclass) {
498
- $type = $pclass->getType();
499
- $monthlyCost = -1;
 
 
 
 
 
 
 
 
 
 
 
 
500
 
501
- if (!in_array($type, array(KlarnaPClass::FIXED, KlarnaPClass::SPECIAL))) {
502
- $lowestPayment = KlarnaCalc::get_lowest_payment_for_account( $pclass->getCountry() );
503
- $monthlyCost = KlarnaCalc::calc_monthly_cost( $amount, $pclass, $page );
 
 
 
 
504
 
505
- if ($monthlyCost < $lowestPayment) {
506
- if ($page == KlarnaFlags::CHECKOUT_PAGE && $type == KlarnaPClass::ACCOUNT) {
507
- $monthlyCost = $lowestPayment;
 
 
 
 
 
 
 
 
 
 
508
  }
 
509
  }
510
  }
511
 
512
- if ($minimum === null || $minval > $monthlyCost) {
513
- $minimum = $pclass;
514
- $minval = $monthlyCost;
515
- }
516
-
517
  }
518
- return $minimum;
519
  }
520
 
521
- protected function _getDefaultPClass($pclasses)
522
  {
523
- $default = NULL;
524
- foreach ($pclasses as $pclass) {
525
- $type = $pclass->getType();
526
 
527
- if ($type == KlarnaPClass::ACCOUNT) {
528
- $default = $pclass;
529
- } else if ($type == KlarnaPClass::CAMPAIGN) {
530
- if ($default === NULL || $default->getType() != KlarnaPClass::ACCOUNT) {
531
- $default = $pclass;
532
- }
533
- } else {
534
- if ($default === NULL) {
535
- $default = $pclass;
536
- }
537
- }
538
  }
539
- return $default;
540
  }
541
 
542
- protected function _PClassToArray($pclass, $amount, $default = NULL, $minimum = NULL)
543
  {
544
- $type = $pclass->getType();
545
- $monthlyCost = -1;
546
-
547
- if (!in_array($type, array(KlarnaPClass::FIXED, KlarnaPClass::SPECIAL))) {
548
- $lowestPayment = KlarnaCalc::get_lowest_payment_for_account( $pclass->getCountry() );
549
- $monthlyCost = KlarnaCalc::calc_monthly_cost( $amount, $pclass, KlarnaFlags::CHECKOUT_PAGE );
550
 
551
- if ($monthlyCost < $lowestPayment) {
552
- if ($type == KlarnaPClass::ACCOUNT) {
553
- $monthlyCost = $lowestPayment;
554
- }
555
- }
 
 
556
  }
557
- $totalCost = KlarnaCalc::total_credit_purchase_cost($amount, $pclass, KlarnaFlags::CHECKOUT_PAGE);
558
-
559
- $pclassArr = $pclass->toArray();
560
- if ($default) {
561
- if ($pclass==$default) {
562
- $pclassArr['default'] = true;
563
- } else {
564
- $pclassArr['default'] = false;
 
 
 
 
565
  }
566
- } else {
567
- $pclassArr['default'] = NULL;
568
- }
569
 
570
- if ($minimum) {
571
- if ($pclass==$minimum) {
572
- $pclassArr['cheapest'] = true;
573
- } else {
574
- $pclassArr['cheapest'] = false;
575
- }
576
- } else {
577
- $pclassArr['cheapest'] = NULL;
578
  }
579
- $pclassArr['monthly_cost'] = $monthlyCost;
580
- $pclassArr['total_cost'] = $totalCost;
581
- return $pclassArr;
582
  }
583
 
584
- /*
585
- *
586
- *
587
- */
588
- public function getValidCheckoutPClasses()
589
  {
590
  try {
591
- $amount = $this->getQuote()->getGrandTotal();
592
- $pclasses = $this->_getAllPClasses(true);
593
- $pclasses = $this->_filterPClasses($pclasses, KlarnaFlags::CHECKOUT_PAGE, $amount);
594
  $default = $this->_getDefaultPClass($pclasses);
595
  $minimum = $this->_getPClassMinimum($pclasses, KlarnaFlags::CHECKOUT_PAGE, $amount);
596
 
@@ -604,64 +793,15 @@ class Vaimo_Klarna_Model_Klarna_Api extends Vaimo_Klarna_Model_Klarna_Tools_Api
604
  }
605
  } catch (Mage_Core_Exception $e) {
606
  $this->logKlarnaException($e);
607
- Mage::throwException($this->_decode($e->getMessage()));
608
- }
609
- return $res;
610
- }
611
-
612
- /*
613
- *
614
- *
615
- */
616
- protected function _getSpecificPClass($id)
617
- {
618
- try {
619
- $amount = $this->getQuote()->getGrandTotal();
620
- $pclasses = $this->_getAllPClasses(true);
621
-
622
- $res = NULL;
623
- foreach ($pclasses as $pclass) {
624
- if ($pclass->getId()==$id) {
625
- $res = $this->_PClassToArray($pclass, $amount);
626
- break;
627
- }
628
- }
629
- } catch (Mage_Core_Exception $e) {
630
- $this->logKlarnaException($e);
631
  }
632
  return $res;
633
  }
634
 
635
- public function setPClassTypes($types)
636
- {
637
- if (!is_array($types)) {
638
- switch ($types) {
639
- case Vaimo_Klarna_Helper_Data::KLARNA_METHOD_ACCOUNT:
640
- $types = array(KlarnaPClass::ACCOUNT,
641
- KlarnaPClass::CAMPAIGN,
642
- KlarnaPClass::FIXED
643
- );
644
- break;
645
- case Vaimo_Klarna_Helper_Data::KLARNA_METHOD_SPECIAL:
646
- $types = array(KlarnaPClass::SPECIAL,
647
- KlarnaPClass::DELAY
648
- );
649
- break;
650
- }
651
- }
652
- parent::setPClassTypes($types);
653
-
654
- return $types;
655
- }
656
-
657
- /*
658
- *
659
- *
660
- */
661
  public function getDisplayAllPClasses()
662
  {
663
  $res = array();
664
- $pclasses = $this->_getAllPClasses(false);
665
  foreach ($pclasses as $pclass) {
666
  $pclassArr = $pclass->toArray();
667
  switch ($pclass->getCountry()) {
@@ -692,58 +832,6 @@ class Vaimo_Klarna_Model_Klarna_Api extends Vaimo_Klarna_Model_Klarna_Tools_Api
692
  return $res;
693
  }
694
 
695
- /**
696
- * Set the addresses on the Klarna object
697
- *
698
- * @return void
699
- */
700
- protected function _setAddresses()
701
- {
702
- $shipping = $this->toKlarna($this->getShippingAddress());
703
- $billing = $this->toKlarna($this->getBillingAddress());
704
-
705
- $email = $this->_getAdditionalInformation('email');
706
- $shipping->setEmail($email);
707
- $billing->setEmail($email);
708
-
709
- $this->_setReference($shipping, $billing);
710
-
711
- $this->_klarnaApi->setAddress(KlarnaFlags::IS_SHIPPING, $shipping);
712
- $this->_klarnaApi->setAddress(KlarnaFlags::IS_BILLING, $billing);
713
-
714
- $this->_logDebugInfo('shippingAddress', $shipping->toArray());
715
- $this->_logDebugInfo('billingAddress', $billing->toArray());
716
-
717
- }
718
-
719
- /**
720
- * Set the company reference for the purchase
721
- *
722
- * @param KlarnaAddr $shipping Klarna shipping address
723
- * @param KlarnaAddr $billing Klarna billing address
724
- *
725
- * @return void
726
- */
727
- protected function _setReference($shipping, $billing)
728
- {
729
- $data = $this->_getAdditionalInformation();
730
- $reference = null;
731
- if (array_key_exists("reference", $data)) {
732
- $reference = $data["reference"];
733
- } elseif ($billing->isCompany) {
734
- $reference = $shipping->getFirstName() . " " . $shipping->getLastName();
735
- } elseif ($shipping->isCompany) {
736
- $reference = $billing->getFirstName() . " " . $billing->getLastName();
737
- }
738
-
739
- if (strlen($reference) == 0) {
740
- return;
741
- }
742
- $reference = html_entity_decode(trim($reference), ENT_COMPAT, 'ISO-8859-1');
743
- $this->_klarnaApi->setReference($reference, "");
744
- $this->_klarnaApi->setComment("Ref:{$reference}");
745
- }
746
-
747
  /**
748
  * Create a KlarnaAddr from a Magento address
749
  *
@@ -751,7 +839,7 @@ class Vaimo_Klarna_Model_Klarna_Api extends Vaimo_Klarna_Model_Klarna_Tools_Api
751
  *
752
  * @return KlarnaAddr
753
  */
754
- public function toKlarna($address)
755
  {
756
  if (!$address) return NULL;
757
 
@@ -777,20 +865,20 @@ class Vaimo_Klarna_Model_Klarna_Api extends Vaimo_Klarna_Model_Klarna_Tools_Api
777
  "",
778
  $address->getTelephone(), // Telno
779
  "", // Cellno
780
- $this->_encode($address->getFirstname()),
781
- $this->_encode($address->getLastname()),
782
  "",
783
- $this->_encode(trim($split["street"])),
784
- $this->_encode($address->getPostcode()),
785
- $this->_encode($address->getCity()),
786
  $address->getCountry(),
787
- $this->_encode(trim($houseNo)),
788
- $this->_encode(trim($houseExt))
789
  );
790
 
791
  $company = $address->getCompany();
792
  if (strlen($company) > 0 && $this->isCompanyAllowed()) {
793
- $klarnaAddr->setCompanyName($this->_encode($company));
794
  $klarnaAddr->isCompany = true;
795
  } else {
796
  $klarnaAddr->setCompanyName('');
@@ -801,77 +889,31 @@ class Vaimo_Klarna_Model_Klarna_Api extends Vaimo_Klarna_Model_Klarna_Tools_Api
801
  }
802
 
803
  /**
804
- * Add an article to the goods list and pad it with default values
805
- *
806
- * Keys : qty, sku, name, price, tax, discount, flags
807
- *
808
- * @param array $array The array to use
809
  *
810
  * @return void
811
  */
812
- protected function _addArticle($array)
813
  {
814
- $default = array(
815
- "qty" => 0,
816
- "sku" => "",
817
- "name" => "",
818
- "price" => 0,
819
- "tax" => 0,
820
- "discount" => 0,
821
- "flags" => KlarnaFlags::NO_FLAG
822
- );
823
-
824
- //Filter out null values and overwrite the default values
825
- $values = array_merge($default, array_filter($array));
826
 
827
- switch ($values['flags']) {
828
- case self::FLAG_ITEM_NORMAL:
829
- $values['flags'] = KlarnaFlags::INC_VAT;
830
- break;
831
- case self::FLAG_ITEM_SHIPPING_FEE:
832
- $values['flags'] = KlarnaFlags::INC_VAT | KlarnaFlags::IS_SHIPMENT;
833
- break;
834
- case self::FLAG_ITEM_HANDLING_FEE:
835
- $values['flags'] = KlarnaFlags::INC_VAT | KlarnaFlags::IS_HANDLING;
836
- break;
837
  }
 
 
838
 
839
- $this->_klarnaApi->addArticle(
840
- $values["qty"],
841
- $this->_encode($values["sku"]),
842
- $this->_encode($values["name"]),
843
- $values["price"],
844
- $values["tax"],
845
- $values["discount"],
846
- $values["flags"]
847
- );
848
- $this->_logDebugInfo('addArticle', $values);
849
- }
850
 
851
- /*
852
- * Add an article to the goods list and pad it with default values
853
- *
854
- * Keys : qty, sku, name, price, tax, discount, flags
855
- *
856
- * @param array $array The array to use
857
- *
858
- * @return void
859
- */
860
- protected function _addArtNo($array)
861
- {
862
- $default = array(
863
- "qty" => 0,
864
- "sku" => ""
865
- );
866
 
867
- //Filter out null values and overwrite the default values
868
- $values = array_merge($default, array_filter($array));
869
 
870
- $this->_klarnaApi->addArtNo(
871
- intval($values["qty"]),
872
- strval($this->_encode($values["sku"]))
873
- );
874
- $this->_logDebugInfo('addArticle', $values);
875
  }
876
 
877
  /**
@@ -879,12 +921,12 @@ class Vaimo_Klarna_Model_Klarna_Api extends Vaimo_Klarna_Model_Klarna_Tools_Api
879
  *
880
  * @return void
881
  */
882
- protected function _setGoodsListReserve()
883
  {
884
- foreach ($this->_getGoodsList() as $item) {
885
  $this->_addArticle($item);
886
  }
887
- foreach ($this->_getExtras() as $extra) {
888
  $this->_addArticle($extra);
889
  }
890
  }
@@ -895,12 +937,12 @@ class Vaimo_Klarna_Model_Klarna_Api extends Vaimo_Klarna_Model_Klarna_Tools_Api
895
  *
896
  * @return void
897
  */
898
- protected function _setGoodsListCapture()
899
  {
900
- foreach (array_reverse($this->_getExtras()) as $extra) {
901
  $this->_addArtNo($extra);
902
  }
903
- foreach (array_reverse($this->_getGoodsList()) as $item) {
904
  $this->_addArtNo($item);
905
  }
906
  }
@@ -910,25 +952,15 @@ class Vaimo_Klarna_Model_Klarna_Api extends Vaimo_Klarna_Model_Klarna_Tools_Api
910
  *
911
  * @return void
912
  */
913
- protected function _setGoodsListRefund()
914
  {
915
- foreach ($this->_getGoodsList() as $item) {
916
  $this->_addArtNo($item);
917
  }
918
 
919
- foreach ($this->_getExtras() as $extra) {
920
  $this->_addArtNo($extra);
921
  }
922
  }
923
 
924
- protected function _setCaptureFlags()
925
- {
926
- $res = NULL;
927
- if ($this->_getConfigData("send_klarna_email")) {
928
- $res = KlarnaFlags::RSRV_SEND_BY_EMAIL;
929
-
930
- }
931
- return $res;
932
- }
933
-
934
  }
23
  * @copyright Copyright (c) 2009-2014 Vaimo AB
24
  */
25
 
 
 
 
 
 
 
 
26
  require_once Mage::getBaseDir('lib') . '/Klarna/transport/xmlrpc-3.0.0.beta/lib/xmlrpc.inc';
27
  require_once Mage::getBaseDir('lib') . '/Klarna/Klarna.php';
28
  require_once Mage::getBaseDir('lib') . '/Klarna/pclasses/mysqlstorage.class.php';
29
 
30
 
31
+ class Vaimo_Klarna_Model_Api_Xmlrpc extends Vaimo_Klarna_Model_Api_Abstract
32
  {
33
  protected $_klarnaApi = NULL;
34
 
35
+ public function __construct($klarnaApi = null)
 
 
36
  {
37
  parent::__construct();
 
 
 
38
 
39
  $this->_klarnaApi = $klarnaApi;
40
  if ($this->_klarnaApi == null) {
43
  }
44
 
45
  /**
46
+ * Build the PClass URI
47
+ *
48
+ * @return array
49
+ */
50
+ protected function _getPCURI()
51
+ {
52
+ $mageConfig = Mage::getResourceModel('sales/order')->getReadConnection()->getConfig();
53
+ return array(
54
+ "user" => $mageConfig['username'],
55
+ "passwd" => $mageConfig['password'],
56
+ "dsn" => $mageConfig['host'],
57
+ "db" => $mageConfig['dbname'],
58
+ "table" => "klarnapclasses"
59
+ );
60
+ }
61
+
62
+ protected function _klarnaReservationStatusToCode($status)
63
+ {
64
+ switch ($status) {
65
+ case KlarnaFlags::ACCEPTED:
66
+ $res = Vaimo_Klarna_Helper_Data::KLARNA_STATUS_ACCEPTED;
67
+ break;
68
+ case KlarnaFlags::PENDING:
69
+ $res = Vaimo_Klarna_Helper_Data::KLARNA_STATUS_PENDING;
70
+ break;
71
+ case KlarnaFlags::DENIED:
72
+ $res = Vaimo_Klarna_Helper_Data::KLARNA_STATUS_DENIED;
73
+ break;
74
+ default:
75
+ $res = 'unknown_' . $status;
76
+ break;
77
+ }
78
+ return $res;
79
+ }
80
+
81
+ protected function _setCaptureFlags($sendEmail = false)
82
+ {
83
+ $res = NULL;
84
+ if ($sendEmail) {
85
+ $res = KlarnaFlags::RSRV_SEND_BY_EMAIL;
86
+ }
87
+ return $res;
88
+ }
89
+
90
+ /**
91
+ * Klarna supports three different types of refunds, full, part and amount
92
+ * If any additional amount is specified, it will refund amount wise
93
+ * If The entire amount is refunded, it will be a full refund
94
+ * If above alternatives are false, it will refund part (meaning per item)
95
+ * The exception to this is if you have discounts, then the orderline in Klarna
96
+ * is the non-discounted one, followed by a total discount amount line.
97
+ * Then it is impossible to refund part, then we need the amount refund.
98
+ *
99
+ * @param float $amount The amount to refund
100
+ *
101
+ * @return string One of the const methods defined above
102
+ */
103
+ protected function _decideRefundMethod($model, $amount)
104
+ {
105
+ $res = Vaimo_Klarna_Helper_Data::KLARNA_REFUND_METHOD_PART;
106
+ $remaining = $model->getOrder()->getTotalInvoiced() - $model->getOrder()->getTotalOnlineRefunded(); // - $model->getOrder()->getShippingRefunded();
107
+ if (abs($remaining - $amount) < 0.00001) {
108
+ $res = Vaimo_Klarna_Helper_Data::KLARNA_REFUND_METHOD_FULL;
109
+ } else {
110
+ if ($model->getCreditmemo()->getAdjustmentPositive()!=0 || $model->getCreditmemo()->getAdjustmentNegative()!=0) {
111
+ $res = Vaimo_Klarna_Helper_Data::KLARNA_REFUND_METHOD_AMOUNT;
112
+ } else {
113
+ foreach ($model->getExtras() as $extra) {
114
+ if (isset($extra['flags'])) {
115
+ switch ($extra['flags']) {
116
+ case Vaimo_Klarna_Helper_Data::KLARNA_FLAG_ITEM_HANDLING_FEE:
117
+ if ($model->getCreditmemo()->getVaimoKlarnaFeeRefund()>0) {
118
+ if (isset($extra['original_price'])) {
119
+ if ($extra['original_price']!=$extra['price']) { // If not full shipping refunded, it will use refund amount instead
120
+ $res = Vaimo_Klarna_Helper_Data::KLARNA_REFUND_METHOD_AMOUNT;
121
+ }
122
+ }
123
+ }
124
+ break;
125
+ case Vaimo_Klarna_Helper_Data::KLARNA_FLAG_ITEM_SHIPPING_FEE;
126
+ if ($model->getCreditmemo()->getShippingAmount()>0) {
127
+ if (isset($extra['original_price'])) {
128
+ if ($extra['original_price']!=$extra['price']) { // If not full shipping refunded, it will use refund amount instead
129
+ $res = Vaimo_Klarna_Helper_Data::KLARNA_REFUND_METHOD_AMOUNT;
130
+ }
131
+ }
132
+ }
133
+ break;
134
+ case Vaimo_Klarna_Helper_Data::KLARNA_FLAG_ITEM_NORMAL:
135
+ break;
136
+ default:
137
+ break;
138
+ }
139
+ }
140
+ }
141
+ }
142
+ $discount_amount = 0;
143
+ foreach ($model->getOrder()->getItemsCollection() as $item) {
144
+ $discount_amount += $item->getDiscountAmount();
145
+ }
146
+ if ($discount_amount) {
147
+ $res = Vaimo_Klarna_Helper_Data::KLARNA_REFUND_METHOD_AMOUNT;
148
+ }
149
+ }
150
+ return $res;
151
+ }
152
+
153
+ /**
154
+ * Set the company reference for the purchase
155
+ *
156
+ * @param KlarnaAddr $shipping Klarna shipping address
157
+ * @param KlarnaAddr $billing Klarna billing address
158
+ *
159
+ * @return void
160
+ */
161
+ protected function _setReference($data, $shipping, $billing)
162
+ {
163
+ $reference = null;
164
+ if (array_key_exists("reference", $data)) {
165
+ $reference = $data["reference"];
166
+ } elseif ($billing->isCompany) {
167
+ $reference = $shipping->getFirstName() . " " . $shipping->getLastName();
168
+ } elseif ($shipping->isCompany) {
169
+ $reference = $billing->getFirstName() . " " . $billing->getLastName();
170
+ }
171
+
172
+ if (strlen($reference) == 0) {
173
+ return;
174
+ }
175
+ $reference = html_entity_decode(trim($reference), ENT_COMPAT, 'ISO-8859-1');
176
+ $this->_klarnaApi->setReference($reference, "");
177
+ $this->_klarnaApi->setComment("Ref:{$reference}");
178
+ }
179
+
180
+ /**
181
+ * Split a string into an array consisting of Street, House Number and
182
+ * House extension.
183
+ *
184
+ * @param string $address Address string to split
185
+ *
186
+ * @return array
187
+ */
188
+ protected static function _splitAddress($address)
189
+ {
190
+ // Get everything up to the first number with a regex
191
+ $hasMatch = preg_match('/^[^0-9]*/', $address, $match);
192
+
193
+ // If no matching is possible, return the supplied string as the street
194
+ if (!$hasMatch) {
195
+ return array($address, "", "");
196
+ }
197
+
198
+ // Remove the street from the address.
199
+ $address = str_replace($match[0], "", $address);
200
+ $street = trim($match[0]);
201
+
202
+ // Nothing left to split, return
203
+ if (strlen($address) == 0) {
204
+ return array($street, "", "");
205
+ }
206
+ // Explode address to an array
207
+ $addrArray = explode(" ", $address);
208
+
209
+ // Shift the first element off the array, that is the house number
210
+ $housenumber = array_shift($addrArray);
211
+
212
+ // If the array is empty now, there is no extension.
213
+ if (count($addrArray) == 0) {
214
+ return array($street, $housenumber, "");
215
+ }
216
+
217
+ // Join together the remaining pieces as the extension.
218
+ $extension = implode(" ", $addrArray);
219
+
220
+ return array($street, $housenumber, $extension);
221
+ }
222
+
223
+ /**
224
+ * Get the formatted street required for a Klarna Addr
225
+ *
226
+ * @param string $street The street to split
227
+ * @param array $split An array determining the parts of the split
228
+ *
229
+ * @return array
230
+ */
231
+ protected function _splitStreet($street)
232
+ {
233
+ $split = $this->_getTransport()->getSplit();
234
+ $result = array(
235
+ 'street' => '',
236
+ 'house_extension' => '',
237
+ 'house_number' => ''
238
+ );
239
+ $elements = $this->_splitAddress($street);
240
+ $result['street'] = $elements[0];
241
+
242
+ if (in_array('house_extension', $split)) {
243
+ $result['house_extension'] = $elements[2];
244
+ } else {
245
+ $elements[1] .= ' ' . $elements[2];
246
+ }
247
+
248
+ if (in_array('house_number', $split)) {
249
+ $result['house_number'] = $elements[1];
250
+ } else {
251
+ $result['street'] .= ' ' . $elements[1];
252
+ }
253
+
254
+ return array_map('trim', $result);
255
+ }
256
+
257
+ /**
258
+ * Add an article to the goods list and pad it with default values
259
+ *
260
+ * Keys : qty, sku, name, price, tax, discount, flags
261
+ *
262
+ * @param array $array The array to use
263
+ *
264
+ * @return void
265
+ */
266
+ protected function _addArticle($array)
267
+ {
268
+ $default = array(
269
+ "qty" => 0,
270
+ "sku" => "",
271
+ "name" => "",
272
+ "price" => 0,
273
+ "tax" => 0,
274
+ "discount" => 0,
275
+ "flags" => KlarnaFlags::NO_FLAG
276
+ );
277
+
278
+ //Filter out null values and overwrite the default values
279
+ $values = array_merge($default, array_filter($array));
280
+
281
+ switch ($values['flags']) {
282
+ case Vaimo_Klarna_Helper_Data::KLARNA_FLAG_ITEM_NORMAL:
283
+ $values['flags'] = KlarnaFlags::INC_VAT;
284
+ break;
285
+ case Vaimo_Klarna_Helper_Data::KLARNA_FLAG_ITEM_SHIPPING_FEE:
286
+ $values['flags'] = KlarnaFlags::INC_VAT | KlarnaFlags::IS_SHIPMENT;
287
+ break;
288
+ case Vaimo_Klarna_Helper_Data::KLARNA_FLAG_ITEM_HANDLING_FEE:
289
+ $values['flags'] = KlarnaFlags::INC_VAT | KlarnaFlags::IS_HANDLING;
290
+ break;
291
+ }
292
+
293
+ $this->_klarnaApi->addArticle(
294
+ $values["qty"],
295
+ Mage::helper('klarna')->encode($values["sku"]),
296
+ Mage::helper('klarna')->encode($values["name"]),
297
+ $values["price"],
298
+ $values["tax"],
299
+ $values["discount"],
300
+ $values["flags"]
301
+ );
302
+ $this->_getTransport()->logDebugInfo('addArticle', $values);
303
+ }
304
+
305
+ /*
306
+ * Add an article to the goods list and pad it with default values
307
+ *
308
+ * Keys : qty, sku, name, price, tax, discount, flags
309
+ *
310
+ * @param array $array The array to use
311
+ *
312
+ * @return void
313
+ */
314
+ protected function _addArtNo($array)
315
+ {
316
+ $default = array(
317
+ "qty" => 0,
318
+ "sku" => ""
319
+ );
320
+
321
+ //Filter out null values and overwrite the default values
322
+ $values = array_merge($default, array_filter($array));
323
+
324
+ $this->_klarnaApi->addArtNo(
325
+ intval($values["qty"]),
326
+ strval(Mage::helper('klarna')->encode($values["sku"]))
327
+ );
328
+ $this->_getTransport()->logDebugInfo('addArticle', $values);
329
+ }
330
+
331
+ /**
332
+ * Get a unique key used to identify the given address
333
+ *
334
+ * The key is a hash of the lower bit ascii portion of company name,
335
+ * first name, last name and street joined with pipes
336
  *
337
+ * @param KlarnaAddr $klarnaAddr address
338
+ *
339
+ * @return string key for this address
340
  */
341
+ protected static function _getAddressKey($klarnaAddr)
342
+ {
343
+ return hash(
344
+ 'crc32',
345
+ preg_replace(
346
+ '/[^\w]*/', '',
347
+ $klarnaAddr->getCompanyName() . '|' .
348
+ $klarnaAddr->getFirstName() . '|' .
349
+ $klarnaAddr->getLastName() . '|' .
350
+ $klarnaAddr->getStreet()
351
+ )
352
+ );
353
+ }
354
+
355
+ protected function _filterPClasses($method, $pclasses, $page, $amount)
356
  {
357
+ $types = array();
358
+ switch ($method) {
359
+ case Vaimo_Klarna_Helper_Data::KLARNA_METHOD_ACCOUNT:
360
+ $types = array(KlarnaPClass::ACCOUNT,
361
+ KlarnaPClass::CAMPAIGN,
362
+ KlarnaPClass::FIXED
363
+ );
364
+ break;
365
+ case Vaimo_Klarna_Helper_Data::KLARNA_METHOD_SPECIAL:
366
+ $types = array(KlarnaPClass::SPECIAL,
367
+ KlarnaPClass::DELAY
368
+ );
369
+ break;
370
+ }
371
+ foreach ($pclasses as $id => $pclass) {
372
+ $type = $pclass->getType();
373
+ $monthlyCost = -1;
374
+
375
+ if (!in_array($pclass->getType(), $types)) {
376
+ unset($pclasses[$id]);
377
+ continue;
378
+ }
379
+
380
+ if ($pclass->getMinAmount()) {
381
+ if ($amount < $pclass->getMinAmount()) {
382
+ unset($pclasses[$id]);
383
+ continue;
384
+ }
385
+ }
386
+
387
+
388
+ if (in_array($type, array(KlarnaPClass::FIXED, KlarnaPClass::DELAY, KlarnaPClass::SPECIAL))) {
389
+ if ($page == KlarnaFlags::PRODUCT_PAGE) {
390
+ unset($pclasses[$id]);
391
+ continue;
392
+ }
393
+ } else {
394
+ $lowestPayment = KlarnaCalc::get_lowest_payment_for_account( $pclass->getCountry() );
395
+ $monthlyCost = KlarnaCalc::calc_monthly_cost( $amount, $pclass, $page );
396
+ if ($monthlyCost < 0.01) {
397
+ unset($pclasses[$id]);
398
+ continue;
399
+ }
400
+
401
+ if ($monthlyCost < $lowestPayment) {
402
+ if ($type == KlarnaPClass::CAMPAIGN) {
403
+ unset($pclasses[$id]);
404
+ continue;
405
+ }
406
+ if ($page == KlarnaFlags::CHECKOUT_PAGE && $type == KlarnaPClass::ACCOUNT) {
407
+ $monthlyCost = $lowestPayment;
408
+ }
409
+ }
410
+ }
411
+ }
412
+ return $pclasses;
413
+ }
414
+
415
+ /*
416
+ * Same logic as function above, but it's easier to read if these functions are split...
417
+ *
418
+ */
419
+ protected function _getPClassMinimum($pclasses, $page, $amount)
420
+ {
421
+ $minimum = NULL;
422
+ $minval = NULL;
423
+ foreach ($pclasses as $pclass) {
424
+ $type = $pclass->getType();
425
+ $monthlyCost = -1;
426
+
427
+ if (!in_array($type, array(KlarnaPClass::FIXED, KlarnaPClass::SPECIAL))) {
428
+ $lowestPayment = KlarnaCalc::get_lowest_payment_for_account( $pclass->getCountry() );
429
+ $monthlyCost = KlarnaCalc::calc_monthly_cost( $amount, $pclass, $page );
430
+
431
+ if ($monthlyCost < $lowestPayment) {
432
+ if ($page == KlarnaFlags::CHECKOUT_PAGE && $type == KlarnaPClass::ACCOUNT) {
433
+ $monthlyCost = $lowestPayment;
434
+ }
435
+ }
436
+ }
437
+
438
+ if ($minimum === null || $minval > $monthlyCost) {
439
+ $minimum = $pclass;
440
+ $minval = $monthlyCost;
441
+ }
442
+
443
+ }
444
+ return $minimum;
445
+ }
446
+
447
+ protected function _getDefaultPClass($pclasses)
448
+ {
449
+ $default = NULL;
450
+ foreach ($pclasses as $pclass) {
451
+ $type = $pclass->getType();
452
+
453
+ if ($type == KlarnaPClass::ACCOUNT) {
454
+ $default = $pclass;
455
+ } else if ($type == KlarnaPClass::CAMPAIGN) {
456
+ if ($default === NULL || $default->getType() != KlarnaPClass::ACCOUNT) {
457
+ $default = $pclass;
458
+ }
459
+ } else {
460
+ if ($default === NULL) {
461
+ $default = $pclass;
462
+ }
463
+ }
464
+ }
465
+ return $default;
466
+ }
467
+
468
+ protected function _PClassToArray($pclass, $amount, $default = NULL, $minimum = NULL)
469
+ {
470
+ $type = $pclass->getType();
471
+ $monthlyCost = -1;
472
+
473
+ if (!in_array($type, array(KlarnaPClass::FIXED, KlarnaPClass::SPECIAL))) {
474
+ $lowestPayment = KlarnaCalc::get_lowest_payment_for_account( $pclass->getCountry() );
475
+ $monthlyCost = KlarnaCalc::calc_monthly_cost( $amount, $pclass, KlarnaFlags::CHECKOUT_PAGE );
476
+
477
+ if ($monthlyCost < $lowestPayment) {
478
+ if ($type == KlarnaPClass::ACCOUNT) {
479
+ $monthlyCost = $lowestPayment;
480
+ }
481
+ }
482
+ }
483
+ $totalCost = KlarnaCalc::total_credit_purchase_cost($amount, $pclass, KlarnaFlags::CHECKOUT_PAGE);
484
+
485
+ $pclassArr = $pclass->toArray();
486
+ if ($default) {
487
+ if ($pclass==$default) {
488
+ $pclassArr['default'] = true;
489
+ } else {
490
+ $pclassArr['default'] = false;
491
+ }
492
+ } else {
493
+ $pclassArr['default'] = NULL;
494
+ }
495
+
496
+ if ($minimum) {
497
+ if ($pclass==$minimum) {
498
+ $pclassArr['cheapest'] = true;
499
+ } else {
500
+ $pclassArr['cheapest'] = false;
501
+ }
502
+ } else {
503
+ $pclassArr['cheapest'] = NULL;
504
+ }
505
+ $pclassArr['monthly_cost'] = $monthlyCost;
506
+ $pclassArr['total_cost'] = $totalCost;
507
+ return $pclassArr;
508
+ }
509
+
510
+ public function init($klarnaSetup)
511
+ {
512
+ $this->_klarnaSetup = $klarnaSetup;
513
+ $host = $this->_klarnaSetup->getHost();
514
  if ($host == 'LIVE') {
515
  $mode = Klarna::LIVE;
516
  } else {
517
  $mode = Klarna::BETA;
518
  }
519
  $this->_klarnaApi->config(
520
+ $this->_klarnaSetup->getMerchantId(),
521
+ $this->_klarnaSetup->getSharedSecret(),
522
+ $this->_klarnaSetup->getCountryCode(),
523
+ $this->_klarnaSetup->getLanguageCode(),
524
+ $this->_klarnaSetup->getCurrencyCode(),
525
  $mode, // Live / Beta
526
  'mysql', // pcStorage
527
  $this->_getPCURI(), // pclasses.json
544
  $this->_klarnaApi->setVersion('PHP_' . 'Magento ' . $magentoEdition . '_' . $magentoVersion . '_' . $module . '_' . $version);
545
  }
546
 
547
+ public function reserve()
548
  {
549
  try {
550
+ $this->_klarnaApi->setEstoreInfo($this->_getTransport()->getOrder()->getIncrementId());
 
 
 
 
 
 
 
 
551
  $result = $this->_klarnaApi->reserveAmount(
552
+ $this->_getTransport()->getPNO(),
553
+ $this->_getTransport()->getGender(),
554
+ $this->_getTransport()->getOrder()->getTotalDue(),
555
  KlarnaFlags::NO_FLAG,
556
+ $this->_getTransport()->getPaymentPlan()
557
  );
558
 
559
  $res = array(
561
  Vaimo_Klarna_Helper_Data::KLARNA_API_RESPONSE_STATUS => $this->_klarnaReservationStatusToCode($result[1])
562
  );
563
 
 
 
 
 
 
 
 
 
 
 
 
 
564
  } catch (KlarnaException $e) {
565
+ $this->_getTransport()->logKlarnaApi('Response Error Code = ' . $e->getCode());
566
+ $this->_getTransport()->logKlarnaException($e);
567
+ Mage::throwException(Mage::helper('klarna')->decode($e->getMessage()));
568
  }
569
  return $res;
570
  }
571
 
572
+ public function capture($reservation_no, $amount, $sendEmailf)
573
  {
574
  try {
575
+ $this->_klarnaApi->setEstoreInfo($this->_getTransport()->getOrder()->getIncrementId());
576
+ $this->_klarnaApi->setActivateInfo('orderid1', strval($this->_getTransport()->getOrder()->getIncrementId()));
 
 
 
 
 
 
 
 
 
 
577
 
578
  $ocr = NULL;
579
+ $flags = $this->_setCaptureFlags($sendEmailf);
580
 
581
+ $result = $this->_klarnaApi->activate($reservation_no, $ocr, $flags);
582
 
583
  $res = array(
584
  Vaimo_Klarna_Helper_Data::KLARNA_API_RESPONSE_STATUS => $result[0],
585
+ Vaimo_Klarna_Helper_Data::KLARNA_API_RESPONSE_TRANSACTION_ID => $result[1]
 
586
  );
 
 
 
 
587
  } catch (KlarnaException $e) {
588
+ $this->_getTransport()->logKlarnaApi('Response Error Code = ' . $e->getCode());
589
+ $this->_getTransport()->logKlarnaException($e);
590
+ Mage::throwException(Mage::helper('klarna')->decode($e->getMessage()));
591
  }
592
  return $res;
593
  }
594
 
595
+ public function refund($amount, $invoice_no)
596
  {
597
  try {
598
+
599
+ switch ($this->_decideRefundMethod($this->_getTransport(), $amount)) {
600
+ case Vaimo_Klarna_Helper_Data::KLARNA_REFUND_METHOD_FULL:
601
+ $this->_getTransport()->logKlarnaApi('Full with invoice ID ' . $invoice_no);
602
+ $result = $this->_klarnaApi->creditInvoice($invoice_no);
 
 
 
 
 
603
  break;
604
+ case Vaimo_Klarna_Helper_Data::KLARNA_REFUND_METHOD_AMOUNT:
605
  $taxRate = 0;
606
+ foreach ($this->_getTransport()->getGoodsList() as $item) {
607
  if (isset($item['tax'])) {
608
  $taxRate = $item['tax'];
609
  break;
610
  }
611
  }
612
+ // $amountExclDiscount = $amount - $this->_getTransport()->getCreditmemo()->getDiscountAmount();
613
+ $this->_getTransport()->logKlarnaApi('Amount with invoice ID ' . $invoice_no);
614
+ $result = $this->_klarnaApi->returnAmount($invoice_no, $amount, $taxRate, KlarnaFlags::INC_VAT, Mage::helper('klarna')->__('Refund amount'));
615
  break;
616
+ default: // Vaimo_Klarna_Helper_Data::KLARNA_REFUND_METHOD_PART
617
+ $this->_getTransport()->logKlarnaApi('Part with invoice ID ' . $invoice_no);
618
+ $this->_setGoodsListRefund($amount);
619
+ $result = $this->_klarnaApi->creditPart($invoice_no);
620
  break;
621
  }
622
 
623
  $res = array(
624
  Vaimo_Klarna_Helper_Data::KLARNA_API_RESPONSE_STATUS => 'OK',
625
+ Vaimo_Klarna_Helper_Data::KLARNA_API_RESPONSE_TRANSACTION_ID => $result
 
626
  );
627
 
 
 
 
628
  } catch (KlarnaException $e) {
629
+ $this->_getTransport()->logKlarnaApi('Response Error Code = ' . $e->getCode());
630
+ $this->_getTransport()->logKlarnaException($e);
631
+ Mage::throwException(Mage::helper('klarna')->decode($e->getMessage()));
632
  }
633
  return $res;
634
  }
635
 
636
+ public function cancel($reservation_no)
637
  {
638
  try {
639
+ $result = $this->_klarnaApi->cancelReservation($reservation_no);
 
 
 
 
 
 
 
 
 
 
640
 
641
  $res = array(
642
  Vaimo_Klarna_Helper_Data::KLARNA_API_RESPONSE_STATUS => $result,
643
  );
644
 
 
 
 
645
  } catch (KlarnaException $e) {
646
+ $this->_getTransport()->logKlarnaApi('Response Error Code = ' . $e->getCode());
647
+ $this->_getTransport()->logKlarnaException($e);
648
+ Mage::throwException(Mage::helper('klarna')->decode($e->getMessage()));
649
  }
650
  return $res;
651
  }
652
 
653
+ public function release($reservation_no)
654
  {
655
+ return $this->cancel($reservation_no);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
656
  }
657
 
658
+ public function checkStatus($reservation_no)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
659
  {
660
  try {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
661
 
662
+ $result = $this->_klarnaApi->checkOrderStatus($reservation_no);
663
 
664
+ $res = array(
665
+ Vaimo_Klarna_Helper_Data::KLARNA_API_RESPONSE_STATUS => $this->_klarnaReservationStatusToCode($result),
666
+ );
 
 
 
 
 
 
 
 
 
667
 
668
+ } catch (KlarnaException $e) {
669
+ $this->_getTransport()->logKlarnaApi('Response Error Code = ' . $e->getCode());
670
+ $this->_getTransport()->logKlarnaException($e);
671
+ Mage::throwException(Mage::helper('klarna')->decode($e->getMessage()));
 
 
 
 
 
 
672
  }
673
+ return $res;
674
  }
675
 
676
+ public function getAddresses($personal_id)
 
 
 
 
677
  {
678
+ try {
679
+ $res = array();
680
+ $result = $this->_klarnaApi->getAddresses($personal_id);
681
+ foreach ($result as $klarnaAddr) {
682
+ $res[] = array(
683
+ 'company_name' => Mage::helper('klarna')->decode($klarnaAddr->getCompanyName()),
684
+ 'first_name' => Mage::helper('klarna')->decode($klarnaAddr->getFirstName()),
685
+ 'last_name' => Mage::helper('klarna')->decode($klarnaAddr->getLastName()),
686
+ 'street' => Mage::helper('klarna')->decode($klarnaAddr->getStreet()),
687
+ 'zip' => Mage::helper('klarna')->decode($klarnaAddr->getZipCode()),
688
+ 'city' => Mage::helper('klarna')->decode($klarnaAddr->getCity()),
689
+ 'house_number' => Mage::helper('klarna')->decode($klarnaAddr->getHouseNumber()),
690
+ 'house_extension' => Mage::helper('klarna')->decode($klarnaAddr->getHouseExt()),
691
+ 'country_code' => $klarnaAddr->getCountryCode(),
692
+ 'id' => $this->_getAddressKey($klarnaAddr)
693
+ );
694
+ }
695
 
696
+ } catch (KlarnaException $e) {
697
+ $this->_getTransport()->logKlarnaApi('Response Error Code = ' . $e->getCode());
698
+ $this->_getTransport()->logKlarnaException($e);
699
+ Mage::throwException(Mage::helper('klarna')->decode($e->getMessage()));
700
+ }
701
+ return $res;
702
+ }
703
 
704
+ public function getPClasses($onlyCurrentStore = false)
705
+ {
706
+ try {
707
+ $res = array();
708
+
709
+ $pclasses = $this->_klarnaApi->getAllPClasses();
710
+
711
+ if (is_array($pclasses)) {
712
+ foreach ($pclasses as $pclass) {
713
+ if ($onlyCurrentStore) {
714
+ if ($this->_klarnaSetup->getCountryCode()!=KlarnaCountry::getCode($pclass->getCountry())) {
715
+ continue;
716
+ }
717
  }
718
+ $res[] = $pclass;
719
  }
720
  }
721
 
722
+
723
+ } catch (KlarnaException $e) {
724
+ $this->_getTransport()->logKlarnaApi('Response Error Code = ' . $e->getCode());
725
+ $this->_getTransport()->logKlarnaException($e);
726
+ Mage::throwException(Mage::helper('klarna')->decode($e->getMessage()));
727
  }
728
+ return $res;
729
  }
730
 
731
+ public function clearPClasses()
732
  {
733
+ try {
734
+ $this->_klarnaApi->clearPClasses();
 
735
 
736
+ } catch (KlarnaException $e) {
737
+ $this->_getTransport()->logKlarnaApi('Response Error Code = ' . $e->getCode());
738
+ $this->_getTransport()->logKlarnaException($e);
739
+ Mage::throwException(Mage::helper('klarna')->decode($e->getMessage()));
 
 
 
 
 
 
 
740
  }
 
741
  }
742
 
743
+ public function fetchPClasses($storeId)
744
  {
745
+ try {
746
+ $this->_klarnaApi->fetchPClasses($this->_klarnaSetup->getCountryCode(), $this->_klarnaSetup->getLanguageCode(), $this->_klarnaSetup->getCurrencyCode());
 
 
 
 
747
 
748
+ } catch (KlarnaException $e) {
749
+ $this->_getTransport()->logKlarnaApi('Response Error Code = ' . $e->getCode());
750
+ $this->_getTransport()->logKlarnaException($e);
751
+ // Should not be in API file, but I require all details from $e
752
+ Mage::getSingleton('adminhtml/session')->addError(
753
+ Mage::helper('klarna')->__('Fetching PClasses failed for store %s. Error: %s - %s', Mage::app()->getStore($storeId)->getName(), $e->getCode(), $e->getMessage())
754
+ );
755
  }
756
+ }
757
+
758
+ public function getSpecificPClass($id, $amount)
759
+ {
760
+ try {
761
+ $pclasses = $this->getPClasses(true);
762
+ $res = NULL;
763
+ foreach ($pclasses as $pclass) {
764
+ if ($pclass->getId()==$id) {
765
+ $res = $this->_PClassToArray($pclass, $amount);
766
+ break;
767
+ }
768
  }
 
 
 
769
 
770
+ } catch (KlarnaException $e) {
771
+ $this->_getTransport()->logKlarnaApi('Response Error Code = ' . $e->getCode());
772
+ $this->_getTransport()->logKlarnaException($e);
773
+ Mage::throwException(Mage::helper('klarna')->decode($e->getMessage()));
 
 
 
 
774
  }
775
+ return $res;
 
 
776
  }
777
 
778
+ public function getValidCheckoutPClasses($method, $amount)
 
 
 
 
779
  {
780
  try {
781
+ $pclasses = $this->getPClasses(true);
782
+ $pclasses = $this->_filterPClasses($method, $pclasses, KlarnaFlags::CHECKOUT_PAGE, $amount);
 
783
  $default = $this->_getDefaultPClass($pclasses);
784
  $minimum = $this->_getPClassMinimum($pclasses, KlarnaFlags::CHECKOUT_PAGE, $amount);
785
 
793
  }
794
  } catch (Mage_Core_Exception $e) {
795
  $this->logKlarnaException($e);
796
+ Mage::throwException(Mage::helper('klarna')->decode($e->getMessage()));
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
797
  }
798
  return $res;
799
  }
800
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
801
  public function getDisplayAllPClasses()
802
  {
803
  $res = array();
804
+ $pclasses = $this->getPClasses(false);
805
  foreach ($pclasses as $pclass) {
806
  $pclassArr = $pclass->toArray();
807
  switch ($pclass->getCountry()) {
832
  return $res;
833
  }
834
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
835
  /**
836
  * Create a KlarnaAddr from a Magento address
837
  *
839
  *
840
  * @return KlarnaAddr
841
  */
842
+ public function toKlarnaAddress($address)
843
  {
844
  if (!$address) return NULL;
845
 
865
  "",
866
  $address->getTelephone(), // Telno
867
  "", // Cellno
868
+ Mage::helper('klarna')->encode($address->getFirstname()),
869
+ Mage::helper('klarna')->encode($address->getLastname()),
870
  "",
871
+ Mage::helper('klarna')->encode(trim($split["street"])),
872
+ Mage::helper('klarna')->encode($address->getPostcode()),
873
+ Mage::helper('klarna')->encode($address->getCity()),
874
  $address->getCountry(),
875
+ Mage::helper('klarna')->encode(trim($houseNo)),
876
+ Mage::helper('klarna')->encode(trim($houseExt))
877
  );
878
 
879
  $company = $address->getCompany();
880
  if (strlen($company) > 0 && $this->isCompanyAllowed()) {
881
+ $klarnaAddr->setCompanyName(Mage::helper('klarna')->encode($company));
882
  $klarnaAddr->isCompany = true;
883
  } else {
884
  $klarnaAddr->setCompanyName('');
889
  }
890
 
891
  /**
892
+ * Set the addresses on the Klarna object
 
 
 
 
893
  *
894
  * @return void
895
  */
896
+ public function setAddresses($billingAddress, $shippingAddress, $data)
897
  {
898
+ $shipping = $this->toKlarnaAddress($shippingAddress);
899
+ $billing = $this->toKlarnaAddress($billingAddress);
 
 
 
 
 
 
 
 
 
 
900
 
901
+ if (array_key_exists("email", $data)) {
902
+ $email = $data["email"];
903
+ } else {
904
+ $email = "";
 
 
 
 
 
 
905
  }
906
+ $shipping->setEmail($email);
907
+ $billing->setEmail($email);
908
 
909
+ $this->_setReference($data, $shipping, $billing);
 
 
 
 
 
 
 
 
 
 
910
 
911
+ $this->_klarnaApi->setAddress(KlarnaFlags::IS_SHIPPING, $shipping);
912
+ $this->_klarnaApi->setAddress(KlarnaFlags::IS_BILLING, $billing);
 
 
 
 
 
 
 
 
 
 
 
 
 
913
 
914
+ $this->_getTransport()->logDebugInfo('shippingAddress', $shipping->toArray());
915
+ $this->_getTransport()->logDebugInfo('billingAddress', $billing->toArray());
916
 
 
 
 
 
 
917
  }
918
 
919
  /**
921
  *
922
  * @return void
923
  */
924
+ public function setGoodsListReserve()
925
  {
926
+ foreach ($this->_getTransport()->getGoodsList() as $item) {
927
  $this->_addArticle($item);
928
  }
929
+ foreach ($this->_getTransport()->getExtras() as $extra) {
930
  $this->_addArticle($extra);
931
  }
932
  }
937
  *
938
  * @return void
939
  */
940
+ public function setGoodsListCapture($amount)
941
  {
942
+ foreach (array_reverse($this->_getTransport()->getExtras()) as $extra) {
943
  $this->_addArtNo($extra);
944
  }
945
+ foreach (array_reverse($this->_getTransport()->getGoodsList()) as $item) {
946
  $this->_addArtNo($item);
947
  }
948
  }
952
  *
953
  * @return void
954
  */
955
+ protected function _setGoodsListRefund($amount)
956
  {
957
+ foreach ($this->_getTransport()->getGoodsList() as $item) {
958
  $this->_addArtNo($item);
959
  }
960
 
961
+ foreach ($this->_getTransport()->getExtras() as $extra) {
962
  $this->_addArtNo($extra);
963
  }
964
  }
965
 
 
 
 
 
 
 
 
 
 
 
966
  }
app/code/community/Vaimo/Klarna/Model/Creditmemo/Tax.php CHANGED
@@ -25,6 +25,25 @@
25
 
26
  class Vaimo_Klarna_Model_Creditmemo_Tax extends Mage_Sales_Model_Order_Creditmemo_Total_Tax
27
  {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
28
 
29
  /**
30
  * Collect the order total
@@ -40,7 +59,7 @@ class Vaimo_Klarna_Model_Creditmemo_Tax extends Mage_Sales_Model_Order_Creditmem
40
  if ($order && $invoice) {
41
  $payment = $order->getPayment();
42
  if ($payment) {
43
- if (!Mage::helper('klarna')->isMethodKlarna($payment->getMethod())) {
44
  return $this;
45
  }
46
  $info = $payment->getMethodInstance()->getInfoInstance();
25
 
26
  class Vaimo_Klarna_Model_Creditmemo_Tax extends Mage_Sales_Model_Order_Creditmemo_Total_Tax
27
  {
28
+ protected $_moduleHelper = NULL;
29
+
30
+ /**
31
+ * constructor
32
+ *
33
+ * @param $moduleHelper
34
+ */
35
+ public function __construct($moduleHelper = NULL)
36
+ {
37
+ $this->_moduleHelper = $moduleHelper;
38
+ if ($this->_moduleHelper==NULL) {
39
+ $this->_moduleHelper = Mage::helper('klarna');
40
+ }
41
+ }
42
+
43
+ protected function _getHelper()
44
+ {
45
+ return $this->_moduleHelper;
46
+ }
47
 
48
  /**
49
  * Collect the order total
59
  if ($order && $invoice) {
60
  $payment = $order->getPayment();
61
  if ($payment) {
62
+ if (!$this->_getHelper()->isMethodKlarna($payment->getMethod())) {
63
  return $this;
64
  }
65
  $info = $payment->getMethodInstance()->getInfoInstance();
app/code/community/Vaimo/Klarna/Model/Creditmemo/Total.php CHANGED
@@ -25,6 +25,35 @@
25
 
26
  class Vaimo_Klarna_Model_Creditmemo_Total extends Mage_Sales_Model_Order_Creditmemo_Total_Abstract
27
  {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
28
 
29
  /**
30
  * Collect the order total
@@ -42,8 +71,8 @@ class Vaimo_Klarna_Model_Creditmemo_Total extends Mage_Sales_Model_Order_Creditm
42
  */
43
  $order = $creditmemo->getOrder();
44
  $invoice = $creditmemo->getInvoice();
45
- if (Mage::getSingleton('admin/session')->isLoggedIn()) {
46
- $data = Mage::app()->getRequest()->getParam('creditmemo');
47
  if ($data) {
48
  if (isset($data['vaimo_klarna_fee_refund'])) {
49
  if ($data['vaimo_klarna_fee_refund']=='') {
@@ -61,12 +90,12 @@ class Vaimo_Klarna_Model_Creditmemo_Total extends Mage_Sales_Model_Order_Creditm
61
  if ($order) {
62
  $payment = $order->getPayment();
63
  if ($payment) {
64
- if (!Mage::helper('klarna')->isMethodKlarna($payment->getMethod())) {
65
  return $this;
66
  }
67
  if (!$invoice) {
68
  Mage::getSingleton('adminhtml/session')->addError(
69
- Mage::helper('klarna')->__('You must create the credit memo from the invoice, not directly from the order, to update Klarna with the credited amount/items')
70
  );
71
  return $this;
72
  }
25
 
26
  class Vaimo_Klarna_Model_Creditmemo_Total extends Mage_Sales_Model_Order_Creditmemo_Total_Abstract
27
  {
28
+ protected $_moduleHelper = NULL;
29
+
30
+ /**
31
+ * constructor
32
+ *
33
+ * @param $moduleHelper
34
+ */
35
+ public function __construct($moduleHelper = NULL)
36
+ {
37
+ $this->_moduleHelper = $moduleHelper;
38
+ if ($this->_moduleHelper==NULL) {
39
+ $this->_moduleHelper = Mage::helper('klarna');
40
+ }
41
+ }
42
+
43
+ protected function _getHelper()
44
+ {
45
+ return $this->_moduleHelper;
46
+ }
47
+
48
+ protected function _isLoggedIn()
49
+ {
50
+ return Mage::getSingleton('admin/session')->isLoggedIn();
51
+ }
52
+
53
+ protected function _getRequest($param)
54
+ {
55
+ return Mage::app()->getRequest()->getParam($param);
56
+ }
57
 
58
  /**
59
  * Collect the order total
71
  */
72
  $order = $creditmemo->getOrder();
73
  $invoice = $creditmemo->getInvoice();
74
+ if ($this->_isLoggedIn()) {
75
+ $data = $this->_getRequest('creditmemo');
76
  if ($data) {
77
  if (isset($data['vaimo_klarna_fee_refund'])) {
78
  if ($data['vaimo_klarna_fee_refund']=='') {
90
  if ($order) {
91
  $payment = $order->getPayment();
92
  if ($payment) {
93
+ if (!$this->_getHelper()->isMethodKlarna($payment->getMethod())) {
94
  return $this;
95
  }
96
  if (!$invoice) {
97
  Mage::getSingleton('adminhtml/session')->addError(
98
+ $this->_getHelper()->__('You must create the credit memo from the invoice, not directly from the order, to update Klarna with the credited amount/items')
99
  );
100
  return $this;
101
  }
app/code/community/Vaimo/Klarna/Model/Invoice/Pdf/Total.php CHANGED
@@ -25,6 +25,52 @@
25
 
26
  class Vaimo_Klarna_Model_Invoice_Pdf_Total extends Mage_Sales_Model_Order_Pdf_Total_Default
27
  {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
28
  public function getTotalsForDisplay()
29
  {
30
  $amount = $this->getAmount();
@@ -33,7 +79,7 @@ class Vaimo_Klarna_Model_Invoice_Pdf_Total extends Mage_Sales_Model_Order_Pdf_To
33
  $amount = $this->getAmountPrefix() . $amount;
34
  }
35
 
36
- $label = Mage::helper('klarna')->__($this->getTitle()) . ':';
37
  $fontSize = $this->getFontSize() ? $this->getFontSize() : 7;
38
 
39
  $info = $this->getOrder()->getPayment()->getMethodInstance()->getInfoInstance();
@@ -42,7 +88,7 @@ class Vaimo_Klarna_Model_Invoice_Pdf_Total extends Mage_Sales_Model_Order_Pdf_To
42
  $amountInclTax = $this->getOrder()->formatPriceTxt($amountInclTax);
43
 
44
  $store = $this->getOrder()->getStore();
45
- $config = Mage::getSingleton('klarna/tax_config');
46
  if ($config->displaySalesKlarnaFeeInclTax($store->getId())) {
47
  $totals = array(array(
48
  'amount' => $amountInclTax,
@@ -53,12 +99,12 @@ class Vaimo_Klarna_Model_Invoice_Pdf_Total extends Mage_Sales_Model_Order_Pdf_To
53
  $totals = array(
54
  array(
55
  'amount' => $amount,
56
- 'label' => Mage::helper('tax')->__('Invoice fee (Excl. Tax)') . ':',
57
  'font_size' => $fontSize
58
  ),
59
  array(
60
  'amount' => $amountInclTax,
61
- 'label' => Mage::helper('tax')->__('Invoice fee (Incl. Tax)') . ':',
62
  'font_size' => $fontSize
63
  ),
64
  );
25
 
26
  class Vaimo_Klarna_Model_Invoice_Pdf_Total extends Mage_Sales_Model_Order_Pdf_Total_Default
27
  {
28
+ protected $_moduleHelper = NULL;
29
+
30
+ protected $_taxConfig = NULL;
31
+
32
+ /**
33
+ * constructor
34
+ *
35
+ * @param $moduleHelper
36
+ * @param $taxHelper
37
+ * @param $taxConfig
38
+ */
39
+ public function __construct($moduleHelper = NULL, $taxHelper = NULL)
40
+ {
41
+ $this->_moduleHelper = $moduleHelper;
42
+ if ($this->_moduleHelper==NULL) {
43
+ $this->_moduleHelper = Mage::helper('klarna');
44
+ }
45
+ $this->_taxHelper = $taxHelper;
46
+ if ($this->_taxHelper==NULL) {
47
+ $this->_taxHelper = Mage::helper('tax');
48
+ }
49
+ }
50
+
51
+ protected function _getHelper()
52
+ {
53
+ return $this->_moduleHelper;
54
+ }
55
+
56
+ protected function _getTaxHelper()
57
+ {
58
+ return $this->_taxHelper;
59
+ }
60
+
61
+ public function setTaxConfig($confObj)
62
+ {
63
+ $this->_taxConfig = $confObj;
64
+ }
65
+
66
+ protected function _getTaxConfig()
67
+ {
68
+ if ($this->_taxConfig==NULL) {
69
+ $this->_taxConfig = Mage::getSingleton('klarna/tax_config');
70
+ }
71
+ return $this->_taxConfig;
72
+ }
73
+
74
  public function getTotalsForDisplay()
75
  {
76
  $amount = $this->getAmount();
79
  $amount = $this->getAmountPrefix() . $amount;
80
  }
81
 
82
+ $label = $this->_getHelper()->__($this->getTitle()) . ':';
83
  $fontSize = $this->getFontSize() ? $this->getFontSize() : 7;
84
 
85
  $info = $this->getOrder()->getPayment()->getMethodInstance()->getInfoInstance();
88
  $amountInclTax = $this->getOrder()->formatPriceTxt($amountInclTax);
89
 
90
  $store = $this->getOrder()->getStore();
91
+ $config = $this->_getTaxConfig();
92
  if ($config->displaySalesKlarnaFeeInclTax($store->getId())) {
93
  $totals = array(array(
94
  'amount' => $amountInclTax,
99
  $totals = array(
100
  array(
101
  'amount' => $amount,
102
+ 'label' => $this->_getTaxHelper()->__('Invoice fee (Excl. Tax)') . ':',
103
  'font_size' => $fontSize
104
  ),
105
  array(
106
  'amount' => $amountInclTax,
107
+ 'label' => $this->_getTaxHelper()->__('Invoice fee (Incl. Tax)') . ':',
108
  'font_size' => $fontSize
109
  ),
110
  );
app/code/community/Vaimo/Klarna/Model/Invoice/Tax.php CHANGED
@@ -25,6 +25,26 @@
25
 
26
  class Vaimo_Klarna_Model_Invoice_Tax extends Mage_Sales_Model_Order_Invoice_Total_Abstract
27
  {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
28
  public function collect(Mage_Sales_Model_Order_Invoice $invoice)
29
  {
30
  $order = $invoice->getOrder();
@@ -39,7 +59,7 @@ class Vaimo_Klarna_Model_Invoice_Tax extends Mage_Sales_Model_Order_Invoice_Tota
39
  return $this;
40
  }
41
 
42
- if (!Mage::helper('klarna')->isMethodKlarna($payment->getMethod())) {
43
  return $this;
44
  }
45
 
@@ -49,7 +69,7 @@ class Vaimo_Klarna_Model_Invoice_Tax extends Mage_Sales_Model_Order_Invoice_Tota
49
  return $this;
50
  }
51
 
52
- if (!Mage::helper('klarna')->collectInvoiceAddTaxToInvoice()) {
53
  return $this;
54
  }
55
 
25
 
26
  class Vaimo_Klarna_Model_Invoice_Tax extends Mage_Sales_Model_Order_Invoice_Total_Abstract
27
  {
28
+ protected $_moduleHelper = NULL;
29
+
30
+ /**
31
+ * constructor
32
+ *
33
+ * @param $moduleHelper
34
+ */
35
+ public function __construct($moduleHelper = NULL)
36
+ {
37
+ $this->_moduleHelper = $moduleHelper;
38
+ if ($this->_moduleHelper==NULL) {
39
+ $this->_moduleHelper = Mage::helper('klarna');
40
+ }
41
+ }
42
+
43
+ protected function _getHelper()
44
+ {
45
+ return $this->_moduleHelper;
46
+ }
47
+
48
  public function collect(Mage_Sales_Model_Order_Invoice $invoice)
49
  {
50
  $order = $invoice->getOrder();
59
  return $this;
60
  }
61
 
62
+ if (!$this->_getHelper()->isMethodKlarna($payment->getMethod())) {
63
  return $this;
64
  }
65
 
69
  return $this;
70
  }
71
 
72
+ if (!$this->_getHelper()->collectInvoiceAddTaxToInvoice()) {
73
  return $this;
74
  }
75
 
app/code/community/Vaimo/Klarna/Model/Invoice/Total.php CHANGED
@@ -25,6 +25,26 @@
25
 
26
  class Vaimo_Klarna_Model_Invoice_Total extends Mage_Sales_Model_Order_Invoice_Total_Abstract
27
  {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
28
  public function collect(Mage_Sales_Model_Order_Invoice $invoice)
29
  {
30
  $order = $invoice->getOrder();
@@ -39,7 +59,7 @@ class Vaimo_Klarna_Model_Invoice_Total extends Mage_Sales_Model_Order_Invoice_To
39
  return $this;
40
  }
41
 
42
- if (!Mage::helper('klarna')->isMethodKlarna($payment->getMethod())) {
43
  return $this;
44
  }
45
 
@@ -62,7 +82,7 @@ class Vaimo_Klarna_Model_Invoice_Total extends Mage_Sales_Model_Order_Invoice_To
62
  $baseInvoiceTotal = $invoice->getBaseGrandTotal();
63
  $invoiceTotal = $invoice->getGrandTotal();
64
 
65
- if (Mage::helper('klarna')->collectInvoiceAddTaxToInvoice()) {
66
  $baseInvoiceTotal = $baseInvoiceTotal + $baseKlarnaFee + $baseKlarnaFeeTax;
67
  $invoiceTotal = $invoiceTotal + $klarnaFee + $klarnaFeeTax;
68
  } else {
25
 
26
  class Vaimo_Klarna_Model_Invoice_Total extends Mage_Sales_Model_Order_Invoice_Total_Abstract
27
  {
28
+ protected $_moduleHelper = NULL;
29
+
30
+ /**
31
+ * constructor
32
+ *
33
+ * @param $moduleHelper
34
+ */
35
+ public function __construct($moduleHelper = NULL)
36
+ {
37
+ $this->_moduleHelper = $moduleHelper;
38
+ if ($this->_moduleHelper==NULL) {
39
+ $this->_moduleHelper = Mage::helper('klarna');
40
+ }
41
+ }
42
+
43
+ protected function _getHelper()
44
+ {
45
+ return $this->_moduleHelper;
46
+ }
47
+
48
  public function collect(Mage_Sales_Model_Order_Invoice $invoice)
49
  {
50
  $order = $invoice->getOrder();
59
  return $this;
60
  }
61
 
62
+ if (!$this->_getHelper()->isMethodKlarna($payment->getMethod())) {
63
  return $this;
64
  }
65
 
82
  $baseInvoiceTotal = $invoice->getBaseGrandTotal();
83
  $invoiceTotal = $invoice->getGrandTotal();
84
 
85
+ if ($this->_getHelper()->collectInvoiceAddTaxToInvoice()) {
86
  $baseInvoiceTotal = $baseInvoiceTotal + $baseKlarnaFee + $baseKlarnaFeeTax;
87
  $invoiceTotal = $invoiceTotal + $klarnaFee + $klarnaFeeTax;
88
  } else {
app/code/community/Vaimo/Klarna/Model/Klarna.php ADDED
@@ -0,0 +1,586 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Copyright (c) 2009-2014 Vaimo AB
4
+ *
5
+ * Vaimo reserves all rights in the Program as delivered. The Program
6
+ * or any portion thereof may not be reproduced in any form whatsoever without
7
+ * the written consent of Vaimo, except as provided by licence. A licence
8
+ * under Vaimo's rights in the Program may be available directly from
9
+ * Vaimo.
10
+ *
11
+ * Disclaimer:
12
+ * THIS NOTICE MAY NOT BE REMOVED FROM THE PROGRAM BY ANY USER THEREOF.
13
+ * THE PROGRAM IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
14
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
16
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ * OUT OF OR IN CONNECTION WITH THE PROGRAM OR THE USE OR OTHER DEALINGS
19
+ * IN THE PROGRAM.
20
+ *
21
+ * @category Vaimo
22
+ * @package Vaimo_Klarna
23
+ * @copyright Copyright (c) 2009-2014 Vaimo AB
24
+ */
25
+
26
+ /*
27
+ *
28
+ * This is the only file in the module that loads and uses the Klarna library folder
29
+ * It should never be instantiated by itself, it can, but for readability one should not
30
+ * No Klarna specific variables, constants or functions should be used outside this class
31
+ *
32
+ */
33
+ class Vaimo_Klarna_Model_Klarna extends Vaimo_Klarna_Model_Klarna_Abstract
34
+ {
35
+ protected $_api = NULL;
36
+
37
+ protected static $_session_key = 'klarna_address';
38
+
39
+ public function __construct($setStoreInfo = true, $moduleHelper = NULL, $entGWHelper = NULL, $salesHelper = NULL, $taxCalculation = NULL)
40
+ {
41
+ parent::__construct($setStoreInfo, $moduleHelper, $entGWHelper, $salesHelper, $taxCalculation);
42
+ $this->_setFunctionName('klarna');
43
+ }
44
+
45
+ /**
46
+ * Function added for Unit testing
47
+ *
48
+ * @param Vaimo_Klarna_Model_Api_Abstract $apiObject
49
+ */
50
+ public function setApi(Vaimo_Klarna_Model_Api_Abstract $apiObject)
51
+ {
52
+ $this->_api = $apiObject;
53
+ }
54
+
55
+ /**
56
+ * Will return the API object, it set, otherwise null
57
+ *
58
+ * @return Vaimo_Klarna_Model_Api_Xmlrpc|Vaimo_Klarna_Model_Api_Rest|Vaimo_Klarna_Model_Api_Kco
59
+ */
60
+ public function getApi()
61
+ {
62
+ return $this->_api;
63
+ }
64
+
65
+ /**
66
+ * Could have been added to getApi, but I made it separate for Unit testing
67
+ *
68
+ * @param $storeId
69
+ * @param $method
70
+ * @param $functionName
71
+ */
72
+ protected function _initApi($storeId, $method, $functionName)
73
+ {
74
+ if (!$this->getApi()) {
75
+ /** @var Vaimo_Klarna_Model_Api $klarnaApiModel */
76
+ $klarnaApiModel = Mage::getModel('klarna/api');
77
+ $this->setApi($klarnaApiModel->getApiInstance($storeId, $method, $functionName));
78
+ }
79
+ }
80
+
81
+ /**
82
+ * Init funcition
83
+ *
84
+ * @todo If storeid is null, we need to find first store where Klarna is active, not just trust that default store has it active...
85
+ */
86
+ protected function _init($functionName)
87
+ {
88
+ $this->_setFunctionName($this->_getFunctionName() . '-' . $functionName);
89
+ $this->_initApi($this->_getStoreId(), $this->getMethod(), $functionName);
90
+ $this->getApi()->init($this->getKlarnaSetup());
91
+ $this->getApi()->setTransport($this->_getTransport());
92
+ }
93
+
94
+ public function reserve($amount)
95
+ {
96
+ try {
97
+ $this->_init(Vaimo_Klarna_Helper_Data::KLARNA_API_CALL_RESERVE);
98
+ $this->_setAdditionalInformation($this->getPayment()->getAdditionalInformation());
99
+ $items = $this->getPayment()->getKlarnaItemList();
100
+ $this->_createGoodsList($items);
101
+ $this->logKlarnaApi('Call with personal ID ' . $this->getPNO());
102
+
103
+ $this->getApi()->setGoodsListReserve();
104
+ $this->getApi()->setAddresses($this->getBillingAddress(), $this->getShippingAddress(), $this->_getAdditionalInformation());
105
+ $res = $this->getApi()->reserve();
106
+
107
+ $this->logKlarnaApi('Response ' . $res[Vaimo_Klarna_Helper_Data::KLARNA_API_RESPONSE_STATUS] . ' - ' . $res[Vaimo_Klarna_Helper_Data::KLARNA_API_RESPONSE_TRANSACTION_ID]);
108
+ if ($res[Vaimo_Klarna_Helper_Data::KLARNA_API_RESPONSE_STATUS]==Vaimo_Klarna_Helper_Data::KLARNA_STATUS_PENDING) {
109
+ if ($this->getConfigData("pending_status_action")) {
110
+ $this->cancel($res[Vaimo_Klarna_Helper_Data::KLARNA_API_RESPONSE_TRANSACTION_ID]);
111
+ Mage::throwException($this->_getHelper()->__('Unable to pay with Klarna, please choose another payment method'));
112
+ }
113
+ }
114
+
115
+ $this->_getHelper()->dispatchMethodEvent($this->getOrder(), Vaimo_Klarna_Helper_Data::KLARNA_DISPATCH_RESERVED, $this->getOrder()->getTotalDue(), $this->getMethod());
116
+
117
+ $this->_cleanAdditionalInfo();
118
+
119
+ } catch (KlarnaException $e) {
120
+ Mage::throwException($e->getMessage());
121
+ }
122
+ return $res;
123
+ }
124
+
125
+ public function capture($amount)
126
+ {
127
+ try {
128
+ $this->_init(Vaimo_Klarna_Helper_Data::KLARNA_API_CALL_CAPTURE);
129
+ $this->_setAdditionalInformation($this->getPayment()->getAdditionalInformation());
130
+ $items = $this->getPayment()->getKlarnaItemList();
131
+ $this->_createGoodsList($items);
132
+
133
+ $reservation_no = $this->_getReservationNo();
134
+ $this->logKlarnaApi('Call with reservation ID ' . $reservation_no);
135
+
136
+ $this->getApi()->setGoodsListCapture($amount);
137
+ $this->getApi()->setAddresses($this->getBillingAddress(), $this->getShippingAddress(), $this->_getAdditionalInformation());
138
+ $res = $this->getApi()->capture($reservation_no, $amount, $this->getConfigData("send_klarna_email"));
139
+
140
+ $res[Vaimo_Klarna_Helper_Data::KLARNA_API_RESPONSE_FEE_CAPTURED] = $this->_feeAmountIncluded();
141
+
142
+ $this->_getHelper()->dispatchMethodEvent($this->getOrder(), Vaimo_Klarna_Helper_Data::KLARNA_DISPATCH_CAPTURED, $this->getOrder()->getTotalDue(), $this->getMethod());
143
+
144
+ $this->logKlarnaApi('Response ' . $res[Vaimo_Klarna_Helper_Data::KLARNA_API_RESPONSE_STATUS] . ' - ' . $res[Vaimo_Klarna_Helper_Data::KLARNA_API_RESPONSE_TRANSACTION_ID]);
145
+ } catch (KlarnaException $e) {
146
+ Mage::throwException($e->getMessage());
147
+ }
148
+ return $res;
149
+ }
150
+
151
+ public function refund($amount)
152
+ {
153
+ try {
154
+ $this->_init(Vaimo_Klarna_Helper_Data::KLARNA_API_CALL_REFUND);
155
+ $invoice_no = $this->getInfoInstance()->getParentTransactionId();
156
+ $this->_setAdditionalInformation($this->getInfoInstance()->getAdditionalInformation());
157
+ $items = $this->getPayment()->getKlarnaItemList();
158
+ $this->_createRefundGoodsList($items);
159
+
160
+ $res = $this->getApi()->refund($amount, $invoice_no);
161
+
162
+ $res[Vaimo_Klarna_Helper_Data::KLARNA_API_RESPONSE_FEE_REFUNDED] = $this->_feeAmountIncluded();
163
+
164
+ $this->_getHelper()->dispatchMethodEvent($this->getOrder(), Vaimo_Klarna_Helper_Data::KLARNA_DISPATCH_REFUNDED, $amount, $this->getMethod());
165
+
166
+ $this->logKlarnaApi('Response ' . $res[Vaimo_Klarna_Helper_Data::KLARNA_API_RESPONSE_STATUS] . ' - ' . $res[Vaimo_Klarna_Helper_Data::KLARNA_API_RESPONSE_TRANSACTION_ID]);
167
+ } catch (KlarnaException $e) {
168
+ Mage::throwException($e->getMessage());
169
+ }
170
+ return $res;
171
+ }
172
+
173
+ public function cancel($direct_rno = NULL)
174
+ {
175
+ try {
176
+ $this->_init(Vaimo_Klarna_Helper_Data::KLARNA_API_CALL_CANCEL);
177
+ $this->_setAdditionalInformation($this->getPayment()->getAdditionalInformation());
178
+
179
+ if ($direct_rno) {
180
+ $reservation_no = $direct_rno;
181
+ } else {
182
+ $reservation_no = $this->_getReservationNo();
183
+ }
184
+ $this->logKlarnaApi('Call with reservation ID ' . $reservation_no);
185
+
186
+ if ($this->getOrder()->getTotalPaid()>0) {
187
+ $res = $this->getApi()->release($reservation_no);
188
+ } else {
189
+ $res = $this->getApi()->cancel($reservation_no);
190
+ }
191
+
192
+ $this->_getHelper()->dispatchMethodEvent($this->getOrder(), Vaimo_Klarna_Helper_Data::KLARNA_DISPATCH_CANCELED, $this->getOrder()->getTotalDue(), $this->getMethod());
193
+
194
+ $this->logKlarnaApi('Response ' . $res[Vaimo_Klarna_Helper_Data::KLARNA_API_RESPONSE_STATUS]);
195
+ } catch (KlarnaException $e) {
196
+ Mage::throwException($e->getMessage());
197
+ }
198
+ return $res;
199
+ }
200
+
201
+ public function checkStatus()
202
+ {
203
+ try {
204
+ $this->_init(Vaimo_Klarna_Helper_Data::KLARNA_API_CALL_CHECKSTATUS);
205
+ $this->_setAdditionalInformation($this->getPayment()->getAdditionalInformation());
206
+
207
+ $reservation_no = $this->_getReservationNo();
208
+ $this->logKlarnaApi('Call with reservation ID ' . $reservation_no);
209
+
210
+ $res = $this->getApi()->checkStatus($reservation_no);
211
+
212
+ $this->logKlarnaApi('Response ' . $res[Vaimo_Klarna_Helper_Data::KLARNA_API_RESPONSE_STATUS]);
213
+ } catch (KlarnaException $e) {
214
+ Mage::throwException($e->getMessage());
215
+ }
216
+ return $res;
217
+ }
218
+
219
+ /*
220
+ * I have copied the cache function from previous Klarna module, it's only for this session
221
+ *
222
+ * @return array
223
+ */
224
+ public function getAddresses($personal_id)
225
+ {
226
+ try {
227
+ $cache = array();
228
+
229
+ if (array_key_exists(self::$_session_key, $_SESSION)) {
230
+ $cache = unserialize( base64_decode($_SESSION[self::$_session_key]) );
231
+ }
232
+ if (array_key_exists($personal_id, $cache)) {
233
+ return $cache[$personal_id];
234
+ }
235
+
236
+ $this->_init(Vaimo_Klarna_Helper_Data::KLARNA_API_CALL_ADDRESSES);
237
+ $this->logKlarnaApi('Call with Personal ID ' . $personal_id);
238
+
239
+ $res = $this->getApi()->getAddresses($personal_id);
240
+
241
+ $this->logKlarnaApi('Response ' .'OK');
242
+
243
+ $cache[$personal_id] = $res;
244
+ $_SESSION[self::$_session_key] = base64_encode( serialize($cache) );
245
+
246
+ } catch (KlarnaException $e) {
247
+ Mage::throwException($e->getMessage());
248
+ }
249
+ return $res;
250
+ }
251
+
252
+ /**
253
+ * Update addresses with data from our checkout box
254
+ *
255
+ * @return void
256
+ */
257
+ public function updateAssignAddress()
258
+ {
259
+ /*
260
+ * getAddress is only allowed in Sweden, so this code is for Sweden only
261
+ */
262
+ if ($this->useGetAddresses()) {
263
+ if (!$this->getPostValues('pno') || !$this->getPostValues('address_id')) {
264
+ /*
265
+ * OneStepCheckout saves payment method upon load, which means an error message must not be produced
266
+ * in this function. Authorize will attempt to use the value and give an error message, which means
267
+ * it will be checked and reported anyway
268
+ */
269
+ if (!$this->_getHelper()->isOneStepCheckout()) {
270
+ Mage::throwException($this->_getHelper()->__(
271
+ 'Unknown address, please specify correct personal id in the payment selection and press Fetch again, or use another payment method'
272
+ )
273
+ );
274
+ }
275
+ }
276
+ if ($this->getPostValues('pno') && $this->getPostValues('address_id')) {
277
+ $addr = $this->_getSelectedAddress($this->getPostValues('pno'), $this->getPostValues('address_id'));
278
+ if ($addr!=NULL) {
279
+ /*
280
+ * This is not approved by Klarna, so address will be updated only when order is placed. This is NOT a bug.
281
+ */
282
+ // $this->_updateShippingWithSelectedAddress($addr);
283
+ } else {
284
+ /*
285
+ * No error message here if using OneStepCheckout
286
+ */
287
+ if (!$this->_getHelper()->isOneStepCheckout()) {
288
+ Mage::throwException($this->_getHelper()->__(
289
+ 'Unknown address, please specify correct personal id in the payment selection and press Fetch again, or use another payment method'
290
+ )
291
+ );
292
+ }
293
+ }
294
+ }
295
+ }
296
+
297
+ /*
298
+ * Update the addresses with values from the checkout
299
+ */
300
+ $this->_updateAddress($this->getShippingAddress());
301
+ $this->_updateAddress($this->getBillingAddress(), 'phonenumber');
302
+
303
+ }
304
+
305
+ /**
306
+ * Update addresses with data from our checkout box
307
+ *
308
+ * @return void
309
+ */
310
+ public function updateAuthorizeAddress()
311
+ {
312
+ //Update with the getAddress call for Swedish customers
313
+ if ($this->useGetAddresses()) {
314
+ $addr = $this->_getSelectedAddress($this->getPayment()->getAdditionalInformation('pno'), $this->getPayment()->getAdditionalInformation('address_id'));
315
+ if ($addr!=NULL) {
316
+ $this->_updateShippingWithSelectedAddress($addr);
317
+ } else {
318
+ Mage::throwException($this->_getHelper()->__('Unknown address, please specify correct personal id in the payment selection and press Fetch again, or use another payment method'));
319
+ }
320
+ }
321
+
322
+ //Check to see if the addresses must be same. If so overwrite billing
323
+ //address with the shipping address.
324
+ if ($this->shippingSameAsBilling()) {
325
+ $this->updateBillingAddress();
326
+ }
327
+ }
328
+
329
+ /**
330
+ * Get a matching address using getAddresses
331
+ *
332
+ * @return array
333
+ */
334
+ protected function _getSelectedAddress($pno, $address_id)
335
+ {
336
+ try {
337
+ $addresses = $this->getAddresses($pno);
338
+ foreach ($addresses as $address) {
339
+ if ($address['id']==$address_id) {
340
+ return $address;
341
+ }
342
+ }
343
+ } catch (Mage_Core_Exception $e) {
344
+ $this->logKlarnaException($e);
345
+ return NULL;
346
+ }
347
+ return NULL;
348
+ }
349
+
350
+ /*
351
+ *
352
+ *
353
+ */
354
+ public function reloadAllPClasses()
355
+ {
356
+ try {
357
+ $countries = $this->_getKlarnaActiveStores();
358
+
359
+ $this->_init(Vaimo_Klarna_Helper_Data::KLARNA_API_CALL_PCLASSES);
360
+
361
+ $this->logKlarnaApi('Call clear');
362
+ $this->getApi()->clearPClasses();
363
+ $this->logKlarnaApi('Call clear OK');
364
+
365
+ } catch (KlarnaException $e) {
366
+ Mage::throwException($e->getMessage());
367
+ }
368
+
369
+ foreach ($countries as $storeId) {
370
+ try {
371
+ $this->setStoreInformation($storeId);
372
+ $this->_init(Vaimo_Klarna_Helper_Data::KLARNA_API_CALL_PCLASSES); // Need to call it again because we now have new storeId
373
+
374
+ $this->logKlarnaApi('Call fetch all');
375
+ $this->getApi()->fetchPClasses($storeId);
376
+ $this->logKlarnaApi('Call fetch all OK');
377
+
378
+ } catch (KlarnaException $e) {
379
+ Mage::throwException($e->getMessage());
380
+ }
381
+ }
382
+ }
383
+
384
+ /*
385
+ *
386
+ *
387
+ */
388
+ public function getValidCheckoutPClasses($method)
389
+ {
390
+ try {
391
+ $this->_init(Vaimo_Klarna_Helper_Data::KLARNA_API_CALL_PCLASSES);
392
+ $amount = $this->getQuote()->getGrandTotal();
393
+ $res = $this->getApi()->getValidCheckoutPClasses($method, $amount);
394
+ } catch (Mage_Core_Exception $e) {
395
+ Mage::throwException($e->getMessage());
396
+ }
397
+ return $res;
398
+ }
399
+
400
+ /*
401
+ *
402
+ *
403
+ */
404
+ protected function _getSpecificPClass($id)
405
+ {
406
+ try {
407
+ $this->_init(Vaimo_Klarna_Helper_Data::KLARNA_API_CALL_PCLASSES);
408
+ $amount = $this->getQuote()->getGrandTotal();
409
+ $this->logKlarnaApi('Call get specific');
410
+
411
+ $res = $this->getApi()->getSpecificPClass($id, $amount);
412
+
413
+ $this->logKlarnaApi('Response OK');
414
+ } catch (Mage_Core_Exception $e) {
415
+ $this->logKlarnaException($e);
416
+ }
417
+ return $res;
418
+ }
419
+
420
+ /*
421
+ *
422
+ *
423
+ */
424
+ public function getDisplayAllPClasses()
425
+ {
426
+ try {
427
+ $this->_init(Vaimo_Klarna_Helper_Data::KLARNA_API_CALL_PCLASSES);
428
+ $this->logKlarnaApi('Call get display all');
429
+
430
+ $res = $this->getApi()->getDisplayAllPClasses();
431
+
432
+ $this->logKlarnaApi('Response OK');
433
+ } catch (Mage_Core_Exception $e) {
434
+ Mage::throwException($e->getMessage());
435
+ }
436
+ return $res;
437
+ }
438
+
439
+ public function getPClassDetails($id)
440
+ {
441
+ $pclassArray = $this->_getSpecificPClass($id);
442
+ $res = new Varien_Object($pclassArray);
443
+ return $res;
444
+ }
445
+
446
+ public function setPaymentPlan()
447
+ {
448
+ $id = $this->getPostValues(Vaimo_Klarna_Helper_Data::KLARNA_INFO_FIELD_PAYMENT_PLAN);
449
+ $method = $this->getPostValues('method');
450
+ if ($id) {
451
+ $pclassArray = $this->_getSpecificPClass($id);
452
+ if (!$pclassArray) {
453
+ Mage::throwException($this->_getHelper()->__('Unexpected error, pclass does not exist, please reload page and try again'));
454
+ }
455
+ $this->addPostValues(array(
456
+ Vaimo_Klarna_Helper_Data::KLARNA_INFO_FIELD_PAYMENT_PLAN_DESCRIPTION => $pclassArray['description'],
457
+ Vaimo_Klarna_Helper_Data::KLARNA_INFO_FIELD_PAYMENT_PLAN_MONTHLY_COST => $pclassArray['monthly_cost'],
458
+ Vaimo_Klarna_Helper_Data::KLARNA_INFO_FIELD_PAYMENT_PLAN_TOTAL_COST => $pclassArray['total_cost'],
459
+ Vaimo_Klarna_Helper_Data::KLARNA_INFO_FIELD_PAYMENT_PLAN_INVOICE_FEE => $pclassArray['invoicefee'],
460
+ Vaimo_Klarna_Helper_Data::KLARNA_INFO_FIELD_PAYMENT_PLAN_START_FEE => $pclassArray['startfee'],
461
+ Vaimo_Klarna_Helper_Data::KLARNA_INFO_FIELD_PAYMENT_PLAN_MONTHS => $pclassArray['months'],
462
+ Vaimo_Klarna_Helper_Data::KLARNA_INFO_FIELD_PAYMENT_PLAN_TYPE => $pclassArray['type'],
463
+ ));
464
+ } else {
465
+ if ($method==Vaimo_Klarna_Helper_Data::KLARNA_METHOD_ACCOUNT || $method==Vaimo_Klarna_Helper_Data::KLARNA_METHOD_SPECIAL ) {
466
+ Mage::throwException($this->_getHelper()->__('You must choose a payment plan'));
467
+ }
468
+ $this->addPostValues(array(
469
+ Vaimo_Klarna_Helper_Data::KLARNA_INFO_FIELD_PAYMENT_PLAN_DESCRIPTION => '',
470
+ Vaimo_Klarna_Helper_Data::KLARNA_INFO_FIELD_PAYMENT_PLAN_MONTHLY_COST => '',
471
+ Vaimo_Klarna_Helper_Data::KLARNA_INFO_FIELD_PAYMENT_PLAN_TOTAL_COST => '',
472
+ Vaimo_Klarna_Helper_Data::KLARNA_INFO_FIELD_PAYMENT_PLAN_INVOICE_FEE => '',
473
+ Vaimo_Klarna_Helper_Data::KLARNA_INFO_FIELD_PAYMENT_PLAN_START_FEE => '',
474
+ Vaimo_Klarna_Helper_Data::KLARNA_INFO_FIELD_PAYMENT_PLAN_MONTHS => '',
475
+ Vaimo_Klarna_Helper_Data::KLARNA_INFO_FIELD_PAYMENT_PLAN_TYPE => '',
476
+ Vaimo_Klarna_Helper_Data::KLARNA_INFO_FIELD_PAYMENT_PLAN => '',
477
+ ));
478
+ }
479
+ }
480
+
481
+ /**
482
+ * Create a KlarnaAddr from a Magento address
483
+ *
484
+ * @param object $address The Magento address to convert
485
+ *
486
+ * @return KlarnaAddr
487
+ */
488
+ public function toKlarnaAddress($address)
489
+ {
490
+ try {
491
+ $this->_init(Vaimo_Klarna_Helper_Data::KLARNA_API_CALL_ADDRESSES);
492
+ $res = $this->getApi()->toKlarnaAddress($address);
493
+ } catch (KlarnaException $e) {
494
+ Mage::throwException($e->getMessage());
495
+ }
496
+ return $res;
497
+ }
498
+
499
+ public function doBasicTests()
500
+ {
501
+ if ($this->_checkPhone()==false) {
502
+ Mage::throwException($this->_getHelper()->__('Phonenumber must be properly entered'));
503
+ }
504
+ if ($this->needDateOfBirth()) {
505
+ if ($this->_checkDateOfBirth()==false) {
506
+ Mage::throwException($this->_getHelper()->__('Date of birth fields must be properly entered'));
507
+ }
508
+ } else {
509
+ if ($this->_checkPno()==false) {
510
+ Mage::throwException($this->_getHelper()->__('Personal ID must not be empty'));
511
+ }
512
+ }
513
+ if ($this->needConsent()) {
514
+ if ($this->_checkConsent()==false) {
515
+ Mage::throwException($this->_getHelper()->__('You need to agree to the terms to be able to continue'));
516
+ }
517
+ }
518
+ if ($this->needGender()) {
519
+ if ($this->_checkGender()==false) {
520
+ Mage::throwException($this->_getHelper()->__('You need to enter your gender to be able to continue'));
521
+ }
522
+ }
523
+ }
524
+
525
+ public function createItemListRefund()
526
+ {
527
+ // The array that will hold the items that we are going to use
528
+ $items = array();
529
+
530
+ // Loop through the item collection
531
+ foreach ($this->getCreditmemo()->getAllItems() as $item) {
532
+ $ord_items = $this->getOrder()->getItemsCollection();
533
+ foreach ($ord_items as $ord_item) {
534
+ if ($ord_item->getId()==$item->getOrderItemId()) {
535
+ if ($this->_getHelper()->shouldItemBeIncluded($ord_item)) {
536
+ $items[] = $item;
537
+ }
538
+ break;
539
+ }
540
+ }
541
+ }
542
+
543
+ return $items;
544
+ }
545
+
546
+ public function createItemListCapture()
547
+ {
548
+ // The array that will hold the items that we are going to use
549
+ $items = array();
550
+
551
+ // Loop through the item collection
552
+ foreach ($this->getInvoice()->getAllItems() as $item) {
553
+ $ord_items = $this->getOrder()->getItemsCollection();
554
+ foreach ($ord_items as $ord_item) {
555
+ if ($ord_item->getId()==$item->getOrderItemId()) {
556
+ if ($this->_getHelper()->shouldItemBeIncluded($ord_item)) {
557
+ $items[] = $item;
558
+ }
559
+ break;
560
+ }
561
+ }
562
+ }
563
+
564
+ return $items;
565
+ }
566
+
567
+ public function createItemListAuthorize()
568
+ {
569
+ // The array that will hold the items that we are going to use
570
+ $items = array();
571
+
572
+ // Loop through the item collection
573
+ foreach ($this->getOrder()->getAllItems() as $item) {
574
+ if ($this->_getHelper()->shouldItemBeIncluded($item)==false) continue;
575
+ $items[] = $item;
576
+ }
577
+
578
+ return $items;
579
+ }
580
+
581
+ protected function _getTransport()
582
+ {
583
+ return $this;
584
+ }
585
+
586
+ }
app/code/community/Vaimo/Klarna/Model/Klarna/Abstract.php ADDED
@@ -0,0 +1,1096 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Copyright (c) 2009-2014 Vaimo AB
4
+ *
5
+ * Vaimo reserves all rights in the Program as delivered. The Program
6
+ * or any portion thereof may not be reproduced in any form whatsoever without
7
+ * the written consent of Vaimo, except as provided by licence. A licence
8
+ * under Vaimo's rights in the Program may be available directly from
9
+ * Vaimo.
10
+ *
11
+ * Disclaimer:
12
+ * THIS NOTICE MAY NOT BE REMOVED FROM THE PROGRAM BY ANY USER THEREOF.
13
+ * THE PROGRAM IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
14
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
16
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ * OUT OF OR IN CONNECTION WITH THE PROGRAM OR THE USE OR OTHER DEALINGS
19
+ * IN THE PROGRAM.
20
+ *
21
+ * @category Vaimo
22
+ * @package Vaimo_Klarna
23
+ * @copyright Copyright (c) 2009-2014 Vaimo AB
24
+ */
25
+
26
+ abstract class Vaimo_Klarna_Model_Klarna_Abstract extends Vaimo_Klarna_Model_Transport_Abstract
27
+ {
28
+ /*
29
+ * Temporary storage of fields that eventually will be added to payments additional_info
30
+ *
31
+ */
32
+ protected $_additionalInfo = NULL;
33
+
34
+ /*
35
+ * Contains the item lines that will be sent to Klarna
36
+ * goods list is the actual products
37
+ * extras contain things like discounts, shipping costs etc
38
+ */
39
+ protected $_goods_list = array();
40
+ protected $_extras = array();
41
+
42
+ /*
43
+ * A manipulated array of html post variables
44
+ * Used only in this file
45
+ *
46
+ */
47
+ protected $_postValues = array();
48
+
49
+ protected $_entGWHelper = NULL;
50
+ protected $_salesHelper = NULL;
51
+ protected $_taxCalculation = NULL;
52
+
53
+ public function __construct($setStoreInfo = true, $moduleHelper = NULL, $entGWHelper = NULL, $salesHelper = NULL, $taxCalculation = NULL)
54
+ {
55
+ parent::__construct($setStoreInfo, $moduleHelper);
56
+
57
+ $this->_entGWHelper = $entGWHelper;
58
+ if ($this->_entGWHelper==NULL) {
59
+ if (class_exists("Enterprise_GiftWrapping_Helper_Data", false)) {
60
+ $this->_entGWHelper = Mage::helper('enterprise_giftwrapping');
61
+ }
62
+ }
63
+ $this->_salesHelper = $salesHelper;
64
+ if ($this->_salesHelper==NULL) {
65
+ $this->_salesHelper = Mage::helper('sales');
66
+ }
67
+ $this->_taxCalculation = $taxCalculation;
68
+ if ($this->_taxCalculation==NULL) {
69
+ $this->_taxCalculation = Mage::getSingleton('tax/calculation');
70
+ }
71
+ }
72
+
73
+ protected function _getEntGWHelper()
74
+ {
75
+ return $this->_entGWHelper;
76
+ }
77
+
78
+ protected function _getSalesHelper()
79
+ {
80
+ return $this->_salesHelper;
81
+ }
82
+
83
+ protected function _getTaxCalculation()
84
+ {
85
+ return $this->_taxCalculation;
86
+ }
87
+
88
+ protected function _setAdditionalInformation($data, $value = NULL)
89
+ {
90
+ if (!$data) return;
91
+ if ($value && !is_array($data)) {
92
+ if ($this->_additionalInfo) {
93
+ $this->_additionalInfo->setData($data, $value);
94
+ } else {
95
+ $this->_additionalInfo = new Varien_Object(array($data => $value));
96
+ }
97
+ } else {
98
+ if ($this->_additionalInfo) {
99
+ $this->_additionalInfo->setData($data);
100
+ } else {
101
+ $this->_additionalInfo = new Varien_Object($data);
102
+ }
103
+ }
104
+ }
105
+
106
+ protected function _unsetAdditionalInformation($field)
107
+ {
108
+ if ($this->_additionalInfo) {
109
+ $this->_additionalInfo->unsetData($field);
110
+ }
111
+ }
112
+
113
+ protected function _getAdditionalInformation($field = '')
114
+ {
115
+ if ($this->_additionalInfo) {
116
+ return $this->_additionalInfo->getData($field);
117
+ } else {
118
+ return NULL;
119
+ }
120
+ }
121
+
122
+ public function getGoodsList()
123
+ {
124
+ return $this->_goods_list;
125
+ }
126
+
127
+ public function getExtras()
128
+ {
129
+ return $this->_extras;
130
+ }
131
+
132
+ /**
133
+ * Get the Personal Number associated to this purchase
134
+ *
135
+ * @return string
136
+ */
137
+ public function getPNO()
138
+ {
139
+ if ($this->needDateOfBirth()) {
140
+ if ((array_key_exists("dob_day", $this->_getAdditionalInformation()))
141
+ && (array_key_exists("dob_month", $this->_getAdditionalInformation()))
142
+ && (array_key_exists("dob_year", $this->_getAdditionalInformation()))
143
+ ) {
144
+ return $this->_getAdditionalInformation("dob_day")
145
+ . $this->_getAdditionalInformation("dob_month")
146
+ . $this->_getAdditionalInformation("dob_year");
147
+ }
148
+ } elseif (array_key_exists("pno", $this->_getAdditionalInformation())
149
+ && strlen($this->_getAdditionalInformation("pno")) > 0
150
+ ) {
151
+ return $this->_getAdditionalInformation("pno");
152
+ }
153
+ return "";
154
+ }
155
+
156
+ /**
157
+ * Get the gender associated to this purchase
158
+ *
159
+ * @return null|int
160
+ */
161
+ public function getGender()
162
+ {
163
+ if ($this->needGender() && array_key_exists("gender", $this->_getAdditionalInformation())) {
164
+ return $this->_getAdditionalInformation("gender");
165
+ }
166
+ return null;
167
+ }
168
+
169
+ /**
170
+ * Get the payment plan associated to this purchase
171
+ *
172
+ * @return int
173
+ */
174
+ public function getPaymentPlan()
175
+ {
176
+ if ((array_key_exists(Vaimo_Klarna_Helper_Data::KLARNA_INFO_FIELD_PAYMENT_PLAN, $this->_getAdditionalInformation()))
177
+ && ($this->getOrder()->getPayment()->getMethod() !== Vaimo_Klarna_Helper_Data::KLARNA_METHOD_INVOICE)
178
+ ) {
179
+ return (int)$this->_getAdditionalInformation(Vaimo_Klarna_Helper_Data::KLARNA_INFO_FIELD_PAYMENT_PLAN);
180
+ }
181
+ return -1;
182
+ }
183
+
184
+ protected function _loadCustomerById($id)
185
+ {
186
+ return Mage::getModel('customer/customer')->load($id);
187
+ }
188
+
189
+ protected function _loadProductById($id)
190
+ {
191
+ return Mage::getModel('catalog/product')->load($id);
192
+ }
193
+
194
+ /**
195
+ * Returns the tax rate
196
+ *
197
+ * @param int $taxClass The tax class to get the rate for
198
+ *
199
+ * @return double The tax rate
200
+ */
201
+ protected function _getTaxRate($taxClass)
202
+ {
203
+ // Load the customer so we can retrevice the correct tax class id
204
+ $customer = $this->_loadCustomerById($this->getOrder()->getCustomerId());
205
+ $calculation = $this->_getTaxCalculation();
206
+ $request = $calculation->getRateRequest(
207
+ $this->getShippingAddress(),
208
+ $this->getBillingAddress(),
209
+ $customer->getTaxClassId(),
210
+ $this->getOrder()->getStore()
211
+ );
212
+ return $calculation->getRate($request->setProductClassId($taxClass));
213
+ }
214
+
215
+ protected function _checkBundles(&$item, $product)
216
+ {
217
+ if ($item->getProductType()==Mage_Catalog_Model_Product_Type::TYPE_BUNDLE) {
218
+ if ($product->getPriceType()==Mage_Bundle_Model_Product_Price::PRICE_TYPE_DYNAMIC) {
219
+ $item->setPriceInclTax(0);
220
+ }
221
+ }
222
+ }
223
+
224
+ /**
225
+ * Create the goods list for Reservations
226
+ *
227
+ * @param array $items The items to add to the goods list
228
+ *
229
+ * @return void
230
+ */
231
+ protected function _createGoodsList($items = null)
232
+ {
233
+ if ($items === null) {
234
+ $items = $this->getOrder()->getAllVisibleItems();
235
+ }
236
+
237
+ $taxRate = NULL;
238
+
239
+ foreach ($items as $item) {
240
+
241
+ if ($this->_getHelper()->shouldItemBeIncluded($item)==false) continue;
242
+
243
+ //For handling the different activation
244
+ $qty = $item->getQtyOrdered(); //Standard
245
+ if (!isset($qty)) {
246
+ $qty = $item->getQty(); //Advanced
247
+ }
248
+ $id = $item->getProductId();
249
+ $product = $this->_loadProductById($id);
250
+
251
+ $this->_checkBundles($item, $product);
252
+
253
+ $taxRate = $this->_getTaxRate($product->getTaxClassId());
254
+
255
+ $this->_goods_list[] =
256
+ array(
257
+ "qty" => $qty,
258
+ "sku" => $item->getSku(),
259
+ "name" => $item->getName(),
260
+ "price" => $item->getPriceInclTax(),
261
+ "total_amount" => $item->getRowTotalInclTax(),
262
+ "total_tax_amount" => $item->getTaxAmount(),
263
+ "tax" => $taxRate,
264
+ "discount" => 0,
265
+ "flags" => Vaimo_Klarna_Helper_Data::KLARNA_FLAG_ITEM_NORMAL,
266
+ );
267
+ }
268
+
269
+ //Only add discounts and etc for unactivated orders
270
+ if ($this->getOrder()->hasInvoices() <= 1) {
271
+ $this->_addExtraFees($taxRate);
272
+ }
273
+ }
274
+
275
+ /**
276
+ * Create the goods list for Refunds
277
+ *
278
+ * @param array $items The items to add to the goods list
279
+ *
280
+ * @return void
281
+ */
282
+ protected function _createRefundGoodsList($items = null)
283
+ {
284
+ if ($items === null) {
285
+ $this->logKlarnaApi('_createRefundGoodsList got no items. Order: ' . $this->getOrder()->getIncrementId());
286
+ }
287
+
288
+ $taxRate = NULL;
289
+
290
+ if ($items) {
291
+ foreach ($items as $item) {
292
+ $qty = $item->getQty();
293
+ $id = $item->getProductId();
294
+ $product = $this->_loadProductById($id);
295
+
296
+ $taxRate = $this->_getTaxRate($product->getTaxClassId());
297
+
298
+ $this->_goods_list[] =
299
+ array(
300
+ "qty" => $qty,
301
+ "sku" => $item->getSku(),
302
+ "name" => $item->getName(),
303
+ "price" => $item->getPriceInclTax(),
304
+ "total_amount" => $item->getRowTotalInclTax(),
305
+ "total_tax_amount" => $item->getTaxAmount(),
306
+ "tax" => $taxRate,
307
+ "discount" => 0,
308
+ "flags" => Vaimo_Klarna_Helper_Data::KLARNA_FLAG_ITEM_NORMAL,
309
+ );
310
+ }
311
+ }
312
+ // Add same extra fees as original order, then remove the ones that should not be refunded
313
+ $this->_addExtraFees($taxRate);
314
+ foreach ($this->getExtras() as $id => $extra) {
315
+ if (isset($extra['flags'])) {
316
+ switch ($extra['flags']) {
317
+ case Vaimo_Klarna_Helper_Data::KLARNA_FLAG_ITEM_HANDLING_FEE:
318
+ if ($this->getCreditmemo()->getVaimoKlarnaFeeRefund()>0) { // If not full invoice fee refunded, it will use refund amount instead
319
+ $this->_extras[$id]['original_price'] = $this->_extras[$id]['price'];
320
+ $this->_extras[$id]['price'] = $this->getCreditmemo()->getVaimoKlarnaFeeRefund();
321
+ } else {
322
+ unset($this->_extras[$id]);
323
+ }
324
+ break;
325
+ case Vaimo_Klarna_Helper_Data::KLARNA_FLAG_ITEM_SHIPPING_FEE;
326
+ if ($this->getCreditmemo()->getShippingAmount()>0) { // If not full shipping refunded, it will use refund amount instead
327
+ $this->_extras[$id]['original_price'] = $this->_extras[$id]['price'];
328
+ $this->_extras[$id]['price'] = $this->getCreditmemo()->getShippingAmount();
329
+ } else {
330
+ unset($this->_extras[$id]);
331
+ }
332
+ break;
333
+ case Vaimo_Klarna_Helper_Data::KLARNA_FLAG_ITEM_NORMAL:
334
+ unset($this->_extras[$id]);
335
+ break;
336
+ default:
337
+ unset($this->_extras[$id]);
338
+ break;
339
+ }
340
+
341
+ } else {
342
+ unset($this->_extras[$id]);
343
+ }
344
+ }
345
+ }
346
+
347
+ /**
348
+ * Returns the total handling fee included in extras
349
+ *
350
+ * @return decimal
351
+ */
352
+ protected function _feeAmountIncluded()
353
+ {
354
+ $res = 0;
355
+ foreach ($this->getExtras() as $extra) {
356
+ if (isset($extra['flags'])) {
357
+ if ($extra['flags']==Vaimo_Klarna_Helper_Data::KLARNA_FLAG_ITEM_HANDLING_FEE) {
358
+ $res = $res + $extra['price'];
359
+ }
360
+ }
361
+ }
362
+ return $res;
363
+ }
364
+
365
+ /**
366
+ * Add all possible fees and discounts.
367
+ *
368
+ * @return void
369
+ */
370
+ protected function _addExtraFees($taxRate)
371
+ {
372
+ $this->_addInvoiceFee();
373
+
374
+ $this->_addShippingFee();
375
+
376
+ $this->_addGiftCard();
377
+
378
+ $this->_addCustomerBalance();
379
+
380
+ $this->_addRewardCurrency();
381
+
382
+ $this->_addGiftWrapPrice();
383
+
384
+ $this->_addGiftWrapItemPrice();
385
+
386
+ $this->_addGwPrintedCardPrice();
387
+
388
+ $this->_addDiscount($taxRate);
389
+
390
+ }
391
+
392
+ /**
393
+ * Add the Gift Wrap Order price to the goods list
394
+ *
395
+ * @return void
396
+ */
397
+ protected function _addGiftWrapPrice()
398
+ {
399
+ if ($this->getOrder()->getGwPrice() <= 0) {
400
+ return;
401
+ }
402
+
403
+ $price = $this->getOrder()->getGwPrice();
404
+ $tax = $this->getOrder()->getGwTaxAmount();
405
+
406
+ $sku = $this->_getHelper()->__('gw_order');
407
+
408
+ $name = $this->_getEntGWHelper()->__("Gift Wrapping for Order");
409
+ $this->_extras[] = array(
410
+ "qty" => 1,
411
+ "sku" => $sku,
412
+ "name" => $name,
413
+ "price" => $price + $tax,
414
+ "total_amount" => $price + $tax,
415
+ "total_tax_amount" => $tax,
416
+ );
417
+ }
418
+
419
+ /**
420
+ * Add the Gift Wrap Item price to the goods list
421
+ *
422
+ * @return void
423
+ */
424
+ protected function _addGiftWrapItemPrice()
425
+ {
426
+ if ($this->getOrder()->getGwItemsPrice() <= 0) {
427
+ return;
428
+ }
429
+
430
+ $price = $this->getOrder()->getGwItemsPrice();
431
+ $tax = $this->getOrder()->getGwItemsTaxAmount();
432
+
433
+ $name = $this->_getEntGWHelper()->__("Gift Wrapping for Items");
434
+
435
+ $sku = $this->_getHelper()->__('gw_items');
436
+
437
+ $this->_extras[] = array(
438
+ "qty" => 1,
439
+ "sku" => $sku,
440
+ "name" => $name,
441
+ "price" => $price + $tax,
442
+ "total_amount" => $price + $tax,
443
+ "total_tax_amount" => $tax,
444
+ );
445
+ }
446
+
447
+ /**
448
+ * Add the Gift Wrap Printed Card to the goods list
449
+ *
450
+ * @return void
451
+ */
452
+ protected function _addGwPrintedCardPrice()
453
+ {
454
+ if ($this->getOrder()->getGwPrintedCardPrice() <= 0) {
455
+ return;
456
+ }
457
+
458
+ $price = $this->getOrder()->getGwPrintedCardPrice();
459
+ $tax = $this->getOrder()->getGwPrintedCardTaxAmount();
460
+
461
+ $name = $this->_getEntGWHelper()->__("Printed Card");
462
+
463
+ $sku = $this->_getHelper()->__('gw_printed_card');
464
+
465
+ $this->_extras[] = array(
466
+ "qty" => 1,
467
+ "sku" => $sku,
468
+ "name" => $name,
469
+ "price" => $price + $tax,
470
+ "total_amount" => $price + $tax,
471
+ "total_tax_amount" => $tax,
472
+ );
473
+ }
474
+
475
+ /**
476
+ * Add the gift card amount to the goods list
477
+ *
478
+ * @return void
479
+ */
480
+ protected function _addGiftCard()
481
+ {
482
+ if ($this->getOrder()->getGiftCardsAmount() <= 0) {
483
+ return;
484
+ }
485
+
486
+ $sku = $this->_getHelper()->__('gift_card');
487
+
488
+ $this->_extras[] = array(
489
+ "qty" => 1,
490
+ "sku" => $sku,
491
+ "name" => $this->_getHelper()->__('Gift Card'),
492
+ "price" => ($this->getOrder()->getGiftCardsAmount() * -1),
493
+ "total_amount" => ($this->getOrder()->getGiftCardsAmount() * -1),
494
+ "total_tax_amount" => 0,
495
+ );
496
+ }
497
+
498
+ /**
499
+ * Add the customer balance to the goods list
500
+ *
501
+ * @return void
502
+ */
503
+ protected function _addCustomerBalance()
504
+ {
505
+ if ($this->getOrder()->getCustomerBalanceAmount() <= 0) {
506
+ return;
507
+ }
508
+
509
+ $sku = $this->_getHelper()->__('customer_balance');
510
+
511
+ $this->_extras[] = array(
512
+ "qty" => 1,
513
+ "sku" => $sku,
514
+ "name" => $this->_getHelper()->__("Customer Balance"),
515
+ "price" => ($this->getOrder()->getCustomerBalanceAmount() * -1),
516
+ "total_amount" => ($this->getOrder()->getCustomerBalanceAmount() * -1),
517
+ "total_tax_amount" => 0,
518
+ );
519
+ }
520
+
521
+ /**
522
+ * Add a reward currency amount to the goods list
523
+ *
524
+ * @return void
525
+ */
526
+ protected function _addRewardCurrency()
527
+ {
528
+ if ($this->getOrder()->getRewardCurrencyAmount() <= 0) {
529
+ return;
530
+ }
531
+
532
+ $sku = $this->_getHelper()->__('reward');
533
+
534
+ $this->_extras[] = array(
535
+ "qty" => 1,
536
+ "sku" => $sku,
537
+ "name" => $this->_getHelper()->__('Reward'),
538
+ "price" => ($this->getOrder()->getRewardCurrencyAmount() * -1),
539
+ "total_amount" => ($this->getOrder()->getRewardCurrencyAmount() * -1),
540
+ "total_tax_amount" => 0,
541
+ );
542
+ }
543
+
544
+ /**
545
+ * Add the invoice fee to the goods list
546
+ *
547
+ * @return void
548
+ */
549
+ protected function _addInvoiceFee()
550
+ {
551
+ if ($this->getOrder()->getPayment()->getMethod() != Vaimo_Klarna_Helper_Data::KLARNA_METHOD_INVOICE) {
552
+ return;
553
+ }
554
+ if ($this->_getAdditionalInformation(Vaimo_Klarna_Helper_Data::KLARNA_INFO_FIELD_FEE)==0) {
555
+ return;
556
+ }
557
+
558
+ $sku = $this->_getHelper()->__('invoice_fee');
559
+
560
+ $this->_extras[] = array(
561
+ "qty" => 1,
562
+ "sku" => $sku,
563
+ "name" => $this->_getHelper()->getKlarnaFeeLabel($this->getOrder()->getStore()),
564
+ "price" => $this->_getAdditionalInformation(Vaimo_Klarna_Helper_Data::KLARNA_INFO_FIELD_FEE) + $this->_getAdditionalInformation(Vaimo_Klarna_Helper_Data::KLARNA_INFO_FIELD_FEE_TAX),
565
+ "tax" => $this->_getHelper()->getVaimoKlarnaFeeVatRate($this->getOrder()),
566
+ "flags" => Vaimo_Klarna_Helper_Data::KLARNA_FLAG_ITEM_HANDLING_FEE,
567
+ "total_amount" => $this->_getAdditionalInformation(Vaimo_Klarna_Helper_Data::KLARNA_INFO_FIELD_FEE) + $this->_getAdditionalInformation(Vaimo_Klarna_Helper_Data::KLARNA_INFO_FIELD_FEE_TAX),
568
+ "total_tax_amount" => $this->_getAdditionalInformation(Vaimo_Klarna_Helper_Data::KLARNA_INFO_FIELD_FEE_TAX),
569
+ );
570
+ }
571
+
572
+ /**
573
+ * Add the shipment fee to the goods list
574
+ *
575
+ * @return void
576
+ */
577
+ protected function _addShippingFee()
578
+ {
579
+ if ($this->getOrder()->getShippingInclTax() <= 0) {
580
+ return;
581
+ }
582
+ $taxClass = $this->_getConfigDataCall('tax/classes/shipping_tax_class', $this->getOrder()->getStoreId());
583
+
584
+ $sku = $this->getOrder()->getShippingMethod();
585
+
586
+ if (!$sku || $this->getMethod()==Vaimo_Klarna_Helper_Data::KLARNA_METHOD_CHECKOUT) {
587
+ $sku = $this->_getHelper()->__('shipping');
588
+ }
589
+
590
+ $this->_extras[] = array(
591
+ "qty" => 1,
592
+ "sku" => $sku,
593
+ "name" => $this->getOrder()->getShippingDescription(),
594
+ "price" => $this->getOrder()->getShippingInclTax(),
595
+ "tax" => $this->_getTaxRate($taxClass),
596
+ "flags" => Vaimo_Klarna_Helper_Data::KLARNA_FLAG_ITEM_SHIPPING_FEE,
597
+ "total_amount" => $this->getOrder()->getShippingInclTax(),
598
+ "total_tax_amount" => $this->getOrder()->getShippingAmount(),
599
+ );
600
+ }
601
+
602
+ /**
603
+ * Add the discount to the goods list
604
+ *
605
+ * @param $taxRate is the VAT rate of the LAST product in cart... Not perfect of course, but better than no VAT. It must be an official rate, can't be median
606
+ * @return void
607
+ */
608
+ protected function _addDiscount($taxRate)
609
+ {
610
+ if ($this->getOrder()->getDiscountAmount() <= 0) {
611
+ return;
612
+ }
613
+ // Instead of calculating discount from order etc, we now simply use the amounts we are adding to goods list
614
+
615
+ //calculate grandtotal and subtotal with all possible fees and extra costs
616
+ $subtotal = $this->getOrder()->getSubtotalInclTax();
617
+ $grandtotal = $this->getOrder()->getGrandTotal();
618
+
619
+ //if fee is added, add to subtotal
620
+ //if discount is added, like cards and such, add to grand total
621
+ foreach ($this->_extras as $extra) {
622
+ if ($extra['price'] > 0) {
623
+ $subtotal+= $extra['price'];
624
+ } else if ($extra['price'] < 0) {
625
+ $grandtotal+= $extra['price'];
626
+ }
627
+ }
628
+
629
+ //now check what the actual discount incl vat is
630
+ $amount = $grandtotal - $subtotal; //grand total is always incl tax
631
+
632
+ $sku = $this->getOrder()->getDiscountDescription();
633
+
634
+ if (!$sku || $this->getMethod()==Vaimo_Klarna_Helper_Data::KLARNA_METHOD_CHECKOUT) {
635
+ $sku = $this->_getHelper()->__('discount');
636
+ }
637
+
638
+ $this->_extras[] = array(
639
+ "qty" => 1,
640
+ "sku" => $sku,
641
+ "name" => $this->_getSalesHelper()->__('Discount (%s)', $sku),
642
+ "price" => $amount,
643
+ "tax" => $taxRate,
644
+ "total_amount" => $amount,
645
+ "total_tax_amount" => 0,
646
+ );
647
+ }
648
+
649
+ protected function _getStores()
650
+ {
651
+ return Mage::app()->getStores();
652
+ }
653
+
654
+ /**
655
+ * Get the store information to use for fetching new PClasses
656
+ *
657
+ * @param storeIds a comma separated list of stores as a filter which ones to include
658
+ *
659
+ * @return array of store ids where Klarna is active
660
+ */
661
+ protected function _getKlarnaActiveStores()
662
+ {
663
+ $result = array();
664
+ foreach ($this->_getStores() as $store) {
665
+ if (!$store->getConfig('payment/' . Vaimo_Klarna_Helper_Data::KLARNA_METHOD_ACCOUNT . '/active')
666
+ && !$store->getConfig('payment/' . Vaimo_Klarna_Helper_Data::KLARNA_METHOD_SPECIAL . '/active')
667
+ ) {
668
+ continue;
669
+ }
670
+ $result[] = $store->getId();
671
+ }
672
+ return $result;
673
+ }
674
+
675
+ /*
676
+ * We do not want to save things in the database that doesn't need to be there
677
+ * Personal ID is also removed from database
678
+ *
679
+ * @return void
680
+ */
681
+ protected function _cleanAdditionalInfo()
682
+ {
683
+ if (array_key_exists("pno", $this->_getAdditionalInformation())) {
684
+ $pno = $this->_getAdditionalInformation("pno");
685
+ if (strlen($pno) > 0) {
686
+ $this->getPayment()->unsAdditionalInformation("pno");
687
+ }
688
+ $this->_getHelper()->dispatchReserveInfo($this->getOrder(), $pno);
689
+ }
690
+ if (array_key_exists("consent", $this->_getAdditionalInformation())) {
691
+ if ($this->_getAdditionalInformation("consent")=="NO") {
692
+ $this->getPayment()->unsAdditionalInformation("consent");
693
+ }
694
+ }
695
+ if (array_key_exists("gender", $this->_getAdditionalInformation())) {
696
+ if ($this->_getAdditionalInformation("gender")=="-1") {
697
+ $this->getPayment()->unsAdditionalInformation("gender");
698
+ }
699
+ }
700
+ }
701
+
702
+ /**
703
+ * Update a Magento address with an array containing address information
704
+ *
705
+ * @param array $addr The addr to use
706
+ *
707
+ * @return void
708
+ */
709
+ protected function _updateShippingWithSelectedAddress($addr)
710
+ {
711
+ $selAddr = new Varien_Object($addr);
712
+ $address = $this->getShippingAddress();
713
+ $street = $selAddr->getStreet();
714
+
715
+ if ($selAddr->getHouseNumber()) {
716
+ $street .= " " . $selAddr->getHouseNumber();
717
+ }
718
+ if ($selAddr->getHouseExtension()) {
719
+ $street .= " " . $selAddr->getHouseExtension();
720
+ }
721
+
722
+ // If it's a company purchase set company name.
723
+ $company = $selAddr->getCompanyName();
724
+ if ($company!="" && $this->isCompanyAllowed()) {
725
+ $address->setCompany($company);
726
+ } else {
727
+ $address->setFirstname($selAddr->getFirstName())
728
+ ->setLastname($selAddr->getLastName())
729
+ ->setCompany('');
730
+ }
731
+
732
+ $address->setPostcode($selAddr->getZip())
733
+ ->setStreet(trim($street))
734
+ ->setCity($selAddr->getCity())
735
+ ->save();
736
+ }
737
+
738
+ /**
739
+ * Update a Magento address with another Magento address and save it.
740
+ *
741
+ * @return void
742
+ */
743
+ public function updateBillingAddress()
744
+ {
745
+ $this->getBillingAddress()->setFirstname($this->getShippingAddress()->getFirstname())
746
+ ->setLastname($this->getShippingAddress()->getLastname())
747
+ ->setPostcode($this->getShippingAddress()->getPostcode())
748
+ ->setStreet($this->getShippingAddress()->getStreet())
749
+ ->setCity($this->getShippingAddress()->getCity())
750
+ ->setTelephone($this->getShippingAddress()->getTelephone())
751
+ ->setCountry($this->getShippingAddress()->getCountry())
752
+ ->setCompany($this->getShippingAddress()->getCompany())
753
+ ->save();
754
+ }
755
+
756
+ /**
757
+ * Get a usable email address
758
+ *
759
+ * @param string $customerSessionEmail email of current user
760
+ *
761
+ * @return string
762
+ */
763
+ public function getEmailValue($customerSessionEmail)
764
+ {
765
+ //Get the email address from the address object if its set
766
+ $addressEmail = $this->getShippingAddress()->getEmail();
767
+ if (strlen($addressEmail) > 0) {
768
+ return $addressEmail;
769
+ }
770
+
771
+ //Otherwise we have to pick up the customers email from the session
772
+ $sessionEmail = $customerSessionEmail;
773
+ if (strlen($sessionEmail) > 0) {
774
+ return $sessionEmail;
775
+ }
776
+
777
+ //For guests and new customers there wont be any email on the
778
+ //customer object in the session or their shipping address, so we
779
+ //have to fall back and get the email from their billing address.
780
+ return $this->getBillingAddress()->getEmail();
781
+ }
782
+
783
+ /**
784
+ * Check that Date of birth has been supplied if required.
785
+ *
786
+ * @return bool
787
+ */
788
+ protected function _checkDateOfBirth()
789
+ {
790
+ try {
791
+ $data = $this->getInfoInstance();
792
+ if (!$data->getAdditionalInformation('dob_day') ||
793
+ !$data->getAdditionalInformation('dob_month') ||
794
+ !$data->getAdditionalInformation('dob_year')) {
795
+ return false;
796
+ }
797
+ if ($data->getAdditionalInformation('dob_day') === "00" ||
798
+ $data->getAdditionalInformation('dob_month') === "00" ||
799
+ $data->getAdditionalInformation('dob_year') === "00" ) {
800
+ return false;
801
+ }
802
+ } catch (Mage_Core_Exception $e) {
803
+ $this->logKlarnaException($e);
804
+ return false;
805
+ }
806
+ return true;
807
+ }
808
+
809
+ protected function _checkField($field)
810
+ {
811
+ try {
812
+ $data = $this->getInfoInstance();
813
+ if (!$data->getAdditionalInformation($field)) {
814
+ return false;
815
+ }
816
+ } catch (Mage_Core_Exception $e) {
817
+ $this->logKlarnaException($e);
818
+ return false;
819
+ }
820
+ return true;
821
+ }
822
+
823
+ /**
824
+ * Check that consent has been given if needed.
825
+ *
826
+ * @return bool
827
+ */
828
+ protected function _checkConsent()
829
+ {
830
+ try {
831
+ $data = $this->getInfoInstance();
832
+ if ((!$data->getAdditionalInformation("consent"))
833
+ || ($data->getAdditionalInformation("consent") !== "consent")) {
834
+ return false;
835
+ }
836
+ } catch (Mage_Core_Exception $e) {
837
+ $this->logKlarnaException($e);
838
+ return false;
839
+ }
840
+ return true;
841
+ }
842
+
843
+ /**
844
+ * Check that gender has been selected
845
+ *
846
+ * @return bool
847
+ */
848
+ protected function _checkGender()
849
+ {
850
+ try {
851
+ $data = $this->getInfoInstance();
852
+ if (($data->getAdditionalInformation("gender")!=="0")
853
+ && ($data->getAdditionalInformation("gender")!=="1")) {
854
+ return false;
855
+ }
856
+ } catch (Mage_Core_Exception $e) {
857
+ $this->logKlarnaException($e);
858
+ return false;
859
+ }
860
+ return true;
861
+ }
862
+
863
+ /**
864
+ * Make sure phonenumber is not blank.
865
+ *
866
+ * @return bool
867
+ */
868
+ protected function _checkPhone()
869
+ {
870
+ return $this->_checkField("phonenumber");
871
+ }
872
+
873
+ /**
874
+ * Make sure pno is not blank.
875
+ *
876
+ * @return bool
877
+ */
878
+ protected function _checkPno()
879
+ {
880
+ return $this->_checkField("pno");
881
+ }
882
+
883
+ protected function _getReservationNo()
884
+ {
885
+ $res = $this->_getAdditionalInformation(Vaimo_Klarna_Helper_Data::KLARNA_INFO_FIELD_RESERVATION_ID);
886
+ if ($this->_getAdditionalInformation(Vaimo_Klarna_Helper_Data::KLARNA_INFO_FIELD_ORDER_ID)) {
887
+ $res = $this->_getAdditionalInformation(Vaimo_Klarna_Helper_Data::KLARNA_INFO_FIELD_ORDER_ID);
888
+ }
889
+ return $res;
890
+ }
891
+
892
+ // Moved from the deleted Tools file
893
+
894
+ /**
895
+ * Collect the post values that are relevant to the payment method
896
+ *
897
+ * @param array $data The post values to save
898
+ * @param string $method The payment method
899
+ *
900
+ * @return void
901
+ */
902
+ public function addPostValues($data, $method = NULL)
903
+ {
904
+ foreach ($data as $key => $value) {
905
+ if ($method) {
906
+ $key = str_replace($method . "_", "", $key);
907
+ }
908
+ if ($this->_getHelper()->isKlarnaField($key)) {
909
+ $this->_postValues[$key] = $value;
910
+ } else {
911
+ $this->logDebugInfo('Field ignored: ' . $key);
912
+ }
913
+ }
914
+ }
915
+
916
+ /*
917
+ * This is required when using one step checkout, as it seems to post all fields for all klarna methods
918
+ * This removes all fields containing names of the not selected klarna methods
919
+ *
920
+ * @param object $data Contains the data array containing the post values to clean
921
+ * @param string $method The payment method
922
+ *
923
+ * @return void
924
+ */
925
+ public function clearInactiveKlarnaMethodsPostvalues($dataObj, $method = NULL)
926
+ {
927
+
928
+ if ($method) {
929
+ $methods = $this->_getHelper()->getSupportedMethods();
930
+ $methodsToClear = array();
931
+ foreach ($methods as $m) {
932
+ if ($m!=$method) {
933
+ $methodsToClear[] = $m;
934
+ }
935
+ }
936
+ $data = $dataObj->getData();
937
+ foreach ($data as $key => $value) {
938
+ foreach ($methodsToClear as $m) {
939
+ if (stristr($key, $m)!=false) {
940
+ unset($data[$key]);
941
+ }
942
+ }
943
+ }
944
+ $dataObj->setData($data);
945
+ }
946
+ }
947
+
948
+ public function unsPostvalue($key)
949
+ {
950
+ unset($this->_postValues[$key]);
951
+ }
952
+
953
+ /**
954
+ * Set Magento additional info.
955
+ *
956
+ * Based on cleaned post values
957
+ *
958
+ * @param Mage_Payment_Model_Info $info payment info instance
959
+ *
960
+ * @return void
961
+ */
962
+ public function updateAdditionalInformation($info)
963
+ {
964
+ foreach ($this->_postValues as $key => $value) {
965
+ if ($value==='') {
966
+ if ($info->getAdditionalInformation($key)) {
967
+ $info->unsAdditionalInformation($key);
968
+ }
969
+ continue;
970
+ }
971
+ $info->setAdditionalInformation($key, $value);
972
+ }
973
+ }
974
+
975
+ /**
976
+ * Update a Magento address with post values and save it
977
+ * Even if they entered with two address lines, we update back to Magento only for first street line
978
+ *
979
+ * @param object $address The Magento address
980
+ * @param string $specific_field To update only one field
981
+ *
982
+ * @return void
983
+ */
984
+ protected function _updateAddress($address, $specific_field = NULL)
985
+ {
986
+ if (array_key_exists("street", $this->_postValues)) {
987
+ if ($specific_field==NULL || $specific_field=='street') {
988
+ $street = $this->_postValues["street"];
989
+ if (array_key_exists("house_number", $this->_postValues)) {
990
+ $street .= " " . $this->_postValues["house_number"];
991
+ }
992
+ if (array_key_exists("house_extension", $this->_postValues)) {
993
+ $street .= " " . $this->_postValues["house_extension"];
994
+ }
995
+ $address->setStreet($this->_getHelper()->decode(trim($street)));
996
+ }
997
+ }
998
+
999
+ if (array_key_exists("first_name", $this->_postValues)) {
1000
+ if ($specific_field==NULL || $specific_field=='first_name') {
1001
+ $address->setFirstname($this->_getHelper()->decode($this->_postValues["first_name"]));
1002
+ }
1003
+ }
1004
+
1005
+ if (array_key_exists("last_name", $this->_postValues)) {
1006
+ if ($specific_field==NULL || $specific_field=='last_name') {
1007
+ $address->setLastname($this->_getHelper()->decode($this->_postValues["last_name"]));
1008
+ }
1009
+ }
1010
+
1011
+ if (array_key_exists("zipcode", $this->_postValues)) {
1012
+ if ($specific_field==NULL || $specific_field=='zipcode') {
1013
+ $address->setPostcode($this->_getHelper()->decode($this->_postValues["zipcode"]));
1014
+ }
1015
+ }
1016
+
1017
+ if (array_key_exists("city", $this->_postValues)) {
1018
+ if ($specific_field==NULL || $specific_field=='city') {
1019
+ $address->setCity($this->_getHelper()->decode($this->_postValues["city"]));
1020
+ }
1021
+ }
1022
+
1023
+ if (array_key_exists("phonenumber", $this->_postValues)) {
1024
+ if ($specific_field==NULL || $specific_field=='phonenumber') {
1025
+ $address->setTelephone($this->_getHelper()->decode($this->_postValues["phonenumber"]));
1026
+ }
1027
+ }
1028
+
1029
+ if ($specific_field==NULL || $specific_field=='company') {
1030
+ $address->setCompany($this->_getCompanyName($address, $this->_postValues));
1031
+ }
1032
+
1033
+ $address->save();
1034
+ }
1035
+
1036
+ /**
1037
+ * Get company name if possible.
1038
+ *
1039
+ * @param object $address The Magento address
1040
+ *
1041
+ * @return string Company name or empty string.
1042
+ */
1043
+ protected function _getCompanyName($address)
1044
+ {
1045
+ if ($this->isCompanyAllowed() === false) {
1046
+ return '';
1047
+ }
1048
+
1049
+ if (array_key_exists('invoice_type', $this->_postValues)
1050
+ && $this->_postValues['invoice_type'] !== 'company'
1051
+ ) {
1052
+ return '';
1053
+ }
1054
+
1055
+ // If there is a company name in the POST, update it on the address.
1056
+ if (array_key_exists('company_name', $this->_postValues)) {
1057
+ return $this->_getHelper()->decode($this->_postValues['company_name']);
1058
+ }
1059
+
1060
+ // Otherwise keep what is on the address.
1061
+ return $address->getCompany();
1062
+ }
1063
+
1064
+ public function getPostValues($key)
1065
+ {
1066
+ if ($key) {
1067
+ if (isset($this->_postValues[$key])) {
1068
+ return $this->_postValues[$key];
1069
+ } else {
1070
+ return NULL;
1071
+ }
1072
+ }
1073
+ return $this->_postValues;
1074
+ }
1075
+
1076
+ public function setPaymentFee($quote)
1077
+ {
1078
+ if ($quote->getVaimoKlarnaFee()) {
1079
+ $this->addPostValues(array(
1080
+ Vaimo_Klarna_Helper_Data::KLARNA_INFO_FIELD_FEE => $quote->getVaimoKlarnaFee(),
1081
+ Vaimo_Klarna_Helper_Data::KLARNA_INFO_FIELD_FEE_TAX => $quote->getVaimoKlarnaFeeTax(),
1082
+ Vaimo_Klarna_Helper_Data::KLARNA_INFO_FIELD_BASE_FEE => $quote->getVaimoKlarnaBaseFee(),
1083
+ Vaimo_Klarna_Helper_Data::KLARNA_INFO_FIELD_BASE_FEE_TAX => $quote->getVaimoKlarnaBaseFeeTax(),
1084
+ ));
1085
+ } else {
1086
+ $this->addPostValues(array(
1087
+ Vaimo_Klarna_Helper_Data::KLARNA_INFO_FIELD_FEE => '',
1088
+ Vaimo_Klarna_Helper_Data::KLARNA_INFO_FIELD_FEE_TAX => '',
1089
+ Vaimo_Klarna_Helper_Data::KLARNA_INFO_FIELD_BASE_FEE => '',
1090
+ Vaimo_Klarna_Helper_Data::KLARNA_INFO_FIELD_BASE_FEE_TAX => '',
1091
+ ));
1092
+ }
1093
+ }
1094
+
1095
+
1096
+ }
app/code/community/Vaimo/Klarna/Model/Klarna/Assign.php DELETED
@@ -1,352 +0,0 @@
1
- <?php
2
- /**
3
- * Copyright (c) 2009-2014 Vaimo AB
4
- *
5
- * Vaimo reserves all rights in the Program as delivered. The Program
6
- * or any portion thereof may not be reproduced in any form whatsoever without
7
- * the written consent of Vaimo, except as provided by licence. A licence
8
- * under Vaimo's rights in the Program may be available directly from
9
- * Vaimo.
10
- *
11
- * Disclaimer:
12
- * THIS NOTICE MAY NOT BE REMOVED FROM THE PROGRAM BY ANY USER THEREOF.
13
- * THE PROGRAM IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
14
- * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
16
- * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
- * OUT OF OR IN CONNECTION WITH THE PROGRAM OR THE USE OR OTHER DEALINGS
19
- * IN THE PROGRAM.
20
- *
21
- * @category Vaimo
22
- * @package Vaimo_Klarna
23
- * @copyright Copyright (c) 2009-2014 Vaimo AB
24
- */
25
-
26
- class Vaimo_Klarna_Model_Klarna_Assign extends Vaimo_Klarna_Model_Klarna_Api
27
- {
28
- protected $_postValues = array();
29
-
30
- public function __construct($klarnaApi = null, $payment = null)
31
- {
32
- parent::__construct($klarnaApi, $payment);
33
- $this->_setFunctionName('assign');
34
- }
35
-
36
- /**
37
- * Collect the post values that are relevant to the payment method
38
- *
39
- * @param array $data The post values to save
40
- * @param string $method The payment method
41
- *
42
- * @return void
43
- */
44
- public function addPostvalues($data, $method = NULL)
45
- {
46
- foreach ($data as $key => $value) {
47
- if ($method) {
48
- $key = str_replace($method . "_", "", $key);
49
- }
50
- if (in_array($key,Mage::helper('klarna')->getKlarnaFields())) {
51
- $this->_postValues[$key] = $value;
52
- } else {
53
- $this->_logDebugInfo('Field ignored: ' . $key);
54
- }
55
- }
56
- }
57
-
58
- /*
59
- * This is required when using one step checkout, as it seems to post all fields for all klarna methods
60
- * This removes all fields containing names of the not selected klarna methods
61
- *
62
- * @param object $data Contains the data array containing the post values to clean
63
- * @param string $method The payment method
64
- *
65
- * @return void
66
- */
67
- public function clearInactiveKlarnaMethodsPostvalues($dataObj, $method = NULL)
68
- {
69
-
70
- if ($method) {
71
- $methods = Mage::helper('klarna')->getSupportedMethods();
72
- $methodsToClear = array();
73
- foreach ($methods as $m) {
74
- if ($m!=$method) {
75
- $methodsToClear[] = $m;
76
- }
77
- }
78
- $data = $dataObj->getData();
79
- foreach ($data as $key => $value) {
80
- foreach ($methodsToClear as $m) {
81
- if (stristr($key, $m)!=false) {
82
- unset($data[$key]);
83
- }
84
- }
85
- }
86
- $dataObj->setData($data);
87
- }
88
- }
89
-
90
- public function unsPostvalue($key)
91
- {
92
- unset($this->_postValues[$key]);
93
- }
94
-
95
- /**
96
- * Set Magento additional info.
97
- *
98
- * Based on cleaned post values
99
- *
100
- * @param Mage_Payment_Model_Info $info payment info instance
101
- *
102
- * @return void
103
- */
104
- public function updateAdditionalInformation($info)
105
- {
106
- foreach ($this->_postValues as $key => $value) {
107
- if ($value==='') {
108
- if ($info->getAdditionalInformation($key)) {
109
- $info->unsAdditionalInformation($key);
110
- }
111
- continue;
112
- }
113
- $info->setAdditionalInformation($key, $value);
114
- }
115
- }
116
-
117
- /**
118
- * Get a usable email address
119
- *
120
- * @param string $customerSessionEmail email of current user
121
- *
122
- * @return string
123
- */
124
- public function getEmailValue($customerSessionEmail)
125
- {
126
- //Get the email address from the address object if its set
127
- $addressEmail = $this->getShippingAddress()->getEmail();
128
- if (strlen($addressEmail) > 0) {
129
- return $addressEmail;
130
- }
131
-
132
- //Otherwise we have to pick up the customers email from the session
133
- $sessionEmail = $customerSessionEmail;
134
- if (strlen($sessionEmail) > 0) {
135
- return $sessionEmail;
136
- }
137
-
138
- //For guests and new customers there wont be any email on the
139
- //customer object in the session or their shipping address, so we
140
- //have to fall back and get the email from their billing address.
141
- return $this->_billingAddress->getEmail();
142
- }
143
-
144
- /**
145
- * Update a Magento address with post values and save it
146
- * Even if they entered with two address lines, we update back to Magento only for first street line
147
- *
148
- * @param object $address The Magento address
149
- * @param string $specific_field To update only one field
150
- *
151
- * @return void
152
- */
153
- protected function _updateAddress($address, $specific_field = NULL)
154
- {
155
- if (array_key_exists("street", $this->_postValues)) {
156
- if ($specific_field==NULL || $specific_field=='street') {
157
- $street = $this->_postValues["street"];
158
- if (array_key_exists("house_number", $this->_postValues)) {
159
- $street .= " " . $this->_postValues["house_number"];
160
- }
161
- if (array_key_exists("house_extension", $this->_postValues)) {
162
- $street .= " " . $this->_postValues["house_extension"];
163
- }
164
- $address->setStreet($this->_decode(trim($street)));
165
- }
166
- }
167
-
168
- if (array_key_exists("first_name", $this->_postValues)) {
169
- if ($specific_field==NULL || $specific_field=='first_name') {
170
- $address->setFirstname($this->_decode($this->_postValues["first_name"]));
171
- }
172
- }
173
-
174
- if (array_key_exists("last_name", $this->_postValues)) {
175
- if ($specific_field==NULL || $specific_field=='last_name') {
176
- $address->setLastname($this->_decode($this->_postValues["last_name"]));
177
- }
178
- }
179
-
180
- if (array_key_exists("zipcode", $this->_postValues)) {
181
- if ($specific_field==NULL || $specific_field=='zipcode') {
182
- $address->setPostcode($this->_decode($this->_postValues["zipcode"]));
183
- }
184
- }
185
-
186
- if (array_key_exists("city", $this->_postValues)) {
187
- if ($specific_field==NULL || $specific_field=='city') {
188
- $address->setCity($this->_decode($this->_postValues["city"]));
189
- }
190
- }
191
-
192
- if (array_key_exists("phonenumber", $this->_postValues)) {
193
- if ($specific_field==NULL || $specific_field=='phonenumber') {
194
- $address->setTelephone($this->_decode($this->_postValues["phonenumber"]));
195
- }
196
- }
197
-
198
- if ($specific_field==NULL || $specific_field=='company') {
199
- $address->setCompany($this->_getCompanyName($address, $this->_postValues));
200
- }
201
-
202
- $address->save();
203
- }
204
-
205
- /**
206
- * Get company name if possible.
207
- *
208
- * @param object $address The Magento address
209
- *
210
- * @return string Company name or empty string.
211
- */
212
- private function _getCompanyName($address)
213
- {
214
- if ($this->isCompanyAllowed() === false) {
215
- return '';
216
- }
217
-
218
- if (array_key_exists('invoice_type', $this->_postValues)
219
- && $this->_postValues['invoice_type'] !== 'company'
220
- ) {
221
- return '';
222
- }
223
-
224
- // If there is a company name in the POST, update it on the address.
225
- if (array_key_exists('company_name', $this->_postValues)) {
226
- return $this->_decode($this->_postValues['company_name']);
227
- }
228
-
229
- // Otherwise keep what is on the address.
230
- return $address->getCompany();
231
- }
232
-
233
- /**
234
- * Update addresses with data from our checkout box
235
- *
236
- * @return void
237
- */
238
- public function updateAddress()
239
- {
240
- /*
241
- * getAddress is only allowed in Sweden, so this code is for Sweden only
242
- */
243
- if ($this->useGetAddresses()) {
244
- if (!isset($this->_postValues['pno']) || !isset($this->_postValues['address_id'])) {
245
- /*
246
- * OneStepCheckout saves payment method upon load, which means an error message must not be produced
247
- * in this function. Authorize will attempt to use the value and give an error message, which means
248
- * it will be checked and reported anyway
249
- */
250
- if (!Mage::helper('klarna')->isOneStepCheckout()) {
251
- Mage::throwException(Mage::helper('klarna')->__(
252
- 'Unknown address, please specify correct personal id in the payment selection and press Fetch again, or use another payment method'
253
- )
254
- );
255
- }
256
- }
257
- if (isset($this->_postValues['pno']) && isset($this->_postValues['address_id'])) {
258
- $addr = $this->_getSelectedAddress($this->_postValues['pno'], $this->_postValues['address_id']);
259
- if ($addr!=NULL) {
260
- /*
261
- * This is not approved by Klarna, so address will be updated only when order is placed. This is NOT a bug.
262
- */
263
- // $this->_updateShippingWithSelectedAddress($addr);
264
- } else {
265
- /*
266
- * No error message here if using OneStepCheckout
267
- */
268
- if (!Mage::helper('klarna')->isOneStepCheckout()) {
269
- Mage::throwException(Mage::helper('klarna')->__(
270
- 'Unknown address, please specify correct personal id in the payment selection and press Fetch again, or use another payment method'
271
- )
272
- );
273
- }
274
- }
275
- }
276
- }
277
-
278
- /*
279
- * Update the addresses with values from the checkout
280
- */
281
- $this->_updateAddress($this->getShippingAddress());
282
- $this->_updateAddress($this->getBillingAddress(), 'phonenumber');
283
-
284
- }
285
-
286
- public function getPostValues($key)
287
- {
288
- if ($key) {
289
- if (isset($this->_postValues[$key])) {
290
- return $this->_postValues[$key];
291
- } else {
292
- return NULL;
293
- }
294
- }
295
- return $this->_postValues;
296
- }
297
-
298
- public function setPaymentPlan()
299
- {
300
- $id = $this->getPostValues(Vaimo_Klarna_Helper_Data::KLARNA_INFO_FIELD_PAYMENT_PLAN);
301
- $method = $this->getPostValues('method');
302
- if ($id) {
303
- $pclassArray = $this->_getSpecificPClass($id);
304
- if (!$pclassArray) {
305
- Mage::throwException(Mage::helper('klarna')->__('Unexpected error, pclass does not exist, please reload page and try again'));
306
- }
307
- $this->addPostvalues(array(
308
- Vaimo_Klarna_Helper_Data::KLARNA_INFO_FIELD_PAYMENT_PLAN_DESCRIPTION => $pclassArray['description'],
309
- Vaimo_Klarna_Helper_Data::KLARNA_INFO_FIELD_PAYMENT_PLAN_MONTHLY_COST => $pclassArray['monthly_cost'],
310
- Vaimo_Klarna_Helper_Data::KLARNA_INFO_FIELD_PAYMENT_PLAN_TOTAL_COST => $pclassArray['total_cost'],
311
- Vaimo_Klarna_Helper_Data::KLARNA_INFO_FIELD_PAYMENT_PLAN_INVOICE_FEE => $pclassArray['invoicefee'],
312
- Vaimo_Klarna_Helper_Data::KLARNA_INFO_FIELD_PAYMENT_PLAN_START_FEE => $pclassArray['startfee'],
313
- Vaimo_Klarna_Helper_Data::KLARNA_INFO_FIELD_PAYMENT_PLAN_MONTHS => $pclassArray['months'],
314
- Vaimo_Klarna_Helper_Data::KLARNA_INFO_FIELD_PAYMENT_PLAN_TYPE => $pclassArray['type'],
315
- ));
316
- } else {
317
- if ($method==Vaimo_Klarna_Helper_Data::KLARNA_METHOD_ACCOUNT || $method==Vaimo_Klarna_Helper_Data::KLARNA_METHOD_SPECIAL ) {
318
- Mage::throwException(Mage::helper('klarna')->__('You must choose a payment plan'));
319
- }
320
- $this->addPostvalues(array(
321
- Vaimo_Klarna_Helper_Data::KLARNA_INFO_FIELD_PAYMENT_PLAN_DESCRIPTION => '',
322
- Vaimo_Klarna_Helper_Data::KLARNA_INFO_FIELD_PAYMENT_PLAN_MONTHLY_COST => '',
323
- Vaimo_Klarna_Helper_Data::KLARNA_INFO_FIELD_PAYMENT_PLAN_TOTAL_COST => '',
324
- Vaimo_Klarna_Helper_Data::KLARNA_INFO_FIELD_PAYMENT_PLAN_INVOICE_FEE => '',
325
- Vaimo_Klarna_Helper_Data::KLARNA_INFO_FIELD_PAYMENT_PLAN_START_FEE => '',
326
- Vaimo_Klarna_Helper_Data::KLARNA_INFO_FIELD_PAYMENT_PLAN_MONTHS => '',
327
- Vaimo_Klarna_Helper_Data::KLARNA_INFO_FIELD_PAYMENT_PLAN_TYPE => '',
328
- Vaimo_Klarna_Helper_Data::KLARNA_INFO_FIELD_PAYMENT_PLAN => '',
329
- ));
330
- }
331
- }
332
-
333
- public function setPaymentFee($quote)
334
- {
335
- if ($quote->getVaimoKlarnaFee()) {
336
- $this->addPostvalues(array(
337
- Vaimo_Klarna_Helper_Data::KLARNA_INFO_FIELD_FEE => $quote->getVaimoKlarnaFee(),
338
- Vaimo_Klarna_Helper_Data::KLARNA_INFO_FIELD_FEE_TAX => $quote->getVaimoKlarnaFeeTax(),
339
- Vaimo_Klarna_Helper_Data::KLARNA_INFO_FIELD_BASE_FEE => $quote->getVaimoKlarnaBaseFee(),
340
- Vaimo_Klarna_Helper_Data::KLARNA_INFO_FIELD_BASE_FEE_TAX => $quote->getVaimoKlarnaBaseFeeTax(),
341
- ));
342
- } else {
343
- $this->addPostvalues(array(
344
- Vaimo_Klarna_Helper_Data::KLARNA_INFO_FIELD_FEE => '',
345
- Vaimo_Klarna_Helper_Data::KLARNA_INFO_FIELD_FEE_TAX => '',
346
- Vaimo_Klarna_Helper_Data::KLARNA_INFO_FIELD_BASE_FEE => '',
347
- Vaimo_Klarna_Helper_Data::KLARNA_INFO_FIELD_BASE_FEE_TAX => '',
348
- ));
349
- }
350
- }
351
-
352
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/community/Vaimo/Klarna/Model/Klarna/Authorize.php DELETED
@@ -1,81 +0,0 @@
1
- <?php
2
- /**
3
- * Copyright (c) 2009-2014 Vaimo AB
4
- *
5
- * Vaimo reserves all rights in the Program as delivered. The Program
6
- * or any portion thereof may not be reproduced in any form whatsoever without
7
- * the written consent of Vaimo, except as provided by licence. A licence
8
- * under Vaimo's rights in the Program may be available directly from
9
- * Vaimo.
10
- *
11
- * Disclaimer:
12
- * THIS NOTICE MAY NOT BE REMOVED FROM THE PROGRAM BY ANY USER THEREOF.
13
- * THE PROGRAM IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
14
- * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
16
- * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
- * OUT OF OR IN CONNECTION WITH THE PROGRAM OR THE USE OR OTHER DEALINGS
19
- * IN THE PROGRAM.
20
- *
21
- * @category Vaimo
22
- * @package Vaimo_Klarna
23
- * @copyright Copyright (c) 2009-2014 Vaimo AB
24
- */
25
-
26
- class Vaimo_Klarna_Model_Klarna_Authorize extends Vaimo_Klarna_Model_Klarna_Api
27
- {
28
- public function __construct($klarnaApi = null, $payment = null)
29
- {
30
- parent::__construct($klarnaApi, $payment);
31
- $this->_setFunctionName('authorize');
32
- }
33
-
34
- public function createItemList()
35
- {
36
- // The array that will hold the items that we are going to use
37
- $items = array();
38
-
39
- // Loop through the item collection
40
- foreach ($this->getOrder()->getAllItems() as $item) {
41
- if (Mage::helper('klarna')->shouldItemBeIncluded($item)==false) continue;
42
- $items[] = $item;
43
- }
44
-
45
- return $items;
46
- }
47
-
48
- public function shouldOrderBeCanceled($status)
49
- {
50
- $cancel_denied = true; // $this->_getConfigData('denied_status'); // Decision to cancel denied always, not optional
51
- if ($status==Vaimo_Klarna_Helper_Data::KLARNA_STATUS_DENIED && $cancel_denied) {
52
- return true;
53
- }
54
- return false;
55
- }
56
-
57
- /**
58
- * Update addresses with data from our checkout box
59
- *
60
- * @return void
61
- */
62
- public function updateAddress()
63
- {
64
- //Update with the getAddress call for Swedish customers
65
- if ($this->useGetAddresses()) {
66
- $addr = $this->_getSelectedAddress($this->getPayment()->getAdditionalInformation('pno'), $this->getPayment()->getAdditionalInformation('address_id'));
67
- if ($addr!=NULL) {
68
- $this->_updateShippingWithSelectedAddress($addr);
69
- } else {
70
- Mage::throwException(Mage::helper('klarna')->__('Unknown address, please specify correct personal id in the payment selection and press Fetch again, or use another payment method'));
71
- }
72
- }
73
-
74
- //Check to see if the addresses must be same. If so overwrite billing
75
- //address with the shipping address.
76
- if ($this->shippingSameAsBilling()) {
77
- $this->updateBillingAddress();
78
- }
79
- }
80
-
81
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/community/Vaimo/Klarna/Model/Klarna/Tools/Address.php DELETED
@@ -1,183 +0,0 @@
1
- <?php
2
- /**
3
- * Copyright (c) 2009-2014 Vaimo AB
4
- *
5
- * Vaimo reserves all rights in the Program as delivered. The Program
6
- * or any portion thereof may not be reproduced in any form whatsoever without
7
- * the written consent of Vaimo, except as provided by licence. A licence
8
- * under Vaimo's rights in the Program may be available directly from
9
- * Vaimo.
10
- *
11
- * Disclaimer:
12
- * THIS NOTICE MAY NOT BE REMOVED FROM THE PROGRAM BY ANY USER THEREOF.
13
- * THE PROGRAM IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
14
- * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
16
- * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
- * OUT OF OR IN CONNECTION WITH THE PROGRAM OR THE USE OR OTHER DEALINGS
19
- * IN THE PROGRAM.
20
- *
21
- * @category Vaimo
22
- * @package Vaimo_Klarna
23
- * @copyright Copyright (c) 2009-2014 Vaimo AB
24
- */
25
-
26
- class Vaimo_Klarna_Model_Klarna_Tools_Address extends Vaimo_Klarna_Model_Klarna_Tools_Abstract
27
- {
28
- /**
29
- * Split a string into an array consisting of Street, House Number and
30
- * House extension.
31
- *
32
- * @param string $address Address string to split
33
- *
34
- * @return array
35
- */
36
- protected static function _splitAddress($address)
37
- {
38
- // Get everything up to the first number with a regex
39
- $hasMatch = preg_match('/^[^0-9]*/', $address, $match);
40
-
41
- // If no matching is possible, return the supplied string as the street
42
- if (!$hasMatch) {
43
- return array($address, "", "");
44
- }
45
-
46
- // Remove the street from the address.
47
- $address = str_replace($match[0], "", $address);
48
- $street = trim($match[0]);
49
-
50
- // Nothing left to split, return
51
- if (strlen($address) == 0) {
52
- return array($street, "", "");
53
- }
54
- // Explode address to an array
55
- $addrArray = explode(" ", $address);
56
-
57
- // Shift the first element off the array, that is the house number
58
- $housenumber = array_shift($addrArray);
59
-
60
- // If the array is empty now, there is no extension.
61
- if (count($addrArray) == 0) {
62
- return array($street, $housenumber, "");
63
- }
64
-
65
- // Join together the remaining pieces as the extension.
66
- $extension = implode(" ", $addrArray);
67
-
68
- return array($street, $housenumber, $extension);
69
- }
70
-
71
- /**
72
- * Get the formatted street required for a Klarna Addr
73
- *
74
- * @param string $street The street to split
75
- * @param array $split An array determining the parts of the split
76
- *
77
- * @return array
78
- */
79
- protected function _splitStreet($street)
80
- {
81
- $split = $this->_getSplit();
82
- $result = array(
83
- 'street' => '',
84
- 'house_extension' => '',
85
- 'house_number' => ''
86
- );
87
- $elements = $this->_splitAddress($street);
88
- $result['street'] = $elements[0];
89
-
90
- if (in_array('house_extension', $split)) {
91
- $result['house_extension'] = $elements[2];
92
- } else {
93
- $elements[1] .= ' ' . $elements[2];
94
- }
95
-
96
- if (in_array('house_number', $split)) {
97
- $result['house_number'] = $elements[1];
98
- } else {
99
- $result['street'] .= ' ' . $elements[1];
100
- }
101
-
102
- return array_map('trim', $result);
103
- }
104
-
105
- /**
106
- * Update a Magento address with an array containing address information
107
- *
108
- * @param array $addr The addr to use
109
- *
110
- * @return void
111
- */
112
- protected function _updateShippingWithSelectedAddress($addr)
113
- {
114
- $selAddr = new Varien_Object($addr);
115
- $address = $this->getShippingAddress();
116
- $street = $selAddr->getStreet();
117
-
118
- if ($selAddr->getHouseNumber()) {
119
- $street .= " " . $selAddr->getHouseNumber();
120
- }
121
- if ($selAddr->getHouseExtension()) {
122
- $street .= " " . $selAddr->getHouseExtension();
123
- }
124
-
125
- // If it's a company purchase set company name.
126
- $company = $selAddr->getCompanyName();
127
- if ($company!="" && $this->isCompanyAllowed()) {
128
- $address->setCompany($company);
129
- } else {
130
- $address->setFirstname($selAddr->getFirstName())
131
- ->setLastname($selAddr->getLastName())
132
- ->setCompany('');
133
- }
134
-
135
- $address->setPostcode($selAddr->getZip())
136
- ->setStreet(trim($street))
137
- ->setCity($selAddr->getCity())
138
- ->save();
139
- }
140
-
141
- /**
142
- * Update a Magento address with another Magento address and save it.
143
- *
144
- * @return void
145
- */
146
- public function updateBillingAddress()
147
- {
148
- $this->getBillingAddress()->setFirstname($this->getShippingAddress()->getFirstname())
149
- ->setLastname($this->getShippingAddress()->getLastname())
150
- ->setPostcode($this->getShippingAddress()->getPostcode())
151
- ->setStreet($this->getShippingAddress()->getStreet())
152
- ->setCity($this->getShippingAddress()->getCity())
153
- ->setTelephone($this->getShippingAddress()->getTelephone())
154
- ->setCountry($this->getShippingAddress()->getCountry())
155
- ->setCompany($this->getShippingAddress()->getCompany())
156
- ->save();
157
- }
158
-
159
- /**
160
- * Get a unique key used to identify the given address
161
- *
162
- * The key is a hash of the lower bit ascii portion of company name,
163
- * first name, last name and street joined with pipes
164
- *
165
- * @param KlarnaAddr $klarnaAddr address
166
- *
167
- * @return string key for this address
168
- */
169
- public static function getAddressKey($klarnaAddr)
170
- {
171
- return hash(
172
- 'crc32',
173
- preg_replace(
174
- '/[^\w]*/', '',
175
- $klarnaAddr->getCompanyName() . '|' .
176
- $klarnaAddr->getFirstName() . '|' .
177
- $klarnaAddr->getLastName() . '|' .
178
- $klarnaAddr->getStreet()
179
- )
180
- );
181
- }
182
-
183
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/community/Vaimo/Klarna/Model/Klarna/Tools/Api.php DELETED
@@ -1,744 +0,0 @@
1
- <?php
2
- /**
3
- * Copyright (c) 2009-2014 Vaimo AB
4
- *
5
- * Vaimo reserves all rights in the Program as delivered. The Program
6
- * or any portion thereof may not be reproduced in any form whatsoever without
7
- * the written consent of Vaimo, except as provided by licence. A licence
8
- * under Vaimo's rights in the Program may be available directly from
9
- * Vaimo.
10
- *
11
- * Disclaimer:
12
- * THIS NOTICE MAY NOT BE REMOVED FROM THE PROGRAM BY ANY USER THEREOF.
13
- * THE PROGRAM IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
14
- * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
16
- * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
- * OUT OF OR IN CONNECTION WITH THE PROGRAM OR THE USE OR OTHER DEALINGS
19
- * IN THE PROGRAM.
20
- *
21
- * @category Vaimo
22
- * @package Vaimo_Klarna
23
- * @copyright Copyright (c) 2009-2014 Vaimo AB
24
- */
25
-
26
- class Vaimo_Klarna_Model_Klarna_Tools_Api extends Vaimo_Klarna_Model_Klarna_Tools_Address
27
- {
28
- protected $_additionalInfo = NULL;
29
- protected $_goods_list = array();
30
- protected $_extras = array();
31
-
32
- protected $_pclasses = array();
33
-
34
- const FLAG_ITEM_NORMAL = "normal";
35
- const FLAG_ITEM_SHIPPING_FEE = "shipping";
36
- const FLAG_ITEM_HANDLING_FEE = "handling";
37
-
38
- const REFUND_METHOD_FULL = "full";
39
- const REFUND_METHOD_PART = "part";
40
- const REFUND_METHOD_AMOUNT = "amount";
41
-
42
-
43
- /**
44
- * Build the PClass URI
45
- *
46
- * @return array
47
- */
48
- protected function _getPCURI()
49
- {
50
- $mageConfig = Mage::getResourceModel('sales/order')->getReadConnection()->getConfig();
51
- return array(
52
- "user" => $mageConfig['username'],
53
- "passwd" => $mageConfig['password'],
54
- "dsn" => $mageConfig['host'],
55
- "db" => $mageConfig['dbname'],
56
- "table" => "klarnapclasses"
57
- );
58
- }
59
-
60
- protected function _setAdditionalInformation($data, $value = NULL)
61
- {
62
- if (!$data) return;
63
- if ($value && !is_array($data)) {
64
- if ($this->_additionalInfo) {
65
- $this->_additionalInfo->setData($data, $value);
66
- } else {
67
- $this->_additionalInfo = new Varien_Object(array($data, $value));
68
- }
69
- } else {
70
- if ($this->_additionalInfo) {
71
- $this->_additionalInfo->setData($data);
72
- } else {
73
- $this->_additionalInfo = new Varien_Object($data);
74
- }
75
- }
76
- }
77
-
78
- protected function _unsetAdditionalInformation($field)
79
- {
80
- $this->_additionalInfo->unsetData($field);
81
- }
82
-
83
- protected function _getAdditionalInformation($field = '')
84
- {
85
- return $this->_additionalInfo->getData($field);
86
- }
87
-
88
- protected function _getGoodsList()
89
- {
90
- return $this->_goods_list;
91
- }
92
-
93
- protected function _getExtras()
94
- {
95
- return $this->_extras;
96
- }
97
-
98
- /**
99
- * Get the Personal Number associated to this purchase
100
- *
101
- * @return string
102
- */
103
- protected function _getPNO()
104
- {
105
- if ($this->needDateOfBirth()) {
106
- if ((array_key_exists("dob_day", $this->_getAdditionalInformation()))
107
- && (array_key_exists("dob_month", $this->_getAdditionalInformation()))
108
- && (array_key_exists("dob_year", $this->_getAdditionalInformation()))
109
- ) {
110
- return $this->_getAdditionalInformation("dob_day")
111
- . $this->_getAdditionalInformation("dob_month")
112
- . $this->_getAdditionalInformation("dob_year");
113
- }
114
- } elseif (array_key_exists("pno", $this->_getAdditionalInformation())
115
- && strlen($this->_getAdditionalInformation("pno")) > 0
116
- ) {
117
- return $this->_getAdditionalInformation("pno");
118
- }
119
- return "";
120
- }
121
-
122
- /**
123
- * Get the gender associated to this purchase
124
- *
125
- * @return null|int
126
- */
127
- protected function _getGender()
128
- {
129
- if ($this->needGender() && array_key_exists("gender", $this->_getAdditionalInformation())) {
130
- return $this->_getAdditionalInformation("gender");
131
- }
132
- return null;
133
- }
134
-
135
- /**
136
- * Get the payment plan associated to this purchase
137
- *
138
- * @return int
139
- */
140
- protected function _getPaymentPlan()
141
- {
142
- if ((array_key_exists(Vaimo_Klarna_Helper_Data::KLARNA_INFO_FIELD_PAYMENT_PLAN, $this->_getAdditionalInformation()))
143
- && ($this->getOrder()->getPayment()->getMethod() !== "klarna_invoice")
144
- ) {
145
- return (int)$this->_getAdditionalInformation(Vaimo_Klarna_Helper_Data::KLARNA_INFO_FIELD_PAYMENT_PLAN);
146
- }
147
- return -1;
148
- }
149
-
150
- /**
151
- * Returns the tax rate
152
- *
153
- * @param int $taxClass The tax class to get the rate for
154
- *
155
- * @return double The tax rate
156
- */
157
- protected function _getTaxRate($taxClass)
158
- {
159
- // Load the customer so we can retrevice the correct tax class id
160
- $customer = Mage::getModel('customer/customer')->load($this->getOrder()->getCustomerId());
161
- $calculation = Mage::getSingleton('tax/calculation');
162
- $request = $calculation->getRateRequest(
163
- $this->getShippingAddress(),
164
- $this->getBillingAddress(),
165
- $customer->getTaxClassId(),
166
- $this->getOrder()->getStore()
167
- );
168
- return $calculation->getRate($request->setProductClassId($taxClass));
169
- }
170
-
171
- /**
172
- * Klarna supports three different types of refunds, full, part and amount
173
- * If any additional amount is specified, it will refund amount wise
174
- * If The entire amount is refunded, it will be a full refund
175
- * If above alternatives are false, it will refund part (meaning per item)
176
- * The exception to this is if you have discounts, then the orderline in Klarna
177
- * is the non-discounted one, followed by a total discount amount line.
178
- * Then it is impossible to refund part, then we need the amount refund.
179
- *
180
- * @param float $amount The amount to refund
181
- *
182
- * @return string One of the const methods defined above
183
- */
184
- protected function _decideRefundMethod($amount)
185
- {
186
- $res = self::REFUND_METHOD_PART;
187
- $remaining = $this->getOrder()->getTotalInvoiced() - $this->getOrder()->getTotalOnlineRefunded(); // - $this->getOrder()->getShippingRefunded();
188
- if (abs($remaining - $amount) < 0.00001) {
189
- $res = self::REFUND_METHOD_FULL;
190
- } else {
191
- if ($this->getCreditmemo()->getAdjustmentPositive()!=0 || $this->getCreditmemo()->getAdjustmentNegative()!=0) {
192
- $res = self::REFUND_METHOD_AMOUNT;
193
- } else {
194
- foreach ($this->_getExtras() as $extra) {
195
- if (isset($extra['flags'])) {
196
- switch ($extra['flags']) {
197
- case self::FLAG_ITEM_HANDLING_FEE:
198
- if ($this->getCreditmemo()->getVaimoKlarnaFeeRefund()>0) {
199
- if (isset($extra['original_price'])) {
200
- if ($extra['original_price']!=$extra['price']) { // If not full shipping refunded, it will use refund amount instead
201
- $res = self::REFUND_METHOD_AMOUNT;
202
- }
203
- }
204
- }
205
- break;
206
- case self::FLAG_ITEM_SHIPPING_FEE;
207
- if ($this->getCreditmemo()->getShippingAmount()>0) {
208
- if (isset($extra['original_price'])) {
209
- if ($extra['original_price']!=$extra['price']) { // If not full shipping refunded, it will use refund amount instead
210
- $res = self::REFUND_METHOD_AMOUNT;
211
- }
212
- }
213
- }
214
- break;
215
- case self::FLAG_ITEM_NORMAL:
216
- break;
217
- default:
218
- break;
219
- }
220
- }
221
- }
222
- }
223
- $discount_amount = 0;
224
- foreach ($this->getOrder()->getItemsCollection() as $item) {
225
- $discount_amount += $item->getDiscountAmount();
226
- }
227
- if ($discount_amount) {
228
- $res = self::REFUND_METHOD_AMOUNT;
229
- }
230
- }
231
- return $res;
232
- }
233
-
234
- protected function _checkBundles($items, &$item, $product)
235
- {
236
- if ($item->getProductType()==Mage_Catalog_Model_Product_Type::TYPE_BUNDLE) {
237
- if ($product->getPriceType()==Mage_Bundle_Model_Product_Price::PRICE_TYPE_DYNAMIC) {
238
- $item->setPriceInclTax(0);
239
- }
240
- }
241
- }
242
-
243
- /**
244
- * Create the goods list for Reservations
245
- *
246
- * @param array $items The items to add to the goods list
247
- *
248
- * @return void
249
- */
250
- protected function _createGoodsList($items = null)
251
- {
252
- if ($items === null) {
253
- $items = $this->getOrder()->getAllVisibleItems();
254
- }
255
-
256
- $taxRate = NULL;
257
-
258
- foreach ($items as $item) {
259
-
260
- if (Mage::helper('klarna')->shouldItemBeIncluded($item)==false) continue;
261
-
262
- //For handling the different activation
263
- $qty = $item->getQtyOrdered(); //Standard
264
- if (!isset($qty)) {
265
- $qty = $item->getQty(); //Advanced
266
- }
267
- $id = $item->getProductId();
268
- $product = Mage::getModel('catalog/product')->load($id);
269
-
270
- $this->_checkBundles($items, $item, $product);
271
-
272
- $taxRate = $this->_getTaxRate($product->getTaxClassId());
273
-
274
- $this->_goods_list[] =
275
- array(
276
- "qty" => $qty,
277
- "sku" => $item->getSku(),
278
- "name" => $item->getName(),
279
- "price" => $item->getPriceInclTax(),
280
- "tax" => $taxRate,
281
- "discount" => 0,
282
- "flags" => self::FLAG_ITEM_NORMAL
283
- );
284
- }
285
-
286
- //Only add discounts and etc for unactivated orders
287
- if ($this->getOrder()->hasInvoices() <= 1) {
288
- $this->_addExtraFees($taxRate);
289
- }
290
- }
291
-
292
- /**
293
- * Create the goods list for Refunds
294
- *
295
- * @param array $items The items to add to the goods list
296
- *
297
- * @return void
298
- */
299
- protected function _createRefundGoodsList($items = null)
300
- {
301
- if ($items === null) {
302
- $this->_logKlarnaApi('_createRefundGoodsList got no items. Order: ' . $this->getOrder()->getIncrementId());
303
- }
304
-
305
- $taxRate = NULL;
306
-
307
- if ($items) {
308
- foreach ($items as $item) {
309
- $qty = $item->getQty();
310
- $id = $item->getProductId();
311
- $product = Mage::getModel('catalog/product')->load($id);
312
-
313
- $taxRate = $this->_getTaxRate($product->getTaxClassId());
314
-
315
- $this->_goods_list[] =
316
- array(
317
- "qty" => $qty,
318
- "sku" => $item->getSku(),
319
- "name" => $item->getName(),
320
- "price" => $item->getPriceInclTax(),
321
- "tax" => $taxRate,
322
- "discount" => 0,
323
- "flags" => self::FLAG_ITEM_NORMAL
324
- );
325
- }
326
- }
327
- // Add same extra fees as original order, then remove the ones that should not be refunded
328
- $this->_addExtraFees($taxRate);
329
- foreach ($this->_getExtras() as $id => $extra) {
330
- if (isset($extra['flags'])) {
331
- switch ($extra['flags']) {
332
- case self::FLAG_ITEM_HANDLING_FEE:
333
- if ($this->getCreditmemo()->getVaimoKlarnaFeeRefund()>0) { // If not full invoice fee refunded, it will use refund amount instead
334
- $this->_extras[$id]['original_price'] = $this->_extras[$id]['price'];
335
- $this->_extras[$id]['price'] = $this->getCreditmemo()->getVaimoKlarnaFeeRefund();
336
- } else {
337
- unset($this->_extras[$id]);
338
- }
339
- break;
340
- case self::FLAG_ITEM_SHIPPING_FEE;
341
- if ($this->getCreditmemo()->getShippingAmount()>0) { // If not full shipping refunded, it will use refund amount instead
342
- $this->_extras[$id]['original_price'] = $this->_extras[$id]['price'];
343
- $this->_extras[$id]['price'] = $this->getCreditmemo()->getShippingAmount();
344
- } else {
345
- unset($this->_extras[$id]);
346
- }
347
- break;
348
- case self::FLAG_ITEM_NORMAL:
349
- unset($this->_extras[$id]);
350
- break;
351
- default:
352
- unset($this->_extras[$id]);
353
- break;
354
- }
355
-
356
- } else {
357
- unset($this->_extras[$id]);
358
- }
359
- }
360
- }
361
-
362
- /**
363
- * Returns the total handling fee included in extras
364
- *
365
- * @return decimal
366
- */
367
- protected function _feeAmountIncluded()
368
- {
369
- $res = 0;
370
- foreach ($this->_getExtras() as $extra) {
371
- if (isset($extra['flags'])) {
372
- if ($extra['flags']==self::FLAG_ITEM_HANDLING_FEE) {
373
- $res = $res + $extra['price'];
374
- }
375
- }
376
- }
377
- return $res;
378
- }
379
-
380
- /**
381
- * Add all possible fees and discounts.
382
- *
383
- * @return void
384
- */
385
- protected function _addExtraFees($taxRate)
386
- {
387
- $this->_addInvoiceFee();
388
-
389
- $this->_addShippingFee();
390
-
391
- $this->_addGiftCard();
392
-
393
- $this->_addCustomerBalance();
394
-
395
- $this->_addRewardCurrency();
396
-
397
- $this->_addGiftWrapPrice();
398
-
399
- $this->_addGiftWrapItemPrice();
400
-
401
- $this->_addGwPrintedCardPrice();
402
-
403
- $this->_addDiscount($taxRate);
404
-
405
- }
406
-
407
- /**
408
- * Add the Gift Wrap Order price to the goods list
409
- *
410
- * @return void
411
- */
412
- protected function _addGiftWrapPrice()
413
- {
414
- if ($this->getOrder()->getGwPrice() <= 0) {
415
- return;
416
- }
417
-
418
- $price = $this->getOrder()->getGwPrice();
419
- $tax = $this->getOrder()->getGwTaxAmount();
420
-
421
- $sku = Mage::helper('klarna')->__('gw_order');
422
-
423
- $name = Mage::helper("enterprise_giftwrapping")->__("Gift Wrapping for Order");
424
- $this->_extras[] = array(
425
- "qty" => 1,
426
- "sku" => $sku,
427
- "name" => $name,
428
- "price" => $price + $tax,
429
- );
430
- }
431
-
432
- /**
433
- * Add the Gift Wrap Item price to the goods list
434
- *
435
- * @return void
436
- */
437
- protected function _addGiftWrapItemPrice()
438
- {
439
- if ($this->getOrder()->getGwItemsPrice() <= 0) {
440
- return;
441
- }
442
-
443
- $price = $this->getOrder()->getGwItemsPrice();
444
- $tax = $this->getOrder()->getGwItemsTaxAmount();
445
-
446
- $name = Mage::helper("enterprise_giftwrapping")->__("Gift Wrapping for Items");
447
-
448
- $sku = Mage::helper('klarna')->__('gw_items');
449
-
450
- $this->_extras[] = array(
451
- "qty" => 1,
452
- "sku" => $sku,
453
- "name" => $name,
454
- "price" => $price + $tax
455
- );
456
- }
457
-
458
- /**
459
- * Add the Gift Wrap Printed Card to the goods list
460
- *
461
- * @return void
462
- */
463
- protected function _addGwPrintedCardPrice()
464
- {
465
- if ($this->getOrder()->getGwPrintedCardPrice() <= 0) {
466
- return;
467
- }
468
-
469
- $price = $this->getOrder()->getGwPrintedCardPrice();
470
- $tax = $this->getOrder()->getGwPrintedCardTaxAmount();
471
-
472
- $name = Mage::helper("enterprise_giftwrapping")->__("Printed Card");
473
-
474
- $sku = Mage::helper('klarna')->__('gw_printed_card');
475
-
476
- $this->_extras[] = array(
477
- "qty" => 1,
478
- "sku" => $sku,
479
- "name" => $name,
480
- "price" => $price + $tax
481
- );
482
- }
483
-
484
- /**
485
- * Add the gift card amount to the goods list
486
- *
487
- * @return void
488
- */
489
- protected function _addGiftCard()
490
- {
491
- if ($this->getOrder()->getGiftCardsAmount() <= 0) {
492
- return;
493
- }
494
-
495
- $sku = Mage::helper('klarna')->__('gift_card');
496
-
497
- $this->_extras[] = array(
498
- "qty" => 1,
499
- "sku" => $sku,
500
- "name" => Mage::helper('klarna')->__('Gift Card'),
501
- "price" => ($this->getOrder()->getGiftCardsAmount() * -1)
502
- );
503
- }
504
-
505
- /**
506
- * Add the customer balance to the goods list
507
- *
508
- * @return void
509
- */
510
- protected function _addCustomerBalance()
511
- {
512
- if ($this->getOrder()->getCustomerBalanceAmount() <= 0) {
513
- return;
514
- }
515
-
516
- $sku = Mage::helper('klarna')->__('customer_balance');
517
-
518
- $this->_extras[] = array(
519
- "qty" => 1,
520
- "sku" => $sku,
521
- "name" => Mage::helper('klarna')->__("Customer Balance"),
522
- "price" => ($this->getOrder()->getCustomerBalanceAmount() * -1)
523
- );
524
- }
525
-
526
- /**
527
- * Add a reward currency amount to the goods list
528
- *
529
- * @return void
530
- */
531
- protected function _addRewardCurrency()
532
- {
533
- if ($this->getOrder()->getRewardCurrencyAmount() <= 0) {
534
- return;
535
- }
536
-
537
- $sku = Mage::helper('klarna')->__('reward_currency');
538
-
539
- $this->_extras[] = array(
540
- "qty" => 1,
541
- "sku" => $sku,
542
- "name" => Mage::helper('klarna')->__('Reward Currency'),
543
- "price" => ($this->getOrder()->getRewardCurrencyAmount() * -1)
544
- );
545
- }
546
-
547
- /**
548
- * Add the invoice fee to the goods list
549
- *
550
- * @return void
551
- */
552
- protected function _addInvoiceFee()
553
- {
554
- if ($this->getOrder()->getPayment()->getMethod() != Vaimo_Klarna_Helper_Data::KLARNA_METHOD_INVOICE) {
555
- return;
556
- }
557
- if ($this->_getAdditionalInformation(Vaimo_Klarna_Helper_Data::KLARNA_INFO_FIELD_FEE)==0) {
558
- return;
559
- }
560
-
561
- $sku = Mage::helper('klarna')->__('invoice_fee');
562
-
563
- $this->_extras[] = array(
564
- "qty" => 1,
565
- "sku" => $sku,
566
- "name" => Mage::helper('klarna')->getKlarnaFeeLabel($this->getOrder()->getStore()),
567
- "price" => $this->_getAdditionalInformation(Vaimo_Klarna_Helper_Data::KLARNA_INFO_FIELD_FEE) + $this->_getAdditionalInformation(Vaimo_Klarna_Helper_Data::KLARNA_INFO_FIELD_FEE_TAX),
568
- "tax" => Mage::helper('klarna')->getVaimoKlarnaFeeVatRate($this->getOrder()),
569
- "flags" => self::FLAG_ITEM_HANDLING_FEE
570
- );
571
- }
572
-
573
- /**
574
- * Add the shipment fee to the goods list
575
- *
576
- * @return void
577
- */
578
- protected function _addShippingFee()
579
- {
580
- if ($this->getOrder()->getShippingInclTax() <= 0) {
581
- return;
582
- }
583
- $taxClass = Mage::getStoreConfig('tax/classes/shipping_tax_class');
584
-
585
- $sku = $this->getOrder()->getShippingMethod();
586
-
587
- if (!$sku) {
588
- $sku = Mage::helper('klarna')->__('discount');
589
- }
590
-
591
- $this->_extras[] = array(
592
- "qty" => 1,
593
- "sku" => $sku,
594
- "name" => $this->getOrder()->getShippingDescription(),
595
- "price" => $this->getOrder()->getShippingInclTax(),
596
- "tax" => $this->_getTaxRate($taxClass),
597
- "flags" => self::FLAG_ITEM_SHIPPING_FEE
598
- );
599
- }
600
-
601
- /**
602
- * Add the discount to the goods list
603
- *
604
- * @param $taxRate is the VAT rate of the LAST product in cart... Not perfect of course, but better than no VAT. It must be an official rate, can't be median
605
- * @return void
606
- */
607
- protected function _addDiscount($taxRate)
608
- {
609
- if ($this->getOrder()->getDiscountAmount() >= 0) {
610
- return;
611
- }
612
- // Instead of calculating discount from order etc, we now simply use the amounts we are adding to goods list
613
-
614
- //calculate grandtotal and subtotal with all possible fees and extra costs
615
- $subtotal = $this->getOrder()->getSubtotalInclTax();
616
- $grandtotal = $this->getOrder()->getGrandTotal();
617
-
618
- //if fee is added, add to subtotal
619
- //if discount is added, like cards and such, add to grand total
620
- foreach ($this->_extras as $extra) {
621
- if ($extra['price'] > 0) {
622
- $subtotal+= $extra['price'];
623
- } else if ($extra['price'] < 0) {
624
- $grandtotal+= $extra['price'];
625
- }
626
- }
627
-
628
- //now check what the actual discount incl vat is
629
- $amount = $grandtotal - $subtotal; //grand total is always incl tax
630
-
631
- /*
632
- $amount = $this->getOrder()->getDiscountAmount();
633
- $applyAfter = Mage::helper('tax')->applyTaxAfterDiscount( $this->getOrder()->getStoreId() );
634
- $prodInclVat = Mage::helper('tax')->priceIncludesTax( $this->getOrder()->getStoreId() );
635
- if ($applyAfter == true) {
636
- //With this setting active the discount will not have the correct
637
- //value. We need to take each respective products rate and calculate
638
- //a new value.
639
-
640
- // The interesting part is that Magento changes how discounts are
641
- // added depending on if product prices are including VAT or not...
642
- if ($prodInclVat == false) {
643
- $amount = 0;
644
- foreach ($this->getOrder()->getAllVisibleItems() as $product) {
645
- $rate = $product->getTaxPercent();
646
- $newAmount = $product->getDiscountAmount() * (($rate / 100 ) + 1);
647
- $amount -= $newAmount;
648
- }
649
- //If the discount also extends to shipping
650
- $shippingDiscount = $this->getOrder()->getShippingDiscountAmount() - 0;
651
- if ($shippingDiscount) {
652
- $taxClass = Mage::getStoreConfig('tax/classes/shipping_tax_class');
653
- $rate = $this->_getTaxRate($taxClass);
654
- $newAmount = $shippingDiscount * (($rate / 100 ) + 1);
655
- $amount -= $newAmount;
656
- }
657
- }
658
- }
659
- */
660
-
661
- $sku = $this->getOrder()->getDiscountDescription();
662
-
663
- if (!$sku) {
664
- $sku = Mage::helper('klarna')->__('discount');
665
- }
666
-
667
- $this->_extras[] = array(
668
- "qty" => 1,
669
- "sku" => $sku,
670
- "name" => Mage::helper('sales')->__('Discount (%s)', $sku),
671
- "price" => $amount,
672
- "tax" => $taxRate
673
- );
674
- }
675
-
676
- /**
677
- * Get the store information to use for fetching new PClasses
678
- *
679
- * @param storeIds a comma separated list of stores as a filter which ones to include
680
- *
681
- * @return array of store ids where Klarna is active
682
- */
683
- protected function _getKlarnaActiveStores()
684
- {
685
- $result = array();
686
- foreach (Mage::app()->getStores() as $store) {
687
- if (!$store->getConfig('payment/' . Vaimo_Klarna_Helper_Data::KLARNA_METHOD_ACCOUNT . '/active')
688
- && !$store->getConfig('payment/' . Vaimo_Klarna_Helper_Data::KLARNA_METHOD_SPECIAL . '/active')
689
- ) {
690
- continue;
691
- }
692
- $result[] = $store->getId();
693
- }
694
- return $result;
695
- }
696
-
697
- /*
698
- * We do not want to save things in the database that doesn't need to be there
699
- * Personal ID is also removed from database
700
- *
701
- * @return void
702
- */
703
- protected function _cleanAdditionalInfo()
704
- {
705
- if (array_key_exists("pno", $this->_getAdditionalInformation())) {
706
- $pno = $this->_getAdditionalInformation("pno");
707
- if (strlen($pno) > 0) {
708
- $this->getPayment()->unsAdditionalInformation("pno");
709
- }
710
- Mage::dispatchEvent( 'vaimo_klarna_pno_used_to_reserve', array(
711
- 'store_id' => $this->getOrder()->getStoreId(),
712
- 'order_id' => $this->getOrder()->getIncrementId(),
713
- 'customer_id' => $this->getOrder()->getCustomerId(),
714
- 'pno' => $pno
715
- ));
716
- }
717
- if (array_key_exists("consent", $this->_getAdditionalInformation())) {
718
- if ($this->_getAdditionalInformation("consent")=="NO") {
719
- $this->getPayment()->unsAdditionalInformation("consent");
720
- }
721
- }
722
- if (array_key_exists("gender", $this->_getAdditionalInformation())) {
723
- if ($this->_getAdditionalInformation("gender")=="-1") {
724
- $this->getPayment()->unsAdditionalInformation("gender");
725
- }
726
- }
727
- }
728
-
729
- /*
730
- * Whenever a refund, capture, reserve or cancel is performed, we send out an event
731
- * This can be listened to for financial reconciliation
732
- *
733
- * @return void
734
- */
735
- protected function _sendMethodEvent($eventcode, $amount)
736
- {
737
- Mage::dispatchEvent( $eventcode, array(
738
- 'store_id' => $this->getOrder()->getStoreId(),
739
- 'order_id' => $this->getOrder()->getIncrementId(),
740
- 'method' => $this->getMethod(),
741
- 'amount' => $amount
742
- ));
743
- }
744
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/community/Vaimo/Klarna/Model/Klarna/Validate.php DELETED
@@ -1,161 +0,0 @@
1
- <?php
2
- /**
3
- * Copyright (c) 2009-2014 Vaimo AB
4
- *
5
- * Vaimo reserves all rights in the Program as delivered. The Program
6
- * or any portion thereof may not be reproduced in any form whatsoever without
7
- * the written consent of Vaimo, except as provided by licence. A licence
8
- * under Vaimo's rights in the Program may be available directly from
9
- * Vaimo.
10
- *
11
- * Disclaimer:
12
- * THIS NOTICE MAY NOT BE REMOVED FROM THE PROGRAM BY ANY USER THEREOF.
13
- * THE PROGRAM IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
14
- * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
16
- * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
- * OUT OF OR IN CONNECTION WITH THE PROGRAM OR THE USE OR OTHER DEALINGS
19
- * IN THE PROGRAM.
20
- *
21
- * @category Vaimo
22
- * @package Vaimo_Klarna
23
- * @copyright Copyright (c) 2009-2014 Vaimo AB
24
- */
25
-
26
- class Vaimo_Klarna_Model_Klarna_Validate extends Vaimo_Klarna_Model_Klarna_Tools_Address
27
- {
28
- protected $_postValues = array();
29
-
30
- public function __construct()
31
- {
32
- parent::__construct();
33
- $this->_setFunctionName('validate');
34
- }
35
-
36
- /**
37
- * Check that Date of birth has been supplied if required.
38
- *
39
- * @return bool
40
- */
41
- public function checkDateOfBirth()
42
- {
43
- try {
44
- $data = $this->getInfoInstance();
45
- if (!$data->getAdditionalInformation('dob_day') ||
46
- !$data->getAdditionalInformation('dob_month') ||
47
- !$data->getAdditionalInformation('dob_year')) {
48
- return false;
49
- }
50
- if ($data->getAdditionalInformation('dob_day') === "00" ||
51
- $data->getAdditionalInformation('dob_month') === "00" ||
52
- $data->getAdditionalInformation('dob_year') === "00" ) {
53
- return false;
54
- }
55
- } catch (Mage_Core_Exception $e) {
56
- $this->logKlarnaException($e);
57
- return false;
58
- }
59
- return true;
60
- }
61
-
62
- protected function _checkField($field)
63
- {
64
- try {
65
- $data = $this->getInfoInstance();
66
- if (!$data->getAdditionalInformation($field)) {
67
- return false;
68
- }
69
- } catch (Mage_Core_Exception $e) {
70
- $this->logKlarnaException($e);
71
- return false;
72
- }
73
- return true;
74
- }
75
-
76
- /**
77
- * Check that consent has been given if needed.
78
- *
79
- * @return bool
80
- */
81
- public function checkConsent()
82
- {
83
- try {
84
- $data = $this->getInfoInstance();
85
- if ((!$data->getAdditionalInformation("consent"))
86
- || ($data->getAdditionalInformation("consent") !== "consent")) {
87
- return false;
88
- }
89
- } catch (Mage_Core_Exception $e) {
90
- $this->logKlarnaException($e);
91
- return false;
92
- }
93
- return true;
94
- }
95
-
96
- /**
97
- * Check that gender has been selected
98
- *
99
- * @return bool
100
- */
101
- public function checkGender()
102
- {
103
- try {
104
- $data = $this->getInfoInstance();
105
- if (($data->getAdditionalInformation("gender")!=="0")
106
- && ($data->getAdditionalInformation("gender")!=="1")) {
107
- return false;
108
- }
109
- } catch (Mage_Core_Exception $e) {
110
- $this->logKlarnaException($e);
111
- return false;
112
- }
113
- return true;
114
- }
115
-
116
- /**
117
- * Make sure phonenumber is not blank.
118
- *
119
- * @return bool
120
- */
121
- public function checkPhone()
122
- {
123
- return $this->_checkField("phonenumber");
124
- }
125
-
126
- /**
127
- * Make sure pno is not blank.
128
- *
129
- * @return bool
130
- */
131
- public function checkPno()
132
- {
133
- return $this->_checkField("pno");
134
- }
135
-
136
- public function doBasicTests()
137
- {
138
- if ($this->checkPhone()==false) {
139
- Mage::throwException(Mage::helper('klarna')->__('Phonenumber must be properly entered'));
140
- }
141
- if ($this->needDateOfBirth()) {
142
- if ($this->checkDateOfBirth()==false) {
143
- Mage::throwException(Mage::helper('klarna')->__('Date of birth fields must be properly entered'));
144
- }
145
- } else {
146
- if ($this->checkPno()==false) {
147
- Mage::throwException(Mage::helper('klarna')->__('Personal ID must not be empty'));
148
- }
149
- }
150
- if ($this->needConsent()) {
151
- if ($this->checkConsent()==false) {
152
- Mage::throwException(Mage::helper('klarna')->__('You need to agree to the terms to be able to continue'));
153
- }
154
- }
155
- if ($this->needGender()) {
156
- if ($this->checkGender()==false) {
157
- Mage::throwException(Mage::helper('klarna')->__('You need to enter your gender to be able to continue'));
158
- }
159
- }
160
- }
161
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/community/Vaimo/Klarna/Model/Klarnacheckout.php ADDED
@@ -0,0 +1,425 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Copyright (c) 2009-2014 Vaimo AB
4
+ *
5
+ * Vaimo reserves all rights in the Program as delivered. The Program
6
+ * or any portion thereof may not be reproduced in any form whatsoever without
7
+ * the written consent of Vaimo, except as provided by licence. A licence
8
+ * under Vaimo's rights in the Program may be available directly from
9
+ * Vaimo.
10
+ *
11
+ * Disclaimer:
12
+ * THIS NOTICE MAY NOT BE REMOVED FROM THE PROGRAM BY ANY USER THEREOF.
13
+ * THE PROGRAM IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
14
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
16
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ * OUT OF OR IN CONNECTION WITH THE PROGRAM OR THE USE OR OTHER DEALINGS
19
+ * IN THE PROGRAM.
20
+ *
21
+ * @category Vaimo
22
+ * @package Vaimo_Klarna
23
+ * @copyright Copyright (c) 2009-2014 Vaimo AB
24
+ */
25
+
26
+ class Vaimo_Klarna_Model_Klarnacheckout extends Vaimo_Klarna_Model_Klarnacheckout_Abstract
27
+ {
28
+ protected $_api = NULL;
29
+
30
+ public function __construct($setStoreInfo = true, $moduleHelper = NULL, $coreHttpHelper = NULL, $coreUrlHelper = NULL, $customerHelper = NULL)
31
+ {
32
+ parent::__construct($setStoreInfo, $moduleHelper, $coreHttpHelper, $coreUrlHelper, $customerHelper);
33
+ $this->_setFunctionName('klarnacheckout');
34
+ }
35
+
36
+ /**
37
+ * Function added for Unit testing
38
+ *
39
+ * @param $apiObject
40
+ */
41
+ public function setApi($apiObject)
42
+ {
43
+ $this->_api = $apiObject;
44
+ }
45
+
46
+ /**
47
+ * Will return the API object, it set, otherwise null
48
+ */
49
+ public function getApi()
50
+ {
51
+ return $this->_api;
52
+ }
53
+
54
+ /**
55
+ * Could have been added to getApi, but I made it separate for Unit testing
56
+ *
57
+ * @param $storeId
58
+ * @param $method
59
+ * @param $functionName
60
+ */
61
+ protected function _initApi($storeId, $method, $functionName)
62
+ {
63
+ if (!$this->getApi()) {
64
+ $this->setApi(Mage::getModel('klarna/api')->getApiInstance($storeId, $method, $functionName));
65
+ }
66
+ }
67
+
68
+ /**
69
+ * Init funcition
70
+ *
71
+ * @todo If storeid is null, we need to find first store where Klarna is active, not just trust that default store has it active...
72
+ */
73
+ protected function _init($functionName)
74
+ {
75
+ $this->_setFunctionName($this->_getFunctionName() . '-' . $functionName);
76
+ $this->_initApi($this->_getStoreId(), $this->getMethod(), $functionName);
77
+ $this->_api->init($this->getKlarnaSetup());
78
+ $this->_api->setTransport($this->_getTransport());
79
+ }
80
+
81
+
82
+ public function getKlarnaOrderHtml($checkoutId = null, $createIfNotExists = false, $updateItems = false)
83
+ {
84
+ $this->_init(Vaimo_Klarna_Helper_Data::KLARNA_API_CALL_KCODISPLAY_ORDER);
85
+ $this->_api->initKlarnaOrder($checkoutId, $createIfNotExists, $updateItems);
86
+ return $this->_api->getKlarnaCheckoutGui();
87
+ }
88
+
89
+ public function getCheckoutStatus($checkoutId = null)
90
+ {
91
+ $this->_init(Vaimo_Klarna_Helper_Data::KLARNA_API_CALL_KCODISPLAY_ORDER);
92
+ $this->_api->initKlarnaOrder($checkoutId);
93
+ return $this->_api->getKlarnaCheckoutStatus();
94
+ }
95
+
96
+ /*
97
+ * This function MUST BE DELETED, the code calling it and using the result must be
98
+ * rewritten!
99
+ *
100
+ */
101
+ public function getActualKlarnaOrder()
102
+ {
103
+ return $this->_api->getActualKlarnaOrder();
104
+ }
105
+
106
+ public function validateQuote($checkoutId)
107
+ {
108
+ /** @var Mage_Sales_Model_Quote $quote */
109
+ $quote = $this->_loadQuoteByKey($checkoutId, 'klarna_checkout_id');
110
+
111
+ if (!$quote->getId()) {
112
+ $this->logDebugInfo('validateQuote could not get quote');
113
+ return 'could not get quote';
114
+ }
115
+
116
+ if (!$quote->hasItems()) {
117
+ $this->logDebugInfo('validateQuote has no items');
118
+ return 'has no items';
119
+ }
120
+
121
+ if ($quote->getHasError()) {
122
+ $result = array('has error');
123
+ /** @var Mage_Core_Model_Message_Error $error */
124
+ foreach ($quote->getErrors() as $error) {
125
+ $result[] = $error->getText();
126
+ }
127
+ $this->logDebugInfo('validateQuote errors: ' . implode(" ", $result));
128
+ return implode("\n", $result);
129
+ }
130
+
131
+ if (!$quote->validateMinimumAmount()) {
132
+ $this->logDebugInfo('validateQuote below minimum amount');
133
+ return 'minimum amount';
134
+ }
135
+
136
+ $quote->reserveOrderId()->save();
137
+ $this->logDebugInfo('validateQuote reserved order id: ' . $quote->getReservedOrderId());
138
+
139
+ return true;
140
+ }
141
+
142
+ public function createOrder($checkoutId = null)
143
+ {
144
+ $this->_init(Vaimo_Klarna_Helper_Data::KLARNA_API_CALL_KCOCREATE_ORDER);
145
+ if (!$this->_api->initKlarnaOrder($checkoutId)) {
146
+ $this->logDebugInfo('createOrder could not get klarna order');
147
+ return 'could not get klarna order';
148
+ }
149
+
150
+ $quote = $this->_api->loadQuote();
151
+ if (!$quote) {
152
+ $this->logDebugInfo('createOrder could not get quote');
153
+ return 'could not get quote';
154
+ }
155
+ $this->setQuote($quote);
156
+
157
+ $varienOrder = $this->_api->initVarienOrder();
158
+ if (!$varienOrder) {
159
+ $this->logDebugInfo('createOrder could not create varienOrder');
160
+ return 'could not create varienOrder';
161
+ }
162
+
163
+ $billingStreetAddress = $varienOrder->getBillingAddress('street_address');
164
+ $billingStreetAddress2 = $varienOrder->getBillingAddress('street_address2');
165
+ $billingStreetName = $varienOrder->getBillingAddress('street_name');
166
+ $billingStreetNumber = $varienOrder->getBillingAddress('street_number');
167
+ $shippingStreetAddress = $varienOrder->getShippingAddress('street_address');
168
+ $shippingStreetAddress2 = $varienOrder->getShippingAddress('street_address2');
169
+ $shippingStreetName = $varienOrder->getShippingAddress('street_name');
170
+ $shippingStreetNumber = $varienOrder->getShippingAddress('street_number');
171
+
172
+ if(!$billingStreetAddress && $billingStreetName && $billingStreetNumber) {
173
+ $streetAddress = $varienOrder->getBillingAddress();
174
+ $streetAddress['street_address'] = $billingStreetName . ' ' . $billingStreetNumber;
175
+ $varienOrder->setBillingAddress($streetAddress);
176
+ }
177
+ if ($billingStreetAddress2) {
178
+ $streetAddress = $varienOrder->getBillingAddress();
179
+ $streetAddress['street_address'] = array($streetAddress['street_address'], $billingStreetAddress2);
180
+ $varienOrder->setBillingAddress($streetAddress);
181
+ }
182
+
183
+ if(!$shippingStreetAddress && $shippingStreetName && $shippingStreetNumber) {
184
+ $streetAddress = $varienOrder->getShippingAddress();
185
+ $streetAddress['street_address'] = $shippingStreetName . ' ' . $shippingStreetNumber;
186
+ $varienOrder->setShippingAddress($streetAddress);
187
+ }
188
+ if ($shippingStreetAddress2) {
189
+ $streetAddress = $varienOrder->getShippingAddress();
190
+ $streetAddress['street_address'] = array($streetAddress['street_address'], $shippingStreetAddress2);
191
+ $varienOrder->setShippingAddress($streetAddress);
192
+ }
193
+
194
+ if ($varienOrder->getStatus() != 'checkout_complete') {
195
+ $this->logDebugInfo('createOrder status not complete');
196
+ return 'status not complete';
197
+ }
198
+
199
+ $orderId = $this->_findAlreadyCreatedOrder($quote->getId());
200
+ if ($orderId>0) {
201
+ $this->logDebugInfo('createOrder order already created ' . $orderId);
202
+ return 'order already created';
203
+ }
204
+ $isNewCustomer = false;
205
+
206
+ if ($quote->getCustomerId()) {
207
+ $customer = $this->_loadCustomer($quote->getCustomerId());
208
+ $quote->setCustomer($customer);
209
+ $quote->setCheckoutMethod('customer');
210
+ } else {
211
+ /** @var $customer Mage_Customer_Model_Customer */
212
+ $customer = $this->_loadCustomerByEmail($varienOrder->getBillingAddress('email'), $quote->getStore());
213
+ if ($customer->getId()) {
214
+ $quote->setCustomer($customer);
215
+ $quote->setCheckoutMethod('customer');
216
+ } else {
217
+ $quote->setCheckoutMethod('register');
218
+ $isNewCustomer = true;
219
+ }
220
+ }
221
+
222
+ $billingAddress = $quote->getBillingAddress();
223
+ $customerAddressId = 0;
224
+
225
+ if ($customerAddressId) {
226
+ $customerAddress = $this->_loadCustomerAddress($customerAddressId);
227
+ if ($customerAddress->getId()) {
228
+ if ($customerAddress->getCustomerId() != $this->getQuote()->getCustomerId()) {
229
+ throw new Exception('Customer Address is not valid');
230
+ }
231
+
232
+ $billingAddress->importCustomerAddress($customerAddress)->setSaveInAddressBook(0);
233
+ }
234
+ } else {
235
+ $billingAddress->setFirstname($varienOrder->getBillingAddress('given_name'));
236
+ $billingAddress->setLastname($varienOrder->getBillingAddress('family_name'));
237
+ $billingAddress->setCareOf($varienOrder->getBillingAddress('care_of'));
238
+ $billingAddress->setStreet($varienOrder->getBillingAddress('street_address'));
239
+ $billingAddress->setPostcode($varienOrder->getBillingAddress('postal_code'));
240
+ $billingAddress->setCity($varienOrder->getBillingAddress('city'));
241
+ $billingAddress->setCountryId(strtoupper($varienOrder->getBillingAddress('country')));
242
+ $billingAddress->setEmail($varienOrder->getBillingAddress('email'));
243
+ $billingAddress->setTelephone($varienOrder->getBillingAddress('phone'));
244
+ $billingAddress->setSaveInAddressBook(1);
245
+ }
246
+
247
+ // $this->_validateCustomerData($data);
248
+
249
+ $shippingAddress = $quote->getShippingAddress();
250
+ $shippingAddress->setFirstname($varienOrder->getShippingAddress('given_name'));
251
+ $shippingAddress->setLastname($varienOrder->getShippingAddress('family_name'));
252
+ $shippingAddress->setCareOf($varienOrder->getShippingAddress('care_of'));
253
+ $shippingAddress->setStreet($varienOrder->getShippingAddress('street_address'));
254
+ $shippingAddress->setPostcode($varienOrder->getShippingAddress('postal_code'));
255
+ $shippingAddress->setCity($varienOrder->getShippingAddress('city'));
256
+ $shippingAddress->setCountryId(strtoupper($varienOrder->getShippingAddress('country')));
257
+ $shippingAddress->setEmail($varienOrder->getShippingAddress('email'));
258
+ $shippingAddress->setTelephone($varienOrder->getShippingAddress('phone'));
259
+
260
+ if ($this->getConfigData("packstation_enabled")) {
261
+ $shippingAddress->setSameAsBilling(0);
262
+ } else {
263
+ $shippingAddress->setSameAsBilling(1);
264
+ }
265
+ $shippingAddress->setSaveInAddressBook(0);
266
+
267
+ $quote->getBillingAddress()->setShouldIgnoreValidation(true);
268
+ $quote->getShippingAddress()->setShouldIgnoreValidation(true);
269
+
270
+ $quote->setTotalsCollectedFlag(true);
271
+ $quote->save();
272
+
273
+ switch ($quote->getCheckoutMethod()) {
274
+ case 'register':
275
+ $this->_prepareNewCustomerQuote($quote);
276
+ break;
277
+ case 'customer':
278
+ $this->_prepareCustomerQuote($quote);
279
+ break;
280
+ }
281
+
282
+ $service = $this->_getServiceQuote($quote);
283
+ $service->submitAll();
284
+
285
+ if ($isNewCustomer) {
286
+ try {
287
+ $this->_involveNewCustomer($quote);
288
+ } catch (Exception $e) {
289
+ $this->logKlarnaException($e);
290
+ }
291
+ }
292
+
293
+ $quote->save();
294
+
295
+ $reservation = $varienOrder->getReservation();
296
+ if ($varienOrder->getOrderId()) {
297
+ $reservation = $varienOrder->getOrderId();
298
+ }
299
+
300
+ // Update Order
301
+ /** @var $order Mage_Sales_Model_Order */
302
+ $order = $this->_loadOrderByKey($quote->getId());
303
+ $payment = $order->getPayment();
304
+
305
+ if ($varienOrder->getReference()) {
306
+ $payment->setAdditionalInformation(Vaimo_Klarna_Helper_Data::KLARNA_INFO_FIELD_REFERENCE, $varienOrder->getReference());
307
+ } else if ($varienOrder->getKlarnaReference()) {
308
+ $payment->setAdditionalInformation(Vaimo_Klarna_Helper_Data::KLARNA_INFO_FIELD_REFERENCE, $varienOrder->getKlarnaReference());
309
+ }
310
+
311
+ if ($reservation) {
312
+ $payment->setAdditionalInformation(Vaimo_Klarna_Helper_Data::KLARNA_INFO_FIELD_RESERVATION_ID, $reservation);
313
+ }
314
+
315
+ $payment->setAdditionalInformation(Vaimo_Klarna_Helper_Data::KLARNA_FORM_FIELD_PHONENUMBER, $varienOrder->getBillingAddress('phone'));
316
+ $payment->setAdditionalInformation(Vaimo_Klarna_Helper_Data::KLARNA_FORM_FIELD_EMAIL, $varienOrder->getBillingAddress('email'));
317
+
318
+ $payment->setAdditionalInformation(Vaimo_Klarna_Helper_Data::KLARNA_INFO_FIELD_HOST, $this->getConfigData("host") );
319
+ $payment->setAdditionalInformation(Vaimo_Klarna_Helper_Data::KLARNA_INFO_FIELD_MERCHANT_ID, $this->getConfigData("merchant_id") );
320
+
321
+
322
+ $payment->setTransactionId($reservation)
323
+ ->setIsTransactionClosed(0)
324
+ ->setStatus(Mage_Payment_Model_Method_Abstract::STATUS_APPROVED);
325
+ if ($transaction = $payment->addTransaction(Mage_Sales_Model_Order_Payment_Transaction::TYPE_AUTH)) {
326
+ $transaction->save();
327
+ }
328
+ $payment->save();
329
+
330
+ // send new order email
331
+ if ($order->getCanSendNewEmailFlag()) {
332
+ try {
333
+ $order->sendNewOrderEmail();
334
+ } catch (Exception $e) {
335
+ $this->logKlarnaException($e);
336
+ }
337
+ }
338
+
339
+ // Subscribe customer to newsletter
340
+ try {
341
+ if ($quote->getKlarnaCheckoutNewsletter()) {
342
+ $this->_addToSubscription($varienOrder->getBillingAddress('email'));
343
+ }
344
+ } catch(Exception $e) {
345
+ $this->logKlarnaException($e);
346
+ }
347
+
348
+ $this->_getHelper()->dispatchMethodEvent($order, Vaimo_Klarna_Helper_Data::KLARNA_DISPATCH_RESERVED, $order->getTotalDue(), $this->getMethod());
349
+
350
+ $this->logDebugInfo('createOrder successfully created order with no: ' . $order->getIncrementId());
351
+
352
+ $this->_api->updateKlarnaOrder($order);
353
+
354
+ return $order;
355
+ }
356
+
357
+ public function getKlarnaCheckoutEnabled()
358
+ {
359
+ $remoteAddr = $this->_getCoreHttpHelper()->getRemoteAddr();
360
+ $message = $remoteAddr . ' ' . $this->_getCoreUrlHelper()->getCurrentUrl();
361
+
362
+ if (!$this->getConfigData('active')) {
363
+ return false;
364
+ }
365
+
366
+ if ($this->_getCustomerHelper()->isLoggedIn() && !$this->getConfigData('allow_when_logged_in')) {
367
+ return false;
368
+ }
369
+ $allowedCustomerGroups = $this->getConfigData('allow_customer_group');
370
+ if (isset($allowedCustomerGroups)) {
371
+ $allowedCustomerGroups = explode(',', $allowedCustomerGroups);
372
+
373
+ if (!in_array(Vaimo_Klarna_Helper_Data::KLARNA_CHECKOUT_ALLOW_ALL_GROUP_ID, $allowedCustomerGroups)) {
374
+ $customerGroupId = $this->_getCustomerSession()->getCustomerGroupId();
375
+ if(!in_array($customerGroupId, $allowedCustomerGroups)) {
376
+ return false;
377
+ }
378
+ }
379
+ }
380
+ if ($allowedIpRange = $this->getConfigData('allowed_ip_range')) {
381
+ $ipParts = explode('.', $remoteAddr);
382
+
383
+ if (is_array($ipParts) && count($ipParts) >= 4) {
384
+ $lastDigit = intval($ipParts[3]);
385
+ } else {
386
+ $lastDigit = 0;
387
+ }
388
+
389
+ list ($allowIpFrom, $allowIpTo) = explode('-', $allowedIpRange, 2);
390
+
391
+ if ($lastDigit >= (int)$allowIpFrom && $lastDigit <= (int)$allowIpTo) {
392
+ return true;
393
+ } else {
394
+ return false;
395
+ }
396
+ }
397
+
398
+ return true;
399
+ }
400
+
401
+ public function checkNewsletter()
402
+ {
403
+ // set newsletter subscribe based on settings
404
+ if ($this->getQuote()->getKlarnaCheckoutNewsletter() == null) {
405
+ $type = (int)$this->getConfigData('enable_newsletter');
406
+ $checked = (bool)$this->getConfigData('newsletter_checked');
407
+
408
+ if (($type == Vaimo_Klarna_Helper_Data::KLARNA_CHECKOUT_NEWSLETTER_SUBSCRIBE && $checked)
409
+ || ($type == Vaimo_Klarna_Helper_Data::KLARNA_CHECKOUT_NEWSLETTER_DONT_SUBSCRIBE && !$checked)) {
410
+ $this->getQuote()->setKlarnaCheckoutNewsletter(1);
411
+ } else {
412
+ $this->getQuote()->setKlarnaCheckoutNewsletter(0);
413
+ }
414
+ $this->getQuote()->save();
415
+ }
416
+
417
+ return $this;
418
+ }
419
+
420
+ protected function _getTransport()
421
+ {
422
+ return $this;
423
+ }
424
+
425
+ }
app/code/community/Vaimo/Klarna/Model/Klarnacheckout/Abstract.php ADDED
@@ -0,0 +1,192 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Copyright (c) 2009-2014 Vaimo AB
4
+ *
5
+ * Vaimo reserves all rights in the Program as delivered. The Program
6
+ * or any portion thereof may not be reproduced in any form whatsoever without
7
+ * the written consent of Vaimo, except as provided by licence. A licence
8
+ * under Vaimo's rights in the Program may be available directly from
9
+ * Vaimo.
10
+ *
11
+ * Disclaimer:
12
+ * THIS NOTICE MAY NOT BE REMOVED FROM THE PROGRAM BY ANY USER THEREOF.
13
+ * THE PROGRAM IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
14
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
16
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ * OUT OF OR IN CONNECTION WITH THE PROGRAM OR THE USE OR OTHER DEALINGS
19
+ * IN THE PROGRAM.
20
+ *
21
+ * @category Vaimo
22
+ * @package Vaimo_Klarna
23
+ * @copyright Copyright (c) 2009-2014 Vaimo AB
24
+ */
25
+
26
+ abstract class Vaimo_Klarna_Model_Klarnacheckout_Abstract extends Vaimo_Klarna_Model_Transport_Abstract
27
+ {
28
+ protected $_coreHttpHelper = NULL;
29
+ protected $_coreUrlHelper = NULL;
30
+ protected $_customerHelper = NULL;
31
+
32
+ public function __construct($setStoreInfo = true, $moduleHelper = NULL, $coreHttpHelper = NULL, $coreUrlHelper = NULL, $customerHelper = NULL)
33
+ {
34
+ parent::__construct($setStoreInfo, $moduleHelper);
35
+
36
+ $this->_coreHttpHelper = $coreHttpHelper;
37
+ if ($this->_coreHttpHelper==NULL) {
38
+ $this->_coreHttpHelper = Mage::helper('core/http');
39
+ }
40
+ $this->_coreUrlHelper = $coreUrlHelper;
41
+ if ($this->_coreUrlHelper==NULL) {
42
+ $this->_coreUrlHelper = Mage::helper('core/url');
43
+ }
44
+ $this->_customerHelper = $customerHelper;
45
+ if ($this->_customerHelper==NULL) {
46
+ $this->_customerHelper = Mage::helper('customer');
47
+ }
48
+ }
49
+
50
+ protected function _getCoreHttpHelper()
51
+ {
52
+ return $this->_coreHttpHelper;
53
+ }
54
+
55
+ protected function _getCoreUrlHelper()
56
+ {
57
+ return $this->_coreUrlHelper;
58
+ }
59
+
60
+ protected function _getCustomerHelper()
61
+ {
62
+ return $this->_customerHelper;
63
+ }
64
+
65
+ protected function _loadQuoteByKey($id, $key)
66
+ {
67
+ return Mage::getModel('sales/quote')->load($id, $key);
68
+ }
69
+
70
+ protected function _loadOrderByKey($id, $key = 'quote_id')
71
+ {
72
+ return Mage::getModel('sales/order')->load($id, $key);
73
+ }
74
+
75
+ protected function _findAlreadyCreatedOrder($id)
76
+ {
77
+ return $this->_loadOrderByKey($id)->getId();
78
+ }
79
+
80
+ protected function _loadCustomer($id)
81
+ {
82
+ return Mage::getModel('customer/customer')->load($id);
83
+ }
84
+
85
+ protected function _getCustomerSession()
86
+ {
87
+ return Mage::getSingleton('customer/session');
88
+ }
89
+
90
+ protected function _loadCustomerByEmail($email, $store)
91
+ {
92
+ return Mage::getModel('customer/customer')->setStore($store)->loadByEmail($email);
93
+ }
94
+
95
+ protected function _loadCustomerAddress($id)
96
+ {
97
+ return Mage::getModel('customer/address')->load($id);
98
+ }
99
+
100
+ protected function _getServiceQuote($quote)
101
+ {
102
+ return Mage::getModel('sales/service_quote', $quote);
103
+ }
104
+
105
+ protected function _addToSubscription($email)
106
+ {
107
+ Mage::getModel('newsletter/subscriber')->subscribe(email);
108
+ }
109
+
110
+ protected function _prepareNewCustomerQuote(Mage_Sales_Model_Quote $quote)
111
+ {
112
+ $billing = $quote->getBillingAddress();
113
+ $shipping = $quote->isVirtual() ? null : $quote->getShippingAddress();
114
+
115
+ /** @var $customer Mage_Customer_Model_Customer */
116
+ $customer = $quote->getCustomer();
117
+ $customerBilling = $billing->exportCustomerAddress();
118
+ $customer->addAddress($customerBilling);
119
+ $billing->setCustomerAddress($customerBilling);
120
+ $customerBilling->setIsDefaultBilling(true);
121
+
122
+ if ($shipping && !$shipping->getSameAsBilling()) {
123
+ $customerShipping = $shipping->exportCustomerAddress();
124
+ $customer->addAddress($customerShipping);
125
+ $shipping->setCustomerAddress($customerShipping);
126
+ $customerShipping->setIsDefaultShipping(true);
127
+ } else {
128
+ $customerBilling->setIsDefaultShipping(true);
129
+ }
130
+
131
+ // Mage::helper('core')->copyFieldset('checkout_onepage_quote', 'to_customer', $quote, $customer);
132
+
133
+ $customer->setFirstname($customerBilling->getFirstname());
134
+ $customer->setLastname($customerBilling->getLastname());
135
+ $customer->setEmail($customerBilling->getEmail());
136
+
137
+ $password = $customer->generatePassword();
138
+ $customer->setPassword($password);
139
+ $customer->setConfirmation($password);
140
+
141
+ // $customer->setPassword($customer->decryptPassword($quote->getPasswordHash()));
142
+ // $customer->setPasswordHash($customer->hashPassword($customer->getPassword()));
143
+ $quote->setCustomer($customer)->setCustomerId(true);
144
+ }
145
+
146
+ protected function _prepareCustomerQuote(Mage_Sales_Model_Quote $quote)
147
+ {
148
+ $billing = $quote->getBillingAddress();
149
+ $shipping = $quote->isVirtual() ? null : $quote->getShippingAddress();
150
+ $customer = $this->_loadCustomer($quote->getCustomerId());
151
+
152
+ if (!$billing->getCustomerId() || $billing->getSaveInAddressBook()) {
153
+ $customerBilling = $billing->exportCustomerAddress();
154
+ $customer->addAddress($customerBilling);
155
+ $billing->setCustomerAddress($customerBilling);
156
+ }
157
+
158
+ if ($shipping && !$shipping->getSameAsBilling() &&
159
+ (!$shipping->getCustomerId() || $shipping->getSaveInAddressBook())) {
160
+ $customerShipping = $shipping->exportCustomerAddress();
161
+ $customer->addAddress($customerShipping);
162
+ $shipping->setCustomerAddress($customerShipping);
163
+ }
164
+
165
+ if (isset($customerBilling) && !$customer->getDefaultBilling()) {
166
+ $customerBilling->setIsDefaultBilling(true);
167
+ }
168
+
169
+ if ($shipping && isset($customerShipping) && !$customer->getDefaultShipping()) {
170
+ $customerShipping->setIsDefaultShipping(true);
171
+ } else if (isset($customerBilling) && !$customer->getDefaultShipping()) {
172
+ $customerBilling->setIsDefaultShipping(true);
173
+ }
174
+
175
+ $quote->setCustomer($customer);
176
+ }
177
+
178
+ protected function _involveNewCustomer(Mage_Sales_Model_Quote $quote)
179
+ {
180
+ /** @var $customer Mage_Customer_Model_Customer */
181
+ $customer = $quote->getCustomer();
182
+
183
+ if ($customer->isConfirmationRequired()) {
184
+ $customer->sendNewAccountEmail('confirmation', '', $quote->getStoreId());
185
+ } else {
186
+ $customer->sendNewAccountEmail('registered', '', $quote->getStoreId());
187
+ }
188
+
189
+ return $this;
190
+ }
191
+
192
+ }
app/code/community/Vaimo/Klarna/Model/Observer.php CHANGED
@@ -36,17 +36,17 @@ class Vaimo_Klarna_Model_Observer extends Mage_Core_Model_Abstract
36
  */
37
  public function prePaymentCapture($observer)
38
  {
39
- $klarnaCapture = Mage::getModel('klarna/klarna_capture');
40
  $payment = $observer->getEvent()->getPayment();
41
- $klarnaCapture->setPayment($payment);
 
42
 
43
- if (!$klarnaCapture->supportedMethod()) {
44
  return $this;
45
  }
46
 
47
  $invoice = $observer->getEvent()->getInvoice();
48
- $klarnaCapture->setInvoice($invoice);
49
- $itemList = $klarnaCapture->createItemList();
50
  $payment->setKlarnaItemList($itemList);
51
  }
52
 
@@ -62,9 +62,9 @@ class Vaimo_Klarna_Model_Observer extends Mage_Core_Model_Abstract
62
  $payment = $observer->getEvent()->getPayment();
63
  if ($payment) {
64
  $data = $observer->getEvent()->getInput();
65
- $klarnaAssign = Mage::getModel('klarna/klarna_assign');
66
- $klarnaAssign->setQuote($payment->getQuote());
67
- $klarnaAssign->clearInactiveKlarnaMethodsPostvalues($data,$data->getMethod());
68
  }
69
  }
70
 
@@ -90,4 +90,52 @@ class Vaimo_Klarna_Model_Observer extends Mage_Core_Model_Abstract
90
  }
91
  }
92
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
93
  }
36
  */
37
  public function prePaymentCapture($observer)
38
  {
 
39
  $payment = $observer->getEvent()->getPayment();
40
+ $klarna = Mage::getModel('klarna/klarna');
41
+ $klarna->setPayment($payment);
42
 
43
+ if (!Mage::helper('klarna')->isMethodKlarna($payment->getMethod())) {
44
  return $this;
45
  }
46
 
47
  $invoice = $observer->getEvent()->getInvoice();
48
+ $klarna->setInvoice($invoice);
49
+ $itemList = $klarna->createItemListCapture();
50
  $payment->setKlarnaItemList($itemList);
51
  }
52
 
62
  $payment = $observer->getEvent()->getPayment();
63
  if ($payment) {
64
  $data = $observer->getEvent()->getInput();
65
+ $klarna = Mage::getModel('klarna/klarna');
66
+ $klarna->setQuote($payment->getQuote());
67
+ $klarna->clearInactiveKlarnaMethodsPostvalues($data,$data->getMethod());
68
  }
69
  }
70
 
90
  }
91
  }
92
 
93
+
94
+ // KLARNA CHECKOUT FROM HERE
95
+
96
+ /**
97
+ * @return Mage_Checkout_Model_Session
98
+ */
99
+ protected function _getSession()
100
+ {
101
+ return Mage::getSingleton('checkout/session');
102
+ }
103
+
104
+ public function customerAddressFormat(Varien_Event_Observer $observer)
105
+ {
106
+ $type = $observer->getEvent()->getType();
107
+
108
+ if (strpos($type->getDefaultFormat(), 'care_of') === false) {
109
+ $defaultFormat = explode("\n", $type->getDefaultFormat());
110
+
111
+ if (is_array($defaultFormat)) {
112
+ $result = array();
113
+
114
+ foreach ($defaultFormat as $key => $value) {
115
+ $result[] = $value;
116
+ if ($key == 0) {
117
+ $result[] = '{{depend care_of}}c/o {{var care_of}}<br />{{/depend}}';
118
+ }
119
+ }
120
+
121
+ $type->setDefaultFormat(implode("\n", $result));
122
+ }
123
+ }
124
+ }
125
+
126
+ public function checkLaunchKlarnaCheckout($observer)
127
+ {
128
+ if (!$this->_getSession()->getUseOtherMethods()) {
129
+ $quote = Mage::getSingleton('checkout/session')->getQuote();
130
+ $klarna = Mage::getModel('klarna/klarnacheckout');
131
+ $klarna->setQuote($quote, Vaimo_Klarna_Helper_Data::KLARNA_METHOD_CHECKOUT);
132
+ if ($klarna->getKlarnaCheckoutEnabled()) {
133
+ $controllerAction = $observer->getControllerAction();
134
+ $controllerAction->getResponse()
135
+ ->setRedirect(Mage::getUrl('checkout/klarna'))
136
+ ->sendResponse();
137
+ exit;
138
+ }
139
+ }
140
+ }
141
  }
app/code/community/Vaimo/Klarna/Model/Payment/Abstract.php CHANGED
@@ -34,11 +34,53 @@ class Vaimo_Klarna_Model_Payment_Abstract extends Mage_Payment_Model_Method_Abst
34
  protected $_canUseForMultishipping = false;
35
  protected $_canSaveCc = false;
36
  protected $_canFetchTransactionInfo = true;
 
37
 
38
- public function getConfigData($field, $storeId = NULL)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
39
  {
40
  if (!$storeId) $storeId = Mage::app()->getStore()->getId();
41
- return parent::getConfigData($field, $storeId);
 
 
 
 
 
 
 
42
  }
43
 
44
  public function canCapture()
@@ -65,7 +107,13 @@ class Vaimo_Klarna_Model_Payment_Abstract extends Mage_Payment_Model_Method_Abst
65
  {
66
  return $this->canCapture();
67
  }
68
-
 
 
 
 
 
 
69
  /*
70
  *
71
  * This returns blank because Klarna doesn't want the title in text
@@ -76,32 +124,40 @@ class Vaimo_Klarna_Model_Payment_Abstract extends Mage_Payment_Model_Method_Abst
76
  */
77
  public function getTitle()
78
  {
79
- if (Mage::helper('klarna')->showTitleAsTextOnly()) {
80
- $klarnaAvailable = Mage::getModel('klarna/klarna_available');
81
- $klarnaAvailable->setQuote($this->getQuote(), $this->_code);
82
- return $klarnaAvailable->getMethodTitle();
83
  } else {
84
  return '';
85
  }
86
  }
87
 
88
- public function getCheckout()
89
  {
90
- return Mage::getSingleton('checkout/session');
 
 
91
  }
92
 
93
- public function getQuote()
94
  {
95
- return $this->getCheckout()->getQuote();
96
  }
97
 
 
 
 
 
 
98
  public function isAvailable( $quote = null )
99
  {
100
- $available = parent::isAvailable($quote);
101
  if(!$available) return false;
102
 
 
103
  try {
104
- $active = $this->getConfigData('active');
105
 
106
  if(!$active) return false;
107
  if(is_null($quote)) return false;
@@ -109,9 +165,9 @@ class Vaimo_Klarna_Model_Payment_Abstract extends Mage_Payment_Model_Method_Abst
109
  $grandTotal = $quote->getGrandTotal();
110
  if(empty ($grandTotal) || $grandTotal <= 0) return false;
111
 
112
- $klarnaAvailable = Mage::getModel('klarna/klarna_available');
113
- $klarnaAvailable->setQuote($quote, $this->_code);
114
- if ($klarnaAvailable->isBelowAllowedHardcodedLimit($grandTotal) == false ) {
115
  return false;
116
  }
117
 
@@ -122,17 +178,17 @@ class Vaimo_Klarna_Model_Payment_Abstract extends Mage_Payment_Model_Method_Abst
122
  return false;
123
  }
124
  }
125
- if ($klarnaAvailable->isCountryAllowed()==false) {
126
  return false;
127
  }
128
  $billingAddress = $quote->getBillingAddress();
129
  if ($billingAddress->getCompany() != null) {
130
- if ($klarnaAvailable->showMethodForCompanyPurchases()==false) {
131
  return false;
132
  }
133
  }
134
  } catch (Mage_Core_Exception $e) {
135
- if ($klarnaAvailable) $klarnaAvailable->logKlarnaException($e);
136
  return false;
137
  }
138
  return true;
@@ -142,44 +198,45 @@ class Vaimo_Klarna_Model_Payment_Abstract extends Mage_Payment_Model_Method_Abst
142
  public function assignData( $data )
143
  {
144
  try {
145
- $klarnaAssign = Mage::getModel('klarna/klarna_assign');
146
  if (!($data instanceof Varien_Object)) {
147
  $data = new Varien_Object($data);
148
  }
149
  $info = $this->getInfoInstance();
 
150
  $quote = $info->getQuote();
151
- $klarnaAssign->setQuote($quote, $data->getMethod());
152
- $klarnaAssign->clearInactiveKlarnaMethodsPostvalues($data, $data->getMethod());
153
- $klarnaAssign->addPostvalues($data->getData(), $data->getMethod());
154
- $email = $klarnaAssign->getEmailValue(Mage::getSingleton('customer/session')->getCustomer()->getEmail());
155
- $klarnaAssign->addPostvalues(array('email' => $email)); // will replace email from checkout...
156
- $klarnaAssign->updateAddress();
157
- $klarnaAssign->setPaymentPlan();
158
- $klarnaAssign->setPaymentFee($quote);
159
- if ($klarnaAssign->getPostValues('consent')===NULL) {
160
- $klarnaAssign->addPostvalues(array('consent' => 'NO')); // If this is not set in post, set it to NO to mark as no consent was given.
 
161
  }
162
- if ($klarnaAssign->getPostValues('gender')===NULL) {
163
- $klarnaAssign->addPostvalues(array('gender' => '-1')); // If this is not set in post, set it to -1.
164
  }
165
 
166
- $klarnaAddr = $klarnaAssign->toKlarna($klarnaAssign->getShippingAddress());
167
 
168
  // These ifs were in a sense copied from old klarna module
169
  // Don't send in reference for non-company purchase.
170
  if (!$klarnaAddr->isCompany) {
171
- if ($klarnaAssign->getPostValues('reference')!==NULL) {
172
- $klarnaAssign->unsPostvalue('reference');
173
  }
174
  } else {
175
  // This insane ifcase is for OneStepCheckout
176
- if ($klarnaAssign->getPostValues('reference')===NULL) {
177
  $reference = $klarnaAddr->getFirstName() . " " . $klarnaAddr->getLastName();
178
- $klarnaAssign->addPostvalues(array('reference' => $reference));
179
  }
180
  }
181
 
182
- $klarnaAssign->updateAdditionalInformation( $info );
183
 
184
  } catch (Mage_Core_Exception $e) {
185
  Mage::throwException($e->getMessage());
@@ -187,31 +244,36 @@ class Vaimo_Klarna_Model_Payment_Abstract extends Mage_Payment_Model_Method_Abst
187
  return $this;
188
  }
189
 
 
 
 
 
 
190
  public function validate()
191
  {
192
- parent::validate();
193
  try {
194
- $klarnaValidate = Mage::getModel('klarna/klarna_validate');
195
  $info = $this->getInfoInstance();
196
  if ($info->getQuote()) {
197
  // Validate is called while in checkout and immediately after place order is pushed
198
  $quote = $info->getQuote();
199
- $klarnaValidate->setInfoInstance($this->getInfoInstance());
200
- $klarnaValidate->setQuote($quote, $info->getMethod());
201
  } else {
202
  // Magento also calls validate when the quote has been changed into an order, then the quote doesn't exist and we do our tests against the order
203
  $order = $info->getOrder();
204
- $klarnaValidate->setInfoInstance($this->getInfoInstance());
205
- $klarnaValidate->setOrder($order);
206
  }
207
 
208
  // We cannot perform basic tests with OneStepCheckout because they try
209
  // to save the payment method as soon as the customer views the checkout
210
- if (Mage::helper('klarna')->isOneStepCheckout()) {
211
  return $this;
212
  }
213
 
214
- $klarnaValidate->doBasicTests();
215
 
216
  } catch (Mage_Core_Exception $e) {
217
  Mage::throwException($e->getMessage());
@@ -225,7 +287,7 @@ class Vaimo_Klarna_Model_Payment_Abstract extends Mage_Payment_Model_Method_Abst
225
  * @param Varien_Object $payment Magento payment model
226
  * @param double $amount The amount to authorize with
227
  *
228
- * @return Klarna_KlarnaPaymentModule_Model_Klarna_Shared
229
  */
230
  public function authorize(Varien_Object $payment, $amount)
231
  {
@@ -234,88 +296,103 @@ class Vaimo_Klarna_Model_Payment_Abstract extends Mage_Payment_Model_Method_Abst
234
  * Since we could not perform basic tests with OneStepCheckout at validate and assign functions
235
  * we do them here instead
236
  */
237
- if (Mage::helper('klarna')->isOneStepCheckout()) {
238
- $klarnaValidate = Mage::getModel('klarna/klarna_validate');
239
- $klarnaValidate->setInfoInstance($this->getInfoInstance());
240
- $klarnaValidate->setPayment($payment);
241
- $klarnaValidate->doBasicTests();
242
  }
243
 
244
- $klarnaAuthorize = Mage::getModel('klarna/klarna_authorize');
245
- $klarnaAuthorize->setPayment($payment);
246
- $klarnaAuthorize->updateAddress();
247
 
248
- if (Mage::helper('klarna')->isOneStepCheckout() && $klarnaAuthorize->shippingSameAsBilling()) {
249
- $klarnaAuthorize->updateBillingAddress();
250
  }
251
 
252
- $itemList = $klarnaAuthorize->createItemList();
253
  $payment->setKlarnaItemList($itemList);
254
 
255
- $result = $klarnaAuthorize->reserve($amount);
256
  $transactionStatus = $result[Vaimo_Klarna_Helper_Data::KLARNA_API_RESPONSE_STATUS];
257
  $transactionId = $result[Vaimo_Klarna_Helper_Data::KLARNA_API_RESPONSE_TRANSACTION_ID];
258
- } catch (Mage_Core_Exception $e) {
259
- Mage::throwException($e->getMessage());
260
- }
261
-
262
- $payment->setAdditionalInformation(Vaimo_Klarna_Helper_Data::KLARNA_INFO_FIELD_RESERVATION_ID, $transactionId );
263
- $payment->setAdditionalInformation(Vaimo_Klarna_Helper_Data::KLARNA_INFO_FIELD_RESERVATION_STATUS, $transactionStatus );
264
- $payment->setAdditionalInformation(Vaimo_Klarna_Helper_Data::KLARNA_INFO_FIELD_HOST, $this->getConfigData("host") );
265
- $payment->setAdditionalInformation(Vaimo_Klarna_Helper_Data::KLARNA_INFO_FIELD_MERCHANT_ID, $this->getConfigData("merchant_id") );
266
 
267
- if ($transactionStatus==Vaimo_Klarna_Helper_Data::KLARNA_STATUS_PENDING) {
268
- $payment->setIsTransactionPending(true);
269
- }
 
 
 
 
 
 
 
 
 
 
 
270
 
271
- $payment->setTransactionId($transactionId)
272
  ->setIsTransactionClosed(0);
 
 
 
273
  return $this;
274
  }
275
 
276
  public function capture(Varien_Object $payment, $amount)
277
  {
278
  try {
279
- $klarnaCapture = Mage::getModel('klarna/klarna_capture');
280
- $klarnaCapture->setPayment($payment);
281
- $result = $klarnaCapture->capture($amount);
282
  $transactionStatus = $result[Vaimo_Klarna_Helper_Data::KLARNA_API_RESPONSE_STATUS];
283
  $transactionId = $result[Vaimo_Klarna_Helper_Data::KLARNA_API_RESPONSE_TRANSACTION_ID];
284
  $feeAmountCaptured = $result[Vaimo_Klarna_Helper_Data::KLARNA_API_RESPONSE_FEE_CAPTURED];
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
285
  } catch (Mage_Core_Exception $e) {
286
  Mage::throwException($e->getMessage());
287
  }
288
- $invoices = $payment->getAdditionalInformation(Vaimo_Klarna_Helper_Data::KLARNA_INFO_FIELD_INVOICE_LIST);
289
- if (!is_array($invoices)) {
290
- $invoices = array();
291
- }
292
- $invoices[] = array(
293
- Vaimo_Klarna_Helper_Data::KLARNA_INFO_FIELD_INVOICE_LIST_STATUS => $transactionStatus,
294
- Vaimo_Klarna_Helper_Data::KLARNA_INFO_FIELD_INVOICE_LIST_ID => $transactionId
295
- );
296
- $payment->setAdditionalInformation(Vaimo_Klarna_Helper_Data::KLARNA_INFO_FIELD_INVOICE_LIST, $invoices);
297
-
298
- if ($feeAmountCaptured) {
299
- $payment->setAdditionalInformation(Vaimo_Klarna_Helper_Data::KLARNA_INFO_FIELD_FEE_CAPTURED_TRANSACTION_ID, $transactionId);
300
- $payment->setAdditionalInformation(Vaimo_Klarna_Helper_Data::KLARNA_INFO_FIELD_FEE_REFUNDED, 0);
301
- }
302
-
303
- $payment->setTransactionId($transactionId)
304
- ->setIsTransactionClosed(0);
305
  return $this;
306
  }
307
 
308
  public function refund(Varien_Object $payment, $amount)
309
  {
310
  try {
311
- $klarnaRefund = Mage::getModel('klarna/klarna_refund');
312
- $klarnaRefund->setPayment($payment);
313
-
314
- $itemList = $klarnaRefund->createItemList();
315
  $payment->setKlarnaItemList($itemList);
316
-
317
- $klarnaRefund->setInfoInstance($this->getInfoInstance());
318
- $result = $klarnaRefund->refund($amount);
319
  $transactionStatus = $result[Vaimo_Klarna_Helper_Data::KLARNA_API_RESPONSE_STATUS]; // Always OK...
320
  $transactionId = $result[Vaimo_Klarna_Helper_Data::KLARNA_API_RESPONSE_TRANSACTION_ID];
321
  $klarnaFeeRefunded = $result[Vaimo_Klarna_Helper_Data::KLARNA_API_RESPONSE_FEE_REFUNDED];
@@ -327,31 +404,32 @@ class Vaimo_Klarna_Model_Payment_Abstract extends Mage_Payment_Model_Method_Abst
327
  }
328
  $id = date('His');
329
  if (!$id) $id = 1;
 
 
 
330
  } catch (Mage_Core_Exception $e) {
331
  Mage::throwException($e->getMessage());
332
  }
333
-
334
- $payment->setTransactionId($transactionId . '-' . $id . '-refund')
335
- ->setIsTransactionClosed(1);
336
  return $this;
337
  }
338
 
339
  public function cancel(Varien_Object $payment)
340
  {
341
  try {
342
- $klarnaCancel = Mage::getModel('klarna/klarna_cancel');
343
- $klarnaCancel->setPayment($payment);
344
- $result = $klarnaCancel->cancel();
345
  $transactionStatus = $result[Vaimo_Klarna_Helper_Data::KLARNA_API_RESPONSE_STATUS];
 
 
 
 
 
 
 
346
  } catch (Mage_Core_Exception $e) {
347
  Mage::throwException($e->getMessage());
348
  }
349
- if (!$transactionStatus) {
350
- Mage::throwException(Mage::helper('klarna')->__('Klarna was not able to cancel the reservation'));
351
- }
352
- $payment->setAdditionalInformation(Vaimo_Klarna_Helper_Data::KLARNA_INFO_FIELD_CANCELED_DATE, date("Y-m-d") );
353
-
354
- $payment->setIsTransactionClosed(1);
355
  return $this;
356
  }
357
 
@@ -360,6 +438,10 @@ class Vaimo_Klarna_Model_Payment_Abstract extends Mage_Payment_Model_Method_Abst
360
  return $this->cancel($payment);
361
  }
362
 
 
 
 
 
363
  /**
364
  * Fetch transaction details info
365
  *
@@ -371,10 +453,10 @@ class Vaimo_Klarna_Model_Payment_Abstract extends Mage_Payment_Model_Method_Abst
371
  */
372
  public function fetchTransactionInfo(Mage_Payment_Model_Info $payment, $transactionId)
373
  {
374
- $klarnaAuthorize = Mage::getModel('klarna/klarna_authorize');
375
- $klarnaAuthorize->setPayment($payment);
376
  $status = $payment->getAdditionalInformation(Vaimo_Klarna_Helper_Data::KLARNA_INFO_FIELD_RESERVATION_STATUS);
377
- $result = $klarnaAuthorize->checkStatus();
378
  $transactionStatus = $result[Vaimo_Klarna_Helper_Data::KLARNA_API_RESPONSE_STATUS];
379
  if ($transactionStatus!=$status) {
380
  $payment->setAdditionalInformation(Vaimo_Klarna_Helper_Data::KLARNA_INFO_FIELD_RESERVATION_STATUS, $transactionStatus );
@@ -384,6 +466,6 @@ class Vaimo_Klarna_Model_Payment_Abstract extends Mage_Payment_Model_Method_Abst
384
  } elseif ($transactionStatus==Vaimo_Klarna_Helper_Data::KLARNA_STATUS_DENIED) {
385
  $payment->setIsTransactionDenied(true);
386
  }
387
- return parent::fetchTransactionInfo($payment, $transactionId);
388
  }
389
  }
34
  protected $_canUseForMultishipping = false;
35
  protected $_canSaveCc = false;
36
  protected $_canFetchTransactionInfo = true;
37
+ protected $_canManageRecurringProfiles = false;
38
 
39
+ protected $_moduleHelper = NULL;
40
+
41
+ public function __construct($moduleHelper = NULL)
42
+ {
43
+ parent::__construct();
44
+
45
+ $this->_moduleHelper = $moduleHelper;
46
+ if ($this->_moduleHelper==NULL) {
47
+ $this->_moduleHelper = Mage::helper('klarna');
48
+ }
49
+ }
50
+
51
+ /**
52
+ * @return false|Vaimo_Klarna_Model_Klarna
53
+ */
54
+ protected function _getKlarnaModel()
55
+ {
56
+ return Mage::getModel('klarna/klarna');
57
+ }
58
+
59
+ /**
60
+ * @return Vaimo_Klarna_Helper_Data|null
61
+ */
62
+ protected function _getHelper()
63
+ {
64
+ return $this->_moduleHelper;
65
+ }
66
+
67
+ /**
68
+ * @param $field
69
+ * @param null $storeId
70
+ *
71
+ * @return mixed
72
+ */
73
+ protected function _getConfigData($field, $storeId = NULL)
74
  {
75
  if (!$storeId) $storeId = Mage::app()->getStore()->getId();
76
+ return $this->getConfigData($field, $storeId);
77
+ }
78
+
79
+ protected function _getCustomerFromSession()
80
+ {
81
+ /** @var Mage_Customer_Model_Session $customerSession */
82
+ $customerSession = Mage::getSingleton('customer/session');
83
+ return $customerSession->getCustomer();
84
  }
85
 
86
  public function canCapture()
107
  {
108
  return $this->canCapture();
109
  }
110
+
111
+ // Expects Magentos current store to be accurate...
112
+ protected function _roundPrice($price)
113
+ {
114
+ return Mage::app()->getStore()->roundPrice($price);
115
+ }
116
+
117
  /*
118
  *
119
  * This returns blank because Klarna doesn't want the title in text
124
  */
125
  public function getTitle()
126
  {
127
+ if ($this->_getHelper()->showTitleAsTextOnly()) {
128
+ $klarna = $this->_getKlarnaModel();
129
+ $klarna->setQuote($this->getQuote(), $this->_code);
130
+ return $klarna->getMethodTitleWithFee($this->_getHelper()->getVaimoKlarnaFeeInclVat($this->getQuote(), false));
131
  } else {
132
  return '';
133
  }
134
  }
135
 
136
+ public function getQuote()
137
  {
138
+ /** @var Mage_Checkout_Model_Session $checkoutSession */
139
+ $checkoutSession = Mage::getSingleton('checkout/session');
140
+ return $checkoutSession->getQuote();
141
  }
142
 
143
+ protected function _isAvailableParent( $quote = NULL)
144
  {
145
+ return parent::isAvailable($quote);
146
  }
147
 
148
+ /**
149
+ * @param Mage_Sales_Model_Quote|null $quote
150
+ *
151
+ * @return bool
152
+ */
153
  public function isAvailable( $quote = null )
154
  {
155
+ $available = $this->_isAvailableParent($quote);
156
  if(!$available) return false;
157
 
158
+ $klarna = null;
159
  try {
160
+ $active = $this->_getConfigData('active'); // Only call to this
161
 
162
  if(!$active) return false;
163
  if(is_null($quote)) return false;
165
  $grandTotal = $quote->getGrandTotal();
166
  if(empty ($grandTotal) || $grandTotal <= 0) return false;
167
 
168
+ $klarna = $this->_getKlarnaModel();
169
+ $klarna->setQuote($quote, $this->_code);
170
+ if ($klarna->isBelowAllowedHardcodedLimit($grandTotal) == false ) {
171
  return false;
172
  }
173
 
178
  return false;
179
  }
180
  }
181
+ if ($klarna->isCountryAllowed()==false) {
182
  return false;
183
  }
184
  $billingAddress = $quote->getBillingAddress();
185
  if ($billingAddress->getCompany() != null) {
186
+ if ($klarna->showMethodForCompanyPurchases()==false) {
187
  return false;
188
  }
189
  }
190
  } catch (Mage_Core_Exception $e) {
191
+ if ($klarna) $klarna->logKlarnaException($e);
192
  return false;
193
  }
194
  return true;
198
  public function assignData( $data )
199
  {
200
  try {
 
201
  if (!($data instanceof Varien_Object)) {
202
  $data = new Varien_Object($data);
203
  }
204
  $info = $this->getInfoInstance();
205
+ /** @var Mage_Sales_Model_Quote $quote */
206
  $quote = $info->getQuote();
207
+ $klarna = $this->_getKlarnaModel();
208
+ $klarna->setQuote($quote, $data->getMethod());
209
+ $klarna->clearInactiveKlarnaMethodsPostvalues($data, $data->getMethod());
210
+ $klarna->addPostValues($data->getData(), $data->getMethod());
211
+ $email = $klarna->getEmailValue($this->_getCustomerFromSession()->getEmail());
212
+ $klarna->addPostValues(array('email' => $email)); // will replace email from checkout...
213
+ $klarna->updateAssignAddress();
214
+ $klarna->setPaymentPlan();
215
+ $klarna->setPaymentFee($quote);
216
+ if ($klarna->getPostValues('consent')===NULL) {
217
+ $klarna->addPostValues(array('consent' => 'NO')); // If this is not set in post, set it to NO to mark as no consent was given.
218
  }
219
+ if ($klarna->getPostValues('gender')===NULL) {
220
+ $klarna->addPostValues(array('gender' => '-1')); // If this is not set in post, set it to -1.
221
  }
222
 
223
+ $klarnaAddr = $klarna->toKlarnaAddress($klarna->getShippingAddress());
224
 
225
  // These ifs were in a sense copied from old klarna module
226
  // Don't send in reference for non-company purchase.
227
  if (!$klarnaAddr->isCompany) {
228
+ if ($klarna->getPostValues('reference')!==NULL) {
229
+ $klarna->unsPostvalue('reference');
230
  }
231
  } else {
232
  // This insane ifcase is for OneStepCheckout
233
+ if ($klarna->getPostValues('reference')===NULL) {
234
  $reference = $klarnaAddr->getFirstName() . " " . $klarnaAddr->getLastName();
235
+ $klarna->addPostValues(array('reference' => $reference));
236
  }
237
  }
238
 
239
+ $klarna->updateAdditionalInformation( $info );
240
 
241
  } catch (Mage_Core_Exception $e) {
242
  Mage::throwException($e->getMessage());
244
  return $this;
245
  }
246
 
247
+ protected function _validateParent()
248
+ {
249
+ return parent::validate();
250
+ }
251
+
252
  public function validate()
253
  {
254
+ $this->_validateParent();
255
  try {
256
+ $klarna = $this->_getKlarnaModel();
257
  $info = $this->getInfoInstance();
258
  if ($info->getQuote()) {
259
  // Validate is called while in checkout and immediately after place order is pushed
260
  $quote = $info->getQuote();
261
+ $klarna->setInfoInstance($this->getInfoInstance());
262
+ $klarna->setQuote($quote, $info->getMethod());
263
  } else {
264
  // Magento also calls validate when the quote has been changed into an order, then the quote doesn't exist and we do our tests against the order
265
  $order = $info->getOrder();
266
+ $klarna->setInfoInstance($this->getInfoInstance());
267
+ $klarna->setOrder($order);
268
  }
269
 
270
  // We cannot perform basic tests with OneStepCheckout because they try
271
  // to save the payment method as soon as the customer views the checkout
272
+ if ($this->_getHelper()->isOneStepCheckout()) {
273
  return $this;
274
  }
275
 
276
+ $klarna->doBasicTests();
277
 
278
  } catch (Mage_Core_Exception $e) {
279
  Mage::throwException($e->getMessage());
287
  * @param Varien_Object $payment Magento payment model
288
  * @param double $amount The amount to authorize with
289
  *
290
+ * @return Vaimo_Klarna_Model_Klarna_Abstract
291
  */
292
  public function authorize(Varien_Object $payment, $amount)
293
  {
296
  * Since we could not perform basic tests with OneStepCheckout at validate and assign functions
297
  * we do them here instead
298
  */
299
+ $klarna = $this->_getKlarnaModel();
300
+ if ($this->_getHelper()->isOneStepCheckout()) {
301
+ $klarna->setInfoInstance($this->getInfoInstance());
302
+ $klarna->setPayment($payment);
303
+ $klarna->doBasicTests();
304
  }
305
 
306
+ $klarna = $this->_getKlarnaModel(); // Is a clean model really needed here?
307
+ $klarna->setPayment($payment);
308
+ $klarna->updateAuthorizeAddress();
309
 
310
+ if ($this->_getHelper()->isOneStepCheckout() && $klarna->shippingSameAsBilling()) {
311
+ $klarna->updateBillingAddress();
312
  }
313
 
314
+ $itemList = $klarna->createItemListAuthorize();
315
  $payment->setKlarnaItemList($itemList);
316
 
317
+ $result = $klarna->reserve($amount);
318
  $transactionStatus = $result[Vaimo_Klarna_Helper_Data::KLARNA_API_RESPONSE_STATUS];
319
  $transactionId = $result[Vaimo_Klarna_Helper_Data::KLARNA_API_RESPONSE_TRANSACTION_ID];
 
 
 
 
 
 
 
 
320
 
321
+ $payment->setAdditionalInformation(Vaimo_Klarna_Helper_Data::KLARNA_INFO_FIELD_RESERVATION_ID, $transactionId);
322
+ $payment->setAdditionalInformation(
323
+ Vaimo_Klarna_Helper_Data::KLARNA_INFO_FIELD_RESERVATION_STATUS, $transactionStatus
324
+ );
325
+ $payment->setAdditionalInformation(
326
+ Vaimo_Klarna_Helper_Data::KLARNA_INFO_FIELD_HOST, $klarna->getConfigData("host")
327
+ );
328
+ $payment->setAdditionalInformation(
329
+ Vaimo_Klarna_Helper_Data::KLARNA_INFO_FIELD_MERCHANT_ID, $klarna->getConfigData("merchant_id")
330
+ );
331
+
332
+ if ($transactionStatus==Vaimo_Klarna_Helper_Data::KLARNA_STATUS_PENDING) {
333
+ $payment->setIsTransactionPending(true);
334
+ }
335
 
336
+ $payment->setTransactionId($transactionId)
337
  ->setIsTransactionClosed(0);
338
+ } catch (Mage_Core_Exception $e) {
339
+ Mage::throwException($e->getMessage());
340
+ }
341
  return $this;
342
  }
343
 
344
  public function capture(Varien_Object $payment, $amount)
345
  {
346
  try {
347
+ $klarna = $this->_getKlarnaModel();
348
+ $klarna->setPayment($payment);
349
+ $result = $klarna->capture($amount);
350
  $transactionStatus = $result[Vaimo_Klarna_Helper_Data::KLARNA_API_RESPONSE_STATUS];
351
  $transactionId = $result[Vaimo_Klarna_Helper_Data::KLARNA_API_RESPONSE_TRANSACTION_ID];
352
  $feeAmountCaptured = $result[Vaimo_Klarna_Helper_Data::KLARNA_API_RESPONSE_FEE_CAPTURED];
353
+ if (isset($result[Vaimo_Klarna_Helper_Data::KLARNA_API_RESPONSE_KCO_CAPTURE_ID])) {
354
+ $kcoCaptureId = $result[Vaimo_Klarna_Helper_Data::KLARNA_API_RESPONSE_KCO_CAPTURE_ID];
355
+ } else {
356
+ $kcoCaptureId = NULL;
357
+ }
358
+
359
+ $invoice = array(
360
+ Vaimo_Klarna_Helper_Data::KLARNA_INFO_FIELD_INVOICE_LIST_STATUS => $transactionStatus,
361
+ Vaimo_Klarna_Helper_Data::KLARNA_INFO_FIELD_INVOICE_LIST_ID => $transactionId
362
+ );
363
+ if ($kcoCaptureId) {
364
+ $invoice[Vaimo_Klarna_Helper_Data::KLARNA_INFO_FIELD_INVOICE_LIST_KCO_ID] = $kcoCaptureId;
365
+ $transactionId = $transactionId . '/' . $kcoCaptureId;
366
+ }
367
+ $invoices = $payment->getAdditionalInformation(Vaimo_Klarna_Helper_Data::KLARNA_INFO_FIELD_INVOICE_LIST);
368
+ if (!is_array($invoices)) {
369
+ $invoices = array();
370
+ }
371
+ $invoices[] = $invoice;
372
+ $payment->setAdditionalInformation(Vaimo_Klarna_Helper_Data::KLARNA_INFO_FIELD_INVOICE_LIST, $invoices);
373
+
374
+ if ($feeAmountCaptured) {
375
+ $payment->setAdditionalInformation(Vaimo_Klarna_Helper_Data::KLARNA_INFO_FIELD_FEE_CAPTURED_TRANSACTION_ID, $transactionId);
376
+ $payment->setAdditionalInformation(Vaimo_Klarna_Helper_Data::KLARNA_INFO_FIELD_FEE_REFUNDED, 0);
377
+ }
378
+
379
+ $payment->setTransactionId($transactionId)
380
+ ->setIsTransactionClosed(0);
381
  } catch (Mage_Core_Exception $e) {
382
  Mage::throwException($e->getMessage());
383
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
384
  return $this;
385
  }
386
 
387
  public function refund(Varien_Object $payment, $amount)
388
  {
389
  try {
390
+ $klarna = $this->_getKlarnaModel();
391
+ $klarna->setPayment($payment);
392
+ $itemList = $klarna->createItemListRefund();
 
393
  $payment->setKlarnaItemList($itemList);
394
+ $klarna->setInfoInstance($this->getInfoInstance());
395
+ $result = $klarna->refund($amount);
 
396
  $transactionStatus = $result[Vaimo_Klarna_Helper_Data::KLARNA_API_RESPONSE_STATUS]; // Always OK...
397
  $transactionId = $result[Vaimo_Klarna_Helper_Data::KLARNA_API_RESPONSE_TRANSACTION_ID];
398
  $klarnaFeeRefunded = $result[Vaimo_Klarna_Helper_Data::KLARNA_API_RESPONSE_FEE_REFUNDED];
404
  }
405
  $id = date('His');
406
  if (!$id) $id = 1;
407
+
408
+ $payment->setTransactionId($transactionId . '-' . $id . '-refund')
409
+ ->setIsTransactionClosed(1);
410
  } catch (Mage_Core_Exception $e) {
411
  Mage::throwException($e->getMessage());
412
  }
 
 
 
413
  return $this;
414
  }
415
 
416
  public function cancel(Varien_Object $payment)
417
  {
418
  try {
419
+ $klarna = $this->_getKlarnaModel();
420
+ $klarna->setPayment($payment);
421
+ $result = $klarna->cancel();
422
  $transactionStatus = $result[Vaimo_Klarna_Helper_Data::KLARNA_API_RESPONSE_STATUS];
423
+
424
+ if (!$transactionStatus) {
425
+ Mage::throwException($this->_getHelper()->__('Klarna was not able to cancel the reservation'));
426
+ }
427
+ $payment->setAdditionalInformation(Vaimo_Klarna_Helper_Data::KLARNA_INFO_FIELD_CANCELED_DATE, date("Y-m-d") );
428
+
429
+ $payment->setIsTransactionClosed(1);
430
  } catch (Mage_Core_Exception $e) {
431
  Mage::throwException($e->getMessage());
432
  }
 
 
 
 
 
 
433
  return $this;
434
  }
435
 
438
  return $this->cancel($payment);
439
  }
440
 
441
+ protected function _fetchTransactionInfoParent(Mage_Payment_Model_Info $payment, $transactionId)
442
+ {
443
+ return parent::fetchTransactionInfo($payment, $transactionId);
444
+ }
445
  /**
446
  * Fetch transaction details info
447
  *
453
  */
454
  public function fetchTransactionInfo(Mage_Payment_Model_Info $payment, $transactionId)
455
  {
456
+ $klarna = $this->_getKlarnaModel();
457
+ $klarna->setPayment($payment);
458
  $status = $payment->getAdditionalInformation(Vaimo_Klarna_Helper_Data::KLARNA_INFO_FIELD_RESERVATION_STATUS);
459
+ $result = $klarna->checkStatus();
460
  $transactionStatus = $result[Vaimo_Klarna_Helper_Data::KLARNA_API_RESPONSE_STATUS];
461
  if ($transactionStatus!=$status) {
462
  $payment->setAdditionalInformation(Vaimo_Klarna_Helper_Data::KLARNA_INFO_FIELD_RESERVATION_STATUS, $transactionStatus );
466
  } elseif ($transactionStatus==Vaimo_Klarna_Helper_Data::KLARNA_STATUS_DENIED) {
467
  $payment->setIsTransactionDenied(true);
468
  }
469
+ return $this->_fetchTransactionInfoParent($payment, $transactionId);
470
  }
471
  }
app/code/community/Vaimo/Klarna/Model/Payment/Account.php CHANGED
@@ -33,18 +33,17 @@ class Vaimo_Klarna_Model_Payment_Account extends Vaimo_Klarna_Model_Payment_Abst
33
  {
34
  if (parent::isAvailable($quote)==false) return false;
35
  try {
36
- $klarnaAvailable = Mage::getModel('klarna/klarna_available');
37
- $klarnaAvailable->setQuote($quote, $this->_code);
38
 
39
- $klarnaAvailable->setPClassTypes($this->_code);
40
- $res = $klarnaAvailable->getValidCheckoutPClasses();
41
 
42
  if (!$res) {
43
  return false;
44
  }
45
 
46
  } catch (Mage_Core_Exception $e) {
47
- if ($klarnaAvailable) $klarnaAvailable->logKlarnaException($e);
48
  return false;
49
  }
50
  return true;
33
  {
34
  if (parent::isAvailable($quote)==false) return false;
35
  try {
36
+ $klarna = $this->_getKlarnaModel();
37
+ $klarna->setQuote($quote, $this->_code);
38
 
39
+ $res = $klarna->getValidCheckoutPClasses($this->_code);
 
40
 
41
  if (!$res) {
42
  return false;
43
  }
44
 
45
  } catch (Mage_Core_Exception $e) {
46
+ if ($klarna) $klarna->logKlarnaException($e);
47
  return false;
48
  }
49
  return true;
app/code/community/Vaimo/Klarna/Model/Payment/Checkout.php ADDED
@@ -0,0 +1,67 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Copyright (c) 2009-2014 Vaimo AB
4
+ *
5
+ * Vaimo reserves all rights in the Program as delivered. The Program
6
+ * or any portion thereof may not be reproduced in any form whatsoever without
7
+ * the written consent of Vaimo, except as provided by licence. A licence
8
+ * under Vaimo's rights in the Program may be available directly from
9
+ * Vaimo.
10
+ *
11
+ * Disclaimer:
12
+ * THIS NOTICE MAY NOT BE REMOVED FROM THE PROGRAM BY ANY USER THEREOF.
13
+ * THE PROGRAM IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
14
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
16
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ * OUT OF OR IN CONNECTION WITH THE PROGRAM OR THE USE OR OTHER DEALINGS
19
+ * IN THE PROGRAM.
20
+ *
21
+ * @category Vaimo
22
+ * @package Vaimo_Klarna
23
+ * @copyright Copyright (c) 2009-2014 Vaimo AB
24
+ */
25
+
26
+ class Vaimo_Klarna_Model_Payment_Checkout extends Vaimo_Klarna_Model_Payment_Abstract
27
+ {
28
+ protected $_code = Vaimo_Klarna_Helper_Data::KLARNA_METHOD_CHECKOUT;
29
+ protected $_formBlockType = 'klarna/form_checkout';
30
+ protected $_infoBlockType = 'klarna/info_checkout';
31
+ //protected $_canAuthorize = false;
32
+
33
+ public function getTitle()
34
+ {
35
+ return '';
36
+ }
37
+
38
+ public function isAvailable($quote = NULL)
39
+ {
40
+ if (parent::isAvailable($quote) == false) return false;
41
+ try {
42
+ $klarna = $this->_getKlarnaModel();
43
+ $klarna->setQuote($quote, $this->_code);
44
+
45
+ $allowedMin = (int)$klarna->getConfigData('minimum_order_cost');
46
+ $grandTotal = $quote->getGrandTotal();
47
+
48
+ if ($this->_roundPrice($grandTotal) < $allowedMin) return false;
49
+ } catch (Mage_Core_Exception $e) {
50
+ if ($klarna) $klarna->logKlarnaException($e);
51
+ return false;
52
+ }
53
+ return true;
54
+ }
55
+
56
+ public function assignData($data)
57
+ {
58
+ Mage::throwException(Mage::helper('klarna')->__('Please click the button to go to Klarna Checkout'));
59
+ }
60
+
61
+ public function validate()
62
+ {
63
+ // No validation, it should just work when it gets here
64
+ return $this;
65
+ }
66
+
67
+ }
app/code/community/Vaimo/Klarna/Model/Payment/Invoice.php CHANGED
@@ -33,18 +33,17 @@ class Vaimo_Klarna_Model_Payment_Invoice extends Vaimo_Klarna_Model_Payment_Abst
33
  {
34
  if (parent::isAvailable($quote)==false) return false;
35
  try {
36
- $klarnaAvailable = Mage::getModel('klarna/klarna_available');
37
- $klarnaAvailable->setQuote($quote, $this->_code);
38
 
39
- $allowedMin = (int)$this->getConfigData('minimum_order_cost');
40
  $grandTotal = $quote->getGrandTotal();
41
 
42
- if(Mage::app()->getStore()->roundPrice($grandTotal) < $allowedMin) return false;
43
  } catch (Mage_Core_Exception $e) {
44
- if ($klarnaAvailable) $klarnaAvailable->logKlarnaException($e);
45
  return false;
46
  }
47
  return true;
48
  }
49
-
50
  }
33
  {
34
  if (parent::isAvailable($quote)==false) return false;
35
  try {
36
+ $klarna = $this->_getKlarnaModel();
37
+ $klarna->setQuote($quote, $this->_code);
38
 
39
+ $allowedMin = (int)$klarna->getConfigData('minimum_order_cost');
40
  $grandTotal = $quote->getGrandTotal();
41
 
42
+ if ($this->_roundPrice($grandTotal) < $allowedMin) return false;
43
  } catch (Mage_Core_Exception $e) {
44
+ if ($klarna) $klarna->logKlarnaException($e);
45
  return false;
46
  }
47
  return true;
48
  }
 
49
  }
app/code/community/Vaimo/Klarna/Model/Payment/Special.php CHANGED
@@ -33,18 +33,17 @@ class Vaimo_Klarna_Model_Payment_Special extends Vaimo_Klarna_Model_Payment_Abst
33
  {
34
  if (parent::isAvailable($quote)==false) return false;
35
  try {
36
- $klarnaAvailable = Mage::getModel('klarna/klarna_available');
37
- $klarnaAvailable->setQuote($quote, $this->_code);
38
 
39
- $klarnaAvailable->setPClassTypes($this->_code);
40
- $res = $klarnaAvailable->getValidCheckoutPClasses();
41
 
42
  if (!$res) {
43
  return false;
44
  }
45
 
46
  } catch (Mage_Core_Exception $e) {
47
- if ($klarnaAvailable) $klarnaAvailable->logKlarnaException($e);
48
  return false;
49
  }
50
  return true;
33
  {
34
  if (parent::isAvailable($quote)==false) return false;
35
  try {
36
+ $klarna = $this->_getKlarnaModel();
37
+ $klarna->setQuote($quote, $this->_code);
38
 
39
+ $res = $klarna->getValidCheckoutPClasses($this->_code);
 
40
 
41
  if (!$res) {
42
  return false;
43
  }
44
 
45
  } catch (Mage_Core_Exception $e) {
46
+ if ($klarna) $klarna->logKlarnaException($e);
47
  return false;
48
  }
49
  return true;
app/code/community/Vaimo/Klarna/Model/Quote/Tax.php CHANGED
@@ -25,14 +25,66 @@
25
 
26
  class Vaimo_Klarna_Model_Quote_Tax extends Mage_Sales_Model_Quote_Address_Total_Tax
27
  {
28
- public function __construct()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
29
  {
30
  $this->setCode('vaimo_klarna_fee_tax');
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
31
  }
32
 
33
  public function collect(Mage_Sales_Model_Quote_Address $address)
34
  {
35
- if (Mage::helper('klarna')->collectQuoteRunParentFunction()) {
36
  // parent::collect($address);
37
  }
38
 
@@ -48,7 +100,7 @@ class Vaimo_Klarna_Model_Quote_Tax extends Mage_Sales_Model_Quote_Address_Total_
48
  return $this;
49
  }
50
 
51
- if (!Mage::helper('klarna')->isMethodKlarna($address->getQuote()->getPayment()->getMethod())) {
52
  return $this;
53
  }
54
 
@@ -60,9 +112,9 @@ class Vaimo_Klarna_Model_Quote_Tax extends Mage_Sales_Model_Quote_Address_Total_
60
  $quote = $address->getQuote();
61
  $custTaxClassId = $quote->getCustomerTaxClassId();
62
  $store = $quote->getStore();
63
- $taxCalculationModel = Mage::getSingleton('tax/calculation');
64
  $request = $taxCalculationModel->getRateRequest($address, $quote->getBillingAddress(), $custTaxClassId, $store);
65
- $klarnaFeeTaxClass = Mage::helper('klarna')->getTaxClass($store);
66
 
67
  $klarnaFeeTax = 0;
68
  $klarnaFeeBaseTax = 0;
@@ -73,7 +125,7 @@ class Vaimo_Klarna_Model_Quote_Tax extends Mage_Sales_Model_Quote_Address_Total_
73
  $klarnaFeeTax = $taxCalculationModel->calcTaxAmount($address->getVaimoKlarnaFee(), $rate, false, true);
74
  $klarnaFeeBaseTax = $taxCalculationModel->calcTaxAmount($address->getVaimoKlarnaBaseFee(), $rate, false, true);
75
 
76
- if (Mage::helper('klarna')->collectQuoteUseExtraTaxInCheckout()) {
77
  $address->setExtraTaxAmount($address->getExtraTaxAmount() + $klarnaFeeTax);
78
  $address->setBaseExtraTaxAmount($address->getBaseExtraTaxAmount() + $klarnaFeeBaseTax);
79
  } else {
@@ -99,7 +151,7 @@ class Vaimo_Klarna_Model_Quote_Tax extends Mage_Sales_Model_Quote_Address_Total_
99
  {
100
  $store = $address->getQuote()->getStore();
101
 
102
- if (Mage::getSingleton('tax/config')->displayCartSubtotalBoth($store) || Mage::getSingleton('tax/config')->displayCartSubtotalInclTax($store)) {
103
  if ($address->getSubtotalInclTax() > 0) {
104
  $subtotalInclTax = $address->getSubtotalInclTax();
105
  } else {
@@ -108,7 +160,7 @@ class Vaimo_Klarna_Model_Quote_Tax extends Mage_Sales_Model_Quote_Address_Total_
108
 
109
  $address->addTotal(array(
110
  'code' => 'subtotal',
111
- 'title' => Mage::helper('sales')->__('Subtotal'),
112
  'value' => $subtotalInclTax,
113
  'value_incl_tax' => $subtotalInclTax,
114
  'value_excl_tax' => $address->getSubtotal(),
25
 
26
  class Vaimo_Klarna_Model_Quote_Tax extends Mage_Sales_Model_Quote_Address_Total_Tax
27
  {
28
+ protected $_moduleHelper = NULL;
29
+ protected $_salesHelper = NULL;
30
+
31
+ protected $_taxCalculation = NULL;
32
+ protected $_taxConfig = NULL;
33
+
34
+ /**
35
+ * constructor
36
+ *
37
+ * @param $moduleHelper
38
+ * @param $salesHelper
39
+ * @param $taxCalculation
40
+ * @param $taxConfig
41
+ */
42
+ public function __construct($moduleHelper = NULL, $salesHelper = NULL,
43
+ $taxCalculation = NULL, $taxConfig = NULL)
44
  {
45
  $this->setCode('vaimo_klarna_fee_tax');
46
+
47
+ $this->_moduleHelper = $moduleHelper;
48
+ if ($this->_moduleHelper==NULL) {
49
+ $this->_moduleHelper = Mage::helper('klarna');
50
+ }
51
+ $this->_salesHelper = $salesHelper;
52
+ if ($this->_salesHelper==NULL) {
53
+ $this->_salesHelper = Mage::helper('sales');
54
+ }
55
+ $this->_taxCalculation = $taxCalculation;
56
+ if ($this->_taxCalculation==NULL) {
57
+ $this->_taxCalculation = Mage::getSingleton('tax/calculation');
58
+ }
59
+ $this->_taxConfig = $taxConfig;
60
+ if ($this->_taxConfig==NULL) {
61
+ $this->_taxConfig = Mage::getSingleton('tax/config');
62
+ }
63
+ }
64
+
65
+ protected function _getHelper()
66
+ {
67
+ return $this->_moduleHelper;
68
+ }
69
+
70
+ protected function _getSalesHelper()
71
+ {
72
+ return $this->_salesHelper;
73
+ }
74
+
75
+ protected function _getTaxCalculation()
76
+ {
77
+ return $this->_taxCalculation;
78
+ }
79
+
80
+ protected function _getTaxConfig()
81
+ {
82
+ return $this->_taxConfig;
83
  }
84
 
85
  public function collect(Mage_Sales_Model_Quote_Address $address)
86
  {
87
+ if ($this->_getHelper()->collectQuoteRunParentFunction()) {
88
  // parent::collect($address);
89
  }
90
 
100
  return $this;
101
  }
102
 
103
+ if (!$this->_getHelper()->isMethodKlarna($address->getQuote()->getPayment()->getMethod())) {
104
  return $this;
105
  }
106
 
112
  $quote = $address->getQuote();
113
  $custTaxClassId = $quote->getCustomerTaxClassId();
114
  $store = $quote->getStore();
115
+ $taxCalculationModel = $this->_getTaxCalculation();
116
  $request = $taxCalculationModel->getRateRequest($address, $quote->getBillingAddress(), $custTaxClassId, $store);
117
+ $klarnaFeeTaxClass = $this->_getHelper()->getTaxClass($store);
118
 
119
  $klarnaFeeTax = 0;
120
  $klarnaFeeBaseTax = 0;
125
  $klarnaFeeTax = $taxCalculationModel->calcTaxAmount($address->getVaimoKlarnaFee(), $rate, false, true);
126
  $klarnaFeeBaseTax = $taxCalculationModel->calcTaxAmount($address->getVaimoKlarnaBaseFee(), $rate, false, true);
127
 
128
+ if ($this->_getHelper()->collectQuoteUseExtraTaxInCheckout()) {
129
  $address->setExtraTaxAmount($address->getExtraTaxAmount() + $klarnaFeeTax);
130
  $address->setBaseExtraTaxAmount($address->getBaseExtraTaxAmount() + $klarnaFeeBaseTax);
131
  } else {
151
  {
152
  $store = $address->getQuote()->getStore();
153
 
154
+ if ($this->_getTaxConfig()->displayCartSubtotalBoth($store) || $this->_getTaxConfig()->displayCartSubtotalInclTax($store)) {
155
  if ($address->getSubtotalInclTax() > 0) {
156
  $subtotalInclTax = $address->getSubtotalInclTax();
157
  } else {
160
 
161
  $address->addTotal(array(
162
  'code' => 'subtotal',
163
+ 'title' => $this->_getSalesHelper()->__('Subtotal'),
164
  'value' => $subtotalInclTax,
165
  'value_incl_tax' => $subtotalInclTax,
166
  'value_excl_tax' => $address->getSubtotal(),
app/code/community/Vaimo/Klarna/Model/Quote/Total.php CHANGED
@@ -25,14 +25,31 @@
25
 
26
  class Vaimo_Klarna_Model_Quote_Total extends Mage_Sales_Model_Quote_Address_Total_Abstract
27
  {
28
- public function __construct()
 
 
 
 
 
 
 
29
  {
30
  $this->setCode('vaimo_klarna_fee');
 
 
 
 
 
 
 
 
 
 
31
  }
32
 
33
  public function collect(Mage_Sales_Model_Quote_Address $address)
34
  {
35
- if (Mage::helper('klarna')->collectQuoteRunParentFunction()) {
36
  parent::collect($address);
37
  }
38
 
@@ -54,7 +71,7 @@ class Vaimo_Klarna_Model_Quote_Total extends Mage_Sales_Model_Quote_Address_Tota
54
  return $this;
55
  }
56
 
57
- if (!Mage::helper('klarna')->isMethodKlarna($address->getQuote()->getPayment()->getMethod())) {
58
  return $this;
59
  }
60
 
@@ -63,7 +80,7 @@ class Vaimo_Klarna_Model_Quote_Total extends Mage_Sales_Model_Quote_Address_Tota
63
  return $this;
64
  }
65
 
66
- $baseKlarnaFee = Mage::helper('klarna')->getVaimoKlarnaFeeExclVat($address);
67
 
68
  if (!$baseKlarnaFee > 0 ) {
69
  return $this;
@@ -90,8 +107,8 @@ class Vaimo_Klarna_Model_Quote_Total extends Mage_Sales_Model_Quote_Address_Tota
90
  {
91
  $amount = $address->getVaimoKlarnaFee();
92
 
93
- if (Mage::helper('klarna')->isOneStepCheckout()) {
94
- if (Mage::helper('klarna')->isOneStepCheckoutTaxIncluded()) {
95
  $amount = $amount + $address->getVaimoKlarnaFeeTax();
96
  }
97
  }
@@ -100,7 +117,7 @@ class Vaimo_Klarna_Model_Quote_Total extends Mage_Sales_Model_Quote_Address_Tota
100
  $quote = $address->getQuote();
101
  $address->addTotal(array(
102
  'code' => $this->getCode(),
103
- 'title' => Mage::helper('klarna')->getKlarnaFeeLabel($quote->getStore()),
104
  'value' => $amount,
105
  ));
106
  }
25
 
26
  class Vaimo_Klarna_Model_Quote_Total extends Mage_Sales_Model_Quote_Address_Total_Abstract
27
  {
28
+ protected $_moduleHelper = NULL;
29
+
30
+ /**
31
+ * constructor
32
+ *
33
+ * @param $moduleHelper
34
+ */
35
+ public function __construct($moduleHelper = NULL)
36
  {
37
  $this->setCode('vaimo_klarna_fee');
38
+
39
+ $this->_moduleHelper = $moduleHelper;
40
+ if ($this->_moduleHelper==NULL) {
41
+ $this->_moduleHelper = Mage::helper('klarna');
42
+ }
43
+ }
44
+
45
+ protected function _getHelper()
46
+ {
47
+ return $this->_moduleHelper;
48
  }
49
 
50
  public function collect(Mage_Sales_Model_Quote_Address $address)
51
  {
52
+ if ($this->_getHelper()->collectQuoteRunParentFunction()) {
53
  parent::collect($address);
54
  }
55
 
71
  return $this;
72
  }
73
 
74
+ if (!$this->_getHelper()->isMethodKlarna($address->getQuote()->getPayment()->getMethod())) {
75
  return $this;
76
  }
77
 
80
  return $this;
81
  }
82
 
83
+ $baseKlarnaFee = $this->_getHelper()->getVaimoKlarnaFeeExclVat($address);
84
 
85
  if (!$baseKlarnaFee > 0 ) {
86
  return $this;
107
  {
108
  $amount = $address->getVaimoKlarnaFee();
109
 
110
+ if ($this->_getHelper()->isOneStepCheckout()) {
111
+ if ($this->_getHelper()->isOneStepCheckoutTaxIncluded()) {
112
  $amount = $amount + $address->getVaimoKlarnaFeeTax();
113
  }
114
  }
117
  $quote = $address->getQuote();
118
  $address->addTotal(array(
119
  'code' => $this->getCode(),
120
+ 'title' => $this->_getHelper()->getKlarnaFeeLabel($quote->getStore()),
121
  'value' => $amount,
122
  ));
123
  }
app/code/community/Vaimo/Klarna/Model/{Klarna/Capture.php → Source/Abstract.php} RENAMED
@@ -23,43 +23,48 @@
23
  * @copyright Copyright (c) 2009-2014 Vaimo AB
24
  */
25
 
26
- class Vaimo_Klarna_Model_Klarna_Capture extends Vaimo_Klarna_Model_Klarna_Api
27
  {
28
-
29
- public function __construct($klarnaApi = null, $payment = null)
30
- {
31
- parent::__construct($klarnaApi, $payment);
32
- $this->_setFunctionName('capture');
33
- }
34
-
35
- public function supportedMethod()
 
 
 
 
36
  {
37
- $method = $this->getPayment()->getMethod();
38
- if (Mage::helper('klarna')->isMethodKlarna($method)) {
39
- return true;
 
 
 
 
 
 
 
 
40
  }
41
- return false;
42
  }
43
 
44
- public function createItemList()
45
  {
46
- // The array that will hold the items that we are going to use
47
- $items = array();
48
 
49
- // Loop through the item collection
50
- foreach ($this->getInvoice()->getAllItems() as $item) {
51
- $ord_items = $this->getOrder()->getItemsCollection();
52
- foreach ($ord_items as $ord_item) {
53
- if ($ord_item->getId()==$item->getOrderItemId()) {
54
- if (Mage::helper('klarna')->shouldItemBeIncluded($ord_item)) {
55
- $items[] = $item;
56
- }
57
- break;
58
- }
59
- }
60
- }
61
-
62
- return $items;
63
  }
64
-
 
 
 
 
 
65
  }
23
  * @copyright Copyright (c) 2009-2014 Vaimo AB
24
  */
25
 
26
+ abstract class Vaimo_Klarna_Model_Source_Abstract
27
  {
28
+ protected $_moduleHelper = NULL;
29
+ protected $_coreHelper = NULL;
30
+ protected $_adminhtmlHelper = NULL;
31
+
32
+ /**
33
+ * constructor
34
+ *
35
+ * @param $moduleHelper
36
+ * @param $coreHelper
37
+ * @param $adminhtmlHelper
38
+ */
39
+ public function __construct($moduleHelper = NULL, $coreHelper = NULL, $adminhtmlHelper = NULL)
40
  {
41
+ $this->_moduleHelper = $moduleHelper;
42
+ if ($this->_moduleHelper==NULL) {
43
+ $this->_moduleHelper = Mage::helper('klarna');
44
+ }
45
+ $this->_coreHelper = $coreHelper;
46
+ if ($this->_coreHelper==NULL) {
47
+ $this->_coreHelper = Mage::helper('core');
48
+ }
49
+ $this->_adminhtmlHelper = $adminhtmlHelper;
50
+ if ($this->_adminhtmlHelper==NULL) {
51
+ $this->_adminhtmlHelper = Mage::helper('adminhtml');
52
  }
 
53
  }
54
 
55
+ protected function _getHelper()
56
  {
57
+ return $this->_moduleHelper;
58
+ }
59
 
60
+ protected function _getCoreHelper()
61
+ {
62
+ return $this->_coreHelper;
 
 
 
 
 
 
 
 
 
 
 
63
  }
64
+
65
+ protected function _getAdminhtmlHelper()
66
+ {
67
+ return $this->_adminhtmlHelper;
68
+ }
69
+
70
  }
app/code/community/Vaimo/Klarna/Model/Source/Allspecificcountries.php CHANGED
@@ -24,13 +24,13 @@
24
  */
25
 
26
 
27
- class Vaimo_Klarna_Model_Source_Allspecificcountries
28
  {
29
  public function toOptionArray()
30
  {
31
  return array(
32
- array('value'=>0, 'label'=>Mage::helper('klarna')->__('Default Country Only')),
33
- array('value'=>1, 'label'=>Mage::helper('klarna')->__('Multiple Countries Allowed')),
34
  );
35
  }
36
  }
24
  */
25
 
26
 
27
+ class Vaimo_Klarna_Model_Source_Allspecificcountries extends Vaimo_Klarna_Model_Source_Abstract
28
  {
29
  public function toOptionArray()
30
  {
31
  return array(
32
+ array('value' => 0, 'label' => $this->_getHelper()->__('Default Country Only')),
33
+ array('value' => 1, 'label' => $this->_getHelper()->__('Multiple Countries Allowed')),
34
  );
35
  }
36
  }
app/code/community/Vaimo/Klarna/Model/{Klarna/Pclass.php → Source/Apiversion.php} RENAMED
@@ -1,4 +1,5 @@
1
  <?php
 
2
  /**
3
  * Copyright (c) 2009-2014 Vaimo AB
4
  *
@@ -22,20 +23,32 @@
22
  * @package Vaimo_Klarna
23
  * @copyright Copyright (c) 2009-2014 Vaimo AB
24
  */
25
-
26
- class Vaimo_Klarna_Model_Klarna_Pclass extends Vaimo_Klarna_Model_Klarna_Api
27
  {
28
- public function __construct($klarnaApi = null, $payment = null)
 
 
 
 
 
 
29
  {
30
- parent::__construct($klarnaApi, $payment);
31
- $this->_setFunctionName('pclass');
 
 
32
  }
33
 
34
- public function getPClassDetails($plan)
 
 
 
 
 
35
  {
36
- $pclassArray = $this->_getSpecificPClass($plan);
37
- $res = new Varien_Object($pclassArray);
38
- return $res;
 
39
  }
40
-
41
- }
1
  <?php
2
+
3
  /**
4
  * Copyright (c) 2009-2014 Vaimo AB
5
  *
23
  * @package Vaimo_Klarna
24
  * @copyright Copyright (c) 2009-2014 Vaimo AB
25
  */
26
+ class Vaimo_Klarna_Model_Source_Apiversion extends Vaimo_Klarna_Model_Source_Abstract
 
27
  {
28
+
29
+ /**
30
+ * Options getter
31
+ *
32
+ * @return array
33
+ */
34
+ public function toOptionArray()
35
  {
36
+ return array(
37
+ array('value' => 2, 'label' => $this->_getHelper()->__('KCO V.2')),
38
+ array('value' => 3, 'label' => $this->_getHelper()->__('KCO V.3 (UK)')),
39
+ );
40
  }
41
 
42
+ /**
43
+ * Get options in "key-value" format
44
+ *
45
+ * @return array
46
+ */
47
+ public function toArray()
48
  {
49
+ return array(
50
+ 2 => $this->_getHelper()->__('KCO V.2'),
51
+ 3 => $this->_getHelper()->__('KCO V.3 (UK)'),
52
+ );
53
  }
54
+ }
 
app/code/community/Vaimo/Klarna/Model/Source/Capture.php CHANGED
@@ -23,13 +23,13 @@
23
  * @copyright Copyright (c) 2009-2014 Vaimo AB
24
  */
25
 
26
- class Vaimo_Klarna_Model_Source_Capture
27
  {
28
  public function toOptionArray()
29
  {
30
  return array(
31
- array('value' => 0, 'label' => Mage::helper('klarna')->__('Direct Capture')),
32
- array('value' => 1, 'label' => Mage::helper('klarna')->__('Capture on Invoice')),
33
  );
34
  }
35
  }
23
  * @copyright Copyright (c) 2009-2014 Vaimo AB
24
  */
25
 
26
+ class Vaimo_Klarna_Model_Source_Capture extends Vaimo_Klarna_Model_Source_Abstract
27
  {
28
  public function toOptionArray()
29
  {
30
  return array(
31
+ array('value' => 0, 'label' => $this->_getHelper()->__('Direct Capture')),
32
+ array('value' => 1, 'label' => $this->_getHelper()->__('Capture on Invoice')),
33
  );
34
  }
35
  }
app/code/community/Vaimo/Klarna/Model/Source/Country.php CHANGED
@@ -23,19 +23,19 @@
23
  * @copyright Copyright (c) 2009-2014 Vaimo AB
24
  */
25
 
26
- class Vaimo_Klarna_Model_Source_Country
27
  {
28
 
29
  public function toOptionArray()
30
  {
31
  return array(
32
- array('value' => 'AT', 'label' => Mage::helper('core')->__('Austria')),
33
- array('value' => 'DK', 'label' => Mage::helper('core')->__('Denmark')),
34
- array('value' => 'FI', 'label' => Mage::helper('core')->__('Finland')),
35
- array('value' => 'DE', 'label' => Mage::helper('core')->__('Germany')),
36
- array('value' => 'NL', 'label' => Mage::helper('core')->__('Netherlands')),
37
- array('value' => 'NO', 'label' => Mage::helper('core')->__('Norway')),
38
- array('value' => 'SE', 'label' => Mage::helper('core')->__('Sweden')),
39
  );
40
  }
41
 
23
  * @copyright Copyright (c) 2009-2014 Vaimo AB
24
  */
25
 
26
+ class Vaimo_Klarna_Model_Source_Country extends Vaimo_Klarna_Model_Source_Abstract
27
  {
28
 
29
  public function toOptionArray()
30
  {
31
  return array(
32
+ array('value' => 'AT', 'label' => $this->_getCoreHelper()->__('Austria')),
33
+ array('value' => 'DK', 'label' => $this->_getCoreHelper()->__('Denmark')),
34
+ array('value' => 'FI', 'label' => $this->_getCoreHelper()->__('Finland')),
35
+ array('value' => 'DE', 'label' => $this->_getCoreHelper()->__('Germany')),
36
+ array('value' => 'NL', 'label' => $this->_getCoreHelper()->__('Netherlands')),
37
+ array('value' => 'NO', 'label' => $this->_getCoreHelper()->__('Norway')),
38
+ array('value' => 'SE', 'label' => $this->_getCoreHelper()->__('Sweden')),
39
  );
40
  }
41
 
app/code/community/Vaimo/Klarna/Model/{Klarna/Refund.php → Source/Customergroup.php} RENAMED
@@ -23,33 +23,44 @@
23
  * @copyright Copyright (c) 2009-2014 Vaimo AB
24
  */
25
 
26
- class Vaimo_Klarna_Model_Klarna_Refund extends Vaimo_Klarna_Model_Klarna_Api
27
  {
28
- public function __construct($klarnaApi = null, $payment = null)
 
 
 
 
 
 
 
29
  {
30
- parent::__construct($klarnaApi, $payment);
31
- $this->_setFunctionName('refund');
32
  }
33
 
34
- public function createItemList()
 
 
 
 
 
35
  {
36
- // The array that will hold the items that we are going to use
37
- $items = array();
38
 
39
- // Loop through the item collection
40
- foreach ($this->getCreditmemo()->getAllItems() as $item) {
41
- $ord_items = $this->getOrder()->getItemsCollection();
42
- foreach ($ord_items as $ord_item) {
43
- if ($ord_item->getId()==$item->getOrderItemId()) {
44
- if (Mage::helper('klarna')->shouldItemBeIncluded($ord_item)) {
45
- $items[] = $item;
46
- }
47
- break;
48
  }
 
49
  }
 
 
50
  }
51
-
52
- return $items;
53
  }
54
-
55
- }
23
  * @copyright Copyright (c) 2009-2014 Vaimo AB
24
  */
25
 
26
+ class Vaimo_Klarna_Model_Source_Customergroup extends Vaimo_Klarna_Model_Source_Abstract
27
  {
28
+ /**
29
+ * Customer groups options array
30
+ *
31
+ * @var null|array
32
+ */
33
+ protected $_options;
34
+
35
+ protected function _getCustomerGroups()
36
  {
37
+ return Mage::getResourceModel('customer/group_collection')
38
+ ->loadData()->toOptionArray();
39
  }
40
 
41
+ /**
42
+ * Retrieve customer groups as array
43
+ *
44
+ * @return array
45
+ */
46
+ public function toOptionArray()
47
  {
48
+ if (!$this->_options) {
49
+ $this->_options = $this->_getCustomerGroups();
50
 
51
+ //Preserve original sort order
52
+ $tmpOptions = array();
53
+ foreach($this->_options as $option) {
54
+ if (empty($tmpOptions)) {
55
+ $tmpOptions[] = array('value' => Vaimo_Klarna_Helper_Data::KLARNA_CHECKOUT_ALLOW_ALL_GROUP_ID,
56
+ 'label' => $this->_getHelper()->__('All customer groups'));
 
 
 
57
  }
58
+ $tmpOptions[] = $option;
59
  }
60
+
61
+ $this->_options = $tmpOptions;
62
  }
63
+
64
+ return $this->_options;
65
  }
66
+ }
 
app/code/community/Vaimo/Klarna/Model/Source/Language.php CHANGED
@@ -23,19 +23,19 @@
23
  * @copyright Copyright (c) 2009-2014 Vaimo AB
24
  */
25
 
26
- class Vaimo_Klarna_Model_Source_Language
27
  {
28
 
29
  public function toOptionArray()
30
  {
31
  return array(
32
- array('value' => '', 'label' => Mage::helper('core')->__('Default')),
33
- array('value' => 'nb', 'label' => Mage::helper('core')->__('Norwegian')),
34
- array('value' => 'se', 'label' => Mage::helper('core')->__('Swedish')),
35
- array('value' => 'fi', 'label' => Mage::helper('core')->__('Finnish')),
36
- array('value' => 'dk', 'label' => Mage::helper('core')->__('Danish')),
37
- array('value' => 'nl', 'label' => Mage::helper('core')->__('Dutch')),
38
- array('value' => 'de', 'label' => Mage::helper('core')->__('German')),
39
  );
40
  }
41
 
23
  * @copyright Copyright (c) 2009-2014 Vaimo AB
24
  */
25
 
26
+ class Vaimo_Klarna_Model_Source_Language extends Vaimo_Klarna_Model_Source_Abstract
27
  {
28
 
29
  public function toOptionArray()
30
  {
31
  return array(
32
+ array('value' => '', 'label' => $this->_getCoreHelper()->__('Default')),
33
+ array('value' => 'nb', 'label' => $this->_getCoreHelper()->__('Norwegian')),
34
+ array('value' => 'se', 'label' => $this->_getCoreHelper()->__('Swedish')),
35
+ array('value' => 'fi', 'label' => $this->_getCoreHelper()->__('Finnish')),
36
+ array('value' => 'dk', 'label' => $this->_getCoreHelper()->__('Danish')),
37
+ array('value' => 'nl', 'label' => $this->_getCoreHelper()->__('Dutch')),
38
+ array('value' => 'de', 'label' => $this->_getCoreHelper()->__('German')),
39
  );
40
  }
41
 
app/code/community/Vaimo/Klarna/Model/Source/Newsletter.php ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Copyright (c) 2009-2014 Vaimo AB
4
+ *
5
+ * Vaimo reserves all rights in the Program as delivered. The Program
6
+ * or any portion thereof may not be reproduced in any form whatsoever without
7
+ * the written consent of Vaimo, except as provided by licence. A licence
8
+ * under Vaimo's rights in the Program may be available directly from
9
+ * Vaimo.
10
+ *
11
+ * Disclaimer:
12
+ * THIS NOTICE MAY NOT BE REMOVED FROM THE PROGRAM BY ANY USER THEREOF.
13
+ * THE PROGRAM IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
14
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
16
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ * OUT OF OR IN CONNECTION WITH THE PROGRAM OR THE USE OR OTHER DEALINGS
19
+ * IN THE PROGRAM.
20
+ *
21
+ * @category Vaimo
22
+ * @package Vaimo_Klarna
23
+ * @copyright Copyright (c) 2009-2014 Vaimo AB
24
+ */
25
+
26
+ class Vaimo_Klarna_Model_Source_Newsletter extends Vaimo_Klarna_Model_Source_Abstract
27
+ {
28
+ public function toOptionArray()
29
+ {
30
+ return array(
31
+ array('value' => Vaimo_Klarna_Helper_Data::KLARNA_CHECKOUT_NEWSLETTER_DISABLED, 'label' => $this->_getHelper()->__('No')),
32
+ array('value' => Vaimo_Klarna_Helper_Data::KLARNA_CHECKOUT_NEWSLETTER_SUBSCRIBE, 'label' => $this->_getHelper()->__('Yes - Subscribe to newsletter')),
33
+ array('value' => Vaimo_Klarna_Helper_Data::KLARNA_CHECKOUT_NEWSLETTER_DONT_SUBSCRIBE, 'label' => $this->_getHelper()->__('Yes - Don\'t subscribe to newsletter')),
34
+ );
35
+ }
36
+ }
app/code/community/Vaimo/Klarna/Model/Source/Servermode.php CHANGED
@@ -23,14 +23,14 @@
23
  * @copyright Copyright (c) 2009-2014 Vaimo AB
24
  */
25
 
26
- class Vaimo_Klarna_Model_Source_Servermode
27
  {
28
 
29
  public function toOptionArray()
30
  {
31
  return array(
32
- array('value' => 'BETA', 'label' => Mage::helper('klarna')->__('Testdrive')),
33
- array('value' => 'LIVE', 'label' => Mage::helper('klarna')->__('Live')),
34
  );
35
  }
36
  }
23
  * @copyright Copyright (c) 2009-2014 Vaimo AB
24
  */
25
 
26
+ class Vaimo_Klarna_Model_Source_Servermode extends Vaimo_Klarna_Model_Source_Abstract
27
  {
28
 
29
  public function toOptionArray()
30
  {
31
  return array(
32
+ array('value' => 'BETA', 'label' => $this->_getHelper()->__('Testdrive')),
33
+ array('value' => 'LIVE', 'label' => $this->_getHelper()->__('Live')),
34
  );
35
  }
36
  }
app/code/community/Vaimo/Klarna/Model/Source/Taxclass.php CHANGED
@@ -23,12 +23,11 @@
23
  * @copyright Copyright (c) 2009-2014 Vaimo AB
24
  */
25
 
26
- class Vaimo_Klarna_Model_Source_Taxclass
27
  {
28
  public function toOptionArray()
29
  {
30
- $options = Mage::getModel('tax/class_source_product')->toOptionArray();
31
- return $options;
32
  }
33
 
34
  }
23
  * @copyright Copyright (c) 2009-2014 Vaimo AB
24
  */
25
 
26
+ class Vaimo_Klarna_Model_Source_Taxclass extends Vaimo_Klarna_Model_Source_Abstract
27
  {
28
  public function toOptionArray()
29
  {
30
+ return Mage::getModel('tax/class_source_product')->toOptionArray();
 
31
  }
32
 
33
  }
app/code/community/Vaimo/Klarna/Model/Source/Yesnodefault.php ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Copyright (c) 2009-2014 Vaimo AB
4
+ *
5
+ * Vaimo reserves all rights in the Program as delivered. The Program
6
+ * or any portion thereof may not be reproduced in any form whatsoever without
7
+ * the written consent of Vaimo, except as provided by licence. A licence
8
+ * under Vaimo's rights in the Program may be available directly from
9
+ * Vaimo.
10
+ *
11
+ * Disclaimer:
12
+ * THIS NOTICE MAY NOT BE REMOVED FROM THE PROGRAM BY ANY USER THEREOF.
13
+ * THE PROGRAM IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
14
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
16
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ * OUT OF OR IN CONNECTION WITH THE PROGRAM OR THE USE OR OTHER DEALINGS
19
+ * IN THE PROGRAM.
20
+ *
21
+ * @category Vaimo
22
+ * @package Vaimo_Klarna
23
+ * @copyright Copyright (c) 2009-2014 Vaimo AB
24
+ */
25
+
26
+ class Vaimo_Klarna_Model_Source_Yesnodefault extends Vaimo_Klarna_Model_Source_Abstract
27
+ {
28
+ public function toOptionArray()
29
+ {
30
+ return array(
31
+ array('value' => '1', 'label' => $this->_getAdminhtmlHelper()->__('Yes')),
32
+ array('value' => '0', 'label' => $this->_getAdminhtmlHelper()->__('No')),
33
+ array('value' => '2', 'label' => $this->_getHelper()->__('Country Default')),
34
+ );
35
+ }
36
+ }
app/code/community/Vaimo/Klarna/Model/Tax/Config.php CHANGED
@@ -34,7 +34,7 @@ class Vaimo_Klarna_Model_Tax_Config extends Mage_Tax_Model_Config
34
  /**
35
  * Prices display settings
36
  */
37
- const CONFIG_XML_PATH_DISPLAY_KLARNA_FEE = 'tax/display/vaimo_klarna_fee';
38
 
39
  /**
40
  * Shopping cart display settings
@@ -50,7 +50,21 @@ class Vaimo_Klarna_Model_Tax_Config extends Mage_Tax_Model_Config
50
  * @var $_klarnaFeePriceIncludeTax bool
51
  */
52
  protected $_klarnaFeePriceIncludeTax = null;
53
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
54
  /**
55
  * Get tax class id specified for klarna fee tax estimation
56
  *
@@ -59,7 +73,7 @@ class Vaimo_Klarna_Model_Tax_Config extends Mage_Tax_Model_Config
59
  */
60
  public function getKlarnaFeeTaxClass($store=null)
61
  {
62
- return (int)Mage::getStoreConfig(self::CONFIG_XML_PATH_KLARNA_FEE_TAX_CLASS, $store);
63
  }
64
 
65
  /**
@@ -70,7 +84,7 @@ class Vaimo_Klarna_Model_Tax_Config extends Mage_Tax_Model_Config
70
  */
71
  public function getKlarnaFeePriceDisplayType($store = null)
72
  {
73
- return (int)Mage::getStoreConfig(self::CONFIG_XML_PATH_DISPLAY_KLARNA_FEE, $store);
74
  }
75
 
76
  /**
@@ -82,7 +96,7 @@ class Vaimo_Klarna_Model_Tax_Config extends Mage_Tax_Model_Config
82
  public function klarnaFeePriceIncludesTax($store = null)
83
  {
84
  if ($this->_klarnaFeePriceIncludeTax === null) {
85
- $this->_klarnaFeePriceIncludeTax = (bool)Mage::getStoreConfig(
86
  self::CONFIG_XML_PATH_KLARNA_FEE_INCLUDES_TAX,
87
  $store
88
  );
@@ -92,32 +106,32 @@ class Vaimo_Klarna_Model_Tax_Config extends Mage_Tax_Model_Config
92
 
93
  public function displayCartKlarnaFeeInclTax($store = null)
94
  {
95
- return Mage::getStoreConfig(self::XML_PATH_DISPLAY_CART_KLARNA_FEE, $store) == self::DISPLAY_TYPE_INCLUDING_TAX;
96
  }
97
 
98
  public function displayCartKlarnaFeeExclTax($store = null)
99
  {
100
- return Mage::getStoreConfig(self::XML_PATH_DISPLAY_CART_KLARNA_FEE, $store) == self::DISPLAY_TYPE_EXCLUDING_TAX;
101
  }
102
 
103
  public function displayCartKlarnaFeeBoth($store = null)
104
  {
105
- return Mage::getStoreConfig(self::XML_PATH_DISPLAY_CART_KLARNA_FEE, $store) == self::DISPLAY_TYPE_BOTH;
106
  }
107
 
108
  public function displaySalesKlarnaFeeInclTax($store = null)
109
  {
110
- return Mage::getStoreConfig(self::XML_PATH_DISPLAY_SALES_KLARNA_FEE, $store) == self::DISPLAY_TYPE_INCLUDING_TAX;
111
  }
112
 
113
  public function displaySalesKlarnaFeeExclTax($store = null)
114
  {
115
- return Mage::getStoreConfig(self::XML_PATH_DISPLAY_SALES_KLARNA_FEE, $store) == self::DISPLAY_TYPE_EXCLUDING_TAX;
116
  }
117
 
118
  public function displaySalesKlarnaFeeBoth($store = null)
119
  {
120
- return Mage::getStoreConfig(self::XML_PATH_DISPLAY_SALES_KLARNA_FEE, $store) == self::DISPLAY_TYPE_BOTH;
121
  }
122
  }
123
 
34
  /**
35
  * Prices display settings
36
  */
37
+ const CONFIG_XML_PATH_DISPLAY_KLARNA_FEE = 'tax/display/vaimo_klarna_fee'; // Not used?
38
 
39
  /**
40
  * Shopping cart display settings
50
  * @var $_klarnaFeePriceIncludeTax bool
51
  */
52
  protected $_klarnaFeePriceIncludeTax = null;
53
+
54
+ /*
55
+ * Will call normal Mage::getStoreConfig
56
+ * It's in it's own function, so it can be mocked in tests
57
+ *
58
+ * @param string $field
59
+ * @param string $storeId
60
+ *
61
+ * @return string
62
+ */
63
+ protected function _getConfigDataCall($field, $storeId)
64
+ {
65
+ return Mage::getStoreConfig($field, $storeId);
66
+ }
67
+
68
  /**
69
  * Get tax class id specified for klarna fee tax estimation
70
  *
73
  */
74
  public function getKlarnaFeeTaxClass($store=null)
75
  {
76
+ return (int)$this->_getConfigDataCall(self::CONFIG_XML_PATH_KLARNA_FEE_TAX_CLASS, $store);
77
  }
78
 
79
  /**
84
  */
85
  public function getKlarnaFeePriceDisplayType($store = null)
86
  {
87
+ return (int)$this->_getConfigDataCall(self::CONFIG_XML_PATH_DISPLAY_KLARNA_FEE, $store);
88
  }
89
 
90
  /**
96
  public function klarnaFeePriceIncludesTax($store = null)
97
  {
98
  if ($this->_klarnaFeePriceIncludeTax === null) {
99
+ $this->_klarnaFeePriceIncludeTax = (bool)$this->_getConfigDataCall(
100
  self::CONFIG_XML_PATH_KLARNA_FEE_INCLUDES_TAX,
101
  $store
102
  );
106
 
107
  public function displayCartKlarnaFeeInclTax($store = null)
108
  {
109
+ return $this->_getConfigDataCall(self::XML_PATH_DISPLAY_CART_KLARNA_FEE, $store) == self::DISPLAY_TYPE_INCLUDING_TAX;
110
  }
111
 
112
  public function displayCartKlarnaFeeExclTax($store = null)
113
  {
114
+ return $this->_getConfigDataCall(self::XML_PATH_DISPLAY_CART_KLARNA_FEE, $store) == self::DISPLAY_TYPE_EXCLUDING_TAX;
115
  }
116
 
117
  public function displayCartKlarnaFeeBoth($store = null)
118
  {
119
+ return $this->_getConfigDataCall(self::XML_PATH_DISPLAY_CART_KLARNA_FEE, $store) == self::DISPLAY_TYPE_BOTH;
120
  }
121
 
122
  public function displaySalesKlarnaFeeInclTax($store = null)
123
  {
124
+ return $this->_getConfigDataCall(self::XML_PATH_DISPLAY_SALES_KLARNA_FEE, $store) == self::DISPLAY_TYPE_INCLUDING_TAX;
125
  }
126
 
127
  public function displaySalesKlarnaFeeExclTax($store = null)
128
  {
129
+ return $this->_getConfigDataCall(self::XML_PATH_DISPLAY_SALES_KLARNA_FEE, $store) == self::DISPLAY_TYPE_EXCLUDING_TAX;
130
  }
131
 
132
  public function displaySalesKlarnaFeeBoth($store = null)
133
  {
134
+ return $this->_getConfigDataCall(self::XML_PATH_DISPLAY_SALES_KLARNA_FEE, $store) == self::DISPLAY_TYPE_BOTH;
135
  }
136
  }
137
 
app/code/community/Vaimo/Klarna/Model/{Klarna/Tools → Transport}/Abstract.php RENAMED
@@ -31,11 +31,15 @@
31
  * As soon as that is done, you can use this class to do tests and set values that are retreived later in the code
32
  * This class does not have any database connection in itself, that's why it's extending Varian_Object rather than any Magento class
33
  *
 
 
 
 
34
  */
35
 
36
- class Vaimo_Klarna_Model_Klarna_Tools_Abstract extends Varien_Object
37
  {
38
- /*
39
  * The following variables are set depending on what child it is
40
  * Setting payment will automatically also set the order, as it is known in the payment object
41
  */
@@ -45,58 +49,42 @@ class Vaimo_Klarna_Model_Klarna_Tools_Abstract extends Varien_Object
45
  protected $_payment = NULL;
46
  protected $_creditmemo = NULL;
47
 
48
- /*
49
  * Info instance is set for example when doing a refund, it also tries to set the credit memo and order, if they are known
50
  */
51
  protected $_info_instance = NULL;
52
 
53
- /*
54
  * The current payment method
55
  */
56
  protected $_method = NULL;
57
 
58
- /*
59
  * Store id that should be used while loading settings etc
60
  * It's set to Mage::app()->getStore()->getId() initially
61
  * But is then changed as soon as one of the record variables above is set
62
  */
63
  protected $_storeId = NULL;
64
 
65
- /*
66
  * Country, Language and Currency code of the current store or of the current record
67
  */
68
  protected $_countryCode = '';
69
  protected $_languageCode = NULL;
70
  protected $_currencyCode = NULL;
71
 
72
- /*
73
  * Both addresses are set when the records above are set
74
  */
75
  protected $_shippingAddress = NULL;
76
  protected $_billingAddress = NULL;
77
 
78
- /*
79
  * Contains the name of the function currently inheriting this class, only used for logs
80
  */
81
  protected $_functionName = NULL;
82
 
83
- protected $_pclassTypes = NULL;
84
-
85
- /**
86
- * The encoding used by the platform
87
- *
88
- * @var string
89
- */
90
- public static $platformEncoding = 'UTF-8';
91
-
92
  /**
93
- * The encoding expected by Klarna
94
- *
95
- * @var string
96
- */
97
- public static $klarnaEncoding = 'ISO-8859-1';
98
-
99
- /*
100
  * Languages supported by Klarna
101
  */
102
  protected $_supportedLanguages = array(
@@ -109,7 +97,7 @@ class Vaimo_Klarna_Model_Klarna_Tools_Abstract extends Varien_Object
109
  'sv', // Swedish
110
  );
111
 
112
- /*
113
  * Countries supported by Klarna (array not used)
114
  */
115
  protected $_supportedCountries = array(
@@ -123,55 +111,49 @@ class Vaimo_Klarna_Model_Klarna_Tools_Abstract extends Varien_Object
123
  );
124
 
125
 
 
 
126
  /**
127
- * Constructor.
 
 
 
128
  */
129
- public function __construct()
130
  {
131
  parent::__construct();
132
- $this->setStoreInformation();
 
 
 
 
 
 
 
133
  }
134
 
135
  /**
136
- * Encode the string to the klarnaEncoding
137
- *
138
- * @param string $str string to encode
139
- * @param string $from from encoding
140
- * @param string $to target encoding
141
- *
142
- * @return string
143
  */
144
- protected function _encode($str, $from = null, $to = null)
145
  {
146
- if ($from === null) {
147
- $from = self::$platformEncoding;
148
- }
149
- if ($to === null) {
150
- $to = self::$klarnaEncoding;
151
- }
152
- return iconv($from, $to, $str);
153
  }
154
 
155
  /**
156
- * Decode the string to the platformEncoding
157
- *
158
- * @param string $str string to decode
159
- * @param string $from from encoding
160
- * @param string $to target encoding
161
  *
162
  * @return string
163
  */
164
- protected function _decode($str, $from = null, $to = null)
165
  {
166
- if ($from === null) {
167
- $from = self::$klarnaEncoding;
168
- }
169
- if ($to === null) {
170
- $to = self::$platformEncoding;
171
- }
172
- return iconv($from, $to, $str);
173
  }
174
-
175
  /**
176
  * Will set current store language, but there is a language override in the Klarna payment setting.
177
  * Language is sent to the Klarna API
@@ -182,10 +164,10 @@ class Vaimo_Klarna_Model_Klarna_Tools_Abstract extends Varien_Object
182
  */
183
  protected function _setDefaultLanguageCode()
184
  {
185
- if ($this->_getConfigData('klarna_language')) {
186
- $this->_languageCode = $this->_getConfigData('klarna_language');
187
  } else {
188
- $localeCode = Mage::getStoreConfig(Mage_Core_Model_Locale::XML_PATH_DEFAULT_LOCALE, $this->_getStoreId() );
189
  $this->_languageCode = $this->_getLocaleCode($localeCode);
190
  }
191
  if (!in_array($this->_languageCode, $this->_supportedLanguages)) {
@@ -193,28 +175,28 @@ class Vaimo_Klarna_Model_Klarna_Tools_Abstract extends Varien_Object
193
  }
194
  }
195
 
196
- /*
197
  * Gets the Default country of the store
198
  *
199
  * @return string
200
  */
201
  protected function _getDefaultCountry()
202
  {
203
- return strtoupper(Mage::getStoreConfig(Mage_Core_Model_Locale::XML_PATH_DEFAULT_COUNTRY, $this->_getStoreId()));
204
  }
205
 
206
- /*
207
  * Sets the default currency to that of this store id
208
  *
209
  * @return void
210
  */
211
  protected function _setDefaultCurrencyCode()
212
  {
213
- $currencyCode = Mage::getStoreConfig(Mage_Directory_Model_Currency::XML_PATH_CURRENCY_DEFAULT, $this->_getStoreId() );
214
  $this->_currencyCode = strtoupper($currencyCode);
215
  }
216
 
217
- /*
218
  * Sets the default country to that of this store id
219
  *
220
  * @return void
@@ -224,17 +206,26 @@ class Vaimo_Klarna_Model_Klarna_Tools_Abstract extends Varien_Object
224
  $this->_countryCode = $this->_getDefaultCountry();
225
  }
226
 
227
- /*
 
 
 
 
 
228
  * Sets the store of this class and then updates the default values
229
  *
 
 
 
 
230
  * @return void
231
  */
232
  public function setStoreInformation($storeId = NULL)
233
  {
234
  if ($storeId === NULL) {
235
- $this->_storeId = Mage::app()->getStore()->getId();
236
  } else {
237
- $this->_storeId = $storeId;
238
  }
239
  $this->_setDefaultLanguageCode();
240
  $this->_setDefaultCurrencyCode();
@@ -250,14 +241,15 @@ class Vaimo_Klarna_Model_Klarna_Tools_Abstract extends Varien_Object
250
  */
251
  protected function _getLocaleCode($localeCode)
252
  {
253
- $result = preg_match("/([a-z]+)_[A-Z]+/", $localeCode, $collection);
254
- if ($result !== 0) {
255
- return $collection[1];
 
256
  }
257
- return null;
258
  }
259
 
260
- /*
261
  * This function is only called if multiple countries are allowed
262
  * And one chooses one of the countries that aren't the default one
263
  * It then changes the language, to match with the country.
@@ -291,7 +283,7 @@ class Vaimo_Klarna_Model_Klarna_Tools_Abstract extends Varien_Object
291
  }
292
  }
293
 
294
- /*
295
  * Once we have a record in one of the record variables, we update the addresses and then we set the country to
296
  * that of the shipping address or billing address, if shipping is empty
297
  *
@@ -368,7 +360,7 @@ class Vaimo_Klarna_Model_Klarna_Tools_Abstract extends Varien_Object
368
  $this->_currencyCode = $order->getOrderCurrencyCode();
369
  }
370
 
371
- /*
372
  * Sets the function name, which is used in logs. This is set in each class construct
373
  *
374
  * @param string $functionName
@@ -380,7 +372,7 @@ class Vaimo_Klarna_Model_Klarna_Tools_Abstract extends Varien_Object
380
  $this->_functionName = $functionName;
381
  }
382
 
383
- /*
384
  * Sets the payment method, either directly from the top class or when the appropriate record object is set
385
  *
386
  * @param string
@@ -392,7 +384,7 @@ class Vaimo_Klarna_Model_Klarna_Tools_Abstract extends Varien_Object
392
  $this->_method = $method;
393
  }
394
 
395
- /*
396
  * Sets the order of this class plus updates what is known on the order, such as payment method, store and address
397
  *
398
  * @param Mage_Sales_Model_Order $order
@@ -410,7 +402,7 @@ class Vaimo_Klarna_Model_Klarna_Tools_Abstract extends Varien_Object
410
  $this->_setAddressesFromOrder($order);
411
  }
412
 
413
- /*
414
  * Sets the quote of this class plus updates what is known on the quote, store and address
415
  * Method can also be set by this function, if it is known
416
  *
@@ -425,11 +417,13 @@ class Vaimo_Klarna_Model_Klarna_Tools_Abstract extends Varien_Object
425
  if ($method) {
426
  $this->setMethod($method);
427
  }
428
- $this->setStoreInformation($this->getQuote()->getStoreId());
429
- $this->_setAddressesFromQuote($quote);
 
 
430
  }
431
 
432
- /*
433
  * Sets the invoice of this class plus updates current store
434
  *
435
  * @param Mage_Sales_Model_Order_Invoice $invoice
@@ -439,11 +433,14 @@ class Vaimo_Klarna_Model_Klarna_Tools_Abstract extends Varien_Object
439
  public function setInvoice($invoice)
440
  {
441
  $this->_invoice = $invoice;
442
- $this->setStoreInformation($this->getInvoice()->getStoreId());
 
 
443
  }
444
 
445
- /*
446
- * Sets the creditmemo of this class
 
447
  *
448
  * @param Mage_Sales_Model_Order_Creditmemo $creditmemo
449
  *
@@ -453,10 +450,9 @@ class Vaimo_Klarna_Model_Klarna_Tools_Abstract extends Varien_Object
453
  {
454
  $this->_creditmemo = $creditmemo;
455
  }
456
-
457
- /*
458
- * Sets the payment of this class plus updates what is known of other varibles, such as order, creditmemo and invoice
459
- *
460
  * @param Mage_Sales_Model_Order_Payment $payment
461
  *
462
  * @return void
@@ -475,7 +471,7 @@ class Vaimo_Klarna_Model_Klarna_Tools_Abstract extends Varien_Object
475
  }
476
  }
477
 
478
- /*
479
  * Sets the info instance of this class plus updates what is known of other varibles, such as order and creditmemo
480
  *
481
  * @param Mage_Payment_Model_Info $info
@@ -493,18 +489,6 @@ class Vaimo_Klarna_Model_Klarna_Tools_Abstract extends Varien_Object
493
  }
494
  }
495
 
496
- /*
497
- * Sets the pclasstype variable, which is an array containing what pclass types are acceptable with the current payment method
498
- *
499
- * @param array $types
500
- *
501
- * @return void
502
- */
503
- public function setPClassTypes($types)
504
- {
505
- $this->_pclassTypes = $types;
506
- }
507
-
508
  /**
509
  * Check if consent is needed
510
  *
@@ -585,7 +569,7 @@ class Vaimo_Klarna_Model_Klarna_Tools_Abstract extends Varien_Object
585
  *
586
  * @return array
587
  */
588
- protected function _getSplit()
589
  {
590
  switch ($this->_getCountryCode()) {
591
  case 'DE':
@@ -597,7 +581,7 @@ class Vaimo_Klarna_Model_Klarna_Tools_Abstract extends Varien_Object
597
  }
598
  }
599
 
600
- /*
601
  * Is the sum below the limit allowed for the given _country?
602
  * This contains a hardcoded value for NL.
603
  * Meaning, if a customer shops for over 250 EUR, it won't be allowed to use any part payment option...
@@ -656,20 +640,66 @@ class Vaimo_Klarna_Model_Klarna_Tools_Abstract extends Varien_Object
656
  return true;
657
  }
658
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
659
 
660
  public function getAvailableMethods()
661
  {
662
  $res = array();
663
  $this->setMethod(Vaimo_Klarna_Helper_Data::KLARNA_METHOD_INVOICE);
664
- if ($this->_getConfigData('active')) {
665
  $res[] = $this->getMethod();
666
  }
667
  $this->setMethod(Vaimo_Klarna_Helper_Data::KLARNA_METHOD_ACCOUNT);
668
- if ($this->_getConfigData('active')) {
669
  $res[] = $this->getMethod();
670
  }
671
  $this->setMethod(Vaimo_Klarna_Helper_Data::KLARNA_METHOD_SPECIAL);
672
- if ($this->_getConfigData('active')) {
 
 
 
 
673
  $res[] = $this->getMethod();
674
  }
675
  return $res;
@@ -682,22 +712,11 @@ class Vaimo_Klarna_Model_Klarna_Tools_Abstract extends Varien_Object
682
  */
683
  public function shippingSameAsBilling()
684
  {
685
- if ($this->_getConfigData('allow_separate_address')) {
686
  $res = false;
687
  } else {
688
  $res = true;
689
  }
690
- /*
691
- switch ($this->_getCountryCode()) {
692
- case 'NL':
693
- case 'DE':
694
- $res = true;
695
- break;
696
- default:
697
- $res = false;
698
- break;
699
- }
700
- */
701
  if (!$res) {
702
  if ($this->getQuote()) {
703
  $shipping = $this->getQuote()->isVirtual() ? null : $this->getQuote()->getShippingAddress();
@@ -717,8 +736,8 @@ class Vaimo_Klarna_Model_Klarna_Tools_Abstract extends Varien_Object
717
  public function isCountryAllowed()
718
  {
719
  if ($this->_getCountryCode() != $this->_getDefaultCountry()) {
720
- if ($this->_getConfigData('allowspecific')) {
721
- $allowedCountries = $this->_getConfigData('specificcountry');
722
  if ($allowedCountries) {
723
  if (in_array($this->_getCountryCode(), explode(",", $allowedCountries))) {
724
  return true;
@@ -738,30 +757,30 @@ class Vaimo_Klarna_Model_Klarna_Tools_Abstract extends Varien_Object
738
  */
739
  public function showMethodForCompanyPurchases()
740
  {
741
- if ($this->_getConfigData('disable_company_purchase')) {
742
  return false;
743
  }
744
  return true;
745
  }
746
 
747
- /*
748
  * Function to read correct payment method setting
749
  *
750
  * @param string $field
751
  *
752
  * @return string
753
  */
754
- protected function _getConfigData($field)
755
  {
756
  if ($this->getMethod() && $this->_getStoreId()!==NULL) {
757
- $res = Mage::getStoreConfig('payment/' . $this->getMethod() . '/' . $field, $this->_getStoreId());
758
  } else {
759
  $res = NULL;
760
  }
761
  return $res;
762
  }
763
 
764
- /*
765
  * Returns this class country code
766
  *
767
  * @return string
@@ -771,7 +790,7 @@ class Vaimo_Klarna_Model_Klarna_Tools_Abstract extends Varien_Object
771
  return $this->_countryCode;
772
  }
773
 
774
- /*
775
  * Returns this class language code
776
  *
777
  * @return string
@@ -781,7 +800,7 @@ class Vaimo_Klarna_Model_Klarna_Tools_Abstract extends Varien_Object
781
  return $this->_languageCode;
782
  }
783
 
784
- /*
785
  * Returns this class currency code
786
  *
787
  * @return string
@@ -791,7 +810,7 @@ class Vaimo_Klarna_Model_Klarna_Tools_Abstract extends Varien_Object
791
  return $this->_currencyCode;
792
  }
793
 
794
- /*
795
  * Returns this class store id
796
  *
797
  * @return int
@@ -801,7 +820,7 @@ class Vaimo_Klarna_Model_Klarna_Tools_Abstract extends Varien_Object
801
  return $this->_storeId;
802
  }
803
 
804
- /*
805
  * Returns this class payment method
806
  *
807
  * @return string
@@ -812,7 +831,7 @@ class Vaimo_Klarna_Model_Klarna_Tools_Abstract extends Varien_Object
812
  return $this->_method;
813
  }
814
 
815
- /*
816
  * Returns the order set in this class
817
  *
818
  * @return Mage_Sales_Model_Order
@@ -823,7 +842,7 @@ class Vaimo_Klarna_Model_Klarna_Tools_Abstract extends Varien_Object
823
  return $this->_order;
824
  }
825
 
826
- /*
827
  * Returns the creditmemo set in this class
828
  *
829
  * @return Mage_Sales_Model_Order_Creditmemo
@@ -834,7 +853,7 @@ class Vaimo_Klarna_Model_Klarna_Tools_Abstract extends Varien_Object
834
  return $this->_creditmemo;
835
  }
836
 
837
- /*
838
  * Returns the invoice set in this class
839
  *
840
  * @return Mage_Sales_Model_Order_Invoice
@@ -845,7 +864,7 @@ class Vaimo_Klarna_Model_Klarna_Tools_Abstract extends Varien_Object
845
  return $this->_invoice;
846
  }
847
 
848
- /*
849
  * Returns the payment set in this class
850
  *
851
  * @return Mage_Sales_Model_Order_Payment
@@ -856,7 +875,7 @@ class Vaimo_Klarna_Model_Klarna_Tools_Abstract extends Varien_Object
856
  return $this->_payment;
857
  }
858
 
859
- /*
860
  * Returns the info instance set in this class
861
  *
862
  * @return Mage_Payment_Model_Info
@@ -867,7 +886,7 @@ class Vaimo_Klarna_Model_Klarna_Tools_Abstract extends Varien_Object
867
  return $this->_info_instance;
868
  }
869
 
870
- /*
871
  * Returns the quote set in this class
872
  *
873
  * @return Mage_Sales_Model_Quote
@@ -878,7 +897,7 @@ class Vaimo_Klarna_Model_Klarna_Tools_Abstract extends Varien_Object
878
  return $this->_quote;
879
  }
880
 
881
- /*
882
  * Returns the billing address set in this class
883
  *
884
  * @return Mage_Customer_Model_Address_Abstract
@@ -888,7 +907,7 @@ class Vaimo_Klarna_Model_Klarna_Tools_Abstract extends Varien_Object
888
  return $this->_billingAddress;
889
  }
890
 
891
- /*
892
  * Returns the shipping address set in this class
893
  *
894
  * @return Mage_Customer_Model_Address_Abstract
@@ -898,7 +917,7 @@ class Vaimo_Klarna_Model_Klarna_Tools_Abstract extends Varien_Object
898
  return $this->_shippingAddress;
899
  }
900
 
901
- /*
902
  * Returns the function name set by the constructors in this class
903
  *
904
  * @return string
@@ -908,54 +927,55 @@ class Vaimo_Klarna_Model_Klarna_Tools_Abstract extends Varien_Object
908
  return $this->_functionName;
909
  }
910
 
911
- /*
 
 
 
 
 
912
  * Returns the current payment methods title, as set in Klarna Payment settings
913
  *
914
  * @return string
915
  */
916
- public function getMethodTitle()
917
  {
918
- $res = Mage::helper('klarna')->__($this->_getConfigData('title'));
919
  if ($this->getQuote() && $this->getMethod()==Vaimo_Klarna_Helper_Data::KLARNA_METHOD_INVOICE) {
920
- $fee = Mage::helper('klarna')->getVaimoKlarnaFeeInclVat($this->getQuote(), false);
921
  if ($fee) {
922
- $res .= ' (' . Mage::app()->getStore($this->getQuote()->getStoreId())->formatPrice($fee, false) . ')';
923
  }
924
  }
925
  return $res;
926
  }
927
 
928
- /*
929
- * Return allowed pclass types for current payment method
930
- *
931
- * @return array
932
- */
933
- protected function _getPClassTypes()
934
- {
935
- return $this->_pclassTypes;
936
- }
937
-
938
- /*
939
  * A function that returns a few setup values unique to the current active session
940
  * If currently selected method is not setup it will default to Invoice method and try again
941
  * It uses recursion, but can only call itself once
942
  *
 
 
 
943
  * @return Varien_Object
944
  */
945
  public function getKlarnaSetup()
946
  {
947
  try {
948
- if (!$this->_getConfigData("active")) {
949
- Mage::throwException(Mage::helper('klarna')->__('Current payment method not available'));
 
 
950
  }
951
  $res = new Varien_Object(
952
  array(
953
- 'merchant_id' => $this->_getConfigData("merchant_id"),
 
954
  'country_code' => $this->_getCountryCode(),
955
  'language_code' => $this->_getLanguageCode(),
956
  'locale_code' => $this->_getLanguageCode() . "_" . $this->_getCountryCode(),
957
  'currency_code' => $this->_getCurrencyCode(),
958
- 'host' => $this->_getConfigData("host"),
 
959
  )
960
  );
961
  } catch( Exception $e ) {
@@ -970,7 +990,7 @@ class Vaimo_Klarna_Model_Klarna_Tools_Abstract extends Varien_Object
970
  return $res;
971
  }
972
 
973
- /*
974
  * Log function that does the writing to log file
975
  *
976
  * @param string $filename What file to write to, will be placed in site/var/klarna/ folder
@@ -980,7 +1000,20 @@ class Vaimo_Klarna_Model_Klarna_Tools_Abstract extends Varien_Object
980
  */
981
  protected function _log($filename, $msg)
982
  {
983
- $logDir = Mage::getBaseDir('var') . DS . 'klarna' . DS;
 
 
 
 
 
 
 
 
 
 
 
 
 
984
  $logFile = $logDir . $filename;
985
 
986
  try {
@@ -1001,19 +1034,19 @@ class Vaimo_Klarna_Model_Klarna_Tools_Abstract extends Varien_Object
1001
  }
1002
  }
1003
 
1004
- /*
1005
  * Log function that logs all Klarna API calls and replies, this to see what functions are called and what reply they get
1006
  *
1007
  * @param string $comment Text to log
1008
  *
1009
  * @return void
1010
  */
1011
- protected function _logKlarnaApi($comment)
1012
  {
1013
- $this->_log('api.log', $comment);
1014
  }
1015
 
1016
- /*
1017
  * Log function used for various debug log information, array is optional
1018
  *
1019
  * @param string $info Header of what is being logged
@@ -1021,16 +1054,25 @@ class Vaimo_Klarna_Model_Klarna_Tools_Abstract extends Varien_Object
1021
  *
1022
  * @return void
1023
  */
1024
- protected function _logDebugInfo($info, $arr = NULL)
1025
  {
1026
  if (!$arr) {
1027
- $this->_log('debug.log', $info);
1028
  } else {
1029
- $this->_log('debug.log', $info . "\narray( " . serialize($arr) . " )\n");
 
 
 
 
1030
  }
1031
  }
1032
 
1033
- /*
 
 
 
 
 
1034
  * If there is an exception, this log function should be used
1035
  * This is mainly meant for exceptions concerning klarna API calls, but can be used for any exception
1036
  *
@@ -1040,15 +1082,16 @@ class Vaimo_Klarna_Model_Klarna_Tools_Abstract extends Varien_Object
1040
  */
1041
  public function logKlarnaException($e)
1042
  {
 
1043
  $errstr = 'Exception:';
1044
  if ($e->getCode()) $errstr = $errstr . ' Code: ' . $e->getCode();
1045
- if ($e->getMessage()) $errstr = $errstr . ' Message: ' . $this->_decode($e->getMessage());
1046
  if ($e->getLine()) $errstr = $errstr . ' Row: ' . $e->getLine();
1047
  if ($e->getFile()) $errstr = $errstr . ' File: ' . $e->getFile();
1048
- $this->_log('error.log', $errstr);
1049
  }
1050
 
1051
- /*
1052
  * Creates the path to the Klarna logotype, it depends on payment method, intended placemen and your merchant id
1053
  *
1054
  * @param $width the width of the logotype
@@ -1061,34 +1104,43 @@ class Vaimo_Klarna_Model_Klarna_Tools_Abstract extends Varien_Object
1061
  {
1062
  $res = "";
1063
  if (!$type) {
1064
- $type = Vaimo_Klarna_Helper_Data::KLARNA_LOGOTYPE_TYPE_INVOICE;
1065
  switch ($this->getMethod()) {
 
 
 
1066
  case Vaimo_Klarna_Helper_Data::KLARNA_METHOD_ACCOUNT:
1067
- $type = Vaimo_Klarna_Helper_Data::KLARNA_LOGOTYPE_TYPE_ACCOUNT;
1068
  break;
1069
  case Vaimo_Klarna_Helper_Data::KLARNA_METHOD_SPECIAL:
1070
- if ($this->_getConfigData('cdn_logotype_override')) {
1071
- $res = $this->_getConfigData('cdn_logotype_override');
1072
  $res .= '" width="' . $width; // Adding width to the file location like this is ugly, but works fine
1073
  return $res;
1074
  }
1075
- $type = Vaimo_Klarna_Helper_Data::KLARNA_LOGOTYPE_TYPE_ACCOUNT;
1076
  break;
1077
  }
1078
  }
 
1079
  switch ($position) {
1080
  case Vaimo_Klarna_Helper_Data::KLARNA_LOGOTYPE_POSITION_FRONTEND:
1081
  if ($type==Vaimo_Klarna_Helper_Data::KLARNA_LOGOTYPE_TYPE_BOTH) {
1082
- $res = 'https://cdn.klarna.com/public/images/' . $this->_getCountryCode() . '/badges/v1/' . $type . '/' . $this->_getCountryCode() . '_' . $type . '_badge_banner_blue.png?width=' . $width . '&eid=' . $this->_getConfigData('merchant_id');
 
 
 
 
 
1083
  } else {
1084
- $res = 'https://cdn.klarna.com/public/images/' . $this->_getCountryCode() . '/badges/v1/' . $type . '/' . $this->_getCountryCode() . '_' . $type . '_badge_std_blue.png?width=' . $width . '&eid=' . $this->_getConfigData('merchant_id');
1085
  }
1086
  break;
1087
  case Vaimo_Klarna_Helper_Data::KLARNA_LOGOTYPE_POSITION_PRODUCT:
1088
- $res = 'https://cdn.klarna.com/public/images/' . $this->_getCountryCode() . '/logos/v1/' . $type . '/' . $this->_getCountryCode() . '_' . $type . '_logo_std_blue-black.png?width=' . $width . '&eid=' . $this->_getConfigData('merchant_id');
1089
  break;
1090
  case Vaimo_Klarna_Helper_Data::KLARNA_LOGOTYPE_POSITION_CHECKOUT:
1091
- $res = 'https://cdn.klarna.com/public/images/' . $this->_getCountryCode() . '/badges/v1/' . $type . '/' . $this->_getCountryCode() . '_' . $type . '_badge_std_blue.png?width=' . $width . '&eid=' . $this->_getConfigData('merchant_id');
1092
  break;
1093
  }
1094
  return $res;
31
  * As soon as that is done, you can use this class to do tests and set values that are retreived later in the code
32
  * This class does not have any database connection in itself, that's why it's extending Varian_Object rather than any Magento class
33
  *
34
+ * Once a model has been created that inherits from this, one or more of setQuote, setOrder, setPayment, setInfoInstance,
35
+ * setInvoice or setCreditmemo should be called. If none of these are called, a call to setStoreInformation() must be made
36
+ * in order to set the required variables. That was previous included in construct, but was changed due to unit testing.
37
+ *
38
  */
39
 
40
+ abstract class Vaimo_Klarna_Model_Transport_Abstract extends Varien_Object
41
  {
42
+ /**
43
  * The following variables are set depending on what child it is
44
  * Setting payment will automatically also set the order, as it is known in the payment object
45
  */
49
  protected $_payment = NULL;
50
  protected $_creditmemo = NULL;
51
 
52
+ /**
53
  * Info instance is set for example when doing a refund, it also tries to set the credit memo and order, if they are known
54
  */
55
  protected $_info_instance = NULL;
56
 
57
+ /**
58
  * The current payment method
59
  */
60
  protected $_method = NULL;
61
 
62
+ /**
63
  * Store id that should be used while loading settings etc
64
  * It's set to Mage::app()->getStore()->getId() initially
65
  * But is then changed as soon as one of the record variables above is set
66
  */
67
  protected $_storeId = NULL;
68
 
69
+ /**
70
  * Country, Language and Currency code of the current store or of the current record
71
  */
72
  protected $_countryCode = '';
73
  protected $_languageCode = NULL;
74
  protected $_currencyCode = NULL;
75
 
76
+ /**
77
  * Both addresses are set when the records above are set
78
  */
79
  protected $_shippingAddress = NULL;
80
  protected $_billingAddress = NULL;
81
 
82
+ /**
83
  * Contains the name of the function currently inheriting this class, only used for logs
84
  */
85
  protected $_functionName = NULL;
86
 
 
 
 
 
 
 
 
 
 
87
  /**
 
 
 
 
 
 
 
88
  * Languages supported by Klarna
89
  */
90
  protected $_supportedLanguages = array(
97
  'sv', // Swedish
98
  );
99
 
100
+ /**
101
  * Countries supported by Klarna (array not used)
102
  */
103
  protected $_supportedCountries = array(
111
  );
112
 
113
 
114
+ protected $_moduleHelper = NULL;
115
+
116
  /**
117
+ * Constructor
118
+ * setStoreInfo parameter added for Unittesting, never set otherwise
119
+ *
120
+ * @param bool $setStoreInfo
121
  */
122
+ public function __construct($setStoreInfo = true, $moduleHelper = NULL)
123
  {
124
  parent::__construct();
125
+ if ($setStoreInfo) {
126
+ $this->setStoreInformation();
127
+ }
128
+
129
+ $this->_moduleHelper = $moduleHelper;
130
+ if ($this->_moduleHelper==NULL) {
131
+ $this->_moduleHelper = Mage::helper('klarna');
132
+ }
133
  }
134
 
135
  /**
136
+ * @return Vaimo_Klarna_Helper_Data
 
 
 
 
 
 
137
  */
138
+ protected function _getHelper()
139
  {
140
+ return $this->_moduleHelper;
 
 
 
 
 
 
141
  }
142
 
143
  /**
144
+ * Will call normal Mage::getStoreConfig
145
+ * It's in it's own function, so it can be mocked in tests
146
+ *
147
+ * @param string $field
148
+ * @param string $storeId
149
  *
150
  * @return string
151
  */
152
+ protected function _getConfigDataCall($field, $storeId)
153
  {
154
+ return Mage::getStoreConfig($field, $storeId);
 
 
 
 
 
 
155
  }
156
+
157
  /**
158
  * Will set current store language, but there is a language override in the Klarna payment setting.
159
  * Language is sent to the Klarna API
164
  */
165
  protected function _setDefaultLanguageCode()
166
  {
167
+ if ($this->getConfigData('klarna_language')) {
168
+ $this->_languageCode = $this->getConfigData('klarna_language');
169
  } else {
170
+ $localeCode = $this->_getConfigDataCall(Mage_Core_Model_Locale::XML_PATH_DEFAULT_LOCALE, $this->_getStoreId() );
171
  $this->_languageCode = $this->_getLocaleCode($localeCode);
172
  }
173
  if (!in_array($this->_languageCode, $this->_supportedLanguages)) {
175
  }
176
  }
177
 
178
+ /**
179
  * Gets the Default country of the store
180
  *
181
  * @return string
182
  */
183
  protected function _getDefaultCountry()
184
  {
185
+ return strtoupper($this->_getConfigDataCall(Mage_Core_Model_Locale::XML_PATH_DEFAULT_COUNTRY, $this->_getStoreId()));
186
  }
187
 
188
+ /**
189
  * Sets the default currency to that of this store id
190
  *
191
  * @return void
192
  */
193
  protected function _setDefaultCurrencyCode()
194
  {
195
+ $currencyCode = $this->_getConfigDataCall(Mage_Directory_Model_Currency::XML_PATH_CURRENCY_DEFAULT, $this->_getStoreId() );
196
  $this->_currencyCode = strtoupper($currencyCode);
197
  }
198
 
199
+ /**
200
  * Sets the default country to that of this store id
201
  *
202
  * @return void
206
  $this->_countryCode = $this->_getDefaultCountry();
207
  }
208
 
209
+ protected function _getMageStore()
210
+ {
211
+ return Mage::app()->getStore()->getId();
212
+ }
213
+
214
+ /**
215
  * Sets the store of this class and then updates the default values
216
  *
217
+ * If no record is set, like setQuote or setOrder, the code that
218
+ * gets this model MUST call setStoreInformation. It used to be part
219
+ * of construct, but it was removed from there because of unit tests
220
+ *
221
  * @return void
222
  */
223
  public function setStoreInformation($storeId = NULL)
224
  {
225
  if ($storeId === NULL) {
226
+ $this->_storeId = (int)$this->_getMageStore();
227
  } else {
228
+ $this->_storeId = (int)$storeId;
229
  }
230
  $this->_setDefaultLanguageCode();
231
  $this->_setDefaultCurrencyCode();
241
  */
242
  protected function _getLocaleCode($localeCode)
243
  {
244
+ $res = NULL;
245
+ $preg_result = preg_match("/([a-z]+)_[A-Z]+/", $localeCode, $collection);
246
+ if ($preg_result !== 0) {
247
+ $res = $collection[1];
248
  }
249
+ return $res;
250
  }
251
 
252
+ /**
253
  * This function is only called if multiple countries are allowed
254
  * And one chooses one of the countries that aren't the default one
255
  * It then changes the language, to match with the country.
283
  }
284
  }
285
 
286
+ /**
287
  * Once we have a record in one of the record variables, we update the addresses and then we set the country to
288
  * that of the shipping address or billing address, if shipping is empty
289
  *
360
  $this->_currencyCode = $order->getOrderCurrencyCode();
361
  }
362
 
363
+ /**
364
  * Sets the function name, which is used in logs. This is set in each class construct
365
  *
366
  * @param string $functionName
372
  $this->_functionName = $functionName;
373
  }
374
 
375
+ /**
376
  * Sets the payment method, either directly from the top class or when the appropriate record object is set
377
  *
378
  * @param string
384
  $this->_method = $method;
385
  }
386
 
387
+ /**
388
  * Sets the order of this class plus updates what is known on the order, such as payment method, store and address
389
  *
390
  * @param Mage_Sales_Model_Order $order
402
  $this->_setAddressesFromOrder($order);
403
  }
404
 
405
+ /**
406
  * Sets the quote of this class plus updates what is known on the quote, store and address
407
  * Method can also be set by this function, if it is known
408
  *
417
  if ($method) {
418
  $this->setMethod($method);
419
  }
420
+ if ($quote) {
421
+ $this->setStoreInformation($this->getQuote()->getStoreId());
422
+ $this->_setAddressesFromQuote($quote);
423
+ }
424
  }
425
 
426
+ /**
427
  * Sets the invoice of this class plus updates current store
428
  *
429
  * @param Mage_Sales_Model_Order_Invoice $invoice
433
  public function setInvoice($invoice)
434
  {
435
  $this->_invoice = $invoice;
436
+ if (!$this->getOrder() && $invoice->getOrder()) {
437
+ $this->setOrder($invoice->getOrder());
438
+ }
439
  }
440
 
441
+ /**
442
+ * Sets the creditmemo of this classplus updates what is known of other varibles, such as order, creditmemo and invoice
443
+ *
444
  *
445
  * @param Mage_Sales_Model_Order_Creditmemo $creditmemo
446
  *
450
  {
451
  $this->_creditmemo = $creditmemo;
452
  }
453
+
454
+ /**
455
+ * Sets the payment of this class
 
456
  * @param Mage_Sales_Model_Order_Payment $payment
457
  *
458
  * @return void
471
  }
472
  }
473
 
474
+ /**
475
  * Sets the info instance of this class plus updates what is known of other varibles, such as order and creditmemo
476
  *
477
  * @param Mage_Payment_Model_Info $info
489
  }
490
  }
491
 
 
 
 
 
 
 
 
 
 
 
 
 
492
  /**
493
  * Check if consent is needed
494
  *
569
  *
570
  * @return array
571
  */
572
+ public function getSplit()
573
  {
574
  switch ($this->_getCountryCode()) {
575
  case 'DE':
581
  }
582
  }
583
 
584
+ /**
585
  * Is the sum below the limit allowed for the given _country?
586
  * This contains a hardcoded value for NL.
587
  * Meaning, if a customer shops for over 250 EUR, it won't be allowed to use any part payment option...
640
  return true;
641
  }
642
  }
643
+
644
+ /**
645
+ * Do we need to display the autofill warning label
646
+ *
647
+ * @return boolean
648
+ */
649
+ public function AllowSeparateAddress()
650
+ {
651
+ $res = false;
652
+ switch ($this->_getCountryCode()) {
653
+ case 'GB':
654
+ case 'DE':
655
+ $res = true;
656
+ break;
657
+ }
658
+ switch ($this->getConfigData("allow_separate_address")) {
659
+ case 0:
660
+ $res = false;
661
+ break;
662
+ case 1:
663
+ $res = true;
664
+ break;
665
+ }
666
+ return $res;
667
+ }
668
+
669
+
670
+ /**
671
+ * Do we need to display the autofill warning label
672
+ *
673
+ * @return boolean
674
+ */
675
+ public function shouldDisplayAutofillWarning()
676
+ {
677
+ switch ($this->_getCountryCode()) {
678
+ case 'DE':
679
+ $this->setMethod(Vaimo_Klarna_Helper_Data::KLARNA_METHOD_CHECKOUT);
680
+ return $this->getConfigData('active');
681
+ default:
682
+ return false;
683
+ }
684
+ }
685
 
686
  public function getAvailableMethods()
687
  {
688
  $res = array();
689
  $this->setMethod(Vaimo_Klarna_Helper_Data::KLARNA_METHOD_INVOICE);
690
+ if ($this->getConfigData('active')) {
691
  $res[] = $this->getMethod();
692
  }
693
  $this->setMethod(Vaimo_Klarna_Helper_Data::KLARNA_METHOD_ACCOUNT);
694
+ if ($this->getConfigData('active')) {
695
  $res[] = $this->getMethod();
696
  }
697
  $this->setMethod(Vaimo_Klarna_Helper_Data::KLARNA_METHOD_SPECIAL);
698
+ if ($this->getConfigData('active')) {
699
+ $res[] = $this->getMethod();
700
+ }
701
+ $this->setMethod(Vaimo_Klarna_Helper_Data::KLARNA_METHOD_CHECKOUT);
702
+ if ($this->getConfigData('active')) {
703
  $res[] = $this->getMethod();
704
  }
705
  return $res;
712
  */
713
  public function shippingSameAsBilling()
714
  {
715
+ if ($this->getConfigData('allow_separate_address')) {
716
  $res = false;
717
  } else {
718
  $res = true;
719
  }
 
 
 
 
 
 
 
 
 
 
 
720
  if (!$res) {
721
  if ($this->getQuote()) {
722
  $shipping = $this->getQuote()->isVirtual() ? null : $this->getQuote()->getShippingAddress();
736
  public function isCountryAllowed()
737
  {
738
  if ($this->_getCountryCode() != $this->_getDefaultCountry()) {
739
+ if ($this->getConfigData('allowspecific')) {
740
+ $allowedCountries = $this->getConfigData('specificcountry');
741
  if ($allowedCountries) {
742
  if (in_array($this->_getCountryCode(), explode(",", $allowedCountries))) {
743
  return true;
757
  */
758
  public function showMethodForCompanyPurchases()
759
  {
760
+ if ($this->getConfigData('disable_company_purchase')) {
761
  return false;
762
  }
763
  return true;
764
  }
765
 
766
+ /**
767
  * Function to read correct payment method setting
768
  *
769
  * @param string $field
770
  *
771
  * @return string
772
  */
773
+ public function getConfigData($field)
774
  {
775
  if ($this->getMethod() && $this->_getStoreId()!==NULL) {
776
+ $res = $this->_getConfigDataCall('payment/' . $this->getMethod() . '/' . $field, $this->_getStoreId());
777
  } else {
778
  $res = NULL;
779
  }
780
  return $res;
781
  }
782
 
783
+ /**
784
  * Returns this class country code
785
  *
786
  * @return string
790
  return $this->_countryCode;
791
  }
792
 
793
+ /**
794
  * Returns this class language code
795
  *
796
  * @return string
800
  return $this->_languageCode;
801
  }
802
 
803
+ /**
804
  * Returns this class currency code
805
  *
806
  * @return string
810
  return $this->_currencyCode;
811
  }
812
 
813
+ /**
814
  * Returns this class store id
815
  *
816
  * @return int
820
  return $this->_storeId;
821
  }
822
 
823
+ /**
824
  * Returns this class payment method
825
  *
826
  * @return string
831
  return $this->_method;
832
  }
833
 
834
+ /**
835
  * Returns the order set in this class
836
  *
837
  * @return Mage_Sales_Model_Order
842
  return $this->_order;
843
  }
844
 
845
+ /**
846
  * Returns the creditmemo set in this class
847
  *
848
  * @return Mage_Sales_Model_Order_Creditmemo
853
  return $this->_creditmemo;
854
  }
855
 
856
+ /**
857
  * Returns the invoice set in this class
858
  *
859
  * @return Mage_Sales_Model_Order_Invoice
864
  return $this->_invoice;
865
  }
866
 
867
+ /**
868
  * Returns the payment set in this class
869
  *
870
  * @return Mage_Sales_Model_Order_Payment
875
  return $this->_payment;
876
  }
877
 
878
+ /**
879
  * Returns the info instance set in this class
880
  *
881
  * @return Mage_Payment_Model_Info
886
  return $this->_info_instance;
887
  }
888
 
889
+ /**
890
  * Returns the quote set in this class
891
  *
892
  * @return Mage_Sales_Model_Quote
897
  return $this->_quote;
898
  }
899
 
900
+ /**
901
  * Returns the billing address set in this class
902
  *
903
  * @return Mage_Customer_Model_Address_Abstract
907
  return $this->_billingAddress;
908
  }
909
 
910
+ /**
911
  * Returns the shipping address set in this class
912
  *
913
  * @return Mage_Customer_Model_Address_Abstract
917
  return $this->_shippingAddress;
918
  }
919
 
920
+ /**
921
  * Returns the function name set by the constructors in this class
922
  *
923
  * @return string
927
  return $this->_functionName;
928
  }
929
 
930
+ protected function _formatPrice($price)
931
+ {
932
+ return Mage::app()->getStore($this->getQuote()->getStoreId())->formatPrice($price, false);
933
+ }
934
+
935
+ /**
936
  * Returns the current payment methods title, as set in Klarna Payment settings
937
  *
938
  * @return string
939
  */
940
+ public function getMethodTitleWithFee($fee = NULL)
941
  {
942
+ $res = $this->_getHelper()->__($this->getConfigData('title'));
943
  if ($this->getQuote() && $this->getMethod()==Vaimo_Klarna_Helper_Data::KLARNA_METHOD_INVOICE) {
 
944
  if ($fee) {
945
+ $res .= ' (' . $this->_formatPrice($fee) . ')';
946
  }
947
  }
948
  return $res;
949
  }
950
 
951
+ /**
 
 
 
 
 
 
 
 
 
 
952
  * A function that returns a few setup values unique to the current active session
953
  * If currently selected method is not setup it will default to Invoice method and try again
954
  * It uses recursion, but can only call itself once
955
  *
956
+ * Klarna checkout is different, if one places an order with KCO and then disables the option, it should
957
+ * still be possible to create the setup of it.
958
+ *
959
  * @return Varien_Object
960
  */
961
  public function getKlarnaSetup()
962
  {
963
  try {
964
+ if (!$this->getConfigData("active")) {
965
+ if ($this->getMethod()!=Vaimo_Klarna_Helper_Data::KLARNA_METHOD_CHECKOUT) {
966
+ Mage::throwException($this->_getHelper()->__('Current payment method not available'));
967
+ }
968
  }
969
  $res = new Varien_Object(
970
  array(
971
+ 'merchant_id' => $this->getConfigData("merchant_id"),
972
+ 'shared_secret' => $this->getConfigData("shared_secret"),
973
  'country_code' => $this->_getCountryCode(),
974
  'language_code' => $this->_getLanguageCode(),
975
  'locale_code' => $this->_getLanguageCode() . "_" . $this->_getCountryCode(),
976
  'currency_code' => $this->_getCurrencyCode(),
977
+ 'terms_url' => $this->getConfigData("terms_url"),
978
+ 'host' => $this->getConfigData("host"),
979
  )
980
  );
981
  } catch( Exception $e ) {
990
  return $res;
991
  }
992
 
993
+ /**
994
  * Log function that does the writing to log file
995
  *
996
  * @param string $filename What file to write to, will be placed in site/var/klarna/ folder
1000
  */
1001
  protected function _log($filename, $msg)
1002
  {
1003
+ Mage::log(getmypid() . ' ' . $msg, null, $filename, true);
1004
+ }
1005
+
1006
+ /**
1007
+ * Log function that does the writing to log file
1008
+ *
1009
+ * @param string $filename What file to write to, will be placed in site/var/klarna/ folder
1010
+ * @param string $msg Text to log
1011
+ *
1012
+ * @return void
1013
+ */
1014
+ protected function _logAlways($filename, $msg)
1015
+ {
1016
+ $logDir = Mage::getBaseDir('var') . DS . 'log' . DS;
1017
  $logFile = $logDir . $filename;
1018
 
1019
  try {
1034
  }
1035
  }
1036
 
1037
+ /**
1038
  * Log function that logs all Klarna API calls and replies, this to see what functions are called and what reply they get
1039
  *
1040
  * @param string $comment Text to log
1041
  *
1042
  * @return void
1043
  */
1044
+ public function logKlarnaApi($comment)
1045
  {
1046
+ $this->_log('klarnaapi.log', $comment);
1047
  }
1048
 
1049
+ /**
1050
  * Log function used for various debug log information, array is optional
1051
  *
1052
  * @param string $info Header of what is being logged
1054
  *
1055
  * @return void
1056
  */
1057
+ public function logDebugInfo($info, $arr = NULL)
1058
  {
1059
  if (!$arr) {
1060
+ $this->_log('klarnadebug.log', $info);
1061
  } else {
1062
+ if (is_array($arr)) {
1063
+ $this->_log('klarnadebug.log', print_r($arr, true));
1064
+ } elseif (is_object($arr)) {
1065
+ $this->_log('klarnadebug.log', print_r(array($arr), true));
1066
+ }
1067
  }
1068
  }
1069
 
1070
+ protected function _logMagentoException($e)
1071
+ {
1072
+ Mage::logException($e);
1073
+ }
1074
+
1075
+ /**
1076
  * If there is an exception, this log function should be used
1077
  * This is mainly meant for exceptions concerning klarna API calls, but can be used for any exception
1078
  *
1082
  */
1083
  public function logKlarnaException($e)
1084
  {
1085
+ $this->_logMagentoException($e);
1086
  $errstr = 'Exception:';
1087
  if ($e->getCode()) $errstr = $errstr . ' Code: ' . $e->getCode();
1088
+ if ($e->getMessage()) $errstr = $errstr . ' Message: ' . $e->getMessage(); // $this->_decode()
1089
  if ($e->getLine()) $errstr = $errstr . ' Row: ' . $e->getLine();
1090
  if ($e->getFile()) $errstr = $errstr . ' File: ' . $e->getFile();
1091
+ $this->_logAlways('klarnaerror.log', $errstr);
1092
  }
1093
 
1094
+ /**
1095
  * Creates the path to the Klarna logotype, it depends on payment method, intended placemen and your merchant id
1096
  *
1097
  * @param $width the width of the logotype
1104
  {
1105
  $res = "";
1106
  if (!$type) {
1107
+ $type = Vaimo_Klarna_Helper_Data::KLARNA_LOGOTYPE_TYPE_BASIC; // KLARNA_LOGOTYPE_TYPE_INVOICE;
1108
  switch ($this->getMethod()) {
1109
+ case Vaimo_Klarna_Helper_Data::KLARNA_METHOD_CHECKOUT:
1110
+ $type = Vaimo_Klarna_Helper_Data::KLARNA_LOGOTYPE_TYPE_BASIC;
1111
+ break;
1112
  case Vaimo_Klarna_Helper_Data::KLARNA_METHOD_ACCOUNT:
1113
+ $type = Vaimo_Klarna_Helper_Data::KLARNA_LOGOTYPE_TYPE_BASIC; // KLARNA_LOGOTYPE_TYPE_ACCOUNT;
1114
  break;
1115
  case Vaimo_Klarna_Helper_Data::KLARNA_METHOD_SPECIAL:
1116
+ if ($this->getConfigData('cdn_logotype_override')) {
1117
+ $res = $this->getConfigData('cdn_logotype_override');
1118
  $res .= '" width="' . $width; // Adding width to the file location like this is ugly, but works fine
1119
  return $res;
1120
  }
1121
+ $type = Vaimo_Klarna_Helper_Data::KLARNA_LOGOTYPE_TYPE_BASIC; // KLARNA_LOGOTYPE_TYPE_ACCOUNT;
1122
  break;
1123
  }
1124
  }
1125
+
1126
  switch ($position) {
1127
  case Vaimo_Klarna_Helper_Data::KLARNA_LOGOTYPE_POSITION_FRONTEND:
1128
  if ($type==Vaimo_Klarna_Helper_Data::KLARNA_LOGOTYPE_TYPE_BOTH) {
1129
+ $res = 'https://cdn.klarna.com/public/images/' . $this->_getCountryCode() . '/badges/v1/' . $type . '/' . $this->_getCountryCode() . '_' . $type . '_badge_banner_blue.png?width=' . $width . '&eid=' . $this->getConfigData('merchant_id');
1130
+ } elseif ($type==Vaimo_Klarna_Helper_Data::KLARNA_LOGOTYPE_TYPE_BASIC) {
1131
+ $res = 'https://cdn.klarna.com/1.0/shared/image/generic/logo/' . $this->_getLanguageCode() . "_" . strtolower($this->_getCountryCode()) . '/' . $type . '/blue-black.png?width=' . $width . '&eid=' . $this->getConfigData('merchant_id');
1132
+ // $res = 'https://cdn.klarna.com/public/images/' . $this->_getCountryCode() . '/logos/v1/' . $type . '/' . $this->_getCountryCode() . '_' . $type . '_logo_std_blue-black.png?width=' . $width . '&eid=' . $this->getConfigData('merchant_id');
1133
+ } elseif ($type==Vaimo_Klarna_Helper_Data::KLARNA_LOGOTYPE_TYPE_CHECKOUT) {
1134
+ $res = 'https://cdn.klarna.com/1.0/shared/image/generic/badge/' . $this->_getLanguageCode() . "_" . strtolower($this->_getCountryCode()) . '/checkout/short-blue.png?width=' . $width . '&eid=' . $this->getConfigData('merchant_id'); // ' . $type . '/
1135
  } else {
1136
+ $res = 'https://cdn.klarna.com/public/images/' . $this->_getCountryCode() . '/badges/v1/' . $type . '/' . $this->_getCountryCode() . '_' . $type . '_badge_std_blue.png?width=' . $width . '&eid=' . $this->getConfigData('merchant_id');
1137
  }
1138
  break;
1139
  case Vaimo_Klarna_Helper_Data::KLARNA_LOGOTYPE_POSITION_PRODUCT:
1140
+ $res = 'https://cdn.klarna.com/public/images/' . $this->_getCountryCode() . '/logos/v1/' . $type . '/' . $this->_getCountryCode() . '_' . $type . '_logo_std_blue-black.png?width=' . $width . '&eid=' . $this->getConfigData('merchant_id');
1141
  break;
1142
  case Vaimo_Klarna_Helper_Data::KLARNA_LOGOTYPE_POSITION_CHECKOUT:
1143
+ $res = 'https://cdn.klarna.com/public/images/' . $this->_getCountryCode() . '/badges/v1/' . $type . '/' . $this->_getCountryCode() . '_' . $type . '_badge_std_blue.png?width=' . $width . '&eid=' . $this->getConfigData('merchant_id');
1144
  break;
1145
  }
1146
  return $res;
app/code/community/Vaimo/Klarna/Tests/Model/Klarna/ApiTest.php DELETED
@@ -1,62 +0,0 @@
1
- <?php
2
- /**
3
- * Copyright (c) 2009-2014 Vaimo AB
4
- *
5
- * Vaimo reserves all rights in the Program as delivered. The Program
6
- * or any portion thereof may not be reproduced in any form whatsoever without
7
- * the written consent of Vaimo, except as provided by licence. A licence
8
- * under Vaimo's rights in the Program may be available directly from
9
- * Vaimo.
10
- *
11
- * Disclaimer:
12
- * THIS NOTICE MAY NOT BE REMOVED FROM THE PROGRAM BY ANY USER THEREOF.
13
- * THE PROGRAM IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
14
- * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
16
- * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
- * OUT OF OR IN CONNECTION WITH THE PROGRAM OR THE USE OR OTHER DEALINGS
19
- * IN THE PROGRAM.
20
- *
21
- * @category Vaimo
22
- * @package Vaimo_Klarna
23
- * @copyright Copyright (c) 2009-2014 Vaimo AB
24
- */
25
-
26
- class Vaimo_Klarna_Tests_Model_Klarna_ApiTest extends Vaimo_Klarna_Tests_TestCase
27
- {
28
- protected $klarnaApi;
29
-
30
- protected $api;
31
-
32
- public function setUp()
33
- {
34
- $this->klarnaApi = new Varien_Object();
35
- $this->api = new Vaimo_Klarna_Model_Klarna_Api($this->klarnaApi);
36
- }
37
-
38
- public function testSetPClassTypesShouldReturnKlarnaClassesForAccount()
39
- {
40
- $types = Vaimo_Klarna_Helper_Data::KLARNA_METHOD_ACCOUNT;
41
- $result = $this->api->setPClassTypes($types);
42
-
43
- $expected = array(KlarnaPClass::ACCOUNT,
44
- KlarnaPClass::CAMPAIGN,
45
- KlarnaPClass::FIXED
46
- );
47
-
48
- $this->assertEquals($expected, $result);
49
- }
50
-
51
- public function testSetPClassTypesShouldReturnKlarnaClassesForSpecial()
52
- {
53
- $types = Vaimo_Klarna_Helper_Data::KLARNA_METHOD_SPECIAL;
54
- $result = $this->api->setPClassTypes($types);
55
-
56
- $expected = array(KlarnaPClass::SPECIAL,
57
- KlarnaPClass::DELAY
58
- );
59
-
60
- $this->assertEquals($expected, $result);
61
- }
62
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/community/Vaimo/Klarna/Tests/Model/Klarna/ValidateTest.php DELETED
@@ -1,183 +0,0 @@
1
- <?php
2
- /**
3
- * Copyright (c) 2009-2014 Vaimo AB
4
- *
5
- * Vaimo reserves all rights in the Program as delivered. The Program
6
- * or any portion thereof may not be reproduced in any form whatsoever without
7
- * the written consent of Vaimo, except as provided by licence. A licence
8
- * under Vaimo's rights in the Program may be available directly from
9
- * Vaimo.
10
- *
11
- * Disclaimer:
12
- * THIS NOTICE MAY NOT BE REMOVED FROM THE PROGRAM BY ANY USER THEREOF.
13
- * THE PROGRAM IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
14
- * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
16
- * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
- * OUT OF OR IN CONNECTION WITH THE PROGRAM OR THE USE OR OTHER DEALINGS
19
- * IN THE PROGRAM.
20
- *
21
- * @category Vaimo
22
- * @package Vaimo_Klarna
23
- * @copyright Copyright (c) 2009-2014 Vaimo AB
24
- */
25
-
26
- class Vaimo_Klarna_Tests_Model_Klarna_ValidateTest extends Vaimo_Klarna_Tests_TestCase
27
- {
28
- public $additionalInformationCorrect = null;
29
- public $additionalInformationIncorrect = null;
30
- public $infoinstance = null;
31
-
32
- public function setUp()
33
- {
34
- //@todo: create mock function for getInfoInstance used in Vaimo_Klarna_Model_Klarna_Validate
35
- $this->infoinstance = new Varien_Object();
36
- $this->additionalInformationCorrect = array(
37
- 'consent' => 'consent',
38
- 'dob_day' => '01',
39
- 'dob_month' => '01',
40
- 'dob_year' => '01',
41
- 'phonenumber' => '032110325',
42
- 'pno' => '8303030303',
43
- 'gender' => '1',
44
- );
45
-
46
- $this->additionalInformationIncorrect = array(
47
- 'consent' => '',
48
- 'dob_day' => '00',
49
- 'dob_month' => '00',
50
- 'dob_year' => '00',
51
- 'phonenumber' => '',
52
- 'pno' => '',
53
- 'gender' => '',
54
- );
55
- }
56
-
57
- public function testCheckConsentShouldReturnTrue()
58
- {
59
- $this->infoinstance->setData('additional_information', $this->additionalInformationCorrect);
60
- $stub = $this->getMock('Vaimo_Klarna_Model_Klarna_Validate', array('getInfoInstance'));
61
- $stub->expects($this->any())
62
- ->method('getInfoInstance')
63
- ->will($this->returnValue($this->infoinstance));
64
-
65
- $expected = true;
66
- $this->assertEquals($expected, $stub->checkConsent());
67
- }
68
-
69
- public function testCheckConsentShouldReturnFalse()
70
- {
71
- $this->infoinstance->setData('additional_information', $this->additionalInformationIncorrect);
72
- $stub = $this->getMock('Vaimo_Klarna_Model_Klarna_Validate', array('getInfoInstance'));
73
- $stub->expects($this->any())
74
- ->method('getInfoInstance')
75
- ->will($this->returnValue($this->infoinstance));
76
-
77
- $expected = false;
78
- $this->assertEquals($expected, $stub->checkConsent);
79
- }
80
-
81
- public function testCheckDateOfBirthShouldReturnTrue(){
82
- $this->infoinstance->setData('additional_information', $this->additionalInformationCorrect);
83
-
84
- $stub = $this->getMock('Vaimo_Klarna_Model_Klarna_Validate', array('getInfoInstance'));
85
- $stub->expects($this->any())
86
- ->method('getInfoInstance')
87
- ->will($this->returnValue($this->infoinstance));
88
-
89
- $expected = true;
90
- $this->assertEquals($expected, $stub->checkDateOfBirth());
91
- }
92
-
93
- public function testCheckDateOfBirthShouldReturnFalse(){
94
- $this->infoinstance->setData('additional_information', $this->additionalInformationIncorrect);
95
-
96
- $stub = $this->getMock('Vaimo_Klarna_Model_Klarna_Validate', array('getInfoInstance'));
97
- $stub->expects($this->any())
98
- ->method('getInfoInstance')
99
- ->will($this->returnValue($this->infoinstance));
100
-
101
-
102
- $expected = false;
103
- $this->assertEquals($expected, $stub->checkDateOfBirth());
104
- }
105
-
106
- public function testCheckPnoShouldReturnTrue(){
107
- $this->infoinstance->setData('additional_information', $this->additionalInformationCorrect);
108
-
109
- $stub = $this->getMock('Vaimo_Klarna_Model_Klarna_Validate', array('getInfoInstance'));
110
- $stub->expects($this->any())
111
- ->method('getInfoInstance')
112
- ->will($this->returnValue($this->infoinstance));
113
-
114
-
115
- $expected = true;
116
- $this->assertEquals($expected, $stub->checkPno());
117
- }
118
-
119
- public function testCheckPnoShouldReturnFalse(){
120
- $this->infoinstance->setData('additional_information', $this->additionalInformationIncorrect);
121
-
122
- $stub = $this->getMock('Vaimo_Klarna_Model_Klarna_Validate', array('getInfoInstance'));
123
- $stub->expects($this->any())
124
- ->method('getInfoInstance')
125
- ->will($this->returnValue($this->infoinstance));
126
-
127
-
128
- $expected = false;
129
- $this->assertEquals($expected, $stub->checkPno());
130
- }
131
-
132
- public function testCheckPhoneShouldReturnTrue(){
133
- $this->infoinstance->setData('additional_information', $this->additionalInformationCorrect);
134
-
135
- $stub = $this->getMock('Vaimo_Klarna_Model_Klarna_Validate', array('getInfoInstance'));
136
- $stub->expects($this->any())
137
- ->method('getInfoInstance')
138
- ->will($this->returnValue($this->infoinstance));
139
-
140
-
141
- $expected = true;
142
- $this->assertEquals($expected, $stub->checkPhone());
143
- }
144
-
145
- public function testCheckPhoneShouldReturnFalse(){
146
- $this->infoinstance->setData('additional_information', $this->additionalInformationIncorrect);
147
-
148
- $stub = $this->getMock('Vaimo_Klarna_Model_Klarna_Validate', array('getInfoInstance'));
149
- $stub->expects($this->any())
150
- ->method('getInfoInstance')
151
- ->will($this->returnValue($this->infoinstance));
152
-
153
-
154
- $expected = false;
155
- $this->assertEquals($expected, $stub->checkPhone());
156
- }
157
-
158
- public function testCheckGenderShouldReturnTrue(){
159
- $this->infoinstance->setData('additional_information', $this->additionalInformationCorrect);
160
-
161
- $stub = $this->getMock('Vaimo_Klarna_Model_Klarna_Validate', array('getInfoInstance'));
162
- $stub->expects($this->any())
163
- ->method('getInfoInstance')
164
- ->will($this->returnValue($this->infoinstance));
165
-
166
-
167
- $expected = true;
168
- $this->assertEquals($expected, $stub->checkGender());
169
- }
170
-
171
- public function testCheckGenderShouldReturnFalse(){
172
- $this->infoinstance->setData('additional_information', $this->additionalInformationIncorrect);
173
-
174
- $stub = $this->getMock('Vaimo_Klarna_Model_Klarna_Validate', array('getInfoInstance'));
175
- $stub->expects($this->any())
176
- ->method('getInfoInstance')
177
- ->will($this->returnValue($this->infoinstance));
178
-
179
-
180
- $expected = false;
181
- $this->assertEquals($expected, $stub->checkGender());
182
- }
183
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/community/Vaimo/Klarna/controllers/AddressController.php CHANGED
@@ -49,9 +49,9 @@ class Vaimo_Klarna_AddressController extends Mage_Core_Controller_Front_Action
49
  Mage::throwException(Mage::helper('klarna')->__('Please enter your personal ID and try again'));
50
  }
51
  $method = $request->getParam('method');
52
- $klarnaAddressSearch = Mage::getModel('klarna/klarna_addresssearch');
53
- $klarnaAddressSearch->setQuote($this->_getQuote(), $method);
54
- $addresses = $klarnaAddressSearch->getAddresses($pno);
55
 
56
  $block = Mage::getSingleton('core/layout')
57
  ->createBlock('klarna/form_address_search');
49
  Mage::throwException(Mage::helper('klarna')->__('Please enter your personal ID and try again'));
50
  }
51
  $method = $request->getParam('method');
52
+ $klarna = Mage::getModel('klarna/klarna');
53
+ $klarna->setQuote($this->_getQuote(), $method);
54
+ $addresses = $klarna->getAddresses($pno);
55
 
56
  $block = Mage::getSingleton('core/layout')
57
  ->createBlock('klarna/form_address_search');
app/code/community/Vaimo/Klarna/controllers/Adminhtml/Klarna/PclassController.php CHANGED
@@ -35,10 +35,10 @@ class Vaimo_Klarna_Adminhtml_Klarna_PclassController extends Mage_Adminhtml_Cont
35
  try {
36
  $request = $this->getRequest();
37
 
38
- $klarnaPClass = Mage::getModel('klarna/klarna_pclass');
39
- $klarnaPClass->setMethod(Vaimo_Klarna_Helper_Data::KLARNA_METHOD_ACCOUNT);
40
- $klarnaPClass->setStoreInformation(NULL);
41
- $klarnaPClass->reloadAllPClasses();
42
 
43
  $block = Mage::getSingleton('core/layout')
44
  ->createBlock('klarna/adminhtml_pclass_list');;
35
  try {
36
  $request = $this->getRequest();
37
 
38
+ $klarna = Mage::getModel('klarna/klarna');
39
+ $klarna->setStoreInformation();
40
+ $klarna->setMethod(Vaimo_Klarna_Helper_Data::KLARNA_METHOD_ACCOUNT);
41
+ $klarna->reloadAllPClasses();
42
 
43
  $block = Mage::getSingleton('core/layout')
44
  ->createBlock('klarna/adminhtml_pclass_list');;
app/code/community/Vaimo/Klarna/controllers/Checkout/KlarnaController.php ADDED
@@ -0,0 +1,671 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Copyright (c) 2009-2014 Vaimo AB
4
+ *
5
+ * Vaimo reserves all rights in the Program as delivered. The Program
6
+ * or any portion thereof may not be reproduced in any form whatsoever without
7
+ * the written consent of Vaimo, except as provided by licence. A licence
8
+ * under Vaimo's rights in the Program may be available directly from
9
+ * Vaimo.
10
+ *
11
+ * Disclaimer:
12
+ * THIS NOTICE MAY NOT BE REMOVED FROM THE PROGRAM BY ANY USER THEREOF.
13
+ * THE PROGRAM IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
14
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
16
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ * OUT OF OR IN CONNECTION WITH THE PROGRAM OR THE USE OR OTHER DEALINGS
19
+ * IN THE PROGRAM.
20
+ *
21
+ * @category Vaimo
22
+ * @package Vaimo_Klarna
23
+ * @copyright Copyright (c) 2009-2014 Vaimo AB
24
+ */
25
+
26
+ class Vaimo_Klarna_Checkout_KlarnaController extends Mage_Core_Controller_Front_Action
27
+ {
28
+ protected function _log($message)
29
+ {
30
+ Mage::log(getmypid() . ' ' . $message, null, 'klarnacheckout.log', true);
31
+ }
32
+
33
+ /**
34
+ * @return Mage_Checkout_Model_Session
35
+ */
36
+ protected function _getSession()
37
+ {
38
+ return Mage::getSingleton('checkout/session');
39
+ }
40
+ /**
41
+ * Retrieve shopping cart model object
42
+ *
43
+ * @return Mage_Checkout_Model_Cart
44
+ */
45
+ protected function _getCart()
46
+ {
47
+ return Mage::getSingleton('checkout/cart');
48
+ }
49
+
50
+ /**
51
+ * Get current active quote instance
52
+ *
53
+ * @return Mage_Sales_Model_Quote
54
+ */
55
+ protected function _getQuote()
56
+ {
57
+ return $this->_getCart()->getQuote();
58
+ }
59
+
60
+ protected function _checkPaymentMethod()
61
+ {
62
+ // set payment method
63
+ $quote = $this->_getQuote();
64
+
65
+ if ($quote->getPayment()->getMethod() != Vaimo_Klarna_Helper_Data::KLARNA_METHOD_CHECKOUT) {
66
+ if ($quote->isVirtual()) {
67
+ $quote->getBillingAddress()->setPaymentMethod(Vaimo_Klarna_Helper_Data::KLARNA_METHOD_CHECKOUT);
68
+ } else {
69
+ $quote->getShippingAddress()->setPaymentMethod(Vaimo_Klarna_Helper_Data::KLARNA_METHOD_CHECKOUT);
70
+ }
71
+ $quote->getPayment()->setMethod(Vaimo_Klarna_Helper_Data::KLARNA_METHOD_CHECKOUT);
72
+ $quote->save();
73
+ }
74
+
75
+ return $this;
76
+ }
77
+
78
+ protected function _checkShippingMethod()
79
+ {
80
+ // set shipping method
81
+ $quote = $this->_getQuote();
82
+ $shippingAddress = $quote->getShippingAddress();
83
+ if (!$shippingAddress->getShippingMethod()) {
84
+ $quote->setRemoteIp($quote->getRemoteIp());
85
+ if (version_compare(Mage::getVersion(), '1.6.2', '>=')) {
86
+ $countryId = Mage::helper('core')->getDefaultCountry();
87
+ } else {
88
+ $countryId = Mage::getStoreConfig('general/country/default');
89
+ }
90
+ $shippingAddress->setCountryId($countryId);
91
+ $shippingAddress->setCollectShippingRates(true);
92
+ $shippingAddress->collectShippingRates();
93
+ $rates = $shippingAddress->getGroupedAllShippingRates();
94
+ foreach ($rates as $carrierRates) {
95
+ foreach ($carrierRates as $rate) {
96
+ $shippingAddress->setShippingMethod($rate->getCode());
97
+ $quote->setTotalsCollectedFlag(false);
98
+ $quote->collectTotals();
99
+ $quote->save();
100
+ break;
101
+ }
102
+ break;
103
+ }
104
+ }
105
+
106
+ return $this;
107
+ }
108
+
109
+ protected function _checkNewsletter()
110
+ {
111
+ $quote = $this->_getQuote();
112
+ $klarna = Mage::getModel('klarna/klarnacheckout');
113
+ $klarna->setQuote($quote, Vaimo_Klarna_Helper_Data::KLARNA_METHOD_CHECKOUT);
114
+ $klarna->CheckNewsletter();
115
+ return $this;
116
+ }
117
+
118
+ public function othermethodAction()
119
+ {
120
+ $quote = $this->_getQuote();
121
+ // @todo find active method, not just Invoice automatically
122
+ $quote->getPayment()->setMethod(Vaimo_Klarna_Helper_Data::KLARNA_METHOD_INVOICE);
123
+ $quote->setTotalsCollectedFlag(false);
124
+ $quote->collectTotals();
125
+ $quote->save();
126
+ $this->_getSession()->setUseOtherMethods(true);
127
+ if (Mage::helper('klarna')->isOneStepCheckout()) {
128
+ $this->_redirect('onestepcheckout');
129
+ } else {
130
+ $this->_redirect('checkout/onepage');
131
+ }
132
+ }
133
+
134
+ public function kcomethodAction()
135
+ {
136
+ $quote = $this->_getQuote();
137
+ $quote->getPayment()->setMethod(Vaimo_Klarna_Helper_Data::KLARNA_METHOD_CHECKOUT);
138
+ $quote->setTotalsCollectedFlag(false);
139
+ $quote->collectTotals();
140
+ $quote->save();
141
+ $this->_getSession()->setUseOtherMethods(false);
142
+ if (Mage::helper('klarna')->isOneStepCheckout()) {
143
+ $this->_redirect('onestepcheckout');
144
+ } else {
145
+ $this->_redirect('checkout/onepage');
146
+ }
147
+ }
148
+
149
+ public function indexAction()
150
+ {
151
+ $quote = $this->_getQuote();
152
+ $klarna = Mage::getModel('klarna/klarnacheckout');
153
+ $klarna->setQuote($quote, Vaimo_Klarna_Helper_Data::KLARNA_METHOD_CHECKOUT);
154
+ if (!$klarna->getKlarnaCheckoutEnabled()) {
155
+ if (Mage::helper('klarna')->isOneStepCheckout()) {
156
+ $this->_redirect('onestepcheckout');
157
+ } else {
158
+ $this->_redirect('checkout/onepage');
159
+ }
160
+ return;
161
+ }
162
+
163
+ $quote = $this->_getQuote();
164
+
165
+ if (!$quote->hasItems() || $quote->getHasError()) {
166
+ $this->_redirect('checkout/cart');
167
+ return;
168
+ }
169
+
170
+ if (!$quote->validateMinimumAmount()) {
171
+ $error = Mage::getStoreConfig('sales/minimum_order/error_message') ?
172
+ Mage::getStoreConfig('sales/minimum_order/error_message') :
173
+ Mage::helper('checkout')->__('Subtotal must exceed minimum order amount');
174
+
175
+ $this->_getSession()->addError($error);
176
+ $this->_redirect('checkout/cart');
177
+ return;
178
+ }
179
+
180
+ $this->_checkPaymentMethod();
181
+ $this->_checkShippingMethod();
182
+ $this->_checkNewsletter();
183
+
184
+ $this->loadLayout();
185
+ $this->_initLayoutMessages('customer/session');
186
+ $this->getLayout()->getBlock('head')->setTitle($this->__('Klarna Checkout'));
187
+ $this->renderLayout();
188
+ }
189
+
190
+ public function subscribeToNewsletterAction()
191
+ {
192
+ $quote = $this->_getQuote();
193
+ $subscribe = $this->getRequest()->getParam('subscribe_to_newsletter');
194
+ $quote->setKlarnaCheckoutNewsletter($subscribe);
195
+ $quote->save();
196
+ }
197
+
198
+ public function validateAction()
199
+ {
200
+ $checkoutId = $this->getRequest()->getParam('klarna_order');
201
+ $quote = Mage::getModel('sales/quote')->load($checkoutId, 'klarna_checkout_id');
202
+ $klarna = Mage::getModel('klarna/klarnacheckout');
203
+ $klarna->setQuote($quote, Vaimo_Klarna_Helper_Data::KLARNA_METHOD_CHECKOUT);
204
+
205
+ if (substr($checkoutId, -1, 1) == '/') {
206
+ $checkoutId = substr($checkoutId, 0, strlen($checkoutId) - 1);
207
+ }
208
+ $klarna->logKlarnaApi('validateAction checkout id: ' . $checkoutId);
209
+
210
+ $result = $klarna->validateQuote($checkoutId);
211
+ $klarna->logKlarnaApi('validateAction result = ' . $result);
212
+
213
+ if ($result !== true) {
214
+ $this->getResponse()
215
+ ->setHttpResponseCode(303)
216
+ ->setHeader('Location', Mage::getUrl('checkout/cart'));
217
+ }
218
+ }
219
+
220
+ public function pushAction()
221
+ {
222
+ $checkoutId = $this->getRequest()->getParam('klarna_order');
223
+ $quote = Mage::getModel('sales/quote')->load($checkoutId, 'klarna_checkout_id');
224
+
225
+ /** @var Vaimo_Klarna_Model_Klarnacheckout $klarna */
226
+ $klarna = Mage::getModel('klarna/klarnacheckout');
227
+ $klarna->setQuote($quote, Vaimo_Klarna_Helper_Data::KLARNA_METHOD_CHECKOUT);
228
+ if (substr($checkoutId, -1, 1) == '/') {
229
+ $checkoutId = substr($checkoutId, 0, strlen($checkoutId) - 1);
230
+ }
231
+ $klarna->logKlarnaApi('pushAction checkout id: ' . $checkoutId);
232
+ if (!$quote->getId()) {
233
+ $klarna->logKlarnaApi('pushAction checkout quote not found!');
234
+ }
235
+
236
+ if ($checkoutId) {
237
+ try {
238
+ // createOrder returns the order if successful, otherwise an error string
239
+ $result = $klarna->createOrder($checkoutId);
240
+
241
+ if (is_object($result)) {
242
+ $klarna->logKlarnaApi('pushAction order created successfully, order id: ' . $result->getId());
243
+ } else {
244
+ $klarna->logKlarnaApi($result);
245
+ }
246
+ } catch (Exception $e) {
247
+ $klarna->logKlarnaException($e);
248
+ }
249
+ }
250
+ }
251
+
252
+ public function successAction()
253
+ {
254
+ try {
255
+ $checkoutId = $this->_getSession()->getKlarnaCheckoutId();
256
+ $quote = Mage::getModel('sales/quote')->load($checkoutId, 'klarna_checkout_id');
257
+ $klarna = Mage::getModel('klarna/klarnacheckout');
258
+ $klarna->setQuote($quote, Vaimo_Klarna_Helper_Data::KLARNA_METHOD_CHECKOUT);
259
+ $klarna->logKlarnaApi('successAction checkout id: ' . $checkoutId);
260
+
261
+ if (!$checkoutId) {
262
+ $this->_redirect('');
263
+ return;
264
+ }
265
+
266
+ $status = $klarna->getCheckoutStatus($checkoutId);
267
+ $canDisplaySuccess = $status == 'checkout_complete' || $status == 'created';
268
+
269
+ if (!$canDisplaySuccess) {
270
+ $klarna->logKlarnaApi('successAction ERROR: order not created: ' . $status);
271
+ $this->_redirect('');
272
+ return;
273
+ } else {
274
+ $klarna->logKlarnaApi('successAction displaying success');
275
+ }
276
+
277
+ // close the quote if push hasn't closed it already
278
+ $quote = $this->_getQuote();
279
+ if ($quote->getId() && $quote->getIsActive()) {
280
+ $klarna->logKlarnaApi('successAction closing quote');
281
+ /** @var Mage_Core_Model_Resource $resource */
282
+ $resource = Mage::getSingleton('core/resource');
283
+ $read = $resource->getConnection('core_read');
284
+ $read->update($resource->getTableName('sales/quote'), array('is_active' => 0), 'entity_id = ' . $quote->getId());
285
+ }
286
+
287
+ $this->_getSession()->setLastQuoteId($quote->getId());
288
+ $this->_getSession()->clearHelperData();
289
+ $this->_getSession()->clear();
290
+ $this->_getCart()->unsetData('quote');
291
+
292
+ $this->loadLayout();
293
+ $this->_initLayoutMessages('customer/session');
294
+ $this->getLayout()->getBlock('head')->setTitle($this->__('Klarna Checkout'));
295
+
296
+ // This is KCO specific for the current API... This must find another solution
297
+ if ($block = Mage::app()->getFrontController()->getAction()->getLayout()->getBlock('google_analytics')) {
298
+ $block->setKlarnaCheckoutOrder($klarna->getActualKlarnaOrder());
299
+ }
300
+
301
+ $this->renderLayout();
302
+
303
+ $this->_getSession()->setKlarnaCheckoutId('');
304
+ $klarna->logKlarnaApi('successAction displayed success');
305
+ } catch (Exception $e) {
306
+ $klarna->logKlarnaException($e);
307
+ }
308
+ }
309
+
310
+ public function saveShippingMethodAction()
311
+ {
312
+ $resultMessage = array();
313
+
314
+ if ($this->getRequest()->isPost()) {
315
+ $data = $this->getRequest()->getPost('shipping_method', '');
316
+ $resultMessage['shipping_method'] = $data;
317
+
318
+ /** @var $onepage Mage_Checkout_Model_Type_Onepage */
319
+ $onepage = new Mage_Checkout_Model_Type_Onepage(); // Mage::getSingleton('checkout/type_onepage');
320
+ try {
321
+ $result = $onepage->saveShippingMethod($data);
322
+ if (!$result) {
323
+ Mage::dispatchEvent(
324
+ 'klarnacheckout_controller_klarna_save_shipping_method',
325
+ array(
326
+ 'request' => $this->getRequest(),
327
+ 'quote' => $onepage->getQuote()));
328
+ $onepage->getQuote()->collectTotals()->save();
329
+ }
330
+ }
331
+ catch (Exception $e) {
332
+ $resultMessage['error'] = $e->getMessage();
333
+ }
334
+
335
+ $resultMessage['success'] = 'Shipping method successfully saved';
336
+ }
337
+
338
+ if ($this->getRequest()->isXmlHttpRequest()) {
339
+ $this->getResponse()->setBody(Zend_Json::encode($resultMessage));
340
+ } else {
341
+ $this->_redirect('checkout/klarna');
342
+ }
343
+ }
344
+
345
+ public function addGiftCardAction()
346
+ {
347
+ $resultMessage = array();
348
+ $data = $this->getRequest()->getPost();
349
+ if (isset($data['giftcard_code'])) {
350
+ $code = $data['giftcard_code'];
351
+ try {
352
+ Mage::getModel('enterprise_giftcardaccount/giftcardaccount')
353
+ ->loadByCode($code)
354
+ ->addToCart(false);
355
+
356
+ $quote = $this->_getQuote();
357
+ $quote->collectTotals();
358
+ $quote->save();
359
+
360
+ $this->_getSession()->addSuccess(
361
+ $this->__('Gift Card "%s" was added.', Mage::helper('core')->htmlEscape($code))
362
+ );
363
+ $resultMessage['success'] = $this->__('Gift Card "%s" was added.', Mage::helper('core')->htmlEscape($code));
364
+ } catch (Mage_Core_Exception $e) {
365
+ Mage::dispatchEvent('enterprise_giftcardaccount_add', array('status' => 'fail', 'code' => $code));
366
+ $this->_getSession()->addError(
367
+ $e->getMessage()
368
+ );
369
+ $resultMessage['error'] = $e->getMessage();
370
+ } catch (Exception $e) {
371
+ $this->_getSession()->addException($e, $this->__('Cannot apply gift card.'));
372
+ $resultMessage['error'] = $this->__('Cannot apply gift card.');
373
+ }
374
+ }
375
+
376
+ $this->_checkShippingMethod();
377
+
378
+ if ($this->getRequest()->isXmlHttpRequest()) {
379
+ $this->getResponse()->setBody(Zend_Json::encode($resultMessage));
380
+ } else {
381
+ $this->_redirect('checkout/klarna');
382
+ }
383
+ }
384
+
385
+ public function removeGiftCardAction()
386
+ {
387
+ $resultMessage = array();
388
+ if ($code = $this->getRequest()->getParam('code')) {
389
+ try {
390
+ Mage::getModel('enterprise_giftcardaccount/giftcardaccount')
391
+ ->loadByCode($code)
392
+ ->removeFromCart(false);
393
+
394
+ $quote = $this->_getQuote();
395
+ $quote->collectTotals();
396
+ $quote->save();
397
+
398
+ $this->_getSession()->addSuccess(
399
+ $this->__('Gift Card "%s" was removed.', Mage::helper('core')->htmlEscape($code))
400
+ );
401
+ $resultMessage['success'] = $this->__('Gift Card "%s" was removed.', Mage::helper('core')->htmlEscape($code));
402
+ } catch (Mage_Core_Exception $e) {
403
+ $this->_getSession()->addError(
404
+ $e->getMessage()
405
+ );
406
+ $resultMessage['error'] = $e->getMessage();
407
+ } catch (Exception $e) {
408
+ $this->_getSession()->addException($e, $this->__('Cannot remove gift card.'));
409
+ $resultMessage['error'] = $this->__('Cannot remove gift card.');
410
+ }
411
+ }
412
+
413
+ $this->_checkShippingMethod();
414
+
415
+ if ($this->getRequest()->isXmlHttpRequest()) {
416
+ $this->getResponse()->setBody(Zend_Json::encode($resultMessage));
417
+ } else {
418
+ $this->_redirect('checkout/klarna');
419
+ }
420
+ }
421
+
422
+ public function getKlarnaWrapperHtmlAction()
423
+ {
424
+ $this->loadLayout('checkout_klarna_index');
425
+
426
+ $block = $this->getLayout()->getBlock('klarna_wrapper');
427
+ $cartHtml = $block->toHtml();
428
+
429
+ $result['update_sections'] = array(
430
+ 'name' => 'klarna_wrapper',
431
+ 'html' => $cartHtml
432
+ );
433
+
434
+ $this->getResponse()->setBody(Zend_Json::encode($result));
435
+ }
436
+
437
+ public function getKlarnaCheckoutAction()
438
+ {
439
+ $this->loadLayout('checkout_klarna_index');
440
+
441
+ $block = $this->getLayout()->getBlock('checkout');
442
+ $klarnaCheckoutHtml = $block->toHtml();
443
+
444
+ $result['update_sections'] = array(
445
+ 'name' => 'klarna_checkout',
446
+ 'html' => $klarnaCheckoutHtml
447
+ );
448
+
449
+ $this->getResponse()->setBody(Zend_Json::encode($result));
450
+ }
451
+
452
+ /**
453
+ * Copy of _updateShoppingCart in Mage_Checkout_CartController but with ajax response and
454
+ * functionality to work on checkout page. (Tried to keep as standard as possible)
455
+ */
456
+ public function cartUpdatePostAction()
457
+ {
458
+ $result = array();
459
+
460
+ try {
461
+ $cartData = $this->getRequest()->getParam('cart');
462
+ if (is_array($cartData)) {
463
+ $filter = new Zend_Filter_LocalizedToNormalized(
464
+ array('locale' => Mage::app()->getLocale()->getLocaleCode())
465
+ );
466
+ foreach ($cartData as $index => $data) {
467
+ if (isset($data['qty'])) {
468
+ $cartData[$index]['qty'] = $filter->filter(trim($data['qty']));
469
+ }
470
+ }
471
+ $cart = $this->_getCart();
472
+ if (! $cart->getCustomerSession()->getCustomer()->getId() && $cart->getQuote()->getCustomerId()) {
473
+ $cart->getQuote()->setCustomerId(null);
474
+ }
475
+ $cartData = $cart->suggestItemsQty($cartData);
476
+ $cart->updateItems($cartData);
477
+
478
+ // Addon to check qty vs stock to support ajax response
479
+ $items = $cart->getQuote()->getItemsCollection();
480
+
481
+ foreach ($items as $item) {
482
+ $item->checkData();
483
+ }
484
+ $errors = $cart->getQuote()->getErrors();
485
+ $messages = array();
486
+
487
+ foreach ($errors as $error) {
488
+ $messages[] = $error->getCode();
489
+ }
490
+
491
+ if (count($messages) > 0) {
492
+ Mage::throwException(implode(', ', $messages));
493
+ }
494
+
495
+ $cart->save();
496
+
497
+ // Addon for ajax to redirect to cart
498
+ if ($this->_getCart()->getSummaryQty() <= 0) {
499
+ $result['redirect_url'] = Mage::getUrl('checkout/cart');
500
+ }
501
+ }
502
+ $this->_getSession()->setCartWasUpdated(true);
503
+ $result['success'] = $this->__('Shopping cart updated successfully.');
504
+
505
+ } catch (Mage_Core_Exception $e) {
506
+ $result['error'] = Mage::helper('core')->escapeHtml($e->getMessage());
507
+ } catch (Exception $e) {
508
+ $result['error'] = Mage::helper('core')->escapeHtml($e->getMessage());
509
+ Mage::logException($e);
510
+ }
511
+
512
+ $this->_checkShippingMethod();
513
+ $this->getResponse()->setBody(Zend_Json::encode($result));
514
+ }
515
+
516
+ public function couponPostAction()
517
+ {
518
+ $result = array();
519
+
520
+ try {
521
+ $couponCode = (string)trim($this->getRequest()->getParam('coupon_code'));
522
+ $gc = (string)trim($this->getRequest()->getParam('gc'));
523
+
524
+ // Remove GC
525
+ if (isset($gc) && $gc != '') {
526
+ $gcs = $this->_getQuote()->getGiftcertCode();
527
+
528
+ if (!$gc || !$gcs || strpos($gcs, $gc) === false) {
529
+ Mage::throwException('Invalid request.');
530
+ }
531
+
532
+ $gcsArr = array();
533
+
534
+ foreach (explode(',', $gcs) as $gc1) {
535
+ if (trim($gc1) !== $gc) {
536
+ $gcsArr[] = $gc1;
537
+ }
538
+ }
539
+
540
+ $this->_getQuote()->setGiftcertCode(join(',', $gcsArr))->save();
541
+ $result['success'] = $this->__("Gift certificate was removed from your order.");
542
+ } else {
543
+ $isGiftcertActive = Mage::helper('core')->isModuleEnabled('Unirgy_Giftcert') || Mage::helper('core')->isModuleEnabled('Icommerce_Giftcert');
544
+
545
+ if ($isGiftcertActive) {
546
+ $cert = Mage::getModel('ugiftcert/cert')->load($couponCode, 'cert_number');
547
+ } else {
548
+ $cert = new Varien_Object();
549
+ }
550
+
551
+ // If giftcert, add giftcert
552
+ if ($isGiftcertActive && $cert->getId() && $cert->getStatus() == 'A' && $cert->getBalance() > 0) {
553
+ $helper = Mage::helper('ugiftcert');
554
+ try {
555
+ $quote = $this->_getQuote();
556
+ if (Mage::getStoreConfig('ugiftcert/default/use_conditions')) {
557
+ $valid = $this->_validateConditions($cert, $quote);
558
+ if (!$valid) {
559
+ $result['error'] = $helper->__("Gift certificate '%s' cannot be used with your cart items", $cert->getCertNumber());
560
+ }
561
+ }
562
+ $cert->addToQuote($quote);
563
+ $quote->collectTotals()->save();
564
+ $result['success'] = $helper->__("Gift certificate '%s' was applied to your order.", $cert->getCertNumber());
565
+ } catch (Exception $e) {
566
+ $result['error'] = $helper->__("Gift certificate '%s' could not be applied to your order.", $cert->getCertNumber());
567
+ }
568
+ } else {
569
+ // Just plain coupon code
570
+ if ($this->getRequest()->getParam('remove') == 1) {
571
+ $couponCode = '';
572
+ }
573
+ $oldCouponCode = $this->_getQuote()->getCouponCode();
574
+
575
+ if (!strlen($couponCode) && !strlen($oldCouponCode)) {
576
+ throw new Exception($this->__('No coupon code was submitted.'));
577
+ }
578
+
579
+ $this->_getQuote()->getShippingAddress()->setCollectShippingRates(true);
580
+ $this->_getQuote()->setCouponCode(strlen($couponCode) ? $couponCode : '')
581
+ ->collectTotals()
582
+ ->save();
583
+
584
+ if ($couponCode) {
585
+ if ($couponCode == $this->_getQuote()->getCouponCode()) {
586
+ $result['success'] = $this->__('Coupon code "%s" was applied.', Mage::helper('core')->htmlEscape($couponCode));
587
+ } else {
588
+ $result['error'] = $this->__('Coupon code "%s" is not valid.', Mage::helper('core')->htmlEscape($couponCode));
589
+ }
590
+ } else {
591
+ $result['success'] = $this->__('Coupon code was canceled successfully.');
592
+ }
593
+ }
594
+ }
595
+ } catch (Mage_Core_Exception $e) {
596
+ $result['error'] = $e->getMessage();
597
+ } catch (Exception $e) {
598
+ $result['error'] = $e->getMessage();
599
+ }
600
+
601
+ $this->_checkShippingMethod();
602
+ $this->getResponse()->setBody(Zend_Json::encode($result));
603
+ }
604
+
605
+ public function rewardPostAction()
606
+ {
607
+ $useRewardPoints = $this->getRequest()->getParam('use_reward_points');
608
+ $result = array();
609
+
610
+ $quote = $this->_getQuote();
611
+ $quote->setUseRewardPoints((bool)$useRewardPoints);
612
+
613
+ if ($quote->getUseRewardPoints()) {
614
+ /* @var $reward Enterprise_Reward_Model_Reward */
615
+ $reward = Mage::getModel('enterprise_reward/reward')
616
+ ->setCustomer($quote->getCustomer())
617
+ ->setWebsiteId($quote->getStore()->getWebsiteId())
618
+ ->loadByCustomer();
619
+
620
+ $minPointsBalance = (int)Mage::getStoreConfig(
621
+ Enterprise_Reward_Model_Reward::XML_PATH_MIN_POINTS_BALANCE,
622
+ $quote->getStoreId()
623
+ );
624
+
625
+ if ($reward->getId() && $reward->getPointsBalance() >= $minPointsBalance) {
626
+ $quote->setRewardInstance($reward);
627
+ $quote->collectTotals();
628
+ $quote->save();
629
+ $result['success'] = $this->__('Reward points used');
630
+ } else {
631
+ $quote->setUseRewardPoints(false)->collectTotals()->save();
632
+ $result['success'] = $this->__('Reward points unused');
633
+ }
634
+ } else {
635
+ $quote->setUseRewardPoints(false)->collectTotals()->save();
636
+ $result['success'] = $this->__('Reward points unused');
637
+ }
638
+
639
+ $this->_checkShippingMethod();
640
+ $this->getResponse()->setBody(Zend_Json::encode($result));
641
+ }
642
+
643
+ public function customerBalancePostAction()
644
+ {
645
+ $shouldUseBalance = $this->getRequest()->getParam('use_customer_balance', false);
646
+ $result = array();
647
+
648
+ $quote = $this->_getQuote();
649
+ $quote->setUseCustomerBalance($shouldUseBalance);
650
+
651
+ if ($shouldUseBalance) {
652
+ $store = Mage::app()->getStore($quote->getStoreId());
653
+ $balance = Mage::getModel('enterprise_customerbalance/balance')
654
+ ->setCustomerId($quote->getCustomerId())
655
+ ->setWebsiteId($store->getWebsiteId())
656
+ ->loadByCustomer();
657
+ if ($balance) {
658
+ $quote->setCustomerBalanceInstance($balance);
659
+ $result['success'] = $this->__('Store credit used');
660
+ } else {
661
+ $quote->setUseCustomerBalance(false);
662
+ $result['success'] = $this->__('Store credit unused');
663
+ }
664
+ } else {
665
+ $result['success'] = $this->__('Store credit unused');
666
+ }
667
+
668
+ $quote->collectTotals()->save();
669
+ $this->getResponse()->setBody(Zend_Json::encode($result));
670
+ }
671
+ }
app/code/community/Vaimo/Klarna/controllers/PaymentplanController.php CHANGED
@@ -47,9 +47,9 @@ class Vaimo_Klarna_PaymentplanController extends Mage_Core_Controller_Front_Acti
47
  $plan = $request->getParam('payment_plan');
48
  $method = $request->getParam('method');
49
  $storeId = $request->getParam('store_id');
50
- $klarnaPClass = Mage::getModel('klarna/klarna_pclass');
51
- $klarnaPClass->setQuote($this->_getQuote(), $method);
52
- $details = $klarnaPClass->getPClassDetails($plan);
53
 
54
  $block = Mage::getSingleton('core/layout')
55
  ->createBlock('klarna/form_paymentplan_information');
47
  $plan = $request->getParam('payment_plan');
48
  $method = $request->getParam('method');
49
  $storeId = $request->getParam('store_id');
50
+ $klarna = Mage::getModel('klarna/klarna');
51
+ $klarna->setQuote($this->_getQuote(), $method);
52
+ $details = $klarna->getPClassDetails($plan);
53
 
54
  $block = Mage::getSingleton('core/layout')
55
  ->createBlock('klarna/form_paymentplan_information');
app/code/community/Vaimo/Klarna/etc/config.xml CHANGED
@@ -25,7 +25,7 @@
25
  --><config>
26
  <modules>
27
  <Vaimo_Klarna>
28
- <version>5.1.6</version>
29
  <name>Vaimo Klarna Module</name>
30
  <depends>
31
  <Mage_Payment/>
@@ -72,7 +72,27 @@
72
  </connection>
73
  </klarna_read>
74
  </resources>
75
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
76
  <sales>
77
  <quote>
78
  <totals>
@@ -132,8 +152,11 @@
132
  </totals>
133
  </pdf>
134
  </global>
135
-
136
  <frontend>
 
 
 
137
  <layout>
138
  <updates>
139
  <klarna module="klarna">
@@ -149,14 +172,21 @@
149
  <frontName>klarna</frontName>
150
  </args>
151
  </klarna>
 
 
 
 
 
 
 
152
  </routers>
153
  <translate>
154
  <modules>
155
- <klarna>
156
  <files>
157
  <default>Vaimo_Klarna.csv</default>
158
  </files>
159
- </klarna>
160
  </modules>
161
  </translate>
162
  <events>
@@ -176,6 +206,23 @@
176
  </klarna_clean_pno_from_quote>
177
  </observers>
178
  </sales_quote_save_before>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
179
  </events>
180
  </frontend>
181
 
@@ -189,11 +236,11 @@
189
  </layout>
190
  <translate>
191
  <modules>
192
- <klarna>
193
  <files>
194
  <default>Vaimo_Klarna.csv</default>
195
  </files>
196
- </klarna>
197
  </modules>
198
  </translate>
199
  <events>
@@ -268,6 +315,24 @@
268
  <host>BETA</host>
269
  <allow_separate_address>1</allow_separate_address>
270
  </vaimo_klarna_special>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
271
  </payment>
272
  </default>
273
  </config>
25
  --><config>
26
  <modules>
27
  <Vaimo_Klarna>
28
+ <version>5.2.0</version>
29
  <name>Vaimo Klarna Module</name>
30
  <depends>
31
  <Mage_Payment/>
72
  </connection>
73
  </klarna_read>
74
  </resources>
75
+
76
+ <fieldsets>
77
+ <sales_convert_quote_address>
78
+ <care_of>
79
+ <to_order_address>*</to_order_address>
80
+ <to_customer_address>*</to_customer_address>
81
+ </care_of>
82
+ </sales_convert_quote_address>
83
+ </fieldsets>
84
+
85
+ <events>
86
+ <customer_address_format>
87
+ <observers>
88
+ <klarna_address_format>
89
+ <class>klarna/observer</class>
90
+ <method>customerAddressFormat</method>
91
+ </klarna_address_format>
92
+ </observers>
93
+ </customer_address_format>
94
+ </events>
95
+
96
  <sales>
97
  <quote>
98
  <totals>
152
  </totals>
153
  </pdf>
154
  </global>
155
+
156
  <frontend>
157
+ <secure_url>
158
+ <checkout_klarna>/checkout/klarna</checkout_klarna>
159
+ </secure_url>
160
  <layout>
161
  <updates>
162
  <klarna module="klarna">
172
  <frontName>klarna</frontName>
173
  </args>
174
  </klarna>
175
+ <checkout>
176
+ <args>
177
+ <modules>
178
+ <klarna before="Mage_Checkout">Vaimo_Klarna_Checkout</klarna>
179
+ </modules>
180
+ </args>
181
+ </checkout>
182
  </routers>
183
  <translate>
184
  <modules>
185
+ <Vaimo_Klarna>
186
  <files>
187
  <default>Vaimo_Klarna.csv</default>
188
  </files>
189
+ </Vaimo_Klarna>
190
  </modules>
191
  </translate>
192
  <events>
206
  </klarna_clean_pno_from_quote>
207
  </observers>
208
  </sales_quote_save_before>
209
+
210
+ <controller_action_predispatch_checkout_onepage_index>
211
+ <observers>
212
+ <klarna_check_launch_klarnacheckout>
213
+ <class>klarna/observer</class>
214
+ <method>checkLaunchKlarnaCheckout</method>
215
+ </klarna_check_launch_klarnacheckout>
216
+ </observers>
217
+ </controller_action_predispatch_checkout_onepage_index>
218
+ <controller_action_predispatch_onestepcheckout>
219
+ <observers>
220
+ <klarna_check_launch_klarnacheckout>
221
+ <class>klarna/observer</class>
222
+ <method>checkLaunchKlarnaCheckout</method>
223
+ </klarna_check_launch_klarnacheckout>
224
+ </observers>
225
+ </controller_action_predispatch_onestepcheckout>
226
  </events>
227
  </frontend>
228
 
236
  </layout>
237
  <translate>
238
  <modules>
239
+ <Vaimo_Klarna>
240
  <files>
241
  <default>Vaimo_Klarna.csv</default>
242
  </files>
243
+ </Vaimo_Klarna>
244
  </modules>
245
  </translate>
246
  <events>
315
  <host>BETA</host>
316
  <allow_separate_address>1</allow_separate_address>
317
  </vaimo_klarna_special>
318
+ <vaimo_klarna_checkout>
319
+ <title>Klarna Checkout</title>
320
+ <model>klarna/payment_checkout</model>
321
+ <allowspecific>0</allowspecific>
322
+ <active>0</active>
323
+ <sort_order>999</sort_order>
324
+ <order_status>klarna_reserved</order_status>
325
+ <order_status_pending>klarna_pending</order_status_pending>
326
+ <order_status_denied>klarna_denied</order_status_denied>
327
+ <host>BETA</host>
328
+ <allow_when_logged_in>1</allow_when_logged_in>
329
+ <allow_customer_group>99</allow_customer_group>
330
+ <auto_prefil>1</auto_prefil>
331
+ <allow_separate_address>2</allow_separate_address>
332
+ <enable_cart_above_kco>1</enable_cart_above_kco>
333
+ <enable_other_button>1</enable_other_button>
334
+ <enable_auto_focus>1</enable_auto_focus>
335
+ </vaimo_klarna_checkout>
336
  </payment>
337
  </default>
338
  </config>
app/code/community/Vaimo/Klarna/etc/system.xml CHANGED
@@ -31,7 +31,7 @@
31
  <groups>
32
  <vaimo_klarna_invoice translate="label" module="klarna">
33
  <label>Klarna Invoice</label>
34
- <sort_order>10</sort_order>
35
  <show_in_default>1</show_in_default>
36
  <show_in_store>1</show_in_store>
37
  <show_in_website>1</show_in_website>
@@ -201,7 +201,7 @@
201
  </vaimo_klarna_invoice>
202
  <vaimo_klarna_account translate="label" module="klarna">
203
  <label>Klarna Account</label>
204
- <sort_order>10</sort_order>
205
  <show_in_default>1</show_in_default>
206
  <show_in_store>1</show_in_store>
207
  <show_in_website>1</show_in_website>
@@ -368,7 +368,7 @@
368
  </vaimo_klarna_account>
369
  <vaimo_klarna_special translate="label" module="klarna">
370
  <label>Klarna Campaign</label>
371
- <sort_order>10</sort_order>
372
  <show_in_default>1</show_in_default>
373
  <show_in_store>1</show_in_store>
374
  <show_in_website>1</show_in_website>
@@ -532,6 +532,257 @@
532
  </sort_order>
533
  </fields>
534
  </vaimo_klarna_special>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
535
  </groups>
536
  </payment>
537
  <sales>
31
  <groups>
32
  <vaimo_klarna_invoice translate="label" module="klarna">
33
  <label>Klarna Invoice</label>
34
+ <sort_order>6</sort_order>
35
  <show_in_default>1</show_in_default>
36
  <show_in_store>1</show_in_store>
37
  <show_in_website>1</show_in_website>
201
  </vaimo_klarna_invoice>
202
  <vaimo_klarna_account translate="label" module="klarna">
203
  <label>Klarna Account</label>
204
+ <sort_order>7</sort_order>
205
  <show_in_default>1</show_in_default>
206
  <show_in_store>1</show_in_store>
207
  <show_in_website>1</show_in_website>
368
  </vaimo_klarna_account>
369
  <vaimo_klarna_special translate="label" module="klarna">
370
  <label>Klarna Campaign</label>
371
+ <sort_order>8</sort_order>
372
  <show_in_default>1</show_in_default>
373
  <show_in_store>1</show_in_store>
374
  <show_in_website>1</show_in_website>
532
  </sort_order>
533
  </fields>
534
  </vaimo_klarna_special>
535
+ <vaimo_klarna_checkout translate="label" module="klarna">
536
+ <label>Klarna Checkout</label>
537
+ <sort_order>9</sort_order>
538
+ <show_in_default>1</show_in_default>
539
+ <show_in_website>1</show_in_website>
540
+ <show_in_store>1</show_in_store>
541
+ <fields>
542
+ <active translate="label">
543
+ <label>Enabled</label>
544
+ <frontend_type>select</frontend_type>
545
+ <source_model>adminhtml/system_config_source_yesno</source_model>
546
+ <sort_order>10</sort_order>
547
+ <show_in_default>1</show_in_default>
548
+ <show_in_website>1</show_in_website>
549
+ <show_in_store>1</show_in_store>
550
+ </active>
551
+ <api_version translate="label">
552
+ <label>API Version</label>
553
+ <frontend_type>select</frontend_type>
554
+ <source_model>klarna/source_apiversion</source_model>
555
+ <sort_order>20</sort_order>
556
+ <show_in_default>1</show_in_default>
557
+ <show_in_website>1</show_in_website>
558
+ <show_in_store>1</show_in_store>
559
+ </api_version>
560
+ <merchant_id translate="label">
561
+ <label>Merchant ID</label>
562
+ <frontend_type>text</frontend_type>
563
+ <sort_order>30</sort_order>
564
+ <show_in_default>1</show_in_default>
565
+ <show_in_website>1</show_in_website>
566
+ <show_in_store>1</show_in_store>
567
+ <comment>The merchant id that you have received from Klarna</comment>
568
+ </merchant_id>
569
+ <shared_secret translate="label">
570
+ <label>Shared secret</label>
571
+ <frontend_type>text</frontend_type>
572
+ <sort_order>40</sort_order>
573
+ <show_in_default>1</show_in_default>
574
+ <show_in_website>1</show_in_website>
575
+ <show_in_store>1</show_in_store>
576
+ <comment>The shared secret that you have received from Klarna</comment>
577
+ </shared_secret>
578
+ <host translate="label">
579
+ <label>Server</label>
580
+ <frontend_type>select</frontend_type>
581
+ <source_model>klarna/source_servermode</source_model>
582
+ <sort_order>50</sort_order>
583
+ <show_in_default>1</show_in_default>
584
+ <show_in_website>1</show_in_website>
585
+ <show_in_store>1</show_in_store>
586
+ <comment>Choose what server to make calls to</comment>
587
+ </host>
588
+ <auto_prefil translate="label">
589
+ <label>Auto prefill known Klarna details</label>
590
+ <frontend_type>select</frontend_type>
591
+ <source_model>adminhtml/system_config_source_yesno</source_model>
592
+ <sort_order>60</sort_order>
593
+ <show_in_default>1</show_in_default>
594
+ <show_in_website>1</show_in_website>
595
+ <show_in_store>1</show_in_store>
596
+ <comment>When activated, it will use the logged in customer details to prefill the Klarna Checkout form</comment>
597
+ </auto_prefil>
598
+ <order_status translate="label">
599
+ <label>New order status</label>
600
+ <frontend_type>select</frontend_type>
601
+ <source_model>adminhtml/system_config_source_order_status</source_model>
602
+ <sort_order>70</sort_order>
603
+ <show_in_default>1</show_in_default>
604
+ <show_in_website>1</show_in_website>
605
+ <show_in_store>0</show_in_store>
606
+ </order_status>
607
+ <disable_product_widget translate="label">
608
+ <label>Disable payment widget on product page</label>
609
+ <frontend_type>select</frontend_type>
610
+ <source_model>adminhtml/system_config_source_yesno</source_model>
611
+ <sort_order>80</sort_order>
612
+ <show_in_default>1</show_in_default>
613
+ <show_in_website>1</show_in_website>
614
+ <show_in_store>1</show_in_store>
615
+ <comment>If set to yes, the payment information from Klarna will not appear on the product page</comment>
616
+ </disable_product_widget>
617
+ <terms_url translate="label">
618
+ <label>URL to terms and conditions</label>
619
+ <frontend_type>text</frontend_type>
620
+ <sort_order>90</sort_order>
621
+ <show_in_default>1</show_in_default>
622
+ <show_in_website>1</show_in_website>
623
+ <show_in_store>1</show_in_store>
624
+ <comment>URL to this stores own terms and conditions</comment>
625
+ </terms_url>
626
+ <extra_order_attribute translate="label">
627
+ <label>Extra order ID attribute</label>
628
+ <frontend_type>text</frontend_type>
629
+ <sort_order>150</sort_order>
630
+ <show_in_default>1</show_in_default>
631
+ <show_in_website>1</show_in_website>
632
+ <show_in_store>1</show_in_store>
633
+ <comment>Will be used in the orderid2 field on the Klarna order</comment>
634
+ </extra_order_attribute>
635
+ <allow_separate_address translate="label">
636
+ <label>Allow separate addresses</label>
637
+ <frontend_type>select</frontend_type>
638
+ <source_model>klarna/source_yesnodefault</source_model>
639
+ <sort_order>210</sort_order>
640
+ <show_in_default>1</show_in_default>
641
+ <show_in_store>1</show_in_store>
642
+ <show_in_website>1</show_in_website>
643
+ <comment>Allow shipping address to be different from billing address. You might need acceptance from Klarna if activated</comment>
644
+ </allow_separate_address>
645
+ <force_phonenumber translate="label">
646
+ <label>Force entry of phonenumber</label>
647
+ <frontend_type>select</frontend_type>
648
+ <source_model>adminhtml/system_config_source_yesno</source_model>
649
+ <sort_order>220</sort_order>
650
+ <show_in_default>1</show_in_default>
651
+ <show_in_website>1</show_in_website>
652
+ <show_in_store>1</show_in_store>
653
+ </force_phonenumber>
654
+ <packstation_enabled translate="label">
655
+ <label>Enable DHL Packstation</label>
656
+ <frontend_type>select</frontend_type>
657
+ <source_model>adminhtml/system_config_source_yesno</source_model>
658
+ <sort_order>230</sort_order>
659
+ <show_in_default>1</show_in_default>
660
+ <show_in_website>1</show_in_website>
661
+ <show_in_store>1</show_in_store>
662
+ <comment>Only available in Germany</comment>
663
+ </packstation_enabled>
664
+ <enable_cart_above_kco translate="label">
665
+ <label>Enable cart in checkout page</label>
666
+ <frontend_type>select</frontend_type>
667
+ <source_model>adminhtml/system_config_source_yesno</source_model>
668
+ <sort_order>240</sort_order>
669
+ <show_in_default>1</show_in_default>
670
+ <show_in_website>1</show_in_website>
671
+ <show_in_store>1</show_in_store>
672
+ </enable_cart_above_kco>
673
+ <enable_auto_focus translate="label">
674
+ <label>Enable Autofocus for Klarna Checkout</label>
675
+ <frontend_type>select</frontend_type>
676
+ <source_model>adminhtml/system_config_source_yesno</source_model>
677
+ <sort_order>250</sort_order>
678
+ <show_in_default>1</show_in_default>
679
+ <show_in_website>1</show_in_website>
680
+ <show_in_store>1</show_in_store>
681
+ </enable_auto_focus>
682
+
683
+ <heading_other_method_button translate="label">
684
+ <label>Support of other payment methods</label>
685
+ <frontend_model>adminhtml/system_config_form_field_heading</frontend_model>
686
+ <sort_order>720</sort_order>
687
+ <show_in_default>1</show_in_default>
688
+ <show_in_website>1</show_in_website>
689
+ <show_in_store>1</show_in_store>
690
+ </heading_other_method_button>
691
+ <enable_other_button translate="label">
692
+ <label>Enabled</label>
693
+ <frontend_type>select</frontend_type>
694
+ <source_model>klarna/source_yesnodefault</source_model>
695
+ <sort_order>721</sort_order>
696
+ <show_in_default>1</show_in_default>
697
+ <show_in_website>1</show_in_website>
698
+ <show_in_store>1</show_in_store>
699
+ <comment>If enabled, one button will be placed on klarna checkout page and one in the payment section of standard checkout</comment>
700
+ </enable_other_button>
701
+ <label_other_button translate="label">
702
+ <label>Label for Other Payment Methods button</label>
703
+ <frontend_type>text</frontend_type>
704
+ <sort_order>722</sort_order>
705
+ <show_in_default>1</show_in_default>
706
+ <show_in_website>1</show_in_website>
707
+ <show_in_store>1</show_in_store>
708
+ <comment>This can be free text or a complete URL to a reasonably sized image</comment>
709
+ </label_other_button>
710
+ <label_back_button translate="label">
711
+ <label>Label for Back to Klarna Checkout button</label>
712
+ <frontend_type>text</frontend_type>
713
+ <sort_order>723</sort_order>
714
+ <show_in_default>1</show_in_default>
715
+ <show_in_website>1</show_in_website>
716
+ <show_in_store>1</show_in_store>
717
+ <comment>This can be free text or a complete URL to a reasonably sized image</comment>
718
+ </label_back_button>
719
+
720
+ <heading_newsletter translate="label">
721
+ <label>Newsletter</label>
722
+ <frontend_model>adminhtml/system_config_form_field_heading</frontend_model>
723
+ <sort_order>750</sort_order>
724
+ <show_in_default>1</show_in_default>
725
+ <show_in_website>1</show_in_website>
726
+ <show_in_store>1</show_in_store>
727
+ </heading_newsletter>
728
+ <enable_newsletter translate="label">
729
+ <label>Enabled</label>
730
+ <frontend_type>select</frontend_type>
731
+ <source_model>klarna/source_newsletter</source_model>
732
+ <sort_order>760</sort_order>
733
+ <show_in_default>1</show_in_default>
734
+ <show_in_website>1</show_in_website>
735
+ <show_in_store>1</show_in_store>
736
+ <comment>If checkbox for newsletter should be shown in checkout page.</comment>
737
+ </enable_newsletter>
738
+ <newsletter_checked translate="label">
739
+ <label>Checked by default</label>
740
+ <frontend_type>select</frontend_type>
741
+ <source_model>adminhtml/system_config_source_yesno</source_model>
742
+ <sort_order>770</sort_order>
743
+ <show_in_default>1</show_in_default>
744
+ <show_in_website>1</show_in_website>
745
+ <show_in_store>1</show_in_store>
746
+ </newsletter_checked>
747
+ <heading_ab_testing translate="label">
748
+ <label>A/B Testing settings</label>
749
+ <frontend_model>adminhtml/system_config_form_field_heading</frontend_model>
750
+ <sort_order>850</sort_order>
751
+ <show_in_default>1</show_in_default>
752
+ <show_in_website>1</show_in_website>
753
+ <show_in_store>1</show_in_store>
754
+ </heading_ab_testing>
755
+ <allowed_ip_range translate="label">
756
+ <label>Enable for IP range (last digit)</label>
757
+ <frontend_type>text</frontend_type>
758
+ <sort_order>860</sort_order>
759
+ <show_in_default>1</show_in_default>
760
+ <show_in_website>1</show_in_website>
761
+ <show_in_store>1</show_in_store>
762
+ <comment>Specify 2 numbers between 0 and 255, separated by dash. Example: '0-50'. Empty value enables all IP addresses</comment>
763
+ </allowed_ip_range>
764
+ <allow_when_logged_in translate="label">
765
+ <label>Enable for logged in Customers</label>
766
+ <frontend_type>select</frontend_type>
767
+ <source_model>adminhtml/system_config_source_yesno</source_model>
768
+ <sort_order>870</sort_order>
769
+ <show_in_default>1</show_in_default>
770
+ <show_in_website>1</show_in_website>
771
+ <show_in_store>1</show_in_store>
772
+ <comment>If not enabled, logged in customers will use standard Magento checkout</comment>
773
+ </allow_when_logged_in>
774
+ <allow_customer_group translate="label">
775
+ <label>Enable for specific customer groups</label>
776
+ <frontend_type>multiselect</frontend_type>
777
+ <source_model>klarna/source_customergroup</source_model>
778
+ <sort_order>880</sort_order>
779
+ <show_in_default>1</show_in_default>
780
+ <show_in_website>1</show_in_website>
781
+ <show_in_store>1</show_in_store>
782
+ <comment>If you do not belong to a selected customer group, standard Magento checkout will be used. None selected, means enabled for all</comment>
783
+ </allow_customer_group>
784
+ </fields>
785
+ </vaimo_klarna_checkout>
786
  </groups>
787
  </payment>
788
  <sales>
app/code/community/Vaimo/Klarna/sql/klarna_setup/mysql4-upgrade-5.1.6-5.1.7.php ADDED
@@ -0,0 +1,72 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Copyright (c) 2009-2012 Vaimo AB
4
+ *
5
+ * Vaimo reserves all rights in the Program as delivered. The Program
6
+ * or any portion thereof may not be reproduced in any form whatsoever without
7
+ * the written consent of Vaimo, except as provided by licence. A licence
8
+ * under Vaimo's rights in the Program may be available directly from
9
+ * Vaimo.
10
+ *
11
+ * Disclaimer:
12
+ * THIS NOTICE MAY NOT BE REMOVED FROM THE PROGRAM BY ANY USER THEREOF.
13
+ * THE PROGRAM IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
14
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
16
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ * OUT OF OR IN CONNECTION WITH THE PROGRAM OR THE USE OR OTHER DEALINGS
19
+ * IN THE PROGRAM.
20
+ *
21
+ * @category Vaimo
22
+ * @package Vaimo_Klarna
23
+ * @copyright Copyright (c) 2009-2013 Vaimo AB
24
+ */
25
+
26
+ /** @var $installer Mage_Sales_Model_Resource_Setup */
27
+ $installer = Mage::getResourceModel('sales/setup', 'sales_setup');
28
+
29
+ $installer->startSetup();
30
+
31
+ $installer->addAttribute('quote', 'klarna_checkout_id', array(
32
+ 'type' => 'varchar',
33
+ 'required' => 0,
34
+ 'comment' => 'Klarna Checkout Id',
35
+ ));
36
+
37
+ $installer->addAttribute('quote', 'klarna_checkout_newsletter', array(
38
+ 'type' => 'smallint',
39
+ 'required' => 0,
40
+ 'comment' => 'Sign up for Newsletter',
41
+ ));
42
+
43
+ $installer->addAttribute('quote_address', 'care_of', array(
44
+ 'type' => Varien_Db_Ddl_Table::TYPE_VARCHAR,
45
+ 'length' => 255,
46
+ 'required' => false,
47
+ 'comment' => 'Care of',
48
+ ));
49
+
50
+ $installer->addAttribute('order_address', 'care_of', array(
51
+ 'type' => Varien_Db_Ddl_Table::TYPE_VARCHAR,
52
+ 'length' => 255,
53
+ 'required' => false,
54
+ 'comment' => 'Care of',
55
+ ));
56
+
57
+ $installer->addAttribute('customer_address', 'care_of', array(
58
+ 'label' => 'Care of',
59
+ 'type' => Varien_Db_Ddl_Table::TYPE_VARCHAR,
60
+ 'length' => 255,
61
+ 'input' => 'text',
62
+ 'visible' => true,
63
+ 'required' => false
64
+ ));
65
+
66
+ Mage::getSingleton('eav/config')
67
+ ->getAttribute('customer_address', 'care_of')
68
+ ->setData('used_in_forms', array('adminhtml_customer_address', 'customer_address_edit', 'customer_register_address'))
69
+ ->setSortOrder(55)
70
+ ->save();
71
+
72
+ $installer->endSetup();
app/design/adminhtml/default/default/template/vaimo/klarna/info/account.phtml CHANGED
@@ -27,7 +27,10 @@
27
 
28
  <ul id="payment_info_<?php echo $this->getMethodCode(); ?>" class="form-list">
29
  <li>
30
- <?php echo '<img src="' . $this->getKlarnaLogotype(125) . '" alt="' . Mage::helper('klarna')->__($this->getMethodTitle()) . '"/>'; ?>
 
 
 
31
  </li>
32
 
33
  <?php echo $this->getInvoicesHtml(); ?>
27
 
28
  <ul id="payment_info_<?php echo $this->getMethodCode(); ?>" class="form-list">
29
  <li>
30
+ <?php echo '<img src="' . $this->getKlarnaLogotype(125) . '" alt=""/>'; ?>
31
+ </li>
32
+ <li>
33
+ <?php echo Mage::helper('klarna')->__($this->getMethodTitle()); ?>
34
  </li>
35
 
36
  <?php echo $this->getInvoicesHtml(); ?>
app/design/adminhtml/default/default/template/vaimo/klarna/info/checkout.phtml ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Copyright (c) 2009-2014 Vaimo AB
4
+ *
5
+ * Vaimo reserves all rights in the Program as delivered. The Program
6
+ * or any portion thereof may not be reproduced in any form whatsoever without
7
+ * the written consent of Vaimo, except as provided by licence. A licence
8
+ * under Vaimo's rights in the Program may be available directly from
9
+ * Vaimo.
10
+ *
11
+ * Disclaimer:
12
+ * THIS NOTICE MAY NOT BE REMOVED FROM THE PROGRAM BY ANY USER THEREOF.
13
+ * THE PROGRAM IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
14
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
16
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ * OUT OF OR IN CONNECTION WITH THE PROGRAM OR THE USE OR OTHER DEALINGS
19
+ * IN THE PROGRAM.
20
+ *
21
+ * @category Vaimo
22
+ * @package Vaimo_Klarna
23
+ * @copyright Copyright (c) 2009-2014 Vaimo AB
24
+ */
25
+
26
+ ?>
27
+
28
+ <ul id="payment_info_<?php echo $this->getMethodCode(); ?>" class="form-list">
29
+ <li>
30
+ <?php echo '<img src="' . $this->getKlarnaLogotype(125) . '" alt=""/>'; ?>
31
+ </li>
32
+ <li>
33
+ <?php echo Mage::helper('klarna')->__($this->getMethodTitle()); ?>
34
+ </li>
35
+
36
+ <?php echo $this->getInvoicesHtml(); ?>
37
+
38
+ <?php echo $this->getReservationHtml(); ?>
39
+
40
+ <?php echo $this->getReferenceHtml(); ?>
41
+
42
+ </ul>
43
+
app/design/adminhtml/default/default/template/vaimo/klarna/info/children/invoices.phtml CHANGED
@@ -33,9 +33,15 @@ $info = $this->getPaymentInfo();
33
 
34
  <?php if ($info->getKlarnaInvoiceList()): ?>
35
  <?php foreach ($info->getKlarnaInvoiceList() as $invoice): ?>
36
- <li>
37
- <?php echo Mage::helper('klarna')->__('Invoice') . ' <a href="' . $this->getKlarnaInvoiceLink($invoice['invoice_id']) . '">' . $invoice['invoice_id'] . '</a>'; ?>
38
- </li>
 
 
 
 
 
 
39
  <?php endforeach; ?>
40
  <?php endif; ?>
41
 
33
 
34
  <?php if ($info->getKlarnaInvoiceList()): ?>
35
  <?php foreach ($info->getKlarnaInvoiceList() as $invoice): ?>
36
+ <?php if (isset($invoice[Vaimo_Klarna_Helper_Data::KLARNA_INFO_FIELD_INVOICE_LIST_KCO_ID])): ?>
37
+ <li>
38
+ <?php echo Mage::helper('klarna')->__('Capture ID') . ': ' . $invoice[Vaimo_Klarna_Helper_Data::KLARNA_INFO_FIELD_INVOICE_LIST_KCO_ID]; ?>
39
+ </li>
40
+ <?php else: ?>
41
+ <li>
42
+ <?php echo Mage::helper('klarna')->__('Invoice') . ' <a href="' . $this->getKlarnaInvoiceLink($invoice['invoice_id']) . '">' . $invoice['invoice_id'] . '</a>'; ?>
43
+ </li>
44
+ <?php endif; ?>
45
  <?php endforeach; ?>
46
  <?php endif; ?>
47
 
app/design/adminhtml/default/default/template/vaimo/klarna/info/children/reference.phtml ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Copyright (c) 2009-2014 Vaimo AB
4
+ *
5
+ * Vaimo reserves all rights in the Program as delivered. The Program
6
+ * or any portion thereof may not be reproduced in any form whatsoever without
7
+ * the written consent of Vaimo, except as provided by licence. A licence
8
+ * under Vaimo's rights in the Program may be available directly from
9
+ * Vaimo.
10
+ *
11
+ * Disclaimer:
12
+ * THIS NOTICE MAY NOT BE REMOVED FROM THE PROGRAM BY ANY USER THEREOF.
13
+ * THE PROGRAM IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
14
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
16
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ * OUT OF OR IN CONNECTION WITH THE PROGRAM OR THE USE OR OTHER DEALINGS
19
+ * IN THE PROGRAM.
20
+ *
21
+ * @category Vaimo
22
+ * @package Vaimo_Klarna
23
+ * @copyright Copyright (c) 2009-2014 Vaimo AB
24
+ */
25
+
26
+ $info = $this->getPaymentInfo();
27
+
28
+ ?>
29
+
30
+ <?php if ($info): ?>
31
+
32
+ <?php if ($info->getKlarnaReservationReference()): ?>
33
+ <li>
34
+ <?php echo Mage::helper('klarna')->__('Reference') . ' ' . $info->getKlarnaReservationReference(); ?>
35
+ </li>
36
+ <?php endif; ?>
37
+
38
+ <?php endif; ?>
app/design/adminhtml/default/default/template/vaimo/klarna/info/children/reservation.phtml CHANGED
@@ -30,7 +30,7 @@ $info = $this->getPaymentInfo();
30
  <?php if ($info): ?>
31
 
32
  <?php if ($info->getKlarnaReservationId()): ?>
33
- <?php if ($this->somethingLeftToCapture()): ?>
34
  <li>
35
  <?php echo Mage::helper('klarna')->__('Reservation') . ' ' . $info->getKlarnaReservationId(); ?>
36
  <?php
30
  <?php if ($info): ?>
31
 
32
  <?php if ($info->getKlarnaReservationId()): ?>
33
+ <?php if ($this->somethingLeftToCapture() || $this->getMethodCode()==Vaimo_Klarna_Helper_Data::KLARNA_METHOD_CHECKOUT): ?>
34
  <li>
35
  <?php echo Mage::helper('klarna')->__('Reservation') . ' ' . $info->getKlarnaReservationId(); ?>
36
  <?php
app/design/adminhtml/default/default/template/vaimo/klarna/info/invoice.phtml CHANGED
@@ -27,7 +27,10 @@
27
 
28
  <ul id="payment_info_<?php echo $this->getMethodCode(); ?>" class="form-list">
29
  <li>
30
- <?php echo '<img src="' . $this->getKlarnaLogotype(125) . '" alt="' . Mage::helper('klarna')->__($this->getMethodTitle()) . '"/>'; ?>
 
 
 
31
  </li>
32
 
33
  <?php echo $this->getInvoicesHtml(); ?>
27
 
28
  <ul id="payment_info_<?php echo $this->getMethodCode(); ?>" class="form-list">
29
  <li>
30
+ <?php echo '<img src="' . $this->getKlarnaLogotype(125) . '" alt=""/>'; ?>
31
+ </li>
32
+ <li>
33
+ <?php echo Mage::helper('klarna')->__($this->getMethodTitle()); ?>
34
  </li>
35
 
36
  <?php echo $this->getInvoicesHtml(); ?>
app/design/adminhtml/default/default/template/vaimo/klarna/info/special.phtml CHANGED
@@ -27,7 +27,10 @@
27
 
28
  <ul id="payment_info_<?php echo $this->getMethodCode(); ?>" class="form-list">
29
  <li>
30
- <?php echo '<img src="' . $this->getKlarnaLogotype(125) . '" alt="' . Mage::helper('klarna')->__($this->getMethodTitle()) . '"/>'; ?>
 
 
 
31
  </li>
32
 
33
  <?php echo $this->getInvoicesHtml(); ?>
27
 
28
  <ul id="payment_info_<?php echo $this->getMethodCode(); ?>" class="form-list">
29
  <li>
30
+ <?php echo '<img src="' . $this->getKlarnaLogotype(125) . '" alt=""/>'; ?>
31
+ </li>
32
+ <li>
33
+ <?php echo Mage::helper('klarna')->__($this->getMethodTitle()); ?>
34
  </li>
35
 
36
  <?php echo $this->getInvoicesHtml(); ?>
app/design/frontend/base/default/layout/vaimo_klarna.xml CHANGED
@@ -120,4 +120,129 @@
120
  <block name="vaimo_totals" type="klarna/invoice_totals" before="tax"/>
121
  </reference>
122
  </sales_email_order_invoice_items>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
123
  </layout>
120
  <block name="vaimo_totals" type="klarna/invoice_totals" before="tax"/>
121
  </reference>
122
  </sales_email_order_invoice_items>
123
+
124
+
125
+ <!--
126
+ /*
127
+ * Klarna Checkout specific layout
128
+ * Own checkout view, own success page and going through our extended Googleanalytics block,
129
+ * which is required because of the way that the orders are created in Klarna Checkout
130
+ *
131
+ */
132
+ -->
133
+
134
+ <checkout_klarna_index translate="label">
135
+ <label>Klarna Checkout</label>
136
+
137
+ <reference name="root">
138
+ <action method="setTemplate">
139
+ <template>page/1column.phtml</template>
140
+ </action>
141
+ </reference>
142
+
143
+ <remove name="right"/>
144
+ <remove name="left"/>
145
+
146
+ <reference name="head">
147
+ <action method="addCss"><stylesheet>css/vaimo/klarna/klarnacheckout.css</stylesheet></action>
148
+ <action method="addJs"><script>vaimo/klarna/klarnacheckout.js</script></action>
149
+ </reference>
150
+
151
+ <reference name="content">
152
+ <block type="core/template" name="klarna_msg" template="vaimo/klarna/klarnacheckout/msg.phtml"/>
153
+ <block type="page/html_wrapper" name="klarna_wrapper" as="klarna_wrapper">
154
+ <action method="setElementId"><value>klarna_wrapper</value></action>
155
+
156
+ <block type="core/template" name="klarna_header" template="vaimo/klarna/klarnacheckout/header.phtml"/>
157
+
158
+ <block type="page/html_wrapper" name="klarna_left" as="klarna_left">
159
+ <action method="setElementId"><value>klarna_left</value></action>
160
+
161
+ <block type="checkout/cart" name="checkout.cart">
162
+ <action method="setCartTemplate"><value>vaimo/klarna/klarnacheckout/cart.phtml</value></action>
163
+ <action method="setEmptyTemplate"><value>checkout/cart/noItems.phtml</value></action>
164
+ <action method="chooseTemplate"/>
165
+ <action method="addItemRender"><type>simple</type><block>checkout/cart_item_renderer</block><template>vaimo/klarna/klarnacheckout/cart/item/default.phtml</template></action>
166
+ <action method="addItemRender"><type>grouped</type><block>checkout/cart_item_renderer_grouped</block><template>vaimo/klarna/klarnacheckout/cart/item/default.phtml</template></action>
167
+ <action method="addItemRender"><type>configurable</type><block>checkout/cart_item_renderer_configurable</block><template>vaimo/klarna/klarnacheckout/cart/item/default.phtml</template></action>
168
+ <action method="addItemRender"><type>bundle</type><block>checkout/cart_item_renderer</block><template>vaimo/klarna/klarnacheckout/cart/item/default.phtml</template></action>
169
+ <action method="addItemRender"><type>ugiftcert</type><block>ugiftcert/cart_item</block><template>vaimo/klarna/klarnacheckout/cart/item/default.phtml</template></action>
170
+ </block>
171
+
172
+ <block type="checkout/onepage_shipping_method" name="checkout.onepage.shipping_method" as="shipping_method" template="vaimo/klarna/klarnacheckout/shipping_method.phtml">
173
+ <block type="checkout/onepage_shipping_method_available" name="checkout.onepage.shipping_method.available" as="available" template="vaimo/klarna/klarnacheckout/shipping_method/available.phtml"/>
174
+ </block>
175
+ </block>
176
+
177
+ <block type="page/html_wrapper" name="klarna_right" as="klarna_right">
178
+ <action method="setElementId"><value>klarna_right</value></action>
179
+
180
+ <block type="checkout/cart_totals" name="checkout.cart.totals" as="totals" template="vaimo/klarna/klarnacheckout/cart/totals.phtml"/>
181
+
182
+ <block type="klarna/klarnacheckout_reward" name="klarnacheckout.reward" template="vaimo/klarna/klarnacheckout/reward.phtml"/>
183
+
184
+ <block type="klarna/klarnacheckout_customer_balance" name="klarnacheckout.customer_balance" template="vaimo/klarna/klarnacheckout/customer/balance.phtml"/>
185
+
186
+ <block type="klarna/klarnacheckout_newsletter" name="checkout.newsletter" template="vaimo/klarna/klarnacheckout/newsletter.phtml"/>
187
+
188
+ <block type="klarna/klarnacheckout_discount" name="discount" as="discount" template="vaimo/klarna/klarnacheckout/discount.phtml">
189
+ <block type="checkout/cart_coupon" name="checkout.cart.coupon" as="coupon" template="vaimo/klarna/klarnacheckout/discount/coupon.phtml"/>
190
+ </block>
191
+
192
+ <block type="klarna/klarnacheckout_othermethod" name="other.payment.methods" template="vaimo/klarna/klarnacheckout/othermethod.phtml"/>
193
+
194
+ </block>
195
+ </block>
196
+
197
+
198
+
199
+ <block type="page/html_wrapper" name="klarna_checkout" as="klarna_checkout">
200
+ <action method="setElementId"><value>klarna_checkout</value></action>
201
+ <block type="klarna/klarnacheckout_klarnacheckout" name="checkout" template="vaimo/klarna/klarnacheckout/klarnacheckout.phtml"/>
202
+ </block>
203
+
204
+ </reference>
205
+
206
+ </checkout_klarna_index>
207
+
208
+ <checkout_klarna_success translate="label">
209
+
210
+ <label>Klarna Checkout Success</label>
211
+
212
+ <reference name="root">
213
+ <action method="setTemplate">
214
+ <template>page/1column.phtml</template>
215
+ </action>
216
+ </reference>
217
+
218
+ <remove name="right"/>
219
+ <remove name="left"/>
220
+
221
+ <reference name="head">
222
+ <action method="addCss"><stylesheet>css/vaimo/klarna/klarnacheckout.css</stylesheet></action>
223
+ </reference>
224
+
225
+ <reference name="content">
226
+ <block type="klarna/klarnacheckout_success" name="checkout" template="vaimo/klarna/klarnacheckout/success.phtml"/>
227
+ </reference>
228
+
229
+ </checkout_klarna_success>
230
+
231
+ <default>
232
+ <reference name="google_analytics">
233
+ <block type="klarna/klarnacheckout_ga" name="google_analytics" as="google_analytics" template="googleanalytics/ga.phtml" />
234
+ </reference>
235
+ </default>
236
+
237
+ <customer_account_login>
238
+ <reference name="form.additional.info">
239
+ <block type="klarna/klarnacheckout_autofill" name="klarnacheckout.autofill" after="-" template="vaimo/klarna/klarnacheckout/autofill.phtml"/>
240
+ </reference>
241
+ </customer_account_login>
242
+ <customer_account_create>
243
+ <reference name="form.additional.info">
244
+ <block type="klarna/klarnacheckout_autofill" name="klarnacheckout.autofill" after="-" template="vaimo/klarna/klarnacheckout/autofill.phtml"/>
245
+ </reference>
246
+ </customer_account_create>
247
+
248
  </layout>
app/design/frontend/base/default/template/vaimo/klarna/form/address/search.phtml CHANGED
@@ -23,6 +23,8 @@
23
  * @copyright Copyright (c) 2009-2014 Vaimo AB
24
  */
25
 
 
 
26
  $addresses = $this->getAddresses();
27
  $limit_for_radiobuttons = 2; // When you have more addresses than this, create dropdown
28
 
23
  * @copyright Copyright (c) 2009-2014 Vaimo AB
24
  */
25
 
26
+ /** @var Vaimo_Klarna_Block_Form_Address_Search $this */
27
+
28
  $addresses = $this->getAddresses();
29
  $limit_for_radiobuttons = 2; // When you have more addresses than this, create dropdown
30
 
app/design/frontend/base/default/template/vaimo/klarna/form/checkout.phtml ADDED
@@ -0,0 +1,45 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Copyright (c) 2009-2014 Vaimo AB
4
+ *
5
+ * Vaimo reserves all rights in the Program as delivered. The Program
6
+ * or any portion thereof may not be reproduced in any form whatsoever without
7
+ * the written consent of Vaimo, except as provided by licence. A licence
8
+ * under Vaimo's rights in the Program may be available directly from
9
+ * Vaimo.
10
+ *
11
+ * Disclaimer:
12
+ * THIS NOTICE MAY NOT BE REMOVED FROM THE PROGRAM BY ANY USER THEREOF.
13
+ * THE PROGRAM IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
14
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
16
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ * OUT OF OR IN CONNECTION WITH THE PROGRAM OR THE USE OR OTHER DEALINGS
19
+ * IN THE PROGRAM.
20
+ *
21
+ * @category Vaimo
22
+ * @package Vaimo_Klarna
23
+ * @copyright Copyright (c) 2009-2014 Vaimo AB
24
+ */
25
+
26
+ $button_name = $this->getBackButtonName();
27
+
28
+ ?>
29
+
30
+ <?php if ($this->isButtonEnabled()==false) return; ?>
31
+
32
+ <ul id="payment_form_<?php echo $this->getMethodCode(); ?>" class="form-list">
33
+
34
+ <li class="klarna_kcomethod">
35
+
36
+ <?php if ($this->isButtonNameUrl($button_name)): ?>
37
+ <a href="#" onclick="klarnaCheckoutGo('<?php echo $this->getUrl('checkout/klarna/kcomethod') ?>')"><span><span><img src="<?php echo $button_name?>"/></span></span></a>
38
+ <?php else: ?>
39
+ <a href="#" class="button" onclick="klarnaCheckoutGo('<?php echo $this->getUrl('checkout/klarna/kcomethod') ?>')"><span><span><?php echo $button_name?></span></span></a>
40
+ <?php endif; ?>
41
+
42
+ </li>
43
+
44
+ </ul>
45
+
app/design/frontend/base/default/template/vaimo/klarna/info/checkout.phtml ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Copyright (c) 2009-2014 Vaimo AB
4
+ *
5
+ * Vaimo reserves all rights in the Program as delivered. The Program
6
+ * or any portion thereof may not be reproduced in any form whatsoever without
7
+ * the written consent of Vaimo, except as provided by licence. A licence
8
+ * under Vaimo's rights in the Program may be available directly from
9
+ * Vaimo.
10
+ *
11
+ * Disclaimer:
12
+ * THIS NOTICE MAY NOT BE REMOVED FROM THE PROGRAM BY ANY USER THEREOF.
13
+ * THE PROGRAM IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
14
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
16
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ * OUT OF OR IN CONNECTION WITH THE PROGRAM OR THE USE OR OTHER DEALINGS
19
+ * IN THE PROGRAM.
20
+ *
21
+ * @category Vaimo
22
+ * @package Vaimo_Klarna
23
+ * @copyright Copyright (c) 2009-2014 Vaimo AB
24
+ */
25
+ ?>
26
+
27
+ <table>
28
+ <tbody>
29
+ <tr>
30
+ <th align="left"><?php echo '<img src="' . $this->getKlarnaLogotype(125) . '" alt="' . Mage::helper('klarna')->__($this->getMethodTitle()) . '"/>'; ?></th>
31
+ </tr>
32
+ <?php echo $this->getInvoicesHtml(); ?>
33
+ </tbody>
34
+ </table>
app/design/frontend/base/default/template/vaimo/klarna/klarnacheckout/autofill.phtml ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Copyright (c) 2009-2014 Vaimo AB
4
+ *
5
+ * Vaimo reserves all rights in the Program as delivered. The Program
6
+ * or any portion thereof may not be reproduced in any form whatsoever without
7
+ * the written consent of Vaimo, except as provided by licence. A licence
8
+ * under Vaimo's rights in the Program may be available directly from
9
+ * Vaimo.
10
+ *
11
+ * Disclaimer:
12
+ * THIS NOTICE MAY NOT BE REMOVED FROM THE PROGRAM BY ANY USER THEREOF.
13
+ * THE PROGRAM IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
14
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
16
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ * OUT OF OR IN CONNECTION WITH THE PROGRAM OR THE USE OR OTHER DEALINGS
19
+ * IN THE PROGRAM.
20
+ *
21
+ * @category Vaimo
22
+ * @package Vaimo_Klarna
23
+ * @copyright Copyright (c) 2009-2014 Vaimo AB
24
+ */
25
+ ?>
26
+
27
+ <?php if ($this->getDisplayAutofill()): ?>
28
+ <?php $termsLink = $this->getTermsLink(); ?>
29
+ <?php echo $this->helper('klarna')->__('For an easy checkout, I consent to use the data saved in my account with the new Klarna Checkout according to the %s', $termsLink) ?>
30
+ <?php endif; ?>
app/design/frontend/base/default/template/vaimo/klarna/klarnacheckout/cart.phtml ADDED
@@ -0,0 +1,107 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Copyright (c) 2009-2014 Vaimo AB
4
+ *
5
+ * Vaimo reserves all rights in the Program as delivered. The Program
6
+ * or any portion thereof may not be reproduced in any form whatsoever without
7
+ * the written consent of Vaimo, except as provided by licence. A licence
8
+ * under Vaimo's rights in the Program may be available directly from
9
+ * Vaimo.
10
+ *
11
+ * Disclaimer:
12
+ * THIS NOTICE MAY NOT BE REMOVED FROM THE PROGRAM BY ANY USER THEREOF.
13
+ * THE PROGRAM IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
14
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
16
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ * OUT OF OR IN CONNECTION WITH THE PROGRAM OR THE USE OR OTHER DEALINGS
19
+ * IN THE PROGRAM.
20
+ *
21
+ * @category Vaimo
22
+ * @package Vaimo_Klarna
23
+ * @copyright Copyright (c) 2009-2014 Vaimo AB
24
+ */
25
+ ?>
26
+
27
+ <?php if (Mage::helper('klarna')->excludeCartInKlarnaCheckout()) : ?>
28
+ <form id="klarna_cart" action="<?php echo $this->getUrl('checkout/klarna/cartUpdatePost') ?>" method="post">
29
+ <input type="hidden" name="return_url" value="<?php echo $this->getUrl('checkout/klarna') ?>"/>
30
+ <!-- <input type="hidden" id="klarna_cart_reload" name="klarna_cart_reload" value="<?php //echo $this->getUrl('checkout/klarna/getKlarnaWrapperHtml') ?>"/> -->
31
+ <input type="hidden" id="klarna_checkout_reload" name="klarna_checkout_reload" value="<?php echo $this->getUrl('checkout/klarna/getKlarnaCheckout') ?>"/>
32
+
33
+ </form>
34
+ <?php else: ?>
35
+ <?php if(!$this->hasError()): ?>
36
+ <ul class="checkout-types">
37
+ <?php foreach ($this->getMethods('top_methods') as $method): ?>
38
+ <?php if ($methodHtml = $this->getMethodHtml($method)): ?>
39
+ <li><?php echo $methodHtml; ?></li>
40
+ <?php endif; ?>
41
+ <?php endforeach; ?>
42
+ </ul>
43
+ <?php endif; ?>
44
+
45
+ <?php echo $this->getChildHtml('form_before') ?>
46
+
47
+ <form id="klarna_cart" action="<?php echo $this->getUrl('checkout/klarna/cartUpdatePost') ?>" method="post">
48
+
49
+ <input type="hidden" name="return_url" value="<?php echo $this->getUrl('checkout/klarna') ?>"/>
50
+ <input type="hidden" id="klarna_cart_reload" name="klarna_cart_reload" value="<?php echo $this->getUrl('checkout/klarna/getKlarnaWrapperHtml') ?>"/>
51
+ <input type="hidden" id="klarna_checkout_reload" name="klarna_checkout_reload" value="<?php echo $this->getUrl('checkout/klarna/getKlarnaCheckout') ?>"/>
52
+
53
+ <table id="cart_table">
54
+
55
+ <?php $mergedCells = ($this->helper('tax')->displayCartBothPrices() ? 2 : 1); ?>
56
+ <thead>
57
+ <tr>
58
+ <th colspan="<?php echo $mergedCells; ?>"></th>
59
+ <th rowspan="<?php echo $mergedCells; ?>"></th>
60
+ <th rowspan="<?php echo $mergedCells; ?>"><?php echo $this->__('Product Name') ?></th>
61
+ <th colspan="<?php echo $mergedCells; ?>"><?php echo $this->__('Unit Price') ?></th>
62
+ <th class="qty" colspan="<?php echo $mergedCells; ?>"><?php echo $this->__('Qty') ?></th>
63
+ <th colspan="<?php echo $mergedCells; ?>"><?php echo $this->__('Subtotal') ?></th>
64
+ </tr>
65
+
66
+ <?php if ($this->helper('tax')->displayCartBothPrices()): ?>
67
+ <tr>
68
+ <th class="a-right"><?php echo $this->helper('tax')->getIncExcTaxLabel(false) ?></th>
69
+ <th><?php echo $this->helper('tax')->getIncExcTaxLabel(true) ?></th>
70
+ <th class="a-right"><?php echo $this->helper('tax')->getIncExcTaxLabel(false) ?></th>
71
+ <th><?php echo $this->helper('tax')->getIncExcTaxLabel(true) ?></th>
72
+ </tr>
73
+ <?php endif; ?>
74
+ </thead>
75
+
76
+ <?php if($this->getContinueShoppingUrl()): ?>
77
+ <tfoot>
78
+ <tr>
79
+ <td colspan="6">
80
+ <a href="<?php echo $this->getContinueShoppingUrl() ?>" title="<?php echo $this->__('Continue Shopping') ?>">&lt;&lt; <?php echo $this->__('Continue Shopping') ?></a>
81
+ </td>
82
+ </tr>
83
+ </tfoot>
84
+ <?php endif; ?>
85
+
86
+ <tbody>
87
+ <?php foreach($this->getItems() as $_item): ?>
88
+ <?php echo $this->getItemHtml($_item) ?>
89
+ <?php endforeach ?>
90
+ </tbody>
91
+
92
+ </table>
93
+ <script type="text/javascript">decorateTable('cart_table')</script>
94
+ </form>
95
+
96
+ <?php echo $this->getChildHtml('totals'); ?>
97
+
98
+ <?php if(!$this->hasError()): ?>
99
+ <ul class="checkout-types">
100
+ <?php foreach ($this->getMethods('methods') as $method): ?>
101
+ <?php if ($methodHtml = $this->getMethodHtml($method)): ?>
102
+ <li><?php echo $methodHtml; ?></li>
103
+ <?php endif; ?>
104
+ <?php endforeach; ?>
105
+ </ul>
106
+ <?php endif; ?>
107
+ <?php endif; ?>
app/design/frontend/base/default/template/vaimo/klarna/klarnacheckout/cart/item/default.phtml ADDED
@@ -0,0 +1,282 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Copyright (c) 2009-2014 Vaimo AB
4
+ *
5
+ * Vaimo reserves all rights in the Program as delivered. The Program
6
+ * or any portion thereof may not be reproduced in any form whatsoever without
7
+ * the written consent of Vaimo, except as provided by licence. A licence
8
+ * under Vaimo's rights in the Program may be available directly from
9
+ * Vaimo.
10
+ *
11
+ * Disclaimer:
12
+ * THIS NOTICE MAY NOT BE REMOVED FROM THE PROGRAM BY ANY USER THEREOF.
13
+ * THE PROGRAM IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
14
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
16
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ * OUT OF OR IN CONNECTION WITH THE PROGRAM OR THE USE OR OTHER DEALINGS
19
+ * IN THE PROGRAM.
20
+ *
21
+ * @category Vaimo
22
+ * @package Vaimo_Klarna
23
+ * @copyright Copyright (c) 2009-2014 Vaimo AB
24
+ */
25
+
26
+ $_item = $this->getItem();
27
+ $isVisibleProduct = $_item->getProduct()->isVisibleInSiteVisibility();
28
+ if (version_compare(Mage::getVersion(), '1.7.0', '<') || ((version_compare(Mage::getVersion(), '1.10.0')>=0) && (version_compare(Mage::getVersion(), '1.11.0')<0))) {
29
+ $canApplyMsrp = false;
30
+ } else {
31
+ $canApplyMsrp = Mage::helper('catalog')->canApplyMsrp($_item->getProduct(), Mage_Catalog_Model_Product_Attribute_Source_Msrp_Type::TYPE_BEFORE_ORDER_CONFIRM);
32
+ }
33
+
34
+ ?>
35
+
36
+ <tr id="cart_item_<?php echo $_item->getId(); ?>" data-itemid="<?php echo $_item->getId(); ?>">
37
+ <td><a href="#" class="remove-item" title="<?php echo $this->__('Remove item')?>" data-itemid="<?php echo $_item->getId(); ?>"><?php echo $this->__('Remove item')?></a></td>
38
+ <td><?php if ($this->hasProductUrl()):?><a href="<?php echo $this->getProductUrl() ?>" title="<?php echo $this->htmlEscape($this->getProductName()) ?>" class="product-image"><?php endif;?><img src="<?php echo $this->getProductThumbnail()->resize(59); ?>" width="59" height="59" alt="<?php echo $this->htmlEscape($this->getProductName()) ?>" /><?php if ($this->hasProductUrl()):?></a><?php endif;?></td>
39
+ <td class="product_name">
40
+ <?php if ($this->hasProductUrl()):?>
41
+ <a href="<?php echo $this->getProductUrl() ?>"><?php echo $this->htmlEscape($this->getProductName()) ?></a>
42
+ <?php else: ?>
43
+ <?php echo $this->htmlEscape($this->getProductName()) ?>
44
+ <?php endif; ?>
45
+ <?php if ($_options = $this->getOptionList()):?>
46
+ <dl class="item-options">
47
+ <?php foreach ($_options as $_option) : ?>
48
+ <?php $_formatedOptionValue = $this->getFormatedOptionValue($_option) ?>
49
+ <dt><?php echo $this->htmlEscape($_option['label']) ?></dt>
50
+ <dd<?php if (isset($_formatedOptionValue['full_view'])): ?> class="truncated"<?php endif; ?>><?php echo $_formatedOptionValue['value'] ?>
51
+ <?php if (isset($_formatedOptionValue['full_view'])): ?>
52
+ <div class="truncated_full_value">
53
+ <dl class="item-options">
54
+ <dt><?php echo $this->htmlEscape($_option['label']) ?></dt>
55
+ <dd><?php echo $_formatedOptionValue['full_view'] ?></dd>
56
+ </dl>
57
+ </div>
58
+ <?php endif; ?>
59
+ </dd>
60
+ <?php endforeach; ?>
61
+ </dl>
62
+ <?php endif;?>
63
+ <?php if ($messages = $this->getMessages()): ?>
64
+ <?php foreach ($messages as $message): ?>
65
+ <p class="item-msg <?php echo $message['type'] ?>">* <?php echo $this->escapeHtml($message['text']) ?></p>
66
+ <?php endforeach; ?>
67
+ <?php endif; ?>
68
+ <?php $addInfoBlock = $this->getProductAdditionalInformationBlock(); ?>
69
+ <?php if ($addInfoBlock): ?>
70
+ <?php echo $addInfoBlock->setItem($_item)->toHtml() ?>
71
+ <?php endif;?>
72
+ </td>
73
+ <?php if (false): ?>
74
+ <td class="a-center">
75
+ <?php if ($isVisibleProduct): ?>
76
+ <a href="<?php echo $this->getConfigureUrl() ?>" title="<?php echo $this->__('Edit item parameters') ?>"><?php echo $this->__('Edit') ?></a>
77
+ <?php endif ?>
78
+ </td>
79
+ <?php endif; ?>
80
+
81
+ <?php if ($canApplyMsrp): ?>
82
+ <td class="a-right"<?php if ($this->helper('tax')->displayCartBothPrices()): ?> colspan="2"<?php endif; ?>>
83
+ <span class="cart-price">
84
+ <span class="cart-msrp-unit"><?php echo $this->__('See price before order confirmation.'); ?></span>
85
+ <?php $helpLinkId = 'cart-msrp-help-' . $_item->getId(); ?>
86
+ <a id="<?php echo $helpLinkId ?>" href="#" class="map-help-link"><?php echo $this->__("What's this?"); ?></a>
87
+ <script type="text/javascript">
88
+ Catalog.Map.addHelpLink($('<?php echo $helpLinkId ?>'), "<?php echo $this->__("What's this?") ?>");
89
+ </script>
90
+ </span>
91
+ </td>
92
+ <?php else: ?>
93
+
94
+ <?php if ($this->helper('tax')->displayCartPriceExclTax() || $this->helper('tax')->displayCartBothPrices()): ?>
95
+ <td class="a-right">
96
+ <?php if (Mage::helper('weee')->typeOfDisplay($_item, array(1, 4), 'sales') && $_item->getWeeeTaxAppliedAmount()): ?>
97
+ <span class="cart-tax-total" onclick="taxToggle('eunit-item-tax-details<?php echo $_item->getId(); ?>', this, 'cart-tax-total-expanded');">
98
+ <?php else: ?>
99
+ <span class="cart-price">
100
+ <?php endif; ?>
101
+ <?php if (Mage::helper('weee')->typeOfDisplay($_item, array(0, 1, 4), 'sales') && $_item->getWeeeTaxAppliedAmount()): ?>
102
+ <?php echo $this->helper('checkout')->formatPrice($_item->getCalculationPrice()+$_item->getWeeeTaxAppliedAmount()+$_item->getWeeeTaxDisposition()); ?>
103
+ <?php else: ?>
104
+ <?php echo $this->helper('checkout')->formatPrice($_item->getCalculationPrice()) ?>
105
+ <?php endif; ?>
106
+
107
+ </span>
108
+
109
+
110
+ <?php if (Mage::helper('weee')->getApplied($_item)): ?>
111
+
112
+ <div class="cart-tax-info" id="eunit-item-tax-details<?php echo $_item->getId(); ?>" style="display:none;">
113
+ <?php if (Mage::helper('weee')->typeOfDisplay($_item, 1, 'sales') && $_item->getWeeeTaxAppliedAmount()): ?>
114
+ <?php foreach (Mage::helper('weee')->getApplied($_item) as $tax): ?>
115
+ <span class="weee"><?php echo $tax['title']; ?>: <?php echo Mage::helper('checkout')->formatPrice($tax['amount'],true,true); ?></span>
116
+ <?php endforeach; ?>
117
+ <?php elseif (Mage::helper('weee')->typeOfDisplay($_item, 2, 'sales') && $_item->getWeeeTaxAppliedAmount()): ?>
118
+ <?php foreach (Mage::helper('weee')->getApplied($_item) as $tax): ?>
119
+ <span class="weee"><?php echo $tax['title']; ?>: <?php echo Mage::helper('checkout')->formatPrice($tax['amount_incl_tax'],true,true); ?></span>
120
+ <?php endforeach; ?>
121
+ <?php elseif (Mage::helper('weee')->typeOfDisplay($_item, 4, 'sales') && $_item->getWeeeTaxAppliedAmount()): ?>
122
+ <?php foreach (Mage::helper('weee')->getApplied($_item) as $tax): ?>
123
+ <span class="weee"><?php echo $tax['title']; ?>: <?php echo Mage::helper('checkout')->formatPrice($tax['amount_incl_tax'],true,true); ?></span>
124
+ <?php endforeach; ?>
125
+ <?php endif; ?>
126
+ </div>
127
+
128
+ <?php if (Mage::helper('weee')->typeOfDisplay($_item, 2, 'sales') && $_item->getWeeeTaxAppliedAmount()): ?>
129
+ <div class="cart-tax-total" onclick="taxToggle('eunit-item-tax-details<?php echo $_item->getId(); ?>', this, 'cart-tax-total-expanded');">
130
+ <span class="weee"><?php echo Mage::helper('weee')->__('Total'); ?>: <?php echo $this->helper('checkout')->formatPrice($_item->getCalculationPrice()+$_item->getWeeeTaxAppliedAmount()+$_item->getWeeeTaxDisposition()); ?></span>
131
+ </div>
132
+ <?php endif; ?>
133
+ <?php endif; ?>
134
+ </td>
135
+ <?php endif; ?>
136
+ <?php if ($this->helper('tax')->displayCartPriceInclTax() || $this->helper('tax')->displayCartBothPrices()): ?>
137
+ <td>
138
+ <?php $_incl = $this->helper('checkout')->getPriceInclTax($_item); ?>
139
+ <?php if (Mage::helper('weee')->typeOfDisplay($_item, array(1, 4), 'sales') && $_item->getWeeeTaxAppliedAmount()): ?>
140
+ <span class="cart-tax-total" onclick="taxToggle('unit-item-tax-details<?php echo $_item->getId(); ?>', this, 'cart-tax-total-expanded');">
141
+ <?php else: ?>
142
+ <span class="cart-price">
143
+ <?php endif; ?>
144
+
145
+ <?php if (Mage::helper('weee')->typeOfDisplay($_item, array(0, 1, 4), 'sales') && $_item->getWeeeTaxAppliedAmount()): ?>
146
+ <?php echo $this->helper('checkout')->formatPrice($_incl+$_item->getWeeeTaxAppliedAmount()); ?>
147
+ <?php else: ?>
148
+ <?php echo $this->helper('checkout')->formatPrice($_incl-$_item->getWeeeTaxDisposition()) ?>
149
+ <?php endif; ?>
150
+
151
+ </span>
152
+ <?php if (Mage::helper('weee')->getApplied($_item)): ?>
153
+
154
+ <div class="cart-tax-info" id="unit-item-tax-details<?php echo $_item->getId(); ?>" style="display:none;">
155
+ <?php if (Mage::helper('weee')->typeOfDisplay($_item, 1, 'sales') && $_item->getWeeeTaxAppliedAmount()): ?>
156
+ <?php foreach (Mage::helper('weee')->getApplied($_item) as $tax): ?>
157
+ <span class="weee"><?php echo $tax['title']; ?>: <?php echo Mage::helper('checkout')->formatPrice($tax['amount'],true,true); ?></span>
158
+ <?php endforeach; ?>
159
+ <?php elseif (Mage::helper('weee')->typeOfDisplay($_item, 2, 'sales') && $_item->getWeeeTaxAppliedAmount()): ?>
160
+ <?php foreach (Mage::helper('weee')->getApplied($_item) as $tax): ?>
161
+ <span class="weee"><?php echo $tax['title']; ?>: <?php echo Mage::helper('checkout')->formatPrice($tax['amount_incl_tax'],true,true); ?></span>
162
+ <?php endforeach; ?>
163
+ <?php elseif (Mage::helper('weee')->typeOfDisplay($_item, 4, 'sales') && $_item->getWeeeTaxAppliedAmount()): ?>
164
+ <?php foreach (Mage::helper('weee')->getApplied($_item) as $tax): ?>
165
+ <span class="weee"><?php echo $tax['title']; ?>: <?php echo Mage::helper('checkout')->formatPrice($tax['amount_incl_tax'],true,true); ?></span>
166
+ <?php endforeach; ?>
167
+ <?php endif; ?>
168
+ </div>
169
+
170
+ <?php if (Mage::helper('weee')->typeOfDisplay($_item, 2, 'sales') && $_item->getWeeeTaxAppliedAmount()): ?>
171
+ <div class="cart-tax-total" onclick="taxToggle('unit-item-tax-details<?php echo $_item->getId(); ?>', this, 'cart-tax-total-expanded');">
172
+ <span class="weee"><?php echo Mage::helper('weee')->__('Total incl. tax'); ?>: <?php echo $this->helper('checkout')->formatPrice($_incl+$_item->getWeeeTaxAppliedAmount()); ?></span>
173
+ </div>
174
+ <?php endif; ?>
175
+ <?php endif; ?>
176
+ </td>
177
+ <?php endif; ?>
178
+ <?php endif; ?>
179
+ <td class="qty">
180
+ <?php if (true): ?>
181
+ <a href="#" class="subtract-item" data-itemid="<?php echo $_item->getId(); ?>"><?php echo $this->__('Subtract item')?></a>
182
+ <?php endif; ?>
183
+ <input id="cart_item_qty_<?php echo $_item->getId(); ?>" class="qty-input" name="cart[<?php echo $_item->getId() ?>][qty]" data-itemid="<?php echo $_item->getId(); ?>" value="<?php echo $this->getQty() ?>" size="4" title="<?php echo $this->__('Qty') ?>" maxlength="12" />
184
+ <input type="hidden" id="cart_item_qty_org_<?php echo $_item->getId(); ?>" name="org_qty_<?php echo $_item->getId() ?>" class="org_qty_<?php echo $_item->getId(); ?>" data-itemid="<?php echo $_item->getId(); ?>" value="<?php echo $this->getQty() ?>" />
185
+ <?php if (true): ?>
186
+ <a href="#" class="add-item" data-itemid="<?php echo $_item->getId(); ?>"><?php echo $this->__('Add item')?></a>
187
+ <?php endif; ?>
188
+ </td>
189
+ <?php if (($this->helper('tax')->displayCartPriceExclTax() || $this->helper('tax')->displayCartBothPrices()) && !$_item->getNoSubtotal()): ?>
190
+ <td class="a-right">
191
+ <?php if (Mage::helper('weee')->typeOfDisplay($_item, array(1, 4), 'sales') && $_item->getWeeeTaxAppliedAmount()): ?>
192
+ <span class="cart-tax-total" onclick="taxToggle('esubtotal-item-tax-details<?php echo $_item->getId(); ?>', this, 'cart-tax-total-expanded');">
193
+ <?php else: ?>
194
+ <span class="cart-price">
195
+ <?php endif; ?>
196
+
197
+ <?php if ($canApplyMsrp): ?>
198
+ <span class="cart-msrp-subtotal">--</span>
199
+ <?php else: ?>
200
+ <?php if (Mage::helper('weee')->typeOfDisplay($_item, array(0, 1, 4), 'sales') && $_item->getWeeeTaxAppliedAmount()): ?>
201
+ <?php echo $this->helper('checkout')->formatPrice($_item->getRowTotal()+$_item->getWeeeTaxAppliedRowAmount()+$_item->getWeeeTaxRowDisposition()); ?>
202
+ <?php else: ?>
203
+ <?php echo $this->helper('checkout')->formatPrice($_item->getRowTotal()) ?>
204
+ <?php endif; ?>
205
+ <?php endif; ?>
206
+
207
+ </span>
208
+ <?php if (Mage::helper('weee')->getApplied($_item)): ?>
209
+
210
+ <div class="cart-tax-info" id="esubtotal-item-tax-details<?php echo $_item->getId(); ?>" style="display:none;">
211
+ <?php if (Mage::helper('weee')->typeOfDisplay($_item, 1, 'sales') && $_item->getWeeeTaxAppliedAmount()): ?>
212
+ <?php foreach (Mage::helper('weee')->getApplied($_item) as $tax): ?>
213
+ <span class="weee"><?php echo $tax['title']; ?>: <?php echo Mage::helper('checkout')->formatPrice($tax['row_amount'],true,true); ?></span>
214
+ <?php endforeach; ?>
215
+ <?php elseif (Mage::helper('weee')->typeOfDisplay($_item, 2, 'sales') && $_item->getWeeeTaxAppliedAmount()): ?>
216
+ <?php foreach (Mage::helper('weee')->getApplied($_item) as $tax): ?>
217
+ <span class="weee"><?php echo $tax['title']; ?>: <?php echo Mage::helper('checkout')->formatPrice($tax['row_amount_incl_tax'],true,true); ?></span>
218
+ <?php endforeach; ?>
219
+ <?php elseif (Mage::helper('weee')->typeOfDisplay($_item, 4, 'sales') && $_item->getWeeeTaxAppliedAmount()): ?>
220
+ <?php foreach (Mage::helper('weee')->getApplied($_item) as $tax): ?>
221
+ <span class="weee"><?php echo $tax['title']; ?>: <?php echo Mage::helper('checkout')->formatPrice($tax['row_amount_incl_tax'],true,true); ?></span>
222
+ <?php endforeach; ?>
223
+ <?php endif; ?>
224
+ </div>
225
+
226
+ <?php if (Mage::helper('weee')->typeOfDisplay($_item, 2, 'sales') && $_item->getWeeeTaxAppliedAmount()): ?>
227
+ <div class="cart-tax-total" onclick="taxToggle('esubtotal-item-tax-details<?php echo $_item->getId(); ?>', this, 'cart-tax-total-expanded');">
228
+ <span class="weee"><?php echo Mage::helper('weee')->__('Total'); ?>: <?php echo $this->helper('checkout')->formatPrice($_item->getRowTotal()+$_item->getWeeeTaxAppliedRowAmount()+$_item->getWeeeTaxRowDisposition()); ?></span>
229
+ </div>
230
+ <?php endif; ?>
231
+ <?php endif; ?>
232
+ </td>
233
+ <?php endif; ?>
234
+ <?php if (($this->helper('tax')->displayCartPriceInclTax() || $this->helper('tax')->displayCartBothPrices()) && !$_item->getNoSubtotal()): ?>
235
+ <td>
236
+ <?php $_incl = $this->helper('checkout')->getSubtotalInclTax($_item); ?>
237
+ <?php if (Mage::helper('weee')->typeOfDisplay($_item, array(1, 4), 'sales') && $_item->getWeeeTaxAppliedAmount()): ?>
238
+ <span class="cart-tax-total" onclick="taxToggle('subtotal-item-tax-details<?php echo $_item->getId(); ?>', this, 'cart-tax-total-expanded');">
239
+ <?php else: ?>
240
+ <span class="cart-price">
241
+ <?php endif; ?>
242
+
243
+ <?php if ($canApplyMsrp): ?>
244
+ <span class="cart-msrp-subtotal">--</span>
245
+ <?php else: ?>
246
+ <?php if (Mage::helper('weee')->typeOfDisplay($_item, array(0, 1, 4), 'sales') && $_item->getWeeeTaxAppliedAmount()): ?>
247
+ <?php echo $this->helper('checkout')->formatPrice($_incl+$_item->getWeeeTaxAppliedRowAmount()); ?>
248
+ <?php else: ?>
249
+ <?php echo $this->helper('checkout')->formatPrice($_incl-$_item->getWeeeTaxRowDisposition()) ?>
250
+ <?php endif; ?>
251
+ <?php endif; ?>
252
+
253
+ </span>
254
+
255
+
256
+ <?php if (Mage::helper('weee')->getApplied($_item)): ?>
257
+
258
+ <div class="cart-tax-info" id="subtotal-item-tax-details<?php echo $_item->getId(); ?>" style="display:none;">
259
+ <?php if (Mage::helper('weee')->typeOfDisplay($_item, 1, 'sales') && $_item->getWeeeTaxAppliedAmount()): ?>
260
+ <?php foreach (Mage::helper('weee')->getApplied($_item) as $tax): ?>
261
+ <span class="weee"><?php echo $tax['title']; ?>: <?php echo Mage::helper('checkout')->formatPrice($tax['row_amount'],true,true); ?></span>
262
+ <?php endforeach; ?>
263
+ <?php elseif (Mage::helper('weee')->typeOfDisplay($_item, 2, 'sales') && $_item->getWeeeTaxAppliedAmount()): ?>
264
+ <?php foreach (Mage::helper('weee')->getApplied($_item) as $tax): ?>
265
+ <span class="weee"><?php echo $tax['title']; ?>: <?php echo Mage::helper('checkout')->formatPrice($tax['row_amount_incl_tax'],true,true); ?></span>
266
+ <?php endforeach; ?>
267
+ <?php elseif (Mage::helper('weee')->typeOfDisplay($_item, 4, 'sales') && $_item->getWeeeTaxAppliedAmount()): ?>
268
+ <?php foreach (Mage::helper('weee')->getApplied($_item) as $tax): ?>
269
+ <span class="weee"><?php echo $tax['title']; ?>: <?php echo Mage::helper('checkout')->formatPrice($tax['row_amount_incl_tax'],true,true); ?></span>
270
+ <?php endforeach; ?>
271
+ <?php endif; ?>
272
+ </div>
273
+
274
+ <?php if (Mage::helper('weee')->typeOfDisplay($_item, 2, 'sales') && $_item->getWeeeTaxAppliedAmount()): ?>
275
+ <div class="cart-tax-total" onclick="taxToggle('subtotal-item-tax-details<?php echo $_item->getId(); ?>', this, 'cart-tax-total-expanded');">
276
+ <span class="weee"><?php echo Mage::helper('weee')->__('Total incl. tax'); ?>: <?php echo $this->helper('checkout')->formatPrice($_incl+$_item->getWeeeTaxAppliedRowAmount()); ?></span>
277
+ </div>
278
+ <?php endif; ?>
279
+ <?php endif; ?>
280
+ </td>
281
+ <?php endif; ?>
282
+ </tr>
app/design/frontend/base/default/template/vaimo/klarna/klarnacheckout/cart/totals.phtml ADDED
@@ -0,0 +1,57 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Copyright (c) 2009-2014 Vaimo AB
4
+ *
5
+ * Vaimo reserves all rights in the Program as delivered. The Program
6
+ * or any portion thereof may not be reproduced in any form whatsoever without
7
+ * the written consent of Vaimo, except as provided by licence. A licence
8
+ * under Vaimo's rights in the Program may be available directly from
9
+ * Vaimo.
10
+ *
11
+ * Disclaimer:
12
+ * THIS NOTICE MAY NOT BE REMOVED FROM THE PROGRAM BY ANY USER THEREOF.
13
+ * THE PROGRAM IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
14
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
16
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ * OUT OF OR IN CONNECTION WITH THE PROGRAM OR THE USE OR OTHER DEALINGS
19
+ * IN THE PROGRAM.
20
+ *
21
+ * @category Vaimo
22
+ * @package Vaimo_Klarna
23
+ * @copyright Copyright (c) 2009-2014 Vaimo AB
24
+ */
25
+
26
+ /**
27
+ * Shopping cart totals template
28
+ *
29
+ * @see Mage_Checkout_Block_Cart_Totals
30
+ * @var $this Mage_Checkout_Block_Cart_Totals
31
+ */
32
+ ?>
33
+
34
+ <?php if (Mage::helper('klarna')->excludeCartInKlarnaCheckout()) return; ?>
35
+
36
+ <div id="klarna_totals">
37
+ <?php
38
+ if (version_compare(Mage::getVersion(), '1.7.0', '<') || ((version_compare(Mage::getVersion(), '1.10.0')>=0) && (version_compare(Mage::getVersion(), '1.11.0')<0))) {
39
+ $canApplyMsrp = false;
40
+ } else {
41
+ $canApplyMsrp = $this->canApplyMsrp();
42
+ }
43
+ ?>
44
+ <?php if ($canApplyMsrp): ?>
45
+ <div class="cart-msrp-totals"><?php echo $this->__('ORDER TOTAL WILL BE DISPLAYED BEFORE YOU SUBMIT THE ORDER'); ?></div>
46
+ <?php else: ?>
47
+ <table>
48
+ <tfoot>
49
+ <?php echo $this->renderTotals('footer'); ?>
50
+ </tfoot>
51
+ <tbody>
52
+ <?php echo $this->renderTotals(); ?>
53
+ </tbody>
54
+ </table>
55
+ <?php endif; ?>
56
+
57
+ </div>
app/design/frontend/base/default/template/vaimo/klarna/klarnacheckout/customer/balance.phtml ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Copyright (c) 2009-2014 Vaimo AB
4
+ *
5
+ * Vaimo reserves all rights in the Program as delivered. The Program
6
+ * or any portion thereof may not be reproduced in any form whatsoever without
7
+ * the written consent of Vaimo, except as provided by licence. A licence
8
+ * under Vaimo's rights in the Program may be available directly from
9
+ * Vaimo.
10
+ *
11
+ * Disclaimer:
12
+ * THIS NOTICE MAY NOT BE REMOVED FROM THE PROGRAM BY ANY USER THEREOF.
13
+ * THE PROGRAM IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
14
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
16
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ * OUT OF OR IN CONNECTION WITH THE PROGRAM OR THE USE OR OTHER DEALINGS
19
+ * IN THE PROGRAM.
20
+ *
21
+ * @category Vaimo
22
+ * @package Vaimo_Klarna
23
+ * @copyright Copyright (c) 2009-2014 Vaimo AB
24
+ */
25
+ ?>
26
+
27
+ <?php if ($this->isDisplayContainer()): ?>
28
+ <div class="checkout-onepage-payment-additional-customerbalance" id="customerbalance_placer">
29
+ <form id="klarna-checkout-customer-balance" action="<?php echo $this->getUrl('checkout/klarna/customerBalancePost') ?>" method="post">
30
+ <input type="hidden" name="payment[use_customer_balance]" value="0" />
31
+ <input type="checkbox" class="checkbox" name="use_customer_balance" value="1" id="use_customer_balance" <?php echo ($this->isCustomerBalanceUsed() ? 'checked' : '') ?>/>
32
+
33
+ <?php $balance = Mage::helper('core')->currency($this->getBalance()); ?>
34
+ <label for="use_customer_balance">
35
+ <strong>
36
+ <?php echo Mage::helper('enterprise_customerbalance')->__('Use Store Credit'); ?>
37
+ (<span id="customerbalance_available_amount"><?php echo $balance; ?></span>
38
+ <?php echo Mage::helper('enterprise_customerbalance')->__('available'); ?>)
39
+ </strong>
40
+ </label>
41
+ </form>
42
+ </div>
43
+ <?php endif; ?>
app/{code/community/Vaimo/Klarna/Model/Klarna/Addresssearch.php → design/frontend/base/default/template/vaimo/klarna/klarnacheckout/discount.phtml} RENAMED
@@ -22,13 +22,14 @@
22
  * @package Vaimo_Klarna
23
  * @copyright Copyright (c) 2009-2014 Vaimo AB
24
  */
 
25
 
26
- class Vaimo_Klarna_Model_Klarna_Addresssearch extends Vaimo_Klarna_Model_Klarna_Api
27
- {
28
- public function __construct($klarnaApi = null, $payment = null)
29
- {
30
- parent::__construct($klarnaApi, $payment);
31
- $this->_setFunctionName('address');
32
- }
33
 
34
- }
 
 
 
 
 
 
22
  * @package Vaimo_Klarna
23
  * @copyright Copyright (c) 2009-2014 Vaimo AB
24
  */
25
+ ?>
26
 
27
+ <?php if (Mage::helper('klarna')->excludeCartInKlarnaCheckout()) return; ?>
 
 
 
 
 
 
28
 
29
+ <div id="klarna_discount">
30
+ <?php echo $this->getChildHtml('coupon') ?>
31
+
32
+ <div id="checkout-giftcards-load">
33
+ <?php echo $this->getChildHtml('giftcards') ?>
34
+ </div>
35
+ </div>
app/design/frontend/base/default/template/vaimo/klarna/klarnacheckout/discount/coupon.phtml ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Copyright (c) 2009-2014 Vaimo AB
4
+ *
5
+ * Vaimo reserves all rights in the Program as delivered. The Program
6
+ * or any portion thereof may not be reproduced in any form whatsoever without
7
+ * the written consent of Vaimo, except as provided by licence. A licence
8
+ * under Vaimo's rights in the Program may be available directly from
9
+ * Vaimo.
10
+ *
11
+ * Disclaimer:
12
+ * THIS NOTICE MAY NOT BE REMOVED FROM THE PROGRAM BY ANY USER THEREOF.
13
+ * THE PROGRAM IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
14
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
16
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ * OUT OF OR IN CONNECTION WITH THE PROGRAM OR THE USE OR OTHER DEALINGS
19
+ * IN THE PROGRAM.
20
+ *
21
+ * @category Vaimo
22
+ * @package Vaimo_Klarna
23
+ * @copyright Copyright (c) 2009-2014 Vaimo AB
24
+ */
25
+ ?>
26
+
27
+ <div class="coupon">
28
+
29
+ <h3><?php echo $this->__('Coupon') ?> <label for="coupon_code"><?php echo $this->__('Enter your coupon code if you have one.') ?></label></h3>
30
+
31
+ <form id="klarna_coupon" action="<?php echo $this->getUrl('checkout/klarna/couponPost') ?>" method="post">
32
+
33
+ <fieldset>
34
+ <input type="hidden" name="return_url" value="<?php echo $this->getUrl('checkout/klarna') ?>" />
35
+ <input type="hidden" name="remove" id="remove-coupone" value="0" />
36
+
37
+ <input class="input-text" id="coupon_code" name="coupon_code" value="<?php echo $this->htmlEscape($this->getCouponCode()) ?>" />
38
+ <?php if(!strlen($this->getCouponCode())): ?>
39
+ <button class="button" type="button" value="<?php echo $this->__('Apply Coupon') ?>"><span><span><?php echo $this->__('Apply Coupon') ?></span></span></button>
40
+ <?php else: ?>
41
+ <button type="button" class="button cancel-btn" value="<?php echo $this->__('Cancel Coupon') ?>"><span><span><?php echo $this->__('Cancel Coupon') ?></span></span></button>
42
+ <?php endif;?>
43
+ </fieldset>
44
+
45
+ </form>
46
+
47
+ </div>
app/design/frontend/base/default/template/vaimo/klarna/klarnacheckout/discount/giftcardaccount.phtml ADDED
@@ -0,0 +1,71 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Copyright (c) 2009-2014 Vaimo AB
4
+ *
5
+ * Vaimo reserves all rights in the Program as delivered. The Program
6
+ * or any portion thereof may not be reproduced in any form whatsoever without
7
+ * the written consent of Vaimo, except as provided by licence. A licence
8
+ * under Vaimo's rights in the Program may be available directly from
9
+ * Vaimo.
10
+ *
11
+ * Disclaimer:
12
+ * THIS NOTICE MAY NOT BE REMOVED FROM THE PROGRAM BY ANY USER THEREOF.
13
+ * THE PROGRAM IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
14
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
16
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ * OUT OF OR IN CONNECTION WITH THE PROGRAM OR THE USE OR OTHER DEALINGS
19
+ * IN THE PROGRAM.
20
+ *
21
+ * @category Vaimo
22
+ * @package Vaimo_Klarna
23
+ * @copyright Copyright (c) 2009-2014 Vaimo AB
24
+ */
25
+ ?>
26
+
27
+ <div class="giftcard">
28
+ <h3><?php echo $this->__('Giftcard') ?> <label for="giftcard_code"><?php echo $this->__('Enter the gift card code') ?></label></h3>
29
+ <div id="giftcard_balance_lookup"></div>
30
+ <form id="giftcard-form" action="<?php echo $this->getUrl('checkout/klarna/addGiftCard') ?>" method="post">
31
+ <fieldset>
32
+ <div class="v-fix"><input class="required-entry input-text" id="giftcard_code" name="giftcard_code" value="" /></div>
33
+ <button class="button" onclick="giftcardForm.submit()" type="button" value="<?php echo $this->__('Add Gift Card') ?>"><span><span><?php echo $this->__('Add Gift Card') ?></span></span></button>
34
+ <img src="<?php echo $this->getSkinUrl('images/opc-ajax-loader.gif')?>" alt="" style="display:none;" id="giftcard-loader" />
35
+ <?php /*<button class="button check-gc-status" onclick="quickCheckout.checkGiftCardStatus(); return false;" type="button" value="<?php echo $this->__('Check Gift Card status and balance') ?>"><span><span><?php echo $this->__('Check Gift Card status and balance') ?></span></span></button> */ ?>
36
+ <img src="<?php echo $this->getSkinUrl('images/opc-ajax-loader.gif')?>" alt="" style="display:none;" id="check-giftcard-status-loader" />
37
+ </fieldset>
38
+ </form>
39
+
40
+ <div id="applied-gift-cards">
41
+ <?php
42
+ $_quote = Mage::getSingleton('checkout/session')->getQuote();
43
+ $_cards = Mage::helper('enterprise_giftcardaccount')->getCards($_quote); ?>
44
+ <?php foreach ($_cards as $_c): ?>
45
+ <div class="item">
46
+ <span class="left">
47
+ <?php echo $this->__('Gift Card (%s)', $_c['c']); ?>
48
+ <?php $_url = Mage::getUrl('checkout/klarna/removeGiftCard', array('code'=>$_c['c'])); ?>
49
+ <?php $_title = $this->__('Remove'); ?>
50
+ <a href="<?php echo $_url ?>" title="<?php echo $_title; ?>" class="btn-remove"><img src="<?php echo $this->getSkinUrl('images/btn_remove.gif') ?>" alt="<?php echo $this->__('Remove')?>" /></a>
51
+ </span>
52
+ <span class="right">
53
+ -<?php echo $this->helper('checkout')->formatPrice($_c['a']) ?>
54
+ </span>
55
+ </div>
56
+ <?php endforeach; ?>
57
+ <img src="<?php echo $this->getSkinUrl('images/opc-ajax-loader.gif')?>" alt="" style="display:none;" id="remove-giftcard-loader" />
58
+ </div>
59
+
60
+ <script type="text/javascript">
61
+ //<![CDATA[
62
+ var giftcardForm = new VarienForm('giftcard-form');
63
+ giftcardForm.submit = function() {
64
+ return VarienForm.prototype.submit.bind(giftcardForm)();
65
+ }
66
+ function removeGiftCard(code) {
67
+ return true;
68
+ }
69
+ //]]>
70
+ </script>
71
+ </div>
app/design/frontend/base/default/template/vaimo/klarna/klarnacheckout/header.phtml ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Copyright (c) 2009-2014 Vaimo AB
4
+ *
5
+ * Vaimo reserves all rights in the Program as delivered. The Program
6
+ * or any portion thereof may not be reproduced in any form whatsoever without
7
+ * the written consent of Vaimo, except as provided by licence. A licence
8
+ * under Vaimo's rights in the Program may be available directly from
9
+ * Vaimo.
10
+ *
11
+ * Disclaimer:
12
+ * THIS NOTICE MAY NOT BE REMOVED FROM THE PROGRAM BY ANY USER THEREOF.
13
+ * THE PROGRAM IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
14
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
16
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ * OUT OF OR IN CONNECTION WITH THE PROGRAM OR THE USE OR OTHER DEALINGS
19
+ * IN THE PROGRAM.
20
+ *
21
+ * @category Vaimo
22
+ * @package Vaimo_Klarna
23
+ * @copyright Copyright (c) 2009-2014 Vaimo AB
24
+ */
25
+ ?>
26
+
27
+ <div id="klarna_loader"><img src="<?php echo $this->getSkinUrl('images/opc-ajax-loader.gif')?>" alt="" id="klarna_loader_img" /></div>
28
+
29
+ <div class="page-title">
30
+
31
+ <h1><?php echo $this->__('Shopping Cart') ?></h1>
32
+
33
+ </div>
34
+
35
+ <?php echo $this->getMessagesBlock()->getGroupedHtml() ?>
app/{code/community/Vaimo/Klarna/Model/Klarna/Cancel.php → design/frontend/base/default/template/vaimo/klarna/klarnacheckout/klarnacheckout.phtml} RENAMED
@@ -22,14 +22,6 @@
22
  * @package Vaimo_Klarna
23
  * @copyright Copyright (c) 2009-2014 Vaimo AB
24
  */
 
25
 
26
- class Vaimo_Klarna_Model_Klarna_Cancel extends Vaimo_Klarna_Model_Klarna_Api
27
- {
28
-
29
- public function __construct($klarnaApi = null, $payment = null)
30
- {
31
- parent::__construct($klarnaApi, $payment);
32
- $this->_setFunctionName('cancel');
33
- }
34
-
35
- }
22
  * @package Vaimo_Klarna
23
  * @copyright Copyright (c) 2009-2014 Vaimo AB
24
  */
25
+ ?>
26
 
27
+ <?php echo $this->getKlarnaHtml() ?>
 
 
 
 
 
 
 
 
 
app/{code/community/Vaimo/Klarna/Model/Klarna/Available.php → design/frontend/base/default/template/vaimo/klarna/klarnacheckout/msg.phtml} RENAMED
@@ -22,13 +22,6 @@
22
  * @package Vaimo_Klarna
23
  * @copyright Copyright (c) 2009-2014 Vaimo AB
24
  */
 
25
 
26
- class Vaimo_Klarna_Model_Klarna_Available extends Vaimo_Klarna_Model_Klarna_Api
27
- {
28
- public function __construct($klarnaApi = null, $payment = null)
29
- {
30
- parent::__construct($klarnaApi, $payment);
31
- $this->_setFunctionName('available');
32
- }
33
-
34
- }
22
  * @package Vaimo_Klarna
23
  * @copyright Copyright (c) 2009-2014 Vaimo AB
24
  */
25
+ ?>
26
 
27
+ <div id="klarna_msg"></div>
 
 
 
 
 
 
 
 
app/design/frontend/base/default/template/vaimo/klarna/klarnacheckout/newsletter.phtml ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Copyright (c) 2009-2014 Vaimo AB
4
+ *
5
+ * Vaimo reserves all rights in the Program as delivered. The Program
6
+ * or any portion thereof may not be reproduced in any form whatsoever without
7
+ * the written consent of Vaimo, except as provided by licence. A licence
8
+ * under Vaimo's rights in the Program may be available directly from
9
+ * Vaimo.
10
+ *
11
+ * Disclaimer:
12
+ * THIS NOTICE MAY NOT BE REMOVED FROM THE PROGRAM BY ANY USER THEREOF.
13
+ * THE PROGRAM IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
14
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
16
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ * OUT OF OR IN CONNECTION WITH THE PROGRAM OR THE USE OR OTHER DEALINGS
19
+ * IN THE PROGRAM.
20
+ *
21
+ * @category Vaimo
22
+ * @package Vaimo_Klarna
23
+ * @copyright Copyright (c) 2009-2014 Vaimo AB
24
+ */
25
+ ?>
26
+
27
+ <?php if ($this->isEnabled()): ?>
28
+ <div id="klarna-checkout-newsletter-container">
29
+ <h3><?php echo $this->__('Newsletter') ?></h3>
30
+ <input id="klarna-checkout-newsletter-url" type="hidden" value="<?php echo $this->getUrl('checkout/klarna/subscribeToNewsletter') ?>" />
31
+ <input id="klarna-checkout-newsletter-type" type="hidden" value="<?php echo $this->getType() ?>" />
32
+ <?php $checked = $this->isChecked() ? 'checked ' : '' ?>
33
+ <input id="klarna-checkout-newsletter" type="checkbox" name="klarna_checkout_newsletter" <?php echo $checked ?>/>
34
+ <label for="klarna-checkout-newsletter"><?php echo $this->getLabel() ?></label>
35
+ </div>
36
+ <?php endif; ?>
app/{code/community/Vaimo/Klarna/Tests/bootstrap.php → design/frontend/base/default/template/vaimo/klarna/klarnacheckout/othermethod.phtml} RENAMED
@@ -23,19 +23,16 @@
23
  * @copyright Copyright (c) 2009-2014 Vaimo AB
24
  */
25
 
26
- if (version_compare(PHP_VERSION, '5.3', '<')) {
27
- echo 'Magento Unit Tests can run only on PHP version higher then 5.3';
28
- exit(1);
29
- }
30
 
31
- $_baseDir = getcwd();
32
 
33
- // Include Mage file by detecting app root
34
- require_once $_baseDir . DIRECTORY_SEPARATOR . 'app' . DIRECTORY_SEPARATOR . 'Mage.php';
35
 
36
- /* Replace server variables for proper file naming */
37
- $_SERVER['SCRIPT_NAME'] = $_baseDir . DS . 'index.php';
38
- $_SERVER['SCRIPT_FILENAME'] = $_baseDir . DS . 'index.php';
39
-
40
- Mage::app('admin');
41
- Mage::getConfig()->init();
 
23
  * @copyright Copyright (c) 2009-2014 Vaimo AB
24
  */
25
 
26
+ $button_name = $this->getOthermethodButtonName();
 
 
 
27
 
28
+ ?>
29
 
30
+ <?php if ($this->isButtonEnabled()==false) return; ?>
 
31
 
32
+ <div id="klarna_methods">
33
+ <?php if ($this->isButtonNameUrl($button_name)): ?>
34
+ <a href="#" onclick="klarnaCheckoutGo('<?php echo $this->getUrl('checkout/klarna/othermethod') ?>')"><span><span><img src="<?php echo $button_name?>"/></span></span></a>
35
+ <?php else: ?>
36
+ <a href="#" class="button" onclick="klarnaCheckoutGo('<?php echo $this->getUrl('checkout/klarna/othermethod') ?>')"><span><span><?php echo $button_name?></span></span></a>
37
+ <?php endif; ?>
38
+ </div>
app/design/frontend/base/default/template/vaimo/klarna/klarnacheckout/reward.phtml ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Copyright (c) 2009-2014 Vaimo AB
4
+ *
5
+ * Vaimo reserves all rights in the Program as delivered. The Program
6
+ * or any portion thereof may not be reproduced in any form whatsoever without
7
+ * the written consent of Vaimo, except as provided by licence. A licence
8
+ * under Vaimo's rights in the Program may be available directly from
9
+ * Vaimo.
10
+ *
11
+ * Disclaimer:
12
+ * THIS NOTICE MAY NOT BE REMOVED FROM THE PROGRAM BY ANY USER THEREOF.
13
+ * THE PROGRAM IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
14
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
16
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ * OUT OF OR IN CONNECTION WITH THE PROGRAM OR THE USE OR OTHER DEALINGS
19
+ * IN THE PROGRAM.
20
+ *
21
+ * @category Vaimo
22
+ * @package Vaimo_Klarna
23
+ * @copyright Copyright (c) 2009-2014 Vaimo AB
24
+ */
25
+ ?>
26
+
27
+ <?php if (Mage::helper('klarna')->excludeCartInKlarnaCheckout()) return; ?>
28
+
29
+ <?php if ($this->getCanUseRewardPoints()): ?>
30
+ <div id="klarna-checkout-reward-container">
31
+ <h3><?php echo $this->__('Reward Points') ?></h3>
32
+ <form id="klarna-checkout-reward" action="<?php echo $this->getUrl('checkout/klarna/rewardPost') ?>" method="post">
33
+ <input type="checkbox" name="use_reward_points" value="1" id="use-reward-points"<?php echo $this->useRewardPoints()?' checked="checked"':'' ?> class="checkbox" />
34
+ <label for="use-reward-points"><?php echo Mage::helper('enterprise_reward')->__('Use my reward points, %s available', Mage::helper('enterprise_reward')->formatReward($this->getPointsBalance(), $this->getCurrencyAmount())); ?></label>
35
+ </form>
36
+ </div>
37
+ <?php endif; ?>
app/design/frontend/base/default/template/vaimo/klarna/klarnacheckout/shipping_method.phtml ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Copyright (c) 2009-2014 Vaimo AB
4
+ *
5
+ * Vaimo reserves all rights in the Program as delivered. The Program
6
+ * or any portion thereof may not be reproduced in any form whatsoever without
7
+ * the written consent of Vaimo, except as provided by licence. A licence
8
+ * under Vaimo's rights in the Program may be available directly from
9
+ * Vaimo.
10
+ *
11
+ * Disclaimer:
12
+ * THIS NOTICE MAY NOT BE REMOVED FROM THE PROGRAM BY ANY USER THEREOF.
13
+ * THE PROGRAM IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
14
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
16
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ * OUT OF OR IN CONNECTION WITH THE PROGRAM OR THE USE OR OTHER DEALINGS
19
+ * IN THE PROGRAM.
20
+ *
21
+ * @category Vaimo
22
+ * @package Vaimo_Klarna
23
+ * @copyright Copyright (c) 2009-2014 Vaimo AB
24
+ */
25
+ ?>
26
+
27
+ <form id="klarna_shipping" action="<?php echo $this->getUrl('checkout/klarna/saveShippingMethod') ?>" method="post">
28
+ <h3><?php echo $this->__('Choose shipping method') ?></h3>
29
+ <?php echo $this->getChildHtml('available') ?>
30
+ <input type="hidden" name="test" value="testvalue" />
31
+ </form>
32
+
33
+ <script>
34
+ if(document.getElementById('s_method_matrixrate_matrixrate_free') && getCookie('klarnaShippingChanged') != 1) {
35
+ document.getElementById('s_method_matrixrate_matrixrate_free').checked = true;
36
+ document.cookie = 'klarnaShippingChanged=1; expires=0;';
37
+ }
38
+ </script>
app/design/frontend/base/default/template/vaimo/klarna/klarnacheckout/shipping_method/available.phtml ADDED
@@ -0,0 +1,63 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Copyright (c) 2009-2014 Vaimo AB
4
+ *
5
+ * Vaimo reserves all rights in the Program as delivered. The Program
6
+ * or any portion thereof may not be reproduced in any form whatsoever without
7
+ * the written consent of Vaimo, except as provided by licence. A licence
8
+ * under Vaimo's rights in the Program may be available directly from
9
+ * Vaimo.
10
+ *
11
+ * Disclaimer:
12
+ * THIS NOTICE MAY NOT BE REMOVED FROM THE PROGRAM BY ANY USER THEREOF.
13
+ * THE PROGRAM IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
14
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
16
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ * OUT OF OR IN CONNECTION WITH THE PROGRAM OR THE USE OR OTHER DEALINGS
19
+ * IN THE PROGRAM.
20
+ *
21
+ * @category Vaimo
22
+ * @package Vaimo_Klarna
23
+ * @copyright Copyright (c) 2009-2014 Vaimo AB
24
+ */
25
+
26
+ $_shippingRateGroups = $this->getShippingRates();
27
+
28
+ ?>
29
+
30
+ <?php if (!$_shippingRateGroups): ?>
31
+
32
+ <p><?php echo $this->__('Sorry, no quotes are available for this order at this time.') ?></p>
33
+
34
+ <?php else: ?>
35
+
36
+ <ul>
37
+ <?php $shippingCodePrice = array(); ?>
38
+ <?php $_sole = count($_shippingRateGroups) == 1; ?>
39
+ <?php foreach ($_shippingRateGroups as $code => $_rates): ?>
40
+ <?php $_sole = $_sole && count($_rates) == 1; ?>
41
+ <?php foreach ($_rates as $_rate): ?>
42
+ <?php $shippingCodePrice[] = "'".$_rate->getCode()."':".(float)$_rate->getPrice(); ?>
43
+ <li>
44
+ <?php if ($_rate->getErrorMessage()): ?>
45
+ <ul class="messages"><li class="error-msg"><ul><li><?php echo $this->escapeHtml($_rate->getErrorMessage()) ?></li></ul></li></ul>
46
+ <?php else: ?>
47
+ <input name="shipping_method" type="radio" class="shipping-method-input-radio" value="<?php echo $_rate->getCode() ?>" id="s_method_<?php echo $_rate->getCode() ?>"<?php if($_rate->getCode()===$this->getAddressShippingMethod()) echo ' checked="checked"' ?> />
48
+
49
+ <label for="s_method_<?php echo $_rate->getCode() ?>"><?php echo $this->escapeHtml($_rate->getMethodTitle()) ?>,
50
+ <?php $_excl = $this->getShippingPrice($_rate->getPrice(), $this->helper('tax')->displayShippingPriceIncludingTax()); ?>
51
+ <?php $_incl = $this->getShippingPrice($_rate->getPrice(), true); ?>
52
+ <?php echo $_excl; ?>
53
+ <?php if ($this->helper('tax')->displayShippingBothPrices() && $_incl != $_excl): ?>
54
+ (<?php echo $this->__('Incl. Tax'); ?> <?php echo $_incl; ?>)
55
+ <?php endif; ?>
56
+ </label>
57
+ <?php endif ?>
58
+ </li>
59
+ <?php endforeach; ?>
60
+ <?php endforeach; ?>
61
+ </ul>
62
+
63
+ <?php endif; ?>
app/design/frontend/base/default/template/vaimo/klarna/klarnacheckout/success.phtml ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Copyright (c) 2009-2014 Vaimo AB
4
+ *
5
+ * Vaimo reserves all rights in the Program as delivered. The Program
6
+ * or any portion thereof may not be reproduced in any form whatsoever without
7
+ * the written consent of Vaimo, except as provided by licence. A licence
8
+ * under Vaimo's rights in the Program may be available directly from
9
+ * Vaimo.
10
+ *
11
+ * Disclaimer:
12
+ * THIS NOTICE MAY NOT BE REMOVED FROM THE PROGRAM BY ANY USER THEREOF.
13
+ * THE PROGRAM IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
14
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
16
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ * OUT OF OR IN CONNECTION WITH THE PROGRAM OR THE USE OR OTHER DEALINGS
19
+ * IN THE PROGRAM.
20
+ *
21
+ * @category Vaimo
22
+ * @package Vaimo_Klarna
23
+ * @copyright Copyright (c) 2009-2014 Vaimo AB
24
+ */
25
+ ?>
26
+
27
+ <div id="vaimo_klarna_klarnacheckout_success">
28
+ <?php echo $this->getKlarnaHtml() ?>
29
+ </div>
app/design/frontend/base/default/template/vaimo/klarna/page/html/logo.phtml CHANGED
@@ -24,7 +24,7 @@
24
  */
25
 
26
  $_availableMethods = $this->getAvailableMethods();
27
- $_logos = $this->getAllMethodLogos($_availableMethods, 160);
28
 
29
  ?>
30
 
24
  */
25
 
26
  $_availableMethods = $this->getAvailableMethods();
27
+ $_logos = $this->getAllMethodLogos($_availableMethods, 180);
28
 
29
  ?>
30
 
app/locale/da_DK/Vaimo_Klarna.csv CHANGED
@@ -97,10 +97,54 @@
97
  "Day","Dag"
98
  "07xxxxxxxx",""
99
 
100
- "Disable payment widget on product page","Disable payment widget on product page"
101
- "If set to yes, the payment information from Klarna will not appear on the product page","If set to yes, the payment information from Klarna will not appear on the product page"
102
 
103
- "Disable method for company purchase","Disable method for company purchase"
104
- "Disable this method when company field is filled in during checkout","Disable this method when company field is filled in during checkout"
105
- "Default Country Only","Default Country Only"
106
- "Multiple Countries Allowed","Multiple Countries Allowed"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
97
  "Day","Dag"
98
  "07xxxxxxxx",""
99
 
100
+ "Disable payment widget on product page","Deaktiver betalingsapplikation produktsiden"
101
+ "If set to yes, the payment information from Klarna will not appear on the product page","Hvis indstillingen er sat til “ja”, vises betalingsinformationen fra Klarna ikke produktsiden"
102
 
103
+ "Disable method for company purchase","Deaktiver metode for firmakøb"
104
+ "Disable this method when company field is filled in during checkout","Deaktiver denne metode, når firmafeltet udfyldes ved check-out"
105
+ "Default Country Only","Kun det land valgt som standard"
106
+ "Multiple Countries Allowed","Flere lande tilladt"
107
+
108
+ "Klarna Checkout","Klarna Checkout"
109
+ "Auto prefill known Klarna details","Udfyld automatisk de oplysninger, som Klarna har"
110
+ "When activated, it will use the logged in customer details to prefill the Klarna Checkout form","Ved aktivering benyttes de indtastede kundeoplysninger til at udfylde resten automatisk i Klarna Checkout-formularen."
111
+ "Extra order ID attribute","Ekstra attribut i ordre-ID"
112
+ "Will be used in the orderid2 field on the Klarna order","Vil blive brugt i feltet ”ordreid2” på ordren med Klarna"
113
+ "Newsletter","Nyhedsbrev"
114
+ "If checkbox for newsletter should be shown in checkout page.","Hvis afkrydsningsboksen til nyhedsbrev skal vises i kassen"
115
+ "Checked by default","Markeret som standardindstilling"
116
+ "A/B Testing settings","A/B testindstillinger"
117
+ "Enable for IP range","Aktiver for IP-rækkevidde"
118
+ "Specify 2 numbers between 0 and 255, separated by dash. Example: '0-50'. Empty value enables all IP addresses","Specificer to cifre mellem 0 og 255, adskilt med bindestreg. Eksempel: ”0-50”. En tom værdi aktiverer alle IP-adresser"
119
+ "Enable for logged in Customers","Aktiver for kunder som er logget ind"
120
+ "If not enabled, logged in customers will use standard Magento checkout","Hvis det ikke er aktiveret, benytter kunder, som er logget ind, standardkassen Magento"
121
+ "Enable for specific customer groups","Aktiver for specifikke kundegrupper"
122
+ "If you do not belong to a selected customer group, standard Magento checkout will be used. None selected, means enabled for all","Hvis du ikke tilhører en valgt kundegruppe, vil standardkassen Magento blive benyttet. ”Ingen valgt” betyder, at det er aktiveret for alle"
123
+ "For an easy checkout, I consent to use the data saved in my account with the new Klarna Checkout according to the %s","For en simpel kasseløsning giver jeg samtykke til at bruge de data, der er gemt i min konto med den nye Klarna Checkout, ifølge %s"
124
+ "No","Nej"
125
+ "Yes - Subscribe to newsletter","Ja – tilmeld nyhedsbrev"
126
+ "Yes - Don't subscribe to newsletter","Ja – tilmeld ikke nyhedsbrev"
127
+ "Subscribe to newsletter","Tilmeld nyhedsbrev"
128
+ "Don't subscribe to newsletter","Tilmeld ikke nyhedsbrev"
129
+ "URL to this stores own terms and conditions","Link til denne butiks egne vilkår og betingelser"
130
+ "Refund amount","Refunder beløb"
131
+ "Go to Klarna Checkout","Gå til Klarna Checkout"
132
+ "Other Payment Methods","Andre betalingsmetoder"
133
+
134
+ "Country Default","Land som standard"
135
+ "Force entry of phonenumber","Gør indtastning af telefonnummer obligatorisk"
136
+ "Enable DHL Packstation","Aktiver DHL Pakkestation"
137
+ "Enable cart in checkout page","Aktiver indkøbskurv ved kassen"
138
+ "Only available in Germany","Kun tilgængeligt i Tyskland"
139
+ "Enable Autofocus for Klarna Checkout","Aktiver autofokus for Klarna Checkout"
140
+ "Support of other payment methods","Understøttelse af andre betalingsmetoder"
141
+ "If enabled, one button will be placed on klarna checkout page and one in the payment section of standard checkout","Ved aktivering placeres en knap på siden med Klarna Checkout og en i betalingssektionen med standardkassen."
142
+ "Label for Other Payment Methods button","Betegnelse for knappen “Andre betalingsmetoder"
143
+ "Label for Back to Klarna Checkout button","Betegnelse for knappen ”Gå tilbage til Klarna Checkout"
144
+ "Other Payment Methods","Andre betalingsmetoder"
145
+ "Go to Klarna Checkout","Gå til Klarna Checkout"
146
+ "This can be free text or a complete URL to a reasonably sized image","Dette kan være en fritekst eller en fuldstændig URL til et billede i rimelig størrelse."
147
+ "Reference","Reference"
148
+ "Order Id","Ordre-ID"
149
+ "Capture ID","Capture ID"
150
+ "Klarna Checkout is not responding properly. Please try again in a while or choose another payment method.","Klarna Checkout svarer ikke. Prøv venligst igen senere, eller vælg en anden betalingsmetode."
app/locale/de_AT/Vaimo_Klarna.csv CHANGED
@@ -104,3 +104,47 @@
104
  "Disable this method when company field is filled in during checkout","Deaktivieren der Funktion, wenn Firmen-Feld beim Checkout ausgefüllt ist"
105
  "Default Country Only","Land das Standard eingestellt ist"
106
  "Multiple Countries Allowed","Mehrere Länder zugelassen"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
104
  "Disable this method when company field is filled in during checkout","Deaktivieren der Funktion, wenn Firmen-Feld beim Checkout ausgefüllt ist"
105
  "Default Country Only","Land das Standard eingestellt ist"
106
  "Multiple Countries Allowed","Mehrere Länder zugelassen"
107
+
108
+ "Klarna Checkout","Klarna Checkout"
109
+ "Auto prefill known Klarna details","AutoVervollständigen gekannter Klarna details"
110
+ "When activated, it will use the logged in customer details to prefill the Klarna Checkout form","Bei Aktivierung werden die hinterlegten Kundendaten automatisch in den Klarna Checkout eingepflegt"
111
+ "Extra order ID attribute","Extra Bestellnummer Attribute"
112
+ "Will be used in the orderid2 field on the Klarna order","Wird in dem Feld Bestellnummer 2 der Klarna Bestellung genutzt"
113
+ "Newsletter","Newsletter"
114
+ "If checkbox for newsletter should be shown in checkout page.","Wenn Kontrollbox für den Newsletter auf der Checkout Seite angezeigt werden soll."
115
+ "Checked by default","Per Voreinstellung geprüft"
116
+ "A/B Testing settings","A/B Testing Einstellungen"
117
+ "Enable for IP range","Für IP-Bereich aktiveren"
118
+ "Specify 2 numbers between 0 and 255, separated by dash. Example: '0-50'. Empty value enables all IP addresses","SSpezifiziert Zahlen zwischen 2 und 255, durch “-” getrennt. Beispiel: '0-50'. Keine Eingabe ermöglicht alle IP Adressen"
119
+ "Enable for logged in Customers","Für eingeloggte Kunden ermöglichen"
120
+ "If not enabled, logged in customers will use standard Magento checkout","Wenn nicht ausgewählt, nutzen eingeloggte Kunden den Standard Magento Checkout"
121
+ "Enable for specific customer groups","Für bestimmte Kundengruppen ermöglichen"
122
+ "If you do not belong to a selected customer group, standard Magento checkout will be used. None selected, means enabled for all","Wenn du nicht zu der ausgewählten Kundengruppe gehörst, wird der Standard Magento Checkout ermöglicht"
123
+ "For an easy checkout, I consent to use the data saved in my account with the new Klarna Checkout according to the %s","Ich stimme den %s und der Anwendung meiner Daten in der Express Kasse zu."
124
+ "No","Nein"
125
+ "Yes - Subscribe to newsletter","Ja - Newsletter abonnieren"
126
+ "Yes - Don't subscribe to newsletter","Ja - Newsletter nicht abonnieren"
127
+ "Subscribe to newsletter","Newsletter abonnieren"
128
+ "Don't subscribe to newsletter","Newsletter nicht abonnieren"
129
+ "URL to this stores own terms and conditions","Link zu den Händler Geschäftsbedingungen."
130
+ "Refund amount","Betrag rückerstatten"
131
+ "Go to Klarna Checkout","Gehe zum Klarna Checkout"
132
+ "Other Payment Methods","Andere Bezahlmethoden"
133
+
134
+ "Country Default","Ländervoreinstellung"
135
+ "Force entry of phonenumber","Eingabe der Telefonnummer erzwingen"
136
+ "Enable DHL Packstation","DHL Packstation ermöglichen"
137
+ "Enable cart in checkout page","Einkaufswagen auf Checkout Seite ermöglichen"
138
+ "Only available in Germany","Nur in Deutschland verfügbar"
139
+ "Enable Autofocus for Klarna Checkout","Autofokus für Klarna Checkout ermöglichen"
140
+ "Support of other payment methods","Unterstützung anderer Zahlungsmethoden"
141
+ "If enabled, one button will be placed on klarna checkout page and one in the payment section of standard checkout","Wenn aktiviert, wird eine Schaltfläche auf der Klarna Checkout und eine auf der Seite der Bezahlmethoden des Standard Checkouts plaziert."
142
+ "Label for Other Payment Methods button","Bezeichnung für Andere-Bezahlmethoden-Schaltfäche"
143
+ "Label for Back to Klarna Checkout button","Bezeichung für Zurück-zum-Klarna-Checkout-Schaltfläche"
144
+ "Other Payment Methods","Andere Bezahlmethoden"
145
+ "Go to Klarna Checkout","Gehe zum Klarna Checkout"
146
+ "This can be free text or a complete URL to a reasonably sized image","Dies kann freier Text oder eine vollständige URL bis zu einer angemessenen Größe sein."
147
+ "Reference","Referenz"
148
+ "Order Id","Bestellnummer"
149
+ "Capture ID","Capture ID"
150
+ "Klarna Checkout is not responding properly. Please try again in a while or choose another payment method.","Klarna Checkout reagiert nicht ordnungsgemäß. Bitte versuchen Sie es in Kürze nochmals oder wähle Sie eine andere Bezahlmethode."
app/locale/de_DE/Vaimo_Klarna.csv CHANGED
@@ -104,3 +104,47 @@
104
  "Disable this method when company field is filled in during checkout","Deaktivieren der Funktion, wenn Firmen-Feld beim Checkout ausgefüllt ist"
105
  "Default Country Only","Land das Standard eingestellt ist"
106
  "Multiple Countries Allowed","Mehrere Länder zugelassen"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
104
  "Disable this method when company field is filled in during checkout","Deaktivieren der Funktion, wenn Firmen-Feld beim Checkout ausgefüllt ist"
105
  "Default Country Only","Land das Standard eingestellt ist"
106
  "Multiple Countries Allowed","Mehrere Länder zugelassen"
107
+
108
+ "Klarna Checkout","Klarna Checkout"
109
+ "Auto prefill known Klarna details","AutoVervollständigen gekannter Klarna details"
110
+ "When activated, it will use the logged in customer details to prefill the Klarna Checkout form","Bei Aktivierung werden die hinterlegten Kundendaten automatisch in den Klarna Checkout eingepflegt"
111
+ "Extra order ID attribute","Extra Bestellnummer Attribute"
112
+ "Will be used in the orderid2 field on the Klarna order","Wird in dem Feld Bestellnummer 2 der Klarna Bestellung genutzt"
113
+ "Newsletter","Newsletter"
114
+ "If checkbox for newsletter should be shown in checkout page.","Wenn Kontrollbox für den Newsletter auf der Checkout Seite angezeigt werden soll."
115
+ "Checked by default","Per Voreinstellung geprüft"
116
+ "A/B Testing settings","A/B Testing Einstellungen"
117
+ "Enable for IP range","Für IP-Bereich aktiveren"
118
+ "Specify 2 numbers between 0 and 255, separated by dash. Example: '0-50'. Empty value enables all IP addresses","SSpezifiziert Zahlen zwischen 2 und 255, durch “-” getrennt. Beispiel: '0-50'. Keine Eingabe ermöglicht alle IP Adressen"
119
+ "Enable for logged in Customers","Für eingeloggte Kunden ermöglichen"
120
+ "If not enabled, logged in customers will use standard Magento checkout","Wenn nicht ausgewählt, nutzen eingeloggte Kunden den Standard Magento Checkout"
121
+ "Enable for specific customer groups","Für bestimmte Kundengruppen ermöglichen"
122
+ "If you do not belong to a selected customer group, standard Magento checkout will be used. None selected, means enabled for all","Wenn du nicht zu der ausgewählten Kundengruppe gehörst, wird der Standard Magento Checkout ermöglicht"
123
+ "For an easy checkout, I consent to use the data saved in my account with the new Klarna Checkout according to the %s","Ich stimme den %s und der Anwendung meiner Daten in der Express Kasse zu."
124
+ "No","Nein"
125
+ "Yes - Subscribe to newsletter","Ja - Newsletter abonnieren"
126
+ "Yes - Don't subscribe to newsletter","Ja - Newsletter nicht abonnieren"
127
+ "Subscribe to newsletter","Newsletter abonnieren"
128
+ "Don't subscribe to newsletter","Newsletter nicht abonnieren"
129
+ "URL to this stores own terms and conditions","Link zu den Händler Geschäftsbedingungen."
130
+ "Refund amount","Betrag rückerstatten"
131
+ "Go to Klarna Checkout","Gehe zum Klarna Checkout"
132
+ "Other Payment Methods","Andere Bezahlmethoden"
133
+
134
+ "Country Default","Ländervoreinstellung"
135
+ "Force entry of phonenumber","Eingabe der Telefonnummer erzwingen"
136
+ "Enable DHL Packstation","DHL Packstation ermöglichen"
137
+ "Enable cart in checkout page","Einkaufswagen auf Checkout Seite ermöglichen"
138
+ "Only available in Germany","Nur in Deutschland verfügbar"
139
+ "Enable Autofocus for Klarna Checkout","Autofokus für Klarna Checkout ermöglichen"
140
+ "Support of other payment methods","Unterstützung anderer Zahlungsmethoden"
141
+ "If enabled, one button will be placed on klarna checkout page and one in the payment section of standard checkout","Wenn aktiviert, wird eine Schaltfläche auf der Klarna Checkout und eine auf der Seite der Bezahlmethoden des Standard Checkouts plaziert."
142
+ "Label for Other Payment Methods button","Bezeichnung für Andere-Bezahlmethoden-Schaltfäche"
143
+ "Label for Back to Klarna Checkout button","Bezeichung für Zurück-zum-Klarna-Checkout-Schaltfläche"
144
+ "Other Payment Methods","Andere Bezahlmethoden"
145
+ "Go to Klarna Checkout","Gehe zum Klarna Checkout"
146
+ "This can be free text or a complete URL to a reasonably sized image","Dies kann freier Text oder eine vollständige URL bis zu einer angemessenen Größe sein."
147
+ "Reference","Referenz"
148
+ "Order Id","Bestellnummer"
149
+ "Capture ID","Capture ID"
150
+ "Klarna Checkout is not responding properly. Please try again in a while or choose another payment method.","Klarna Checkout reagiert nicht ordnungsgemäß. Bitte versuchen Sie es in Kürze nochmals oder wähle Sie eine andere Bezahlmethode."
app/locale/fi_FI/Vaimo_Klarna.csv CHANGED
@@ -97,10 +97,54 @@
97
  "Day","Päivä"
98
  "07xxxxxxxx",""
99
 
100
- "Disable payment widget on product page","Disable payment widget on product page"
101
- "If set to yes, the payment information from Klarna will not appear on the product page","If set to yes, the payment information from Klarna will not appear on the product page"
102
 
103
- "Disable method for company purchase","Disable method for company purchase"
104
- "Disable this method when company field is filled in during checkout","Disable this method when company field is filled in during checkout"
105
- "Default Country Only","Default Country Only"
106
- "Multiple Countries Allowed","Multiple Countries Allowed"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
97
  "Day","Päivä"
98
  "07xxxxxxxx",""
99
 
100
+ "Disable payment widget on product page","Estä maksuwidgetit tuotesivulla"
101
+ "If set to yes, the payment information from Klarna will not appear on the product page","Jos valitset kyllä, Klarnan maksutietoja ei näytetä tuotesivulla"
102
 
103
+ "Disable method for company purchase","Estä yritysostojen menetelmä"
104
+ "Disable this method when company field is filled in during checkout","Estä tämä menetelmä, kun yrityskenttä on täytetty kassalla"
105
+ "Default Country Only","Vain oletusmaa"
106
+ "Multiple Countries Allowed","Useat maat sallittu"
107
+
108
+ "Klarna Checkout","Klarna Checkout"
109
+ "Auto prefill known Klarna details","Esitäytä tunnetut Klarna-tiedot automaattisesti"
110
+ "When activated, it will use the logged in customer details to prefill the Klarna Checkout form","Aktivoinnin jälkeen järjestelmä käyttää kirjautumistietoja esitäyttääkseen Klarna Checkout-lomakkeen"
111
+ "Extra order ID attribute","Ylimääräinen tilaustunnus-attribuutti"
112
+ "Will be used in the orderid2 field on the Klarna order","Käytetään Klarna-tilauksissa tilaustunnus2-kentässä"
113
+ "Newsletter","Uutiskirje"
114
+ "If checkbox for newsletter should be shown in checkout page.","Jos uutiskirjeen valintaruudun tulisi näkyä kassasivulla."
115
+ "Checked by default","Oletuksena valittu"
116
+ "A/B Testing settings","A/B-Testausasetukset"
117
+ "Enable for IP range","Salli IP-alue"
118
+ "Specify 2 numbers between 0 and 255, separated by dash. Example: '0-50'. Empty value enables all IP addresses","Valitse kaksi numeroa välillä 0 ja 255, viivalla erotettuna. Esimerkiksi: '0-50'. Tyhjä arvo sallii kaikki IP-osoitteet"
119
+ "Enable for logged in Customers","Salli sisäänkirjautuneet asiakkaat"
120
+ "If not enabled, logged in customers will use standard Magento checkout","Jos ei sallittu, sisäänkirjautuneet asiakkaat käyttävät Magenton standardikassaa"
121
+ "Enable for specific customer groups","Salli tietyt asiakasryhmät"
122
+ "If you do not belong to a selected customer group, standard Magento checkout will be used. None selected, means enabled for all","Jos et kuulu valittuun asiakasryhmään, käytetään Magenton standardikassaa. Jos mitään ei valita, tarkoittaa se sallittua kaikille"
123
+ "For an easy checkout, I consent to use the data saved in my account with the new Klarna Checkout according to the %s","For an easy checkout, I consent to use the data saved in my account with the new Klarna Checkout according to the %s"
124
+ "No","Ei"
125
+ "Yes - Subscribe to newsletter","Kyllä - Tilaa uutiskirje"
126
+ "Yes - Don't subscribe to newsletter","Kyllä - En tilaa uutiskirjettä"
127
+ "Subscribe to newsletter","Tilaa uutiskirje"
128
+ "Don't subscribe to newsletter","En tilaa uutiskirjettä"
129
+ "URL to this stores own terms and conditions","URL kaupan omiin ehtoihin."
130
+ "Refund amount","Palautussumma"
131
+ "Go to Klarna Checkout","Siirry Klarna Checkout -palveluun"
132
+ "Other Payment Methods","Muut maksutavat"
133
+
134
+ "Country Default","Maa, oletus"
135
+ "Force entry of phonenumber","Pakota puhelinnumeron merkintä"
136
+ "Enable DHL Packstation","Salli DHL Packstation"
137
+ "Enable cart in checkout page","Salli kori kassasivulla"
138
+ "Only available in Germany","Saatavilla vain Saksassa"
139
+ "Enable Autofocus for Klarna Checkout","Salli Autofocus Klarna Checkoutissa"
140
+ "Support of other payment methods","Muiden maksutapojen tuki"
141
+ "If enabled, one button will be placed on klarna checkout page and one in the payment section of standard checkout","Jos sallittu, yksi painike sijoitetaan Klarna Checkout -sivulle ja yksi standardikassan maksuvaiheeseen"
142
+ "Label for Other Payment Methods button","Muut maksutavat-painikkeen nimike"
143
+ "Label for Back to Klarna Checkout button","Takaisin Klarna Checkoutiin -painikkeen nimike"
144
+ "Other Payment Methods","Muut maksutavat"
145
+ "Go to Klarna Checkout","Siirry Klarna Checkoutiin"
146
+ "This can be free text or a complete URL to a reasonably sized image","TTämä voi olla tekstiä tai kokonainen URL kohtuullisen kokoiseen kuvaan"
147
+ "Reference","Viite"
148
+ "Order Id","Tilaustunnus"
149
+ "Capture ID","Capture ID"
150
+ "Klarna Checkout is not responding properly. Please try again in a while or choose another payment method.","Klarna Checkout ei vastaa normaalisti. Ole hyvä ja yritä hetken kuluttua uudelleen tai valitse jokin toinen maksutapa."
app/locale/nb_NO/Vaimo_Klarna.csv CHANGED
@@ -104,3 +104,47 @@
104
  "Disable this method when company field is filled in during checkout","Disable this method when company field is filled in during checkout"
105
  "Default Country Only","Default Country Only"
106
  "Multiple Countries Allowed","Multiple Countries Allowed"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
104
  "Disable this method when company field is filled in during checkout","Disable this method when company field is filled in during checkout"
105
  "Default Country Only","Default Country Only"
106
  "Multiple Countries Allowed","Multiple Countries Allowed"
107
+
108
+ "Klarna Checkout","Klarna Checkout"
109
+ "Auto prefill known Klarna details","Auto prefill known Klarna details"
110
+ "When activated, it will use the logged in customer details to prefill the Klarna Checkout form","When activated, it will use the logged in customer details to prefill the Klarna Checkout form"
111
+ "Extra order ID attribute","Extra order ID attribute"
112
+ "Will be used in the orderid2 field on the Klarna order","Will be used in the orderid2 field on the Klarna order"
113
+ "Newsletter","Newsletter"
114
+ "If checkbox for newsletter should be shown in checkout page.","If checkbox for newsletter should be shown in checkout page."
115
+ "Checked by default","Checked by default"
116
+ "A/B Testing settings","A/B Testing settings"
117
+ "Enable for IP range","Enable for IP range"
118
+ "Specify 2 numbers between 0 and 255, separated by dash. Example: '0-50'. Empty value enables all IP addresses","Specify 2 numbers between 0 and 255, separated by dash. Example: '0-50'. Empty value enables all IP addresses"
119
+ "Enable for logged in Customers","Enable for logged in Customers"
120
+ "If not enabled, logged in customers will use standard Magento checkout","If not enabled, logged in customers will use standard Magento checkout"
121
+ "Enable for specific customer groups","Enable for specific customer groups"
122
+ "If you do not belong to a selected customer group, standard Magento checkout will be used. None selected, means enabled for all","If you do not belong to a selected customer group, standard Magento checkout will be used. None selected, means enabled for all"
123
+ "For an easy checkout, I consent to use the data saved in my account with the new Klarna Checkout according to the %s","For an easy checkout, I consent to use the data saved in my account with the new Klarna Checkout according to the %s"
124
+ "No","No"
125
+ "Yes - Subscribe to newsletter","Yes - Subscribe to newsletter"
126
+ "Yes - Don't subscribe to newsletter","Yes - Don't subscribe to newsletter"
127
+ "Subscribe to newsletter","Subscribe to newsletter"
128
+ "Don't subscribe to newsletter","Don't subscribe to newsletter"
129
+ "URL to this stores own terms and conditions","URL til butikkens egne salgsbetingelser"
130
+ "Refund amount","Refund amount"
131
+ "Go to Klarna Checkout","Go to Klarna Checkout"
132
+ "Other Payment Methods","Other Payment Methods"
133
+
134
+ "Country Default","Country Default"
135
+ "Force entry of phonenumber","Force entry of phonenumber"
136
+ "Enable DHL Packstation","Enable DHL Packstation"
137
+ "Enable cart in checkout page","Enable cart in checkout page"
138
+ "Only available in Germany","Only available in Germany"
139
+ "Enable Autofocus for Klarna Checkout","Enable Autofocus for Klarna Checkout"
140
+ "Support of other payment methods","Support of other payment methods"
141
+ "If enabled, one button will be placed on klarna checkout page and one in the payment section of standard checkout","If enabled, one button will be placed on klarna checkout page and one in the payment section of standard checkout"
142
+ "Label for Other Payment Methods button","Label for Other Payment Methods button"
143
+ "Label for Back to Klarna Checkout button","Label for Back to Klarna Checkout button"
144
+ "Other Payment Methods","Other Payment Methods"
145
+ "Go to Klarna Checkout","Go to Klarna Checkout"
146
+ "This can be free text or a complete URL to a reasonably sized image","This can be free text or a complete URL to a reasonably sized image"
147
+ "Reference","Reference"
148
+ "Order Id","Order Id"
149
+ "Capture ID","Capture ID"
150
+ "Klarna Checkout is not responding properly. Please try again in a while or choose another payment method.","Klarna Checkout is not responding properly. Please try again in a while or choose another payment method."
app/locale/nl_NL/Vaimo_Klarna.csv CHANGED
@@ -104,3 +104,47 @@
104
  "Disable this method when company field is filled in during checkout","Schakel deze functie uit wanneer het veld voor bedrijfsgegevens ingevuld wordt in de checkout"
105
  "Default Country Only","Land dat standaard ingesteld is"
106
  "Multiple Countries Allowed","Meerdere landen toegestaan"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
104
  "Disable this method when company field is filled in during checkout","Schakel deze functie uit wanneer het veld voor bedrijfsgegevens ingevuld wordt in de checkout"
105
  "Default Country Only","Land dat standaard ingesteld is"
106
  "Multiple Countries Allowed","Meerdere landen toegestaan"
107
+
108
+ "Klarna Checkout","Klarna Checkout"
109
+ "Auto prefill known Klarna details","Gegevens die bekend zijn bij Klarna worden automatisch ingevuld"
110
+ "When activated, it will use the logged in customer details to prefill the Klarna Checkout form","When activated, it will use the logged in customer details to prefill the Klarna Checkout form"
111
+ "Extra order ID attribute","Extra bestelling ID toevoegen"
112
+ "Will be used in the orderid2 field on the Klarna order","Zal gebruikt worden in de bestelling 2 veld op de Klarna bestelling"
113
+ "Newsletter","Nieuwsbrief"
114
+ "If checkbox for newsletter should be shown in checkout page.","De checkbox voor de nieuwsbrief moet worden weergegeven in de checkout pagina."
115
+ "Checked by default","Default gecontroleerd"
116
+ "A/B Testing settings","A/B test instellingen"
117
+ "Enable for IP range","Geactiveerd voor IP range"
118
+ "Specify 2 numbers between 0 and 255, separated by dash. Example: '0-50'. Empty value enables all IP addresses","Specify 2 numbers between 0 and 255, separated by dash. Example: '0-50'. Empty value enables all IP addresses"
119
+ "Enable for logged in Customers","Geactiveerd voor ingelogde klanten"
120
+ "If not enabled, logged in customers will use standard Magento checkout","If not enabled, logged in customers will use standard Magento checkout"
121
+ "Enable for specific customer groups","Geactiveerd voor specifieke klantgroepen"
122
+ "If you do not belong to a selected customer group, standard Magento checkout will be used. None selected, means enabled for all","If you do not belong to a selected customer group, standard Magento checkout will be used. None selected, means enabled for all"
123
+ "For an easy checkout, I consent to use the data saved in my account with the new Klarna Checkout according to the %s","Ich stimme den %s und der Anwendung meiner Daten in der Express Kasse zu."
124
+ "No","Nee"
125
+ "Yes - Subscribe to newsletter","Ja - Meld je aan voor de nieuwsbrief"
126
+ "Yes - Don't subscribe to newsletter","Ja - Meld je niet aan voor de nieuwsbrief"
127
+ "Subscribe to newsletter","Meld je aan voor de nieuwsbrief"
128
+ "Don't subscribe to newsletter","Meld je niet aan voor de nieuwsbrief"
129
+ "URL to this stores own terms and conditions","URL naar de (AGB) algemene voorwaarden van uw webshop"
130
+ "Refund amount","Bedrag van teruggave"
131
+ "Go to Klarna Checkout","Ga naar Klarna Checkout"
132
+ "Other Payment Methods","Andere betaalmogelijkheden"
133
+
134
+ "Country Default","Standaard land"
135
+ "Force entry of phonenumber","Gedwongen om een telefoonnummer in te voeren"
136
+ "Enable DHL Packstation","DHL levering geactiveerd"
137
+ "Enable cart in checkout page","Winkelwagen geactiveerd in de checkout pagina"
138
+ "Only available in Germany","Alleen beschikbaar in Duitsland"
139
+ "Enable Autofocus for Klarna Checkout","Autofocus geactiveerd voor Klarna Checkout"
140
+ "Support of other payment methods","Ondersteuning van andere betaalmethoden"
141
+ "If enabled, one button will be placed on klarna checkout page and one in the payment section of standard checkout","If enabled, one button will be placed on klarna checkout page and one in the payment section of standard checkout"
142
+ "Label for Other Payment Methods button","Label voor op de knoppen van de andere betaalmethoden"
143
+ "Label for Back to Klarna Checkout button","Label voor op de knop: Terug naar Klarna Checkout"
144
+ "Other Payment Methods","Andere betaalmethoden"
145
+ "Go to Klarna Checkout","Ga naar Klarna Checkout"
146
+ "This can be free text or a complete URL to a reasonably sized image","TDit kan losse tekst zijn of een complete URL naar een medium grote afbeelding zijn"
147
+ "Reference","Referentie"
148
+ "Order Id","Andere ID"
149
+ "Capture ID","Capture ID"
150
+ "Klarna Checkout is not responding properly. Please try again in a while or choose another payment method.","Klarna Checkout reageert niet correct. Probeer het later nog eens of kies voor een andere betaalmethode."
app/locale/nn_NO/Vaimo_Klarna.csv CHANGED
@@ -103,4 +103,48 @@
103
  "Disable method for company purchase","Disable method for company purchase"
104
  "Disable this method when company field is filled in during checkout","Disable this method when company field is filled in during checkout"
105
  "Default Country Only","Default Country Only"
106
- "Multiple Countries Allowed","Multiple Countries Allowed"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
103
  "Disable method for company purchase","Disable method for company purchase"
104
  "Disable this method when company field is filled in during checkout","Disable this method when company field is filled in during checkout"
105
  "Default Country Only","Default Country Only"
106
+ "Multiple Countries Allowed","Multiple Countries Allowed"
107
+
108
+ "Klarna Checkout","Klarna Checkout"
109
+ "Auto prefill known Klarna details","Auto prefill known Klarna details"
110
+ "When activated, it will use the logged in customer details to prefill the Klarna Checkout form","When activated, it will use the logged in customer details to prefill the Klarna Checkout form"
111
+ "Extra order ID attribute","Extra order ID attribute"
112
+ "Will be used in the orderid2 field on the Klarna order","Will be used in the orderid2 field on the Klarna order"
113
+ "Newsletter","Newsletter"
114
+ "If checkbox for newsletter should be shown in checkout page.","If checkbox for newsletter should be shown in checkout page."
115
+ "Checked by default","Checked by default"
116
+ "A/B Testing settings","A/B Testing settings"
117
+ "Enable for IP range","Enable for IP range"
118
+ "Specify 2 numbers between 0 and 255, separated by dash. Example: '0-50'. Empty value enables all IP addresses","Specify 2 numbers between 0 and 255, separated by dash. Example: '0-50'. Empty value enables all IP addresses"
119
+ "Enable for logged in Customers","Enable for logged in Customers"
120
+ "If not enabled, logged in customers will use standard Magento checkout","If not enabled, logged in customers will use standard Magento checkout"
121
+ "Enable for specific customer groups","Enable for specific customer groups"
122
+ "If you do not belong to a selected customer group, standard Magento checkout will be used. None selected, means enabled for all","If you do not belong to a selected customer group, standard Magento checkout will be used. None selected, means enabled for all"
123
+ "For an easy checkout, I consent to use the data saved in my account with the new Klarna Checkout according to the %s","For an easy checkout, I consent to use the data saved in my account with the new Klarna Checkout according to the %s"
124
+ "No","No"
125
+ "Yes - Subscribe to newsletter","Yes - Subscribe to newsletter"
126
+ "Yes - Don't subscribe to newsletter","Yes - Don't subscribe to newsletter"
127
+ "Subscribe to newsletter","Subscribe to newsletter"
128
+ "Don't subscribe to newsletter","Don't subscribe to newsletter"
129
+ "URL to this stores own terms and conditions","URL til butikkens egne salgsbetingelser"
130
+ "Refund amount","Refund amount"
131
+ "Go to Klarna Checkout","Go to Klarna Checkout"
132
+ "Other Payment Methods","Other Payment Methods"
133
+
134
+ "Country Default","Country Default"
135
+ "Force entry of phonenumber","Force entry of phonenumber"
136
+ "Enable DHL Packstation","Enable DHL Packstation"
137
+ "Enable cart in checkout page","Enable cart in checkout page"
138
+ "Only available in Germany","Only available in Germany"
139
+ "Enable Autofocus for Klarna Checkout","Enable Autofocus for Klarna Checkout"
140
+ "Support of other payment methods","Support of other payment methods"
141
+ "If enabled, one button will be placed on klarna checkout page and one in the payment section of standard checkout","If enabled, one button will be placed on klarna checkout page and one in the payment section of standard checkout"
142
+ "Label for Other Payment Methods button","Label for Other Payment Methods button"
143
+ "Label for Back to Klarna Checkout button","Label for Back to Klarna Checkout button"
144
+ "Other Payment Methods","Other Payment Methods"
145
+ "Go to Klarna Checkout","Go to Klarna Checkout"
146
+ "This can be free text or a complete URL to a reasonably sized image","This can be free text or a complete URL to a reasonably sized image"
147
+ "Reference","Reference"
148
+ "Order Id","Order Id"
149
+ "Capture ID","Capture ID"
150
+ "Klarna Checkout is not responding properly. Please try again in a while or choose another payment method.","Klarna Checkout is not responding properly. Please try again in a while or choose another payment method."
app/locale/sv_SE/Vaimo_Klarna.csv CHANGED
@@ -1,5 +1,5 @@
1
  "Klarna Invoice","Klarna Faktura"
2
- "Klarna Account","Delbetalning"
3
  "Klarna Campaign","Klarna Kampanj"
4
  "Enabled","Aktiverad"
5
  "Merchant ID","Butiks-ID"
@@ -103,4 +103,48 @@
103
  "Disable method for company purchase","Deaktivera betalsätt för företagsköp"
104
  "Disable this method when company field is filled in during checkout","Deaktivera betalsättet när företagsfältet är ifyllt"
105
  "Default Country Only","Endast förvalt land"
106
- "Multiple Countries Allowed","Flera länder accepteras"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  "Klarna Invoice","Klarna Faktura"
2
+ "Klarna Account","Klarna Delbetalning"
3
  "Klarna Campaign","Klarna Kampanj"
4
  "Enabled","Aktiverad"
5
  "Merchant ID","Butiks-ID"
103
  "Disable method for company purchase","Deaktivera betalsätt för företagsköp"
104
  "Disable this method when company field is filled in during checkout","Deaktivera betalsättet när företagsfältet är ifyllt"
105
  "Default Country Only","Endast förvalt land"
106
+ "Multiple Countries Allowed","Flera länder accepteras"
107
+
108
+ "Klarna Checkout","Klarna Checkout"
109
+ "Auto prefill known Klarna details","Fyll i känd information i checkout"
110
+ "When activated, it will use the logged in customer details to prefill the Klarna Checkout form","När den är aktiverad, använder den information om den inloggade kunden för att fylla i Klarna Checkout formuläret"
111
+ "Extra order ID attribute","Extra order id attribut"
112
+ "Will be used in the orderid2 field on the Klarna order","Kommer användas i fältet orderid2 på Klarna ordern"
113
+ "Newsletter","Nyhetsbrev"
114
+ "If checkbox for newsletter should be shown in checkout page.","Om checkboxen för nyhetsbrev ska visas i checkout"
115
+ "Checked by default","Checkbox ifylld automatiskt"
116
+ "A/B Testing settings","A/B testning inställningar"
117
+ "Enable for IP range","Aktivera för IP intervall"
118
+ "Specify 2 numbers between 0 and 255, separated by dash. Example: '0-50'. Empty value enables all IP addresses","Två siffror, separerade med minus tecken. Till exempel 0-50"
119
+ "Enable for logged in Customers","Aktivera för inloggade kunder"
120
+ "If not enabled, logged in customers will use standard Magento checkout","Om den inte är aktiverad, kommer inloggade kunder att använda standard kassan"
121
+ "Enable for specific customer groups","Aktivera för vissa kundgrupper"
122
+ "If you do not belong to a selected customer group, standard Magento checkout will be used. None selected, means enabled for all","Om du inte tillhör en kundgrupp som är aktiverad, kommer standard kassa användas. Inga valda i inställningen betyder alla kundgrupper"
123
+ "For an easy checkout, I consent to use the data saved in my account with the new Klarna Checkout according to the %s","Jag godkänner att min information används för att fylla i fält i Klarna Checkout, enligt %s"
124
+ "No","Nej"
125
+ "Yes - Subscribe to newsletter","Ja - Prenumerera på nyhetsbrev"
126
+ "Yes - Don't subscribe to newsletter","Ja - Prenumerera inte på nyhetsbrev"
127
+ "Subscribe to newsletter","Prenumerera på nyhetsbrev"
128
+ "Don't subscribe to newsletter","Jag vill inte få lojalitetserbjudanden som rabattkoder via min e-postadress"
129
+ "URL to this stores own terms and conditions","URL till butikens villkor"
130
+ "Refund amount","Återbetalning"
131
+ "Go to Klarna Checkout","Gå till Klarna Checkout"
132
+ "Other Payment Methods","Andra betalsätt"
133
+
134
+ "Country Default","Standard"
135
+ "Force entry of phonenumber","Tvinga telefonnummer"
136
+ "Enable DHL Packstation","Aktivera DHL Packstation"
137
+ "Enable cart in checkout page","Aktivera varukorgen på checkout sidan"
138
+ "Only available in Germany","Endast tillgängligt i Tyskland"
139
+ "Enable Autofocus for Klarna Checkout","Aktivera automatisk fokus till Klarna Checkout"
140
+ "Support of other payment methods","Stöd för användning av andra betalsätt"
141
+ "If enabled, one button will be placed on klarna checkout page and one in the payment section of standard checkout","Om man aktiverar detta så visas en knapp i Klarna Checkout och en annan i betalsätt sektionen på standard kassan"
142
+ "Label for Other Payment Methods button","Namn på knappen till Andra Betalsätt"
143
+ "Label for Back to Klarna Checkout button","Namn på knappen för att Återgå till Klarna Checkout"
144
+ "Other Payment Methods","Andra Betalsätt"
145
+ "Go to Klarna Checkout","Tillbaka till Klarna Checkout"
146
+ "This can be free text or a complete URL to a reasonably sized image","Detta kan vara fri text eller en komplett URL till en bild av korrekt storlek"
147
+ "Reference","Referens"
148
+ "Order Id","Order Id"
149
+ "Capture ID","Aktiverings ID"
150
+ "Klarna Checkout is not responding properly. Please try again in a while or choose another payment method.","Just nu kan vi inte genomföra ditt köp med Klarna på grund av ett tekniskt fel. Försök igen om en stund. Om du fortfarande får detta meddelande, vänligen välj ett annat betalsätt för att genomföra ditt köp"
js/vaimo/klarna/klarna.js CHANGED
@@ -171,7 +171,7 @@ function enableUpdatePclassButton()
171
  $('update_pclass_button').removeClassName('disabled');
172
  }
173
 
174
- function disableUpdatePclassButton()
175
  {
176
  $("update_pclass_message").update('');
177
  }
@@ -211,7 +211,7 @@ function doUpdatePClass(url)
211
  });
212
 
213
  disableUpdatePclassButton();
214
- clearUpdatePclassMessae();
215
  }
216
 
217
  function insertKlarnaInvoiceElements(merchant, locale, invoiceFee) {
@@ -301,3 +301,6 @@ function insertKlarnaSpecialElements(merchant, locale) {
301
  }
302
  }
303
 
 
 
 
171
  $('update_pclass_button').removeClassName('disabled');
172
  }
173
 
174
+ function clearUpdatePclassMessage()
175
  {
176
  $("update_pclass_message").update('');
177
  }
211
  });
212
 
213
  disableUpdatePclassButton();
214
+ clearUpdatePclassMessage();
215
  }
216
 
217
  function insertKlarnaInvoiceElements(merchant, locale, invoiceFee) {
301
  }
302
  }
303
 
304
+ function klarnaCheckoutGo(url) {
305
+ window.location.assign(url);
306
+ }
js/vaimo/klarna/klarnacheckout.js ADDED
@@ -0,0 +1,675 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /** Helping functions for replacing jQuery functions with default js * */
2
+ (function(funcName, baseObj) {
3
+
4
+ funcName = funcName || "docReady";
5
+ baseObj = baseObj || window;
6
+ var readyList = [];
7
+ var readyFired = false;
8
+ var readyEventHandlersInstalled = false;
9
+
10
+ function ready() {
11
+ if (!readyFired) {
12
+ readyFired = true;
13
+ for (var i = 0; i < readyList.length; i++) {
14
+ readyList[i].fn.call(window, readyList[i].ctx);
15
+ }
16
+ readyList = [];
17
+ }
18
+ }
19
+
20
+ function readyStateChange() {
21
+ if ( document.readyState === "complete" ) {
22
+ ready();
23
+ }
24
+ }
25
+
26
+ baseObj[funcName] = function(callback, context) {
27
+ if (readyFired) {
28
+ setTimeout(function() {callback(context);}, 1);
29
+ return;
30
+ } else {
31
+ readyList.push({fn: callback, ctx: context});
32
+ }
33
+ if (document.readyState === "complete") {
34
+ setTimeout(ready, 1);
35
+ } else if (!readyEventHandlersInstalled) {
36
+ if (document.addEventListener) {
37
+ document.addEventListener("DOMContentLoaded", ready, false);
38
+ window.addEventListener("load", ready, false);
39
+ } else {
40
+ document.attachEvent("onreadystatechange", readyStateChange);
41
+ window.attachEvent("onload", ready);
42
+ }
43
+ readyEventHandlersInstalled = true;
44
+ }
45
+ }
46
+
47
+ })("docReady", window);
48
+
49
+ // Abstract(s) for Klarna: Suspend and resume
50
+ function _klarnaCheckoutWrapper(callback) {
51
+ if (typeof _klarnaCheckout != 'undefined') {
52
+ _klarnaCheckout(function(api) {
53
+ api.suspend();
54
+ typeof callback === 'function' && callback(api);
55
+ });
56
+ }
57
+ };
58
+
59
+ // Helpers for Klarna: Suspend and resume
60
+ function klarnaCheckoutSuspend() {
61
+ _klarnaCheckoutWrapper();
62
+ };
63
+
64
+ function klarnaCheckoutResume() {
65
+ _klarnaCheckoutWrapper(function(api) {
66
+ api.resume();
67
+ });
68
+ };
69
+
70
+ function vanillaAjax(url, dataString, callbackOnSuccess, callbackOnError, callbackOnOther) {
71
+ var xmlhttp;
72
+
73
+ if (window.XMLHttpRequest) {
74
+ // code for IE7+, Firefox, Chrome, Opera, Safari
75
+ xmlhttp = new XMLHttpRequest();
76
+ } else {
77
+ // code for IE6, IE5
78
+ xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
79
+ }
80
+
81
+ xmlhttp.onreadystatechange = function() {
82
+ if (xmlhttp.readyState == XMLHttpRequest.DONE ) {
83
+ var response = xmlhttp.responseText;
84
+ if(xmlhttp.status == 200){
85
+ callbackOnSuccess(response);
86
+ } else if(xmlhttp.status == 400) {
87
+ callbackOnError(response);
88
+ } else {
89
+ callbackOnOther(response);
90
+ }
91
+ }
92
+ }
93
+
94
+ xmlhttp.open("POST", url, true);
95
+
96
+ // Send the proper header information along with the request
97
+ xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
98
+ xmlhttp.setRequestHeader("Content-length", dataString.length);
99
+ xmlhttp.setRequestHeader("Connection", "close");
100
+ xmlhttp.setRequestHeader("X_REQUESTED_WITH", "XMLHttpRequest");
101
+
102
+ xmlhttp.send(dataString);
103
+ };
104
+
105
+ // fade out
106
+ function fadeOut(el){
107
+ el.style.opacity = 1;
108
+
109
+ (function fade() {
110
+ if ((el.style.opacity -= .1) < 0) {
111
+ el.style.display = "none";
112
+ } else {
113
+ requestAnimationFrame(fade);
114
+ }
115
+ })();
116
+ };
117
+
118
+ // fade in
119
+ function fadeIn(el, display){
120
+ if (el) {
121
+ el.style.opacity = 0;
122
+ el.style.display = display || "block";
123
+
124
+ (function fade() {
125
+ var val = parseFloat(el.style.opacity);
126
+ if (!((val += .1) > 1)) {
127
+ el.style.opacity = val;
128
+ requestAnimationFrame(fade);
129
+ }
130
+ })();
131
+ }
132
+ };
133
+
134
+ // Closest
135
+ function closest() {
136
+ var parents = [];
137
+ var tmpList = document.getElementsByClassName('world');
138
+ for (var i = 0; i < tmpList.length; i++) {
139
+ parents.push(tmpList[i].parentNode);
140
+ }
141
+
142
+ var list = [];
143
+ for (var i = 0; i < parents.lenght; i++) {
144
+ if ((parents[i].hasAttribute('data-prefix')) && (parents[i].attributes.getNamedItem('data-prefix').textContent == 'hello')) {
145
+ list.push(tmpList[i]);
146
+ }
147
+ }
148
+ return list;
149
+ };
150
+
151
+ // IE check
152
+ function isIECheck() {
153
+ var ua = window.navigator.userAgent;
154
+ var msie = ua.indexOf("MSIE ");
155
+
156
+ if (msie > 0 || !!navigator.userAgent.match(/Trident.*rv\:11\./)) {
157
+ return true;
158
+ } else {
159
+ return false;
160
+ }
161
+ };
162
+
163
+ // Serialize
164
+ /* Add the forEach method to Array elements if absent */
165
+ if (!Array.prototype.forEach) {
166
+ Array.prototype.forEach = function(fn, scope) {
167
+ 'use strict';
168
+
169
+ var i, len;
170
+
171
+ for (i = 0, len = this.length; i < len; ++i) {
172
+ if (i in this) {
173
+ fn.call(scope, this[i], i, this);
174
+ }
175
+ }
176
+ };
177
+ }
178
+
179
+ /* Extrapolate the Array forEach method to NodeList elements if absent */
180
+ if (!NodeList.prototype.forEach) {
181
+ NodeList.prototype.forEach = Array.prototype.forEach;
182
+ }
183
+
184
+ /*
185
+ * Extrapolate the Array forEach method to HTMLFormControlsCollection elements
186
+ * if absent
187
+ */
188
+ if (!isIECheck) {
189
+ if (!HTMLFormControlsCollection.prototype.forEach) {
190
+ HTMLFormControlsCollection.prototype.forEach = Array.prototype.forEach;
191
+ }
192
+ } else {
193
+ if (!HTMLCollection.prototype.forEach) {
194
+ HTMLCollection.prototype.forEach = Array.prototype.forEach;
195
+ }
196
+ }
197
+
198
+ /**
199
+ * Convert form elements to query string or JavaScript object.
200
+ *
201
+ * @param asObject
202
+ * If the serialization should be returned as an object.
203
+ */
204
+ HTMLFormElement.prototype.serialize = function(asObject) {
205
+ 'use strict';
206
+ var form = this;
207
+ var elements;
208
+ var add = function(name, value) {
209
+ value = encodeURIComponent(value);
210
+
211
+ if (asObject) {
212
+ elements[name] = value;
213
+ } else {
214
+ elements.push(name + '=' + value);
215
+ }
216
+ };
217
+
218
+ if (asObject) {
219
+ elements = {};
220
+ } else {
221
+ elements = [];
222
+ }
223
+
224
+ form.elements.forEach(function(element) {
225
+ switch (element.nodeName) {
226
+ case 'BUTTON':
227
+ /* Omit this elements */
228
+ break;
229
+
230
+ default:
231
+ switch (element.type) {
232
+ case 'submit':
233
+ case 'button':
234
+ /* Omit this types */
235
+ break;
236
+ case 'radio':
237
+ if (element.checked) {
238
+ add(element.name, element.value);
239
+ }
240
+ break;
241
+ default:
242
+ add(element.name, element.value);
243
+ break;
244
+ }
245
+ break;
246
+ }
247
+ });
248
+
249
+ if (asObject) {
250
+ return elements;
251
+ }
252
+
253
+ return elements.join('&');
254
+ };
255
+
256
+ /** Actual Klarna Checkout functions * */
257
+ /** ================================ * */
258
+
259
+ function getCookie(name) {
260
+ var re = new RegExp(name + "=([^;]+)");
261
+ var value = re.exec(document.cookie);
262
+ return (value != null) ? unescape(value[1]) : null;
263
+ };
264
+
265
+ function updateCartKlarna(type, input, quantity) {
266
+ var klarnaCart = document.getElementById("klarna_wrapper");
267
+ var klarnaLoader = document.getElementById("klarna_loader");
268
+ var klarnaMsg = document.getElementById("klarna_msg");
269
+ var klarnaCartHtml = document.getElementById("klarna_cart_reload");
270
+ var klarnaHtml = document.getElementById("klarna_checkout_reload");
271
+ var klarnaCheckout = document.getElementById("klarna_checkout");
272
+ var klarnaTotals = document.getElementById("klarna_totals");
273
+ var klarnaCheckoutContainer = document.getElementById('klarna-checkout-container');
274
+ var klarnaQtyInput = typeof input != 'undefined' ? input : null;
275
+ var klarnaQty = typeof quantity != 'undefined' ? quantity : null;
276
+
277
+ klarnaMsg.style.display = 'none';
278
+ klarnaMsg.className = klarnaMsg.className.replace( /(?:^|\s)error(?!\S)/g , '' )
279
+ fadeIn(klarnaLoader);
280
+
281
+ // Checks what part that triggered the updateCartKlarna()
282
+ var formID = null;
283
+ switch (type) {
284
+ case 'cart':
285
+ formID = document.getElementById('klarna_cart');
286
+ break;
287
+ case 'shipping':
288
+ formID = document.getElementById('klarna_shipping');
289
+ break;
290
+ case 'coupon':
291
+ formID = document.getElementById('klarna_coupon');
292
+ break;
293
+ case 'giftcard':
294
+ formID = document.getElementById('giftcard-form');
295
+ break;
296
+ case 'giftcard-remove':
297
+ formID = document.getElementById('giftcard-form');
298
+ ajaxUrl = input;
299
+ break;
300
+ case 'reward':
301
+ formID = document.getElementById('klarna-checkout-reward');
302
+ break;
303
+ case 'customer_balance':
304
+ formID = document.getElementById('klarna-checkout-customer-balance')
305
+ }
306
+
307
+ if (formID === null) { return; }
308
+
309
+ var dataString = formID.serialize(false);
310
+ if (typeof ajaxUrl === "undefined") {
311
+ var ajaxUrl = formID.getAttribute("action");
312
+ }
313
+
314
+ _klarnaCheckoutWrapper(function(api) {
315
+ vanillaAjax(ajaxUrl, dataString,
316
+ function (data) {
317
+ var obj = JSON.parse(data);
318
+ fadeOut(klarnaLoader);
319
+ if (obj.redirect_url) {
320
+ window.location.href = obj.redirect_url;
321
+ } else if (obj.success) {
322
+ if (getCookie("klarnaAddShipping") != 1) {
323
+ klarnaMsg.innerHTML = obj.success;
324
+ fadeIn(klarnaMsg);
325
+ } else {
326
+ document.cookie = 'klarnaAddShipping=0; expires=-1;';
327
+ }
328
+
329
+ var klarnaCartValue = ''
330
+ if (klarnaCartHtml) {
331
+ klarnaCartValue = klarnaCartHtml.value;
332
+ }
333
+
334
+ if (klarnaCartValue) {
335
+ // Reload the Klarna iFrame.
336
+ vanillaAjax(
337
+ klarnaCartValue,
338
+ '',
339
+ function (results) {
340
+ var objHtml = JSON.parse(results);
341
+ klarnaCart.innerHTML = objHtml.update_sections.html;
342
+
343
+ if (getCookie("klarnaDiscountShipping") == 1) {
344
+ document.cookie = 'klarnaDiscountShipping=0; expires=0;';
345
+ if (document.getElementById('s_method_matrixrate_matrixrate_free').innerHTML.length > 0 && document.getElementById('s_method_matrixrate_matrixrate_free').checked){
346
+ document.getElementById('s_method_matrixrate_matrixrate_free').checked = true;
347
+ }
348
+ updateCartKlarna("shipping");
349
+ }
350
+
351
+ //for (i=0;i<3;i++) { // "Highlight" the totals table
352
+ // fadeOut(document.getElementById("klarna_totals"));
353
+ fadeIn(document.getElementById("klarna_totals"));
354
+ //}
355
+
356
+ vanillaAjax( // Refresh the Klarna iFrame
357
+ klarnaHtml.value,
358
+ '',
359
+ function(results) {
360
+ var objKlarnaHtml = JSON.parse(results);
361
+ var evaluatedObjKlarnaHtml = objKlarnaHtml.update_sections.html;
362
+ var textNode = document.createTextNode(objKlarnaHtml.update_sections.html);
363
+ var scriptToEval = textNode.substringData(evaluatedObjKlarnaHtml.search('<script')+31, evaluatedObjKlarnaHtml.search('</script')-evaluatedObjKlarnaHtml.search('<script')-31);
364
+ var js = document.createElement('script');
365
+ js.async = true;
366
+ js.innerHTML = scriptToEval;
367
+
368
+ klarnaCheckoutContainer.innerHTML = '';//eval(scriptToEval);
369
+ klarnaCheckoutContainer.appendChild(js);
370
+ bindCheckoutControls();
371
+
372
+ //klarnaCheckout.innerHTML = objKlarnaHtml.update_sections.html;//eval(scriptToEval);
373
+
374
+ /*
375
+ var scripts = document.getElementsByTagName('script');
376
+ for (i=0; i<scripts.length;i++) {
377
+ scriptNode = scripts[i];
378
+ if (scriptNode.parentNode.id=='klarna-checkout-container') {
379
+ //eval(scriptNode.innerHTML);
380
+ console.log(scriptNode.innerHTML);
381
+ }
382
+ }*/
383
+
384
+ api.resume();
385
+ }, '', ''
386
+ );
387
+ }, '', ''
388
+ );
389
+ } else {
390
+ vanillaAjax( // Refresh the Klarna iFrame
391
+ klarnaHtml.value,
392
+ '',
393
+ function(results) {
394
+ if (getCookie("klarnaDiscountShipping") == 1) {
395
+ document.cookie = 'klarnaDiscountShipping=0; expires=0;';
396
+ if (document.getElementById('s_method_matrixrate_matrixrate_free').innerHTML.length > 0 && document.getElementById('s_method_matrixrate_matrixrate_free').checked){
397
+ document.getElementById('s_method_matrixrate_matrixrate_free').checked = true;
398
+ }
399
+ updateCartKlarna("shipping");
400
+ }
401
+
402
+ //for (i=0;i<3;i++) { // "Highlight" the totals table
403
+ // fadeOut(document.getElementById("klarna_totals"));
404
+ fadeIn(document.getElementById("klarna_totals"));
405
+ //}
406
+ var objKlarnaHtml = JSON.parse(results);
407
+ var evaluatedObjKlarnaHtml = objKlarnaHtml.update_sections.html;
408
+ var textNode = document.createTextNode(objKlarnaHtml.update_sections.html);
409
+ var scriptToEval = textNode.substringData(evaluatedObjKlarnaHtml.search('<script')+31, evaluatedObjKlarnaHtml.search('</script')-evaluatedObjKlarnaHtml.search('<script')-31);
410
+ var js = document.createElement('script');
411
+ js.async = true;
412
+ js.innerHTML = scriptToEval;
413
+
414
+ klarnaCheckoutContainer.innerHTML = '';//eval(scriptToEval);
415
+ klarnaCheckoutContainer.appendChild(js);
416
+ bindCheckoutControls();
417
+
418
+ api.resume();
419
+ }, '', ''
420
+ );
421
+ }
422
+ } else if (obj.error) {
423
+ klarnaMsg.innerHTML = obj.error;
424
+ klarnaMsg.className += "error";
425
+ fadeIn(klarnaMsg);
426
+ if (klarnaQtyInput) {
427
+ klarnaQtyInput.value = klarnaQty;
428
+ }
429
+ api.resume();
430
+ }
431
+ },
432
+ function(data) {
433
+ alert(data);
434
+ },
435
+ function(data) {
436
+ alert(data);
437
+ }
438
+ );
439
+ });
440
+ setTimeout(function() { // Fade out the "alert" after 3,5 seconds
441
+ fadeOut(klarnaMsg);
442
+ }, 3500)
443
+ };
444
+
445
+ /** Bindings * */
446
+
447
+ function bindCheckoutControls() {
448
+
449
+ // Helpfull element variables
450
+ var
451
+ removeItemElement = document.getElementsByClassName('remove-item'),
452
+ subtrackItemElement = document.getElementsByClassName('subtract-item'),
453
+ addItemElement = document.getElementsByClassName('add-item'),
454
+ qtyInputList = document.getElementsByClassName('qty-input'),
455
+ shippingMethods = document.getElementsByName('shipping_method');
456
+
457
+ // Bind newsletter checkbox
458
+ if (document.getElementById('klarna-checkout-newsletter')) {
459
+ document.getElementById('klarna-checkout-newsletter').onchange = function() {
460
+ var url = document.getElementById('klarna-checkout-newsletter-url').value;
461
+ var type = Number(document.getElementById('klarna-checkout-newsletter-type').value);
462
+ var checked = false;
463
+ switch (type) {
464
+ case 1:
465
+ checked = this.checked ? 1 : 0;
466
+ break;
467
+ case 2:
468
+ checked = this.checked ? 0 : 1;
469
+ break;
470
+ }
471
+ this.disabled = 'disabled';
472
+ vanillaAjax(url, 'subscribe_to_newsletter=checked', function(){
473
+ document.getElementById('klarna-checkout-newsletter').disabled = '';
474
+ });
475
+ };
476
+ };
477
+
478
+ // Reward
479
+ if (document.getElementsByName('use_reward_points')[0]) {
480
+ document.getElementsByName('use_reward_points')[0].onchange = function() {
481
+ updateCartKlarna('reward');
482
+ };
483
+ };
484
+
485
+ // Store Credit
486
+ if (document.getElementsByName('use_customer_balance')[0]) {
487
+ document.getElementsByName('use_customer_balance')[0].onchange = function() {
488
+ updateCartKlarna('customer_balance');
489
+ };
490
+ };
491
+
492
+ // Change shipping method
493
+ if (shippingMethods) {
494
+ for (var q=0; q<shippingMethods.length; q++) {
495
+ shippingMethodItem = shippingMethods[q];
496
+ shippingMethodItem.onchange = function() {
497
+ updateCartKlarna("shipping");
498
+ updateCartKlarna("cart");
499
+ return false;
500
+ };
501
+ };
502
+ };
503
+
504
+
505
+ // Coupon
506
+ if (document.querySelector('#klarna_coupon button')) {
507
+ document.querySelector('#klarna_coupon button').onclick = function() {
508
+ var couponRemove = document.getElementById('remove-coupone');
509
+ var couponInput = document.getElementById('coupon_code');
510
+
511
+ if (this.className.match(/(?:^|\s)cancel-btn(?!\S)/)) {
512
+ couponRemove.value = 1;
513
+ document.cookie = 'klarnaDiscountShipping=1; expires=0;';
514
+ updateCartKlarna("coupon");
515
+ updateCartKlarna("cart");
516
+ } else if (!couponInput.value) {
517
+ couponInput.focus();
518
+ for(i=0;i<3;i++) {
519
+ fadeOut(couponInput);
520
+ fadeIn(couponInput);
521
+ }
522
+ setTimeout(function() {
523
+ couponInput.className = couponInput.className.replace( /(?:^|\s)error(?!\S)/g , '' )
524
+ }, 6000)
525
+ } else {
526
+ document.cookie = 'klarnaDiscountShipping=1; expires=0;';
527
+ updateCartKlarna('coupon');
528
+ updateCartKlarna("cart");
529
+ }
530
+ };
531
+ }
532
+
533
+ if (document.getElementById('coupon_code')) {
534
+ document.getElementById('coupon_code').onkeydown = function(e) {
535
+ if (e.which == 13) {
536
+ e.preventDefault();
537
+ updateCartKlarna("coupon");
538
+ }
539
+ };
540
+ }
541
+
542
+
543
+ // Giftcard
544
+ if (document.querySelector('#giftcard-form button')) {
545
+ document.querySelector('#giftcard-form button').onclick = function(e) {
546
+ e.preventDefault();
547
+ var giftcardInput = document.getElementById('giftcard_code');
548
+
549
+ if (!giftcardInput.value) {
550
+ giftcardInput.focus();
551
+ for (i = 0; i < 3; i++) {
552
+ fadeOut(giftcardInput);
553
+ fadeIn(giftcardInput);
554
+ }
555
+ setTimeout(function() {
556
+ giftcardInput.className = couponInput.className.replace(
557
+ /(?:^|\s)error(?!\S)/g, '')
558
+ }, 6000)
559
+ } else {
560
+ updateCartKlarna('giftcard');
561
+ updateCartKlarna('cart');
562
+ }
563
+ };
564
+ }
565
+
566
+ if (document.getElementById('giftcard_code')) {
567
+ document.getElementById('giftcard_code').onkeydown = function(e) {
568
+ if (e.which == 13) {
569
+ e.preventDefault();
570
+ updateCartKlarna("giftcard");
571
+ }
572
+ };
573
+ }
574
+
575
+ // Giftcard remove on Klarna
576
+ if (document.querySelector('#applied-gift-cards .btn-remove')) {
577
+ document.querySelector('#applied-gift-cards .btn-remove').onclick = function(e) {
578
+ e.preventDefault();
579
+ updateCartKlarna('giftcard-remove', this.getAttribute('href'));
580
+ updateCartKlarna('cart');
581
+ };
582
+ }
583
+
584
+ for (var q=0; q<removeItemElement.length; q++) {
585
+ removeItem = removeItemElement[q];
586
+ removeItem.onclick = function() {
587
+ var itemid = this.getAttribute('data-itemid');
588
+ fadeOut(document.getElementById('cart_item_' + itemid));
589
+ document.getElementById('cart_item_qty_' + itemid).value = 0;
590
+ updateCartKlarna("cart");
591
+ return false;
592
+ };
593
+ };
594
+
595
+ for (var q=0; q<subtrackItemElement.length; q++) {
596
+ subtrackItem = subtrackItemElement[q];
597
+ subtrackItem.onclick = function() {
598
+ var itemid = this.getAttribute('data-itemid'),
599
+ qtyInput = document.getElementById('cart_item_qty_' + itemid),
600
+ qtyCurrent = parseInt(qtyInput.value);
601
+
602
+ qtyInput.value = (qtyCurrent - 1);
603
+ if (qtyCurrent - 1 == 0) {
604
+ fadeOut(document.getElementById('cart_item_' + itemid));
605
+ }
606
+ updateCartKlarna("cart", qtyInput, qtyCurrent);
607
+ return false;
608
+ };
609
+ };
610
+
611
+ for (var q=0; q<addItemElement.length; q++) {
612
+ addItem = addItemElement[q];
613
+ addItem.onclick = function() {
614
+ var itemid = this.getAttribute('data-itemid'),
615
+ qtyInput = document.getElementById('cart_item_qty_' + itemid),
616
+ qtyCurrent = parseInt(qtyInput.value);
617
+
618
+ qtyInput.value = (qtyCurrent + 1);
619
+ updateCartKlarna("cart", qtyInput, qtyCurrent);
620
+ return false;
621
+ };
622
+ };
623
+
624
+ for (var q=0; q<qtyInputList.length; q++) {
625
+ inputField = qtyInputList[q];
626
+
627
+ inputField.onblur = function() {
628
+ var itemid = this.getAttribute('data-itemid'),
629
+ qtyInput = document.getElementById('cart_item_qty_' + itemid),
630
+ qtyCurrent = parseInt(qtyInput.value),
631
+ qtyOrgInput = document.getElementById('cart_item_qty_org_' + itemid),
632
+ qtyOrgCurrent = parseInt(qtyOrgInput.value);
633
+
634
+ if (qtyCurrent != qtyOrgCurrent) {
635
+ updateCartKlarna("cart", qtyInput, qtyOrgCurrent);
636
+ }
637
+ };
638
+
639
+ inputField.onkeydown = function(e) {
640
+ if (e.which == 13) {
641
+ e.preventDefault();
642
+ var itemid = this.getAttribute('data-itemid'),
643
+ qtyInput = document.getElementById('cart_item_qty_' + itemid),
644
+ qtyCurrent = parseInt(qtyInput.value),
645
+ qtyOrgInput = document.getElementById('cart_item_qty_org_' + itemid),
646
+ qtyOrgCurrent = parseInt(qtyOrgInput.value);
647
+
648
+ if (qtyCurrent != qtyOrgCurrent) {
649
+ updateCartKlarna("cart", qtyInput, qtyOrgCurrent);
650
+ }
651
+ }
652
+ };
653
+ };
654
+
655
+ };
656
+
657
+ // If there's no shipping option selected when the document loads, then select
658
+ // the first option
659
+ docReady(function() {
660
+ var shippingChecked = document.getElementsByClassName('.shipping-method-input-radio:checked');
661
+ document.cookie = 'klarnaDiscountShipping=0; expires=0;';
662
+
663
+ if (!shippingChecked) {
664
+ document.querySelector("input[name=shipping_method]:first-child").checked = true
665
+ document.cookie = 'klarnaAddShipping=1; expires=0;';
666
+ updateCartKlarna("shipping");
667
+ }
668
+
669
+ bindCheckoutControls();
670
+ });
671
+
672
+ function klarnaCheckoutGo(url) {
673
+ window.location.assign(url);
674
+ }
675
+
lib/Klarna/Changelog-Vaimo.txt ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ setVersion
3
+ Function setVersion in Klarna.php changed from protected to public, to be able to set that variable, without having to inherit the class
4
+
5
+ checkout
6
+ Renamed folder checkout to checkoutkpm, in order to be able to have Klarna checkout library in the same folder
7
+ This change also meant changes had to be made to all files trying to call checkout/* files/classes:
8
+ File Klarna.php, function initCheckout
9
+ File Klarna.php, function checkoutHTML
10
+
11
+ KlarnaCheckout
12
+ Added folder Checkout and Checkout.php to Klarna folder
13
+
14
+ Klarna_Checkout_Connector - create
15
+ Klarna_Checkout_BasicConnector - __construct
16
+ Klarna_Checkout_BasicConnector - userAgent
17
+ Added parameter to library so I could send in module and application version in the userAgent
18
+
19
+
lib/Klarna/Checkout.php ADDED
@@ -0,0 +1,50 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Copyright 2012 Klarna AB
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ *
17
+ * Bootstrap file to include the klarna checkout library
18
+ *
19
+ * PHP version 5.3
20
+ *
21
+ * @category Payment
22
+ * @package Klarna_Checkout
23
+ * @author Klarna <support@klarna.com>
24
+ * @copyright 2012 Klarna AB
25
+ * @license http://www.apache.org/licenses/LICENSE-2.0 Apache license v2.0
26
+ * @link http://integration.klarna.com/
27
+ */
28
+
29
+ define('KLARNA_CHECKOUT_DIR', dirname(__file__) . '/Checkout');
30
+
31
+ require_once KLARNA_CHECKOUT_DIR . '/ConnectorInterface.php';
32
+ require_once KLARNA_CHECKOUT_DIR . '/ResourceInterface.php';
33
+ require_once KLARNA_CHECKOUT_DIR . '/Connector.php';
34
+ require_once KLARNA_CHECKOUT_DIR . '/BasicConnector.php';
35
+ require_once KLARNA_CHECKOUT_DIR . '/Order.php';
36
+ require_once KLARNA_CHECKOUT_DIR . '/Digest.php';
37
+ require_once KLARNA_CHECKOUT_DIR . '/Exception.php';
38
+ require_once KLARNA_CHECKOUT_DIR . '/ConnectionErrorException.php';
39
+ require_once KLARNA_CHECKOUT_DIR . '/ConnectorException.php';
40
+ require_once KLARNA_CHECKOUT_DIR . '/UserAgent.php';
41
+
42
+ require_once KLARNA_CHECKOUT_DIR . '/HTTP/TransportInterface.php';
43
+ require_once KLARNA_CHECKOUT_DIR . '/HTTP/CURLHandleInterface.php';
44
+ require_once KLARNA_CHECKOUT_DIR . '/HTTP/Request.php';
45
+ require_once KLARNA_CHECKOUT_DIR . '/HTTP/Response.php';
46
+ require_once KLARNA_CHECKOUT_DIR . '/HTTP/Transport.php';
47
+ require_once KLARNA_CHECKOUT_DIR . '/HTTP/CURLTransport.php';
48
+ require_once KLARNA_CHECKOUT_DIR . '/HTTP/CURLHeaders.php';
49
+ require_once KLARNA_CHECKOUT_DIR . '/HTTP/CURLHandle.php';
50
+ require_once KLARNA_CHECKOUT_DIR . '/HTTP/CURLFactory.php';
lib/Klarna/Checkout/BasicConnector.php ADDED
@@ -0,0 +1,345 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Copyright 2012 Klarna AB
5
+ *
6
+ * Licensed under the Apache License, Version 2.0 (the "License");
7
+ * you may not use this file except in compliance with the License.
8
+ * You may obtain a copy of the License at
9
+ *
10
+ * http://www.apache.org/licenses/LICENSE-2.0
11
+ *
12
+ * Unless required by applicable law or agreed to in writing, software
13
+ * distributed under the License is distributed on an "AS IS" BASIS,
14
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ * See the License for the specific language governing permissions and
16
+ * limitations under the License.
17
+ *
18
+ * File containing the Klarna_Checkout_BasicConnector class
19
+ *
20
+ * PHP version 5.3
21
+ *
22
+ * @category Payment
23
+ * @package Klarna_Checkout
24
+ * @author Klarna <support@klarna.com>
25
+ * @copyright 2012 Klarna AB
26
+ * @license http://www.apache.org/licenses/LICENSE-2.0 Apache license v2.0
27
+ * @link http://integration.klarna.com/
28
+ */
29
+
30
+ /**
31
+ * Basic implementation of the connector interface
32
+ *
33
+ * @category Payment
34
+ * @package Klarna_Checkout
35
+ * @author Rickard D. <rickard.dybeck@klarna.com>
36
+ * @author Christer G. <christer.gustavsson@klarna.com>
37
+ * @author David K. <david.keijser@klarna.com>
38
+ * @copyright 2012 Klarna AB
39
+ * @license http://www.apache.org/licenses/LICENSE-2.0 Apache license v2.0
40
+ * @link http://integration.klarna.com/
41
+ */
42
+ class Klarna_Checkout_BasicConnector implements Klarna_Checkout_ConnectorInterface
43
+ {
44
+
45
+ /**
46
+ * Klarna_Checkout_HTTP_TransportInterface Implementation
47
+ *
48
+ * @var Klarna_Checkout_HTTP_TransportInterface
49
+ */
50
+ protected $http;
51
+
52
+ /**
53
+ * Digester class
54
+ *
55
+ * @var Klarna_Checkout_Digest
56
+ */
57
+ protected $digester;
58
+
59
+ /**
60
+ * Shared Secret used to sign requests
61
+ *
62
+ * @var string
63
+ */
64
+ private $_secret;
65
+
66
+ /**
67
+ *
68
+ * Vaimo added parameter $moduleInfo
69
+ *
70
+ * @var string
71
+ */
72
+ private $_moduleInfo;
73
+
74
+
75
+ /**
76
+ * Create a new Checkout Connector
77
+ *
78
+ * @param Klarna_Checkout_HTTP_TransportInterface $http transport
79
+ * @param Klarna_Checkout_Digest $digester Digest Generator
80
+ * @param string $secret shared secret
81
+ * @param string $moduleInfo module information
82
+ */
83
+ public function __construct(
84
+ Klarna_Checkout_HTTP_TransportInterface $http,
85
+ Klarna_Checkout_Digest $digester,
86
+ $secret,
87
+ $moduleInfo = NULL
88
+ ) {
89
+ $this->http = $http;
90
+ $this->digester = $digester;
91
+ $this->_secret = $secret;
92
+ $this->_moduleInfo = $moduleInfo;
93
+ }
94
+
95
+ /**
96
+ *
97
+ * Vaimo changed function and added addField call
98
+ *
99
+ * @var string
100
+ */
101
+ /**
102
+ * Create the user agent identifier to use
103
+ *
104
+ * @return Klarna_Checkout_UserAgent
105
+ */
106
+ protected function userAgent()
107
+ {
108
+ // return new Klarna_Checkout_UserAgent($this->_moduleInfo);
109
+ $agent = new Klarna_Checkout_UserAgent($this->_moduleInfo);
110
+ if ($this->_moduleInfo) {
111
+ foreach ($this->_moduleInfo as $id => $info) {
112
+ $agent->addField($id, $info);
113
+ }
114
+ }
115
+ return $agent;
116
+ }
117
+
118
+ /**
119
+ * Applying the method on the specific resource
120
+ *
121
+ * @param string $method Http methods
122
+ * @param Klarna_Checkout_ResourceInterface $resource resource
123
+ * @param array $options Options
124
+ *
125
+ * @return mixed
126
+ */
127
+ public function apply(
128
+ $method,
129
+ Klarna_Checkout_ResourceInterface $resource,
130
+ array $options = null
131
+ ) {
132
+ switch ($method) {
133
+ case 'GET':
134
+ case 'POST':
135
+ return $this->handle($method, $resource, $options, array());
136
+ default:
137
+ throw new InvalidArgumentException(
138
+ "{$method} is not a valid HTTP method"
139
+ );
140
+ }
141
+ }
142
+
143
+ /**
144
+ * Gets the underlying transport object
145
+ *
146
+ * @return Klarna_Checkout_HTTP_TransportInterface Transport object
147
+ */
148
+ public function getTransport()
149
+ {
150
+ return $this->http;
151
+ }
152
+
153
+ /**
154
+ * Set content (headers, payload) on a request
155
+ *
156
+ * @param Klarna_Checkout_ResourceInterface $resource Klarna Checkout Resource
157
+ * @param string $method HTTP Method
158
+ * @param string $payload Payload to send with the
159
+ * request
160
+ * @param string $url URL for request
161
+ *
162
+ * @return Klarna_Checkout_HTTP_Request
163
+ */
164
+ protected function createRequest(
165
+ Klarna_Checkout_ResourceInterface $resource,
166
+ $method,
167
+ $payload,
168
+ $url
169
+ ) {
170
+ // Generate the digest string
171
+ $digest = $this->digester->create($payload . $this->_secret);
172
+
173
+ $request = $this->http->createRequest($url);
174
+
175
+ $request->setMethod($method);
176
+
177
+ // Set HTTP Headers
178
+ $request->setHeader('User-Agent', (string)$this->userAgent());
179
+ $request->setHeader('Authorization', "Klarna {$digest}");
180
+ $request->setHeader('Accept', $resource->getContentType());
181
+ if (strlen($payload) > 0) {
182
+ $request->setHeader('Content-Type', $resource->getContentType());
183
+ $request->setData($payload);
184
+ }
185
+
186
+ return $request;
187
+ }
188
+
189
+ /**
190
+ * Get the url to use
191
+ *
192
+ * @param Klarna_Checkout_ResourceInterface $resource resource
193
+ * @param array $options Options
194
+ *
195
+ * @return string Url to use for HTTP requests
196
+ */
197
+ protected function getUrl(
198
+ Klarna_Checkout_ResourceInterface $resource, array $options
199
+ ) {
200
+ if (array_key_exists('url', $options)) {
201
+ return $options['url'];
202
+ }
203
+
204
+ return $resource->getLocation();
205
+ }
206
+
207
+ /**
208
+ * Get the data to use
209
+ *
210
+ * @param Klarna_Checkout_ResourceInterface $resource resource
211
+ * @param array $options Options
212
+ *
213
+ * @return array data to use for HTTP requests
214
+ */
215
+ protected function getData(
216
+ Klarna_Checkout_ResourceInterface $resource, array $options
217
+ ) {
218
+ if (array_key_exists('data', $options)) {
219
+ return $options['data'];
220
+ }
221
+
222
+ return $resource->marshal();
223
+ }
224
+
225
+ /**
226
+ * Throw an exception if the server responds with an error code.
227
+ *
228
+ * @param Klarna_Checkout_HTTP_Response $result HTTP Response object
229
+ *
230
+ * @throws Klarna_Checkout_HTTP_Status_Exception
231
+ * @return void
232
+ */
233
+ protected function verifyResponse(Klarna_Checkout_HTTP_Response $result)
234
+ {
235
+ // Error Status Code recieved. Throw an exception.
236
+ if ($result->getStatus() >= 400 && $result->getStatus() <= 599) {
237
+ throw new Klarna_Checkout_ConnectorException(
238
+ $result->getData(), $result->getStatus()
239
+ );
240
+ }
241
+ }
242
+
243
+ /**
244
+ * Act upon the status of a response
245
+ *
246
+ * @param Klarna_Checkout_HTTP_Response $result response from server
247
+ * @param Klarna_Checkout_ResourceInterface $resource associated resource
248
+ * @param array $visited list of visited locations
249
+ *
250
+ * @return Klarna_Checkout_HTTP_Response
251
+ */
252
+ protected function handleResponse(
253
+ Klarna_Checkout_HTTP_Response $result,
254
+ Klarna_Checkout_ResourceInterface $resource,
255
+ array $visited = array()
256
+ ) {
257
+ // Check if we got an Error status code back
258
+ $this->verifyResponse($result);
259
+
260
+ $url = $result->getHeader('Location');
261
+ switch ($result->getStatus()) {
262
+ case 301:
263
+ // Update location and fallthrough
264
+ $resource->setLocation($url);
265
+ case 302:
266
+ // Don't fallthrough for other than GET
267
+ if ($result->getRequest()->getMethod() !== 'GET') {
268
+ break;
269
+ }
270
+ case 303:
271
+ // Detect eternal loops
272
+ if (in_array($url, $visited)) {
273
+ throw new Klarna_Checkout_ConnectorException(
274
+ 'Infinite redirect loop detected.',
275
+ -1
276
+ );
277
+ }
278
+ $visited[] = $url;
279
+ // Follow redirect
280
+ return $this->handle(
281
+ 'GET',
282
+ $resource,
283
+ array('url' => $url),
284
+ $visited
285
+ );
286
+ case 201:
287
+ // Update Location
288
+ $resource->setLocation($url);
289
+ break;
290
+ case 200:
291
+ // Update Data on resource
292
+ $json = json_decode($result->getData(), true);
293
+ if ($json === null) {
294
+ throw new Klarna_Checkout_ConnectorException(
295
+ 'Bad format on response content.',
296
+ -2
297
+ );
298
+ }
299
+ $resource->parse($json);
300
+ }
301
+
302
+ return $result;
303
+ }
304
+
305
+ /**
306
+ * Perform a HTTP Call on the supplied resource using the wanted method.
307
+ *
308
+ * @param string $method HTTP Method
309
+ * @param Klarna_Checkout_ResourceInterface $resource Klarna Order
310
+ * @param array $options Options
311
+ * @param array $visited list of visited locations
312
+ *
313
+ * @throws Klarna_Checkout_Exception if 4xx or 5xx response code.
314
+ * @return Result object containing status code and payload
315
+ */
316
+ protected function handle(
317
+ $method,
318
+ Klarna_Checkout_ResourceInterface $resource,
319
+ array $options = null,
320
+ array $visited = array()
321
+ ) {
322
+ if ($options === null) {
323
+ $options = array();
324
+ }
325
+
326
+ // Define the target URL
327
+ $url = $this->getUrl($resource, $options);
328
+
329
+ // Set a payload if it is a POST call.
330
+ $payload = '';
331
+ if ($method === 'POST') {
332
+ $payload = json_encode($this->getData($resource, $options));
333
+ }
334
+
335
+ // Create a HTTP Request object
336
+ $request = $this->createRequest($resource, $method, $payload, $url);
337
+ // $this->_setContent($request, $payload, $method);
338
+
339
+ // Execute the HTTP Request
340
+ $result = $this->http->send($request);
341
+
342
+ // Handle statuses appropriately.
343
+ return $this->handleResponse($result, $resource, $visited);
344
+ }
345
+ }
lib/Klarna/Checkout/ConnectionErrorException.php ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Copyright 2012 Klarna AB
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ *
17
+ * File containing the Klarna_Checkout_ConnectionErrorException class
18
+ *
19
+ * PHP version 5.3
20
+ *
21
+ * @category Payment
22
+ * @package Klarna_Checkout
23
+ * @author Klarna <support@klarna.com>
24
+ * @copyright 2012 Klarna AB
25
+ * @license http://www.apache.org/licenses/LICENSE-2.0 Apache license v2.0
26
+ * @link http://integration.klarna.com/
27
+ */
28
+
29
+ /**
30
+ * Connection exception
31
+ *
32
+ * @category Payment
33
+ * @package Klarna_Checkout
34
+ * @author Rickard D. <rickard.dybeck@klarna.com>
35
+ * @author Christer G. <christer.gustavsson@klarna.com>
36
+ * @copyright 2012 Klarna AB
37
+ * @license http://www.apache.org/licenses/LICENSE-2.0 Apache license v2.0
38
+ * @link http://integration.klarna.com/
39
+ */
40
+ class Klarna_Checkout_ConnectionErrorException extends Klarna_Checkout_Exception
41
+ {
42
+
43
+ }
lib/Klarna/Checkout/Connector.php ADDED
@@ -0,0 +1,64 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Copyright 2012 Klarna AB
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ *
17
+ * File containing the Klarna_Checkout_Connector facade class
18
+ *
19
+ * PHP version 5.3
20
+ *
21
+ * @category Payment
22
+ * @package Klarna_Checkout
23
+ * @author Klarna <support@klarna.com>
24
+ * @copyright 2012 Klarna AB
25
+ * @license http://www.apache.org/licenses/LICENSE-2.0 Apache license v2.0
26
+ * @link http://integration.klarna.com/
27
+ */
28
+
29
+ /**
30
+ * Connector factory
31
+ *
32
+ * @category Payment
33
+ * @package Klarna_Checkout
34
+ * @author Rickard D. <rickard.dybeck@klarna.com>
35
+ * @author Christer G. <christer.gustavsson@klarna.com>
36
+ * @author David K. <david.keijser@klarna.com>
37
+ * @copyright 2012 Klarna AB
38
+ * @license http://www.apache.org/licenses/LICENSE-2.0 Apache license v2.0
39
+ * @link http://integration.klarna.com/
40
+ */
41
+ class Klarna_Checkout_Connector
42
+ {
43
+ /**
44
+ *
45
+ * Vaimo added parameter $moduleInfo
46
+ *
47
+ */
48
+ /**
49
+ * Create a new Checkout Connector
50
+ *
51
+ * @param string $secret string used to sign requests
52
+ *
53
+ * @return Klarna_Checkout_ConnectorInterface
54
+ */
55
+ public static function create($secret, $moduleInfo = NULL)
56
+ {
57
+ return new Klarna_Checkout_BasicConnector(
58
+ Klarna_Checkout_HTTP_Transport::create(),
59
+ new Klarna_Checkout_Digest,
60
+ $secret,
61
+ $moduleInfo
62
+ );
63
+ }
64
+ }
lib/Klarna/Checkout/ConnectorException.php ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Copyright 2012 Klarna AB
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ *
17
+ * File containing the Klarna_Checkout_ConnectorException class
18
+ *
19
+ * PHP version 5.3
20
+ *
21
+ * @category Payment
22
+ * @package Klarna_Checkout
23
+ * @author Klarna <support@klarna.com>
24
+ * @copyright 2012 Klarna AB
25
+ * @license http://www.apache.org/licenses/LICENSE-2.0 Apache license v2.0
26
+ * @link http://integration.klarna.com/
27
+ */
28
+
29
+ /**
30
+ * Connector exception
31
+ *
32
+ * @category Payment
33
+ * @package Klarna_Checkout
34
+ * @author Rickard D. <rickard.dybeck@klarna.com>
35
+ * @author David K. <david.keijser@klarna.com>
36
+ * @copyright 2012 Klarna AB
37
+ * @license http://www.apache.org/licenses/LICENSE-2.0 Apache license v2.0
38
+ * @link http://integration.klarna.com/
39
+ */
40
+ class Klarna_Checkout_ConnectorException extends Klarna_Checkout_Exception
41
+ {
42
+
43
+ }
lib/Klarna/Checkout/ConnectorInterface.php ADDED
@@ -0,0 +1,64 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Copyright 2012 Klarna AB
5
+ *
6
+ * Licensed under the Apache License, Version 2.0 (the "License");
7
+ * you may not use this file except in compliance with the License.
8
+ * You may obtain a copy of the License at
9
+ *
10
+ * http://www.apache.org/licenses/LICENSE-2.0
11
+ *
12
+ * Unless required by applicable law or agreed to in writing, software
13
+ * distributed under the License is distributed on an "AS IS" BASIS,
14
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ * See the License for the specific language governing permissions and
16
+ * limitations under the License.
17
+ *
18
+ * File containing the Klarna_Checkout_Connector interface
19
+ *
20
+ * PHP version 5.3
21
+ *
22
+ * @category Payment
23
+ * @package Klarna_Checkout
24
+ * @author Klarna <support@klarna.com>
25
+ * @copyright 2012 Klarna AB
26
+ * @license http://www.apache.org/licenses/LICENSE-2.0 Apache license v2.0
27
+ * @link http://integration.klarna.com/
28
+ */
29
+
30
+ /**
31
+ * Interface for the resource object
32
+ *
33
+ * @category Payment
34
+ * @package Klarna_Checkout
35
+ * @author Majid G. <majid.garmaroudi@klarna.com>
36
+ * @author David K. <david.keijser@klarna.com>
37
+ * @copyright 2012 Klarna AB
38
+ * @license http://www.apache.org/licenses/LICENSE-2.0 Apache license v2.0
39
+ * @link http://integration.klarna.com/
40
+ */
41
+ interface Klarna_Checkout_ConnectorInterface
42
+ {
43
+ /**
44
+ * Applying the method on the specific resource
45
+ *
46
+ * @param string $method Http methods
47
+ * @param Klarna_Checkout_ResourceInterface $resource resource
48
+ * @param array $options Options
49
+ *
50
+ * @return void
51
+ */
52
+ public function apply(
53
+ $method,
54
+ Klarna_Checkout_ResourceInterface $resource,
55
+ array $options = null
56
+ );
57
+
58
+ /**
59
+ * Gets the underlying transport object
60
+ *
61
+ * @return Klarna_Checkout_HTTP_TransportInterface Transport object
62
+ */
63
+ public function getTransport();
64
+ }
lib/Klarna/Checkout/Digest.php ADDED
@@ -0,0 +1,54 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Copyright 2012 Klarna AB
5
+ *
6
+ * Licensed under the Apache License, Version 2.0 (the "License");
7
+ * you may not use this file except in compliance with the License.
8
+ * You may obtain a copy of the License at
9
+ *
10
+ * http://www.apache.org/licenses/LICENSE-2.0
11
+ *
12
+ * Unless required by applicable law or agreed to in writing, software
13
+ * distributed under the License is distributed on an "AS IS" BASIS,
14
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ * See the License for the specific language governing permissions and
16
+ * limitations under the License.
17
+ *
18
+ * File containing the Klarna_Checkout_Digester class
19
+ *
20
+ * PHP version 5.3
21
+ *
22
+ * @category Payment
23
+ * @package Klarna_Checkout
24
+ * @author Klarna <support@klarna.com>
25
+ * @copyright 2012 Klarna AB
26
+ * @license http://www.apache.org/licenses/LICENSE-2.0 Apache license v2.0
27
+ * @link http://integration.klarna.com/
28
+ */
29
+
30
+ /**
31
+ * Class to handle the digesting of hash string
32
+ *
33
+ * @category Payment
34
+ * @package Klarna_Checkout
35
+ * @author Rickard D. <rickard.dybeck@klarna.com>
36
+ * @author Christer G. <christer.gustavsson@klarna.com>
37
+ * @copyright 2012 Klarna AB
38
+ * @license http://www.apache.org/licenses/LICENSE-2.0 Apache license v2.0
39
+ * @link http://integration.klarna.com/
40
+ */
41
+ class Klarna_Checkout_Digest
42
+ {
43
+ /**
44
+ * create a digest from a supplied string
45
+ *
46
+ * @param string $digestString string to hash
47
+ *
48
+ * @return string Base64 and SHA256 hashed string
49
+ */
50
+ public function create($digestString)
51
+ {
52
+ return base64_encode(hash('sha256', $digestString, true));
53
+ }
54
+ }
lib/Klarna/Checkout/Exception.php ADDED
@@ -0,0 +1,44 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Copyright 2012 Klarna AB
5
+ *
6
+ * Licensed under the Apache License, Version 2.0 (the "License");
7
+ * you may not use this file except in compliance with the License.
8
+ * You may obtain a copy of the License at
9
+ *
10
+ * http://www.apache.org/licenses/LICENSE-2.0
11
+ *
12
+ * Unless required by applicable law or agreed to in writing, software
13
+ * distributed under the License is distributed on an "AS IS" BASIS,
14
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ * See the License for the specific language governing permissions and
16
+ * limitations under the License.
17
+ *
18
+ * File containing the Klarna_Checkout_Exception class
19
+ *
20
+ * PHP version 5.3
21
+ *
22
+ * @category Payment
23
+ * @package Klarna_Checkout
24
+ * @author Klarna <support@klarna.com>
25
+ * @copyright 2012 Klarna AB
26
+ * @license http://www.apache.org/licenses/LICENSE-2.0 Apache license v2.0
27
+ * @link http://integration.klarna.com/
28
+ */
29
+
30
+ /**
31
+ * Basic exception class
32
+ *
33
+ * @category Payment
34
+ * @package Klarna_Checkout
35
+ * @author Majid G. <majid.garmaroudi@klarna.com>
36
+ * @author David K. <david.keijser@klarna.com>
37
+ * @copyright 2012 Klarna AB
38
+ * @license http://www.apache.org/licenses/LICENSE-2.0 Apache license v2.0
39
+ * @link http://integration.klarna.com/
40
+ */
41
+ class Klarna_Checkout_Exception extends Exception
42
+ {
43
+
44
+ }
lib/Klarna/Checkout/HTTP/CURLFactory.php ADDED
@@ -0,0 +1,52 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Copyright 2012 Klarna AB
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ *
17
+ * File containing the PHPUnit Klarna_HTTP_CURLTest test case
18
+ *
19
+ * PHP version 5.3
20
+ *
21
+ * @category Payment
22
+ * @package Payment_Klarna
23
+ * @subpackage Unit_Tests
24
+ * @author Klarna <support@klarna.com>
25
+ * @copyright 2012 Klarna AB
26
+ * @license http://www.apache.org/licenses/LICENSE-2.0 Apache license v2.0
27
+ * @link http://integration.klarna.com/
28
+ */
29
+
30
+ /**
31
+ * Factory of cURL handles
32
+ *
33
+ * @category Payment
34
+ * @package Payment_Klarna
35
+ * @subpackage Unit_Tests
36
+ * @author Klarna <support@klarna.com>
37
+ * @copyright 2012 Klarna AB
38
+ * @license http://www.apache.org/licenses/LICENSE-2.0 Apache license v2.0
39
+ * @link http://integration.klarna.com/
40
+ */
41
+ class Klarna_Checkout_HTTP_CURLFactory
42
+ {
43
+ /**
44
+ * Create a new cURL handle
45
+ *
46
+ * @return Klarna_Checkout_HTTP_CURLHandle
47
+ */
48
+ public function handle()
49
+ {
50
+ return new Klarna_Checkout_HTTP_CURLHandle();
51
+ }
52
+ }
lib/Klarna/Checkout/HTTP/CURLHandle.php ADDED
@@ -0,0 +1,105 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Copyright 2012 Klarna AB
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ *
17
+ * File containing the Klarna_Checkout_HTTP_CURLHeaders class
18
+ *
19
+ * PHP version 5.3
20
+ *
21
+ * @category Payment
22
+ * @package Payment_Klarna
23
+ * @subpackage HTTP
24
+ * @author Klarna <support@klarna.com>
25
+ * @copyright 2012 Klarna AB
26
+ * @license http://www.apache.org/licenses/LICENSE-2.0 Apache license v2.0
27
+ * @link http://integration.klarna.com/
28
+ */
29
+
30
+ /**
31
+ * A wrapper around the cURL functions
32
+ *
33
+ * @category Payment
34
+ * @package Payment_Klarna
35
+ * @subpackage HTTP
36
+ * @author David K. <david.keijser@klarna.com>
37
+ * @copyright 2012 Klarna AB
38
+ * @license http://www.apache.org/licenses/LICENSE-2.0 Apache license v2.0
39
+ * @link http://integration.klarna.com/
40
+ */
41
+ class Klarna_Checkout_HTTP_CURLHandle
42
+ implements Klarna_Checkout_HTTP_CURLHandleInterface
43
+ {
44
+ /**
45
+ * cURL handle
46
+ * @var resource
47
+ */
48
+ private $_handle = null;
49
+
50
+ /**
51
+ * Create a new cURL handle
52
+ */
53
+ public function __construct()
54
+ {
55
+ if (!extension_loaded('curl')) {
56
+ throw new RuntimeException(
57
+ 'cURL extension is requred.'
58
+ );
59
+ }
60
+ $this->_handle = curl_init();
61
+ }
62
+
63
+ /**
64
+ * Set an option for the cURL transfer
65
+ *
66
+ * @param int $name option the set
67
+ * @param mixed $value the value to be set on option
68
+ *
69
+ * @return void
70
+ */
71
+ public function setOption($name, $value)
72
+ {
73
+ curl_setopt($this->_handle, $name, $value);
74
+ }
75
+
76
+ /**
77
+ * Perform the cURL session
78
+ *
79
+ * @return mixed response
80
+ */
81
+ public function execute()
82
+ {
83
+ return curl_exec($this->_handle);
84
+ }
85
+
86
+ /**
87
+ * Get information regarding this transfer
88
+ *
89
+ * @return array
90
+ */
91
+ public function getInfo()
92
+ {
93
+ return curl_getinfo($this->_handle);
94
+ }
95
+
96
+ /**
97
+ * Close the cURL session
98
+ *
99
+ * @return void
100
+ */
101
+ public function close()
102
+ {
103
+ curl_close($this->_handle);
104
+ }
105
+ }
lib/Klarna/Checkout/HTTP/CURLHandleInterface.php ADDED
@@ -0,0 +1,73 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Copyright 2012 Klarna AB
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ *
17
+ * File containing the Klarna_Checkout_HTTP_CURLHeaders class
18
+ *
19
+ * PHP version 5.3
20
+ *
21
+ * @category Payment
22
+ * @package Payment_Klarna
23
+ * @subpackage HTTP
24
+ * @author Klarna <support@klarna.com>
25
+ * @copyright 2012 Klarna AB
26
+ * @license http://www.apache.org/licenses/LICENSE-2.0 Apache license v2.0
27
+ * @link http://integration.klarna.com/
28
+ */
29
+
30
+ /**
31
+ * Defines a cURL handle interface
32
+ *
33
+ * @category Payment
34
+ * @package Payment_Klarna
35
+ * @subpackage HTTP
36
+ * @author David K. <david.keijser@klarna.com>
37
+ * @copyright 2012 Klarna AB
38
+ * @license http://www.apache.org/licenses/LICENSE-2.0 Apache license v2.0
39
+ * @link http://integration.klarna.com/
40
+ */
41
+ interface Klarna_Checkout_HTTP_CURLHandleInterface
42
+ {
43
+ /**
44
+ * Set an option for the cURL transfer
45
+ *
46
+ * @param int $name option the set
47
+ * @param mixed $value the value to be set on option
48
+ *
49
+ * @return void
50
+ */
51
+ public function setOption($name, $value);
52
+
53
+ /**
54
+ * Perform the cURL session
55
+ *
56
+ * @return mixed response
57
+ */
58
+ public function execute();
59
+
60
+ /**
61
+ * Get information regarding this transfer
62
+ *
63
+ * @return array
64
+ */
65
+ public function getInfo();
66
+
67
+ /**
68
+ * Close the cURL session
69
+ *
70
+ * @return void
71
+ */
72
+ public function close();
73
+ }
lib/Klarna/Checkout/HTTP/CURLHeaders.php ADDED
@@ -0,0 +1,95 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Copyright 2012 Klarna AB
5
+ *
6
+ * Licensed under the Apache License, Version 2.0 (the "License");
7
+ * you may not use this file except in compliance with the License.
8
+ * You may obtain a copy of the License at
9
+ *
10
+ * http://www.apache.org/licenses/LICENSE-2.0
11
+ *
12
+ * Unless required by applicable law or agreed to in writing, software
13
+ * distributed under the License is distributed on an "AS IS" BASIS,
14
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ * See the License for the specific language governing permissions and
16
+ * limitations under the License.
17
+ *
18
+ * File containing the Klarna_Checkout_HTTP_CURLHeaders class
19
+ *
20
+ * PHP version 5.3
21
+ *
22
+ * @category Payment
23
+ * @package Payment_Klarna
24
+ * @subpackage HTTP
25
+ * @author Klarna <support@klarna.com>
26
+ * @copyright 2012 Klarna AB
27
+ * @license http://www.apache.org/licenses/LICENSE-2.0 Apache license v2.0
28
+ * @link http://integration.klarna.com/
29
+ */
30
+
31
+ /**
32
+ * A simple class handling the header callback for cURL.
33
+ *
34
+ * @category Payment
35
+ * @package Payment_Klarna
36
+ * @subpackage HTTP
37
+ * @author Klarna <support@klarna.com>
38
+ * @copyright 2012 Klarna AB
39
+ * @license http://www.apache.org/licenses/LICENSE-2.0 Apache license v2.0
40
+ * @link http://integration.klarna.com/
41
+ */
42
+ class Klarna_Checkout_HTTP_CURLHeaders
43
+ {
44
+ /**
45
+ * Response headers, cleared for each request.
46
+ *
47
+ * @var array
48
+ */
49
+ protected $headers;
50
+
51
+ /**
52
+ * Initializes a new instance of the HTTP cURL class.
53
+ */
54
+ public function __construct()
55
+ {
56
+ $this->headers = array();
57
+ }
58
+
59
+ /**
60
+ * Callback method to handle custom headers.
61
+ *
62
+ * @param resource $curl the cURL resource.
63
+ * @param string $header the header data.
64
+ *
65
+ * @return int the number of bytes handled.
66
+ */
67
+ public function processHeader($curl, $header)
68
+ {
69
+ $curl = null;
70
+ //TODO replace with regexp, e.g. /^([^:]+):([^:]*)$/ ?
71
+ $pos = strpos($header, ':');
72
+ // Didn't find a colon.
73
+ if ($pos === false) {
74
+ // Not real header, abort.
75
+ return strlen($header);
76
+ }
77
+
78
+ $key = substr($header, 0, $pos);
79
+ $value = trim(substr($header, $pos+1));
80
+
81
+ $this->headers[$key] = trim($value);
82
+
83
+ return strlen($header);
84
+ }
85
+
86
+ /**
87
+ * Gets the accumulated headers.
88
+ *
89
+ * @return array
90
+ */
91
+ public function getHeaders()
92
+ {
93
+ return $this->headers;
94
+ }
95
+ }
lib/Klarna/Checkout/HTTP/CURLTransport.php ADDED
@@ -0,0 +1,182 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Copyright 2012 Klarna AB
5
+ *
6
+ * Licensed under the Apache License, Version 2.0 (the "License");
7
+ * you may not use this file except in compliance with the License.
8
+ * You may obtain a copy of the License at
9
+ *
10
+ * http://www.apache.org/licenses/LICENSE-2.0
11
+ *
12
+ * Unless required by applicable law or agreed to in writing, software
13
+ * distributed under the License is distributed on an "AS IS" BASIS,
14
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ * See the License for the specific language governing permissions and
16
+ * limitations under the License.
17
+ *
18
+ * File containing the Klarna_Checkout_HTTP_CURLTransport class
19
+ *
20
+ * PHP version 5.3
21
+ *
22
+ * @category Payment
23
+ * @package Payment_Klarna
24
+ * @subpackage HTTP
25
+ * @author Klarna <support@klarna.com>
26
+ * @copyright 2012 Klarna AB AB
27
+ * @license http://www.apache.org/licenses/LICENSE-2.0 Apache license v2.0
28
+ * @link http://integration.klarna.com/
29
+ */
30
+
31
+ /**
32
+ * Klarna HTTP transport implementation for cURL
33
+ *
34
+ * @category Payment
35
+ * @package Payment_Klarna
36
+ * @subpackage HTTP
37
+ * @author Klarna <support@klarna.com>
38
+ * @copyright 2012 Klarna AB
39
+ * @license http://www.apache.org/licenses/LICENSE-2.0 Apache license v2.0
40
+ * @link http://integration.klarna.com/
41
+ */
42
+ class Klarna_Checkout_HTTP_CURLTransport
43
+ implements Klarna_Checkout_HTTP_TransportInterface
44
+ {
45
+ const DEFAULT_TIMEOUT = 10;
46
+
47
+ /**
48
+ * @var Klarna_Checkout_HTTP_CURLFactory
49
+ */
50
+ protected $curl;
51
+
52
+ /**
53
+ * Number of seconds before the connection times out.
54
+ *
55
+ * @var int
56
+ */
57
+ protected $timeout;
58
+
59
+ /**
60
+ * Initializes a new instance of the HTTP cURL class.
61
+ *
62
+ * @param Klarna_Checkout_HTTP_CURLFactory $curl factory to for curl handles
63
+ */
64
+ public function __construct(Klarna_Checkout_HTTP_CURLFactory $curl)
65
+ {
66
+ $this->curl = $curl;
67
+ $this->timeout = self::DEFAULT_TIMEOUT;
68
+ }
69
+
70
+ /**
71
+ * Sets the number of seconds until a connection times out.
72
+ *
73
+ * @param int $timeout number of seconds
74
+ *
75
+ * @return void
76
+ */
77
+ public function setTimeout($timeout)
78
+ {
79
+ $this->timeout = intval($timeout);
80
+ }
81
+
82
+ /**
83
+ * Gets the number of seconds before the connection times out.
84
+ *
85
+ * @return int timeout in number of seconds
86
+ */
87
+ public function getTimeout()
88
+ {
89
+ return $this->timeout;
90
+ }
91
+
92
+ /**
93
+ * Performs a HTTP request.
94
+ *
95
+ * @param Klarna_Checkout_HTTP_Request $request the HTTP request to send.
96
+ *
97
+ * @throws RuntimeException Thrown if a cURL handle cannot
98
+ * be initialized.
99
+ * @throws Klarna_Checkout_ConnectionErrorException Thrown for unspecified
100
+ * network or hardware issues.
101
+ * @return Klarna_Checkout_HTTP_Response
102
+ */
103
+ public function send(Klarna_Checkout_HTTP_Request $request)
104
+ {
105
+ $curl = $this->curl->handle();
106
+ if ($curl === false) {
107
+ throw new RuntimeException(
108
+ 'Failed to initialize a HTTP handle.'
109
+ );
110
+ }
111
+
112
+ $url = $request->getURL();
113
+ $curl->setOption(CURLOPT_URL, $url);
114
+
115
+ $method = $request->getMethod();
116
+ if ($method === 'POST') {
117
+ $curl->setOption(CURLOPT_POST, true);
118
+ $curl->setOption(CURLOPT_POSTFIELDS, $request->getData());
119
+ }
120
+
121
+ // Convert headers to cURL format.
122
+ $requestHeaders = array();
123
+ foreach ($request->getHeaders() as $key => $value) {
124
+ $requestHeaders[] = $key . ': ' . $value;
125
+ }
126
+
127
+ $curl->setOption(CURLOPT_HTTPHEADER, $requestHeaders);
128
+
129
+ $curl->setOption(CURLOPT_RETURNTRANSFER, true);
130
+ $curl->setOption(CURLOPT_CONNECTTIMEOUT, $this->timeout);
131
+
132
+ $curlHeaders = new Klarna_Checkout_HTTP_CURLHeaders();
133
+ $curl->setOption(
134
+ CURLOPT_HEADERFUNCTION,
135
+ array(&$curlHeaders, 'processHeader')
136
+ );
137
+
138
+ // TODO remove me when real cert is in place
139
+ $curl->setOption(CURLOPT_SSL_VERIFYPEER, false);
140
+
141
+ $payload = $curl->execute();
142
+ $info = $curl->getInfo();
143
+
144
+ $curl->close();
145
+
146
+ /*
147
+ * A failure occured if:
148
+ * payload is false (e.g. HTTP timeout?).
149
+ * info is false, then it has no HTTP status code.
150
+ */
151
+ if ($payload === false || $info === false) {
152
+ throw new Klarna_Checkout_ConnectionErrorException(
153
+ "Connection to '{$url}' failed."
154
+ );
155
+ }
156
+
157
+ $headers = $curlHeaders->getHeaders();
158
+
159
+ // Convert Content-Type into a normal header
160
+ $headers['Content-Type'] = $info['content_type'];
161
+
162
+ $response = new Klarna_Checkout_HTTP_Response(
163
+ $request, $headers, intval($info['http_code']), strval($payload)
164
+ );
165
+
166
+ return $response;
167
+ }
168
+
169
+ /**
170
+ * Creates a HTTP request object.
171
+ *
172
+ * @param string $url the request URL.
173
+ *
174
+ * @throws InvalidArgumentException If the specified argument
175
+ * is not of type string.
176
+ * @return Klarna_Checkout_HTTP_Request
177
+ */
178
+ public function createRequest($url)
179
+ {
180
+ return new Klarna_Checkout_HTTP_Request($url);
181
+ }
182
+ }
lib/Klarna/Checkout/HTTP/Request.php ADDED
@@ -0,0 +1,185 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Copyright 2012 Klarna AB
5
+ *
6
+ * Licensed under the Apache License, Version 2.0 (the "License");
7
+ * you may not use this file except in compliance with the License.
8
+ * You may obtain a copy of the License at
9
+ *
10
+ * http://www.apache.org/licenses/LICENSE-2.0
11
+ *
12
+ * Unless required by applicable law or agreed to in writing, software
13
+ * distributed under the License is distributed on an "AS IS" BASIS,
14
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ * See the License for the specific language governing permissions and
16
+ * limitations under the License.
17
+ *
18
+ * File containing the Klarna_Checkout_HTTP_Request class
19
+ *
20
+ * PHP version 5.3
21
+ *
22
+ * @category Payment
23
+ * @package Payment_Klarna
24
+ * @subpackage HTTP
25
+ * @author Klarna <support@klarna.com>
26
+ * @copyright 2012 Klarna AB
27
+ * @license http://www.apache.org/licenses/LICENSE-2.0 Apache license v2.0
28
+ * @link http://integration.klarna.com/
29
+ */
30
+
31
+ /**
32
+ * Klarna HTTP Request class
33
+ *
34
+ * @category Payment
35
+ * @package Payment_Klarna
36
+ * @subpackage HTTP
37
+ * @author Klarna <support@klarna.com>
38
+ * @copyright 2012 Klarna AB
39
+ * @license http://www.apache.org/licenses/LICENSE-2.0 Apache license v2.0
40
+ * @link http://integration.klarna.com/
41
+ */
42
+ class Klarna_Checkout_HTTP_Request
43
+ {
44
+ /**
45
+ * @var string
46
+ */
47
+ protected $url;
48
+
49
+ /**
50
+ * @var string
51
+ */
52
+ protected $method;
53
+
54
+ /**
55
+ * @var array
56
+ */
57
+ protected $headers;
58
+
59
+ /**
60
+ * @var string
61
+ */
62
+ protected $data;
63
+
64
+ /**
65
+ * Initializes a new instance of the HTTP request class.
66
+ *
67
+ * @param string $url the request URL.
68
+ *
69
+ * @throws InvalidArgumentException If the specified argument
70
+ * is not of type string.
71
+ */
72
+ public function __construct($url)
73
+ {
74
+ $this->url = $url;
75
+ $this->method = 'GET';
76
+ $this->headers = array();
77
+ $this->data = '';
78
+ }
79
+
80
+ /**
81
+ * Gets the request URL.
82
+ *
83
+ * @return string the request URL.
84
+ */
85
+ public function getURL()
86
+ {
87
+ return $this->url;
88
+ }
89
+
90
+ /**
91
+ * Specifies the HTTP method used for the request.
92
+ *
93
+ * @param string $method a HTTP method.
94
+ *
95
+ * @throws InvalidArgumentException If the specified argument
96
+ * is not of type string.
97
+ * @return void
98
+ */
99
+ public function setMethod($method)
100
+ {
101
+ $this->method = strtoupper($method);
102
+ }
103
+
104
+ /**
105
+ * Gets the HTTP method used for the request.
106
+ *
107
+ * @return string a HTTP method
108
+ */
109
+ public function getMethod()
110
+ {
111
+ return $this->method;
112
+ }
113
+
114
+ /**
115
+ * Specifies a header for the request.
116
+ *
117
+ * @param string $name the header name
118
+ * @param mixed $value the header value
119
+ *
120
+ * @throws InvalidArgumentException If the argument name is not of type
121
+ * string or an empty string.
122
+ * @return void
123
+ */
124
+ public function setHeader($name, $value)
125
+ {
126
+ $this->headers[$name] = strval($value);
127
+ }
128
+
129
+ /**
130
+ * Gets a specific header for the request.
131
+ *
132
+ * @param string $name the header name
133
+ *
134
+ * @throws InvalidArgumentException If the specified argument
135
+ * is not of type string.
136
+ * @return string|null the header value or null if it doesn't exist
137
+ */
138
+ public function getHeader($name)
139
+ {
140
+ if (!array_key_exists($name, $this->headers)) {
141
+ return null;
142
+ }
143
+
144
+ return $this->headers[$name];
145
+ }
146
+
147
+ /**
148
+ * Gets the headers specified for the request.
149
+ *
150
+ * @return array
151
+ */
152
+ public function getHeaders()
153
+ {
154
+ return $this->headers;
155
+ }
156
+
157
+ /**
158
+ * Sets the data (payload) for the request.
159
+ *
160
+ * \code
161
+ * $request->setMethod('POST');
162
+ * $request->setData('some data');
163
+ * \endcode
164
+ *
165
+ * @param string $data the request payload
166
+ *
167
+ * @throws InvalidArgumentException If the specified argument
168
+ * is not of type string.
169
+ * @return void
170
+ */
171
+ public function setData($data)
172
+ {
173
+ $this->data = $data;
174
+ }
175
+
176
+ /**
177
+ * Gets the data (payload) for the request.
178
+ *
179
+ * @return string the request payload
180
+ */
181
+ public function getData()
182
+ {
183
+ return $this->data;
184
+ }
185
+ }
lib/Klarna/Checkout/HTTP/Response.php ADDED
@@ -0,0 +1,142 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Copyright 2012 Klarna AB
5
+ *
6
+ * Licensed under the Apache License, Version 2.0 (the "License");
7
+ * you may not use this file except in compliance with the License.
8
+ * You may obtain a copy of the License at
9
+ *
10
+ * http://www.apache.org/licenses/LICENSE-2.0
11
+ *
12
+ * Unless required by applicable law or agreed to in writing, software
13
+ * distributed under the License is distributed on an "AS IS" BASIS,
14
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ * See the License for the specific language governing permissions and
16
+ * limitations under the License.
17
+ *
18
+ * File containing the Klarna_HTTP_Response class
19
+ *
20
+ * PHP version 5.3
21
+ *
22
+ * @category Payment
23
+ * @package Payment_Klarna
24
+ * @subpackage HTTP
25
+ * @author Klarna <support@klarna.com>
26
+ * @copyright 2012 Klarna AB
27
+ * @license http://www.apache.org/licenses/LICENSE-2.0 Apache license v2.0
28
+ * @link http://integration.klarna.com/
29
+ */
30
+
31
+ /**
32
+ * Klarna HTTP Response class
33
+ *
34
+ * @category Payment
35
+ * @package Payment_Klarna
36
+ * @subpackage HTTP
37
+ * @author Klarna <support@klarna.com>
38
+ * @copyright 2012 Klarna AB
39
+ * @license http://www.apache.org/licenses/LICENSE-2.0 Apache license v2.0
40
+ * @link http://integration.klarna.com/
41
+ */
42
+ class Klarna_Checkout_HTTP_Response
43
+ {
44
+ /**
45
+ * @var int
46
+ */
47
+ protected $status;
48
+
49
+ /**
50
+ * @var Klarna_Checkout_HTTP_Request
51
+ */
52
+ protected $request;
53
+
54
+ /**
55
+ * @var array
56
+ */
57
+ protected $headers;
58
+
59
+ /**
60
+ * @var string
61
+ */
62
+ protected $data;
63
+
64
+ /**
65
+ * Initializes a new instance of the HTTP response class.
66
+ *
67
+ * @param Klarna_Checkout_HTTP_Request $request the origin request.
68
+ * @param array $headers the response HTTP headers.
69
+ * @param int $status the HTTP status code.
70
+ * @param string $data the response payload.
71
+ */
72
+ public function __construct(
73
+ Klarna_Checkout_HTTP_Request $request, array $headers, $status, $data
74
+ ) {
75
+ $this->request = $request;
76
+ $this->headers = array();
77
+ foreach ($headers as $key => $value) {
78
+ $this->headers[strtolower($key)] = $value;
79
+ }
80
+ $this->status = $status;
81
+ $this->data = $data;
82
+ }
83
+
84
+ /**
85
+ * Gets the HTTP status code.
86
+ *
87
+ * @return int HTTP status code.
88
+ */
89
+ public function getStatus()
90
+ {
91
+ return $this->status;
92
+ }
93
+
94
+ /**
95
+ * Gets the HTTP request this response originated from.
96
+ *
97
+ * @return Klarna_Checkout_HTTP_Request
98
+ */
99
+ public function getRequest()
100
+ {
101
+ return $this->request;
102
+ }
103
+
104
+ /**
105
+ * Gets specified HTTP header.
106
+ *
107
+ * @param string $name the header name.
108
+ *
109
+ * @throws InvalidArgumentException If the specified argument
110
+ * is not of type string.
111
+ * @return string|null Null if header doesn't exist, else header value.
112
+ */
113
+ public function getHeader($name)
114
+ {
115
+ $name = strtolower($name);
116
+ if (!array_key_exists($name, $this->headers)) {
117
+ return null;
118
+ }
119
+
120
+ return $this->headers[$name];
121
+ }
122
+
123
+ /**
124
+ * Gets the headers specified for the response.
125
+ *
126
+ * @return array
127
+ */
128
+ public function getHeaders()
129
+ {
130
+ return $this->headers;
131
+ }
132
+
133
+ /**
134
+ * Gets the data (payload) for the response.
135
+ *
136
+ * @return string the response payload.
137
+ */
138
+ public function getData()
139
+ {
140
+ return $this->data;
141
+ }
142
+ }
lib/Klarna/Checkout/HTTP/Transport.php ADDED
@@ -0,0 +1,54 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Copyright 2012 Klarna AB
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ *
17
+ * File containing the Transport factory
18
+ *
19
+ * PHP version 5.3
20
+ *
21
+ * @category Payment
22
+ * @package Payment_Klarna
23
+ * @subpackage Unit_Tests
24
+ * @author Klarna <support@klarna.com>
25
+ * @copyright 2012 Klarna AB
26
+ * @license http://www.apache.org/licenses/LICENSE-2.0 Apache license v2.0
27
+ * @link http://integration.klarna.com/
28
+ */
29
+
30
+ /**
31
+ * Factory of HTTP Transport
32
+ *
33
+ * @category Payment
34
+ * @package Payment_Klarna
35
+ * @subpackage Unit_Tests
36
+ * @author David K. <david.keijser@klarna.com>
37
+ * @copyright 2012 Klarna AB
38
+ * @license http://www.apache.org/licenses/LICENSE-2.0 Apache license v2.0
39
+ * @link http://integration.klarna.com/
40
+ */
41
+ class Klarna_Checkout_HTTP_Transport
42
+ {
43
+ /**
44
+ * Create a new transport instance
45
+ *
46
+ * @return Klarna_Checkout_HTTP_TransportInterface
47
+ */
48
+ public static function create()
49
+ {
50
+ return new Klarna_Checkout_HTTP_CURLTransport(
51
+ new Klarna_Checkout_HTTP_CURLFactory
52
+ );
53
+ }
54
+ }
lib/Klarna/Checkout/HTTP/TransportInterface.php ADDED
@@ -0,0 +1,83 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Copyright 2012 Klarna AB
5
+ *
6
+ * Licensed under the Apache License, Version 2.0 (the "License");
7
+ * you may not use this file except in compliance with the License.
8
+ * You may obtain a copy of the License at
9
+ *
10
+ * http://www.apache.org/licenses/LICENSE-2.0
11
+ *
12
+ * Unless required by applicable law or agreed to in writing, software
13
+ * distributed under the License is distributed on an "AS IS" BASIS,
14
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ * See the License for the specific language governing permissions and
16
+ * limitations under the License.
17
+ *
18
+ * File containing the Klarna_Checkout_HTTP_TransportInterface interface
19
+ *
20
+ * PHP version 5.3
21
+ *
22
+ * @category Payment
23
+ * @package Payment_Klarna
24
+ * @subpackage Interfaces
25
+ * @author Klarna <support@klarna.com>
26
+ * @copyright 2012 Klarna AB
27
+ * @license http://www.apache.org/licenses/LICENSE-2.0 Apache license v2.0
28
+ * @link http://integration.klarna.com/
29
+ */
30
+
31
+ /**
32
+ * Interface for a Klarna HTTP Transport object
33
+ *
34
+ * @category Payment
35
+ * @package Payment_Klarna
36
+ * @subpackage Interfaces
37
+ * @author Klarna <support@klarna.com>
38
+ * @copyright 2012 Klarna AB
39
+ * @license http://www.apache.org/licenses/LICENSE-2.0 Apache license v2.0
40
+ * @link http://integration.klarna.com/
41
+ */
42
+ interface Klarna_Checkout_HTTP_TransportInterface
43
+ {
44
+ /**
45
+ * Specifies the number of seconds before the connection times out.
46
+ *
47
+ * @param int $timeout number of seconds
48
+ *
49
+ * @throws InvalidArgumentException If the specified argument
50
+ * is not of type integer.
51
+ * @return void
52
+ */
53
+ public function setTimeout($timeout);
54
+
55
+ /**
56
+ * Gets the number of seconds before the connection times out.
57
+ *
58
+ * @return int timeout in number of seconds
59
+ */
60
+ public function getTimeout();
61
+
62
+ /**
63
+ * Performs a HTTP request.
64
+ *
65
+ * @param Klarna_Checkout_HTTP_Request $request the HTTP request to send.
66
+ *
67
+ * @throws Klarna_Checkout_ConnectionErrorException Thrown for unspecified
68
+ * network or hardware issues.
69
+ * @return Klarna_Checkout_HTTP_Response
70
+ */
71
+ public function send(Klarna_Checkout_HTTP_Request $request);
72
+
73
+ /**
74
+ * Creates a HTTP request object.
75
+ *
76
+ * @param string $url the request URL.
77
+ *
78
+ * @throws InvalidArgumentException If the specified argument
79
+ * is not of type string.
80
+ * @return Klarna_Checkout_HTTP_Request
81
+ */
82
+ public function createRequest($url);
83
+ }
lib/Klarna/Checkout/Order.php ADDED
@@ -0,0 +1,259 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Copyright 2012 Klarna AB
5
+ *
6
+ * Licensed under the Apache License, Version 2.0 (the "License");
7
+ * you may not use this file except in compliance with the License.
8
+ * You may obtain a copy of the License at
9
+ *
10
+ * http://www.apache.org/licenses/LICENSE-2.0
11
+ *
12
+ * Unless required by applicable law or agreed to in writing, software
13
+ * distributed under the License is distributed on an "AS IS" BASIS,
14
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ * See the License for the specific language governing permissions and
16
+ * limitations under the License.
17
+ *
18
+ * File containing the Klarna_Checkout_Order class
19
+ *
20
+ * PHP version 5.3
21
+ *
22
+ * @category Payment
23
+ * @package Klarna_Checkout
24
+ * @author Klarna <support@klarna.com>
25
+ * @copyright 2012 Klarna AB
26
+ * @license http://www.apache.org/licenses/LICENSE-2.0 Apache license v2.0
27
+ * @link http://integration.klarna.com/
28
+ */
29
+
30
+ /**
31
+ * Implementation of the order resource
32
+ *
33
+ * @category Payment
34
+ * @package Klarna_Checkout
35
+ * @author Majid G. <majid.garmaroudi@klarna.com>
36
+ * @author David K. <david.keijser@klarna.com>
37
+ * @copyright 2012 Klarna AB
38
+ * @license http://www.apache.org/licenses/LICENSE-2.0 Apache license v2.0
39
+ * @link http://integration.klarna.com/
40
+ */
41
+ class Klarna_Checkout_Order
42
+ implements Klarna_Checkout_ResourceInterface, ArrayAccess
43
+ {
44
+ /**
45
+ * Base URI that is used to create order resources
46
+ *
47
+ * @var string
48
+ */
49
+ public static $baseUri = null;
50
+
51
+ /**
52
+ * Content Type to use
53
+ *
54
+ * @var string
55
+ */
56
+ public static $contentType = null;
57
+
58
+ /**
59
+ * URI of remote resource
60
+ *
61
+ * @var string
62
+ */
63
+ private $_location;
64
+
65
+ /**
66
+ * Order data
67
+ *
68
+ * @var array
69
+ */
70
+ private $_data = array();
71
+
72
+ /**
73
+ * Connector
74
+ *
75
+ * @var Klarna_Checkout_ConnectorInterface
76
+ */
77
+ protected $connector;
78
+
79
+ /**
80
+ * Create a new Order object
81
+ *
82
+ * @param Klarna_Checkout_ConnectorInterface $connector connector to use
83
+ * @param string $uri uri of resource
84
+ *
85
+ * @return void
86
+ */
87
+ public function __construct(
88
+ Klarna_Checkout_ConnectorInterface $connector,
89
+ $uri = null
90
+ ) {
91
+ $this->connector = $connector;
92
+ if ($uri !== null) {
93
+ $this->setLocation($uri);
94
+ }
95
+ }
96
+
97
+ /**
98
+ * Get the URL of the resource
99
+ *
100
+ * @return string
101
+ */
102
+ public function getLocation()
103
+ {
104
+ return $this->_location;
105
+ }
106
+
107
+ /**
108
+ * Set the URL of the resource
109
+ *
110
+ * @param string $location URL of the resource
111
+ *
112
+ * @return void
113
+ */
114
+ public function setLocation($location)
115
+ {
116
+ $this->_location = strval($location);
117
+ }
118
+
119
+ /**
120
+ * Return content type of the resource
121
+ *
122
+ * @return string Content type
123
+ */
124
+ public function getContentType()
125
+ {
126
+ return self::$contentType;
127
+ }
128
+
129
+ /**
130
+ * Replace resource data
131
+ *
132
+ * @param array $data data
133
+ *
134
+ * @return void
135
+ */
136
+ public function parse(array $data)
137
+ {
138
+ $this->_data = $data;
139
+ }
140
+
141
+ /**
142
+ * Basic representation of the object
143
+ *
144
+ * @return array Data
145
+ */
146
+ public function marshal()
147
+ {
148
+ return $this->_data;
149
+ }
150
+
151
+ /**
152
+ * Create a new order
153
+ *
154
+ * @param array $data data to initialise order resource with
155
+ *
156
+ * @return void
157
+ */
158
+ public function create(array $data)
159
+ {
160
+ $options = array(
161
+ 'url' => self::$baseUri,
162
+ 'data' => $data
163
+ );
164
+
165
+ $this->connector->apply('POST', $this, $options);
166
+ }
167
+
168
+ /**
169
+ * Fetch order data
170
+ *
171
+ * @return void
172
+ */
173
+ public function fetch()
174
+ {
175
+ $options = array(
176
+ 'url' => $this->_location
177
+ );
178
+ $this->connector->apply('GET', $this, $options);
179
+ }
180
+
181
+ /**
182
+ * Update order data
183
+ *
184
+ * @param array $data data to update order resource with
185
+ *
186
+ * @return void
187
+ */
188
+ public function update(
189
+ array $data
190
+ ) {
191
+ $options = array(
192
+ 'url' => $this->_location,
193
+ 'data' => $data
194
+ );
195
+ $this->connector->apply('POST', $this, $options);
196
+ }
197
+
198
+ /**
199
+ * Get value of a key
200
+ *
201
+ * @param string $key Key
202
+ *
203
+ * @return mixed data
204
+ */
205
+ public function offsetGet($key)
206
+ {
207
+ if (!is_string($key)) {
208
+ throw new InvalidArgumentException("Key must be string");
209
+ }
210
+
211
+ return $this->_data[$key];
212
+ }
213
+
214
+ /**
215
+ * Set value of a key
216
+ *
217
+ * @param string $key Key
218
+ * @param mixed $value Value of the key
219
+ *
220
+ * @return void
221
+ */
222
+ public function offsetSet($key, $value)
223
+ {
224
+ if (!is_string($key)) {
225
+ throw new InvalidArgumentException("Key must be string");
226
+ }
227
+
228
+ $value = print_r($value, true);
229
+ throw new RuntimeException(
230
+ "Use update function to change values. trying to set $key to $value"
231
+ );
232
+ }
233
+
234
+ /**
235
+ * Check if a key exists in the resource
236
+ *
237
+ * @param string $key key
238
+ *
239
+ * @return boolean
240
+ */
241
+ public function offsetExists($key)
242
+ {
243
+ return array_key_exists($key, $this->_data);
244
+ }
245
+
246
+ /**
247
+ * Unset the value of a key
248
+ *
249
+ * @param string $key key
250
+ *
251
+ * @return void
252
+ */
253
+ public function offsetUnset($key)
254
+ {
255
+ throw new RuntimeException(
256
+ "unset of fields not supported. trying to unset $key"
257
+ );
258
+ }
259
+ }
lib/Klarna/Checkout/ResourceInterface.php ADDED
@@ -0,0 +1,81 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Copyright 2012 Klarna AB
5
+ *
6
+ * Licensed under the Apache License, Version 2.0 (the "License");
7
+ * you may not use this file except in compliance with the License.
8
+ * You may obtain a copy of the License at
9
+ *
10
+ * http://www.apache.org/licenses/LICENSE-2.0
11
+ *
12
+ * Unless required by applicable law or agreed to in writing, software
13
+ * distributed under the License is distributed on an "AS IS" BASIS,
14
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ * See the License for the specific language governing permissions and
16
+ * limitations under the License.
17
+ *
18
+ * File containing the Klarna_Checkout_Resource interface
19
+ *
20
+ * PHP version 5.3
21
+ *
22
+ * @category Payment
23
+ * @package Klarna_Checkout
24
+ * @author Klarna <support@klarna.com>
25
+ * @copyright 2012 Klarna AB
26
+ * @license http://www.apache.org/licenses/LICENSE-2.0 Apache license v2.0
27
+ * @link http://integration.klarna.com/
28
+ */
29
+
30
+ /**
31
+ * Interface for the resource object
32
+ *
33
+ * @category Payment
34
+ * @package Klarna_Checkout
35
+ * @author Majid G. <majid.garmaroudi@klarna.com>
36
+ * @author David K. <david.keijser@klarna.com>
37
+ * @copyright 2012 Klarna AB
38
+ * @license http://www.apache.org/licenses/LICENSE-2.0 Apache license v2.0
39
+ * @link http://integration.klarna.com/
40
+ */
41
+ interface Klarna_Checkout_ResourceInterface
42
+ {
43
+ /**
44
+ * Get the URL of the resource
45
+ *
46
+ * @return string
47
+ */
48
+ public function getLocation();
49
+
50
+ /**
51
+ * Set the URL of the resource
52
+ *
53
+ * @param string $location URL of the resource
54
+ *
55
+ * @return void
56
+ */
57
+ public function setLocation($location);
58
+
59
+ /**
60
+ * Return content type of the resource
61
+ *
62
+ * @return string Content type
63
+ */
64
+ public function getContentType();
65
+
66
+ /**
67
+ * Update resource with the new data
68
+ *
69
+ * @param array $data data
70
+ *
71
+ * @return void
72
+ */
73
+ public function parse(array $data);
74
+
75
+ /**
76
+ * Basic representation of the object
77
+ *
78
+ * @return array data
79
+ */
80
+ public function marshal();
81
+ }
lib/Klarna/Checkout/UserAgent.php ADDED
@@ -0,0 +1,104 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Copyright 2012 Klarna AB
5
+ *
6
+ * Licensed under the Apache License, Version 2.0 (the "License");
7
+ * you may not use this file except in compliance with the License.
8
+ * You may obtain a copy of the License at
9
+ *
10
+ * http://www.apache.org/licenses/LICENSE-2.0
11
+ *
12
+ * Unless required by applicable law or agreed to in writing, software
13
+ * distributed under the License is distributed on an "AS IS" BASIS,
14
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ * See the License for the specific language governing permissions and
16
+ * limitations under the License.
17
+ *
18
+ * File containing the Klarna_Checkout_UserAgent class
19
+ *
20
+ * PHP version 5.3
21
+ *
22
+ * @category Payment
23
+ * @package Klarna_Checkout
24
+ * @author Klarna <support@klarna.com>
25
+ * @copyright 2012 Klarna AB
26
+ * @license http://www.apache.org/licenses/LICENSE-2.0 Apache license v2.0
27
+ * @link http://integration.klarna.com/
28
+ */
29
+
30
+ /**
31
+ * UserAgent string builder
32
+ *
33
+ * @category Payment
34
+ * @package Klarna_Checkout
35
+ * @author David K. <david.keijser@klarna.com>
36
+ * @copyright 2012 Klarna AB
37
+ * @license http://www.apache.org/licenses/LICENSE-2.0 Apache license v2.0
38
+ * @link http://integration.klarna.com/
39
+ */
40
+ class Klarna_Checkout_UserAgent
41
+ {
42
+ /**
43
+ * Components of the user-agent
44
+ *
45
+ * @var array
46
+ */
47
+ private $_fields;
48
+
49
+ /**
50
+ * Initialise user-agent with default fields
51
+ */
52
+ public function __construct()
53
+ {
54
+ $this->_fields = array(
55
+ 'Library' => array(
56
+ 'name' => 'Klarna.ApiWrapper',
57
+ 'version' => '1.1.0',
58
+ ),
59
+ 'OS' => array(
60
+ 'name' => php_uname('s'),
61
+ 'version' => php_uname('r')
62
+ ),
63
+ 'Language' => array(
64
+ 'name' => 'PHP',
65
+ 'version' => phpversion()
66
+ )
67
+ );
68
+ }
69
+
70
+ /**
71
+ * Add a new field to the user agent
72
+ *
73
+ * @param string $field Name of field
74
+ * @param array $data data array with name, version and possibly options
75
+ *
76
+ * @return void
77
+ */
78
+ public function addField($field, array $data)
79
+ {
80
+ if (array_key_exists($field, $this->_fields)) {
81
+ throw new Klarna_Checkout_Exception(
82
+ "Unable to redefine field {$field}"
83
+ );
84
+ }
85
+ $this->_fields[$field] = $data;
86
+ }
87
+
88
+ /**
89
+ * Serialise fields to a user agent string
90
+ *
91
+ * @return string
92
+ */
93
+ public function __toString()
94
+ {
95
+ $parts = array();
96
+ foreach ($this->_fields as $key => $value) {
97
+ $parts[] = "$key/{$value['name']}_{$value['version']}";
98
+ if (array_key_exists('options', $value)) {
99
+ $parts[] = '(' . implode(' ; ', $value['options']) . ')';
100
+ }
101
+ }
102
+ return implode(' ', $parts);
103
+ }
104
+ }
lib/Klarna/Klarna.php CHANGED
@@ -3709,10 +3709,10 @@ class Klarna
3709
  $dir = dirname(__FILE__);
3710
 
3711
  //Require the CheckoutHTML interface/abstract class
3712
- include_once $dir.'/checkout/checkouthtml.intf.php';
3713
 
3714
  //Iterate over all .class.php files in checkout/
3715
- foreach (glob($dir.'/checkout/*.class.php') as $checkout) {
3716
  if (!self::$debug) {
3717
  ob_start();
3718
  }
@@ -3750,7 +3750,7 @@ class Klarna
3750
  $dir = dirname(__FILE__);
3751
 
3752
  //Require the CheckoutHTML interface/abstract class
3753
- include_once $dir.'/checkout/checkouthtml.intf.php';
3754
 
3755
  //Iterate over all .class.php files in
3756
  $html = "\n";
3709
  $dir = dirname(__FILE__);
3710
 
3711
  //Require the CheckoutHTML interface/abstract class
3712
+ include_once $dir.'/checkoutkpm/checkouthtml.intf.php';
3713
 
3714
  //Iterate over all .class.php files in checkout/
3715
+ foreach (glob($dir.'/checkoutkpm/*.class.php') as $checkout) {
3716
  if (!self::$debug) {
3717
  ob_start();
3718
  }
3750
  $dir = dirname(__FILE__);
3751
 
3752
  //Require the CheckoutHTML interface/abstract class
3753
+ include_once $dir.'/checkoutkpm/checkouthtml.intf.php';
3754
 
3755
  //Iterate over all .class.php files in
3756
  $html = "\n";
lib/Klarna/{checkout → checkoutkpm}/checkouthtml.intf.php RENAMED
File without changes
lib/Klarna/{checkout → checkoutkpm}/threatmetrix.class.php RENAMED
File without changes
package.xml CHANGED
@@ -1,18 +1,18 @@
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>klarnapayments</name>
4
- <version>5.1.7</version>
5
  <stability>stable</stability>
6
  <license>Open Software License (OSL)</license>
7
  <channel>community</channel>
8
  <extends/>
9
- <summary>Klarna module for invoice and part payment</summary>
10
- <description>Klarna payment module for invoice and part payments. This module works with both invoice and part payments in Sweden, Finland, Denmark, Norway, Germany, Austria and Netherlands. To use this module requires that you have a contract with Klarna.</description>
11
  <notes>This version is not compatible with any Klarna module version of 4.x or earlier.</notes>
12
  <authors><author><name>Klarna</name><user>Klarna</user><email>magento@klarna.com</email></author><author><name>Vaimo</name><user>VAIMO</user><email>info@vaimo.com</email></author></authors>
13
- <date>2014-08-15</date>
14
- <time>09:03:57</time>
15
- <contents><target name="magecommunity"><dir name="Vaimo"><dir name="Klarna"><dir name="Block"><dir name="Adminhtml"><dir name="Pclass"><file name="List.php" hash="50db355e3da129c8870fb1385c7e346f"/><file name="Update.php" hash="fd444645b9f78fc4ea65c91ee3fc0044"/></dir><dir name="Sales"><dir name="Creditmemo"><dir name="Create"><file name="Adjustments.php" hash="12074f6aabbe90f14b8d30b7f65da9dc"/></dir><file name="Totals.php" hash="198afd117e90e17999f24c419a92b24b"/></dir><dir name="Invoice"><file name="Totals.php" hash="bc28f21c484fe2b4ca6d7a06da726fc3"/></dir><dir name="Order"><file name="Totals.php" hash="c80ca5283b0341964c36e70a850faaf6"/></dir></dir></dir><dir name="Catalog"><dir name="Product"><file name="Pricewidget.php" hash="f3235ed383b06cc8a5b1f587aab3e581"/></dir></dir><dir name="Checkout"><file name="Fee.php" hash="1ffae1896b12e6d87fbbd2d3843fef75"/><file name="Top.php" hash="c28060443f710ab345ec2a742b4477b8"/></dir><dir name="Form"><file name="Abstract.php" hash="733aafd4a3ded20eba9c04a76213882c"/><file name="Account.php" hash="f6bf008c1af0b93ead5b5a2577b59ea5"/><dir name="Address"><file name="Search.php" hash="600b472559cbcec011f03244eed499b5"/></dir><file name="Invoice.php" hash="105a41b84e52b45f26f3c5de2d4bdd4a"/><dir name="Paymentplan"><file name="Information.php" hash="7c66acd887a1e3a165e3cd967d0f3331"/></dir><file name="Special.php" hash="8db5a5f33510cd32d724c6ecd6368aa2"/></dir><dir name="Info"><file name="Abstract.php" hash="caf208862b2336027ca2d498008603fe"/><file name="Account.php" hash="d302c2fc556e05858464fadd51cd4854"/><file name="Invoice.php" hash="f98adb5521f6c546c462f2e5bde31295"/><file name="Special.php" hash="e07662f39f0ff65505bfd627045c7766"/></dir><dir name="Invoice"><file name="Totals.php" hash="2437d7c7d7499d3ee2fcb7e0426ad64d"/></dir><dir name="Order"><file name="Totals.php" hash="2e56335ff1b4a1d6752e7336b107bd13"/></dir><dir name="Page"><dir name="Html"><file name="Logo.php" hash="2a04f0f8e3be0df5bb5be7bbaa8ebb0b"/></dir></dir></dir><dir name="Helper"><file name="Data.php" hash="092dbb1b42a02311add8e6e9e76901f2"/></dir><dir name="Model"><dir name="Creditmemo"><file name="Tax.php" hash="3a6bc7530bff27bf459661e0d1e9fd0a"/><file name="Total.php" hash="f328960e057bbb5d548521af44059a13"/></dir><dir name="Invoice"><dir name="Pdf"><file name="Total.php" hash="4a436823d6d97eefc32e37425a290e6e"/></dir><file name="Tax.php" hash="3baf99ade36b04f384d1c15cb4d7ed67"/><file name="Total.php" hash="2f6a6cd43221fd19b35b15cd2e7c3640"/></dir><dir name="Klarna"><file name="Addresssearch.php" hash="e3387ff4a122a664482bd5fee40c1813"/><file name="Api.php" hash="aa9d287043f6be51cb2f87518abcaee6"/><file name="Assign.php" hash="aa4689397bed9888a1a238ab6d971c4d"/><file name="Authorize.php" hash="bc17198adec7bcfd2f05709f326b82df"/><file name="Available.php" hash="0aec5ebf162c459e645d84e02b255e11"/><file name="Cancel.php" hash="4632675d11ca981c5052db1f0cca184b"/><file name="Capture.php" hash="2beb7bced6bb2055c13c5b92883ca33a"/><file name="Form.php" hash="ac6255922a3af1f4d176cde1798e47be"/><file name="Info.php" hash="4957a14af1c087b35dbd594535f8b126"/><file name="Pclass.php" hash="46cf1bc8f4a3c659283856567b61d6e8"/><file name="Refund.php" hash="5cb1d208f8fbd63a775209d46120f434"/><dir name="Tools"><file name="Abstract.php" hash="4f3ae29de83a93c8629626559c5ce907"/><file name="Address.php" hash="a0158b7d2cc0eafb44a8c4f5467044d1"/><file name="Api.php" hash="2675b8f3da170af8bbda8f5443433e4d"/></dir><file name="Validate.php" hash="94ee56e3431c5b1aad762729988aa646"/><file name="Widget.php" hash="5ba02191e1d74244626e74ca5393906a"/></dir><file name="Observer.php" hash="0e5a24a6cb75f8d9e7ffd2e1cf490d35"/><dir name="Payment"><file name="Abstract.php" hash="7900216a6f2c23c33310574b917a2ae0"/><file name="Account.php" hash="6c905fbd93ae0c198b1c1d7d4865b8a0"/><file name="Invoice.php" hash="e77f59b136528a64c7e9a1f5ce28b850"/><file name="Special.php" hash="fa6767acffd19a5411c3a547c644b85b"/></dir><dir name="Quote"><file name="Tax.php" hash="7a4eab3cd02115cfedb1ba7af3358b73"/><file name="Total.php" hash="6bac56d746083634d31decb568e8362e"/></dir><dir name="Resource"><dir name="Mysql4"><file name="Setup.php" hash="0a40d43403823a6053d74bd2d2f688e7"/></dir></dir><dir name="Source"><file name="Allspecificcountries.php" hash="3ef9f594b15aa3b06f89d961da8e4315"/><file name="Capture.php" hash="f491dd88120e191d65d7d2ff53860236"/><file name="Country.php" hash="591cac4c906f9640ec4e83b67f3a89bb"/><file name="Language.php" hash="8e425aad2a21c0d2ffa450a376735451"/><file name="Servermode.php" hash="702a23f9fbac1c5618e3d7f234bff7c8"/><file name="Taxclass.php" hash="836424e4e3569d41e4321a846c59c98b"/></dir><dir name="Tax"><file name="Config.php" hash="7ac7e62c358331e99e3439a12cb9f852"/></dir></dir><dir name="Tests"><dir name="Model"><dir name="Klarna"><file name="ApiTest.php" hash="1a8617c031cda61a4b10e67d448e1e99"/><file name="ValidateTest.php" hash="b252d4600110b09c9d11dfa9642c0a8c"/></dir></dir><file name="TestCase.php" hash="2eb43dd276ab9489a7adc49665fdba7e"/><file name="bootstrap.php" hash="15c72bd1a5e73d91f9272166684e35c6"/></dir><dir name="controllers"><file name="AddressController.php" hash="0d6ceb7ca9ee6dce08d316cecd84c990"/><dir name="Adminhtml"><dir name="Klarna"><file name="PclassController.php" hash="1b2e714da75b47e6eddb18b004b0c8ec"/></dir></dir><file name="PaymentplanController.php" hash="89128f42495bbfb81028b5e37d1465ea"/></dir><dir name="etc"><file name="config.xml" hash="67ffab47a3924489e0d79d5126c2fe91"/><file name="system.xml" hash="fe1c33cc8c37c732a124a64eca943896"/></dir><dir name="sql"><dir name="klarna_setup"><file name="mysql4-install-0.1.0.php" hash="d36b51433fd28241386594f39def3080"/></dir></dir></dir></dir></target><target name="magedesign"><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="layout"><file name="vaimo_klarna.xml" hash="19a196d33bcc2e1eaf4413dcefeb5f04"/></dir><dir name="template"><dir name="vaimo"><dir name="klarna"><dir name="creditmemo"><dir name="totals"><file name="adjustments.phtml" hash="b0299ac0b1ca75b4d143413cc8eb8217"/></dir></dir><dir name="info"><file name="account.phtml" hash="14225b9a0b95d52926d5ccee339b445a"/><dir name="children"><file name="invoicefee.phtml" hash="2b721be479706716f6468c8395455fa5"/><file name="invoices.phtml" hash="3d3c653a28bfa95e821abb67c9e06dba"/><file name="paymentplan.phtml" hash="885c020c05afd4516a42a33a6986f32f"/><file name="reservation.phtml" hash="7beb37cc5df2cda75626d6975beb6829"/></dir><file name="invoice.phtml" hash="1f417e5d0380b53d64966b21bebd4419"/><file name="special.phtml" hash="14225b9a0b95d52926d5ccee339b445a"/></dir><dir name="pclass"><file name="list.phtml" hash="5cef6b0093bb5da18dbf1f9fd7316c66"/><file name="update.phtml" hash="ed53d5eb248f8181cd601e7b10cb170f"/></dir></dir></dir></dir></dir></dir></dir><dir name="frontend"><dir name="base"><dir name="default"><dir name="layout"><file name="vaimo_klarna.xml" hash="b4fdb67bdad6d422c1ce86164eb62ece"/></dir><dir name="template"><dir name="vaimo"><dir name="klarna"><dir name="catalog"><dir name="product"><file name="pricewidget.phtml" hash="f5838b8bb129634487a398ca2557f48b"/></dir></dir><dir name="checkout"><file name="fee.phtml" hash="3a58d7e7278bf9fcae1cdb9d836d4ff3"/><file name="header.phtml" hash="51a7f95f2fcb5f7b02e19b13690631a8"/><file name="top.phtml" hash="9cc1ce32346bd6ed7c16139f3f960a95"/></dir><dir name="form"><file name="account.phtml" hash="25386497892129effff92a64f326ff42"/><dir name="address"><file name="search.phtml" hash="36aa810e587da54995e961f77aa11a72"/></dir><dir name="children"><file name="addressresult.phtml" hash="7ed16bca431a8146139ce51fd7001d11"/><file name="consent.phtml" hash="a4f446258fa20a453d3566cffc20085d"/><file name="dateofbirth.phtml" hash="e1dbe367ce43029d671dae6f7d3ca956"/><file name="gender.phtml" hash="c8428e9b76db957a866cfc109d7a0c09"/><file name="notifications.phtml" hash="485d9f8e90ca6ff3c8152d2c3a0ee138"/><file name="paymentplan_information.phtml" hash="8f28c418c08df3e664744ef28bc283c3"/><file name="pclass.phtml" hash="848a7e485badbdf11d10628c93906b21"/><file name="personalnumber.phtml" hash="a8d723a0ff1b71f07ccdd1aed1dba5fb"/><file name="phonenumber.phtml" hash="6348b12795e073d8881ab0b74d7df175"/></dir><file name="invoice.phtml" hash="43a3a4aaae78b3a835c8de7d9edff8b4"/><dir name="paymentplan"><file name="information.phtml" hash="d19f6766d1bebdacb367aee65edb06fd"/></dir><file name="special.phtml" hash="68561f42f556c496fb46c2c12f35b410"/></dir><dir name="info"><file name="account.phtml" hash="a848c9544a5e400bc27e26d050eafa3c"/><dir name="children"><file name="invoicefee.phtml" hash="c6b4ccff75e220c5641a8fadd6753131"/><file name="invoices.phtml" hash="cbdd0256b8e1d742257bcba9b1eef67a"/><file name="paymentplan.phtml" hash="3a73d918dc733c0888f18e442f9eb64c"/><file name="reservation.phtml" hash="9880ef8208f672d531cc10eef8467856"/></dir><file name="invoice.phtml" hash="cd3514e43dd441b4530b95e408784d84"/><file name="special.phtml" hash="c472684055c8839b8e365b80a5e1ee0c"/></dir><dir name="page"><dir name="html"><file name="logo.phtml" hash="4b67e622b6b5f0421078c2324efd55a3"/></dir></dir></dir></dir></dir></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Vaimo_Klarna.xml" hash="fece558fa050794401aca834b1b12fd4"/></dir></target><target name="magelocale"><dir name="da_DK"><file name="Vaimo_Klarna.csv" hash="9175c738f0d5f027d36ce3b383f20fd4"/></dir><dir name="de_AT"><file name="Vaimo_Klarna.csv" hash="f742305a0efc0a3e3ccd3abdc2905d70"/></dir><dir name="de_DE"><file name="Vaimo_Klarna.csv" hash="6bb2b881b1681b3e8aba6fdcbeed1fe6"/></dir><dir name="fi_FI"><file name="Vaimo_Klarna.csv" hash="0501deb83f9e7b96a11508d591d9307c"/></dir><dir name="nb_NO"><file name="Vaimo_Klarna.csv" hash="7b55b60812003c4d14917d689af05780"/></dir><dir name="nl_NL"><file name="Vaimo_Klarna.csv" hash="0146ce5d1dca315654f48baa6f9b8f73"/></dir><dir name="nn_NO"><file name="Vaimo_Klarna.csv" hash="30c305e173968f339faf5c1c41d21b09"/></dir><dir name="sv_SE"><file name="Vaimo_Klarna.csv" hash="22446c8a3709837854385427ae7e2d7f"/></dir></target><target name="mage"><dir name="js"><dir name="vaimo"><dir name="klarna"><file name="klarna.js" hash="580f2f4f363461734c578b0297a33b2e"/></dir></dir></dir></target><target name="magelib"><dir name="Klarna"><file name="CHANGELOG" hash="7c2deef157ef77304e1d0efc970d6c48"/><file name="Country.php" hash="40360c3964fc6193e7fb922845eb419b"/><file name="Currency.php" hash="a709407428d86521cc0775cbeb281523"/><file name="Encoding.php" hash="f8f8e744303ff7ce7f4b226331e7bdcf"/><file name="Exceptions.php" hash="933b2811e910da817743766cdde8ffeb"/><file name="Flags.php" hash="b407a1373adf5f172bef3e3d01e81cdb"/><file name="Klarna.php" hash="1fbeb52770b21cd6dd1fde92c734d928"/><file name="Language.php" hash="8e40aed0dece8f0a3fbe07e37451af16"/><dir name="checkout"><file name="checkouthtml.intf.php" hash="81e0740254585f2af67895df28093d35"/><file name="threatmetrix.class.php" hash="6ce1bfded90b6b3bb329176ff4c7acac"/></dir><dir name="examples"><file name="activate.php" hash="b49a0bd5c5a57577b9765d657dad7b78"/><file name="activateInvoice.php" hash="31061b3cf79a6fd32f580f3aa6b603ad"/><file name="activatePart.php" hash="72af1ee8d312df08e24cdc7b01cc72ed"/><file name="activateReservation.php" hash="6380e346db2466a655df17cbe4078b3a"/><file name="addTransaction.php" hash="015cdd7663d7bbe0716f8ed8f700e13e"/><file name="calc_monthly_cost.php" hash="9a45009fe051f76bd2d23db854f67cad"/><file name="cancelReservation.php" hash="219504c253caa372f479af8f6bf452eb"/><file name="changeReservation.php" hash="cdf4f971d74570e2ba9191792f69bf79"/><file name="checkOrderStatus.php" hash="b9d12df62f9619cb791bc4db9b2e19c4"/><file name="creditInvoice.php" hash="f174d28d812f5139c4a0397a27f419d9"/><file name="creditPart.php" hash="4c1a6397eb2bc7ee0bac5ed1a76aa7d8"/><file name="deleteInvoice.php" hash="b59be611d1ba7439d0c9ec43f38e8f95"/><file name="emailInvoice.php" hash="31f644dc6b1a97181d3ba474f2d77517"/><file name="fetchPClasses.php" hash="18a60ab1bde9ace0765c58f3343c4165"/><file name="getAddresses.php" hash="bf80e3108d51dcf4c581bff291e4a2fc"/><file name="getPClasses.php" hash="18b7bc054ceb36c8f004d21804fea832"/><file name="invoiceAddress.php" hash="a7a9c89f6ee017d72f9d9d5a959c7416"/><file name="invoiceAmount.php" hash="d404dba99dd5efd2954bec58eab720ca"/><file name="invoicePartAmount.php" hash="37e3726190f1fb403fbba19de2088dd5"/><file name="reserveAmount.php" hash="4c93a455264dafc93a2cd9ce41c8aaaa"/><file name="reserveOCR.php" hash="a67258e40b080027c5e60490a15d3347"/><file name="returnAmount.php" hash="ae01bab7225bdd6529593d499247e8f6"/><file name="sendInvoice.php" hash="46584ac7995d779ff4fa2a4a4b109df9"/><file name="splitReservation.php" hash="35c495a8bfc1e29b109a0de3800d4d44"/><file name="update.php" hash="1275db160660e97a6eb1328cf1f9c6b4"/><file name="updateChargeAmount.php" hash="ae4cf8072078cc8e527b786ea03a8337"/><file name="updateGoodsQty.php" hash="6e10c98895fe94f842ee45673ec790b3"/><file name="updateOrderNo.php" hash="e9d7a59d10b4be660b2cfd700ecc992d"/></dir><file name="klarnaaddr.php" hash="b090d4b0a819fdb7cc58815a8643de18"/><file name="klarnacalc.php" hash="3ab728bf3889240b881f282122fd25fd"/><file name="klarnaconfig.php" hash="a3a4011dccda60fcf3567f56254699ff"/><file name="klarnapclass.php" hash="26a8fd1df0806788f6719cb894787f76"/><dir name="pclasses"><file name="jsonstorage.class.php" hash="e59e526d9dcc17d1ca92ded188750672"/><file name="mysqlstorage.class.php" hash="896a5cd4edf461ef517e0bb2e328707b"/><file name="sqlstorage.class.php" hash="bb7ba4359e7e69424c9f0ecdafc0c9ae"/><file name="storage.intf.php" hash="26db57484b6db3d717c0150ffaa87b19"/><file name="xmlstorage.class.php" hash="4f13939bf8d73f2724f858dd17f219de"/></dir><dir name="transport"><dir name="xmlrpc-3.0.0.beta"><dir name="lib"><file name="xmlrpc.inc" hash="5a74ea2a831648febc9b2c8f809b252c"/><file name="xmlrpc_wrappers.inc" hash="5aa00141ead09fc5498d9a3c9fcab888"/><file name="xmlrpcs.inc" hash="158b97bda79333e9b40793d876b6e98f"/></dir></dir></dir></dir></target><target name="mageskin"><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="vaimo"><dir name="klarna"><dir name="css"><file name="admin.css" hash="ef4915be839e2039fb037f29c1506d30"/></dir></dir></dir></dir></dir></dir><dir name="frontend"><dir name="base"><dir name="default"><dir name="css"><dir name="vaimo"><dir name="klarna"><file name="checkout.css" hash="e133a0576c4a69adc210e9103725790b"/><file name="checkout_osc.css" hash="7f621724b0cb096f11d6cc42870bd544"/><file name="global.css" hash="22b6a446e6e874e6a95608f7046eac2a"/><file name="product.css" hash="d41d8cd98f00b204e9800998ecf8427e"/></dir></dir></dir><dir name="images"><dir name="vaimo"><dir name="klarna"><file name="balk_afm3.jpg" hash="8855567960bff35b1e3ba486670b5878"/></dir></dir></dir></dir></dir></dir></target></contents>
16
  <compatible/>
17
  <dependencies><required><php><min>5.2.0</min><max>6.0.0</max></php><package><name></name><channel>connect.magentocommerce.com/core</channel><min></min><max></max></package></required></dependencies>
18
  </package>
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>klarnapayments</name>
4
+ <version>5.2.0</version>
5
  <stability>stable</stability>
6
  <license>Open Software License (OSL)</license>
7
  <channel>community</channel>
8
  <extends/>
9
+ <summary>Klarna's module for Klarna Checkout, invoice and part payment.</summary>
10
+ <description>Klarna payment module for Klarna Checkout, invoice and part payments. This module works for all countries were Klarna's product offering is applicable. To use this module requires that you have a contract with Klarna.</description>
11
  <notes>This version is not compatible with any Klarna module version of 4.x or earlier.</notes>
12
  <authors><author><name>Klarna</name><user>Klarna</user><email>magento@klarna.com</email></author><author><name>Vaimo</name><user>VAIMO</user><email>info@vaimo.com</email></author></authors>
13
+ <date>2014-11-05</date>
14
+ <time>13:34:42</time>
15
+ <contents><target name="magedesign"><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="layout"><file name="vaimo_klarna.xml" hash="19a196d33bcc2e1eaf4413dcefeb5f04"/></dir><dir name="template"><dir name="vaimo"><dir name="klarna"><dir name="creditmemo"><dir name="totals"><file name="adjustments.phtml" hash="b0299ac0b1ca75b4d143413cc8eb8217"/></dir></dir><dir name="info"><file name="account.phtml" hash="4c51cb3b4aeb54bb009e384d300ece98"/><file name="checkout.phtml" hash="6c35211c76987e619b51f6b6f06b0707"/><dir name="children"><file name="invoicefee.phtml" hash="2b721be479706716f6468c8395455fa5"/><file name="invoices.phtml" hash="ac4e3bd4aea83e9ea3479fc04ed0d5a4"/><file name="paymentplan.phtml" hash="885c020c05afd4516a42a33a6986f32f"/><file name="reference.phtml" hash="a789d5c8d4253c6ba4d894e2f0465f9c"/><file name="reservation.phtml" hash="d96f36640577e8e053050c24bfb4ec43"/></dir><file name="invoice.phtml" hash="498a1d706ac1da4fc71982f1232de492"/><file name="special.phtml" hash="4c51cb3b4aeb54bb009e384d300ece98"/></dir><dir name="pclass"><file name="list.phtml" hash="5cef6b0093bb5da18dbf1f9fd7316c66"/><file name="update.phtml" hash="ed53d5eb248f8181cd601e7b10cb170f"/></dir></dir></dir></dir></dir></dir></dir><dir name="frontend"><dir name="base"><dir name="default"><dir name="layout"><file name="vaimo_klarna.xml" hash="3ddb8e805772c96d1833961df13a78eb"/></dir><dir name="template"><dir name="vaimo"><dir name="klarna"><dir name="catalog"><dir name="product"><file name="pricewidget.phtml" hash="f5838b8bb129634487a398ca2557f48b"/></dir></dir><dir name="checkout"><file name="fee.phtml" hash="3a58d7e7278bf9fcae1cdb9d836d4ff3"/><file name="header.phtml" hash="51a7f95f2fcb5f7b02e19b13690631a8"/><file name="top.phtml" hash="9cc1ce32346bd6ed7c16139f3f960a95"/></dir><dir name="form"><file name="account.phtml" hash="25386497892129effff92a64f326ff42"/><dir name="address"><file name="search.phtml" hash="42c4fa161e9f6870bba41971c865cf34"/></dir><file name="checkout.phtml" hash="fe86056c73f86d53a73ebda5c5f3547c"/><dir name="children"><file name="addressresult.phtml" hash="7ed16bca431a8146139ce51fd7001d11"/><file name="consent.phtml" hash="a4f446258fa20a453d3566cffc20085d"/><file name="dateofbirth.phtml" hash="e1dbe367ce43029d671dae6f7d3ca956"/><file name="gender.phtml" hash="c8428e9b76db957a866cfc109d7a0c09"/><file name="notifications.phtml" hash="485d9f8e90ca6ff3c8152d2c3a0ee138"/><file name="paymentplan_information.phtml" hash="8f28c418c08df3e664744ef28bc283c3"/><file name="pclass.phtml" hash="848a7e485badbdf11d10628c93906b21"/><file name="personalnumber.phtml" hash="a8d723a0ff1b71f07ccdd1aed1dba5fb"/><file name="phonenumber.phtml" hash="6348b12795e073d8881ab0b74d7df175"/></dir><file name="invoice.phtml" hash="43a3a4aaae78b3a835c8de7d9edff8b4"/><dir name="paymentplan"><file name="information.phtml" hash="d19f6766d1bebdacb367aee65edb06fd"/></dir><file name="special.phtml" hash="68561f42f556c496fb46c2c12f35b410"/></dir><dir name="info"><file name="account.phtml" hash="a848c9544a5e400bc27e26d050eafa3c"/><file name="checkout.phtml" hash="1364aae5f0b71233e215e8a1c40ea7f7"/><dir name="children"><file name="invoicefee.phtml" hash="c6b4ccff75e220c5641a8fadd6753131"/><file name="invoices.phtml" hash="cbdd0256b8e1d742257bcba9b1eef67a"/><file name="paymentplan.phtml" hash="3a73d918dc733c0888f18e442f9eb64c"/><file name="reservation.phtml" hash="9880ef8208f672d531cc10eef8467856"/></dir><file name="invoice.phtml" hash="cd3514e43dd441b4530b95e408784d84"/><file name="special.phtml" hash="c472684055c8839b8e365b80a5e1ee0c"/></dir><dir name="klarnacheckout"><file name="autofill.phtml" hash="6bdd6c22fd1771106f52876e66d7f4de"/><dir name="cart"><dir name="item"><file name="default.phtml" hash="3d7c79cb13703b9cffe190fe6947306f"/></dir><file name="totals.phtml" hash="73b2c41c796fbf542c1f52ba99d131c4"/></dir><file name="cart.phtml" hash="c1c367cda021a53fb57029642803a03f"/><dir name="customer"><file name="balance.phtml" hash="af890728b26b0808c299ab199bc5f4c0"/></dir><dir name="discount"><file name="coupon.phtml" hash="35ccd00c06e448b900577f40ba360af0"/><file name="giftcardaccount.phtml" hash="8895e32abbc97d84fce366221637a1d9"/></dir><file name="discount.phtml" hash="04c4a517d0fbeae72aec9d2dd0fac84e"/><file name="header.phtml" hash="a0125224ad2b46b8348d81c308e92ee7"/><file name="klarnacheckout.phtml" hash="e5ad0ae7db7cb7279220de4e2b1453c7"/><file name="msg.phtml" hash="292efb0ca5a1b70204fb383ab4d4173e"/><file name="newsletter.phtml" hash="8c26bd84bc690c1aa0172c063dae99f8"/><file name="othermethod.phtml" hash="7fe13acf83fe1f0b5624414bbef4a566"/><file name="reward.phtml" hash="1aecb7c2b7e154d47e2c4add8b79e1ee"/><dir name="shipping_method"><file name="available.phtml" hash="a441651173fda6ec78742e4fcb859b97"/></dir><file name="shipping_method.phtml" hash="56f31b29cbf65527eeea8d919a085a78"/><file name="success.phtml" hash="b1f276ce825e09d472aef29d631ddf7b"/></dir><dir name="page"><dir name="html"><file name="logo.phtml" hash="fb2d29e255453128bbdf37218289caf1"/></dir></dir></dir></dir></dir></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Vaimo_Klarna.xml" hash="fece558fa050794401aca834b1b12fd4"/></dir></target><target name="magelocale"><dir name="da_DK"><file name="Vaimo_Klarna.csv" hash="69faf96ad13d2d4a5c9dcd30fb60bd6c"/></dir><dir name="de_AT"><file name="Vaimo_Klarna.csv" hash="86ec4e92f26cc28e2bbe3efaf7896e1d"/></dir><dir name="de_DE"><file name="Vaimo_Klarna.csv" hash="1e167c02c49a79fb0834a49ae2b6deb6"/></dir><dir name="fi_FI"><file name="Vaimo_Klarna.csv" hash="b63b5a2176896b24494e7e84434597b5"/></dir><dir name="nb_NO"><file name="Vaimo_Klarna.csv" hash="f1722434ccb02247c8326574b4ce61e8"/></dir><dir name="nl_NL"><file name="Vaimo_Klarna.csv" hash="ae931192108a1bafadce32363e8c2792"/></dir><dir name="nn_NO"><file name="Vaimo_Klarna.csv" hash="fc847790589c737f8c8362e57754184e"/></dir><dir name="sv_SE"><file name="Vaimo_Klarna.csv" hash="da59083e4dd7f1ca7b8499ff1635d95c"/></dir></target><target name="mage"><dir name="js"><dir name="vaimo"><dir name="klarna"><file name="klarna.js" hash="0b4cd9d9238833d4d8783e3265c1b87a"/><file name="klarnacheckout.js" hash="ff6e3b5db706ffa4c90c764696983969"/></dir></dir></dir></target><target name="magelib"><dir name="Klarna"><file name="CHANGELOG" hash="7c2deef157ef77304e1d0efc970d6c48"/><file name="Changelog-Vaimo.txt" hash="e4dd5098593f2c52ae0bffa0fda2cd09"/><dir name="Checkout"><file name="BasicConnector.php" hash="8a9d008cda8e0805537b70d1e0e3bcd5"/><file name="ConnectionErrorException.php" hash="352ae3f5bbb18c04f0a9d3ca1be30faf"/><file name="Connector.php" hash="199d9134e8c5188e5b8f958ac1f17029"/><file name="ConnectorException.php" hash="fe4017579c8757798e018fb0755496c0"/><file name="ConnectorInterface.php" hash="0ebfd5610fec6ddce7b7fd0f45f3d1d6"/><file name="Digest.php" hash="d7c2ea4ff1f22c8919685aad7e4e9c8b"/><file name="Exception.php" hash="31a95e8212f01d149265f75e20b31bcb"/><dir name="HTTP"><file name="CURLFactory.php" hash="591493c487797a80fd76f4f80ca598d0"/><file name="CURLHandle.php" hash="2d58ba553ffddafdcc9c80bea0c2c5ee"/><file name="CURLHandleInterface.php" hash="df5e3ddf82deb09164c75249c7235756"/><file name="CURLHeaders.php" hash="2a900efb8591defaf9230368403c975f"/><file name="CURLTransport.php" hash="c35a9910a04007372c2d6673f4657b89"/><file name="Request.php" hash="180f04ffd522b713b4261087a7e60c68"/><file name="Response.php" hash="86993580c2a11b14bab4af6328caa6de"/><file name="Transport.php" hash="4aa96d5086e105d79b0f97593fbe5d9b"/><file name="TransportInterface.php" hash="3d6aab36479741136c9dee1bbcf3914e"/></dir><file name="Order.php" hash="568242a47b838ae9abf8438a4bc7301e"/><file name="ResourceInterface.php" hash="55fc925edc0f69a89f2d79e348152a2c"/><file name="UserAgent.php" hash="ee6a35f67e56391f5bdfa387616e5618"/></dir><file name="Checkout.php" hash="6e16bb237ecfc54f086a0d533a8e69e3"/><file name="Country.php" hash="40360c3964fc6193e7fb922845eb419b"/><file name="Currency.php" hash="a709407428d86521cc0775cbeb281523"/><file name="Encoding.php" hash="f8f8e744303ff7ce7f4b226331e7bdcf"/><file name="Exceptions.php" hash="933b2811e910da817743766cdde8ffeb"/><file name="Flags.php" hash="b407a1373adf5f172bef3e3d01e81cdb"/><file name="Klarna.php" hash="36e5956a0eeb94c7ba1871d0bd8b9973"/><file name="Language.php" hash="8e40aed0dece8f0a3fbe07e37451af16"/><dir name="checkoutkpm"><file name="checkouthtml.intf.php" hash="81e0740254585f2af67895df28093d35"/><file name="threatmetrix.class.php" hash="6ce1bfded90b6b3bb329176ff4c7acac"/></dir><dir name="examples"><file name="activate.php" hash="b49a0bd5c5a57577b9765d657dad7b78"/><file name="activateInvoice.php" hash="31061b3cf79a6fd32f580f3aa6b603ad"/><file name="activatePart.php" hash="72af1ee8d312df08e24cdc7b01cc72ed"/><file name="activateReservation.php" hash="6380e346db2466a655df17cbe4078b3a"/><file name="addTransaction.php" hash="015cdd7663d7bbe0716f8ed8f700e13e"/><file name="calc_monthly_cost.php" hash="9a45009fe051f76bd2d23db854f67cad"/><file name="cancelReservation.php" hash="219504c253caa372f479af8f6bf452eb"/><file name="changeReservation.php" hash="cdf4f971d74570e2ba9191792f69bf79"/><file name="checkOrderStatus.php" hash="b9d12df62f9619cb791bc4db9b2e19c4"/><file name="creditInvoice.php" hash="f174d28d812f5139c4a0397a27f419d9"/><file name="creditPart.php" hash="4c1a6397eb2bc7ee0bac5ed1a76aa7d8"/><file name="deleteInvoice.php" hash="b59be611d1ba7439d0c9ec43f38e8f95"/><file name="emailInvoice.php" hash="31f644dc6b1a97181d3ba474f2d77517"/><file name="fetchPClasses.php" hash="18a60ab1bde9ace0765c58f3343c4165"/><file name="getAddresses.php" hash="bf80e3108d51dcf4c581bff291e4a2fc"/><file name="getPClasses.php" hash="18b7bc054ceb36c8f004d21804fea832"/><file name="invoiceAddress.php" hash="a7a9c89f6ee017d72f9d9d5a959c7416"/><file name="invoiceAmount.php" hash="d404dba99dd5efd2954bec58eab720ca"/><file name="invoicePartAmount.php" hash="37e3726190f1fb403fbba19de2088dd5"/><file name="reserveAmount.php" hash="4c93a455264dafc93a2cd9ce41c8aaaa"/><file name="reserveOCR.php" hash="a67258e40b080027c5e60490a15d3347"/><file name="returnAmount.php" hash="ae01bab7225bdd6529593d499247e8f6"/><file name="sendInvoice.php" hash="46584ac7995d779ff4fa2a4a4b109df9"/><file name="splitReservation.php" hash="35c495a8bfc1e29b109a0de3800d4d44"/><file name="update.php" hash="1275db160660e97a6eb1328cf1f9c6b4"/><file name="updateChargeAmount.php" hash="ae4cf8072078cc8e527b786ea03a8337"/><file name="updateGoodsQty.php" hash="6e10c98895fe94f842ee45673ec790b3"/><file name="updateOrderNo.php" hash="e9d7a59d10b4be660b2cfd700ecc992d"/></dir><file name="klarnaaddr.php" hash="b090d4b0a819fdb7cc58815a8643de18"/><file name="klarnacalc.php" hash="3ab728bf3889240b881f282122fd25fd"/><file name="klarnaconfig.php" hash="a3a4011dccda60fcf3567f56254699ff"/><file name="klarnapclass.php" hash="26a8fd1df0806788f6719cb894787f76"/><dir name="pclasses"><file name="jsonstorage.class.php" hash="e59e526d9dcc17d1ca92ded188750672"/><file name="mysqlstorage.class.php" hash="896a5cd4edf461ef517e0bb2e328707b"/><file name="sqlstorage.class.php" hash="bb7ba4359e7e69424c9f0ecdafc0c9ae"/><file name="storage.intf.php" hash="26db57484b6db3d717c0150ffaa87b19"/><file name="xmlstorage.class.php" hash="4f13939bf8d73f2724f858dd17f219de"/></dir><dir name="transport"><dir name="xmlrpc-3.0.0.beta"><dir name="lib"><file name="xmlrpc.inc" hash="5a74ea2a831648febc9b2c8f809b252c"/><file name="xmlrpc_wrappers.inc" hash="5aa00141ead09fc5498d9a3c9fcab888"/><file name="xmlrpcs.inc" hash="158b97bda79333e9b40793d876b6e98f"/></dir></dir></dir></dir></target><target name="mageskin"><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="vaimo"><dir name="klarna"><dir name="css"><file name="admin.css" hash="ef4915be839e2039fb037f29c1506d30"/></dir></dir></dir></dir></dir></dir><dir name="frontend"><dir name="base"><dir name="default"><dir name="css"><dir name="vaimo"><dir name="klarna"><file name="checkout.css" hash="4cbeefa920f8d31181e030aeff997bad"/><file name="checkout_osc.css" hash="61f85446731eb80de0a592897e87cd21"/><file name="global.css" hash="22b6a446e6e874e6a95608f7046eac2a"/><file name="klarnacheckout.css" hash="c4e9dcdf5be333fb5a959ff400484ac1"/><file name="product.css" hash="d41d8cd98f00b204e9800998ecf8427e"/></dir></dir></dir><dir name="images"><dir name="vaimo"><dir name="klarna"><file name="balk_afm3.jpg" hash="8855567960bff35b1e3ba486670b5878"/><file name="icons.png" hash="7f0808d4cf63c3d43637d40a703f30fe"/></dir></dir></dir></dir></dir></dir></target><target name="magecommunity"><dir name="Vaimo"><dir name="Klarna"><dir name="Block"><dir name="Adminhtml"><dir name="Pclass"><file name="List.php" hash="7c68e3ec74e5cea1b62bb0218d297089"/><file name="Update.php" hash="fd444645b9f78fc4ea65c91ee3fc0044"/></dir><dir name="Sales"><dir name="Creditmemo"><dir name="Create"><file name="Adjustments.php" hash="12074f6aabbe90f14b8d30b7f65da9dc"/></dir><file name="Totals.php" hash="198afd117e90e17999f24c419a92b24b"/></dir><dir name="Invoice"><file name="Totals.php" hash="bc28f21c484fe2b4ca6d7a06da726fc3"/></dir><dir name="Order"><file name="Totals.php" hash="c80ca5283b0341964c36e70a850faaf6"/></dir></dir></dir><dir name="Catalog"><dir name="Product"><file name="Pricewidget.php" hash="67210e5d92b4dc33c729759f47a2cf24"/></dir></dir><dir name="Checkout"><file name="Fee.php" hash="1ffae1896b12e6d87fbbd2d3843fef75"/><file name="Top.php" hash="a8f9084322c1f924ef6fb4802908019d"/></dir><dir name="Form"><file name="Abstract.php" hash="8fc62f56116522ba14b6759985231244"/><file name="Account.php" hash="f6bf008c1af0b93ead5b5a2577b59ea5"/><dir name="Address"><file name="Search.php" hash="439e9f9a5d9480a4356043bb73f9c9c7"/></dir><file name="Checkout.php" hash="a7e6876317a29184f07040b646b84ec7"/><file name="Invoice.php" hash="105a41b84e52b45f26f3c5de2d4bdd4a"/><dir name="Paymentplan"><file name="Information.php" hash="7c66acd887a1e3a165e3cd967d0f3331"/></dir><file name="Special.php" hash="8db5a5f33510cd32d724c6ecd6368aa2"/></dir><dir name="Info"><file name="Abstract.php" hash="586393b00cd2c57ed6d53b8b50a8a535"/><file name="Account.php" hash="d302c2fc556e05858464fadd51cd4854"/><file name="Checkout.php" hash="df92291673e6bfe63ac968ad7297cca3"/><file name="Invoice.php" hash="f98adb5521f6c546c462f2e5bde31295"/><file name="Special.php" hash="e07662f39f0ff65505bfd627045c7766"/></dir><dir name="Invoice"><file name="Totals.php" hash="2437d7c7d7499d3ee2fcb7e0426ad64d"/></dir><dir name="Klarnacheckout"><file name="Autofill.php" hash="9bfabd568384b14c70175218f62fab9a"/><dir name="Customer"><file name="Balance.php" hash="e35153845d979d91ff79d0558e7b6c0b"/></dir><file name="Discount.php" hash="d0470865220ff0cd09e5f2daf33f372f"/><file name="Ga.php" hash="c74dd6174899a65d61bd0abeefb6ae6b"/><file name="Klarnacheckout.php" hash="5780da78ea75efd34ca0db1d4f0705fa"/><file name="Newsletter.php" hash="ce97e11c097b0cd9696919936fa59dc6"/><file name="Othermethod.php" hash="a31bc678ce541f8eea1d043801c13974"/><file name="Reward.php" hash="98d72b6cf65070dcb4cc87a303cd8b54"/><file name="Success.php" hash="8b04804a106bae8dabb7f0d93fa33e2d"/></dir><dir name="Order"><file name="Totals.php" hash="2e56335ff1b4a1d6752e7336b107bd13"/></dir><dir name="Page"><dir name="Html"><file name="Logo.php" hash="fda8fc32997328feb9c7ebf15c8a51fa"/></dir></dir></dir><dir name="controllers"><file name="AddressController.php" hash="e3272d6463e7ea0082c249924c31e34b"/><dir name="Adminhtml"><dir name="Klarna"><file name="PclassController.php" hash="80dc9c19549ce161e50484e57c600b0c"/></dir></dir><dir name="Checkout"><file name="KlarnaController.php" hash="bff463d2262cbe7c28bd685357b9af59"/></dir><file name="PaymentplanController.php" hash="fea9d33a5dbd5d4858ef174569dae636"/></dir><dir name="etc"><file name="config.xml" hash="5c5894fe9a4c5d39060be598566affee"/><file name="system.xml" hash="8232ea11eecb1c84817883f682318f31"/></dir><dir name="Helper"><file name="Data.php" hash="4d8ac90de2d8374193e0c7b6265742bf"/></dir><dir name="Model"><dir name="Api"><file name="Abstract.php" hash="b3057bd602fda03cce6fc420c495673b"/><file name="Kco.php" hash="e17c83b2e915131bc9a79c42dda6a67e"/><file name="Rest.php" hash="553ef171cb17e5399e97a7dd30c3757a"/><file name="Xmlrpc.php" hash="035d10f930efedad724ef17180871824"/></dir><file name="Api.php" hash="5c3f199a2fb6a8d733bd9c8d8996791e"/><dir name="Creditmemo"><file name="Tax.php" hash="c3d5162de38f5ef2075bca483085e5d0"/><file name="Total.php" hash="0f9b9298c35f2e69b141d1197bb593a5"/></dir><dir name="Invoice"><dir name="Pdf"><file name="Total.php" hash="06412f97df9ac6a1854978b61f68fb36"/></dir><file name="Tax.php" hash="ff4c665fade58265440f21f00e577932"/><file name="Total.php" hash="3e89c7d9e9be6cc481b140a0bcc543b6"/></dir><dir name="Klarna"><file name="Abstract.php" hash="0c2a3aaa1de1e938b85cd8cd1a419768"/></dir><file name="Klarna.php" hash="3dc634a89bfeb8c14c2494b6297f5f60"/><dir name="Klarnacheckout"><file name="Abstract.php" hash="ae4c167242096aec289ddcc339469853"/></dir><file name="Klarnacheckout.php" hash="f5a5a1189433e29e1031110067699a03"/><file name="Observer.php" hash="b76c1d29a35eb98a083840d53ae461ff"/><dir name="Payment"><file name="Abstract.php" hash="036a09c1b4c9ad57c2d348940bd14403"/><file name="Account.php" hash="184c3b627b2355490058463c5c8452df"/><file name="Checkout.php" hash="83e6c060effd7c99aca28754926fa70d"/><file name="Invoice.php" hash="8db24d7cddfd3166257ab1de3159efbd"/><file name="Special.php" hash="bd11a7c3aad411dbff20b62d7b522f4d"/></dir><dir name="Quote"><file name="Tax.php" hash="b53f4a52d0f09afc7daeb094d6e30881"/><file name="Total.php" hash="a1442ecba3f2c49a42ff43e006057878"/></dir><dir name="Resource"><dir name="Mysql4"><file name="Setup.php" hash="0a40d43403823a6053d74bd2d2f688e7"/></dir></dir><dir name="Source"><file name="Abstract.php" hash="8d0d746d1cd2e5bc7d11350908a01585"/><file name="Allspecificcountries.php" hash="1a98316e25baeaba307b3be62364e1ca"/><file name="Apiversion.php" hash="536c62f5022aec99d71f68e1118c0d99"/><file name="Capture.php" hash="c2d31ebb607202555e9905e439dbe86d"/><file name="Country.php" hash="2444140a6155e42d2e4909ae150037b7"/><file name="Customergroup.php" hash="01c6e41abac6e7105e4d290f53f68733"/><file name="Language.php" hash="efe69e0132b87242d2fbf08b2f8febe1"/><file name="Newsletter.php" hash="f1532e5ff4c7e04384e9410cbb0969fa"/><file name="Servermode.php" hash="7acd8c7bb39f640dccef12df69ed7c57"/><file name="Taxclass.php" hash="de1ebcf0027eaff23f676da569034ed7"/><file name="Yesnodefault.php" hash="a296d6a62f1f1858ac093c0d7974cf6a"/></dir><dir name="Tax"><file name="Config.php" hash="7767f6d07f63df09228ab6c496ed0c05"/></dir><dir name="Transport"><file name="Abstract.php" hash="2e404635744d99c769d465592658e0b2"/></dir></dir><dir name="sql"><dir name="klarna_setup"><file name="mysql4-install-0.1.0.php" hash="d36b51433fd28241386594f39def3080"/><file name="mysql4-upgrade-5.1.6-5.1.7.php" hash="014a7b827a8958a94c57a0229127a427"/></dir></dir></dir></dir></target></contents>
16
  <compatible/>
17
  <dependencies><required><php><min>5.2.0</min><max>6.0.0</max></php><package><name></name><channel>connect.magentocommerce.com/core</channel><min></min><max></max></package></required></dependencies>
18
  </package>
skin/frontend/base/default/css/vaimo/klarna/checkout.css CHANGED
@@ -215,3 +215,43 @@ label[for=vaimo_klarna_special_consent] {
215
  line-height: 18.6px;
216
  display: inline-block;
217
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
215
  line-height: 18.6px;
216
  display: inline-block;
217
  }
218
+
219
+ #p_method_vaimo_klarna_checkout { display: none; }
220
+ #container_payment_method_vaimo_klarna_checkout { display: block !important; }
221
+
222
+ a.button::-moz-focus-inner {
223
+ padding:0;
224
+ border:0;
225
+ }
226
+ a.button {
227
+ -webkit-border-fit:lines;
228
+ }
229
+ a.button {
230
+ overflow:visible;
231
+ width:auto;
232
+ border:0;
233
+ padding:0;
234
+ margin:0;
235
+ background:transparent;
236
+ cursor:pointer;
237
+ text-decoration: none;
238
+ }
239
+ a.button span {
240
+ display:block;
241
+ height:19px;
242
+ border:1px solid #de5400;
243
+ background:#f18200;
244
+ padding:0 8px;
245
+ font:bold 12px/19px Arial, Helvetica, sans-serif;
246
+ text-align:center;
247
+ white-space:nowrap;
248
+ color:#fff;
249
+ }
250
+ a.button span span {
251
+ border:0;
252
+ padding:0;
253
+ }
254
+ a.disabled span {
255
+ border-color:#bbb !important;
256
+ background:#bbb !important;
257
+ }
skin/frontend/base/default/css/vaimo/klarna/checkout_osc.css CHANGED
@@ -214,3 +214,43 @@ label[for=vaimo_klarna_special_consent] {
214
  line-height: 18.6px;
215
  display: inline-block;
216
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
214
  line-height: 18.6px;
215
  display: inline-block;
216
  }
217
+
218
+ #p_method_vaimo_klarna_checkout { display: none; }
219
+ #container_payment_method_vaimo_klarna_checkout { display: block !important; }
220
+
221
+ a.button::-moz-focus-inner {
222
+ padding:0;
223
+ border:0;
224
+ }
225
+ a.button {
226
+ -webkit-border-fit:lines;
227
+ }
228
+ a.button {
229
+ overflow:visible;
230
+ width:auto;
231
+ border:0;
232
+ padding:0;
233
+ margin:0;
234
+ background:transparent;
235
+ cursor:pointer;
236
+ text-decoration: none;
237
+ }
238
+ a.button span {
239
+ display:block;
240
+ height:19px;
241
+ border:1px solid #de5400;
242
+ background:#f18200;
243
+ padding:0 8px;
244
+ font:bold 12px/19px Arial, Helvetica, sans-serif;
245
+ text-align:center;
246
+ white-space:nowrap;
247
+ color:#fff;
248
+ }
249
+ a.button span span {
250
+ border:0;
251
+ padding:0;
252
+ }
253
+ a.disabled span {
254
+ border-color:#bbb !important;
255
+ background:#bbb !important;
256
+ }
skin/frontend/base/default/css/vaimo/klarna/klarnacheckout.css ADDED
@@ -0,0 +1,445 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /* Vaimo_Klarna_Klarnacheckout */
2
+
3
+ /* ===========================================================
4
+ * Misc
5
+ * =========================================================== */
6
+
7
+ #klarna_wrapper {
8
+ position: relative;
9
+ overflow: hidden;
10
+ margin: 10px 0 10px 0;
11
+ font-size: 0;
12
+ }
13
+
14
+ #klarna_loader {
15
+ display: none;
16
+ background-color: #ffffff;
17
+ background-color: rgba(255, 255, 255, .7);
18
+ position: absolute;
19
+ z-index: 10;
20
+ top: 0;
21
+ left: 0;
22
+ width: 100%;
23
+ height: 100%;
24
+ }
25
+
26
+ #klarna_loader img {
27
+ position: absolute;
28
+ top: 50%;
29
+ left: 50%;
30
+ z-index: 20;
31
+ margin: -8px 0 0 -8px;
32
+ }
33
+
34
+ #klarna_left,
35
+ #klarna_right {
36
+ display: inline-block;
37
+ vertical-align: top;
38
+ }
39
+
40
+ #klarna_left {
41
+ margin-right: 20px;
42
+ /* width: 618px;*/
43
+ }
44
+
45
+ #klarna_msg {
46
+ display: none;
47
+ height: 40px;
48
+ line-height: 40px;
49
+ width: 100%;
50
+ background: #dff0d8;
51
+ border-bottom: 1px solid #cad9c3;
52
+ box-shadow: 0 0 5px rgba(0, 0, 0, 0.2);
53
+ color: #468847;
54
+ font-size: 12px;
55
+ font-weight: bold;
56
+ text-align: center;
57
+ text-shadow: 0 1px 0 rgba(255, 255, 255, 0.5);
58
+ text-transform: uppercase;
59
+ }
60
+
61
+ #klarna_msg.error {
62
+ color: #b94a48;
63
+ background: #f2dede;
64
+ border-bottom: 1px solid #d9c7c7;
65
+ }
66
+
67
+ #klarna_reload {
68
+ display: none;
69
+ }
70
+
71
+ #klarna_checkout {
72
+ min-height: 944px;
73
+ }
74
+
75
+ #klarna_cart,
76
+ #klarna_totals,
77
+ #klarna_shipping,
78
+ #klarna_discount {
79
+ font-size: 11px;
80
+ }
81
+
82
+ /* ===========================================================
83
+ * Cart table
84
+ * =========================================================== */
85
+
86
+ #klarna_cart {
87
+ margin-bottom: 30px;
88
+ }
89
+
90
+ #klarna_cart table {
91
+ width: 620px;
92
+ margin: 0;
93
+ color: #333333;
94
+ text-transform: uppercase;
95
+ border-spacing: 0;
96
+ }
97
+
98
+ #klarna_cart .item-msg {
99
+ font-size: 10px;
100
+ }
101
+
102
+ #klarna_cart th {
103
+ border: none;
104
+ border-bottom: 1px solid #ccc;
105
+ font-weight: normal;
106
+ white-space: nowrap;
107
+ padding: 0 10px 5px 10px;
108
+ }
109
+
110
+ #klarna_cart td {
111
+ border: none;
112
+ border-bottom: 1px solid #cccccc;
113
+ padding: 10px;
114
+ vertical-align: middle;
115
+ }
116
+
117
+ #klarna_cart .even {
118
+ background: #f5f5f5;
119
+ }
120
+
121
+ #klarna_cart tfoot td {
122
+ padding: 15px 0 0 0;
123
+ border-bottom: 0;
124
+ }
125
+
126
+ #klarna_cart .product_name {
127
+ font-weight: bold;
128
+ }
129
+
130
+ #klarna_cart .price {
131
+ font-size: 11px;
132
+ }
133
+
134
+ #klarna_cart .product-image img {
135
+ border: 1px solid #cbcbcb;
136
+ }
137
+
138
+ #klarna_cart .qty {
139
+ text-align: center;
140
+ width: 102px;
141
+ }
142
+
143
+ #klarna_cart .qty input {
144
+ display: inline-block;
145
+ zoom: 1;
146
+ *display: inline;
147
+ width: 24px;
148
+ height: 28px;
149
+ padding: 0 6px;
150
+ background: #ffffff;
151
+ border: 1px solid #cccccc;
152
+ border-radius: 0;
153
+ box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .12);
154
+ text-align: center;
155
+ }
156
+
157
+ #klarna_cart .subtract-item,
158
+ #klarna_cart .add-item,
159
+ #klarna_cart .remove-item {
160
+ outline: 0;
161
+ display: inline-block;
162
+ zoom: 1;
163
+ *display: inline;
164
+ text-indent: -9999px;
165
+ width: 16px;
166
+ height: 16px;
167
+ margin: 8px 5px 0 0;
168
+ background: transparent url(../../../images/vaimo/klarna/icons.png) -32px 0 no-repeat;
169
+ }
170
+
171
+ #klarna_cart .subtract-item:hover {
172
+ background-position: -32px 100%;
173
+ }
174
+
175
+ #klarna_cart .add-item {
176
+ margin: 8px 0 0 5px;
177
+ background-position: -16px 0;
178
+ }
179
+
180
+ #klarna_cart .add-item:hover {
181
+ background-position: -16px 100%;
182
+ }
183
+
184
+ #klarna_cart .remove-item {
185
+ margin: 0;
186
+ background-position: 0 0;
187
+ }
188
+
189
+ #klarna_cart .remove-item:hover {
190
+ background-position: 0 100%;
191
+ }
192
+
193
+ .cart-table .link-wishlist {
194
+ margin: 25px 0 0 0;
195
+ display: block;
196
+ }
197
+
198
+ #klarna_cart dl {
199
+ margin: 0;
200
+ }
201
+
202
+ #klarna_cart .item-options dl,
203
+ #klarna_cart .item-options dt,
204
+ #klarna_cart .item-options dd {
205
+ font-weight: normal;
206
+ font-style: normal;
207
+ padding: 0;
208
+ margin: 0;
209
+ }
210
+
211
+ #klarna_cart .item-options dd {
212
+ margin-left: 5px;
213
+ }
214
+
215
+ /* ===========================================================
216
+ * Totals
217
+ * =========================================================== */
218
+
219
+ #klarna_totals {
220
+ width: 258px;
221
+ border: 1px solid #cecece;
222
+ margin: 22px 0 20px 0;
223
+ padding: 0;
224
+ }
225
+
226
+ #klarna_totals table {
227
+ width: 100%;
228
+ border-spacing: 0;
229
+ text-transform: uppercase;
230
+ }
231
+
232
+ #klarna_totals td {
233
+ padding: 10px 15px;
234
+ border-bottom: 1px solid #f5f5f5;
235
+ }
236
+
237
+ #klarna_totals .price {
238
+ font-size: 11px;
239
+ }
240
+
241
+ #klarna_totals .a-left {
242
+ text-align: right;
243
+ }
244
+
245
+ #klarna_totals .a-right {
246
+ text-align: left;
247
+ }
248
+
249
+ #klarna_totals .checkout-types {
250
+ display: none;
251
+ }
252
+
253
+ #klarna_totals .grand-total-incl {
254
+ border: none;
255
+ font-size: 12px;
256
+ }
257
+
258
+ #klarna_totals .grand-total-incl td {
259
+ border-bottom: none;
260
+ }
261
+
262
+ #klarna_totals .grand-total-incl .price {
263
+ font-size: 12px;
264
+ }
265
+
266
+ /* ===========================================================
267
+ * Shipping options
268
+ * =========================================================== */
269
+
270
+ #klarna_shipping {
271
+ width: 640px;
272
+ }
273
+
274
+ #klarna_shipping ul {
275
+ background: #f5f5f5;
276
+ padding: 10px;
277
+ margin: 0;
278
+ }
279
+
280
+ #klarna_shipping li {
281
+ display: inline-block;
282
+ zoom: 1;
283
+ *display: inline;
284
+ margin: 5px 20px 5px 0;
285
+ padding: 0;
286
+ }
287
+
288
+ #klarna_shipping input {
289
+ margin-right: 5px;
290
+ }
291
+
292
+ #klarna_shipping label {
293
+ margin: 0;
294
+ font-weight: normal;
295
+ }
296
+
297
+ #klarna_shipping .price {
298
+ font-size: inherit;
299
+ font-weight: bold;
300
+ }
301
+
302
+ /* ===========================================================
303
+ * Discount
304
+ * =========================================================== */
305
+
306
+ #klarna_shipping h3,
307
+ #klarna_discount h3 {
308
+ font-size: 12px;
309
+ font-weight: bold;
310
+ text-transform: uppercase;
311
+ }
312
+
313
+ #klarna_discount label {
314
+ font-size: 11px;
315
+ font-weight: normal;
316
+ text-transform: none;
317
+ }
318
+
319
+ #klarna_discount button {
320
+ color: #333333;
321
+ letter-spacing: 0.8px;
322
+ width: 138px;
323
+ border: none;
324
+ border-radius: 3px;
325
+ background-clip: padding-box;
326
+ background-color: #f5f5f5;
327
+ cursor: pointer;
328
+ float: right;
329
+ }
330
+
331
+ #klarna_discount button.button span {
332
+ height: 28px;
333
+ line-height: 28px;
334
+ }
335
+
336
+ #klarna_discount button:hover {
337
+ background-color: #e5e5e5;
338
+ }
339
+
340
+ #klarna_discount input {
341
+ outline: 0;
342
+ background: #ffffff;
343
+ width: 100px;
344
+ height: 28px;
345
+ padding: 0 5px;
346
+ border: 1px solid #cccccc;
347
+ border-radius: 0;
348
+ box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .12);
349
+ }
350
+
351
+ #klarna_discount .error {
352
+ border-color: #ff5e5e;
353
+ box-shadow: inset 0 0 0 1px rgba(255, 26, 26, .12);
354
+ }
355
+
356
+ #main #klarna-checkout-container iframe {
357
+ display: block;
358
+ }
359
+
360
+ /* ===========================================================
361
+ * Newsletter
362
+ * =========================================================== */
363
+
364
+ #klarna-checkout-newsletter-container label {
365
+ font-size: 11px;
366
+ }
367
+
368
+ #klarna-checkout-newsletter-container h3 {
369
+ font-size: 12px;
370
+ font-weight: bold;
371
+ text-transform: uppercase;
372
+ }
373
+
374
+ #klarna-checkout-newsletter {
375
+ margin-right: 5px;
376
+ }
377
+
378
+ /* ===========================================================
379
+ * Reward
380
+ * =========================================================== */
381
+
382
+ #klarna-checkout-reward-container {
383
+ width: 280px;
384
+ }
385
+
386
+ #klarna-checkout-reward-container label {
387
+ font-size: 11px;
388
+ }
389
+
390
+ #klarna-checkout-reward-container h3 {
391
+ font-size: 12px;
392
+ font-weight: bold;
393
+ text-transform: uppercase;
394
+ }
395
+
396
+ #use-reward-points {
397
+ margin-right: 5px;
398
+ }
399
+
400
+
401
+ /* ===========================================================
402
+ * General
403
+ * =========================================================== */
404
+ #klarna-checkout-newsletter-container,
405
+ #klarna_discount {
406
+ width: 260px;
407
+ margin-bottom: 20px;
408
+ }
409
+
410
+ a.button::-moz-focus-inner {
411
+ padding:0;
412
+ border:0;
413
+ }
414
+ a.button {
415
+ -webkit-border-fit:lines;
416
+ }
417
+ a.button {
418
+ overflow:visible;
419
+ width:auto;
420
+ border:0;
421
+ padding:0;
422
+ margin:0;
423
+ background:transparent;
424
+ cursor:pointer;
425
+ text-decoration: none;
426
+ }
427
+ a.button span {
428
+ display:block;
429
+ height:19px;
430
+ border:1px solid #de5400;
431
+ background:#f18200;
432
+ padding:0 8px;
433
+ font:bold 12px/19px Arial, Helvetica, sans-serif;
434
+ text-align:center;
435
+ white-space:nowrap;
436
+ color:#fff;
437
+ }
438
+ a.button span span {
439
+ border:0;
440
+ padding:0;
441
+ }
442
+ a.disabled span {
443
+ border-color:#bbb !important;
444
+ background:#bbb !important;
445
+ }
skin/frontend/base/default/images/vaimo/klarna/icons.png ADDED
Binary file