Klarna_PaymentModule_EE19 - Version 1.0.1

Version Notes

Changelog 1.0.1
* Added the module version in the payment method settings for each payment method
* Added a sort order field for both invoice and part paymentmethod
* Updated the calc_monthly_cost method
* Updated so the special price is used for the part payment price calculated when available.
* Update so the part payment price is always calculated based on the product price incl. VAT
* Updated so the part payment prices on the product pages and the checkout form always are rounded up to closest integer.

Download this release

Release Info

Developer Magento Core Team
Extension Klarna_PaymentModule_EE19
Version 1.0.1
Comparing to
See all releases


Version 1.0.1

Files changed (78) hide show
  1. app/code/community/Klarna/KlarnaPaymentModule/Block/Checkout/Address/List.php +9 -0
  2. app/code/community/Klarna/KlarnaPaymentModule/Block/Checkout/Fee.php +28 -0
  3. app/code/community/Klarna/KlarnaPaymentModule/Block/Invoice/Totals/Fee.php +45 -0
  4. app/code/community/Klarna/KlarnaPaymentModule/Block/Klarna/Invoice/InvoiceForm.php +10 -0
  5. app/code/community/Klarna/KlarnaPaymentModule/Block/Klarna/Invoice/InvoicePaymentInfo.php +40 -0
  6. app/code/community/Klarna/KlarnaPaymentModule/Block/Klarna/PartPayment/PartPaymentForm.php +10 -0
  7. app/code/community/Klarna/KlarnaPaymentModule/Block/Klarna/PartPayment/PartPaymentInfo.php +42 -0
  8. app/code/community/Klarna/KlarnaPaymentModule/Block/Order/Totals/Fee.php +44 -0
  9. app/code/community/Klarna/KlarnaPaymentModule/Block/Product/Price.php +96 -0
  10. app/code/community/Klarna/KlarnaPaymentModule/Helper/Api.php +1214 -0
  11. app/code/community/Klarna/KlarnaPaymentModule/Helper/Calc/Klarna.php +477 -0
  12. app/code/community/Klarna/KlarnaPaymentModule/Helper/Data.php +233 -0
  13. app/code/community/Klarna/KlarnaPaymentModule/Helper/Pclass.php +186 -0
  14. app/code/community/Klarna/KlarnaPaymentModule/Helper/klarnaapi.php +4501 -0
  15. app/code/community/Klarna/KlarnaPaymentModule/Helper/pclasses.php +153 -0
  16. app/code/community/Klarna/KlarnaPaymentModule/Model/Config/Backend/Invoicefee.php +121 -0
  17. app/code/community/Klarna/KlarnaPaymentModule/Model/Invoice/Tax.php +65 -0
  18. app/code/community/Klarna/KlarnaPaymentModule/Model/Invoice/Total.php +79 -0
  19. app/code/community/Klarna/KlarnaPaymentModule/Model/Klarna/Invoice.php +105 -0
  20. app/code/community/Klarna/KlarnaPaymentModule/Model/Klarna/PartPayment.php +94 -0
  21. app/code/community/Klarna/KlarnaPaymentModule/Model/Klarna/Shared.php +365 -0
  22. app/code/community/Klarna/KlarnaPaymentModule/Model/Observer.php +156 -0
  23. app/code/community/Klarna/KlarnaPaymentModule/Model/Quote/TaxTotal.php +117 -0
  24. app/code/community/Klarna/KlarnaPaymentModule/Model/Quote/Total.php +107 -0
  25. app/code/community/Klarna/KlarnaPaymentModule/Model/Resource/Mysql4/Setup.php +5 -0
  26. app/code/community/Klarna/KlarnaPaymentModule/Model/Source/Countries.php +54 -0
  27. app/code/community/Klarna/KlarnaPaymentModule/Model/Source/Integrationmode.php +36 -0
  28. app/code/community/Klarna/KlarnaPaymentModule/controllers/AddressController.php +49 -0
  29. app/code/community/Klarna/KlarnaPaymentModule/controllers/IndexController.php +11 -0
  30. app/code/community/Klarna/KlarnaPaymentModule/etc/config.xml +219 -0
  31. app/code/community/Klarna/KlarnaPaymentModule/etc/system.xml +370 -0
  32. app/code/community/Klarna/KlarnaPaymentModule/sql/klarnaPaymentModule_setup/mysql4-install-1.0.0e.php +52 -0
  33. app/design/adminhtml/default/default/template/klarna/paymentinfo-invoice.phtml +23 -0
  34. app/design/adminhtml/default/default/template/klarna/paymentinfo-partpayment.phtml +19 -0
  35. app/design/frontend/base/default/layout/klarna.xml +47 -0
  36. app/design/frontend/base/default/template/klarna/checkout/address/list.phtml +79 -0
  37. app/design/frontend/base/default/template/klarna/checkout/fee.phtml +56 -0
  38. app/design/frontend/base/default/template/klarna/form-invoice.phtml +151 -0
  39. app/design/frontend/base/default/template/klarna/form-partpayment.phtml +190 -0
  40. app/design/frontend/base/default/template/klarna/order/totals.phtml +1 -0
  41. app/design/frontend/base/default/template/klarna/paymentinfo-invoice.phtml +10 -0
  42. app/design/frontend/base/default/template/klarna/paymentinfo-partpayment.phtml +16 -0
  43. app/design/frontend/base/default/template/klarna/product/price.phtml +43 -0
  44. app/etc/modules/Klarna_KlarnaPaymentModule.xml +8 -0
  45. app/locale/da_DK/Klarna_KlarnaPaymentModule.csv +43 -0
  46. app/locale/de_DE/Klarna_KlarnaPaymentModule.csv +48 -0
  47. app/locale/fi_FI/Klarna_KlarnaPaymentModule.csv +43 -0
  48. app/locale/nb_NO/Klarna_KlarnaPaymentModule.csv +47 -0
  49. app/locale/nl_NL/Klarna_KlarnaPaymentModule.csv +44 -0
  50. app/locale/nn_NO/Klarna_KlarnaPaymentModule.csv +47 -0
  51. app/locale/sv_SE/Klarna_KlarnaPaymentModule.csv +46 -0
  52. js/klarna.js +74 -0
  53. package.xml +26 -0
  54. skin/adminhtml/base/default/klarna/klarna_invoice_de.png +0 -0
  55. skin/adminhtml/base/default/klarna/klarna_invoice_dk.png +0 -0
  56. skin/adminhtml/base/default/klarna/klarna_invoice_fi.png +0 -0
  57. skin/adminhtml/base/default/klarna/klarna_invoice_nl.png +0 -0
  58. skin/adminhtml/base/default/klarna/klarna_invoice_no.png +0 -0
  59. skin/adminhtml/base/default/klarna/klarna_invoice_se.png +0 -0
  60. skin/adminhtml/base/default/klarna/klarna_part_de.png +0 -0
  61. skin/adminhtml/base/default/klarna/klarna_part_dk.png +0 -0
  62. skin/adminhtml/base/default/klarna/klarna_part_fi.png +0 -0
  63. skin/adminhtml/base/default/klarna/klarna_part_nl.png +0 -0
  64. skin/adminhtml/base/default/klarna/klarna_part_no.png +0 -0
  65. skin/adminhtml/base/default/klarna/klarna_part_se.png +0 -0
  66. skin/frontend/base/default/klarna/dutch_credit.jpg +0 -0
  67. skin/frontend/base/default/klarna/klarna_invoice_de.png +0 -0
  68. skin/frontend/base/default/klarna/klarna_invoice_dk.png +0 -0
  69. skin/frontend/base/default/klarna/klarna_invoice_fi.png +0 -0
  70. skin/frontend/base/default/klarna/klarna_invoice_nl.png +0 -0
  71. skin/frontend/base/default/klarna/klarna_invoice_no.png +0 -0
  72. skin/frontend/base/default/klarna/klarna_invoice_se.png +0 -0
  73. skin/frontend/base/default/klarna/klarna_part_de.png +0 -0
  74. skin/frontend/base/default/klarna/klarna_part_dk.png +0 -0
  75. skin/frontend/base/default/klarna/klarna_part_fi.png +0 -0
  76. skin/frontend/base/default/klarna/klarna_part_nl.png +0 -0
  77. skin/frontend/base/default/klarna/klarna_part_no.png +0 -0
  78. skin/frontend/base/default/klarna/klarna_part_se.png +0 -0
app/code/community/Klarna/KlarnaPaymentModule/Block/Checkout/Address/List.php ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Klarna_KlarnaPaymentModule_Block_Checkout_Address_List extends Mage_Core_Block_Template
3
+ {
4
+ protected function _construct() {
5
+
6
+ }
7
+
8
+
9
+ }
app/code/community/Klarna/KlarnaPaymentModule/Block/Checkout/Fee.php ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Klarna_KlarnaPaymentModule_Block_Checkout_Fee extends Mage_Checkout_Block_Total_Default
4
+ {
5
+ protected $_template = 'klarna/checkout/fee.phtml';
6
+
7
+ /**
8
+ * Get Invoice fee include tax
9
+ *
10
+ * @return float
11
+ */
12
+ public function getCodFeeIncludeTax()
13
+ {
14
+ return $this->getTotal()->getAddress()->getInvoiceFee()+$this->getTotal()->getAddress()->getInvoiceTaxAmount();
15
+
16
+ }
17
+
18
+ /**
19
+ * Get Invoice fee exclude tax
20
+ *
21
+ * @return float
22
+ */
23
+ public function getCodFeeExcludeTax()
24
+ {
25
+ return $this->getTotal()->getAddress()->getInvoiceFee();
26
+ }
27
+
28
+ }
app/code/community/Klarna/KlarnaPaymentModule/Block/Invoice/Totals/Fee.php ADDED
@@ -0,0 +1,45 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+
4
+ class Klarna_KlarnaPaymentModule_Block_Invoice_Totals_Fee extends Mage_Core_Block_Abstract
5
+ {
6
+
7
+ public function initTotals()
8
+ {
9
+ $parent = $this->getParentBlock();
10
+ $this->_invoice = $parent->getInvoice();
11
+ $this->_order = $parent->getOrder();
12
+
13
+ $info = $this->_order->getPayment()->getMethodInstance()->getInfoInstance();
14
+
15
+ if($info->getAdditionalInformation("invoice_fee")) {
16
+ $fee = new Varien_Object();
17
+ $fee->setLabel($this->__('Klarna Invoice fee'));
18
+ $fee->setValue($info->getAdditionalInformation("invoice_fee")+$info->getAdditionalInformation("invoice_tax_amount"));
19
+ $fee->setBaseValue($info->getAdditionalInformation("base_invoice_fee")+$info->getAdditionalInformation("base_invoice_tax_amount"));
20
+ $fee->setCode('invoice_fee');
21
+ /*
22
+ if (Mage::helper('klarnaPaymentModule')->displayInvoiceFeeBothPrices()){
23
+ $fee->setLabel($this->__('Klarna Invoice fee (Incl.Tax)'));
24
+
25
+ $feeExcl = new Varien_Object();
26
+ $feeExcl->setLabel($this->__('Klarna Invoice fee (Excl.Tax)'));
27
+ $feeExcl->setValue($info->getAdditionalInformation("invoice_fee"));
28
+ $feeExcl->setBaseValue($info->getAdditionalInformation("base_invoice_fee"));
29
+ $feeExcl->setCode('cod_fee_incl');
30
+
31
+ $parent->addTotalBefore($feeExcl,'tax');
32
+ $parent->addTotalBefore($fee,'tax');
33
+ }elseif(Mage::helper('klarnaPaymentModule')->displayInvoiceFeeExcludingTax()){
34
+ $fee->setValue($info->getAdditionalInformation("invoice_fee"));
35
+ $fee->setBaseValue($info->getAdditionalInformation("base_invoice_fee"));
36
+ $parent->addTotalBefore($fee,'tax');
37
+ }else{
38
+ */
39
+ $parent->addTotalBefore($fee,'tax');
40
+ //}
41
+ }
42
+
43
+ return $this;
44
+ }
45
+ }
app/code/community/Klarna/KlarnaPaymentModule/Block/Klarna/Invoice/InvoiceForm.php ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Klarna_KlarnaPaymentModule_Block_Klarna_Invoice_InvoiceForm extends Mage_Payment_Block_Form
3
+ {
4
+ protected function _construct()
5
+ {
6
+ $this->setTemplate('klarna/form-invoice.phtml');
7
+ parent::_construct();
8
+ }
9
+ }
10
+
app/code/community/Klarna/KlarnaPaymentModule/Block/Klarna/Invoice/InvoicePaymentInfo.php ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Klarna_KlarnaPaymentModule_Block_Klarna_Invoice_InvoicePaymentInfo extends Mage_Payment_Block_Info
4
+ {
5
+ protected function _construct()
6
+ {
7
+ parent::_construct();
8
+ $this->setTemplate('klarna/paymentinfo-invoice.phtml');
9
+ }
10
+
11
+ public function getInvoiceFee()
12
+ {
13
+
14
+ $fee = $this->getInfo()->getAdditionalInformation('invoice_fee');
15
+
16
+ if ($fee && !Mage::helper("klarnaPaymentModule")->invoicePriceIncludesTax()) {
17
+ $fee += $this->getInfo()->getAdditionalInformation('invoice_tax_amount');
18
+ return $fee . ' ' . Mage::app()->getLocale()->currency($this->getInfo()->getOrder()->getOrderCurrencyCode())->getSymbol();
19
+ }
20
+ elseif(!$fee) {
21
+ $helper = Mage::helper('klarnaPaymentModule');
22
+ $fee = $helper->getInvoiceFee();
23
+ }
24
+
25
+ $core = Mage::helper('core');
26
+ return $core->formatPrice($fee);
27
+ }
28
+
29
+ public function getInvoiceNumber()
30
+ {
31
+ $data = $this->getMethod()->getInfoInstance();
32
+ if ($data) {
33
+ return $data->getAdditionalInformation('klarna_invoice_id');
34
+ }
35
+
36
+ return false;
37
+ }
38
+
39
+ }
40
+
app/code/community/Klarna/KlarnaPaymentModule/Block/Klarna/PartPayment/PartPaymentForm.php ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Klarna_KlarnaPaymentModule_Block_Klarna_PartPayment_PartPaymentForm extends Mage_Payment_Block_Form
3
+ {
4
+ protected function _construct()
5
+ {
6
+ $this->setTemplate('klarna/form-partpayment.phtml');
7
+ parent::_construct();
8
+ }
9
+ }
10
+
app/code/community/Klarna/KlarnaPaymentModule/Block/Klarna/PartPayment/PartPaymentInfo.php ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Klarna_KlarnaPaymentModule_Block_Klarna_PartPayment_PartPaymentInfo extends Mage_Payment_Block_Info
4
+ {
5
+ protected function _construct()
6
+ {
7
+ parent::_construct();
8
+ $this->setTemplate('klarna/paymentinfo-partpayment.phtml');
9
+ }
10
+
11
+ public function getInvoiceNumber()
12
+ {
13
+ $data = $this->getMethod()->getInfoInstance();
14
+ if ($data) {
15
+ return $data->getAdditionalInformation('klarna_invoice_id');
16
+ }
17
+
18
+ return false;
19
+ }
20
+
21
+ public function getMonthlyCost()
22
+ {
23
+ $data = $this->getMethod()->getInfoInstance();
24
+ if ($data) {
25
+ return $data->getAdditionalInformation('klarna_monthlycost');
26
+ }
27
+
28
+ return false;
29
+ }
30
+
31
+ public function getPclassType()
32
+ {
33
+ $data = $this->getMethod()->getInfoInstance();
34
+ if ($data) {
35
+ return $data->getAdditionalInformation('klarna_pclasstype');
36
+ }
37
+
38
+ return false;
39
+ }
40
+
41
+ }
42
+
app/code/community/Klarna/KlarnaPaymentModule/Block/Order/Totals/Fee.php ADDED
@@ -0,0 +1,44 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Klarna_KlarnaPaymentModule_Block_Order_Totals_Fee extends Mage_Core_Block_Abstract
3
+ {
4
+
5
+ public function initTotals()
6
+ {
7
+ $parent = $this->getParentBlock();
8
+ $this->_order = $parent->getOrder();
9
+
10
+ $info = $this->_order->getPayment()->getMethodInstance()->getInfoInstance();
11
+
12
+ if($info->getAdditionalInformation("invoice_fee")) {
13
+ $fee = new Varien_Object();
14
+ $fee->setLabel($this->__('Klarna Invoice fee'));
15
+ //$fee->setValue($info->getAdditionalInformation("invoice_fee")+$info->getAdditionalInformation("invoice_tax_amount"));
16
+ //$fee->setBaseValue($info->getAdditionalInformation("base_invoice_fee")+$info->getAdditionalInformation("base_invoice_tax_amount"));
17
+ $fee->setValue($info->getAdditionalInformation("invoice_fee"));
18
+ $fee->setBaseValue($info->getAdditionalInformation("base_invoice_fee"));
19
+ $fee->setCode('invoice_fee');
20
+ /*
21
+ if (Mage::helper('klarnaPaymentModule')->displayInvoiceFeeBothPrices()){
22
+ $fee->setLabel($this->__('Klarna Invoice fee (Incl.Tax)'));
23
+
24
+ $feeExcl = new Varien_Object();
25
+ $feeExcl->setLabel($this->__('Klarna Invoice fee (Excl.Tax)'));
26
+ $feeExcl->setValue($info->getAdditionalInformation("invoice_fee"));
27
+ $feeExcl->setBaseValue($info->getAdditionalInformation("base_invoice_fee"));
28
+ $feeExcl->setCode('cod_fee_incl');
29
+
30
+ $parent->addTotalBefore($feeExcl,'tax');
31
+ $parent->addTotalBefore($fee,'tax');
32
+ }elseif(Mage::helper('klarnaPaymentModule')->displayInvoiceFeeExcludingTax()){
33
+ $fee->setValue($info->getAdditionalInformation("invoice_fee"));
34
+ $fee->setBaseValue($info->getAdditionalInformation("base_invoice_fee"));
35
+ $parent->addTotalBefore($fee,'tax');
36
+ }else{
37
+ */
38
+ $parent->addTotalBefore($fee,'tax');
39
+ //}
40
+ }
41
+
42
+ return $this;
43
+ }
44
+ }
app/code/community/Klarna/KlarnaPaymentModule/Block/Product/Price.php ADDED
@@ -0,0 +1,96 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Klarna_KlarnaPaymentModule_Block_Product_Price extends Mage_Catalog_Block_Product_Price
3
+ {
4
+ // xxx Override toHtml and append our own Html
5
+ protected function _toHtml()
6
+ {
7
+ if($this->getTemplate() == "catalog/product/price.phtml")
8
+ {
9
+ $_taxHelper = $this->helper('tax');
10
+ $curr = Mage::app()->getStore()-> getCurrentCurrencyCode();
11
+ $pclasshelper = Mage::helper("klarnaPaymentModule/pclass");
12
+ $api = Mage::helper("klarnaPaymentModule");
13
+ $price = 0;
14
+
15
+ switch(strtolower($curr))
16
+ {
17
+ case 'sek':
18
+ $country = "SE";
19
+ $lang = "se";
20
+ break;
21
+ case 'nok':
22
+ $country = "NO";
23
+ $lang = "no";
24
+ break;
25
+ case 'eur':
26
+ $locale = Mage::app()->getLocale()->getLocaleCode();
27
+ if($locale == "de_DE") {
28
+ $country = "DE";
29
+ $lang = "de";
30
+ } else if($locale == "fi_FI") {
31
+ $country = "FI";
32
+ $lang = "fi";
33
+ } else if($locale == "nl_NL") {
34
+ $country = "NL";
35
+ $lang = "nl";
36
+ } else {
37
+ return parent::_toHtml();
38
+ }
39
+ break;
40
+ case 'dkk':
41
+ $country = "DK";
42
+ $lang = "dk";
43
+ break;
44
+ default:
45
+ $country = "SE";
46
+ $lang = "se";
47
+ break;
48
+ }
49
+
50
+ $base_currency = Mage::app()->getStore()->getBaseCurrencyCode();
51
+ $convert = ($base_currency != $curr);
52
+
53
+ $rate = 1;
54
+
55
+
56
+ if($convert)
57
+ {
58
+ $cCurr = Mage::getModel('directory/currency');
59
+ $cCurr->load($base_currency);
60
+ $rate = $cCurr->getRate($curr);
61
+ }
62
+
63
+ if($this->getProduct()->getSpecialPrice() > 0)
64
+ $price = $_taxHelper->getPrice($this->getProduct(), $this->getProduct()->getSpecialPrice(), true)*$rate;
65
+ else
66
+ $price = $_taxHelper->getPrice($this->getProduct(), $this->getProduct()->getPrice(), true)*$rate;
67
+
68
+ // Get a collection of pclasses
69
+ $pclasscollection = $pclasshelper->getSortedPclassesForStoreAndCountry($price*100, $country, Mage::app()->getStore()->getId(), 1, 1);
70
+
71
+ // xxx If we get -1 we do not have any konto pclass for this currency
72
+ if(sizeof($pclasscollection) == 0 || (int)Mage::getStoreConfig('payment/klarna_partpayment/active', Mage::app()->getStore()->getId()) == 0)
73
+ return parent::_toHtml();
74
+
75
+ // Get the first option
76
+ $pclass = array_shift($pclasscollection);
77
+
78
+ // xxx If we are at product page and already have created the price block we do not want to do that again
79
+ if($this->getLayout()->getBlock('klarna_price_block') && Mage::app()->getFrontController()->getRequest()->getRouteName() == "catalog")
80
+ {
81
+ return parent::_toHtml();
82
+ }
83
+ else if(Mage::app()->getFrontController()->getRequest()->getRouteName() == "catalog" && !(strstr(strtolower(Mage::app()->getFrontController()->getRequest()->getRequestUri()), "/category/view/")))
84
+ {
85
+ $html = parent::_toHtml() . $this->getLayout()->createBlock('core/template', 'klarna_price_block')->setTemplate('klarna/product/price.phtml')->setData('monthlycost', $pclass[0])->setData('lang', $lang)->setData("sum", $price*100)->setData("pclass", $pclass)->toHtml();
86
+ }
87
+ else
88
+ $html = parent::_toHtml() . $this->getLayout()->createBlock('core/template', chr(rand(97,122)).chr(rand(97,122)).chr(rand(97,122)).chr(rand(97,122)).chr(rand(97,122)).chr(rand(97,122)).chr(rand(97,122)))->setTemplate('klarna/product/price.phtml')->setData('monthlycost', $pclass[0])->setData('lang', $lang)->setData("sum", $price*100)->toHtml();
89
+
90
+ return $html;
91
+ }
92
+ else
93
+ return parent::_toHtml();
94
+ }
95
+
96
+ }
app/code/community/Klarna/KlarnaPaymentModule/Helper/Api.php ADDED
@@ -0,0 +1,1214 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ require_once "klarnaapi.php";
4
+ class Klarna_KlarnaPaymentModule_Klarna_XmlRpc_Integer_Value extends Zend_XmlRpc_Value_Integer
5
+ {
6
+ function __construct($value)
7
+ {
8
+ parent::__construct($value);
9
+ $this->_value = $value;
10
+ }
11
+ }
12
+
13
+ class Klarna_KlarnaPaymentModule_Helper_Api extends Mage_Core_Helper_Abstract
14
+ {
15
+ const KREDITOR_HOST = 'https://payment.klarnaPaymentModule.com';
16
+ const KREDITOR_PORT = 443;
17
+ const KREDITOR_HOST_TEST = 'http://beta-test.klarna.com';
18
+ const KREDITOR_PORT_TEST = 80;
19
+ const PROTO_VSN = '4.0';
20
+ const CLIENT_VSN = 'magento:ee1.0';
21
+ const KREDITOR_SHIPMENT_NORMAL = 1;
22
+ const KREDITOR_SHIPMENT_EXPRESS = 2;
23
+
24
+
25
+ const GOODSFLAG_IS_SHIPMENT = 8; // Indicates that the item is a shipment fee.
26
+ const GOODSFLAG_IS_HANDLING = 16; // Indicates that the item is a handling fee.
27
+ const GOODSFLAG_INC_VAT = 32; // Send the prices including VAT
28
+
29
+ protected $api_host = false;
30
+ protected $api_port = false;
31
+
32
+ protected $test_flag = false;
33
+ protected $paymentmethod = '';
34
+
35
+ protected $order = null;
36
+
37
+ protected $country_settings = array(
38
+ 'NO' => array(
39
+ 'pno_encoding' => 3,
40
+ 'language' => 97,
41
+ 'country' => 164,
42
+ 'currency' => 1,
43
+ 'currency_code' => 'NOK',
44
+ 'title' => 'Faktura - betal innen 14 dager',
45
+ 'title_pp' => 'Delbetaling via Klarna konto',
46
+ 'admin_description' => 'Norway - NOK'
47
+ ),
48
+ 'SE' => array(
49
+ 'pno_encoding' => 2,
50
+ 'language' => 138,
51
+ 'country' => 209,
52
+ 'currency' => 0,
53
+ 'currency_code' => 'SEK',
54
+ 'title' => 'Faktura - Betala om 14 dagar',
55
+ 'title_pp' => 'Delbetalning Klarna konto',
56
+ 'admin_description' => 'Sweden - SEK'
57
+ ),
58
+ 'DK' => array(
59
+ 'pno_encoding' => 5,
60
+ 'language' => 27,
61
+ 'country' => 59,
62
+ 'currency' => 3,
63
+ 'currency_code' => 'DKK',
64
+ 'title' => 'Faktura - Betaling indenfor 14 dage',
65
+ 'title_pp' => 'Delbetaling - Klarna Konto',
66
+ 'admin_description' => 'Denmark - DKK'
67
+ ),
68
+ 'FI' => array(
69
+ 'pno_encoding' => 4,
70
+ 'language' => 37,
71
+ 'country' => 73,
72
+ 'currency' => 2,
73
+ 'currency_code' => 'EUR',
74
+ 'title' => 'Lasku - 14 vrk maksuaikaa',
75
+ 'title_pp' => 'Osamaksu - Klarna Tili',
76
+ 'admin_description' => 'Finland - EURO'
77
+ ),
78
+ 'NL' => array(
79
+ 'pno_encoding' => 7,
80
+ 'language' => 101,
81
+ 'country' => 154,
82
+ 'currency' => 2,
83
+ 'currency_code' => 'EUR',
84
+ 'title' => 'Factuur - Betaal binnen 14 dagen',
85
+ 'title_pp' => 'Gespreide betaling- Klarna Account',
86
+ 'admin_description' => 'Netherlands - EURO'
87
+ ),
88
+ 'DE' => array(
89
+ 'pno_encoding' => 6,
90
+ 'language' => 28,
91
+ 'country' => 81,
92
+ 'currency' => 2,
93
+ 'currency_code' => 'EUR',
94
+ 'title' => 'Rechnung - 14 tage',
95
+ 'title_pp' => 'Ratenkauf',
96
+ 'admin_description' => 'Germany - EURO'
97
+ ),
98
+
99
+ );
100
+
101
+ function getCountryAdminOptions()
102
+ {
103
+ $countries = array();
104
+ foreach($this->country_settings as $key => $value) {
105
+ $countries[] = array(
106
+ 'key' => $key,
107
+ 'value' => $value['admin_description']
108
+ );
109
+ }
110
+
111
+ return $countries;
112
+ }
113
+
114
+ function getCountrySettings($country)
115
+ {
116
+ if(!isset($this->country_settings[$country])) {
117
+ return false;
118
+ }
119
+
120
+ return $this->country_settings[$country];
121
+ }
122
+
123
+ function __construct()
124
+ {
125
+ $this->integration_mode = false;
126
+ $this->field_data = array();
127
+ }
128
+
129
+ function setOrder($order)
130
+ {
131
+ $this->order = $order;
132
+ }
133
+
134
+ function getOrder()
135
+ {
136
+ return $this->order;
137
+ }
138
+
139
+ function setCountrySpecificFields($data)
140
+ {
141
+
142
+ $helper = Mage::helper('klarnaPaymentModule');
143
+ $fields = $helper->getCountrySpecificFields($this->order);
144
+
145
+ foreach($fields as $field) {
146
+ if($field == 'dob') {
147
+ foreach(array('year', 'day', 'month') as $item) {
148
+ $key = 'dob_' . $item;
149
+ $this->field_data[$key] = $helper->getFieldValue($key, $data);
150
+ }
151
+ }
152
+ else {
153
+ $this->field_data[$field] = $helper->getFieldValue($field, $data);
154
+ }
155
+ }
156
+ }
157
+
158
+ function get_goods_secret()
159
+ {
160
+ $goodsList = $this->get_goods_list();
161
+ $buffer = '';
162
+ foreach($goodsList as $goods) {
163
+ $buffer .= $goods['goods']['title'] . ":";
164
+ }
165
+
166
+ $buffer .= $this->secret;
167
+
168
+ $data = $this->md5_base64($this->decode_data($buffer));
169
+
170
+ return $data;
171
+ }
172
+
173
+
174
+ function md5_base64($data) {
175
+ return base64_encode(pack("H*", md5($data)));
176
+ }
177
+
178
+ /**
179
+ *
180
+ * This methods load the correct config based
181
+ * on the store id. Call to this method are needed before any
182
+ * call is made to Klarna
183
+ *
184
+ * @param <type> $store The magento store id
185
+ * @param <string> $method The payment method (klarna_invoice or klarna_partpayment)
186
+ */
187
+ function loadConfig($store, $method)
188
+ {
189
+ if(!$store || !$method)
190
+ Mage::throwException("You must specify the both the store id and payment method");
191
+
192
+ $this->merchantid = (int)Mage::getStoreConfig('payment/' . $method . '/merchant_id', $store);
193
+ $this->secret = Mage::getStoreConfig('payment/' . $method . '/shared_secret', $store);
194
+
195
+ $this->paymentmethod = $method;
196
+
197
+ /* Load correct host / port based on whether it is running in testing */
198
+ $testing = Mage::getStoreConfig('payment/' . $method . '/is_test', $store);
199
+
200
+ if($testing) {
201
+ $this->test_flag = 2;
202
+ }
203
+ else {
204
+ $this->test_flag = 0;
205
+ }
206
+
207
+ $this->startClient();
208
+
209
+ }
210
+
211
+ function startClient()
212
+ {
213
+ $url = $this->api_host . ':' . $this->api_port;
214
+
215
+ $options = array(
216
+ 'sslverify' => false
217
+ );
218
+
219
+ if(false) {
220
+ $options['debug'] = true;
221
+ }
222
+
223
+ //$this->client = new Zend_XmlRpc_Client($url); // XML_RPC2_Client::create($url, $options);
224
+
225
+ }
226
+
227
+ function setIntegrationMode($mode)
228
+ {
229
+ $this->integration_mode = $mode;
230
+ }
231
+
232
+ function getDefaultParams()
233
+ {
234
+ $params = array();
235
+ $params[] = Klarna_KlarnaPaymentModule_Helper_Api::PROTO_VSN; // Proto version
236
+ $params[] = Klarna_KlarnaPaymentModule_Helper_Api::CLIENT_VSN; // Client version
237
+ $params[] = $this->merchantid;
238
+ $params[] = ''; // eStoreUser
239
+ $params[] = $this->get_goods_secret(); //$this->secret; // secret
240
+
241
+ return $params;
242
+ }
243
+
244
+ function get_goods_list($itemcollection = false, $addinvoicefee = true)
245
+ {
246
+ $magentoversion = Mage::getVersion();
247
+ $orderLocale = Mage::getStoreConfig(Mage_Core_Model_Locale::XML_PATH_DEFAULT_LOCALE, $this->order->getStoreId());
248
+ $goods = array();
249
+ $discount_amount = 0;
250
+ $total_discount_amount = 0;
251
+ $discount_tax = 0;
252
+ $discount_count = 0;
253
+ $applyafter = Mage::getStoreConfig("tax/calculation/apply_after_discount");
254
+ $override_applyafter = (Mage::getStoreConfig("tax/calculation/discount_tax", Mage::app()->getStore()->getId()) == 1);
255
+ $price_inc_tax = Mage::helper('tax')->priceIncludesTax($this->order->getStoreId());
256
+ $shipping_price_inc_tax = Mage::helper('tax')->shippingPriceIncludesTax($this->order->getStoreId());
257
+
258
+ $items = $itemcollection ? $itemcollection : $this->order->getAllVisibleItems();
259
+
260
+ foreach($items as $item) {
261
+
262
+ $id = $item->getProductId();
263
+ $product = Mage::getModel('catalog/product')->load($id);
264
+ $qty = (int)($item->getQtyOrdered() ? $item->getQtyOrdered() : $item->getQty());
265
+
266
+ // Get the discount amount
267
+ $discount_amount = $item->getDiscountAmount();
268
+
269
+ // Get the price inc. VAT
270
+ $item_price = $item->getPriceInclTax();
271
+
272
+ // Get the item tax
273
+ $tax_percent = $item->getTaxPercent();
274
+
275
+ $rowtotalincltax = $item->getRowTotalInclTax() ? $item->getRowTotalInclTax() : $item->getRowTotal() + $item->getTaxAmount();
276
+
277
+ if($item->getProductType() != 'bundle')
278
+ $tax_percent = is_numeric($tax_percent) ? $item->getTaxPercent() : $this->getTaxRate($product);
279
+ else
280
+ $tax_percent = $this->getTaxRate($product);
281
+
282
+ // If we for some reason doesnt get the price above we calculate it instead
283
+ if(!$item_price) {
284
+ $item_price = $item->getPrice() / 100 * (100 + $tax_percent);
285
+ }
286
+
287
+ $children = $product->getChildrenItems();
288
+
289
+ // Go through the children items of a bundled product
290
+ $citems = $item->getChildrenItems();
291
+ if(!$product->isConfigurable() && count($citems) > 0) {
292
+
293
+ // There are differences between Magento versions
294
+ // so we need to get the price type this way.
295
+ $pricetype = $item->getProduct() ? $item->getProduct()->getPriceType() : $product->getPriceType();
296
+
297
+ if($pricetype == 1) {
298
+
299
+ $goods[] = array(
300
+ 'goods' => array(
301
+ 'artno' => $item->getSku(),
302
+ 'title' => $item->getName(),
303
+ 'price' => (int)((string)(round($item_price, 2)*100)),
304
+ 'vat' => (double)$item->getTaxPercent(),
305
+ 'discount' => 0,
306
+ 'flags' => self::GOODSFLAG_INC_VAT
307
+ ),
308
+ 'qty' => $qty,
309
+ );
310
+ }
311
+
312
+ foreach($citems as $citem) {
313
+
314
+ // Get the discount for the bundled product
315
+ $citem_discount = $citem->getDiscountAmount();
316
+
317
+ if($applyafter && ($citem_discount > 0)) {
318
+
319
+ $citem_discount = round(($citem->getDiscountAmount()*($citem->getTaxPercent()/100+1)),2);
320
+
321
+ $goods[] = array(
322
+ 'goods' => array(
323
+ 'artno' => 'discount',
324
+ 'title' => $this->translate("Discount", $orderLocale) . " - " . $citem->getName(),
325
+ 'vat' => $citem->getTaxPercent(),
326
+ 'discount' => 0,
327
+ 'price' => (int)(string)($citem_discount*100)*-1,
328
+ 'flags' => self::GOODSFLAG_INC_VAT),
329
+ 'qty' => 1);
330
+
331
+ } else if($citem_discount > 0) {
332
+
333
+ $goods[] = array(
334
+ 'goods' => array(
335
+ 'artno' => 'discount',
336
+ 'title' => $this->translate("Discount", $orderLocale) . " - " . $citem->getName(),
337
+ 'vat' => 0,
338
+ 'discount' => 0,
339
+ 'price' => (int)(string)(round(($citem_discount),2)*100)*-1,
340
+ 'flags' => self::GOODSFLAG_INC_VAT
341
+ ),
342
+ 'qty' => 1
343
+ );
344
+ }
345
+
346
+ $goods[] = array(
347
+ 'goods' => array(
348
+ 'artno' => $citem->getSku(),
349
+ 'title' => $citem->getName(),
350
+ 'price' => (int)((string)(round($citem->getPrice() / 100 * (100 + $citem->getTaxPercent()), 2)*100)),
351
+ 'vat' => (double)$citem->getTaxPercent(),
352
+ 'discount' => 0,
353
+ 'flags' => self::GOODSFLAG_INC_VAT
354
+ ),
355
+ 'qty' => (int)($citem->getQtyOrdered() ? $citem->getQtyOrdered() : $citem->getQty()),
356
+ );
357
+ }
358
+ }
359
+
360
+ if(count($children) == 1 && $product->isConfigurable()) {
361
+ $name = $children[0]->getName();
362
+ $sku = $children[0]->getProduct()->getSKU();
363
+ }
364
+ else {
365
+ $name = $product->getName();
366
+ $sku = $product->getSKU();
367
+ }
368
+
369
+ if($applyafter && ($discount_amount > 0)) {
370
+
371
+ $discount_amount = round(($item->getDiscountAmount()*($tax_percent/100+1)),2);
372
+
373
+ $goods[] = array(
374
+ 'goods' => array(
375
+ 'artno' => 'discount',
376
+ 'title' => $this->translate("Discount", $orderLocale) . " - " . $name,
377
+ 'vat' => $tax_percent,
378
+ 'discount' => 0,
379
+ 'price' => (int)(string)(round($discount_amount,2)*100)*-1,
380
+ 'flags' => self::GOODSFLAG_INC_VAT),
381
+ 'qty' => 1);
382
+ } else if($discount_amount > 0) {
383
+
384
+ $goods[] = array(
385
+ 'goods' => array(
386
+ 'artno' => 'discount',
387
+ 'title' => $this->translate("Discount", $orderLocale) . " - " . $name,
388
+ 'vat' => 0,
389
+ 'discount' => 0,
390
+ 'price' => (int)(string)(round(($discount_amount),2)*100)*-1,
391
+ 'flags' => self::GOODSFLAG_INC_VAT
392
+ ),
393
+ 'qty' => 1
394
+ );
395
+
396
+ }
397
+
398
+ if($item->getProductType() != 'bundle')
399
+ {
400
+ $goods[] = array(
401
+ 'goods' => array(
402
+ 'artno' => $sku,
403
+ 'title' => $name,
404
+ 'price' => (int)((string)(round($item_price, 2)*100)),
405
+ 'vat' => (double)$tax_percent,
406
+ 'discount' => 0,
407
+ 'flags' => self::GOODSFLAG_INC_VAT
408
+ ),
409
+ 'qty' => $qty,
410
+ );
411
+ }
412
+ }
413
+
414
+ // Only add invoice fee if we are making our first invoice
415
+ // This is only used when doing partial activations
416
+ if($addinvoicefee) {
417
+
418
+ /* Add shipping costs to goods */
419
+ $shipping_amount = $this->order->getShippingAmount();
420
+ $shipping_tax = $this->order->getShippingTaxAmount();
421
+
422
+
423
+ if($shipping_amount && $shipping_amount > 0) {
424
+
425
+ $shipping_discount_amount = $this->order->getShippingDiscountAmount();
426
+ $shipping_amount = $shipping_amount+$shipping_tax;
427
+
428
+ $goods[] = array(
429
+ 'goods' => array(
430
+ 'artno' => 'shippingfee',
431
+ 'title' => $this->translate('Shipping fee', $orderLocale),
432
+ 'vat' => (float)$this->getShippingTaxRate(),
433
+ 'discount' => 0,
434
+ 'price' => (int)((string)(($shipping_amount-$shipping_discount_amount)*100)),
435
+ 'flags' => self::GOODSFLAG_IS_SHIPMENT+self::GOODSFLAG_INC_VAT
436
+ ),
437
+ 'qty' => 1
438
+ );
439
+ }
440
+
441
+ /* Add invoice fee to goods */
442
+ $quote = Mage::getSingleton('checkout/session')->getQuote();
443
+
444
+ if ($quote->getId()) {
445
+ $fee_amount = $quote->getInvoiceFee();
446
+ $fee_tax = $quote->getInvoiceTaxAmount();
447
+ }
448
+ else {
449
+ $data = $this->order->getPayment();
450
+ $fee_amount = $data->getAdditionalInformation('invoice_fee');
451
+ $fee_tax = $data->getAdditionalInformation('invoice_tax_amount');
452
+ }
453
+ if ($fee_amount) {
454
+
455
+ $invoicefee = $fee_amount+$fee_tax;
456
+ $invoicefeevat = $fee_tax/$fee_amount;
457
+
458
+ $goods[] = array(
459
+ 'goods' => array(
460
+ 'artno' => 'invoicefee',
461
+ 'title' => $this->translate('Klarna Invoice fee', $orderLocale),
462
+ 'vat' => round($invoicefeevat,2)*100,
463
+ 'discount' => 0,
464
+ 'price' => (int)((string)(($invoicefee)*100)),
465
+ 'flags' => self::GOODSFLAG_IS_HANDLING+self::GOODSFLAG_INC_VAT
466
+ ),
467
+ 'qty' => 1
468
+ );
469
+ }
470
+ }
471
+
472
+ // Add gift card if present
473
+ if($this->order->getGiftCardsAmount() > 0) {
474
+
475
+ $goods[] = array(
476
+ 'goods' => array(
477
+ 'artno' => 'giftcard',
478
+ 'title' => $this->translate('Gift card', $orderLocale),
479
+ 'vat' => 0,
480
+ 'discount' => 0,
481
+ 'price' => (int)((string)(round($this->order->getGiftCardsAmount(),2)*100*-1)),
482
+ 'flags' => self::GOODSFLAG_INC_VAT
483
+ ),
484
+ 'qty' => 1
485
+ );
486
+
487
+ }
488
+
489
+ // Add store credit if present
490
+ if($this->order->getCustomerBalanceAmount() > 0) {
491
+
492
+ $goods[] = array(
493
+ 'goods' => array(
494
+ 'artno' => 'storecredit',
495
+ 'title' => $this->translate('Store credit', $orderLocale),
496
+ 'vat' => 0,
497
+ 'discount' => 0,
498
+ 'price' => (int)((string)(round($this->order->getCustomerBalanceAmount(),2)*100*-1)),
499
+ 'flags' => self::GOODSFLAG_INC_VAT
500
+ ),
501
+ 'qty' => 1
502
+ );
503
+
504
+ }
505
+
506
+ // Add reward points if present
507
+ if($this->order->getRewardCurrencyAmount() > 0) {
508
+
509
+ $goods[] = array(
510
+ 'goods' => array(
511
+ 'artno' => 'rewardpoints',
512
+ 'title' => $this->translate('Reward points', $orderLocale),
513
+ 'vat' => 0,
514
+ 'discount' => 0,
515
+ 'price' => (int)((string)(round($this->order->getRewardCurrencyAmount(),2)*100*-1)),
516
+ 'flags' => self::GOODSFLAG_INC_VAT
517
+ ),
518
+ 'qty' => 1
519
+ );
520
+
521
+ }
522
+
523
+ return $goods;
524
+ }
525
+
526
+ function get_shipmentfee()
527
+ {
528
+ // Deprecated in Klarna API
529
+ return 0;
530
+ }
531
+
532
+ function get_shipmenttype()
533
+ {
534
+ return Klarna_KlarnaPaymentModule_Helper_Api::KREDITOR_SHIPMENT_NORMAL;
535
+ }
536
+
537
+ function get_handlingfee()
538
+ {
539
+ // Deprecated in Klarna API
540
+ return 0;
541
+ }
542
+
543
+ function get_personalnumber_from_order()
544
+ {
545
+ $info = $this->order->getPayment()->getMethodInstance()->getInfoInstance();
546
+ return $info->getAdditionalInformation('klarna_personalnumber');
547
+ }
548
+
549
+ function get_personalnumber()
550
+ {
551
+ if(in_array($this->get_address_country(), Mage::helper('klarnaPaymentModule')->getCustomPersonalNumberCountries())) {
552
+ $date = new DateTime();
553
+ $date->setDate($this->field_data['dob_year'], $this->field_data['dob_month'], $this->field_data['dob_day']);
554
+
555
+ if($this->field_data['gender'] == 'male') {
556
+ $gender = '1';
557
+ }
558
+ else {
559
+ $gender = '0';
560
+ }
561
+
562
+ $personalnumber = $date->format('dmY') . $gender;
563
+
564
+ return $personalnumber;
565
+ }
566
+ else {
567
+ return str_replace(' ', '', $this->field_data['personalnumber']);
568
+ }
569
+ }
570
+
571
+ function get_fname()
572
+ {
573
+ return $this->get_shipping_address()->getFirstname();
574
+ }
575
+
576
+ function get_lname()
577
+ {
578
+ return $this->get_shipping_address()->getLastname();
579
+ }
580
+
581
+ function get_address_street($type = 'billing')
582
+ {
583
+ if($type == 'billing') {
584
+ $address = $this->get_billing_address();
585
+ }
586
+ else {
587
+ $address = $this->get_shipping_address();
588
+
589
+ $helper = Mage::helper('klarnaPaymentModule');
590
+ $fields = $helper->getCountrySpecificFields($this->order);
591
+
592
+ if(in_array('street', $fields)) {
593
+ return $this->get_street();
594
+ }
595
+ }
596
+
597
+ $street = $address->getStreet();
598
+ return implode(', ', $street);
599
+ }
600
+
601
+ function get_street()
602
+ {
603
+ if(isset($this->field_data['street'])) {
604
+ return $this->field_data['street'];
605
+ }
606
+ return '';
607
+ }
608
+
609
+
610
+ function get_housenumber()
611
+ {
612
+ if(isset($this->field_data['house_number'])) {
613
+ return $this->field_data['house_number'];
614
+ }
615
+
616
+ if($this->order) {
617
+ $info = $this->order->getPayment()->getMethodInstance()->getInfoInstance();
618
+ $housenumber = $info->getAdditionalInformation('klarna_house_number');
619
+ if($housenumber) {
620
+ return $info->getAdditionalInformation('klarna_house_number');
621
+ }
622
+ }
623
+
624
+ return '';
625
+ }
626
+
627
+ function get_houseextension()
628
+ {
629
+ if(isset($this->field_data['house_extension'])) {
630
+ return $this->field_data['house_extension'];
631
+ }
632
+ return '';
633
+ }
634
+
635
+ function get_postcode($type)
636
+ {
637
+ if($type == 'billing') {
638
+ $address = $this->get_billing_address();
639
+ }
640
+ else {
641
+ $address = $this->get_shipping_address();
642
+ }
643
+
644
+ if($address->getCountry() == 'NL') {
645
+ return $address->getPostcode();
646
+ }
647
+
648
+ if($this->integration_mode == 'standard') {
649
+ // Need to send postcode as integer in standard mode
650
+ return (int)$address->getPostcode();
651
+ }
652
+
653
+ return $address->getPostcode();
654
+ }
655
+
656
+ function get_housenumber_from_street($street)
657
+ {
658
+ $street_split = explode(' ', $street);
659
+ return $street_split[count($street_split)-1];
660
+ }
661
+
662
+ function get_advanced_address($type = 'shipping')
663
+ {
664
+
665
+ $address_country = $this->get_address_country($type);
666
+
667
+ if($type == 'billing') {
668
+ $address = $this->get_billing_address();
669
+ }
670
+ else {
671
+ $address = $this->get_shipping_address();
672
+ }
673
+
674
+ $country = $this->getCountrySettings($address_country);
675
+
676
+ if($type == 'shipping') {
677
+ $housenumber = $this->get_housenumber();
678
+ $houseextension = $this->get_houseextension();
679
+ }
680
+ else {
681
+ $housenumber = '';
682
+ $houseextension = '';
683
+
684
+ if(in_array($address->getCountry(), array('NL', 'DE'))) {
685
+ if($type == 'shipping')
686
+ $housenumber = $this->get_housenumber_from_street($this->get_address_street($type));
687
+ }
688
+ }
689
+ if($address->getCompany() == '') {
690
+
691
+ $data = array(
692
+ 'fname' => $address->getFirstname(),
693
+ 'lname' => $address->getLastname(),
694
+ 'street' => $this->get_address_street($type),
695
+ 'zip' => $this->get_postcode($type),
696
+ 'city' => $address->getCity(),
697
+ 'country' => strtolower($address->getCountry()),
698
+ 'house_number' => $housenumber != '' ? $housenumber : ' ',
699
+ 'house_extension' => $houseextension
700
+ );
701
+
702
+
703
+
704
+ } else {
705
+ $data = array(
706
+ 'fname' => '',
707
+ 'lname' => $address->getCompany(),
708
+ 'street' => $this->get_address_street($type),
709
+ 'zip' => $this->get_postcode($type),
710
+ 'city' => $address->getCity(),
711
+ 'country' => strtolower($address->getCountry()),
712
+ 'house_number' => $housenumber,
713
+ 'house_extension' => $houseextension
714
+ );
715
+ }
716
+
717
+ return $data;
718
+ }
719
+
720
+ function get_address($type = 'shipping')
721
+ {
722
+ if($type == 'billing') {
723
+ $address = $this->get_billing_address();
724
+ }
725
+ else {
726
+ $address = $this->get_shipping_address();
727
+ }
728
+
729
+ $country = $this->getCountrySettings($this->get_address_country($type));
730
+ $data = array(
731
+ 'careof' => '',
732
+ 'street' => $this->get_address_street($type),
733
+ 'postno' => $this->get_postcode($type),
734
+ 'city' => $address->getCity(),
735
+ 'country' => $country['country'],
736
+ 'telno' => $this->get_phonenumber(),
737
+ 'cellno' => $this->get_phonenumber(),
738
+ 'email' => $this->order->getCustomerEmail(),
739
+ 'house_number' => $this->get_housenumber(),
740
+ 'house_extension' => $this->get_houseextension()
741
+ );
742
+
743
+ return $data;
744
+ }
745
+
746
+ function get_password()
747
+ {
748
+ return '';
749
+ }
750
+
751
+ function get_clientip()
752
+ {
753
+ return $_SERVER['REMOTE_ADDR'];
754
+ }
755
+
756
+ function get_flags()
757
+ {
758
+ // Add alternate credit time if we have a company
759
+ $flag = 0;
760
+ if($this->get_shipping_address()->getCompany() != '')
761
+ $flag += 65536;
762
+
763
+ return $this->test_flag+$flag;
764
+ }
765
+
766
+ function get_comment()
767
+ {
768
+ return '';
769
+ }
770
+
771
+ function get_readydate()
772
+ {
773
+ return '';
774
+ }
775
+
776
+ function get_rand_string()
777
+ {
778
+ return '';
779
+ }
780
+
781
+ function get_pclass()
782
+ {
783
+ $info = $this->order->getPayment()->getMethodInstance()->getInfoInstance();
784
+ return (int)$info->getAdditionalInformation('klarna_pclass');
785
+ }
786
+
787
+ function get_salary()
788
+ {
789
+ $info = $this->order->getPayment()->getMethodInstance()->getInfoInstance();
790
+ return $info->getAdditionalInformation('klarna_yearlysalary') > 0 ? (int)$info->getAdditionalInformation('klarna_yearlysalary')*100 : (int)0;
791
+ }
792
+
793
+ function get_currency()
794
+ {
795
+ $country = $this->get_address_country();
796
+ $settings = $this->getCountrySettings($country);
797
+ return $settings['currency'];
798
+ }
799
+
800
+ function get_language()
801
+ {
802
+ $country = $this->get_address_country();
803
+ $settings = $this->getCountrySettings($country);
804
+ return $settings['language'];
805
+ }
806
+
807
+ function get_country()
808
+ {
809
+ $country = $this->get_address_country();
810
+ $settings = $this->getCountrySettings($country);
811
+ return $settings['country'];
812
+ }
813
+
814
+ function get_pn_encoding()
815
+ {
816
+ $country = $this->get_address_country();
817
+ $settings = $this->getCountrySettings($country);
818
+ return $settings['pno_encoding'];
819
+ }
820
+
821
+ function get_shipping_address()
822
+ {
823
+ return $this->order->getShippingAddress();
824
+ }
825
+
826
+ function get_billing_address()
827
+ {
828
+ return $this->order->getBillingAddress();
829
+ }
830
+
831
+
832
+ function get_address_country($type = 'shipping')
833
+ {
834
+ if($type == 'billing') {
835
+ $address = $this->get_billing_address();
836
+ }
837
+ else {
838
+ $address = $this->get_shipping_address();
839
+ }
840
+
841
+ return $address->getCountry();
842
+ }
843
+
844
+ function get_ordernumber()
845
+ {
846
+ return $this->order->getIncrementId();
847
+ }
848
+
849
+ function get_invoice_secret($invoice_id)
850
+ {
851
+ return $this->md5_base64($this->merchantid . ':' . $invoice_id . ':' . $this->secret);
852
+ }
853
+
854
+
855
+ function activate_invoice($invoice_id)
856
+ {
857
+ $params = array(
858
+ $this->merchantid,
859
+ $invoice_id,
860
+ $this->get_invoice_secret($invoice_id),
861
+ );
862
+
863
+ $result = false;
864
+ $status = kred_call("activate_invoice", $this->decode_data($params), $result, $this->merchantid, $this->secret);
865
+
866
+ if($status == 0) {
867
+ // check to see if we should send the invoice by mail
868
+ $usemailflag = Mage::getStoreConfig('payment/' . $this->paymentmethod . '/send_by_email');
869
+ if($usemailflag) {
870
+ $email_result = "";
871
+ email_invoice($this->merchantid, $invoice_id, $this->secret, $email_result, $this->merchantid, $this->secret);
872
+ }
873
+ return array(
874
+ 'status' => 'success',
875
+ 'invoice_id' => utf8_encode($result)
876
+ );
877
+ } else
878
+ {
879
+ return array(
880
+ 'status' => 'error',
881
+ 'error' => utf8_encode($result)
882
+ );
883
+ }
884
+ }
885
+
886
+ function get_amount()
887
+ {
888
+ return (int)(round($this->order->getGrandTotal(),2)*100);
889
+ }
890
+
891
+ function get_reference()
892
+ {
893
+ if($this->integration_mode == 'advanced') {
894
+ $address = $this->get_shipping_address();
895
+ if($address->getCompany() != '') {
896
+ return $address->getFirstname() . ' ' . $address->getLastname();
897
+ }
898
+ }
899
+
900
+ return '';
901
+ }
902
+
903
+ function get_reference_code()
904
+ {
905
+ return '';
906
+ }
907
+
908
+ function get_advanced_reserve_flags()
909
+ {
910
+ $usemailflag = 0;
911
+ $flag = 0;
912
+ if($this->integration_mode == 'advanced') {
913
+ $usemailflag = Mage::getStoreConfig('payment/' . $this->paymentmethod . '/send_by_email');
914
+ $flag = ($usemailflag == 1 ? 8 : 0);
915
+ }
916
+
917
+ // Add alternate credit time if we have a company
918
+ if($this->get_shipping_address()->getCompany() != '')
919
+ $flag += 128;
920
+
921
+ return $this->test_flag+$flag+16;
922
+ }
923
+
924
+ function get_reserve_amount_secret($personalnumber, $amount)
925
+ {
926
+ $string = $this->merchantid . ':' . $personalnumber . ':'. $amount . ':' . $this->secret;
927
+ return $this->md5_base64($string);
928
+ }
929
+
930
+ function get_activate_amount_secret($personalnumber, $goods)
931
+ {
932
+ $string = $this->merchantid . ':' . $personalnumber . ':';
933
+ foreach($goods as $item) {
934
+ $string .= $item['goods']['artno'] . ':' . $item['qty'] . ':';
935
+ }
936
+
937
+ return $this->md5_base64(utf8_decode($string . $this->secret));
938
+ }
939
+
940
+ function get_phonenumber()
941
+ {
942
+ return $this->field_data['phonenumber'];
943
+ }
944
+
945
+ function get_phonenumber_from_order()
946
+ {
947
+ $info = $this->order->getPayment()->getMethodInstance()->getInfoInstance();
948
+ return $info->getAdditionalInformation('klarna_phonenumber');
949
+ }
950
+
951
+ function activate_reservation($reservation_id, $items = null, $addinvoice = null)
952
+ {
953
+ $params_new = array(
954
+ $reservation_id, // rno
955
+ $this->get_personalnumber_from_order(), // pno
956
+ '', // ocr
957
+ $this->get_goods_list($items, $addinvoice), // goodsList
958
+ $this->get_reference(), // reference
959
+ $this->get_reference_code(), // reference_code
960
+ $this->get_ordernumber(), // orderid1
961
+ '', // Order id #2 // orderid2
962
+ $this->get_advanced_address('shipping'), // lev_addr
963
+ $this->get_advanced_address('billing'), // f_addr
964
+ $this->get_shipmenttype(), // shipmenttype
965
+ $this->order->getCustomerEmail(), // email
966
+ $this->get_phonenumber_from_order(), // phone
967
+ $this->get_phonenumber_from_order(), // cell
968
+ $this->get_clientip(), //clipent_ip
969
+ $this->get_advanced_reserve_flags(),
970
+ $this->get_currency(),
971
+ $this->get_country(),
972
+ $this->get_language(),
973
+ $this->merchantid,
974
+ $this->get_activate_amount_secret($this->get_personalnumber_from_order(), $this->get_goods_list($items, $addinvoice)),
975
+ $this->get_pn_encoding(),
976
+ $this->get_pclass(),
977
+ $this->get_salary(),
978
+ '', // pin
979
+ );
980
+
981
+ $params_new = $this->decode_data($params_new);
982
+
983
+ $result = false;
984
+ $status = kred_call("activate_reservation", $params_new, $result, $this->merchantid, $this->secret);
985
+
986
+ if($status == 0) {
987
+ return array(
988
+ 'status' => 'success',
989
+ 'id' => utf8_encode($result[1])
990
+ );
991
+ } else
992
+ {
993
+ return array(
994
+ 'status' => 'error',
995
+ 'error' => utf8_encode($result)
996
+ );
997
+ }
998
+
999
+
1000
+ }
1001
+
1002
+ function reserve_amount()
1003
+ {
1004
+ $params_new = array(
1005
+ $this->get_personalnumber(),
1006
+ $this->get_amount(),
1007
+ $this->get_reference(),
1008
+ $this->get_reference_code(),
1009
+ $this->get_ordernumber(),
1010
+ '', // Order id #2
1011
+ $this->get_advanced_address('shipping'),
1012
+ $this->get_advanced_address('billing'),
1013
+ $this->order->getCustomerEmail(),
1014
+ $this->get_phonenumber(),
1015
+ $this->get_phonenumber(),
1016
+ $this->get_clientip(),
1017
+ $this->get_advanced_reserve_flags(),
1018
+ $this->get_currency(),
1019
+ $this->get_country(),
1020
+ $this->get_language(),
1021
+ $this->merchantid,
1022
+ $this->get_reserve_amount_secret($this->get_personalnumber(), $this->get_amount()),
1023
+ $this->get_pn_encoding(),
1024
+ $this->get_pclass(),
1025
+ $this->get_salary(),
1026
+ $this->get_goods_list(),
1027
+ );
1028
+
1029
+ $result = false;
1030
+ $status = kred_call("reserve_amount", $this->decode_data($params_new), $result, $this->merchantid, $this->secret);
1031
+
1032
+ if($status == 0) {
1033
+ return array(
1034
+ 'status' => 'success',
1035
+ 'reservation_id' => utf8_encode($result)
1036
+ );
1037
+ } else
1038
+ {
1039
+ return array(
1040
+ 'status' => 'error',
1041
+ 'error' => utf8_encode($result)
1042
+ );
1043
+ }
1044
+ }
1045
+
1046
+
1047
+ function add_invoice()
1048
+ {
1049
+
1050
+ $params_new = array(
1051
+ $this->merchantid,
1052
+ '',
1053
+ $this->get_goods_secret(),
1054
+ $this->get_ordernumber(),
1055
+ $this->get_goods_list(), // goods list
1056
+ $this->get_shipmentfee(),
1057
+ $this->get_shipmenttype(),
1058
+ $this->get_handlingfee(),
1059
+ $this->get_personalnumber(),
1060
+ $this->get_fname(),
1061
+ $this->get_lname(),
1062
+ $this->get_address(),
1063
+ $this->get_password(),
1064
+ $this->get_clientip(),
1065
+ $this->get_password(),
1066
+ $this->get_flags(),
1067
+ $this->get_comment(),
1068
+ $this->get_readydate(),
1069
+ $this->get_rand_string(),
1070
+ $this->get_currency(),
1071
+ $this->get_country(),
1072
+ $this->get_language(),
1073
+ $this->get_pn_encoding(),
1074
+ $this->get_pclass(),
1075
+ $this->get_salary()
1076
+ );
1077
+
1078
+ $result = false;
1079
+ $status = kred_call("add_invoice", $this->decode_data($params_new), $result, $this->merchantid, $this->secret);
1080
+ if($status == 0) {
1081
+
1082
+ return array(
1083
+ 'status' => 'success',
1084
+ 'invoice_id' => utf8_encode($result)
1085
+ );
1086
+ } else
1087
+ {
1088
+ return array(
1089
+ 'status' => 'error',
1090
+ 'error' => utf8_encode($result)
1091
+ );
1092
+ }
1093
+
1094
+ }
1095
+
1096
+ function get_addresses($pno)
1097
+ {
1098
+ $params_new = array(
1099
+ $pno,
1100
+ $this->merchantid,
1101
+ $this->md5_base64($this->merchantid . ":" . $pno . ":" . $this->secret),
1102
+ 2,
1103
+ 1);
1104
+
1105
+ $result = false;
1106
+ $status = kred_call("get_addresses", $this->decode_data($params_new), $result, $this->merchantid, $this->secret);
1107
+
1108
+ if($status == 0) {
1109
+ return array(
1110
+ 'status' => 'success',
1111
+ 'addresses' => $result
1112
+ );
1113
+ } else
1114
+ {
1115
+ return array(
1116
+ 'status' => 'error',
1117
+ 'error' => utf8_encode($result)
1118
+ );
1119
+ }
1120
+ }
1121
+
1122
+ public function magentoCountryToKlarnaCountry($country) {
1123
+ $settings = $this->getCountrySettings($country);
1124
+ return $settings['country'];
1125
+ }
1126
+
1127
+ public function fetchPclasses($eid, $secret) {
1128
+ $countries = array("SE", "NO", "DK", "FI", "DE", "NL");
1129
+ $pclasses = array();
1130
+ foreach($countries as $c) {
1131
+ $pclasses[] = $this->getPclassesByCountry($c, $eid, $secret);
1132
+ }
1133
+ return $pclasses;
1134
+ }
1135
+
1136
+ public function getPclassesByCountry($country, $eid, $secret) {
1137
+ $settings = $this->getCountrySettings($country);
1138
+ $digest = $this->md5_base64((int)$eid . ":" . $settings['currency'] . ":" . $secret);
1139
+
1140
+ $result = false;
1141
+ $status = kred_call("get_pclasses", $this->decode_data(array((int)$eid, $settings['currency'], $digest, $settings['country'], $settings['language'])), $result, $this->merchantid, $this->secret);
1142
+
1143
+ if($status == 0) {
1144
+ return array(
1145
+ 'status' => 'success',
1146
+ 'pclasses' => $result
1147
+ );
1148
+ } else
1149
+ {
1150
+ return array(
1151
+ 'status' => 'error',
1152
+ 'error' => utf8_encode($result)
1153
+ );
1154
+ }
1155
+ }
1156
+
1157
+
1158
+
1159
+ public function decode_data($input) {
1160
+ if(is_array($input)) {
1161
+ foreach($input as $key => $data) {
1162
+ $decoded_array[$key] = $this->decode_data($data);
1163
+ }
1164
+ } elseif(is_string($input)) {
1165
+ if(mb_detect_encoding($input . 'a', 'UTF-8, ISO-8859-1') == 'UTF-8') {
1166
+ return utf8_decode($input);
1167
+ }
1168
+ else {
1169
+ return $input;
1170
+ }
1171
+ } else
1172
+ return $input;
1173
+
1174
+ return $decoded_array;
1175
+ }
1176
+
1177
+ private function translate($string, $locale) {
1178
+ $translate = Mage::getSingleton('core/translate');
1179
+ $translate->setLocale($locale);
1180
+ $translate->init("frontend", true);
1181
+ return $translate->translate(array(new Mage_Core_Model_Translate_Expr($string, 'Klarna')));
1182
+ }
1183
+
1184
+ private function getTaxRate($product) {
1185
+ // Load the customer so we can retrevice the correct tax class id
1186
+ $customer = Mage::getModel('customer/customer')->load($this->order->getCustomerId());
1187
+ $request = Mage::getSingleton('tax/calculation')->getRateRequest($this->order->getShippingAddress(), $this->order->getBillingAddress(), $customer->getTaxClassId(), Mage::app()->getStore($this->order->getStoreId()));
1188
+ $taxrate = Mage::getSingleton('tax/calculation')->getRate($request->setProductClassId($product->getTaxClassId()));
1189
+
1190
+ return $taxrate;
1191
+ }
1192
+
1193
+ /**
1194
+ * Returns the tax rate for the shipping
1195
+ *
1196
+ * @return <string> The shipping tax rate
1197
+ */
1198
+ private function getShippingTaxRate() {
1199
+
1200
+ // Load the customer so we can retrevice the correct tax class id
1201
+ $customer = Mage::getModel('customer/customer')->load($this->order->getCustomerId());
1202
+ $shipping_tax_class = Mage::getStoreConfig('tax/classes/shipping_tax_class');
1203
+ $calculation = Mage::getSingleton('tax/calculation');
1204
+ $request = $calculation->getRateRequest($this->order->getShippingAddress(), $this->order->getBillingAddress(), $customer->getTaxClassId(), Mage::app()->getStore($this->order->getStoreId()));
1205
+ $taxrate = $calculation->getRate($request->setProductClassId($shipping_tax_class));
1206
+
1207
+ return $taxrate;
1208
+ }
1209
+
1210
+
1211
+
1212
+
1213
+ }
1214
+
app/code/community/Klarna/KlarnaPaymentModule/Helper/Calc/Klarna.php ADDED
@@ -0,0 +1,477 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ * Copyright 2010 KLARNA AB. All rights reserved.
4
+ *
5
+ * Redistribution and use in source and binary forms, with or without modification, are
6
+ * permitted provided that the following conditions are met:
7
+ *
8
+ * 1. Redistributions of source code must retain the above copyright notice, this list of
9
+ * conditions and the following disclaimer.
10
+ *
11
+ * 2. Redistributions in binary form must reproduce the above copyright notice, this list
12
+ * of conditions and the following disclaimer in the documentation and/or other materials
13
+ * provided with the distribution.
14
+ *
15
+ * THIS SOFTWARE IS PROVIDED BY KLARNA AB "AS IS" AND ANY EXPRESS OR IMPLIED
16
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
17
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL KLARNA AB OR
18
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
19
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
20
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
21
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
22
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
23
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24
+ *
25
+ * The views and conclusions contained in the software and documentation are those of the
26
+ * authors and should not be interpreted as representing official policies, either expressed
27
+ * or implied, of KLARNA AB.
28
+ *
29
+ */
30
+
31
+ class Klarna_KlarnaPaymentModule_Helper_Calc_Klarna extends Mage_Core_Helper_Abstract
32
+ {
33
+
34
+ const KRED_LIMIT_COST = 0;
35
+ const KRED_ACTUAL_COST = 1;
36
+
37
+ const KRED_ANNUITY_PCLASS = 0;
38
+ const KRED_DIVISOR_PCLASS = 1;
39
+ const KRED_FIXED_PCLASS = 3;
40
+
41
+ // This constant tells the irr function when to stop.
42
+ // If the calculation error is lower than this the calculation is done.
43
+ //protected $accuracy = 0.01; //use this if 100.00 SEK is 100.00
44
+ protected $accuracy = 0.01; //use this if 100.00 SEK is 10000 (counting öres)
45
+ /**
46
+ *
47
+ * @param <int> $sum The sum for the order/product in ören/cents
48
+ * @param <array> $pclass
49
+ * @param <int> $flags Indicates if it is the checkout or a product page
50
+ * @param <int> $currency The Klarna currency
51
+ * @return <int> The monthly cost in ören/cents
52
+ */
53
+ public function calc_monthly_cost($sum, $pclass,
54
+ $flags, $country){
55
+
56
+
57
+ $months = $pclass['months'];
58
+ $monthsfee = ($flags == 0 ? $pclass['handlingfee'] : 0);
59
+ $type = $pclass['type'];
60
+ $rate = $pclass['interest']/100;
61
+ $startfee = ($flags == 0 ? $pclass['startfee'] : 0);
62
+ $sum += $startfee; //include start fee in sum
63
+ $account = ($pclass['type'] == 1);
64
+ $minamount = ($flags == 0 ? ($type == 1 ? self::get_lowest_payment_for_account($country) : 0) : 0);
65
+ $payment = self::annuity ($sum, $months, $rate)+$monthsfee; //add monthly fee
66
+ $payarr = self::fulpacc($sum, $rate, $monthsfee, $minamount, $payment, $months, $account);
67
+
68
+ return isset($payarr[0]) ? $payarr[0] : 0;
69
+
70
+ }
71
+
72
+ /**
73
+ * Returns the lowest monthly payment for Klarna Account.
74
+ *
75
+ * @param int $country
76
+ * @return int
77
+ */
78
+ public static function get_lowest_payment_for_account($country) {
79
+ switch ($country) {
80
+ case 209:
81
+ $lowest_monthly_payment = 5000.00; //Sweden
82
+ break;
83
+ case 164:
84
+ $lowest_monthly_payment = 9500.00; //Norway
85
+ break;
86
+ case 73:
87
+ $lowest_monthly_payment = 895.00; //Finland
88
+ break;
89
+ case 59:
90
+ $lowest_monthly_payment = 8900.00; //Denmark
91
+ break;
92
+ case 81: //Germany
93
+ case 154:
94
+ $lowest_monthly_payment = 695.00; //Netherlands
95
+ break;
96
+ default:
97
+ return -2;
98
+ }
99
+
100
+ return $lowest_monthly_payment;
101
+ }
102
+
103
+ function monthly_cost($sum, $rate, $months, $monthsfee, $flags, $country)
104
+ {
105
+
106
+ if($rate < 100)
107
+ $rate = $rate*100;
108
+
109
+ switch ($country) {
110
+ case 209:
111
+ $lowest_monthly_payment = 5000.00;
112
+ $currency = 0;
113
+ break;
114
+ case 164:
115
+ $lowest_monthly_payment = 9500.00;
116
+ $currency = 1;
117
+ break;
118
+ case 73:
119
+ $lowest_monthly_payment = 895.00;
120
+ $currency = 2;
121
+ break;
122
+ case 59:
123
+ $lowest_monthly_payment = 8900.00;
124
+ $currency = 3;
125
+ break;
126
+ case 81:
127
+ $lowest_monthly_payment = 695.00;
128
+ $currency = 2;
129
+ break;
130
+ case 154:
131
+ $lowest_monthly_payment = 500.00;
132
+ $currency = 2;
133
+ break;
134
+ default:
135
+ return -2;
136
+ }
137
+
138
+ $average_interest_period = 45;
139
+ $calcRate = ($rate / 10000);
140
+
141
+ $interest_value = ($average_interest_period / 365.0) * $calcRate * $sum;
142
+ $periodic_cost = ($sum + $interest_value)/$months;
143
+
144
+ if ($flags == 1)
145
+ {
146
+ return $this->round_up($periodic_cost, $currency);
147
+ }
148
+ else if ($flags == 0)
149
+ {
150
+ $periodic_cost = $periodic_cost + $monthsfee;
151
+ if ($periodic_cost < $lowest_monthly_payment)
152
+ return round($lowest_monthly_payment, 0);
153
+ else
154
+ return $this->round_up($periodic_cost, $currency);
155
+ }
156
+ else
157
+ return -2;
158
+
159
+ return 0;
160
+ }
161
+
162
+ /*************************************************************************
163
+ * API: monthly_cost_new2
164
+ *************************************************************************/
165
+ function monthly_cost_new2($sum, $rate, $months, $monthsfee, $startfee, $flags, $country, $type){
166
+
167
+ if($type == self::KRED_ANNUITY_PCLASS){
168
+ return $this->periodic_cost_new($sum, $months, $monthsfee, $rate, $startfee, $country, $flags);
169
+ }else if($type == self::KRED_DIVISOR_PCLASS){
170
+ return $this->monthly_cost($sum, $rate, $months, $monthsfee, $flags, $country);
171
+ }else if($type == self::KRED_FIXED_PCLASS){
172
+ return fixed_month_cost($sum, $pclass, $monthsfee, $flags);
173
+ }
174
+
175
+ return -1;
176
+ }
177
+
178
+ function fixed_month_cost($sum, $pclass, $monthsfee, $flags){
179
+
180
+ $fixed_cost = $pclass['months'];
181
+ $min_sum = $pclass['minamount'];
182
+ $max_sum = $pclass['maxamount'];
183
+ if (($sum >= $min_sum) && ($sum <= $max_sum)){
184
+ return (int)($fixed_cost + $monthsfee + 0.5);
185
+ } else {
186
+ return -1;
187
+ }
188
+ }
189
+
190
+ /*************************************************************************
191
+ * API: periodic_cost
192
+ *************************************************************************/
193
+ function periodic_cost_new($sum, $months, $monthfee, $rate, $startfee, $currency, $flags){
194
+
195
+ if($flags == self::KRED_ACTUAL_COST){
196
+ $credit_cost = $this->total_credit_purchase_cost($sum, $rate/100, 0, 0, $months, 0);
197
+ }else if($flags == self::KRED_LIMIT_COST){
198
+ $credit_cost = $this->total_credit_purchase_cost($sum, $rate/100, $monthfee, 0, $months, $startfee);
199
+ }else {
200
+ $result = -2;
201
+ }
202
+
203
+ return (int)($credit_cost/$months);
204
+ }
205
+
206
+ function calc_monthpayment($sum, $dailyrate, $months){
207
+ $dates = 0;
208
+ $totdates = (($months - 1) * 30);
209
+ $denom = $this->calc_denom($dailyrate, $totdates);
210
+ $totdates = $totdates + 60;
211
+ return ((pow($dailyrate, $totdates) * $sum) / $denom);
212
+ }
213
+
214
+ function round_up($value, $curr)
215
+ {
216
+ $result;
217
+ $divisor;
218
+
219
+ if ($curr == 2)
220
+ $divisor = 10;
221
+ else
222
+ $divisor = 100;
223
+
224
+ $result = $divisor * round((($divisor/2)+$value)/$divisor); //We want to roundup to closest integer.
225
+
226
+ return $result;
227
+ }
228
+
229
+ function calc_denom($dailyrate, $totdates){
230
+ $sum = 1;
231
+ $startdates = 0;
232
+ while ($totdates > $startdates){
233
+ $startdates = $startdates + 30;
234
+ $sum = ($sum + pow($dailyrate, $startdates));
235
+ }
236
+ return $sum;
237
+ }
238
+
239
+ function daily_rate($rate){
240
+ return pow((($rate / 10000) + 1), (1 / 365.25));
241
+ }
242
+
243
+ function midpoint ($a, $b)
244
+ {
245
+ return (($a+$b)/2);
246
+ }
247
+
248
+ function npv ($pval, $payarray, $rate, $fromdayone)
249
+ {
250
+ $month = $fromdayone;
251
+ foreach ($payarray as $payment)
252
+ {
253
+ $pval -= $payment / pow (1 + $rate/(12*100.0), $month++);
254
+ }
255
+ return ($pval);
256
+ }
257
+
258
+ function irr ($pval, $payarray, $fromdayone)
259
+ {
260
+
261
+
262
+ $low = 0.0;
263
+ $high = 100.0;
264
+ $lowval = $this->npv ($pval, $payarray, $low, $fromdayone);
265
+ $highval = $this->npv ($pval, $payarray, $high, $fromdayone);
266
+
267
+ // The sum of $payarray is smaller than $pval, impossible!
268
+ if ($lowval > 0.0)
269
+ {
270
+ return (-1);
271
+ }
272
+
273
+ // Standard divide and conquer.
274
+ do
275
+ {
276
+ $mid = $this->midpoint ($low, $high);
277
+ $midval = $this->npv ($pval, $payarray, $mid, $fromdayone);
278
+ if (abs($midval) < $this->accuracy)
279
+ {
280
+ //we are close enough
281
+ return ($mid);
282
+ }
283
+
284
+ if ($highval < 0.0)
285
+ {
286
+ // we are not in range, so double it
287
+ $low = $high;
288
+ $lowval = $highval;
289
+ $high *= 2;
290
+ $highval = $this->npv ($pval, $payarray,
291
+ $high, $fromdayone);
292
+ } elseif ($midval >= 0.0)
293
+ {
294
+ // irr is between low and mid
295
+ $high = $mid;
296
+ $highval = $midval;
297
+ } else
298
+ {
299
+ // irr is between mid and high
300
+ $low = $mid;
301
+ $lowval = $midval;
302
+ }
303
+ } while ($high < 1000000);
304
+ // bad input, insanely high interest. APR will be INSANER!
305
+ return (-2);
306
+ }
307
+
308
+ function irr2apr ($irr)
309
+ {
310
+ return (100 * (pow (1 + $irr / (12 * 100.0), 12) - 1));
311
+ }
312
+
313
+ /**
314
+ *
315
+ * @param <type> $pval The sum to lend
316
+ * @param <type> $rate The interest rate
317
+ * @param <type> $fee The monthly fee
318
+ * @param <type> $minpay Minimum amount to pay
319
+ * @param <type> $payment The monthly payment
320
+ * @param int $months Number of months
321
+ * @param <type> $base If it is a base account
322
+ * @return <array>
323
+ */
324
+ function fulpacc ($pval, $rate, $fee, $minpay, $payment, $months, $base = false)
325
+ {
326
+
327
+ $bal = $pval;
328
+ $payarray = array ();
329
+ while ( $months != 0 and $bal > $this->accuracy)
330
+ {
331
+
332
+ $interest = $bal * $rate / (100.0 * 12);
333
+ $newbal = $bal + $interest + $fee;
334
+
335
+
336
+ if ($minpay >= $newbal || $payment >= $newbal)
337
+ {
338
+
339
+ $payarray[] = $newbal;
340
+
341
+
342
+ return $payarray;
343
+ }
344
+
345
+ $newpay = max ($payment,
346
+ $minpay);
347
+ if ($base)
348
+ {
349
+ $newpay = max ($newpay,
350
+ $bal/24.0 + $fee + $interest);
351
+ }
352
+
353
+ $bal = $newbal - $newpay;
354
+ $payarray[] = $newpay;
355
+ $months -= 1;
356
+ }
357
+
358
+ return $payarray;
359
+ }
360
+
361
+ function annuity ($pval, $months, $rate)
362
+ {
363
+ if($months <= 0)
364
+ return $pval;
365
+ if($rate <= 0)
366
+ return $pval/$months;
367
+ $p = $rate / (100.0*12);
368
+ return $pval * $p / (1 - pow((1+$p), -$months));
369
+ }
370
+
371
+ function fixed ($pval, $monthly, $rate, $fromdayone)
372
+ {
373
+ $p = $rate / (100.0*12);
374
+ $f = 1 + $p;
375
+ if ($fromdayone == 0)
376
+ {
377
+ if ( $f < $pval * $p / $monthly )
378
+ {
379
+ return -1;
380
+ }
381
+ // this might be wrong. check it.
382
+ return 1 - log($f - $pval * $p / $monthly) /
383
+ log($f);
384
+ } elseif ($fromdayone == 1)
385
+ {
386
+ if (1.0 < $pval * $p / $monthly )
387
+ {
388
+ return -1;
389
+ }
390
+ return -log(1.0 - $pval * $p / $monthly) /
391
+ log($f);
392
+ } else
393
+ {
394
+ return -2;
395
+ }
396
+ }
397
+
398
+ public function calc_apr($pval, $months, $rate, $fee, $minpay, $type, $free = 0) {
399
+ switch($type) {
400
+ case 0:
401
+ case 1:
402
+ return $this->apr_annuity($pval, $months, $rate, $fee, $minpay);
403
+ break;
404
+ case 2:
405
+ return $this->apr_payin_X_months($pval, $payment, $rate, $fee, $minpay, $free);
406
+ break;
407
+ case 3:
408
+ return $this->apr_fixed($pval, $payment, $rate, $fee, $minpay);
409
+ break;
410
+ }
411
+ }
412
+
413
+ public function total_credit_purchase_cost($pval, $rate, $fee, $minpay, $months, $startfee, $base = false) {
414
+
415
+
416
+ $credit_cost = 0.0;
417
+ $payment = $this->annuity ($pval, $months, $rate) + $fee;
418
+ $payarr = $this->fulpacc($pval, $rate, $fee, $minpay, $payment, $months, $base);
419
+
420
+ foreach($payarr as $pay) {
421
+ $credit_cost += $pay;
422
+ }
423
+
424
+ return ($credit_cost)+$startfee;
425
+ }
426
+
427
+ function apr_annuity ($pval, $months, $rate, $fee, $minpay)
428
+ {
429
+ $payment = $this->annuity ($pval, $months, $rate) + $fee;
430
+ if($payment < 0) { return $payment; }
431
+
432
+ $payarray = $this->fulpacc ($pval, $rate, $fee, $minpay, $payment, $months);
433
+ $apr = $this->irr2apr ($this->irr ($pval, $payarray, 1));
434
+ return $apr;
435
+ }
436
+
437
+ function apr_fixed ($pval, $payment, $rate, $fee, $minpay)
438
+ {
439
+ $months = fixed ($pval, $payment-$fee, $rate, 1);
440
+ if($months < 0) { return $months; }
441
+ $months = ceil ($months);
442
+
443
+ $payarray = fulpacc ($pval, $rate, $fee, $minpay, $payment, $months);
444
+ $apr = irr2apr (irr ($pval, $payarray, 1));
445
+ return $apr;
446
+ }
447
+
448
+ function apr_min ($pval, $rate, $fee, $minpay)
449
+ {
450
+ $payarray = fulpacc ($pval, $rate, $fee, $minpay, 0.0, -1);
451
+ $apr = irr2apr (irr ($pval, $payarray, 1));
452
+ return $apr;
453
+ }
454
+
455
+ //kinda untested against real life.
456
+ public function apr_payin_X_months ($pval, $payment, $rate, $fee, $minpay, $free)
457
+ {
458
+ $firstpay = $payment + $fee;
459
+ $months = fixed ($pval, $payment-$fee, $rate, 0);
460
+ if($months < 0) { return $months; }
461
+ $months = ceil ($months);
462
+
463
+ $newpval = $pval - $firstpay;
464
+ $farray = array();
465
+ while ($free--)
466
+ {
467
+ $farray[] = 0.0;
468
+ }
469
+ $pval += $fee;
470
+ $farray[] = $firstpay;
471
+ $pval -= $firstpay;
472
+ $payarray = fulpacc ($pval, $rate, $fee, $minpay, $payment, $months);
473
+ $newarray = array_merge($farray, $payarray);
474
+ $apr = irr2apr (irr ($pval, $newarray, 1));
475
+ return $apr;
476
+ }
477
+ }
app/code/community/Klarna/KlarnaPaymentModule/Helper/Data.php ADDED
@@ -0,0 +1,233 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Klarna_KlarnaPaymentModule_Helper_Data extends Mage_Core_Helper_Abstract
3
+ {
4
+ function validatePersonalNumber($pno, $country)
5
+ {
6
+ $length = strlen($pno);
7
+ if($length < 10) {
8
+ return false;
9
+ }
10
+
11
+ return true;
12
+ }
13
+
14
+ public function getCustomerCountry()
15
+ {
16
+ return $this->getQuote()->getShippingAddress()->getCountry();
17
+ }
18
+
19
+ public function getMerchantId($type, $store)
20
+ {
21
+ return $this->merchantid = (int)Mage::getStoreConfig('payment/' . $type . '/merchant_id', $store);
22
+ }
23
+
24
+ public function getCheckout()
25
+ {
26
+ return Mage::getSingleton('checkout/session');
27
+ }
28
+
29
+ public function getQuote()
30
+ {
31
+ return $this->getCheckout()->getQuote();
32
+ }
33
+
34
+ function getCustomPersonalNumberCountries()
35
+ {
36
+ return array('NL', 'DE');
37
+ }
38
+
39
+ function getFieldValue($field, $infoInstance)
40
+ {
41
+ $value = $infoInstance->getAdditionalInformation('klarna_' . $field);
42
+
43
+ if($field == 'street' || $field == 'house_number' && $value == '' || !$value) {
44
+
45
+ if($value)
46
+ return $value;
47
+ else {
48
+ try {
49
+ $address = $this->getQuote()->getShippingAddress();
50
+ $address_line = $address->getStreet();
51
+ $address_line = $address_line[0];
52
+ $street_split = explode(' ', $address_line);
53
+
54
+ if($field == 'house_number') {
55
+ if(count($street_split) > 1)
56
+ return $street_split[count($street_split)-1];
57
+ else
58
+ return '';
59
+ }
60
+ elseif($field == 'street') {
61
+ if(count($street_split) > 1)
62
+ array_pop($street_split);
63
+ return implode(' ', $street_split);
64
+ }
65
+ }
66
+ catch(Exception $e) {
67
+ // Fail silently ..
68
+ }
69
+ }
70
+ }
71
+
72
+ return $value;
73
+
74
+
75
+ return $value;
76
+ }
77
+
78
+ function getCountry()
79
+ {
80
+ $country = $this->getQuote()->getShippingAddress()->getCountry();
81
+ return $country;
82
+ }
83
+
84
+ function getCountrySpecificFields($order = null)
85
+ {
86
+ if($order)
87
+ $country = $order->getShippingAddress()->getCountryId();
88
+ else
89
+ $country = $this->getQuote()->getShippingAddress()->getCountry();
90
+
91
+ $fields = array();
92
+ $exclude_pno_countries = array('NL', 'DE');
93
+
94
+ if(!in_array($country, $exclude_pno_countries)) {
95
+ $fields[] = 'personalnumber';
96
+ if(strtolower($country) == "dk")
97
+ $fields[] = 'yearlysalary';
98
+ }
99
+ else {
100
+ $fields[] = 'gender';
101
+ $fields[] = 'dob';
102
+ $fields[] = 'street';
103
+ $fields[] = 'house_number';
104
+ }
105
+
106
+ if($country == 'NL') {
107
+ $fields[] = 'house_extension';
108
+ }
109
+
110
+ $fields[] = 'phonenumber';
111
+
112
+ return $fields;
113
+ }
114
+
115
+ function getAvailableCountries()
116
+ {
117
+ $available_countries = array(
118
+ 'NO', 'SE', 'DK', 'NL', 'DE', 'FI'
119
+ );
120
+ return $available_countries;
121
+ }
122
+
123
+ public function isCountryAllowed($country)
124
+ {
125
+ $allowed_countries = $this->getAvailableCountries();
126
+
127
+ if(in_array($country, $allowed_countries)) {
128
+ return true;
129
+ }
130
+
131
+ return false;
132
+ }
133
+
134
+ public function getTaxClass($store)
135
+ {
136
+ return (int)Mage::getStoreConfig('payment/klarna_invoice/tax_class', $store);
137
+ }
138
+
139
+ public function getInvoiceFeeByCountry($country, $store = null)
140
+ {
141
+ $invoicefee = Mage::getStoreConfig('payment/klarna_invoice/invoice_fee_' . strtolower($country), $store);
142
+
143
+ return $invoicefee;
144
+ }
145
+
146
+ public function getIntegrationMode($store, $type) {
147
+ return Mage::getStoreConfig("payment/" . $type . "/integration_mode", $store);
148
+ }
149
+
150
+ public function getInvoiceFee($store = null, $getbase = false)
151
+ {
152
+ $quote = $this->getQuote();
153
+ $country = $quote->getShippingAddress()->getCountry();
154
+
155
+ $localInvoiceFee = 0;
156
+ $invoiceFee = $this->getInvoiceFeeByCountry($country, $store);
157
+
158
+ if ($invoiceFee) {
159
+ $store = $quote->getStore();
160
+
161
+ if ($store->getCurrentCurrency() != $store->getBaseCurrency()) {
162
+ $rate = $store->getBaseCurrency()->getRate($store->getCurrentCurrency());
163
+ $baseInvoiceFee = $invoiceFee/$rate;
164
+ } else {
165
+ $baseInvoiceFee = $invoiceFee;
166
+ }
167
+ $localInvoiceFee = $store->roundPrice($baseInvoiceFee);
168
+ }
169
+
170
+ // If we do not want to get the base invoice fee we
171
+ // instead return the actual invoice fee
172
+ if(!$getbase) {
173
+ return $invoiceFee;
174
+ }
175
+
176
+ return $localInvoiceFee;
177
+ }
178
+
179
+ public function invoicePriceIncludesTax($store = null)
180
+ {
181
+ return Mage::getStoreConfig('payment/klarna_invoice/invoice_fee_including_vat', $store);
182
+ }
183
+
184
+ public function getInvoiceFeePrice($price, $includingTax = null, $shippingAddress = null, $ctc = null, $store = null){
185
+ $pseudoProduct = new Varien_Object();
186
+ $pseudoProduct->setTaxClassId($this->getTaxClass($store));
187
+
188
+ $billingAddress = false;
189
+ if ($shippingAddress && $shippingAddress->getQuote() && $shippingAddress->getQuote()->getBillingAddress()) {
190
+ $billingAddress = $shippingAddress->getQuote()->getBillingAddress();
191
+ }
192
+
193
+ // Calculate the invoice fee excl. VAT
194
+ if($this->invoicePriceIncludesTax())
195
+ $invoicefee = $price - $this->calculateInvoiceFeeTaxSum($shippingAddress, $price, $this->invoicePriceIncludesTax(Mage::app()->getStore()->getId()));
196
+ else
197
+ $invoicefee = $price;
198
+
199
+ return $invoicefee;
200
+ }
201
+
202
+ /**
203
+ * Returns the invoice fee tax for the invoice fee
204
+ *
205
+ * @param <type> $address
206
+ * @param <type> $invoicefee
207
+ * @return <type>
208
+ */
209
+ public function calculateInvoiceFeeTaxSum($address, $invoicefee, $feeincvat = false) {
210
+
211
+ $invoiceTax = 0;
212
+ $store = $address->getQuote()->getStore();
213
+
214
+ $custTaxClassId = $address->getQuote()->getCustomerTaxClassId();
215
+
216
+ $taxCalculationModel = Mage::getSingleton('tax/calculation');
217
+
218
+ $request = $taxCalculationModel->getRateRequest($address, $address->getQuote()->getBillingAddress(), $custTaxClassId, $store);
219
+ $invoiceTaxClass = Mage::helper('klarnaPaymentModule')->getTaxClass($store);
220
+
221
+ $rate = $taxCalculationModel->getRate($request->setProductClassId($invoiceTaxClass));
222
+
223
+ if($rate)
224
+ $invoiceTax= $taxCalculationModel->calcTaxAmount($invoicefee, $rate, $feeincvat, true);
225
+
226
+ return $invoiceTax;
227
+ }
228
+
229
+ public function isTestMode($type, $store = null) {
230
+ return (Mage::getStoreConfig('payment/' . $type . '/is_test', $store) == '1');
231
+ }
232
+
233
+ }
app/code/community/Klarna/KlarnaPaymentModule/Helper/Pclass.php ADDED
@@ -0,0 +1,186 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ * To change this template, choose Tools | Templates
4
+ * and open the template in the editor.
5
+ */
6
+ class Klarna_KlarnaPaymentModule_Helper_Pclass extends Mage_Core_Helper_Abstract
7
+ {
8
+
9
+
10
+ /**
11
+ * Get all pclasses stored in the database
12
+ *
13
+ * @return <array> A collection of pclasses
14
+ */
15
+ public function getPlcasses() {
16
+ $tableName = Mage::getSingleton('core/resource')->getTableName('klarna_pclasses');
17
+ $read = Mage::getSingleton('core/resource')->getConnection('core_read');
18
+
19
+ $results = $read->fetchAll("SELECT * FROM $tableName");
20
+
21
+ return $results;
22
+ }
23
+
24
+
25
+ /**
26
+ *
27
+ * @param string $country
28
+ * @param int $store
29
+ */
30
+ public function getSortedPclassesForStoreAndCountry($sum, $country, $store, $flag = 0, $type = -1) {
31
+ $tableName = Mage::getSingleton('core/resource')->getTableName('klarna_pclasses');
32
+ $api = Mage::helper("klarnaPaymentModule/api");
33
+ $calc = Mage::helper('klarnaPaymentModule/calc_klarna');
34
+ $settings = $api->getCountrySettings($country);
35
+ $calculatedPclasses = array();
36
+ $read = Mage::getSingleton('core/resource')->getConnection('core_read');
37
+ // If flag = 1, try to load the cache
38
+ $cache = unserialize(Mage::app()->loadCache("klarna_cache_" . $country . "_" . $store));
39
+ $account = array();
40
+ if($flag == 1 && $cache != false) {
41
+ $pclasses = (array)$cache;
42
+ } else {
43
+ // If the select fails we simply return the empty array to
44
+ // indicate that we do not get any pclasses.
45
+ try {
46
+ $pclasses = $read->fetchAll("SELECT * FROM $tableName WHERE storeid=" . (int)$store . " AND country=" . (int)$settings['country'] . ($type != -1 ? " AND type=" . (int)$type : ''));
47
+ } catch (Exception $exc) {
48
+ return $calculatedPclasses;
49
+ }
50
+ }
51
+
52
+ // cache product page pclass if we havent already done so.
53
+ if($flag == 1 && !$cache && sizeof($pclasses) != 0) {
54
+ Mage::app()->saveCache(serialize ($pclasses), "klarna_cache_" . $country . "_" . $store);
55
+ }
56
+
57
+ foreach($pclasses as $pclass) {
58
+ if($sum > $pclass['minamount']) {
59
+ $monthlycost = $calc->calc_monthly_cost($sum, $pclass, $flag, $pclass['country']);
60
+
61
+ if($flag == 1 || $pclass['type'] == 1 || $pclass['type'] == 2 || ($monthlycost > $this->getMinSumForPclass($country))) {
62
+ if($pclass['type'] == 1 || $pclass['type'] == 2)
63
+ $account[] = array(round($monthlycost/100, 1), $pclass);
64
+ else
65
+ $calculatedPclasses[$pclass['months'] . '_' . $monthlycost] = array(round($monthlycost/100,1), $pclass);
66
+ }
67
+ }
68
+ }
69
+
70
+ krsort($calculatedPclasses);
71
+
72
+ // If we have Klarna Account, merge this with the other pclasses
73
+ if(!empty ($account))
74
+ $calculatedPclasses = array_merge ($account, $calculatedPclasses);
75
+
76
+
77
+ return $calculatedPclasses;
78
+
79
+ }
80
+
81
+ /**
82
+ * Retrevies a pclass item based on the provided
83
+ * pclass id
84
+ *
85
+ * @param int $pclassid The pclass to retreive
86
+ */
87
+ public function getPclass($pclassid) {
88
+ $tableName = Mage::getSingleton('core/resource')->getTableName('klarna_pclasses');
89
+ $read = Mage::getSingleton('core/resource')->getConnection('core_read');
90
+
91
+ $results = $read->fetchAll("SELECT * FROM $tableName WHERE pclass_id=" . (int)$pclassid . " AND storeid=" . (int)Mage::app()->getStore()->getId());
92
+
93
+ return $results;
94
+ }
95
+
96
+ /**
97
+ * Updates the pclasses from Klarna. This will loop through all
98
+ * that are created in Magento and make a call to fetch_pclasses
99
+ * for each store and country.
100
+ *
101
+ * @return <bool> Will return true if the update succeded.
102
+ */
103
+ public function updatePclasses() {
104
+ $tableName = Mage::getSingleton('core/resource')->getTableName('klarna_pclasses');
105
+ $this->deletePclasses();
106
+ $write = Mage::getSingleton('core/resource')->getConnection('core_write');
107
+
108
+ // Loop through all stores that are created in Magento
109
+ foreach(Mage::app()->getStores() as $store) {
110
+ // Remove the pclass cache
111
+ Mage::app()->removeCache("KLARNA_CACHE_SE_" . $store->getId());
112
+ Mage::app()->removeCache("KLARNA_CACHE_NO_" . $store->getId());
113
+ Mage::app()->removeCache("KLARNA_CACHE_FI_" . $store->getId());
114
+ Mage::app()->removeCache("KLARNA_CACHE_DK_" . $store->getId());
115
+ Mage::app()->removeCache("KLARNA_CACHE_DE_" . $store->getId());
116
+ Mage::app()->removeCache("KLARNA_CACHE_NL_" . $store->getId());
117
+
118
+ $eid = Mage::getStoreConfig("payment/klarna_partpayment/merchant_id", $store->getId());
119
+ $secret = Mage::getStoreConfig("payment/klarna_partpayment/shared_secret", $store->getId());
120
+ $helper = Mage::helper("klarnaPaymentModule/api");
121
+ $helper->loadConfig($store->getId(), "klarna_partpayment");
122
+ $pclasscollection = $helper->fetchPclasses($eid, $secret);
123
+
124
+ // Go through all countries pclasses and check for errors and store the information
125
+ foreach($pclasscollection as $key => $pclasses) {
126
+ // If there is some errors we add this to the message stack so the error is presented
127
+ // for the user
128
+ if($pclasses["status"] != "error") {
129
+
130
+ // Create a query that we can use.
131
+ $query = "INSERT INTO $tableName VALUES(null, %d, '%s', %d, %d, %d, %d, %d, 0, %d, %d, %d)";
132
+
133
+ // Loop through the pclasses and store them in the database
134
+ foreach($pclasses["pclasses"] as $pclass) {
135
+
136
+ $write->query(sprintf($query, $pclass[0], utf8_encode($pclass[1]), $pclass[2], $pclass[3], $pclass[4], $pclass[5], $pclass[6], $pclass[7], $pclass[8], $store->getId()));
137
+
138
+ }
139
+ }
140
+ }
141
+ if($pclasscollection[$key]["status"] == "error")
142
+ Mage::getSingleton('core/session')->addError("An error occurred for store " . $store->getName() . " : " . $pclasses["error"]);
143
+ else
144
+ Mage::getSingleton('core/session')->addNotice("Campaign information successfully downloaded from Klarna for store " . $store->getName());
145
+ }
146
+
147
+ return true;
148
+ }
149
+
150
+ /**
151
+ * Deletes all pclasses stored in the database
152
+ *
153
+ * @return <type> true if success
154
+ */
155
+ private function deletePclasses() {
156
+ $tableName = Mage::getSingleton('core/resource')->getTableName('klarna_pclasses');
157
+ $write = Mage::getSingleton('core/resource')->getConnection('core_write');
158
+ $write->query("DELETE FROM $tableName");
159
+
160
+ return true;
161
+ }
162
+
163
+ private function getMinSumForPclass($country) {
164
+
165
+ switch (strtolower($country)) {
166
+ case "se":
167
+ return 5000;
168
+ break;
169
+ case "no":
170
+ return 9500;
171
+ break;
172
+ case "fi":
173
+ return 895;
174
+ break;
175
+ case "dk":
176
+ return 8900;
177
+ break;
178
+ case "de":
179
+ return 695;
180
+ break;
181
+ case "nl":
182
+ return 500;
183
+ break;
184
+ }
185
+ }
186
+ }
app/code/community/Klarna/KlarnaPaymentModule/Helper/klarnaapi.php ADDED
@@ -0,0 +1,4501 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ include 'pclasses.php';
3
+ /*
4
+ * XMLRPC protocol and module version
5
+ */
6
+
7
+ global $XMLRPC_LIB;
8
+ $XMLRPC_LIB = "KPEAR";
9
+ global $PROTO_VSN;
10
+ $PROTO_VSN = "4.0";
11
+ global $CLIENT_VSN;
12
+ $CLIENT_VSN = "magentoEE:1.0.1";
13
+ global $KREDITOR_PORT;
14
+ $KREDITOR_PORT = 443;
15
+ //$KREDITOR_PORT = 80;
16
+ global $KREDITOR_HOST;
17
+ $KREDITOR_HOST = "payment.klarna.com";
18
+ //$KREDITOR_HOST = "beta-test.klarna.com";
19
+
20
+ /*
21
+ * Mode: $shipmenttype
22
+ */
23
+
24
+ global $KRED_NORMAL_SHIPMENT;
25
+ $KRED_NORMAL_SHIPMENT = 1;
26
+ global $NORMAL_SHIPMENT; // backwards compatibility
27
+ $NORMAL_SHIPMENT = 1;
28
+ global $KRED_EXPRESS_SHIPMENT;
29
+ $KRED_EXPRESS_SHIPMENT = 2;
30
+ global $EXPRESS_SHIPMENT; // backwards compatibility
31
+ $EXPRESS_SHIPMENT = 2;
32
+
33
+ /*
34
+ * Flags: $flags
35
+ */
36
+
37
+ global $KRED_AUTO_ACTIVATE;
38
+ $KRED_AUTO_ACTIVATE = 1;
39
+ global $AUTO_ACTIVATE; // backwards compatibility
40
+ $AUTO_ACTIVATE = 1;
41
+ global $KRED_TEST_MODE;
42
+ $KRED_TEST_MODE = 2;
43
+ global $TEST_MODE; // backwards compatibility
44
+ $TEST_MODE = 2;
45
+ global $KRED_MANUAL_AUTO_ACTIVATE;
46
+ $KRED_MANUAL_AUTO_ACTIVATE = 4;
47
+ global $KRED_PRE_PAY;
48
+ $KRED_PRE_PAY = 8;
49
+
50
+
51
+ /*
52
+ * Flags: $flags in mk_goods
53
+ */
54
+
55
+ global $KRED_PRINT_1000;
56
+ $KRED_PRINT_1000 = 1;
57
+ global $KRED_PRINT_100;
58
+ $KRED_PRINT_100 = 2;
59
+ global $KRED_PRINT_10;
60
+ $KRED_PRINT_10 = 4;
61
+ global $KRED_IS_SHIPMENT;
62
+ $KRED_IS_SHIPMENT = 8;
63
+ global $KRED_IS_HANDLING;
64
+ $KRED_IS_HANDLING = 16;
65
+ global $KRED_INC_VAT;
66
+ $KRED_INC_VAT = 32;
67
+
68
+ /*
69
+ * Flags monthly_cost
70
+ */
71
+ global $KRED_ACTUAL_COST;
72
+ $KRED_ACTUAL_COST = 1;
73
+ global $KRED_LIMIT_COST;
74
+ $KRED_LIMIT_COST = 0;
75
+
76
+ /*
77
+ * Mode: $type in get_addresses
78
+ */
79
+ global $GA_OLD;
80
+ $GA_OLD = 1;
81
+ global $GA_NEW;
82
+ $GA_NEW = 2;
83
+
84
+ /*
85
+ * Flags: $flags in reserve_amount / activate_reservation / split
86
+ */
87
+
88
+ global $KRED_SEND_BY_MAIL;
89
+ $KRED_SEND_BY_MAIL = 4;
90
+ global $KRED_SEND_BY_EMAIL;
91
+ $KRED_SEND_BY_EMAIL = 8;
92
+ global $KRED_DELAYED_PAY;
93
+ $KRED_DELAYED_PAY = 16;
94
+
95
+ // Klarna Mobile flags
96
+ global $KRED_PRESERVE_RESERVATION;
97
+ $KRED_PRESERVE_RESERVATION = 16;
98
+ global $KRED_PHONE_TRANSACTION;
99
+ $KRED_PHONE_TRANSACTION = 512;
100
+ global $KRED_SEND_PHONE_PIN;
101
+ $KRED_SEND_PHONE_PIN = 1024;
102
+
103
+ /*
104
+ * Pno_encodings
105
+ */
106
+
107
+ global $KRED_SE_PNO;
108
+ $KRED_SE_PNO = 2;
109
+ global $KRED_NO_PNO;
110
+ $KRED_NO_PNO = 3;
111
+ global $KRED_FI_PNO;
112
+ $KRED_FI_PNO = 4;
113
+ global $KRED_DK_PNO;
114
+ $KRED_DK_PNO = 5;
115
+ global $KRED_DE_PNO;
116
+ $KRED_DE_PNO = 6;
117
+ global $KRED_NL_PNO;
118
+ $KRED_NL_PNO = 7;
119
+ global $KRED_CNO_PNO;
120
+ $KRED_CNO_PNO = 1000;
121
+
122
+ global $PNO_SE;
123
+ $PNO_SE = 2; // Swedish
124
+ global $PNO_NO;
125
+ $PNO_NO = 3; // Norwegian
126
+ global $PNO_FI;
127
+ $PNO_FI = 4; // Finnish
128
+ global $PNO_DK;
129
+ $PNO_DK = 5; // Danish
130
+ global $PNO_DE;
131
+ $PNO_DE = 6; // German
132
+ global $PNO_NL;
133
+ $PNO_NL = 7; // Dutch
134
+
135
+ /*
136
+ * Mode: $type in update_charge_amount (Same as ?KD_GT_* in kdb.hrl)
137
+ */
138
+
139
+ global $KRED_SHIPMENT;
140
+ $KRED_SHIPMENT = 1;
141
+ global $KRED_HANDLING;
142
+ $KRED_HANDLING = 2;
143
+
144
+
145
+
146
+ /*
147
+ * Mode: $currency
148
+ */
149
+
150
+ global $KRED_SEK; // Swedish krona
151
+ $KRED_SEK = 0;
152
+ global $KRED_NOK; // Norwegian krona
153
+ $KRED_NOK = 1;
154
+ global $KRED_EUR; // Euro
155
+ $KRED_EUR = 2;
156
+ global $KRED_DKK; // Danska kronor
157
+ $KRED_DKK = 3;
158
+
159
+
160
+ /*
161
+ * Mode: $country
162
+ */
163
+
164
+ global $KRED_ISO3166_AF;
165
+ $KRED_ISO3166_AF = 1; // AFGHANISTAN
166
+ global $KRED_ISO3166_AX;
167
+ $KRED_ISO3166_AX = 2; // �LAND ISLANDS
168
+ global $KRED_ISO3166_AL;
169
+ $KRED_ISO3166_AL = 3; // ALBANIA
170
+ global $KRED_ISO3166_DZ;
171
+ $KRED_ISO3166_DZ = 4; // ALGERIA
172
+ global $KRED_ISO3166_AS;
173
+ $KRED_ISO3166_AS = 5; // AMERICAN SAMOA
174
+ global $KRED_ISO3166_AD;
175
+ $KRED_ISO3166_AD = 6; // ANDORRA
176
+ global $KRED_ISO3166_AO;
177
+ $KRED_ISO3166_AO = 7; // ANGOLA
178
+ global $KRED_ISO3166_AI;
179
+ $KRED_ISO3166_AI = 8; // ANGUILLA
180
+ global $KRED_ISO3166_AQ;
181
+ $KRED_ISO3166_AQ = 9; // ANTARCTICA
182
+ global $KRED_ISO3166_AG;
183
+ $KRED_ISO3166_AG = 10; // ANTIGUA AND BARBUDA
184
+ global $KRED_ISO3166_AR;
185
+ $KRED_ISO3166_AR = 11; // ARGENTINA
186
+ global $KRED_ISO3166_AM;
187
+ $KRED_ISO3166_AM = 12; // ARMENIA
188
+ global $KRED_ISO3166_AW;
189
+ $KRED_ISO3166_AW = 13; // ARUBA
190
+ global $KRED_ISO3166_AU;
191
+ $KRED_ISO3166_AU = 14; // AUSTRALIA
192
+ global $KRED_ISO3166_AT;
193
+ $KRED_ISO3166_AT = 15; // AUSTRIA
194
+ global $KRED_ISO3166_AZ;
195
+ $KRED_ISO3166_AZ = 16; // AZERBAIJAN
196
+ global $KRED_ISO3166_BS;
197
+ $KRED_ISO3166_BS = 17; // BAHAMAS
198
+ global $KRED_ISO3166_BH;
199
+ $KRED_ISO3166_BH = 18; // BAHRAIN
200
+ global $KRED_ISO3166_BD;
201
+ $KRED_ISO3166_BD = 19; // BANGLADESH
202
+ global $KRED_ISO3166_BB;
203
+ $KRED_ISO3166_BB = 20; // BARBADOS
204
+ global $KRED_ISO3166_BY;
205
+ $KRED_ISO3166_BY = 21; // BELARUS
206
+ global $KRED_ISO3166_BE;
207
+ $KRED_ISO3166_BE = 22; // BELGIUM
208
+ global $KRED_ISO3166_BZ;
209
+ $KRED_ISO3166_BZ = 23; // BELIZE
210
+ global $KRED_ISO3166_BJ;
211
+ $KRED_ISO3166_BJ = 24; // BENIN
212
+ global $KRED_ISO3166_BM;
213
+ $KRED_ISO3166_BM = 25; // BERMUDA
214
+ global $KRED_ISO3166_BT;
215
+ $KRED_ISO3166_BT = 26; // BHUTAN
216
+ global $KRED_ISO3166_BO;
217
+ $KRED_ISO3166_BO = 27; // BOLIVIA
218
+ global $KRED_ISO3166_BA;
219
+ $KRED_ISO3166_BA = 28; // BOSNIA AND HERZEGOVINA
220
+ global $KRED_ISO3166_BW;
221
+ $KRED_ISO3166_BW = 29; // BOTSWANA
222
+ global $KRED_ISO3166_BV;
223
+ $KRED_ISO3166_BV = 30; // BOUVET ISLAND
224
+ global $KRED_ISO3166_BR;
225
+ $KRED_ISO3166_BR = 31; // BRAZIL
226
+ global $KRED_ISO3166_IO;
227
+ $KRED_ISO3166_IO = 32; // BRITISH INDIAN OCEAN TERRITORY
228
+ global $KRED_ISO3166_BN;
229
+ $KRED_ISO3166_BN = 33; // BRUNEI DARUSSALAM
230
+ global $KRED_ISO3166_BG;
231
+ $KRED_ISO3166_BG = 34; // BULGARIA
232
+ global $KRED_ISO3166_BF;
233
+ $KRED_ISO3166_BF = 35; // BURKINA FASO
234
+ global $KRED_ISO3166_BI;
235
+ $KRED_ISO3166_BI = 36; // BURUNDI
236
+ global $KRED_ISO3166_KH;
237
+ $KRED_ISO3166_KH = 37; // CAMBODIA
238
+ global $KRED_ISO3166_CM;
239
+ $KRED_ISO3166_CM = 38; // CAMEROON
240
+ global $KRED_ISO3166_CA;
241
+ $KRED_ISO3166_CA = 39; // CANADA
242
+ global $KRED_ISO3166_CV;
243
+ $KRED_ISO3166_CV = 40; // CAPE VERDE
244
+ global $KRED_ISO3166_KY;
245
+ $KRED_ISO3166_KY = 41; // CAYMAN ISLANDS
246
+ global $KRED_ISO3166_CF;
247
+ $KRED_ISO3166_CF = 42; // CENTRAL AFRICAN REPUBLIC
248
+ global $KRED_ISO3166_TD;
249
+ $KRED_ISO3166_TD = 43; // CHAD
250
+ global $KRED_ISO3166_CL;
251
+ $KRED_ISO3166_CL = 44; // CHILE
252
+ global $KRED_ISO3166_CN;
253
+ $KRED_ISO3166_CN = 45; // CHINA
254
+ global $KRED_ISO3166_CX;
255
+ $KRED_ISO3166_CX = 46; // CHRISTMAS ISLAND
256
+ global $KRED_ISO3166_CC;
257
+ $KRED_ISO3166_CC = 47; // COCOS (KEELING) ISLANDS
258
+ global $KRED_ISO3166_CO;
259
+ $KRED_ISO3166_CO = 48; // COLOMBIA
260
+ global $KRED_ISO3166_KM;
261
+ $KRED_ISO3166_KM = 49; // COMOROS
262
+ global $KRED_ISO3166_CG;
263
+ $KRED_ISO3166_CG = 50; // CONGO
264
+ global $KRED_ISO3166_CD;
265
+ $KRED_ISO3166_CD = 51; // CONGO, THE DEMOCRATIC REPUBLIC OF THE
266
+ global $KRED_ISO3166_CK;
267
+ $KRED_ISO3166_CK = 52; // COOK ISLANDS
268
+ global $KRED_ISO3166_CT;
269
+ $KRED_ISO3166_CR = 53; // COSTA RICA
270
+ global $KRED_ISO3166_CI;
271
+ $KRED_ISO3166_CI = 54; // COTE D'IVOIRE
272
+ global $KRED_ISO3166_HR;
273
+ $KRED_ISO3166_HR = 55; // CROATIA
274
+ global $KRED_ISO3166_CU;
275
+ $KRED_ISO3166_CU = 56; // CUBA
276
+ global $KRED_ISO3166_CY;
277
+ $KRED_ISO3166_CY = 57; // CYPRUS
278
+ global $KRED_ISO3166_CZ;
279
+ $KRED_ISO3166_CZ = 58; // CZECH REPUBLIC
280
+ global $KRED_ISO3166_DK;
281
+ $KRED_ISO3166_DK = 59; // DENMARK
282
+ global $KRED_ISO3166_DJ;
283
+ $KRED_ISO3166_DJ = 60; // DJIBOUTI
284
+ global $KRED_ISO3166_DM;
285
+ $KRED_ISO3166_DM = 61; // DOMINICA
286
+ global $KRED_ISO3166_DO;
287
+ $KRED_ISO3166_DO = 62; // DOMINICAN REPUBLIC
288
+ global $KRED_ISO3166_EC;
289
+ $KRED_ISO3166_EC = 63; // ECUADOR
290
+ global $KRED_ISO3166_EG;
291
+ $KRED_ISO3166_EG = 64; // EGYPT
292
+ global $KRED_ISO3166_SV;
293
+ $KRED_ISO3166_SV = 65; // EL SALVADOR
294
+ global $KRED_ISO3166_GQ;
295
+ $KRED_ISO3166_GQ = 66; // EQUATORIAL GUINEA
296
+ global $KRED_ISO3166_ER;
297
+ $KRED_ISO3166_ER = 67; // ERITREA
298
+ global $KRED_ISO3166_EE;
299
+ $KRED_ISO3166_EE = 68; // ESTONIA
300
+ global $KRED_ISO3166_ET;
301
+ $KRED_ISO3166_ET = 69; // ETHIOPIA
302
+ global $KRED_ISO3166_FK;
303
+ $KRED_ISO3166_FK = 70; // FALKLAND ISLANDS (MALVINAS)
304
+ global $KRED_ISO3166_FO;
305
+ $KRED_ISO3166_FO = 71; // FAROE ISLANDS
306
+ global $KRED_ISO3166_FJ;
307
+ $KRED_ISO3166_FJ = 72; // FIJI
308
+ global $KRED_ISO3166_FI;
309
+ $KRED_ISO3166_FI = 73; // FINLAND
310
+ global $KRED_ISO3166_FR;
311
+ $KRED_ISO3166_FR = 74; // FRANCE
312
+ global $KRED_ISO3166_GF;
313
+ $KRED_ISO3166_GF = 75; // FRENCH GUIANA
314
+ global $KRED_ISO3166_PF;
315
+ $KRED_ISO3166_PF = 76; // FRENCH POLYNESIA
316
+ global $KRED_ISO3166_TF;
317
+ $KRED_ISO3166_TF = 77; // FRENCH SOUTHERN TERRITORIES
318
+ global $KRED_ISO3166_GA;
319
+ $KRED_ISO3166_GA = 78; // GABON
320
+ global $KRED_ISO3166_GA;
321
+ $KRED_ISO3166_GM = 79; // GAMBIA
322
+ global $KRED_ISO3166_GE;
323
+ $KRED_ISO3166_GE = 80; // GEORGIA
324
+ global $KRED_ISO3166_DE;
325
+ $KRED_ISO3166_DE = 81; // GERMANY
326
+ global $KRED_ISO3166_GH;
327
+ $KRED_ISO3166_GH = 82; // GHANA
328
+ global $KRED_ISO3166_GI;
329
+ $KRED_ISO3166_GI = 83; // GIBRALTAR
330
+ global $KRED_ISO3166_GR;
331
+ $KRED_ISO3166_GR = 84; // GREECE
332
+ global $KRED_ISO3166_GL;
333
+ $KRED_ISO3166_GL = 85; // GREENLAND
334
+ global $KRED_ISO3166_GD;
335
+ $KRED_ISO3166_GD = 86; // GRENADA
336
+ global $KRED_ISO3166_GP;
337
+ $KRED_ISO3166_GP = 87; // GUADELOUPE
338
+ global $KRED_ISO3166_GU;
339
+ $KRED_ISO3166_GU = 88; // GUAM
340
+ global $KRED_ISO3166_GT;
341
+ $KRED_ISO3166_GT = 89; // GUATEMALA
342
+ global $KRED_ISO3166_GG;
343
+ $KRED_ISO3166_GG = 90; // GUERNSEY
344
+ global $KRED_ISO3166_GN;
345
+ $KRED_ISO3166_GN = 91; // GUINEA
346
+ global $KRED_ISO3166_GW;
347
+ $KRED_ISO3166_GW = 92; // GUINEA-BISSAU
348
+ global $KRED_ISO3166_GY;
349
+ $KRED_ISO3166_GY = 93; // GUYANA
350
+ global $KRED_ISO3166_HT;
351
+ $KRED_ISO3166_HT = 94; // HAITI
352
+ global $KRED_ISO3166_HM;
353
+ $KRED_ISO3166_HM = 95; // HEARD ISLAND AND MCDONALD ISLANDS
354
+ global $KRED_ISO3166_VA;
355
+ $KRED_ISO3166_VA = 96; // HOLY SEE (VATICAN CITY STATE)
356
+ global $KRED_ISO3166_HN;
357
+ $KRED_ISO3166_HN = 97; // HONDURAS
358
+ global $KRED_ISO3166_HK;
359
+ $KRED_ISO3166_HK = 98; // HONG KONG
360
+ global $KRED_ISO3166_HU;
361
+ $KRED_ISO3166_HU = 99; // HUNGARY
362
+ global $KRED_ISO3166_IS;
363
+ $KRED_ISO3166_IS = 100; // ICELAND
364
+ global $KRED_ISO3166_IN;
365
+ $KRED_ISO3166_IN = 101; // INDIA
366
+ global $KRED_ISO3166_ID;
367
+ $KRED_ISO3166_ID = 102; // INDONESIA
368
+ global $KRED_ISO3166_IR;
369
+ $KRED_ISO3166_IR = 103; // IRAN, ISLAMIC REPUBLIC OF
370
+ global $KRED_ISO3166_IQ;
371
+ $KRED_ISO3166_IQ = 104; // IRAQ
372
+ global $KRED_ISO3166_IE;
373
+ $KRED_ISO3166_IE = 105; // IRELAND
374
+ global $KRED_ISO3166_IM;
375
+ $KRED_ISO3166_IM = 106; // ISLE OF MAN
376
+ global $KRED_ISO3166_IL;
377
+ $KRED_ISO3166_IL = 107; // ISRAEL
378
+ global $KRED_ISO3166_IT;
379
+ $KRED_ISO3166_IT = 108; // ITALY
380
+ global $KRED_ISO3166_JM;
381
+ $KRED_ISO3166_JM = 109; // JAMAICA
382
+ global $KRED_ISO3166_JP;
383
+ $KRED_ISO3166_JP = 110; // JAPAN
384
+ global $KRED_ISO3166_JE;
385
+ $KRED_ISO3166_JE = 111; // JERSEY
386
+ global $KRED_ISO3166_JO;
387
+ $KRED_ISO3166_JO = 112; // JORDAN
388
+ global $KRED_ISO3166_KZ;
389
+ $KRED_ISO3166_KZ = 113; // KAZAKHSTAN
390
+ global $KRED_ISO3166_KE;
391
+ $KRED_ISO3166_KE =114; // KENYA
392
+ global $KRED_ISO3166_KI;
393
+ $KRED_ISO3166_KI =115; // KIRIBATI
394
+ global $KRED_ISO3166_KP;
395
+ $KRED_ISO3166_KP =116; // KOREA, DEMOCRATIC PEOPLE'S REPUBLIC OF
396
+ global $KRED_ISO3166_KR;
397
+ $KRED_ISO3166_KR =117; // KOREA, REPUBLIC OF
398
+ global $KRED_ISO3166_KW;
399
+ $KRED_ISO3166_KW = 118; // KUWAIT
400
+ global $KRED_ISO3166_KG;
401
+ $KRED_ISO3166_KG = 119; // KYRGYZSTAN
402
+ global $KRED_ISO3166_LA;
403
+ $KRED_ISO3166_LA = 120; // LAO PEOPLE'S DEMOCRATIC REPUBLIC
404
+ global $KRED_ISO3166_LV;
405
+ $KRED_ISO3166_LV = 121; // LATVIA
406
+ global $KRED_ISO3166_LB;
407
+ $KRED_ISO3166_LB = 122; // LEBANON
408
+ global $KRED_ISO3166_LS;
409
+ $KRED_ISO3166_LS = 123; // LESOTHO
410
+ global $KRED_ISO3166_LR;
411
+ $KRED_ISO3166_LR = 124; // LIBERIA
412
+ global $KRED_ISO3166_LY;
413
+ $KRED_ISO3166_LY = 125; // LIBYAN ARAB JAMAHIRIYA
414
+ global $KRED_ISO3166_LI;
415
+ $KRED_ISO3166_LI = 126; // LIECHTENSTEIN
416
+ global $KRED_ISO3166_LT;
417
+ $KRED_ISO3166_LT = 127; // LITHUANIA
418
+ global $KRED_ISO3166_LU;
419
+ $KRED_ISO3166_LU = 128; // LUXEMBOURG
420
+ global $KRED_ISO3166_MO;
421
+ $KRED_ISO3166_MO = 129; // MACAO
422
+ global $KRED_ISO3166_MK;
423
+ $KRED_ISO3166_MK = 130; // MACEDONIA, THE FORMER YUGOSLAV REPUBLIC OF
424
+ global $KRED_ISO3166_MG;
425
+ $KRED_ISO3166_MG = 131; // MADAGASCAR
426
+ global $KRED_ISO3166_MW;
427
+ $KRED_ISO3166_MW = 132; // MALAWI
428
+ global $KRED_ISO3166_MY;
429
+ $KRED_ISO3166_MY = 133; // MALAYSIA
430
+ global $KRED_ISO3166_MV;
431
+ $KRED_ISO3166_MV = 134; // MALDIVES
432
+ global $KRED_ISO3166_ML;
433
+ $KRED_ISO3166_ML = 135; // MALI
434
+ global $KRED_ISO3166_MT;
435
+ $KRED_ISO3166_MT = 136; // MALTA
436
+ global $KRED_ISO3166_MH;
437
+ $KRED_ISO3166_MH = 137; // MARSHALL ISLANDS
438
+ global $KRED_ISO3166_MQ;
439
+ $KRED_ISO3166_MQ = 138; // MARTINIQUE
440
+ global $KRED_ISO3166_MR;
441
+ $KRED_ISO3166_MR = 139; // MAURITANIA
442
+ global $KRED_ISO3166_MU;
443
+ $KRED_ISO3166_MU = 140; // MAURITIUS
444
+ global $KRED_ISO3166_YT;
445
+ $KRED_ISO3166_YT = 141; // MAYOTTE
446
+ global $KRED_ISO3166_MX;
447
+ $KRED_ISO3166_MX = 142; // MEXICO
448
+ global $KRED_ISO3166_FM;
449
+ $KRED_ISO3166_FM = 143; // MICRONESIA FEDERATED STATES OF
450
+ global $KRED_ISO3166_MD;
451
+ $KRED_ISO3166_MD = 144; // MOLDOVA, REPUBLIC OF
452
+ global $KRED_ISO3166_MC;
453
+ $KRED_ISO3166_MC = 145; // MONACO
454
+ global $KRED_ISO3166_MN;
455
+ $KRED_ISO3166_MN = 146; // MONGOLIA
456
+ global $KRED_ISO3166_MS;
457
+ $KRED_ISO3166_MS = 147; // MONTSERRAT
458
+ global $KRED_ISO3166_MA;
459
+ $KRED_ISO3166_MA = 148; // MOROCCO
460
+ global $KRED_ISO3166_MZ;
461
+ $KRED_ISO3166_MZ = 149; // MOZAMBIQUE
462
+ global $KRED_ISO3166_MM;
463
+ $KRED_ISO3166_MM = 150; // MYANMAR
464
+ global $KRED_ISO3166_NA;
465
+ $KRED_ISO3166_NA = 151; // NAMIBIA
466
+ global $KRED_ISO3166_NR;
467
+ $KRED_ISO3166_NR = 152; // NAURU
468
+ global $KRED_ISO3166_NP;
469
+ $KRED_ISO3166_NP = 153; // NEPAL
470
+ global $KRED_ISO3166_NL;
471
+ $KRED_ISO3166_NL = 154; // NETHERLANDS
472
+ global $KRED_ISO3166_AN;
473
+ $KRED_ISO3166_AN = 155; // NETHERLANDS ANTILLES
474
+ global $KRED_ISO3166_NC;
475
+ $KRED_ISO3166_NC = 156; // NEW CALEDONIA
476
+ global $KRED_ISO3166_NZ;
477
+ $KRED_ISO3166_NZ = 157; // NEW ZEALAND
478
+ global $KRED_ISO3166_NI;
479
+ $KRED_ISO3166_NI = 158; // NICARAGUA
480
+ global $KRED_ISO3166_NE;
481
+ $KRED_ISO3166_NE = 159; // NIGER
482
+ global $KRED_ISO3166_NG;
483
+ $KRED_ISO3166_NG = 160; // NIGERIA
484
+ global $KRED_ISO3166_NU;
485
+ $KRED_ISO3166_NU = 161; // NIUE
486
+ global $KRED_ISO3166_NF;
487
+ $KRED_ISO3166_NF = 162; // NORFOLK ISLAND
488
+ global $KRED_ISO3166_MP;
489
+ $KRED_ISO3166_MP = 163; // NORTHERN MARIANA ISLANDS
490
+ global $KRED_ISO3166_NO;
491
+ $KRED_ISO3166_NO = 164; // NORWAY
492
+ global $KRED_ISO3166_OM;
493
+ $KRED_ISO3166_OM = 165; // OMAN
494
+ global $KRED_ISO3166_PK;
495
+ $KRED_ISO3166_PK = 166; // PAKISTAN
496
+ global $KRED_ISO3166_PW;
497
+ $KRED_ISO3166_PW = 167; // PALAU
498
+ global $KRED_ISO3166_PS;
499
+ $KRED_ISO3166_PS = 168; // PALESTINIAN TERRITORY OCCUPIED
500
+ global $KRED_ISO3166_PA;
501
+ $KRED_ISO3166_PA = 169; // PANAMA
502
+ global $KRED_ISO3166_PG;
503
+ $KRED_ISO3166_PG = 170; // PAPUA NEW GUINEA
504
+ global $KRED_ISO3166_PY;
505
+ $KRED_ISO3166_PY = 171; // PARAGUAY
506
+ global $KRED_ISO3166_PE;
507
+ $KRED_ISO3166_PE = 172; // PERU
508
+ global $KRED_ISO3166_PH;
509
+ $KRED_ISO3166_PH = 173; // PHILIPPINES
510
+ global $KRED_ISO3166_PN;
511
+ $KRED_ISO3166_PN = 174; // PITCAIRN
512
+ global $KRED_ISO3166_PL;
513
+ $KRED_ISO3166_PL = 175; // POLAND
514
+ global $KRED_ISO3166_PT;
515
+ $KRED_ISO3166_PT = 176; // PORTUGAL
516
+ global $KRED_ISO3166_PR;
517
+ $KRED_ISO3166_PR = 177; // PUERTO RICO
518
+ global $KRED_ISO3166_QA;
519
+ $KRED_ISO3166_QA = 178; // QATAR
520
+ global $KRED_ISO3166_RE;
521
+ $KRED_ISO3166_RE = 179; // REUNION
522
+ global $KRED_ISO3166_RO;
523
+ $KRED_ISO3166_RO = 180; // ROMANIA
524
+ global $KRED_ISO3166_RU;
525
+ $KRED_ISO3166_RU = 181; // RUSSIAN FEDERATION
526
+ global $KRED_ISO3166_RW;
527
+ $KRED_ISO3166_RW = 182; // RWANDA
528
+ global $KRED_ISO3166_SH;
529
+ $KRED_ISO3166_SH = 183; // SAINT HELENA
530
+ global $KRED_ISO3166_KN;
531
+ $KRED_ISO3166_KN = 184; // SAINT KITTS AND NEVIS
532
+ global $KRED_ISO3166_LC;
533
+ $KRED_ISO3166_LC = 185; // SAINT LUCIA
534
+ global $KRED_ISO3166_PM;
535
+ $KRED_ISO3166_PM = 186; // SAINT PIERRE AND MIQUELON
536
+ global $KRED_ISO3166_VC;
537
+ $KRED_ISO3166_VC = 187; // SAINT VINCENT AND THE GRENADINES
538
+ global $KRED_ISO3166_WS;
539
+ $KRED_ISO3166_WS = 188; // SAMOA
540
+ global $KRED_ISO3166_SM;
541
+ $KRED_ISO3166_SM = 189; // SAN MARINO
542
+ global $KRED_ISO3166_ST;
543
+ $KRED_ISO3166_ST = 190; // SAO TOME AND PRINCIPE
544
+ global $KRED_ISO3166_SA;
545
+ $KRED_ISO3166_SA = 191; // SAUDI ARABIA
546
+ global $KRED_ISO3166_SN;
547
+ $KRED_ISO3166_SN = 192; // SENEGAL
548
+ global $KRED_ISO3166_CS;
549
+ $KRED_ISO3166_CS = 193; // SERBIA AND MONTENEGRO
550
+ global $KRED_ISO3166_SC;
551
+ $KRED_ISO3166_SC = 194; // SEYCHELLES
552
+ global $KRED_ISO3166_SL;
553
+ $KRED_ISO3166_SL = 195; // SIERRA LEONE
554
+ global $KRED_ISO3166_SG;
555
+ $KRED_ISO3166_SG = 196; // SINGAPORE
556
+ global $KRED_ISO3166_SK;
557
+ $KRED_ISO3166_SK = 197; // SLOVAKIA
558
+ global $KRED_ISO3166_SI;
559
+ $KRED_ISO3166_SI = 198; // SLOVENIA
560
+ global $KRED_ISO3166_SB;
561
+ $KRED_ISO3166_SB = 199; // SOLOMON ISLANDS
562
+ global $KRED_ISO3166_SO;
563
+ $KRED_ISO3166_SO = 200; // SOMALIA
564
+ global $KRED_ISO3166_ZA;
565
+ $KRED_ISO3166_ZA = 201; // SOUTH AFRICA
566
+ global $KRED_ISO3166_GS;
567
+ $KRED_ISO3166_GS = 202; // SOUTH GEORGIA AND THE SOUTH SANDWICH ISLANDS
568
+ global $KRED_ISO3166_ES;
569
+ $KRED_ISO3166_ES = 203; // SPAIN
570
+ global $KRED_ISO3166_LK;
571
+ $KRED_ISO3166_LK = 204; // SRI LANKA
572
+ global $KRED_ISO3166_SD;
573
+ $KRED_ISO3166_SD = 205; // SUDAN
574
+ global $KRED_ISO3166_SR;
575
+ $KRED_ISO3166_SR = 206; // SURINAME
576
+ global $KRED_ISO3166_SJ;
577
+ $KRED_ISO3166_SJ = 207; // SVALBARD AND JAN MAYEN
578
+ global $KRED_ISO3166_SZ;
579
+ $KRED_ISO3166_SZ = 208; // SWAZILAND
580
+ global $KRED_ISO3166_SE;
581
+ $KRED_ISO3166_SE = 209; // SWEDEN
582
+ global $KRED_ISO3166_CH;
583
+ $KRED_ISO3166_CH = 210; // SWITZERLAND
584
+ global $KRED_ISO3166_SY;
585
+ $KRED_ISO3166_SY = 211; // SYRIAN ARAB REPUBLIC
586
+ global $KRED_ISO3166_TW;
587
+ $KRED_ISO3166_TW = 212; // TAIWAN PROVINCE OF CHINA
588
+ global $KRED_ISO3166_TJ;
589
+ $KRED_ISO3166_TJ = 213; // TAJIKISTAN
590
+ global $KRED_ISO3166_TZ;
591
+ $KRED_ISO3166_TZ = 214; // TANZANIA, UNITED REPUBLIC OF
592
+ global $KRED_ISO3166_TH;
593
+ $KRED_ISO3166_TH = 215; // THAILAND
594
+ global $KRED_ISO3166_TL;
595
+ $KRED_ISO3166_TL = 216; // TIMOR-LESTE
596
+ global $KRED_ISO3166_TC;
597
+ $KRED_ISO3166_TG = 217; // TOGO
598
+ global $KRED_ISO3166_TK;
599
+ $KRED_ISO3166_TK = 218; // TOKELAU
600
+ global $KRED_ISO3166_TO;
601
+ $KRED_ISO3166_TO = 219; // TONGA
602
+ global $KRED_ISO3166_TT;
603
+ $KRED_ISO3166_TT = 220; // TRINIDAD AND TOBAGO
604
+ global $KRED_ISO3166_TN;
605
+ $KRED_ISO3166_TN = 221; // TUNISIA
606
+ global $KRED_ISO3166_TR;
607
+ $KRED_ISO3166_TR = 222; // TURKEY
608
+ global $KRED_ISO3166_TM;
609
+ $KRED_ISO3166_TM = 223; // TURKMENISTAN
610
+ global $KRED_ISO3166_TC;
611
+ $KRED_ISO3166_TC = 224; // TURKS AND CAICOS ISLANDS
612
+ global $KRED_ISO3166_TV;
613
+ $KRED_ISO3166_TV = 225; // TUVALU
614
+ global $KRED_ISO3166_UG;
615
+ $KRED_ISO3166_UG = 226; // UGANDA
616
+ global $KRED_ISO3166_UA;
617
+ $KRED_ISO3166_UA = 227; // UKRAINE
618
+ global $KRED_ISO3166_AE;
619
+ $KRED_ISO3166_AE = 228; // UNITED ARAB EMIRATES
620
+ global $KRED_ISO3166_GB;
621
+ $KRED_ISO3166_GB = 229; // UNITED KINGDOM
622
+ global $KRED_ISO3166_US;
623
+ $KRED_ISO3166_US = 230; // UNITED STATES
624
+ global $KRED_ISO3166_UM;
625
+ $KRED_ISO3166_UM = 231; // UNITED STATES MINOR OUTLYING ISLANDS
626
+ global $KRED_ISO3166_UY;
627
+ $KRED_ISO3166_UY = 232; // URUGUAY
628
+ global $KRED_ISO3166_UZ;
629
+ $KRED_ISO3166_UZ = 233; // UZBEKISTAN
630
+ global $KRED_ISO3166_VU;
631
+ $KRED_ISO3166_VU = 234; // VANUATU
632
+ global $KRED_ISO3166_VE;
633
+ $KRED_ISO3166_VE = 235; // VENEZUELA
634
+ global $KRED_ISO3166_VN;
635
+ $KRED_ISO3166_VN = 236; // VIET NAM
636
+ global $KRED_ISO3166_VG;
637
+ $KRED_ISO3166_VG = 237; // VIRGIN ISLANDS, BRITISH
638
+ global $KRED_ISO3166_VI;
639
+ $KRED_ISO3166_VI = 238; // VIRGIN ISLANDS, US
640
+ global $KRED_ISO3166_WF;
641
+ $KRED_ISO3166_WF = 239; // WALLIS AND FUTUNA
642
+ global $KRED_ISO3166_EH;
643
+ $KRED_ISO3166_EH = 240; // WESTERN SAHARA
644
+ global $KRED_ISO3166_YE;
645
+ $KRED_ISO3166_YE = 241; // YEMEN
646
+ global $KRED_ISO3166_ZM;
647
+ $KRED_ISO3166_ZM = 242; // ZAMBIA
648
+ global $KRED_ISO3166_ZW;
649
+ $KRED_ISO3166_ZW = 243; // ZIMBABWE
650
+
651
+
652
+
653
+ /*
654
+ * Language code
655
+ */
656
+
657
+ global $KRED_ISO639_AA;
658
+ $KRED_ISO639_AA = 1; // Afar
659
+ global $KRED_ISO639_AB;
660
+ $KRED_ISO639_AB = 2; // Abkhazian
661
+ global $KRED_ISO639_AE;
662
+ $KRED_ISO639_AE = 3; // Avestan
663
+ global $KRED_ISO639_AF;
664
+ $KRED_ISO639_AF = 4; // Afrikaans
665
+ global $KRED_ISO639_AM;
666
+ $KRED_ISO639_AM = 5; // Amharic
667
+ global $KRED_ISO639_AR;
668
+ $KRED_ISO639_AR = 6; // Arabic
669
+ global $KRED_ISO639_AS;
670
+ $KRED_ISO639_AS = 7; // Assamese
671
+ global $KRED_ISO639_AY;
672
+ $KRED_ISO639_AY = 8; // Aymara
673
+ global $KRED_ISO639_AZ;
674
+ $KRED_ISO639_AZ = 9; // Azerbaijani
675
+ global $KRED_ISO639_BA;
676
+ $KRED_ISO639_BA = 10; // Bashkir
677
+ global $KRED_ISO639_BE;
678
+ $KRED_ISO639_BE = 11; // Byelorussian; Belarusian
679
+ global $KRED_ISO639_BG;
680
+ $KRED_ISO639_BG = 12; // Bulgarian
681
+ global $KRED_ISO639_BH;
682
+ $KRED_ISO639_BH = 13; // Bihari
683
+ global $KRED_ISO639_BI;
684
+ $KRED_ISO639_BI = 14; // Bislama
685
+ global $KRED_ISO639_BN;
686
+ $KRED_ISO639_BN = 15; // Bengali; Bangla
687
+ global $KRED_ISO639_BO;
688
+ $KRED_ISO639_BO = 16; // Tibetan
689
+ global $KRED_ISO639_BR;
690
+ $KRED_ISO639_BR = 17; // Breton
691
+ global $KRED_ISO639_BS;
692
+ $KRED_ISO639_BS = 18; // Bosnian
693
+ global $KRED_ISO639_CA;
694
+ $KRED_ISO639_CA = 19; // Catalan
695
+ global $KRED_ISO639_CE;
696
+ $KRED_ISO639_CE = 20; // Chechen
697
+ global $KRED_ISO639_CH;
698
+ $KRED_ISO639_CH = 21; // Chamorro
699
+ global $KRED_ISO639_CO;
700
+ $KRED_ISO639_CO = 22; // Corsican
701
+ global $KRED_ISO639_CS;
702
+ $KRED_ISO639_CS = 23; // Czech
703
+ global $KRED_ISO639_CU;
704
+ $KRED_ISO639_CU = 24; // Church Slavic
705
+ global $KRED_ISO639_CV;
706
+ $KRED_ISO639_CV = 25; // Chuvash
707
+ global $KRED_ISO639_CY;
708
+ $KRED_ISO639_CY = 26; // Welsh
709
+ global $KRED_ISO639_DA;
710
+ $KRED_ISO639_DA = 27; // Danish
711
+ global $KRED_ISO639_DE;
712
+ $KRED_ISO639_DE = 28; // German
713
+ global $KRED_ISO639_DZ;
714
+ $KRED_ISO639_DZ = 29; // Dzongkha; Bhutani
715
+ global $KRED_ISO639_EL;
716
+ $KRED_ISO639_EL = 30; // Greek
717
+ global $KRED_ISO639_EN;
718
+ $KRED_ISO639_EN = 31; // English
719
+ global $KRED_ISO639_EO;
720
+ $KRED_ISO639_EO = 32; // Esperanto
721
+ global $KRED_ISO639_ES;
722
+ $KRED_ISO639_ES = 33; // Spanish
723
+ global $KRED_ISO639_ET;
724
+ $KRED_ISO639_ET = 34; // Estonian
725
+ global $KRED_ISO639_EU;
726
+ $KRED_ISO639_EU = 35; // Basque
727
+ global $KRED_ISO639_FA;
728
+ $KRED_ISO639_FA = 36; // Persian
729
+ global $KRED_ISO639_FI;
730
+ $KRED_ISO639_FI = 37; // Finnish
731
+ global $KRED_ISO639_FJ;
732
+ $KRED_ISO639_FJ = 38; // Fijian; Fiji
733
+ global $KRED_ISO639_FO;
734
+ $KRED_ISO639_FO = 39; // Faroese
735
+ global $KRED_ISO639_FR;
736
+ $KRED_ISO639_FR = 40; // French
737
+ global $KRED_ISO639_FY;
738
+ $KRED_ISO639_FY = 41; // Frisian
739
+ global $KRED_ISO639_GA;
740
+ $KRED_ISO639_GA = 42; // Irish
741
+ global $KRED_ISO639_GD;
742
+ $KRED_ISO639_GD = 43; // Scots; Gaelic
743
+ global $KRED_ISO639_GL;
744
+ $KRED_ISO639_GL = 44; // Gallegan; Galician
745
+ global $KRED_ISO639_GN;
746
+ $KRED_ISO639_GN = 45; // Guarani
747
+ global $KRED_ISO639_GU;
748
+ $KRED_ISO639_GU = 46; // Gujarati
749
+ global $KRED_ISO639_GV;
750
+ $KRED_ISO639_GV = 47; // Manx
751
+ global $KRED_ISO639_HA;
752
+ $KRED_ISO639_HA = 48; // Hausa (?)
753
+ global $KRED_ISO639_HE;
754
+ $KRED_ISO639_HE = 49; // Hebrew (formerly iw)
755
+ global $KRED_ISO639_HI;
756
+ $KRED_ISO639_HI = 50; // Hindi
757
+ global $KRED_ISO639_HO;
758
+ $KRED_ISO639_HO = 51; // Hiri Motu
759
+ global $KRED_ISO639_HR;
760
+ $KRED_ISO639_HR = 52; // Croatian
761
+ global $KRED_ISO639_HU;
762
+ $KRED_ISO639_HU = 53; // Hungarian
763
+ global $KRED_ISO639_HY;
764
+ $KRED_ISO639_HY = 54; // Armenian
765
+ global $KRED_ISO639_HZ;
766
+ $KRED_ISO639_HZ = 55; // Herero
767
+ global $KRED_ISO639_IA;
768
+ $KRED_ISO639_IA = 56; // Interlingua
769
+ global $KRED_ISO639_ID;
770
+ $KRED_ISO639_ID = 57; // Indonesian (formerly in)
771
+ global $KRED_ISO639_IE;
772
+ $KRED_ISO639_IE = 58; // Interlingue
773
+ global $KRED_ISO639_IK;
774
+ $KRED_ISO639_IK = 59; // Inupiak
775
+ global $KRED_ISO639_IO;
776
+ $KRED_ISO639_IO = 60; // Ido
777
+ global $KRED_ISO639_IS;
778
+ $KRED_ISO639_IS = 61; // Icelandic
779
+ global $KRED_ISO639_IT;
780
+ $KRED_ISO639_IT = 62; // Italian
781
+ global $KRED_ISO639_IU;
782
+ $KRED_ISO639_IU = 63; // Inuktitut
783
+ global $KRED_ISO639_JA;
784
+ $KRED_ISO639_JA = 64; // Japanese
785
+ global $KRED_ISO639_JV;
786
+ $KRED_ISO639_JV = 65; // Javanese
787
+ global $KRED_ISO639_KA;
788
+ $KRED_ISO639_KA = 66; // Georgian
789
+ global $KRED_ISO639_KI;
790
+ $KRED_ISO639_KI = 67; // Kikuyu
791
+ global $KRED_ISO639_KJ;
792
+ $KRED_ISO639_KJ = 68; // Kuanyama
793
+ global $KRED_ISO639_KK;
794
+ $KRED_ISO639_KK = 69; // Kazakh
795
+ global $KRED_ISO639_KL;
796
+ $KRED_ISO639_KL = 70; // Kalaallisut; Greenlandic
797
+ global $KRED_ISO639_KM;
798
+ $KRED_ISO639_KM = 71; // Khmer; Cambodian
799
+ global $KRED_ISO639_KN;
800
+ $KRED_ISO639_KN = 72; // Kannada
801
+ global $KRED_ISO639_KO;
802
+ $KRED_ISO639_KO = 73; // Korean
803
+ global $KRED_ISO639_KS;
804
+ $KRED_ISO639_KS = 74; // Kashmiri
805
+ global $KRED_ISO639_KU;
806
+ $KRED_ISO639_KU = 75; // Kurdish
807
+ global $KRED_ISO639_KV;
808
+ $KRED_ISO639_KV = 76; // Komi
809
+ global $KRED_ISO639_KW;
810
+ $KRED_ISO639_KW = 77; // Cornish
811
+ global $KRED_ISO639_KY;
812
+ $KRED_ISO639_KY = 78; // Kirghiz
813
+ global $KRED_ISO639_LA;
814
+ $KRED_ISO639_LA = 79; // Latin
815
+ global $KRED_ISO639_LB;
816
+ $KRED_ISO639_LB = 80; // Letzeburgesch
817
+ global $KRED_ISO639_LN;
818
+ $KRED_ISO639_LN = 81; // Lingala
819
+ global $KRED_ISO639_LO;
820
+ $KRED_ISO639_LO = 82; // Lao; Laotian
821
+ global $KRED_ISO639_LT;
822
+ $KRED_ISO639_LT = 83; // Lithuanian
823
+ global $KRED_ISO639_LV;
824
+ $KRED_ISO639_LV = 84; // Latvian; Lettish
825
+ global $KRED_ISO639_MG;
826
+ $KRED_ISO639_MG = 85; // Malagasy
827
+ global $KRED_ISO639_MH;
828
+ $KRED_ISO639_MH = 86; // Marshall
829
+ global $KRED_ISO639_MI;
830
+ $KRED_ISO639_MI = 87; // Maori
831
+ global $KRED_ISO639_MK;
832
+ $KRED_ISO639_MK = 88; // Macedonian
833
+ global $KRED_ISO639_ML;
834
+ $KRED_ISO639_ML = 89; // Malayalam
835
+ global $KRED_ISO639_MN;
836
+ $KRED_ISO639_MN = 90; // Mongolian
837
+ global $KRED_ISO639_MO;
838
+ $KRED_ISO639_MO = 91; // Moldavian
839
+ global $KRED_ISO639_MR;
840
+ $KRED_ISO639_MR = 92; // Marathi
841
+ global $KRED_ISO639_MS;
842
+ $KRED_ISO639_MS = 93; // Malay
843
+ global $KRED_ISO639_MT;
844
+ $KRED_ISO639_MT = 94; // Maltese
845
+ global $KRED_ISO639_MY;
846
+ $KRED_ISO639_MY = 95; // Burmese
847
+ global $KRED_ISO639_NA;
848
+ $KRED_ISO639_NA = 96; // Nauru
849
+ global $KRED_ISO639_NB;
850
+ $KRED_ISO639_NB = 97; // Norwegian Bokm�l
851
+ global $KRED_ISO639_ND;
852
+ $KRED_ISO639_ND = 98; // Ndebele, North
853
+ global $KRED_ISO639_NE;
854
+ $KRED_ISO639_NE = 99; // Nepali
855
+ global $KRED_ISO639_NG;
856
+ $KRED_ISO639_NG = 100; // Ndonga
857
+ global $KRED_ISO639_NL;
858
+ $KRED_ISO639_NL = 101; // Dutch
859
+ global $KRED_ISO639_NN;
860
+ $KRED_ISO639_NN = 102; // Norwegian Nynorsk
861
+ global $KRED_ISO639_NO;
862
+ $KRED_ISO639_NO = 103; // Norwegian
863
+ global $KRED_ISO639_NR;
864
+ $KRED_ISO639_NR = 104; // Ndebele, South
865
+ global $KRED_ISO639_NV;
866
+ $KRED_ISO639_NV = 105; // Navajo
867
+ global $KRED_ISO639_NY;
868
+ $KRED_ISO639_NY = 106; // Chichewa; Nyanja
869
+ global $KRED_ISO639_OC;
870
+ $KRED_ISO639_OC = 107; // Occitan; Proven�al
871
+ global $KRED_ISO639_OM;
872
+ $KRED_ISO639_OM = 108; // (Afan) Oromo
873
+ global $KRED_ISO639_OR;
874
+ $KRED_ISO639_OR = 109; // Oriya
875
+ global $KRED_ISO639_OS;
876
+ $KRED_ISO639_OS = 110; // Ossetian; Ossetic
877
+ global $KRED_ISO639_PA;
878
+ $KRED_ISO639_PA = 111; // Panjabi; Punjabi
879
+ global $KRED_ISO639_PI;
880
+ $KRED_ISO639_PI = 112; // Pali
881
+ global $KRED_ISO639_PL;
882
+ $KRED_ISO639_PL = 113; // Polish
883
+ global $KRED_ISO639_PS;
884
+ $KRED_ISO639_PS = 114; // Pashto, Pushto
885
+ global $KRED_ISO639_PT;
886
+ $KRED_ISO639_PT = 115; // Portuguese
887
+ global $KRED_ISO639_QU;
888
+ $KRED_ISO639_QU = 116; // Quechua
889
+ global $KRED_ISO639_RM;
890
+ $KRED_ISO639_RM = 117; // Rhaeto-Romance
891
+ global $KRED_ISO639_RN;
892
+ $KRED_ISO639_RN = 118; // Rundi; Kirundi
893
+ global $KRED_ISO639_RO;
894
+ $KRED_ISO639_RO = 119; // Romanian
895
+ global $KRED_ISO639_RU;
896
+ $KRED_ISO639_RU = 120; // Russian
897
+ global $KRED_ISO639_RW;
898
+ $KRED_ISO639_RW = 121; // Kinyarwanda
899
+ global $KRED_ISO639_SA;
900
+ $KRED_ISO639_SA = 122; // Sanskrit
901
+ global $KRED_ISO639_SC;
902
+ $KRED_ISO639_SC = 123; // Sardinian
903
+ global $KRED_ISO639_SD;
904
+ $KRED_ISO639_SD = 124; // Sindhi
905
+ global $KRED_ISO639_SE;
906
+ $KRED_ISO639_SE = 125; // Northern Sami
907
+ global $KRED_ISO639_SG;
908
+ $KRED_ISO639_SG = 126; // Sango; Sangro
909
+ global $KRED_ISO639_SI;
910
+ $KRED_ISO639_SI = 127; // Sinhalese
911
+ global $KRED_ISO639_SK;
912
+ $KRED_ISO639_SK = 128; // Slovak
913
+ global $KRED_ISO639_SL;
914
+ $KRED_ISO639_SL = 129; // Slovenian
915
+ global $KRED_ISO639_SM;
916
+ $KRED_ISO639_SM = 130; // Samoan
917
+ global $KRED_ISO639_SN;
918
+ $KRED_ISO639_SN = 131; // Shona
919
+ global $KRED_ISO639_SO;
920
+ $KRED_ISO639_SO = 132; // Somali
921
+ global $KRED_ISO639_SQ;
922
+ $KRED_ISO639_SQ = 133; // Albanian
923
+ global $KRED_ISO639_SR;
924
+ $KRED_ISO639_SR = 134; // Serbian
925
+ global $KRED_ISO639_SS;
926
+ $KRED_ISO639_SS = 135; // Swati; Siswati
927
+ global $KRED_ISO639_ST;
928
+ $KRED_ISO639_ST = 136; // Sesotho; Sotho, Southern
929
+ global $KRED_ISO639_SU;
930
+ $KRED_ISO639_SU = 137; // Sundanese
931
+ global $KRED_ISO639_SV;
932
+ $KRED_ISO639_SV = 138; // Swedish
933
+ global $KRED_ISO639_SW;
934
+ $KRED_ISO639_SW = 139; // Swahili
935
+ global $KRED_ISO639_TA;
936
+ $KRED_ISO639_TA = 140; // Tamil
937
+ global $KRED_ISO639_TE;
938
+ $KRED_ISO639_TE = 141; // Telugu
939
+ global $KRED_ISO639_TG;
940
+ $KRED_ISO639_TG = 142; // Tajik
941
+ global $KRED_ISO639_TH;
942
+ $KRED_ISO639_TH = 143; // Thai
943
+ global $KRED_ISO639_TI;
944
+ $KRED_ISO639_TI = 144; // Tigrinya
945
+ global $KRED_ISO639_TK;
946
+ $KRED_ISO639_TK = 145; // Turkmen
947
+ global $KRED_ISO639_TL;
948
+ $KRED_ISO639_TL = 146; // Tagalog
949
+ global $KRED_ISO639_TN;
950
+ $KRED_ISO639_TN = 147; // Tswana; Setswana
951
+ global $KRED_ISO639_TO;
952
+ $KRED_ISO639_TO = 148; // Tonga (?)
953
+ global $KRED_ISO639_TR;
954
+ $KRED_ISO639_TR = 149; // Turkish
955
+ global $KRED_ISO639_TS;
956
+ $KRED_ISO639_TS = 150; // Tsonga
957
+ global $KRED_ISO639_TT;
958
+ $KRED_ISO639_TT = 151; // Tatar
959
+ global $KRED_ISO639_TW;
960
+ $KRED_ISO639_TW = 152; // Twi
961
+ global $KRED_ISO639_TY;
962
+ $KRED_ISO639_TY = 153; // Tahitian
963
+ global $KRED_ISO639_UG;
964
+ $KRED_ISO639_UG = 154; // Uighur
965
+ global $KRED_ISO639_UK;
966
+ $KRED_ISO639_UK = 155; // Ukrainian
967
+ global $KRED_ISO639_UR;
968
+ $KRED_ISO639_UR = 156; // Urdu
969
+ global $KRED_ISO639_UZ;
970
+ $KRED_ISO639_UZ = 157; // Uzbek
971
+ global $KRED_ISO639_VI;
972
+ $KRED_ISO639_VI = 158; // Vietnamese
973
+ global $KRED_ISO639_VO;
974
+ $KRED_ISO639_VO = 159; // Volapuk
975
+ global $KRED_ISO639_WA;
976
+ $KRED_ISO639_WA = 160; // Walloon
977
+ global $KRED_ISO639_WO;
978
+ $KRED_ISO639_WO = 161; // Wolof
979
+ global $KRED_ISO639_XH;
980
+ $KRED_ISO639_XH = 162; // Xhosa
981
+ global $KRED_ISO639_YI;
982
+ $KRED_ISO639_YI = 163; // Yiddish (formerly ji)
983
+ global $KRED_ISO639_YO;
984
+ $KRED_ISO639_YO = 164; // Yoruba
985
+ global $KRED_ISO639_ZA;
986
+ $KRED_ISO639_ZA = 165; // Zhuang
987
+ global $KRED_ISO639_ZH;
988
+ $KRED_ISO639_ZH = 166; // Chinese
989
+ global $KRED_ISO639_ZU;
990
+ $KRED_ISO639_ZU = 167; // Zulu
991
+
992
+ global $KRED_ANNUITY_PCLASS;
993
+ $KRED_ANNUITY_PCLASS = 0;
994
+ global $KRED_DIVISOR_PCLASS;
995
+ $KRED_DIVISOR_PCLASS = 1;
996
+ global $KRED_FIXED_PCLASS;
997
+ $KRED_FIXED_PCLASS = 2;
998
+
999
+ /*
1000
+ * Select available klarnaPaymentModule host
1001
+ */
1002
+ /*
1003
+ * Do an xmlrpc call to Klarna.
1004
+ */
1005
+
1006
+ function kred_call($function, $paramList, &$result, $eid = "", $secret = "") {
1007
+ global $PROTO_VSN;
1008
+ global $CLIENT_VSN;
1009
+ global $XMLRPC_LIB;
1010
+ global $KREDITOR_PORT;
1011
+ global $KREDITOR_HOST;
1012
+
1013
+ $timestart = @microtime(true);
1014
+
1015
+ $return = '';
1016
+ $params = array($PROTO_VSN, $CLIENT_VSN);
1017
+
1018
+ while (list(, $v) = each($paramList)) {
1019
+ $params[] = $v;
1020
+ }
1021
+
1022
+ switch ($XMLRPC_LIB) {
1023
+ case "EPI":
1024
+ $xmlRequest = xmlrpc_encode_request($function, $params);
1025
+ $selectDateTime = @microtime(true);
1026
+ $xmlResponse = xmlrpc_call($KREDITOR_HOST, $KREDITOR_PORT, $xmlRequest);
1027
+ $xmlResponse =
1028
+ substr($xmlResponse, strpos($xmlResponse, "\r\n\r\n") + 4);
1029
+ $response = xmlrpc_decode($xmlResponse);
1030
+
1031
+ if ($response == NULL) {
1032
+ // xmlrpc_decode may not handle faultCode/faultString
1033
+ if (preg_match("<methodResponse><fault><value><struct><member><name>faultCode</name><value><int>(-?[0-9]+)</int></value></member><member><name>faultString</name><value><string>([^<]*)</string></value></member></struct></value></fault></methodResponse>", $xmlResponse, $regs)) {
1034
+ $result = $regs[2];
1035
+ $return = $regs[1];
1036
+ } else {
1037
+ $result = $xmlResponse;
1038
+ $return = -99;
1039
+ }
1040
+ } else
1041
+ if (is_array($response)) {
1042
+ $result = $response["faultString"];
1043
+ $return = $response["faultCode"];
1044
+ } else {
1045
+ $result = $response;
1046
+ $return = 0;
1047
+ }
1048
+
1049
+ case "KPEAR":
1050
+ $parameterArray = array(XML_RPC_encode($params));
1051
+ $message = new XML_RPC_Message($function, $parameterArray);
1052
+ $message->setSendEncoding("ISO-8859-1");
1053
+ $client = new XML_RPC_Client("/", $KREDITOR_HOST, $KREDITOR_PORT);
1054
+ //$client->setDebug(1);
1055
+ $selectDateTime = @microtime(true);
1056
+ $response = $client->send($message);
1057
+
1058
+ if (is_int($response) && ($response == 0)) {
1059
+ $result = $client->errstr;
1060
+ $return = -99;
1061
+ } else
1062
+ $faultCode = $response->faultCode();
1063
+
1064
+ if ($faultCode != 0) {
1065
+ $result = $response->faultString();
1066
+ $return = $faultCode;
1067
+ } else {
1068
+ $result = XML_RPC_decode($response->value());
1069
+ $return = 0;
1070
+ }
1071
+
1072
+ break;
1073
+ default:
1074
+
1075
+ $selectDateTime = @microtime(true);
1076
+ $result = "Unknown XMLRPC library: " . $XMLRPC_LIB;
1077
+ $return = -99;
1078
+
1079
+ break;
1080
+ }
1081
+
1082
+ $timeend = @microtime(true);
1083
+
1084
+ $time = (int) (($selectDateTime - $timestart)*1000);
1085
+ $selectTime = (int) (($timeend - $timestart)*1000);
1086
+
1087
+ $Url = $KREDITOR_HOST . ":" . $KREDITOR_PORT;
1088
+ @send_stat($eid, $function, $time, $selectTime, $return, $Url, $secret);
1089
+
1090
+ return $return;
1091
+ }
1092
+
1093
+ /**
1094
+ *
1095
+ * @param int $eid Store id.
1096
+ * @param string $function the name of the function that is sent
1097
+ * @param string $time ???
1098
+ * @param string $selectTime ???
1099
+ * @param string $Status Transaction Result
1100
+ * @param string $Url the URL that is contact with in the transaction moment, beta-test.klarna.com or payment.klarna.com
1101
+ * @param string $secret Shared secret used to confirm the integrity of the store.
1102
+ */
1103
+ function send_stat($eid, $function, $time, $selectTime, $Status, $Url, $secret) {
1104
+ $client_sendstats_host = 'udp://clientstat.kreditor.se';
1105
+ $client_sendstats_port = '80';
1106
+
1107
+ $fp = @fsockopen($client_sendstats_host, $client_sendstats_port, $errno, $errstr, 1500);
1108
+
1109
+ if ($fp) {
1110
+
1111
+ $data = "";
1112
+ $checksum = "";
1113
+ $data .= $eid . '|';
1114
+ $checksum .= $eid . '|';
1115
+ $data .= $function . '|';
1116
+ $checksum .= $function . '|';
1117
+ $data .= $time . '|';
1118
+ $checksum .= $time . '|';
1119
+ $data .= $selectTime . '|';
1120
+ $checksum .= $selectTime . '|';
1121
+ $data .= $Status . '|';
1122
+ $checksum .= $Status . '|';
1123
+ $data .= $Url . '|';
1124
+ $checksum .= $Url . '|';
1125
+ $checksum .= $secret;
1126
+ $digest = md5_base64($checksum);
1127
+ $data .= $digest;
1128
+
1129
+ @fwrite($fp, $data);
1130
+ @fclose($fp);
1131
+ }
1132
+ }
1133
+
1134
+ /*
1135
+ * API: activate_invoice
1136
+ */
1137
+
1138
+ function activate_invoice($eid, $invno, $secret, &$result) {
1139
+ our_settype_integer($eid);
1140
+ our_settype_string($invno);
1141
+ our_settype_string($secret);
1142
+ $digestSecret = invoice_digest($eid, $invno, $secret);
1143
+ $paramList = array($eid, $invno, $digestSecret);
1144
+ return kred_call("activate_invoice", $paramList, $result);
1145
+ }
1146
+
1147
+ /*
1148
+ * API: activate_part
1149
+ */
1150
+ function mk_artno($qty, $artno) {
1151
+ our_settype_integer($qty);
1152
+ our_settype_string($artno);
1153
+ return array("artno" => $artno, "qty" => $qty);
1154
+ }
1155
+
1156
+ function activate_part($eid, $invno, $artnos, $secret, &$result) {
1157
+ our_settype_integer($eid);
1158
+ our_settype_string($invno);
1159
+ our_settype_string($secret);
1160
+ $digestSecret = activate_part_digest($eid, $invno, $artnos, $secret);
1161
+ $paramList = array($eid, $invno, $artnos, $digestSecret);
1162
+ return kred_call("activate_part", $paramList, $result);
1163
+ }
1164
+
1165
+ /*
1166
+ * API: invoice_part_amount
1167
+ */
1168
+ function invoice_part_amount($eid, $invno, $artnos, $secret, &$result) {
1169
+ our_settype_integer($eid);
1170
+ our_settype_string($invno);
1171
+ our_settype_string($secret);
1172
+ our_settype_integer($amount);
1173
+ $digestSecret = activate_part_digest($eid, $invno, $artnos, $secret);
1174
+ $paramList = array($eid, $invno, $artnos, $digestSecret);
1175
+ return kred_call("invoice_part_amount", $paramList, $result);
1176
+ }
1177
+
1178
+ /*
1179
+ * API: send_invoice
1180
+ */
1181
+
1182
+ function send_invoice($eid, $invno, $secret, &$result) {
1183
+ our_settype_integer($eid);
1184
+ our_settype_string($invno);
1185
+ our_settype_string($secret);
1186
+ $digestSecret = invoice_digest($eid, $invno, $secret);
1187
+ $paramList = array($eid, $invno, $digestSecret);
1188
+ return kred_call("send_invoice", $paramList, $result);
1189
+ }
1190
+
1191
+ /*
1192
+ * API: email_invoice
1193
+ */
1194
+
1195
+ function email_invoice($eid, $invno, $secret, &$result, $eid, $secret) {
1196
+ our_settype_integer($eid);
1197
+ our_settype_string($invno);
1198
+ our_settype_string($secret);
1199
+ $digestSecret = invoice_digest($eid, $invno, $secret);
1200
+ $paramList = array($eid, $invno, $digestSecret);
1201
+ return kred_call("email_invoice", $paramList, $result);
1202
+ }
1203
+
1204
+ // has account
1205
+ function has_account($eid, $pno, $secret, $pno_encoding, &$result)
1206
+ {
1207
+ our_settype_integer($eid);
1208
+ our_strip_string($pno);
1209
+ our_settype_string($secret);
1210
+ our_settype_integer($pno_encoding);
1211
+
1212
+ $digest = invoice_digest($eid, $pno, $secret);
1213
+
1214
+ return kred_call("has_account", array($eid, $pno, $digest, $pno_encoding), $result);
1215
+ }
1216
+
1217
+ // CHECK_RESERVATION
1218
+ function check_reservation($eid, $rno, $amount, $address, $secret, $pno, &$result) {
1219
+
1220
+ our_settype_integer($eid);
1221
+ our_settype_string($rno);
1222
+ our_settype_integer($amount);
1223
+ our_settype_string($secret);
1224
+ our_settype_integer($pno_encoding);
1225
+ $digest = periodic_cost_digest($eid,$rno,$amount,$secret);
1226
+
1227
+ return kred_call("check_reservation", array($eid, $rno, $amount, $address, $digest, $pno), $result);
1228
+
1229
+ }
1230
+
1231
+ /*
1232
+ * API: mk_goods
1233
+ */
1234
+
1235
+ function mk_goods($qty, $artno, $title, $price, $vat, $discount) {
1236
+ our_settype_integer($qty);
1237
+ our_settype_string($artno);
1238
+ our_settype_string($title);
1239
+ our_settype_integer($price);
1240
+ settype($vat, "double");
1241
+ settype($discount, "double");
1242
+ return array("goods" => array("artno" => $artno,
1243
+ "title" => $title,
1244
+ "price" => $price,
1245
+ "vat" => $vat,
1246
+ "discount" => $discount),
1247
+ "qty" => $qty);
1248
+ }
1249
+
1250
+ function mk_goods_flags($qty, $artno, $title, $price, $vat, $discount, $flags){
1251
+ our_settype_integer($qty);
1252
+ our_settype_integer($flags);
1253
+ our_settype_string($artno);
1254
+ our_settype_string($title);
1255
+ our_settype_integer($price);
1256
+ settype($vat, "double");
1257
+ settype($discount, "double");
1258
+ return array("goods" => array("artno" => $artno,
1259
+ "title" => $title,
1260
+ "price" => $price,
1261
+ "vat" => $vat,
1262
+ "discount" => $discount,
1263
+ "flags" => $flags),
1264
+ "qty" => $qty);
1265
+ }
1266
+
1267
+ /*
1268
+ * API: mk_address(for reserve_amount)
1269
+ */
1270
+
1271
+ function mk_address_se($fname, $lname, $street, $postno, $city) {
1272
+ return mk_address($fname, $lname, $street, $postno, $city, "se", "", "");
1273
+ }
1274
+
1275
+ function mk_address_no($fname, $lname, $street, $postno, $city) {
1276
+ return mk_address($fname, $lname, $street, $postno, $city, "no", "", "");
1277
+ }
1278
+
1279
+ function mk_address_dk($fname, $lname, $street, $postno, $city) {
1280
+ return mk_address($fname, $lname, $street, $postno, $city, "dk", "", "");
1281
+ }
1282
+
1283
+ function mk_address_fi($fname, $lname, $street, $postno, $city) {
1284
+ return mk_address($fname, $lname, $street, $postno, $city, "fi", "", "");
1285
+ }
1286
+
1287
+ function mk_address_de($fname, $lname, $street, $postno, $city, $housenumber) {
1288
+ return mk_address($fname, $lname, $street, $postno, $city, "de", $housenumber, "");
1289
+ }
1290
+
1291
+ function mk_address_nl($fname, $lname, $street, $postno, $city, $housenumber, $houseextension) {
1292
+ return mk_address($fname, $lname, $street, $postno, $city, "nl", $housenumber, $houseextension);
1293
+ }
1294
+
1295
+ function mk_address($fname, $lname, $street, $postno, $city, $country, $housenumber = "", $houseextension = "") {
1296
+ our_settype_string($fname);
1297
+ our_settype_string($lname);
1298
+ our_settype_string($street);
1299
+ our_settype_string($postno);
1300
+ our_settype_string($city);
1301
+ our_settype_string($country);
1302
+ our_settype_string($housenumber);
1303
+ our_settype_string($houseextension);
1304
+ return array("fname" => $fname,
1305
+ "lname" => $lname,
1306
+ "street" => $street,
1307
+ "zip" => $postno,
1308
+ "city" => $city,
1309
+ "country" => $country,
1310
+ "house_number" => $housenumber,
1311
+ "house_extension" => $houseextension);
1312
+
1313
+ }
1314
+
1315
+ /*
1316
+ * API: mk_addr(for add_transaction)
1317
+ */
1318
+
1319
+ function mk_addr_se($careof, $street, $postno, $city, $telno, $cellno, $email){
1320
+ global $KRED_ISO3166_SE;
1321
+ return mk_addr($careof, $street, $postno, $city, $KRED_ISO3166_SE, $telno,
1322
+ $cellno, $email, "", "");
1323
+ }
1324
+
1325
+ function mk_addr_no($careof, $street, $postno, $city, $telno, $cellno, $email){
1326
+ global $KRED_ISO3166_NO;
1327
+ return mk_addr($careof, $street, $postno, $city, $KRED_ISO3166_NO, $telno,
1328
+ $cellno, $email, "", "");
1329
+ }
1330
+
1331
+
1332
+ function mk_addr_dk($careof, $street, $postno, $city, $telno, $cellno, $email){
1333
+ global $KRED_ISO3166_DK;
1334
+ return mk_addr($careof, $street, $postno, $city, $KRED_ISO3166_DK, $telno,
1335
+ $cellno, $email, "", "");
1336
+ }
1337
+
1338
+ function mk_addr_fi($careof, $street, $postno, $city, $telno, $cellno, $email){
1339
+ global $KRED_ISO3166_FI;
1340
+ return mk_addr($careof, $street, $postno, $city, $KRED_ISO3166_FI, $telno,
1341
+ $cellno, $email, "", "");
1342
+ }
1343
+
1344
+ function mk_addr_de($careof, $street, $postno, $city, $telno, $cellno, $email, $housenumber){
1345
+ global $KRED_ISO3166_DE;
1346
+ return mk_addr($careof, $street, $postno, $city, $KRED_ISO3166_DE, $telno,
1347
+ $cellno, $email, $housenumber, "");
1348
+ }
1349
+
1350
+ function mk_addr_nl($careof, $street, $postno, $city, $telno, $cellno, $email, $housenumber, $houseextension){
1351
+ global $KRED_ISO3166_NL;
1352
+ return mk_addr($careof, $street, $postno, $city, $KRED_ISO3166_NL, $telno,
1353
+ $cellno, $email, $housenumber, $houseextension);
1354
+ }
1355
+
1356
+ function mk_addr($careof, $street, $postno, $city, $country, $telno, $cellno,
1357
+ $email, $housenumber = "", $houseextension = "") {
1358
+ our_settype_string($careof);
1359
+ our_settype_string($street);
1360
+
1361
+ if($country == 154)
1362
+ our_settype_string($postno);
1363
+ else
1364
+ our_settype_integer($postno);
1365
+
1366
+ our_settype_string($city);
1367
+ our_settype_integer($country);
1368
+ our_settype_string($telno);
1369
+ our_settype_string($cellno);
1370
+ our_settype_string($email);
1371
+ our_settype_string($housenumber);
1372
+ our_settype_string($houseextension);
1373
+ return array("careof" => $careof,
1374
+ "street" => $street,
1375
+ "postno" => $postno,
1376
+ "city" => $city,
1377
+ "country" => $country,
1378
+ "telno" => $telno,
1379
+ "cellno" => $cellno,
1380
+ "email" => $email,
1381
+ "house_number" => $housenumber,
1382
+ "house_extension" => $houseextension);
1383
+ }
1384
+
1385
+ function apr_annuity($sum, $months, $monthfee, $rate, $startfee, $curr, &$result)
1386
+ {
1387
+ $r_min; $r_max; $r_guess; $apr_sum; $precision; $period_cost; $resp;
1388
+ $precision = 0.001;
1389
+
1390
+ $r_guess = 50.00; // we guess rate is somewhere (below) this value (for faster iteration)
1391
+ $r_min = 0.0; //lower limit is 0%
1392
+ $r_max = 10000.0; // upper limit. The value we are looking for should be way lower
1393
+
1394
+ $period_cost = total_monthly_cost($sum, $months, $monthfee, $rate, $startfee, $curr);
1395
+
1396
+ $apr_sum = 0;
1397
+
1398
+ for($i = 0; $i < 1000; $i++)
1399
+ {
1400
+ $apr_sum = 0;
1401
+
1402
+ for($k = 1; $k < $months + 1; $k++)
1403
+ $apr_sum = $apr_sum + $period_cost / pow((1 + $r_guess / 100),((double)($k / 12)));
1404
+
1405
+ if ($apr_sum + $precision > $sum && $apr_sum - $precision < $sum)
1406
+ {
1407
+ $result = $r_guess * 100;
1408
+ }
1409
+ elseif ($apr_sum > $sum)
1410
+ $r_min = $r_guess;
1411
+ else
1412
+ $r_max = $r_guess;
1413
+
1414
+ $r_guess = ($r_min + $r_max) / 2;
1415
+ }
1416
+ }
1417
+
1418
+ // new function
1419
+ function total_credit_purchase_cost($sum, $pc, $cur, &$result)
1420
+ {
1421
+ global $KRED_SEK, $KRED_NOK, $KRED_EUR, $KRED_DKK,$KRED_DIVISOR_PCLASS, $KRED_ANNUITY_PCLASS;
1422
+ if (($cur == $KRED_NOK) && (get_type($pc) == $KRED_DIVISOR_PCLASS))
1423
+ $months = 12;
1424
+ else
1425
+ $months = get_months($pc);
1426
+
1427
+
1428
+ $monthfee = get_month_fee($pc);
1429
+ $startfee = get_start_fee($pc);
1430
+ $rate = get_rate($pc);
1431
+
1432
+ $result = $months * total_monthly_cost($sum, $months, $monthfee, $rate, $startfee, $cur);
1433
+ }
1434
+
1435
+ /* Calculates the total monthly cost (annuity payments) i.e the cost per
1436
+ ' month including all fees, the purchase sum and interest, taking account:
1437
+ '- that the startfee is paid at the first payment (with no interest) and
1438
+ ' - the monthly fee is paid with every payment before any amortizing is done.
1439
+ ' This cost should be as close as possible as the real cost will be.*/
1440
+ function total_monthly_cost($sum, $months, $monthfee, $rate, $startfee, $cur)
1441
+ {
1442
+ $sum_j_to_N = 0;
1443
+ // reference: Avbetalningsplaner.pdf
1444
+ $K0 = $sum;
1445
+ $A = $monthfee;
1446
+ $S = $startfee;
1447
+ $R = (pow(1.0+$rate/10000, 1.0/12.0));
1448
+ $N = $months;
1449
+ if ($rate == 0)
1450
+ $T = (1 / $N)*($K0 + ($N * $A) + $S);
1451
+ else
1452
+ {
1453
+ // the total cost of fees plus the cost of paying off the monthly fee first and after that amortize
1454
+ for ($j = 2; $j < $N+1; $j++)
1455
+ {
1456
+ $sum_j_to_N = $sum_j_to_N + pow($R, $N - $j) * $A;
1457
+ }
1458
+ $T = (($R - 1) / (pow($R, $N) - 1)) * (pow($R, $N) * $K0 + $sum_j_to_N + pow($R, $N - 1) * ($A + $S));
1459
+ }
1460
+
1461
+ return round($T, 0);
1462
+ }
1463
+
1464
+ /*
1465
+ * API: add_transaction
1466
+ */
1467
+
1468
+
1469
+ function add_transaction_se($eid, $estoreUser, $secret, $estoreOrderNo,
1470
+ $goodsList, $shipmentfee, $shipmenttype,
1471
+ $handlingfee, $pno, $fname, $lname, $addr, $passwd,
1472
+ $clientIp, $newPasswd, $flags, $comment,
1473
+ $ready_date, $rand_string, $pclass, $ysalary,
1474
+ &$result) {
1475
+ global $KRED_SE_PNO, $KRED_SEK, $KRED_ISO3166_SE, $KRED_ISO639_SV;
1476
+ return add_transaction($eid, $estoreUser, $secret, $estoreOrderNo,
1477
+ $goodsList, $shipmentfee, $shipmenttype,
1478
+ $handlingfee, $pno, $fname, $lname, $addr, $passwd,
1479
+ $clientIp, $newPasswd, $flags, $comment,
1480
+ $ready_date, $rand_string, $KRED_SEK,
1481
+ $KRED_ISO3166_SE, $KRED_ISO639_SV, $KRED_SE_PNO, $pclass,
1482
+ $ysalary, $result);
1483
+ }
1484
+
1485
+ function add_transaction_no($eid, $estoreUser, $secret, $estoreOrderNo,
1486
+ $goodsList, $shipmentfee, $shipmenttype,
1487
+ $handlingfee, $pno, $fname, $lname, $addr, $passwd,
1488
+ $clientIp, $newPasswd, $flags, $comment,
1489
+ $ready_date, $rand_string, $pclass, $ysalary,
1490
+ &$result) {
1491
+ global $KRED_NO_PNO, $KRED_NOK, $KRED_ISO3166_NO, $KRED_ISO639_NB;
1492
+ return add_transaction($eid, $estoreUser, $secret, $estoreOrderNo,
1493
+ $goodsList, $shipmentfee, $shipmenttype,
1494
+ $handlingfee, $pno, $fname, $lname, $addr, $passwd,
1495
+ $clientIp, $newPasswd, $flags, $comment,
1496
+ $ready_date, $rand_string, $KRED_NOK,
1497
+ $KRED_ISO3166_NO, $KRED_ISO639_NB, $KRED_NO_PNO, $pclass,
1498
+ $ysalary, $result);
1499
+ }
1500
+
1501
+
1502
+ function add_transaction_dk($eid, $estoreUser, $secret, $estoreOrderNo,
1503
+ $goodsList, $shipmentfee, $shipmenttype,
1504
+ $handlingfee, $pno, $fname, $lname, $addr, $passwd,
1505
+ $clientIp, $newPasswd, $flags, $comment,
1506
+ $ready_date, $rand_string, $pclass, $ysalary,
1507
+ &$result) {
1508
+ global $KRED_DK_PNO, $KRED_DKK, $KRED_ISO3166_DK, $KRED_ISO639_DA;
1509
+ return add_transaction($eid, $estoreUser, $secret, $estoreOrderNo,
1510
+ $goodsList, $shipmentfee, $shipmenttype,
1511
+ $handlingfee, $pno, $fname, $lname, $addr, $passwd,
1512
+ $clientIp, $newPasswd, $flags, $comment,
1513
+ $ready_date, $rand_string, $KRED_DKK,
1514
+ $KRED_ISO3166_DK, $KRED_ISO639_DA, $KRED_DK_PNO, $pclass,
1515
+ $ysalary, $result);
1516
+ }
1517
+
1518
+ function add_transaction_fi($eid, $estoreUser, $secret, $estoreOrderNo,
1519
+ $goodsList, $shipmentfee, $shipmenttype,
1520
+ $handlingfee, $pno, $fname, $lname, $addr, $passwd,
1521
+ $clientIp, $newPasswd, $flags, $comment,
1522
+ $ready_date, $rand_string, $pclass, $ysalary,
1523
+ &$result) {
1524
+ global $KRED_FI_PNO, $KRED_EUR, $KRED_ISO3166_FI, $KRED_ISO639_FI;
1525
+ return add_transaction($eid, $estoreUser, $secret, $estoreOrderNo,
1526
+ $goodsList, $shipmentfee, $shipmenttype,
1527
+ $handlingfee, $pno, $fname, $lname, $addr, $passwd,
1528
+ $clientIp, $newPasswd, $flags, $comment,
1529
+ $ready_date, $rand_string, $KRED_EUR,
1530
+ $KRED_ISO3166_FI, $KRED_ISO639_FI, $KRED_FI_PNO, $pclass,
1531
+ $ysalary, $result);
1532
+ }
1533
+
1534
+ function add_transaction_de($eid, $estoreUser, $secret, $estoreOrderNo,
1535
+ $goodsList, $shipmentfee, $shipmenttype,
1536
+ $handlingfee, $pno, $fname, $lname, $addr, $passwd,
1537
+ $clientIp, $newPasswd, $flags, $comment,
1538
+ $ready_date, $rand_string, $pclass, $ysalary,
1539
+ &$result) {
1540
+ global $KRED_DE_PNO, $KRED_EUR, $KRED_ISO3166_DE, $KRED_ISO639_DE;
1541
+ return add_transaction($eid, $estoreUser, $secret, $estoreOrderNo,
1542
+ $goodsList, $shipmentfee, $shipmenttype,
1543
+ $handlingfee, $pno, $fname, $lname, $addr, $passwd,
1544
+ $clientIp, $newPasswd, $flags, $comment,
1545
+ $ready_date, $rand_string, $KRED_EUR,
1546
+ $KRED_ISO3166_DE, $KRED_ISO639_DE, $KRED_DE_PNO, $pclass,
1547
+ $ysalary, $result);
1548
+ }
1549
+
1550
+ function add_transaction_nl($eid, $estoreUser, $secret, $estoreOrderNo,
1551
+ $goodsList, $shipmentfee, $shipmenttype,
1552
+ $handlingfee, $pno, $fname, $lname, $addr, $passwd,
1553
+ $clientIp, $newPasswd, $flags, $comment,
1554
+ $ready_date, $rand_string, $pclass, $ysalary,
1555
+ &$result) {
1556
+ global $KRED_NL_PNO, $KRED_EUR, $KRED_ISO3166_NL, $KRED_ISO639_NL;
1557
+ return add_transaction($eid, $estoreUser, $secret, $estoreOrderNo,
1558
+ $goodsList, $shipmentfee, $shipmenttype,
1559
+ $handlingfee, $pno, $fname, $lname, $addr, $passwd,
1560
+ $clientIp, $newPasswd, $flags, $comment,
1561
+ $ready_date, $rand_string, $KRED_EUR,
1562
+ $KRED_ISO3166_NL, $KRED_ISO639_NL, $KRED_NL_PNO, $pclass,
1563
+ $ysalary, $result);
1564
+ }
1565
+
1566
+ function add_transaction($eid, $estoreUser, $secret, $estoreOrderNo,$goodsList,
1567
+ $shipmentfee, $shipmenttype, $handlingfee, $pno,
1568
+ $fname, $lname, $addr, $passwd, $clientIp, $newPasswd,
1569
+ $flags, $comment, $ready_date, $rand_string,
1570
+ $currency, $country, $language, $pno_encoding,
1571
+ $pclass, $ysalary, &$result) {
1572
+ our_settype_integer($eid);
1573
+ our_settype_string($estoreUser);
1574
+ our_settype_string($secret);
1575
+ our_settype_string($estoreOrderNo);
1576
+ our_settype_integer($shipmentfee);
1577
+ our_settype_integer($shipmenttype);
1578
+ our_settype_integer($handlingfee);
1579
+ our_strip_string($pno);
1580
+ our_settype_string($fname);
1581
+ our_settype_string($lname);
1582
+ our_settype_string($passwd);
1583
+ our_settype_string($clientIp);
1584
+ our_settype_string($newPasswd);
1585
+ our_settype_integer($flags);
1586
+ settype($comment, "string");
1587
+ our_settype_string($ready_date);
1588
+ our_settype_integer($currency);
1589
+ our_settype_integer($country);
1590
+ our_settype_integer($language);
1591
+ our_settype_integer($pno_encoding);
1592
+ our_settype_integer($pclass);
1593
+ our_settype_integer($ysalary);
1594
+ $digestSecret = add_transaction_digest($goodsList, $secret);
1595
+ $paramList =
1596
+ array($eid, $estoreUser, $digestSecret,
1597
+ $estoreOrderNo, $goodsList, $shipmentfee, $shipmenttype,
1598
+ $handlingfee, $pno, $fname, $lname, $addr, $passwd, $clientIp,
1599
+ $newPasswd, $flags, $comment, $ready_date, $rand_string,
1600
+ $currency, $country, $language, $pno_encoding, $pclass, $ysalary);
1601
+ return kred_call("add_invoice", $paramList, $result);
1602
+ }
1603
+
1604
+ /*
1605
+ * API: invoice_address
1606
+ */
1607
+
1608
+ function invoice_address($eid, $invno, $secret, &$result) {
1609
+ our_settype_integer($eid);
1610
+ our_settype_string($invno);
1611
+ our_settype_string($secret);
1612
+ $digestSecret = invoice_digest($eid, $invno, $secret);
1613
+ $paramList = array($eid, $invno, $digestSecret);
1614
+ return kred_call("invoice_address", $paramList, $result);
1615
+ }
1616
+
1617
+ /*
1618
+ * API: invoice_amount
1619
+ */
1620
+
1621
+ function invoice_amount($eid, $invno, $secret, &$result) {
1622
+ our_settype_integer($eid);
1623
+ our_settype_string($invno);
1624
+ our_settype_string($secret);
1625
+ $digestSecret = invoice_digest($eid, $invno, $secret);
1626
+ $paramList = array($eid, $invno, $digestSecret);
1627
+ return kred_call("invoice_amount", $paramList, $result);
1628
+ }
1629
+
1630
+ /*
1631
+ * API: delete_invoice
1632
+ */
1633
+
1634
+ function delete_invoice($eid, $invno, $secret, &$result) {
1635
+ our_settype_integer($eid);
1636
+ our_settype_string($invno);
1637
+ our_settype_string($secret);
1638
+ $digestSecret = invoice_digest($eid, $invno, $secret);
1639
+ $paramList = array($eid, $invno, $digestSecret);
1640
+ return kred_call("delete_invoice", $paramList, $result);
1641
+ }
1642
+
1643
+ /*
1644
+ * API: return_invoice
1645
+ */
1646
+
1647
+ function return_invoice($eid, $invno, $secret, &$result) {
1648
+ our_settype_integer($eid);
1649
+ our_settype_string($invno);
1650
+ our_settype_string($secret);
1651
+ $digestSecret = invoice_digest($eid, $invno, $secret);
1652
+ $paramList = array($eid, $invno, $digestSecret);
1653
+ return kred_call("return_invoice", $paramList, $result);
1654
+ }
1655
+
1656
+ /*
1657
+ * API: credit_invoice
1658
+ */
1659
+
1660
+ function credit_invoice($eid, $invno, $credno, $secret, &$result) {
1661
+ our_settype_integer($eid);
1662
+ our_settype_string($invno);
1663
+ our_settype_string($credno);
1664
+ our_settype_string($secret);
1665
+ $digestSecret = invoice_digest($eid, $invno, $secret);
1666
+ $paramList = array($eid, $invno, $credno, $digestSecret);
1667
+ return kred_call("credit_invoice", $paramList, $result);
1668
+ }
1669
+
1670
+ /*
1671
+ * API: return_part
1672
+ */
1673
+
1674
+ function return_part($eid, $invno, $artnos, $secret, &$result) {
1675
+ our_settype_integer($eid);
1676
+ our_settype_string($invno);
1677
+ our_settype_string($secret);
1678
+ $digestSecret = activate_part_digest($eid, $invno, $artnos, $secret);
1679
+ $paramList = array($eid, $invno, $artnos, $digestSecret);
1680
+ return kred_call("return_part", $paramList, $result);
1681
+ }
1682
+
1683
+ /*
1684
+ * API: credit_part
1685
+ */
1686
+
1687
+ function credit_part($eid, $invno, $artnos, $credno, $secret, &$result) {
1688
+ our_settype_integer($eid);
1689
+ our_settype_string($invno);
1690
+ our_settype_string($credno);
1691
+ our_settype_string($secret);
1692
+ $digestSecret = activate_part_digest($eid, $invno, $artnos, $secret);
1693
+ $paramList = array($eid, $invno, $artnos, $credno, $digestSecret);
1694
+ return kred_call("credit_part", $paramList, $result);
1695
+ }
1696
+
1697
+ /*
1698
+ * API: return_amount
1699
+ */
1700
+
1701
+ function return_amount($eid, $invno, $amount, $vat, $secret, &$result) {
1702
+ our_settype_integer($eid);
1703
+ our_settype_string($invno);
1704
+ our_settype_integer($amount);
1705
+ settype($vat, "float");
1706
+ our_settype_string($secret);
1707
+ $digestSecret = invoice_digest($eid, $invno, $secret);
1708
+ $paramList = array($eid, $invno, $amount, $vat, $digestSecret);
1709
+ return kred_call("return_amount", $paramList, $result);
1710
+ }
1711
+
1712
+ /*
1713
+ * API: update_goods_qty
1714
+ */
1715
+
1716
+ function update_goods_qty($eid, $invno, $secret, $artno, $newQty, &$result) {
1717
+ our_settype_integer($eid);
1718
+ our_settype_string($invno);
1719
+ our_settype_string($secret);
1720
+ our_settype_string($artno);
1721
+ our_settype_integer($newQty);
1722
+ $digestSecret = update_goods_qty_digest($invno, $artno, $newQty, $secret);
1723
+ $paramList = array($eid, $digestSecret, $invno, $artno, $newQty);
1724
+ return kred_call("update_goods_qty", $paramList, $result);
1725
+ }
1726
+
1727
+ /*
1728
+ * API: update_charge_amount
1729
+ */
1730
+
1731
+ function update_charge_amount($eid, $invno, $secret, $type, $newAmount,
1732
+ &$result) {
1733
+ our_settype_integer($eid);
1734
+ our_settype_string($invno);
1735
+ our_settype_string($secret);
1736
+ our_settype_integer($type);
1737
+ our_settype_integer($newAmount);
1738
+ $digestSecret =
1739
+ update_charge_amount_digest($invno, $type, $newAmount, $secret);
1740
+ $paramList = array($eid, $digestSecret,
1741
+ $invno, $type, $newAmount);
1742
+ return kred_call("update_charge_amount", $paramList, $result);
1743
+ }
1744
+
1745
+ /*
1746
+ * API: update_orderno
1747
+ */
1748
+
1749
+ function update_orderno($eid, $invno, $secret, $estoreOrderNo, &$result) {
1750
+ our_settype_integer($eid);
1751
+ our_settype_string($secret);
1752
+ our_settype_string($invno);
1753
+ our_settype_string($estoreOrderNo);
1754
+ $digestSecret = update_orderno_digest($invno, $estoreOrderNo, $secret);
1755
+ $paramList = array($eid, $digestSecret, $invno, $estoreOrderNo);
1756
+ return kred_call("update_orderno", $paramList, $result);
1757
+ }
1758
+
1759
+
1760
+ /*
1761
+ * API: update_notes
1762
+ */
1763
+
1764
+ function update_notes($eid, $invno, $secret, $notes, &$result) {
1765
+ our_settype_integer($eid);
1766
+ our_settype_string($secret);
1767
+ our_settype_string($invno);
1768
+ our_settype_string($notes);
1769
+ $digestSecret = update_notes_digest($invno, $notes, $secret);
1770
+ $paramList = array($eid, $digestSecret, $invno, $notes);
1771
+ return kred_call("update_notes", $paramList, $result);
1772
+ }
1773
+
1774
+ /*
1775
+ * API: update_email
1776
+ */
1777
+
1778
+ function update_email($eid, $secret, $pno, $email, &$result) {
1779
+ our_settype_integer($eid);
1780
+ our_settype_string($secret);
1781
+ our_strip_string($pno);
1782
+ our_settype_string($email);
1783
+ $digestSecret = update_notes_digest($pno, $email, $secret);
1784
+ $paramList = array($eid, $digestSecret, $pno, $email);
1785
+ return kred_call("update_email", $paramList, $result);
1786
+ }
1787
+
1788
+ /*
1789
+ * API: get_addresses
1790
+ */
1791
+
1792
+ function get_addresses($eid, $pno, $secret, $pno_encoding, $type, &$result) {
1793
+ our_settype_integer($eid);
1794
+ our_settype_string($secret);
1795
+ our_strip_string($pno);
1796
+ our_settype_integer($pno_encoding);
1797
+ $digestSecret = pno_digest($eid, $pno, $secret);
1798
+ $paramList = array($pno, $eid, $digestSecret, $pno_encoding, $type);
1799
+ return kred_call("get_addresses", $paramList, $result);
1800
+ }
1801
+
1802
+ /*
1803
+ * API: reserve_amount
1804
+ */
1805
+
1806
+ function reserve_amount($pno, $amount, $reference, $referece_code, $orderid1,
1807
+ $orderid2, $lev_addr, $f_addr, $email, $phone, $cell,
1808
+ $client_ip, $flags, $currency, $country, $language,
1809
+ $eid, $secret, $pno_encoding, $pclass, $ysalary,
1810
+ $goodsList, &$result) {
1811
+ our_strip_string($pno);
1812
+ our_settype_integer($amount);
1813
+ settype($referece, "string");
1814
+ settype($referece_code, "string");
1815
+ our_settype_string($orderid1);
1816
+ our_settype_string($orderid2);
1817
+ our_settype_string($email);
1818
+ our_settype_string($phone);
1819
+ our_settype_string($cell);
1820
+ our_settype_string($client_ip);
1821
+ our_settype_integer($flags);
1822
+ our_settype_integer($currency);
1823
+ our_settype_integer($country);
1824
+ our_settype_integer($language);
1825
+ our_settype_integer($eid);
1826
+ our_settype_string($secret);
1827
+ our_settype_integer($pno_encoding);
1828
+ our_settype_integer($pclass);
1829
+ our_settype_integer($ysalary);
1830
+ $digestSecret = reserve_amount_digest($eid, $pno, $amount, $secret);
1831
+ $paramList = array($pno, $amount, $reference, $referece_code, $orderid1,
1832
+ $orderid2, $lev_addr, $f_addr, $email, $phone, $cell,
1833
+ $client_ip, $flags, $currency, $country, $language,
1834
+ $eid, $digestSecret, $pno_encoding, $pclass,
1835
+ $ysalary, $goodsList);
1836
+ return kred_call("reserve_amount", $paramList, $result);
1837
+ }
1838
+
1839
+
1840
+
1841
+ /*
1842
+ * API: cancel_reservation
1843
+ */
1844
+
1845
+ function cancel_reservation($rno, $eid, $secret, &$result) {
1846
+ our_settype_string($rno);
1847
+ our_settype_integer($eid);
1848
+ our_settype_string($secret);
1849
+ $digestSecret = ref_no_digest($eid, $rno, $secret);
1850
+ $paramList = array($rno, $eid, $digestSecret);
1851
+ return kred_call("cancel_reservation", $paramList, $result);
1852
+ }
1853
+
1854
+
1855
+
1856
+ /*
1857
+ * API: change_reservation
1858
+ */
1859
+
1860
+ function change_reservation($rno, $newAmount, $eid, $secret, $flags, &$result) {
1861
+ our_settype_string($rno);
1862
+ our_settype_integer($newAmount);
1863
+ our_settype_integer($eid);
1864
+ our_settype_string($secret);
1865
+ our_settype_integer($flags);
1866
+ $digestSecret = change_res_digest($eid, $rno, $newAmount, $secret);
1867
+ $paramList = array($rno, $newAmount, $eid, $digestSecret, $flags);
1868
+ return kred_call("change_reservation", $paramList, $result);
1869
+ }
1870
+
1871
+ /*
1872
+ * API: split_reservation
1873
+ */
1874
+
1875
+ function split_reservation($rno, $splitAmount, $orderid1, $orderid2,
1876
+ $flags, $eid, $secret, &$result) {
1877
+ our_settype_string($rno);
1878
+ our_settype_integer($splitAmount);
1879
+ our_settype_string($orderid1);
1880
+ our_settype_string($orderid2);
1881
+ our_settype_integer($flags);
1882
+ our_settype_integer($eid);
1883
+ our_settype_string($secret);
1884
+ $digestSecret = split_reserve_digest($eid, $rno, $splitAmount, $secret);
1885
+ $paramList = array($rno, $splitAmount, $orderid1, $orderid2, $flags,
1886
+ $eid, $digestSecret);
1887
+ return kred_call("split_reservation", $paramList, $result);
1888
+ }
1889
+
1890
+
1891
+ /*
1892
+ * API: activate_reservation
1893
+ */
1894
+
1895
+ function activate_reservation($rno, $pno, $ocr, $goodslist, $reference,
1896
+ $referece_code, $orderid1, $orderid2, $lev_addr, $f_addr,
1897
+ $shipmenttype, $email, $phone, $cell, $client_ip, $flags,
1898
+ $currency, $country, $language, $eid, $secret, $pno_encoding,
1899
+ $pclass, $ysalary, $pin, &$result) {
1900
+
1901
+ our_settype_string($rno);
1902
+ our_strip_string($pno);
1903
+ our_settype_string($ocr);
1904
+ settype($referece, "string");
1905
+ settype($referece_code, "string");
1906
+ our_settype_string($orderid1);
1907
+ our_settype_string($orderid2);
1908
+
1909
+ our_settype_integer($shipmenttype);
1910
+ our_settype_string($email);
1911
+ our_settype_string($phone);
1912
+ our_settype_string($cell);
1913
+ our_settype_string($client_ip);
1914
+ our_settype_integer($flags);
1915
+ our_settype_integer($currency);
1916
+ our_settype_integer($country);
1917
+ our_settype_integer($language);
1918
+ our_settype_integer($eid);
1919
+ our_settype_string($secret);
1920
+ our_settype_integer($pno_encoding);
1921
+ our_settype_integer($pclass);
1922
+ our_settype_integer($ysalary);
1923
+ our_settype_string($pin);
1924
+ $digestSecret = activate_reservation_digest($eid, $pno, $goodslist, $secret);
1925
+ $paramList = array($rno, $pno, $ocr, $goodslist, $reference,
1926
+ $referece_code, $orderid1, $orderid2, $lev_addr, $f_addr,
1927
+ $shipmenttype, $email, $phone, $cell, $client_ip, $flags,
1928
+ $currency, $country, $language, $eid, $digestSecret, $pno_encoding,
1929
+ $pclass, $ysalary * 100, $pin);
1930
+ return kred_call("activate_reservation", $paramList, $result);
1931
+ }
1932
+
1933
+ function activate_reservation_old($rno, $pno, $goodslist, $reference,
1934
+ $referece_code, $orderid1, $orderid2, $lev_addr, $f_addr,
1935
+ $shipmenttype, $email, $phone, $cell, $client_ip, $flags,
1936
+ $currency, $country, $language, $eid, $secret, $pno_encoding,
1937
+ $pclass, $ysalary, &$result) {
1938
+
1939
+ return activate_reservation($rno, $pno, "", $goodslist, $reference,
1940
+ $referece_code, $orderid1, $orderid2, $lev_addr, $f_addr,
1941
+ $shipmenttype, $email, $phone, $cell, $client_ip, $flags,
1942
+ $currency, $country, $language, $eid, $secret, $pno_encoding,
1943
+ $pclass, $ysalary, $result);
1944
+
1945
+ }
1946
+
1947
+
1948
+ /*
1949
+ * API: activate_reservation with ocr
1950
+ */
1951
+ function activate_reservation_ocr($rno, $pno, $ocr, $goodslist, $reference,
1952
+ $referece_code, $orderid1, $orderid2, $lev_addr, $f_addr,
1953
+ $shipmenttype, $email, $phone, $cell, $client_ip, $flags,
1954
+ $eid, $secret, $pno_encoding, $pclass, $ysalary, &$result) {
1955
+ our_settype_string($rno);
1956
+ our_strip_string($pno);
1957
+ our_settype_string($ocr);
1958
+
1959
+ settype($referece, "string");
1960
+ settype($referece_code, "string");
1961
+ our_settype_string($orderid1);
1962
+ our_settype_string($orderid2);
1963
+
1964
+ our_settype_integer($shipmenttype);
1965
+ our_settype_string($email);
1966
+ our_settype_string($phone);
1967
+ our_settype_string($cell);
1968
+ our_settype_string($client_ip);
1969
+ our_settype_integer($flags);
1970
+ our_settype_integer($eid);
1971
+ our_settype_string($secret);
1972
+ our_settype_integer($pno_encoding);
1973
+ our_settype_integer($pclass);
1974
+ our_settype_integer($ysalary);
1975
+ $digestSecret = activate_reservation_digest($eid, $pno, $goodslist, $secret);
1976
+
1977
+ $paramList = array($rno, $pno, $ocr, $goodslist, $reference,
1978
+ $referece_code, $orderid1, $orderid2, $lev_addr, $f_addr,
1979
+ $shipmenttype, $email, $phone, $cell, $client_ip, $flags,
1980
+ $eid, $digestSecret, $pno_encoding, $pclass, $ysalary * 100);
1981
+ return kred_call("activate_reservation", $paramList, $result);
1982
+ }
1983
+
1984
+ /*
1985
+ * API: reserve_ocr_nums
1986
+ */
1987
+
1988
+ function reserve_ocr_nums($no, $eid, $secret, $country, &$result) {
1989
+ our_settype_integer($no);
1990
+ our_settype_integer($eid);
1991
+ our_settype_string($secret);
1992
+ our_settype_integer($country);
1993
+ $digestSecret = ref_no_digest($eid, $no, $secret);
1994
+ $paramList = array($no, $eid, $digestSecret, $country);
1995
+ return kred_call("reserve_ocr_nums", $paramList, $result);
1996
+ }
1997
+
1998
+ /*
1999
+ * API: is_invoice_paid
2000
+ */
2001
+
2002
+ function is_invoice_paid($invno, $eid, $secret, &$result) {
2003
+ our_settype_string($invno);
2004
+ our_settype_integer($eid);
2005
+ our_settype_string($secret);
2006
+ $digestSecret = ref_no_digest($eid, $invno, $secret);
2007
+ $paramList = array($invno, $eid, $digestSecret);
2008
+ return kred_call("is_invoice_paid", $paramList, $result);
2009
+ }
2010
+
2011
+
2012
+ /*
2013
+ * API: reserve_ocr_nums with email
2014
+ */
2015
+
2016
+ function reserve_ocr_nums_email($no, $email, $eid, $secret, &$result) {
2017
+ our_settype_integer($no);
2018
+ our_settype_string($email);
2019
+ our_settype_integer($eid);
2020
+ our_settype_string($secret);
2021
+ $digestSecret = ref_no_digest($eid, $no, $secret);
2022
+ $paramList = array($no, $email, $eid, $digestSecret);
2023
+ return kred_call("reserve_ocr_nums", $paramList, $result);
2024
+ }
2025
+
2026
+ /*
2027
+ * API: set_customer_no
2028
+ */
2029
+
2030
+ function set_customer_no($pno, $cust_no, $eid, $secret,
2031
+ $pno_encoding, &$result) {
2032
+ our_strip_string($pno);
2033
+ our_settype_string($cust_no);
2034
+ our_settype_integer($eid);
2035
+ our_settype_string($secret);
2036
+ our_settype_integer($pno_encoding);
2037
+ $digestSecret = set_customer_no_digest($eid, $pno, $cust_no, $secret);
2038
+ $paramList = array($pno, $cust_no, $eid, $digestSecret, $pno_encoding);
2039
+ return kred_call("set_customer_no", $paramList, $result);
2040
+ }
2041
+
2042
+ /*
2043
+ * API: get_customer_no
2044
+ */
2045
+
2046
+ function get_customer_no($pno, $eid, $secret, $pno_encoding, &$result) {
2047
+ our_strip_string($pno);
2048
+ our_settype_integer($eid);
2049
+ our_settype_string($secret);
2050
+ our_settype_integer($pno_encoding);
2051
+ $digestSecret = ref_no_digest($eid, $pno, $secret);
2052
+ $paramList = array($pno, $eid, $digestSecret, $pno_encoding);
2053
+ return kred_call("get_customer_no", $paramList, $result);
2054
+ }
2055
+
2056
+ /*
2057
+ * API: periodic_cost
2058
+ */
2059
+ function periodic_cost($eid, $sum, $pclass, $currency, $flags, $secret,
2060
+ &$result){
2061
+ $months = get_months($pclass);
2062
+ $monthfee = get_month_fee($pclass);
2063
+ $startfee = get_start_fee($pclass);
2064
+ $rate = get_rate($pclass);
2065
+ $result = periodic_cost2($sum, $months, $monthfee, $rate, $startfee);
2066
+ return 0;
2067
+ }
2068
+
2069
+ function periodic_cost2($sum, $months, $monthfee, $rate, $startfee){
2070
+ $dailyrate = daily_rate($rate);
2071
+ $monthpayment = calc_monthpayment($sum + $startfee, $dailyrate, $months);
2072
+ return round($monthpayment + $monthfee);
2073
+ }
2074
+
2075
+
2076
+ function calc_monthpayment($sum, $dailyrate, $months){
2077
+ $dates = 0;
2078
+ $totdates = (($months - 1) * 30);
2079
+ $denom = calc_denom($dailyrate, $totdates);
2080
+ $totdates = $totdates + 60;
2081
+ return ((pow($dailyrate, $totdates) * $sum) / $denom);
2082
+ }
2083
+
2084
+ function calc_denom($dailyrate, $totdates){
2085
+ $sum = 1;
2086
+ $startdates = 0;
2087
+ while ($totdates > $startdates){
2088
+ $startdates = $startdates + 30;
2089
+ $sum = ($sum + pow($dailyrate, $startdates));
2090
+ }
2091
+ return $sum;
2092
+ }
2093
+
2094
+ function daily_rate($rate){
2095
+ return pow((($rate / 10000) + 1), (1 / 365.25));
2096
+ }
2097
+
2098
+ function periodic_cost_rpc($eid, $sum, $pclass, $currency, $flags, $secret,
2099
+ &$result){
2100
+ our_settype_integer($eid);
2101
+ our_settype_integer($sum);
2102
+ our_settype_integer($pclass);
2103
+ our_settype_integer($currency);
2104
+ our_settype_integer($flags);
2105
+ $digestSecret = periodic_cost_digest($eid, $sum, $pclass, $secret);
2106
+ $paramList = array($eid, $sum, $pclass, $currency, $flags, $digestSecret);
2107
+ return kred_call("periodic_cost", $paramList, $result);
2108
+
2109
+ }
2110
+
2111
+ function monthly_cost($sum, $rate, $months, $monthsfee, $flags, $country, &$result)
2112
+ {
2113
+ global $KRED_ISO3166_SE, $KRED_ISO3166_NO, $KRED_ISO3166_DK, $KRED_ISO3166_FI, $KRED_ISO3166_DE, $KRED_ISO3166_NL, $KRED_EUR, $KRED_NOK, $KRED_SEK, $KRED_DKK;
2114
+ if($rate < 100)
2115
+ $rate = $rate*100;
2116
+
2117
+ switch ($country) {
2118
+ case $KRED_ISO3166_SE:
2119
+ $lowest_monthly_payment = 5000.00;
2120
+ $currency = $KRED_SEK;
2121
+ break;
2122
+ case $KRED_ISO3166_NO:
2123
+ $lowest_monthly_payment = 9500.00;
2124
+ $currency = $KRED_NOK;
2125
+ break;
2126
+ case $KRED_ISO3166_FI:
2127
+ $lowest_monthly_payment = 895.00;
2128
+ $currency = $KRED_EUR;
2129
+ break;
2130
+ case $KRED_ISO3166_DK:
2131
+ $lowest_monthly_payment = 8900.00;
2132
+ $currency = $KRED_DKK;
2133
+ break;
2134
+ case $KRED_ISO3166_DE:
2135
+ $lowest_monthly_payment = 695.00;
2136
+ $currency = $KRED_EUR;
2137
+ break;
2138
+ case $KRED_ISO3166_NL:
2139
+ $lowest_monthly_payment = 500.00;
2140
+ $currency = $KRED_EUR;
2141
+ break;
2142
+ default:
2143
+ return -2;
2144
+ }
2145
+
2146
+ $average_interest_period = 45;
2147
+ $calcRate = ($rate / 10000);
2148
+
2149
+ $interest_value = ($average_interest_period / 365.0) * $calcRate * $sum;
2150
+ $periodic_cost = ($sum + $interest_value)/$months;
2151
+
2152
+ if ($flags == 1)
2153
+ {
2154
+ $result = round_up($periodic_cost, $currency);
2155
+ }
2156
+ else if ($flags == 0)
2157
+ {
2158
+ $periodic_cost = $periodic_cost + $monthsfee;
2159
+ if ($periodic_cost < $lowest_monthly_payment)
2160
+ $result = round($lowest_monthly_payment, 0);
2161
+ else
2162
+ $result = round_up($periodic_cost, $currency);
2163
+ }
2164
+ else
2165
+ return -2;
2166
+
2167
+ return 0;
2168
+ }
2169
+
2170
+ /*************************************************************************
2171
+ * API: monthly_cost_new
2172
+ *************************************************************************/
2173
+ function calc_monthly_cost($sum, $pclass, $flags, $country, &$result){
2174
+ $months;
2175
+ $monthsfee;
2176
+ $type;
2177
+ $rate;
2178
+ $startfee;
2179
+
2180
+ $months = get_months($pclass);
2181
+ $monthsfee = get_month_fee($pclass);
2182
+ $type = get_type($pclass);
2183
+ $rate = get_rate($pclass);
2184
+ $startfee = get_start_fee($pclass);
2185
+ return monthly_cost_new2($sum, $rate, $months, $monthsfee, $startfee, $flags,
2186
+ $country, $type, $pclass, $result);
2187
+ }
2188
+
2189
+ /*************************************************************************
2190
+ * API: monthly_cost_new2
2191
+ *************************************************************************/
2192
+ function monthly_cost_new2($sum, $rate, $months, $monthsfee, $startfee,
2193
+ $flags, $country, $type, $pclass, &$result){
2194
+ global $KRED_ANNUITY_PCLASS, $KRED_DIVISOR_PCLASS, $KRED_FIXED_PCLASS;
2195
+ if($type == $KRED_ANNUITY_PCLASS){
2196
+ return periodic_cost_new($sum, $months, $monthsfee, $rate, $startfee,
2197
+ $country, $flags, $result);
2198
+ }else if($type == $KRED_DIVISOR_PCLASS){
2199
+ return monthly_cost($sum, $rate, $months, $monthsfee, $flags, $country,
2200
+ $result);
2201
+ }else if($type == $KRED_FIXED_PCLASS){
2202
+ return fixed_month_cost($sum, $pclass, $monthsfee, $flags, $result);
2203
+ }
2204
+
2205
+ return -1;
2206
+ }
2207
+
2208
+ function fixed_month_cost($sum, $pclass, $monthsfee, $flags, &$result){
2209
+ $fixed_cost;
2210
+ $min_sum;
2211
+ $max_sum;
2212
+
2213
+ $fixed_cost = get_fixed_cost($pclass);
2214
+ $min_sum = get_min_sum($pclass);
2215
+ $max_sum = get_max_sum($pclass);
2216
+ if (($sum >= $min_sum) && ($sum <= $max_sum)){
2217
+ $result = (int)($fixed_cost + $monthsfee + 0.5);
2218
+ } else {
2219
+ return -1;
2220
+ }
2221
+ }
2222
+
2223
+ /*************************************************************************
2224
+ * API: periodic_cost
2225
+ *************************************************************************/
2226
+ function periodic_cost_new($sum, $months, $monthfee,
2227
+ $rate, $startfee, $currency, $flags, &$result){
2228
+
2229
+ global $KRED_ACTUAL_COST, $KRED_LIMIT_COST;
2230
+ $mountscost = 0;
2231
+ $dailyrate = daily_rate($rate);
2232
+ $monthpayment = calc_monthpayment($sum+$startfee, $dailyrate, $months);
2233
+ if($flags == $KRED_ACTUAL_COST){
2234
+ $mountscost = $monthpayment + 0.5;
2235
+ }else if($flags == $KRED_LIMIT_COST){
2236
+ $mountscost = $monthpayment + $monthfee + 0.5;
2237
+ }else{
2238
+ $result = -2;
2239
+ }
2240
+ $result = (int)$mountscost;
2241
+ }
2242
+
2243
+ function round_up($value, $curr) //value, currency
2244
+ {
2245
+ $result;
2246
+ $divisor;
2247
+
2248
+ if ($curr == 2)
2249
+ $divisor = 10;
2250
+ else
2251
+ $divisor = 100;
2252
+
2253
+ $result = $divisor * round((($divisor/2)+$value)/$divisor); //We want to roundup to closest integer.
2254
+
2255
+ return $result;
2256
+ }
2257
+
2258
+ function get_pclasses($eid, $cur, $secret, &$result){
2259
+ our_settype_integer($eid);
2260
+ our_settype_integer($cur);
2261
+ $digestSecret = invoice_digest($eid, $cur, $secret);
2262
+ $paramList = array($eid, $cur, $digestSecret);
2263
+ return kred_call("get_pclasses", $paramList, $result);
2264
+ }
2265
+
2266
+ function fetch_pclasses($eid, $cur, $secret, $country, $language, &$result){
2267
+ our_settype_integer($eid);
2268
+ our_settype_integer($cur);
2269
+ our_settype_integer($country);
2270
+ our_settype_integer($language);
2271
+ $digestSecret = invoice_digest($eid, $cur, $secret);
2272
+ $paramList = array($eid, $cur, $digestSecret, $country, $language);
2273
+ return kred_call("get_pclasses", $paramList, $result);
2274
+ }
2275
+
2276
+ /*
2277
+ * Digests
2278
+ */
2279
+
2280
+ function set_customer_no_digest($eid, $pno, $cust_no, $secret){
2281
+ $string = $eid . ":" . $pno . ":" . $cust_no . ":" . $secret;
2282
+ return md5_base64($string);
2283
+ }
2284
+
2285
+ function change_res_digest($eid, $pno, $amount, $secret){
2286
+ $string = $eid . ":" . $pno . ":" . $amount . ":" . $secret;
2287
+ return md5_base64($string);
2288
+ }
2289
+
2290
+ function split_reserve_digest($eid, $pno, $amount, $secret){
2291
+ $string = $eid . ":" . $pno . ":" . $amount . ":" . $secret;
2292
+ return md5_base64($string);
2293
+ }
2294
+
2295
+ function ref_no_digest($eid, $ref_no, $secret) {
2296
+ $string = $eid . ":" . $ref_no . ":" . $secret;
2297
+ return md5_base64($string);
2298
+ }
2299
+
2300
+ function invoice_digest($eid, $invno, $secret) {
2301
+ $string = $eid . ":" . $invno . ":" . $secret;
2302
+ return md5_base64($string);
2303
+ }
2304
+
2305
+ function pno_digest($eid, $pno, $secret) {
2306
+ $string = $eid . ":" . $pno . ":" . $secret;
2307
+ return md5_base64($string);
2308
+ }
2309
+
2310
+ function periodic_cost_digest($eid, $sum, $pclass, $secret) {
2311
+ $string = $eid . ":" . $sum . ":" . $pclass . ":" . $secret;
2312
+ return md5_base64($string);
2313
+ }
2314
+
2315
+ function reserve_amount_digest($eid, $pno, $amount, $secret) {
2316
+ $string = $eid . ":" . $pno . ":" . $amount . ":" . $secret;
2317
+ return md5_base64($string);
2318
+ }
2319
+
2320
+ function activate_part_digest($eid, $invno, $artnos, $secret) {
2321
+ $string = $eid . ":" . $invno . ":";
2322
+
2323
+ foreach ($artnos as $artno)
2324
+ $string .= $artno["artno"] . ":". $artno["qty"] . ":";
2325
+
2326
+ return md5_base64($string . $secret);
2327
+
2328
+ }
2329
+
2330
+ function activate_reservation_digest($eid, $pno, $goodsList, $secret) {
2331
+ $string = $eid . ":" . $pno . ":";
2332
+ foreach ($goodsList as $goods)
2333
+ $string .= $goods["goods"]["artno"] . ":" .
2334
+ $goods["qty"] . ":";
2335
+
2336
+ return md5_base64($string . $secret);
2337
+ }
2338
+
2339
+ function add_transaction_digest($goodsList, $secret) {
2340
+ $string = "";
2341
+
2342
+ foreach ($goodsList as $goods)
2343
+ $string .= $goods["goods"]["title"] . ":";
2344
+ return md5_base64($string . $secret);
2345
+ }
2346
+
2347
+ function update_charge_amount_digest($invno, $type, $newAmount, $secret) {
2348
+ $string = $invno . ":" . $type . ":" . $newAmount . ":" . $secret;
2349
+ return md5_base64($string);
2350
+ }
2351
+
2352
+ function update_goods_qty_digest($invno, $artno, $newQty, $secret) {
2353
+ $string = $invno . ":" . $artno . ":" . $newQty . ":" . $secret;
2354
+ return md5_base64($string);
2355
+ }
2356
+
2357
+ function update_orderno_digest($invno, $orderno, $secret) {
2358
+ $string = $invno . ":" . $orderno . ":" . $secret;
2359
+ return md5_base64($string);
2360
+ }
2361
+
2362
+ function update_notes_digest($invno, $notes, $secret) {
2363
+ $string = $invno . ":" . $notes . ":" . $secret;
2364
+ return md5_base64($string);
2365
+ }
2366
+
2367
+ function md5_base64($data) {
2368
+ return base64_encode(pack("H*", md5($data)));
2369
+ }
2370
+
2371
+ /*
2372
+ * EPI XMLRPC call
2373
+ */
2374
+
2375
+ function xmlrpc_call($host, $port, $request) {
2376
+ $fp = fsockopen($host, $port, $errno, $errstr, 30);
2377
+ $query = "POST / HTTP/1.0\r\nUser-Agent: Klarna PHP Client\r\nHost: " . $host."\nConnection: close\r\nContent-Type: text/xml\r\nContent-Length: " . strlen($request) . "\r\n\r\n" . $request;
2378
+
2379
+ if (!fputs($fp, $query, strlen($query))) {
2380
+ $errstr = "Write error";
2381
+ return 0;
2382
+ }
2383
+
2384
+ $contents = "";
2385
+
2386
+ while (!feof($fp))
2387
+ $contents .= fgets($fp);
2388
+
2389
+ fclose($fp);
2390
+ return $contents;
2391
+ }
2392
+
2393
+ /*
2394
+ * Utilities
2395
+ */
2396
+
2397
+ function our_settype_integer(&$x) {
2398
+ if (is_double($x)) {
2399
+ $x = round($x)+(($x>0)?0.00000001:-0.00000001);
2400
+ } else if (is_float($x)) {
2401
+ $x = round($x)+(($x>0)?0.00000001:-0.00000001);
2402
+ } else if (is_string($x)) {
2403
+ $x = preg_replace("/[ \n\r\t\e]/", "", $x);
2404
+ }
2405
+
2406
+ settype($x, "integer");
2407
+ }
2408
+
2409
+ function our_strip_string(&$x) {
2410
+ $x = str_replace(array(" ","-"), "", $x);
2411
+ }
2412
+
2413
+ function our_settype_string(&$x){
2414
+ $res = "";
2415
+ $length = strlen($x);
2416
+ for($i = 0; $i < $length; $i++){
2417
+ if($x[$i] >= " "){
2418
+ $res .= $x[$i];
2419
+ }else{
2420
+ $res .= " ";
2421
+ }
2422
+ }
2423
+ $x = $res;
2424
+ }
2425
+
2426
+ function check_params($function, $paramList) {
2427
+ }
2428
+
2429
+ /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
2430
+
2431
+ /**
2432
+ * PHP implementation of the XML-RPC protocol
2433
+ *
2434
+ * This is a PEAR-ified version of Useful inc's XML-RPC for PHP.
2435
+ * It has support for HTTP transport, proxies and authentication.
2436
+ *
2437
+ * PHP versions 4 and 5
2438
+ *
2439
+ * @category Web Services
2440
+ * @package XML_RPC
2441
+ * @author Edd Dumbill <edd@usefulinc.com>
2442
+ * @author Stig Bakken <stig@php.net>
2443
+ * @author Martin Jansen <mj@php.net>
2444
+ * @author Daniel Convissor <danielc@php.net>
2445
+ * @copyright 1999-2001 Edd Dumbill, 2001-2010 The PHP Group
2446
+ * @license http://www.php.net/license/3_01.txt PHP License
2447
+ * @version SVN: $Id: RPC.php 293238 2010-01-08 03:21:06Z danielc $
2448
+ * @link http://pear.php.net/package/XML_RPC
2449
+ */
2450
+
2451
+
2452
+ if (!function_exists('xml_parser_create')) {
2453
+ include_once 'PEAR.php';
2454
+ PEAR::loadExtension('xml');
2455
+ }
2456
+
2457
+ /**#@+
2458
+ * Error constants
2459
+ */
2460
+ /**
2461
+ * Parameter values don't match parameter types
2462
+ */
2463
+ define('XML_RPC_ERROR_INVALID_TYPE', 101);
2464
+ /**
2465
+ * Parameter declared to be numeric but the values are not
2466
+ */
2467
+ define('XML_RPC_ERROR_NON_NUMERIC_FOUND', 102);
2468
+ /**
2469
+ * Communication error
2470
+ */
2471
+ define('XML_RPC_ERROR_CONNECTION_FAILED', 103);
2472
+ /**
2473
+ * The array or struct has already been started
2474
+ */
2475
+ define('XML_RPC_ERROR_ALREADY_INITIALIZED', 104);
2476
+ /**
2477
+ * Incorrect parameters submitted
2478
+ */
2479
+ define('XML_RPC_ERROR_INCORRECT_PARAMS', 105);
2480
+ /**
2481
+ * Programming error by developer
2482
+ */
2483
+ define('XML_RPC_ERROR_PROGRAMMING', 106);
2484
+ /**#@-*/
2485
+
2486
+
2487
+ /**
2488
+ * Data types
2489
+ * @global string $GLOBALS['XML_RPC_I4']
2490
+ */
2491
+ $GLOBALS['XML_RPC_I4'] = 'i4';
2492
+
2493
+ /**
2494
+ * Data types
2495
+ * @global string $GLOBALS['XML_RPC_Int']
2496
+ */
2497
+ $GLOBALS['XML_RPC_Int'] = 'int';
2498
+
2499
+ /**
2500
+ * Data types
2501
+ * @global string $GLOBALS['XML_RPC_Boolean']
2502
+ */
2503
+ $GLOBALS['XML_RPC_Boolean'] = 'boolean';
2504
+
2505
+ /**
2506
+ * Data types
2507
+ * @global string $GLOBALS['XML_RPC_Double']
2508
+ */
2509
+ $GLOBALS['XML_RPC_Double'] = 'double';
2510
+
2511
+ /**
2512
+ * Data types
2513
+ * @global string $GLOBALS['XML_RPC_String']
2514
+ */
2515
+ $GLOBALS['XML_RPC_String'] = 'string';
2516
+
2517
+ /**
2518
+ * Data types
2519
+ * @global string $GLOBALS['XML_RPC_DateTime']
2520
+ */
2521
+ $GLOBALS['XML_RPC_DateTime'] = 'dateTime.iso8601';
2522
+
2523
+ /**
2524
+ * Data types
2525
+ * @global string $GLOBALS['XML_RPC_Base64']
2526
+ */
2527
+ $GLOBALS['XML_RPC_Base64'] = 'base64';
2528
+
2529
+ /**
2530
+ * Data types
2531
+ * @global string $GLOBALS['XML_RPC_Array']
2532
+ */
2533
+ $GLOBALS['XML_RPC_Array'] = 'array';
2534
+
2535
+ /**
2536
+ * Data types
2537
+ * @global string $GLOBALS['XML_RPC_Struct']
2538
+ */
2539
+ $GLOBALS['XML_RPC_Struct'] = 'struct';
2540
+
2541
+
2542
+ /**
2543
+ * Data type meta-types
2544
+ * @global array $GLOBALS['XML_RPC_Types']
2545
+ */
2546
+ $GLOBALS['XML_RPC_Types'] = array(
2547
+ $GLOBALS['XML_RPC_I4'] => 1,
2548
+ $GLOBALS['XML_RPC_Int'] => 1,
2549
+ $GLOBALS['XML_RPC_Boolean'] => 1,
2550
+ $GLOBALS['XML_RPC_String'] => 1,
2551
+ $GLOBALS['XML_RPC_Double'] => 1,
2552
+ $GLOBALS['XML_RPC_DateTime'] => 1,
2553
+ $GLOBALS['XML_RPC_Base64'] => 1,
2554
+ $GLOBALS['XML_RPC_Array'] => 2,
2555
+ $GLOBALS['XML_RPC_Struct'] => 3,
2556
+ );
2557
+
2558
+
2559
+ /**
2560
+ * Error message numbers
2561
+ * @global array $GLOBALS['XML_RPC_err']
2562
+ */
2563
+ $GLOBALS['XML_RPC_err'] = array(
2564
+ 'unknown_method' => 1,
2565
+ 'invalid_return' => 2,
2566
+ 'incorrect_params' => 3,
2567
+ 'introspect_unknown' => 4,
2568
+ 'http_error' => 5,
2569
+ 'not_response_object' => 6,
2570
+ 'invalid_request' => 7,
2571
+ );
2572
+
2573
+ /**
2574
+ * Error message strings
2575
+ * @global array $GLOBALS['XML_RPC_str']
2576
+ */
2577
+ $GLOBALS['XML_RPC_str'] = array(
2578
+ 'unknown_method' => 'Unknown method',
2579
+ 'invalid_return' => 'Invalid return payload: enable debugging to examine incoming payload',
2580
+ 'incorrect_params' => 'Incorrect parameters passed to method',
2581
+ 'introspect_unknown' => 'Can\'t introspect: method unknown',
2582
+ 'http_error' => 'Didn\'t receive 200 OK from remote server.',
2583
+ 'not_response_object' => 'The requested method didn\'t return an XML_RPC_Response object.',
2584
+ 'invalid_request' => 'Invalid request payload',
2585
+ );
2586
+
2587
+
2588
+ /**
2589
+ * Default XML encoding (ISO-8859-1, UTF-8 or US-ASCII)
2590
+ * @global string $GLOBALS['XML_RPC_defencoding']
2591
+ */
2592
+ $GLOBALS['XML_RPC_defencoding'] = 'UTF-8';
2593
+
2594
+ /**
2595
+ * User error codes start at 800
2596
+ * @global int $GLOBALS['XML_RPC_erruser']
2597
+ */
2598
+ $GLOBALS['XML_RPC_erruser'] = 800;
2599
+
2600
+ /**
2601
+ * XML parse error codes start at 100
2602
+ * @global int $GLOBALS['XML_RPC_errxml']
2603
+ */
2604
+ $GLOBALS['XML_RPC_errxml'] = 100;
2605
+
2606
+
2607
+ /**
2608
+ * Compose backslashes for escaping regexp
2609
+ * @global string $GLOBALS['XML_RPC_backslash']
2610
+ */
2611
+ $GLOBALS['XML_RPC_backslash'] = chr(92) . chr(92);
2612
+
2613
+
2614
+ /**#@+
2615
+ * Which functions to use, depending on whether mbstring is enabled or not.
2616
+ */
2617
+ if (function_exists('mb_ereg')) {
2618
+ /** @global string $GLOBALS['XML_RPC_func_ereg'] */
2619
+ $GLOBALS['XML_RPC_func_ereg'] = 'mb_eregi';
2620
+ /** @global string $GLOBALS['XML_RPC_func_ereg_replace'] */
2621
+ $GLOBALS['XML_RPC_func_ereg_replace'] = 'mb_eregi_replace';
2622
+ /** @global string $GLOBALS['XML_RPC_func_split'] */
2623
+ $GLOBALS['XML_RPC_func_split'] = 'mb_split';
2624
+ } else {
2625
+ /** @ignore */
2626
+ $GLOBALS['XML_RPC_func_ereg'] = 'eregi';
2627
+ /** @ignore */
2628
+ $GLOBALS['XML_RPC_func_ereg_replace'] = 'eregi_replace';
2629
+ /** @ignore */
2630
+ $GLOBALS['XML_RPC_func_split'] = 'split';
2631
+ }
2632
+ /**#@-*/
2633
+
2634
+
2635
+ /**
2636
+ * Should we automatically base64 encode strings that contain characters
2637
+ * which can cause PHP's SAX-based XML parser to break?
2638
+ * @global boolean $GLOBALS['XML_RPC_auto_base64']
2639
+ */
2640
+ $GLOBALS['XML_RPC_auto_base64'] = false;
2641
+
2642
+
2643
+ /**
2644
+ * Valid parents of XML elements
2645
+ * @global array $GLOBALS['XML_RPC_valid_parents']
2646
+ */
2647
+ $GLOBALS['XML_RPC_valid_parents'] = array(
2648
+ 'BOOLEAN' => array('VALUE'),
2649
+ 'I4' => array('VALUE'),
2650
+ 'INT' => array('VALUE'),
2651
+ 'STRING' => array('VALUE'),
2652
+ 'DOUBLE' => array('VALUE'),
2653
+ 'DATETIME.ISO8601' => array('VALUE'),
2654
+ 'BASE64' => array('VALUE'),
2655
+ 'ARRAY' => array('VALUE'),
2656
+ 'STRUCT' => array('VALUE'),
2657
+ 'PARAM' => array('PARAMS'),
2658
+ 'METHODNAME' => array('METHODCALL'),
2659
+ 'PARAMS' => array('METHODCALL', 'METHODRESPONSE'),
2660
+ 'MEMBER' => array('STRUCT'),
2661
+ 'NAME' => array('MEMBER'),
2662
+ 'DATA' => array('ARRAY'),
2663
+ 'FAULT' => array('METHODRESPONSE'),
2664
+ 'VALUE' => array('MEMBER', 'DATA', 'PARAM', 'FAULT'),
2665
+ );
2666
+
2667
+
2668
+ /**
2669
+ * Stores state during parsing
2670
+ *
2671
+ * quick explanation of components:
2672
+ * + ac = accumulates values
2673
+ * + qt = decides if quotes are needed for evaluation
2674
+ * + cm = denotes struct or array (comma needed)
2675
+ * + isf = indicates a fault
2676
+ * + lv = indicates "looking for a value": implements the logic
2677
+ * to allow values with no types to be strings
2678
+ * + params = stores parameters in method calls
2679
+ * + method = stores method name
2680
+ *
2681
+ * @global array $GLOBALS['XML_RPC_xh']
2682
+ */
2683
+ $GLOBALS['XML_RPC_xh'] = array();
2684
+
2685
+
2686
+ /**
2687
+ * Start element handler for the XML parser
2688
+ *
2689
+ * @return void
2690
+ */
2691
+ function XML_RPC_se($parser_resource, $name, $attrs)
2692
+ {
2693
+ global $XML_RPC_xh, $XML_RPC_valid_parents;
2694
+
2695
+ $parser = (int) $parser_resource;
2696
+
2697
+ // if invalid xmlrpc already detected, skip all processing
2698
+ if ($XML_RPC_xh[$parser]['isf'] >= 2) {
2699
+ return;
2700
+ }
2701
+
2702
+ // check for correct element nesting
2703
+ // top level element can only be of 2 types
2704
+ if (count($XML_RPC_xh[$parser]['stack']) == 0) {
2705
+ if ($name != 'METHODRESPONSE' && $name != 'METHODCALL') {
2706
+ $XML_RPC_xh[$parser]['isf'] = 2;
2707
+ $XML_RPC_xh[$parser]['isf_reason'] = 'missing top level xmlrpc element';
2708
+ return;
2709
+ }
2710
+ } else {
2711
+ // not top level element: see if parent is OK
2712
+ if (!in_array($XML_RPC_xh[$parser]['stack'][0], $XML_RPC_valid_parents[$name])) {
2713
+ $name = $GLOBALS['XML_RPC_func_ereg_replace']('[^a-zA-Z0-9._-]', '', $name);
2714
+ $XML_RPC_xh[$parser]['isf'] = 2;
2715
+ $XML_RPC_xh[$parser]['isf_reason'] = "xmlrpc element $name cannot be child of {$XML_RPC_xh[$parser]['stack'][0]}";
2716
+ return;
2717
+ }
2718
+ }
2719
+
2720
+ switch ($name) {
2721
+ case 'STRUCT':
2722
+ $XML_RPC_xh[$parser]['cm']++;
2723
+
2724
+ // turn quoting off
2725
+ $XML_RPC_xh[$parser]['qt'] = 0;
2726
+
2727
+ $cur_val = array();
2728
+ $cur_val['value'] = array();
2729
+ $cur_val['members'] = 1;
2730
+ array_unshift($XML_RPC_xh[$parser]['valuestack'], $cur_val);
2731
+ break;
2732
+
2733
+ case 'ARRAY':
2734
+ $XML_RPC_xh[$parser]['cm']++;
2735
+
2736
+ // turn quoting off
2737
+ $XML_RPC_xh[$parser]['qt'] = 0;
2738
+
2739
+ $cur_val = array();
2740
+ $cur_val['value'] = array();
2741
+ $cur_val['members'] = 0;
2742
+ array_unshift($XML_RPC_xh[$parser]['valuestack'], $cur_val);
2743
+ break;
2744
+
2745
+ case 'NAME':
2746
+ $XML_RPC_xh[$parser]['ac'] = '';
2747
+ break;
2748
+
2749
+ case 'FAULT':
2750
+ $XML_RPC_xh[$parser]['isf'] = 1;
2751
+ break;
2752
+
2753
+ case 'PARAM':
2754
+ $XML_RPC_xh[$parser]['valuestack'] = array();
2755
+ break;
2756
+
2757
+ case 'VALUE':
2758
+ $XML_RPC_xh[$parser]['lv'] = 1;
2759
+ $XML_RPC_xh[$parser]['vt'] = $GLOBALS['XML_RPC_String'];
2760
+ $XML_RPC_xh[$parser]['ac'] = '';
2761
+ $XML_RPC_xh[$parser]['qt'] = 0;
2762
+ // look for a value: if this is still 1 by the
2763
+ // time we reach the first data segment then the type is string
2764
+ // by implication and we need to add in a quote
2765
+ break;
2766
+
2767
+ case 'I4':
2768
+ case 'INT':
2769
+ case 'STRING':
2770
+ case 'BOOLEAN':
2771
+ case 'DOUBLE':
2772
+ case 'DATETIME.ISO8601':
2773
+ case 'BASE64':
2774
+ $XML_RPC_xh[$parser]['ac'] = ''; // reset the accumulator
2775
+
2776
+ if ($name == 'DATETIME.ISO8601' || $name == 'STRING') {
2777
+ $XML_RPC_xh[$parser]['qt'] = 1;
2778
+
2779
+ if ($name == 'DATETIME.ISO8601') {
2780
+ $XML_RPC_xh[$parser]['vt'] = $GLOBALS['XML_RPC_DateTime'];
2781
+ }
2782
+
2783
+ } elseif ($name == 'BASE64') {
2784
+ $XML_RPC_xh[$parser]['qt'] = 2;
2785
+ } else {
2786
+ // No quoting is required here -- but
2787
+ // at the end of the element we must check
2788
+ // for data format errors.
2789
+ $XML_RPC_xh[$parser]['qt'] = 0;
2790
+ }
2791
+ break;
2792
+
2793
+ case 'MEMBER':
2794
+ $XML_RPC_xh[$parser]['ac'] = '';
2795
+ break;
2796
+
2797
+ case 'DATA':
2798
+ case 'METHODCALL':
2799
+ case 'METHODNAME':
2800
+ case 'METHODRESPONSE':
2801
+ case 'PARAMS':
2802
+ // valid elements that add little to processing
2803
+ break;
2804
+ }
2805
+
2806
+
2807
+ // Save current element to stack
2808
+ array_unshift($XML_RPC_xh[$parser]['stack'], $name);
2809
+
2810
+ if ($name != 'VALUE') {
2811
+ $XML_RPC_xh[$parser]['lv'] = 0;
2812
+ }
2813
+ }
2814
+
2815
+ /**
2816
+ * End element handler for the XML parser
2817
+ *
2818
+ * @return void
2819
+ */
2820
+ function XML_RPC_ee($parser_resource, $name)
2821
+ {
2822
+ global $XML_RPC_xh;
2823
+
2824
+ $parser = (int) $parser_resource;
2825
+
2826
+ if ($XML_RPC_xh[$parser]['isf'] >= 2) {
2827
+ return;
2828
+ }
2829
+
2830
+ // push this element from stack
2831
+ // NB: if XML validates, correct opening/closing is guaranteed and
2832
+ // we do not have to check for $name == $curr_elem.
2833
+ // we also checked for proper nesting at start of elements...
2834
+ $curr_elem = array_shift($XML_RPC_xh[$parser]['stack']);
2835
+
2836
+ switch ($name) {
2837
+ case 'STRUCT':
2838
+ case 'ARRAY':
2839
+ $cur_val = array_shift($XML_RPC_xh[$parser]['valuestack']);
2840
+ $XML_RPC_xh[$parser]['value'] = $cur_val['value'];
2841
+ $XML_RPC_xh[$parser]['vt'] = strtolower($name);
2842
+ $XML_RPC_xh[$parser]['cm']--;
2843
+ break;
2844
+
2845
+ case 'NAME':
2846
+ $XML_RPC_xh[$parser]['valuestack'][0]['name'] = $XML_RPC_xh[$parser]['ac'];
2847
+ break;
2848
+
2849
+ case 'BOOLEAN':
2850
+ // special case here: we translate boolean 1 or 0 into PHP
2851
+ // constants true or false
2852
+ if ($XML_RPC_xh[$parser]['ac'] == '1') {
2853
+ $XML_RPC_xh[$parser]['ac'] = 'true';
2854
+ } else {
2855
+ $XML_RPC_xh[$parser]['ac'] = 'false';
2856
+ }
2857
+
2858
+ $XML_RPC_xh[$parser]['vt'] = strtolower($name);
2859
+ // Drop through intentionally.
2860
+
2861
+ case 'I4':
2862
+ case 'INT':
2863
+ case 'STRING':
2864
+ case 'DOUBLE':
2865
+ case 'DATETIME.ISO8601':
2866
+ case 'BASE64':
2867
+ if ($XML_RPC_xh[$parser]['qt'] == 1) {
2868
+ // we use double quotes rather than single so backslashification works OK
2869
+ $XML_RPC_xh[$parser]['value'] = $XML_RPC_xh[$parser]['ac'];
2870
+ } elseif ($XML_RPC_xh[$parser]['qt'] == 2) {
2871
+ $XML_RPC_xh[$parser]['value'] = base64_decode($XML_RPC_xh[$parser]['ac']);
2872
+ } elseif ($name == 'BOOLEAN') {
2873
+ $XML_RPC_xh[$parser]['value'] = $XML_RPC_xh[$parser]['ac'];
2874
+ } else {
2875
+ // we have an I4, INT or a DOUBLE
2876
+ // we must check that only 0123456789-.<space> are characters here
2877
+ if (!$GLOBALS['XML_RPC_func_ereg']("^[+-]?[0123456789 \t\.]+$", $XML_RPC_xh[$parser]['ac'])) {
2878
+ XML_RPC_Base::raiseError('Non-numeric value received in INT or DOUBLE',
2879
+ XML_RPC_ERROR_NON_NUMERIC_FOUND);
2880
+ $XML_RPC_xh[$parser]['value'] = XML_RPC_ERROR_NON_NUMERIC_FOUND;
2881
+ } else {
2882
+ // it's ok, add it on
2883
+ $XML_RPC_xh[$parser]['value'] = $XML_RPC_xh[$parser]['ac'];
2884
+ }
2885
+ }
2886
+
2887
+ $XML_RPC_xh[$parser]['ac'] = '';
2888
+ $XML_RPC_xh[$parser]['qt'] = 0;
2889
+ $XML_RPC_xh[$parser]['lv'] = 3; // indicate we've found a value
2890
+ break;
2891
+
2892
+ case 'VALUE':
2893
+ if ($XML_RPC_xh[$parser]['vt'] == $GLOBALS['XML_RPC_String']) {
2894
+ if (strlen($XML_RPC_xh[$parser]['ac']) > 0) {
2895
+ $XML_RPC_xh[$parser]['value'] = $XML_RPC_xh[$parser]['ac'];
2896
+ } elseif ($XML_RPC_xh[$parser]['lv'] == 1) {
2897
+ // The <value> element was empty.
2898
+ $XML_RPC_xh[$parser]['value'] = '';
2899
+ }
2900
+ }
2901
+
2902
+ $temp = new XML_RPC_Value($XML_RPC_xh[$parser]['value'], $XML_RPC_xh[$parser]['vt']);
2903
+
2904
+ $cur_val = array_shift($XML_RPC_xh[$parser]['valuestack']);
2905
+ if (is_array($cur_val)) {
2906
+ if ($cur_val['members']==0) {
2907
+ $cur_val['value'][] = $temp;
2908
+ } else {
2909
+ $XML_RPC_xh[$parser]['value'] = $temp;
2910
+ }
2911
+ array_unshift($XML_RPC_xh[$parser]['valuestack'], $cur_val);
2912
+ } else {
2913
+ $XML_RPC_xh[$parser]['value'] = $temp;
2914
+ }
2915
+ break;
2916
+
2917
+ case 'MEMBER':
2918
+ $XML_RPC_xh[$parser]['ac'] = '';
2919
+ $XML_RPC_xh[$parser]['qt'] = 0;
2920
+
2921
+ $cur_val = array_shift($XML_RPC_xh[$parser]['valuestack']);
2922
+ if (is_array($cur_val)) {
2923
+ if ($cur_val['members']==1) {
2924
+ $cur_val['value'][$cur_val['name']] = $XML_RPC_xh[$parser]['value'];
2925
+ }
2926
+ array_unshift($XML_RPC_xh[$parser]['valuestack'], $cur_val);
2927
+ }
2928
+ break;
2929
+
2930
+ case 'DATA':
2931
+ $XML_RPC_xh[$parser]['ac'] = '';
2932
+ $XML_RPC_xh[$parser]['qt'] = 0;
2933
+ break;
2934
+
2935
+ case 'PARAM':
2936
+ $XML_RPC_xh[$parser]['params'][] = $XML_RPC_xh[$parser]['value'];
2937
+ break;
2938
+
2939
+ case 'METHODNAME':
2940
+ case 'RPCMETHODNAME':
2941
+ $XML_RPC_xh[$parser]['method'] = $GLOBALS['XML_RPC_func_ereg_replace']("^[\n\r\t ]+", '',
2942
+ $XML_RPC_xh[$parser]['ac']);
2943
+ break;
2944
+ }
2945
+
2946
+ // if it's a valid type name, set the type
2947
+ if (isset($GLOBALS['XML_RPC_Types'][strtolower($name)])) {
2948
+ $XML_RPC_xh[$parser]['vt'] = strtolower($name);
2949
+ }
2950
+ }
2951
+
2952
+ /**
2953
+ * Character data handler for the XML parser
2954
+ *
2955
+ * @return void
2956
+ */
2957
+ function XML_RPC_cd($parser_resource, $data)
2958
+ {
2959
+ global $XML_RPC_xh, $XML_RPC_backslash;
2960
+
2961
+ $parser = (int) $parser_resource;
2962
+
2963
+ if ($XML_RPC_xh[$parser]['lv'] != 3) {
2964
+ // "lookforvalue==3" means that we've found an entire value
2965
+ // and should discard any further character data
2966
+
2967
+ if ($XML_RPC_xh[$parser]['lv'] == 1) {
2968
+ // if we've found text and we're just in a <value> then
2969
+ // turn quoting on, as this will be a string
2970
+ $XML_RPC_xh[$parser]['qt'] = 1;
2971
+ // and say we've found a value
2972
+ $XML_RPC_xh[$parser]['lv'] = 2;
2973
+ }
2974
+
2975
+ // replace characters that eval would
2976
+ // do special things with
2977
+ if (!isset($XML_RPC_xh[$parser]['ac'])) {
2978
+ $XML_RPC_xh[$parser]['ac'] = '';
2979
+ }
2980
+ $XML_RPC_xh[$parser]['ac'] .= $data;
2981
+ }
2982
+ }
2983
+
2984
+ /**
2985
+ * The common methods and properties for all of the XML_RPC classes
2986
+ *
2987
+ * @category Web Services
2988
+ * @package XML_RPC
2989
+ * @author Edd Dumbill <edd@usefulinc.com>
2990
+ * @author Stig Bakken <stig@php.net>
2991
+ * @author Martin Jansen <mj@php.net>
2992
+ * @author Daniel Convissor <danielc@php.net>
2993
+ * @copyright 1999-2001 Edd Dumbill, 2001-2010 The PHP Group
2994
+ * @license http://www.php.net/license/3_01.txt PHP License
2995
+ * @version Release: 1.5.3
2996
+ * @link http://pear.php.net/package/XML_RPC
2997
+ */
2998
+ class XML_RPC_Base {
2999
+
3000
+ /**
3001
+ * PEAR Error handling
3002
+ *
3003
+ * @return object PEAR_Error object
3004
+ */
3005
+ function raiseError($msg, $code)
3006
+ {
3007
+ include_once 'PEAR.php';
3008
+ if (is_object(@$this)) {
3009
+ return PEAR::raiseError(get_class($this) . ': ' . $msg, $code);
3010
+ } else {
3011
+ return PEAR::raiseError('XML_RPC: ' . $msg, $code);
3012
+ }
3013
+ }
3014
+
3015
+ /**
3016
+ * Tell whether something is a PEAR_Error object
3017
+ *
3018
+ * @param mixed $value the item to check
3019
+ *
3020
+ * @return bool whether $value is a PEAR_Error object or not
3021
+ *
3022
+ * @access public
3023
+ */
3024
+ function isError($value)
3025
+ {
3026
+ return ($value instanceof PEAR_Error);
3027
+ }
3028
+ }
3029
+
3030
+ /**
3031
+ * The methods and properties for submitting XML RPC requests
3032
+ *
3033
+ * @category Web Services
3034
+ * @package XML_RPC
3035
+ * @author Edd Dumbill <edd@usefulinc.com>
3036
+ * @author Stig Bakken <stig@php.net>
3037
+ * @author Martin Jansen <mj@php.net>
3038
+ * @author Daniel Convissor <danielc@php.net>
3039
+ * @copyright 1999-2001 Edd Dumbill, 2001-2010 The PHP Group
3040
+ * @license http://www.php.net/license/3_01.txt PHP License
3041
+ * @version Release: 1.5.3
3042
+ * @link http://pear.php.net/package/XML_RPC
3043
+ */
3044
+ class XML_RPC_Client extends XML_RPC_Base {
3045
+
3046
+ /**
3047
+ * The path and name of the RPC server script you want the request to go to
3048
+ * @var string
3049
+ */
3050
+ var $path = '';
3051
+
3052
+ /**
3053
+ * The name of the remote server to connect to
3054
+ * @var string
3055
+ */
3056
+ var $server = '';
3057
+
3058
+ /**
3059
+ * The protocol to use in contacting the remote server
3060
+ * @var string
3061
+ */
3062
+ var $protocol = 'http://';
3063
+
3064
+ /**
3065
+ * The port for connecting to the remote server
3066
+ *
3067
+ * The default is 80 for http:// connections
3068
+ * and 443 for https:// and ssl:// connections.
3069
+ *
3070
+ * @var integer
3071
+ */
3072
+ var $port = 80;
3073
+
3074
+ /**
3075
+ * A user name for accessing the RPC server
3076
+ * @var string
3077
+ * @see XML_RPC_Client::setCredentials()
3078
+ */
3079
+ var $username = '';
3080
+
3081
+ /**
3082
+ * A password for accessing the RPC server
3083
+ * @var string
3084
+ * @see XML_RPC_Client::setCredentials()
3085
+ */
3086
+ var $password = '';
3087
+
3088
+ /**
3089
+ * The name of the proxy server to use, if any
3090
+ * @var string
3091
+ */
3092
+ var $proxy = '';
3093
+
3094
+ /**
3095
+ * The protocol to use in contacting the proxy server, if any
3096
+ * @var string
3097
+ */
3098
+ var $proxy_protocol = 'http://';
3099
+
3100
+ /**
3101
+ * The port for connecting to the proxy server
3102
+ *
3103
+ * The default is 8080 for http:// connections
3104
+ * and 443 for https:// and ssl:// connections.
3105
+ *
3106
+ * @var integer
3107
+ */
3108
+ var $proxy_port = 8080;
3109
+
3110
+ /**
3111
+ * A user name for accessing the proxy server
3112
+ * @var string
3113
+ */
3114
+ var $proxy_user = '';
3115
+
3116
+ /**
3117
+ * A password for accessing the proxy server
3118
+ * @var string
3119
+ */
3120
+ var $proxy_pass = '';
3121
+
3122
+ /**
3123
+ * The error number, if any
3124
+ * @var integer
3125
+ */
3126
+ var $errno = 0;
3127
+
3128
+ /**
3129
+ * The error message, if any
3130
+ * @var string
3131
+ */
3132
+ var $errstr = '';
3133
+
3134
+ /**
3135
+ * The current debug mode (1 = on, 0 = off)
3136
+ * @var integer
3137
+ */
3138
+ var $debug = 0;
3139
+
3140
+ /**
3141
+ * The HTTP headers for the current request.
3142
+ * @var string
3143
+ */
3144
+ var $headers = '';
3145
+
3146
+
3147
+ /**
3148
+ * Sets the object's properties
3149
+ *
3150
+ * @param string $path the path and name of the RPC server script
3151
+ * you want the request to go to
3152
+ * @param string $server the URL of the remote server to connect to.
3153
+ * If this parameter doesn't specify a
3154
+ * protocol and $port is 443, ssl:// is
3155
+ * assumed.
3156
+ * @param integer $port a port for connecting to the remote server.
3157
+ * Defaults to 80 for http:// connections and
3158
+ * 443 for https:// and ssl:// connections.
3159
+ * @param string $proxy the URL of the proxy server to use, if any.
3160
+ * If this parameter doesn't specify a
3161
+ * protocol and $port is 443, ssl:// is
3162
+ * assumed.
3163
+ * @param integer $proxy_port a port for connecting to the remote server.
3164
+ * Defaults to 8080 for http:// connections and
3165
+ * 443 for https:// and ssl:// connections.
3166
+ * @param string $proxy_user a user name for accessing the proxy server
3167
+ * @param string $proxy_pass a password for accessing the proxy server
3168
+ *
3169
+ * @return void
3170
+ */
3171
+ function XML_RPC_Client($path, $server, $port = 0,
3172
+ $proxy = '', $proxy_port = 0,
3173
+ $proxy_user = '', $proxy_pass = '')
3174
+ {
3175
+ $this->path = $path;
3176
+ $this->proxy_user = $proxy_user;
3177
+ $this->proxy_pass = $proxy_pass;
3178
+
3179
+ $GLOBALS['XML_RPC_func_ereg']('^(http://|https://|ssl://|sslv2://)?(.*)$', $server, $match);
3180
+ if ($match[1] == '') {
3181
+ if ($port == 443) {
3182
+ $this->server = $match[2];
3183
+ $this->protocol = 'sslv3://';
3184
+ $this->port = 443;
3185
+ } else {
3186
+ $this->server = $match[2];
3187
+ if ($port) {
3188
+ $this->port = $port;
3189
+ }
3190
+ }
3191
+ } elseif ($match[1] == 'http://') {
3192
+ $this->server = $match[2];
3193
+ if ($port) {
3194
+ $this->port = $port;
3195
+ }
3196
+ } else {
3197
+ $this->server = $match[2];
3198
+ $this->protocol = 'sslv3://';
3199
+ if ($port) {
3200
+ $this->port = $port;
3201
+ } else {
3202
+ $this->port = 443;
3203
+ }
3204
+ }
3205
+
3206
+ if ($proxy) {
3207
+ $GLOBALS['XML_RPC_func_ereg']('^(http://|https://|ssl://)?(.*)$', $proxy, $match);
3208
+ if ($match[1] == '') {
3209
+ if ($proxy_port == 443) {
3210
+ $this->proxy = $match[2];
3211
+ $this->proxy_protocol = 'sslv3://';
3212
+ $this->proxy_port = 443;
3213
+ } else {
3214
+ $this->proxy = $match[2];
3215
+ if ($proxy_port) {
3216
+ $this->proxy_port = $proxy_port;
3217
+ }
3218
+ }
3219
+ } elseif ($match[1] == 'http://') {
3220
+ $this->proxy = $match[2];
3221
+ if ($proxy_port) {
3222
+ $this->proxy_port = $proxy_port;
3223
+ }
3224
+ } else {
3225
+ $this->proxy = $match[2];
3226
+ $this->proxy_protocol = 'sslv3://';
3227
+ if ($proxy_port) {
3228
+ $this->proxy_port = $proxy_port;
3229
+ } else {
3230
+ $this->proxy_port = 443;
3231
+ }
3232
+ }
3233
+ }
3234
+ }
3235
+
3236
+ /**
3237
+ * Change the current debug mode
3238
+ *
3239
+ * @param int $in where 1 = on, 0 = off
3240
+ *
3241
+ * @return void
3242
+ */
3243
+ function setDebug($in)
3244
+ {
3245
+ if ($in) {
3246
+ $this->debug = 1;
3247
+ } else {
3248
+ $this->debug = 0;
3249
+ }
3250
+ }
3251
+
3252
+ /**
3253
+ * Sets whether strings that contain characters which may cause PHP's
3254
+ * SAX-based XML parser to break should be automatically base64 encoded
3255
+ *
3256
+ * This is is a workaround for systems that don't have PHP's mbstring
3257
+ * extension available.
3258
+ *
3259
+ * @param int $in where 1 = on, 0 = off
3260
+ *
3261
+ * @return void
3262
+ */
3263
+ function setAutoBase64($in)
3264
+ {
3265
+ if ($in) {
3266
+ $GLOBALS['XML_RPC_auto_base64'] = true;
3267
+ } else {
3268
+ $GLOBALS['XML_RPC_auto_base64'] = false;
3269
+ }
3270
+ }
3271
+
3272
+ /**
3273
+ * Set username and password properties for connecting to the RPC server
3274
+ *
3275
+ * @param string $u the user name
3276
+ * @param string $p the password
3277
+ *
3278
+ * @return void
3279
+ *
3280
+ * @see XML_RPC_Client::$username, XML_RPC_Client::$password
3281
+ */
3282
+ function setCredentials($u, $p)
3283
+ {
3284
+ $this->username = $u;
3285
+ $this->password = $p;
3286
+ }
3287
+
3288
+ /**
3289
+ * Transmit the RPC request via HTTP 1.0 protocol
3290
+ *
3291
+ * @param object $msg the XML_RPC_Message object
3292
+ * @param int $timeout how many seconds to wait for the request
3293
+ *
3294
+ * @return object an XML_RPC_Response object. 0 is returned if any
3295
+ * problems happen.
3296
+ *
3297
+ * @see XML_RPC_Message, XML_RPC_Client::XML_RPC_Client(),
3298
+ * XML_RPC_Client::setCredentials()
3299
+ */
3300
+ function send($msg, $timeout = 0)
3301
+ {
3302
+ if (!($msg instanceof XML_RPC_Message)) {
3303
+ $this->errstr = 'send()\'s $msg parameter must be an'
3304
+ . ' XML_RPC_Message object.';
3305
+ $this->raiseError($this->errstr, XML_RPC_ERROR_PROGRAMMING);
3306
+ return 0;
3307
+ }
3308
+ $msg->debug = $this->debug;
3309
+ return $this->sendPayloadHTTP10($msg, $this->server, $this->port,
3310
+ $timeout, $this->username,
3311
+ $this->password);
3312
+ }
3313
+
3314
+ /**
3315
+ * Transmit the RPC request via HTTP 1.0 protocol
3316
+ *
3317
+ * Requests should be sent using XML_RPC_Client send() rather than
3318
+ * calling this method directly.
3319
+ *
3320
+ * @param object $msg the XML_RPC_Message object
3321
+ * @param string $server the server to send the request to
3322
+ * @param int $port the server port send the request to
3323
+ * @param int $timeout how many seconds to wait for the request
3324
+ * before giving up
3325
+ * @param string $username a user name for accessing the RPC server
3326
+ * @param string $password a password for accessing the RPC server
3327
+ *
3328
+ * @return object an XML_RPC_Response object. 0 is returned if any
3329
+ * problems happen.
3330
+ *
3331
+ * @access protected
3332
+ * @see XML_RPC_Client::send()
3333
+ */
3334
+ function sendPayloadHTTP10($msg, $server, $port, $timeout = 0,
3335
+ $username = '', $password = '')
3336
+ {
3337
+ // Pre-emptive BC hacks for fools calling sendPayloadHTTP10() directly
3338
+ if ($username != $this->username) {
3339
+ $this->setCredentials($username, $password);
3340
+ }
3341
+
3342
+ // Only create the payload if it was not created previously
3343
+ if (empty($msg->payload)) {
3344
+ $msg->createPayload();
3345
+ }
3346
+ $this->createHeaders($msg);
3347
+
3348
+ $op = $this->headers . "\r\n\r\n";
3349
+ $op .= $msg->payload;
3350
+
3351
+ if ($this->debug) {
3352
+ print "\n<pre>---SENT---\n";
3353
+ print $op;
3354
+ print "\n---END---</pre>\n";
3355
+ }
3356
+
3357
+ /*
3358
+ * If we're using a proxy open a socket to the proxy server
3359
+ * instead to the xml-rpc server
3360
+ */
3361
+ if ($this->proxy) {
3362
+ if ($this->proxy_protocol == 'http://') {
3363
+ $protocol = '';
3364
+ } else {
3365
+ $protocol = $this->proxy_protocol;
3366
+ }
3367
+ if ($timeout > 0) {
3368
+ $fp = @fsockopen($protocol . $this->proxy, $this->proxy_port,
3369
+ $this->errno, $this->errstr, $timeout);
3370
+ } else {
3371
+ $fp = @fsockopen($protocol . $this->proxy, $this->proxy_port,
3372
+ $this->errno, $this->errstr);
3373
+ }
3374
+ } else {
3375
+ if ($this->protocol == 'http://') {
3376
+ $protocol = '';
3377
+ } else {
3378
+ $protocol = $this->protocol;
3379
+ }
3380
+ if ($timeout > 0) {
3381
+ $fp = @fsockopen($protocol . $server, $port,
3382
+ $this->errno, $this->errstr, $timeout);
3383
+ } else {
3384
+ $fp = @fsockopen($protocol . $server, $port,
3385
+ $this->errno, $this->errstr);
3386
+ }
3387
+ }
3388
+
3389
+ /*
3390
+ * Just raising the error without returning it is strange,
3391
+ * but keep it here for backwards compatibility.
3392
+ */
3393
+ if (!$fp && $this->proxy) {
3394
+ $this->raiseError('Connection to proxy server '
3395
+ . $this->proxy . ':' . $this->proxy_port
3396
+ . ' failed. ' . $this->errstr,
3397
+ XML_RPC_ERROR_CONNECTION_FAILED);
3398
+ return 0;
3399
+ } elseif (!$fp) {
3400
+ $this->raiseError('Connection to RPC server '
3401
+ . $server . ':' . $port
3402
+ . ' failed. ' . $this->errstr,
3403
+ XML_RPC_ERROR_CONNECTION_FAILED);
3404
+ return 0;
3405
+ }
3406
+
3407
+ if ($timeout) {
3408
+ /*
3409
+ * Using socket_set_timeout() because stream_set_timeout()
3410
+ * was introduced in 4.3.0, but we need to support 4.2.0.
3411
+ */
3412
+ socket_set_timeout($fp, $timeout);
3413
+ }
3414
+
3415
+ if (!fputs($fp, $op, strlen($op))) {
3416
+ $this->errstr = 'Write error';
3417
+ return 0;
3418
+ }
3419
+ $resp = $msg->parseResponseFile($fp);
3420
+
3421
+ $meta = socket_get_status($fp);
3422
+ if ($meta['timed_out']) {
3423
+ fclose($fp);
3424
+ $this->errstr = 'RPC server did not send response before timeout.';
3425
+ $this->raiseError($this->errstr, XML_RPC_ERROR_CONNECTION_FAILED);
3426
+ return 0;
3427
+ }
3428
+
3429
+ fclose($fp);
3430
+ return $resp;
3431
+ }
3432
+
3433
+ /**
3434
+ * Determines the HTTP headers and puts it in the $headers property
3435
+ *
3436
+ * @param object $msg the XML_RPC_Message object
3437
+ *
3438
+ * @return boolean TRUE if okay, FALSE if the message payload isn't set.
3439
+ *
3440
+ * @access protected
3441
+ */
3442
+ function createHeaders($msg)
3443
+ {
3444
+ if (empty($msg->payload)) {
3445
+ return false;
3446
+ }
3447
+ if ($this->proxy) {
3448
+ $this->headers = 'POST ' . $this->protocol . $this->server;
3449
+ if ($this->proxy_port) {
3450
+ $this->headers .= ':' . $this->port;
3451
+ }
3452
+ } else {
3453
+ $this->headers = 'POST ';
3454
+ }
3455
+ $this->headers .= $this->path. " HTTP/1.0\r\n";
3456
+
3457
+ $this->headers .= "User-Agent: PEAR XML_RPC\r\n";
3458
+ $this->headers .= 'Host: ' . $this->server . "\r\n";
3459
+
3460
+ if ($this->proxy && $this->proxy_user) {
3461
+ $this->headers .= 'Proxy-Authorization: Basic '
3462
+ . base64_encode("$this->proxy_user:$this->proxy_pass")
3463
+ . "\r\n";
3464
+ }
3465
+
3466
+ // thanks to Grant Rauscher <grant7@firstworld.net> for this
3467
+ if ($this->username) {
3468
+ $this->headers .= 'Authorization: Basic '
3469
+ . base64_encode("$this->username:$this->password")
3470
+ . "\r\n";
3471
+ }
3472
+
3473
+ $this->headers .= "Content-Type: text/xml\r\n";
3474
+ $this->headers .= 'Content-Length: ' . strlen($msg->payload);
3475
+ return true;
3476
+ }
3477
+ }
3478
+
3479
+ /**
3480
+ * The methods and properties for interpreting responses to XML RPC requests
3481
+ *
3482
+ * @category Web Services
3483
+ * @package XML_RPC
3484
+ * @author Edd Dumbill <edd@usefulinc.com>
3485
+ * @author Stig Bakken <stig@php.net>
3486
+ * @author Martin Jansen <mj@php.net>
3487
+ * @author Daniel Convissor <danielc@php.net>
3488
+ * @copyright 1999-2001 Edd Dumbill, 2001-2010 The PHP Group
3489
+ * @license http://www.php.net/license/3_01.txt PHP License
3490
+ * @version Release: 1.5.3
3491
+ * @link http://pear.php.net/package/XML_RPC
3492
+ */
3493
+ class XML_RPC_Response extends XML_RPC_Base
3494
+ {
3495
+ var $xv;
3496
+ var $fn;
3497
+ var $fs;
3498
+ var $hdrs;
3499
+
3500
+ /**
3501
+ * @return void
3502
+ */
3503
+ function XML_RPC_Response($val, $fcode = 0, $fstr = '')
3504
+ {
3505
+ if ($fcode != 0) {
3506
+ $this->fn = $fcode;
3507
+ $this->fs = htmlspecialchars($fstr);
3508
+ } else {
3509
+ $this->xv = $val;
3510
+ }
3511
+ }
3512
+
3513
+ /**
3514
+ * @return int the error code
3515
+ */
3516
+ function faultCode()
3517
+ {
3518
+ if (isset($this->fn)) {
3519
+ return $this->fn;
3520
+ } else {
3521
+ return 0;
3522
+ }
3523
+ }
3524
+
3525
+ /**
3526
+ * @return string the error string
3527
+ */
3528
+ function faultString()
3529
+ {
3530
+ return $this->fs;
3531
+ }
3532
+
3533
+ /**
3534
+ * @return mixed the value
3535
+ */
3536
+ function value()
3537
+ {
3538
+ return $this->xv;
3539
+ }
3540
+
3541
+ /**
3542
+ * @return string the error message in XML format
3543
+ */
3544
+ function serialize()
3545
+ {
3546
+ $rs = "<methodResponse>\n";
3547
+ if ($this->fn) {
3548
+ $rs .= "<fault>
3549
+ <value>
3550
+ <struct>
3551
+ <member>
3552
+ <name>faultCode</name>
3553
+ <value><int>" . $this->fn . "</int></value>
3554
+ </member>
3555
+ <member>
3556
+ <name>faultString</name>
3557
+ <value><string>" . $this->fs . "</string></value>
3558
+ </member>
3559
+ </struct>
3560
+ </value>
3561
+ </fault>";
3562
+ } else {
3563
+ $rs .= "<params>\n<param>\n" . $this->xv->serialize() .
3564
+ "</param>\n</params>";
3565
+ }
3566
+ $rs .= "\n</methodResponse>";
3567
+ return $rs;
3568
+ }
3569
+ }
3570
+
3571
+ /**
3572
+ * The methods and properties for composing XML RPC messages
3573
+ *
3574
+ * @category Web Services
3575
+ * @package XML_RPC
3576
+ * @author Edd Dumbill <edd@usefulinc.com>
3577
+ * @author Stig Bakken <stig@php.net>
3578
+ * @author Martin Jansen <mj@php.net>
3579
+ * @author Daniel Convissor <danielc@php.net>
3580
+ * @copyright 1999-2001 Edd Dumbill, 2001-2010 The PHP Group
3581
+ * @license http://www.php.net/license/3_01.txt PHP License
3582
+ * @version Release: 1.5.3
3583
+ * @link http://pear.php.net/package/XML_RPC
3584
+ */
3585
+ class XML_RPC_Message extends XML_RPC_Base
3586
+ {
3587
+ /**
3588
+ * Should the payload's content be passed through mb_convert_encoding()?
3589
+ *
3590
+ * @see XML_RPC_Message::setConvertPayloadEncoding()
3591
+ * @since Property available since Release 1.5.1
3592
+ * @var boolean
3593
+ */
3594
+ var $convert_payload_encoding = false;
3595
+
3596
+ /**
3597
+ * The current debug mode (1 = on, 0 = off)
3598
+ * @var integer
3599
+ */
3600
+ var $debug = 0;
3601
+
3602
+ /**
3603
+ * The encoding to be used for outgoing messages
3604
+ *
3605
+ * Defaults to the value of <var>$GLOBALS['XML_RPC_defencoding']</var>
3606
+ *
3607
+ * @var string
3608
+ * @see XML_RPC_Message::setSendEncoding(),
3609
+ * $GLOBALS['XML_RPC_defencoding'], XML_RPC_Message::xml_header()
3610
+ */
3611
+ var $send_encoding = '';
3612
+
3613
+ /**
3614
+ * The method presently being evaluated
3615
+ * @var string
3616
+ */
3617
+ var $methodname = '';
3618
+
3619
+ /**
3620
+ * @var array
3621
+ */
3622
+ var $params = array();
3623
+
3624
+ /**
3625
+ * The XML message being generated
3626
+ * @var string
3627
+ */
3628
+ var $payload = '';
3629
+
3630
+ /**
3631
+ * Should extra line breaks be removed from the payload?
3632
+ * @since Property available since Release 1.4.6
3633
+ * @var boolean
3634
+ */
3635
+ var $remove_extra_lines = true;
3636
+
3637
+ /**
3638
+ * The XML response from the remote server
3639
+ * @since Property available since Release 1.4.6
3640
+ * @var string
3641
+ */
3642
+ var $response_payload = '';
3643
+
3644
+
3645
+ /**
3646
+ * @return void
3647
+ */
3648
+ function XML_RPC_Message($meth, $pars = 0)
3649
+ {
3650
+ $this->methodname = $meth;
3651
+ if (is_array($pars) && sizeof($pars) > 0) {
3652
+ for ($i = 0; $i < sizeof($pars); $i++) {
3653
+ $this->addParam($pars[$i]);
3654
+ }
3655
+ }
3656
+ }
3657
+
3658
+ /**
3659
+ * Produces the XML declaration including the encoding attribute
3660
+ *
3661
+ * The encoding is determined by this class' <var>$send_encoding</var>
3662
+ * property. If the <var>$send_encoding</var> property is not set, use
3663
+ * <var>$GLOBALS['XML_RPC_defencoding']</var>.
3664
+ *
3665
+ * @return string the XML declaration and <methodCall> element
3666
+ *
3667
+ * @see XML_RPC_Message::setSendEncoding(),
3668
+ * XML_RPC_Message::$send_encoding, $GLOBALS['XML_RPC_defencoding']
3669
+ */
3670
+ function xml_header()
3671
+ {
3672
+ global $XML_RPC_defencoding;
3673
+
3674
+ if (!$this->send_encoding) {
3675
+ $this->send_encoding = $XML_RPC_defencoding;
3676
+ }
3677
+ return '<?xml version="1.0" encoding="' . $this->send_encoding . '"?>'
3678
+ . "\n<methodCall>\n";
3679
+ }
3680
+
3681
+ /**
3682
+ * @return string the closing </methodCall> tag
3683
+ */
3684
+ function xml_footer()
3685
+ {
3686
+ return "</methodCall>\n";
3687
+ }
3688
+
3689
+ /**
3690
+ * Fills the XML_RPC_Message::$payload property
3691
+ *
3692
+ * Part of the process makes sure all line endings are in DOS format
3693
+ * (CRLF), which is probably required by specifications.
3694
+ *
3695
+ * If XML_RPC_Message::setConvertPayloadEncoding() was set to true,
3696
+ * the payload gets passed through mb_convert_encoding()
3697
+ * to ensure the payload matches the encoding set in the
3698
+ * XML declaration. The encoding type can be manually set via
3699
+ * XML_RPC_Message::setSendEncoding().
3700
+ *
3701
+ * @return void
3702
+ *
3703
+ * @uses XML_RPC_Message::xml_header(), XML_RPC_Message::xml_footer()
3704
+ * @see XML_RPC_Message::setSendEncoding(), $GLOBALS['XML_RPC_defencoding'],
3705
+ * XML_RPC_Message::setConvertPayloadEncoding()
3706
+ */
3707
+ function createPayload()
3708
+ {
3709
+ $this->payload = $this->xml_header();
3710
+ $this->payload .= '<methodName>' . $this->methodname . "</methodName>\n";
3711
+ $this->payload .= "<params>\n";
3712
+ for ($i = 0; $i < sizeof($this->params); $i++) {
3713
+ $p = $this->params[$i];
3714
+ $this->payload .= "<param>\n" . $p->serialize() . "</param>\n";
3715
+ }
3716
+ $this->payload .= "</params>\n";
3717
+ $this->payload .= $this->xml_footer();
3718
+ if ($this->remove_extra_lines) {
3719
+ $this->payload = $GLOBALS['XML_RPC_func_ereg_replace']("[\r\n]+", "\r\n", $this->payload);
3720
+ } else {
3721
+ $this->payload = $GLOBALS['XML_RPC_func_ereg_replace']("\r\n|\n|\r|\n\r", "\r\n", $this->payload);
3722
+ }
3723
+ if ($this->convert_payload_encoding) {
3724
+ $this->payload = mb_convert_encoding($this->payload, $this->send_encoding);
3725
+ }
3726
+ }
3727
+
3728
+ /**
3729
+ * @return string the name of the method
3730
+ */
3731
+ function method($meth = '')
3732
+ {
3733
+ if ($meth != '') {
3734
+ $this->methodname = $meth;
3735
+ }
3736
+ return $this->methodname;
3737
+ }
3738
+
3739
+ /**
3740
+ * @return string the payload
3741
+ */
3742
+ function serialize()
3743
+ {
3744
+ $this->createPayload();
3745
+ return $this->payload;
3746
+ }
3747
+
3748
+ /**
3749
+ * @return void
3750
+ */
3751
+ function addParam($par)
3752
+ {
3753
+ $this->params[] = $par;
3754
+ }
3755
+
3756
+ /**
3757
+ * Obtains an XML_RPC_Value object for the given parameter
3758
+ *
3759
+ * @param int $i the index number of the parameter to obtain
3760
+ *
3761
+ * @return object the XML_RPC_Value object.
3762
+ * If the parameter doesn't exist, an XML_RPC_Response object.
3763
+ *
3764
+ * @since Returns XML_RPC_Response object on error since Release 1.3.0
3765
+ */
3766
+ function getParam($i)
3767
+ {
3768
+ global $XML_RPC_err, $XML_RPC_str;
3769
+
3770
+ if (isset($this->params[$i])) {
3771
+ return $this->params[$i];
3772
+ } else {
3773
+ $this->raiseError('The submitted request did not contain this parameter',
3774
+ XML_RPC_ERROR_INCORRECT_PARAMS);
3775
+ return new XML_RPC_Response(0, $XML_RPC_err['incorrect_params'],
3776
+ $XML_RPC_str['incorrect_params']);
3777
+ }
3778
+ }
3779
+
3780
+ /**
3781
+ * @return int the number of parameters
3782
+ */
3783
+ function getNumParams()
3784
+ {
3785
+ return sizeof($this->params);
3786
+ }
3787
+
3788
+ /**
3789
+ * Sets whether the payload's content gets passed through
3790
+ * mb_convert_encoding()
3791
+ *
3792
+ * Returns PEAR_ERROR object if mb_convert_encoding() isn't available.
3793
+ *
3794
+ * @param int $in where 1 = on, 0 = off
3795
+ *
3796
+ * @return void
3797
+ *
3798
+ * @see XML_RPC_Message::setSendEncoding()
3799
+ * @since Method available since Release 1.5.1
3800
+ */
3801
+ function setConvertPayloadEncoding($in)
3802
+ {
3803
+ if ($in && !function_exists('mb_convert_encoding')) {
3804
+ return $this->raiseError('mb_convert_encoding() is not available',
3805
+ XML_RPC_ERROR_PROGRAMMING);
3806
+ }
3807
+ $this->convert_payload_encoding = $in;
3808
+ }
3809
+
3810
+ /**
3811
+ * Sets the XML declaration's encoding attribute
3812
+ *
3813
+ * @param string $type the encoding type (ISO-8859-1, UTF-8 or US-ASCII)
3814
+ *
3815
+ * @return void
3816
+ *
3817
+ * @see XML_RPC_Message::setConvertPayloadEncoding(), XML_RPC_Message::xml_header()
3818
+ * @since Method available since Release 1.2.0
3819
+ */
3820
+ function setSendEncoding($type)
3821
+ {
3822
+ $this->send_encoding = $type;
3823
+ }
3824
+
3825
+ /**
3826
+ * Determine the XML's encoding via the encoding attribute
3827
+ * in the XML declaration
3828
+ *
3829
+ * If the encoding parameter is not set or is not ISO-8859-1, UTF-8
3830
+ * or US-ASCII, $XML_RPC_defencoding will be returned.
3831
+ *
3832
+ * @param string $data the XML that will be parsed
3833
+ *
3834
+ * @return string the encoding to be used
3835
+ *
3836
+ * @link http://php.net/xml_parser_create
3837
+ * @since Method available since Release 1.2.0
3838
+ */
3839
+ function getEncoding($data)
3840
+ {
3841
+ global $XML_RPC_defencoding;
3842
+
3843
+ if ($GLOBALS['XML_RPC_func_ereg']('<\?xml[^>]*[:space:]*encoding[:space:]*=[:space:]*[\'"]([^"\']*)[\'"]',
3844
+ $data, $match))
3845
+ {
3846
+ $match[1] = trim(strtoupper($match[1]));
3847
+ switch ($match[1]) {
3848
+ case 'ISO-8859-1':
3849
+ case 'UTF-8':
3850
+ case 'US-ASCII':
3851
+ return $match[1];
3852
+ break;
3853
+
3854
+ default:
3855
+ return $XML_RPC_defencoding;
3856
+ }
3857
+ } else {
3858
+ return $XML_RPC_defencoding;
3859
+ }
3860
+ }
3861
+
3862
+ /**
3863
+ * @return object a new XML_RPC_Response object
3864
+ */
3865
+ function parseResponseFile($fp)
3866
+ {
3867
+ $ipd = '';
3868
+ while ($data = @fread($fp, 8192)) {
3869
+ $ipd .= $data;
3870
+ }
3871
+ return $this->parseResponse($ipd);
3872
+ }
3873
+
3874
+ /**
3875
+ * @return object a new XML_RPC_Response object
3876
+ */
3877
+ function parseResponse($data = '')
3878
+ {
3879
+ global $XML_RPC_xh, $XML_RPC_err, $XML_RPC_str, $XML_RPC_defencoding;
3880
+
3881
+ $encoding = $this->getEncoding($data);
3882
+ $parser_resource = xml_parser_create($encoding);
3883
+ $parser = (int) $parser_resource;
3884
+
3885
+ $XML_RPC_xh = array();
3886
+ $XML_RPC_xh[$parser] = array();
3887
+
3888
+ $XML_RPC_xh[$parser]['cm'] = 0;
3889
+ $XML_RPC_xh[$parser]['isf'] = 0;
3890
+ $XML_RPC_xh[$parser]['ac'] = '';
3891
+ $XML_RPC_xh[$parser]['qt'] = '';
3892
+ $XML_RPC_xh[$parser]['stack'] = array();
3893
+ $XML_RPC_xh[$parser]['valuestack'] = array();
3894
+
3895
+ xml_parser_set_option($parser_resource, XML_OPTION_CASE_FOLDING, true);
3896
+ xml_set_element_handler($parser_resource, 'XML_RPC_se', 'XML_RPC_ee');
3897
+ xml_set_character_data_handler($parser_resource, 'XML_RPC_cd');
3898
+
3899
+ $hdrfnd = 0;
3900
+ if ($this->debug) {
3901
+ print "\n<pre>---GOT---\n";
3902
+ print isset($_SERVER['SERVER_PROTOCOL']) ? htmlspecialchars($data) : $data;
3903
+ print "\n---END---</pre>\n";
3904
+ }
3905
+
3906
+ // See if response is a 200 or a 100 then a 200, else raise error.
3907
+ // But only do this if we're using the HTTP protocol.
3908
+ if ($GLOBALS['XML_RPC_func_ereg']('^HTTP', $data) &&
3909
+ !$GLOBALS['XML_RPC_func_ereg']('^HTTP/[0-9\.]+ 200 ', $data) &&
3910
+ !$GLOBALS['XML_RPC_func_ereg']('^HTTP/[0-9\.]+ 10[0-9]([A-Z ]+)?[\r\n]+HTTP/[0-9\.]+ 200', $data))
3911
+ {
3912
+ $errstr = substr($data, 0, strpos($data, "\n") - 1);
3913
+ error_log('HTTP error, got response: ' . $errstr);
3914
+ $r = new XML_RPC_Response(0, $XML_RPC_err['http_error'],
3915
+ $XML_RPC_str['http_error'] . ' (' .
3916
+ $errstr . ')');
3917
+ xml_parser_free($parser_resource);
3918
+ return $r;
3919
+ }
3920
+
3921
+ // gotta get rid of headers here
3922
+ if (!$hdrfnd && ($brpos = strpos($data,"\r\n\r\n"))) {
3923
+ $XML_RPC_xh[$parser]['ha'] = substr($data, 0, $brpos);
3924
+ $data = substr($data, $brpos + 4);
3925
+ $hdrfnd = 1;
3926
+ }
3927
+
3928
+ /*
3929
+ * be tolerant of junk after methodResponse
3930
+ * (e.g. javascript automatically inserted by free hosts)
3931
+ * thanks to Luca Mariano <luca.mariano@email.it>
3932
+ */
3933
+ $data = substr($data, 0, strpos($data, "</methodResponse>") + 17);
3934
+ $this->response_payload = $data;
3935
+
3936
+ if (!xml_parse($parser_resource, $data, sizeof($data))) {
3937
+ // thanks to Peter Kocks <peter.kocks@baygate.com>
3938
+ if (xml_get_current_line_number($parser_resource) == 1) {
3939
+ $errstr = 'XML error at line 1, check URL';
3940
+ } else {
3941
+ $errstr = sprintf('XML error: %s at line %d',
3942
+ xml_error_string(xml_get_error_code($parser_resource)),
3943
+ xml_get_current_line_number($parser_resource));
3944
+ }
3945
+ error_log($errstr);
3946
+ $r = new XML_RPC_Response(0, $XML_RPC_err['invalid_return'],
3947
+ $XML_RPC_str['invalid_return']);
3948
+ xml_parser_free($parser_resource);
3949
+ return $r;
3950
+ }
3951
+
3952
+ xml_parser_free($parser_resource);
3953
+
3954
+ if ($this->debug) {
3955
+ print "\n<pre>---PARSED---\n";
3956
+ var_dump($XML_RPC_xh[$parser]['value']);
3957
+ print "---END---</pre>\n";
3958
+ }
3959
+
3960
+ if ($XML_RPC_xh[$parser]['isf'] > 1) {
3961
+ $r = new XML_RPC_Response(0, $XML_RPC_err['invalid_return'],
3962
+ $XML_RPC_str['invalid_return'].' '.$XML_RPC_xh[$parser]['isf_reason']);
3963
+ } elseif (!is_object($XML_RPC_xh[$parser]['value'])) {
3964
+ // then something odd has happened
3965
+ // and it's time to generate a client side error
3966
+ // indicating something odd went on
3967
+ $r = new XML_RPC_Response(0, $XML_RPC_err['invalid_return'],
3968
+ $XML_RPC_str['invalid_return']);
3969
+ } else {
3970
+ $v = $XML_RPC_xh[$parser]['value'];
3971
+ if ($XML_RPC_xh[$parser]['isf']) {
3972
+ $f = $v->structmem('faultCode');
3973
+ $fs = $v->structmem('faultString');
3974
+ $r = new XML_RPC_Response($v, $f->scalarval(),
3975
+ $fs->scalarval());
3976
+ } else {
3977
+ $r = new XML_RPC_Response($v);
3978
+ }
3979
+ }
3980
+
3981
+ $r->hdrs = explode("\r?\n", $XML_RPC_xh[$parser]['ha'][1]);
3982
+
3983
+ return $r;
3984
+ }
3985
+ }
3986
+
3987
+ /**
3988
+ * The methods and properties that represent data in XML RPC format
3989
+ *
3990
+ * @category Web Services
3991
+ * @package XML_RPC
3992
+ * @author Edd Dumbill <edd@usefulinc.com>
3993
+ * @author Stig Bakken <stig@php.net>
3994
+ * @author Martin Jansen <mj@php.net>
3995
+ * @author Daniel Convissor <danielc@php.net>
3996
+ * @copyright 1999-2001 Edd Dumbill, 2001-2010 The PHP Group
3997
+ * @license http://www.php.net/license/3_01.txt PHP License
3998
+ * @version Release: 1.5.3
3999
+ * @link http://pear.php.net/package/XML_RPC
4000
+ */
4001
+ class XML_RPC_Value extends XML_RPC_Base
4002
+ {
4003
+ var $me = array();
4004
+ var $mytype = 0;
4005
+
4006
+ /**
4007
+ * @return void
4008
+ */
4009
+ function XML_RPC_Value($val = -1, $type = '')
4010
+ {
4011
+ $this->me = array();
4012
+ $this->mytype = 0;
4013
+ if ($val != -1 || $type != '') {
4014
+ if ($type == '') {
4015
+ $type = 'string';
4016
+ }
4017
+ if (!array_key_exists($type, $GLOBALS['XML_RPC_Types'])) {
4018
+ // XXX
4019
+ // need some way to report this error
4020
+ } elseif ($GLOBALS['XML_RPC_Types'][$type] == 1) {
4021
+ $this->addScalar($val, $type);
4022
+ } elseif ($GLOBALS['XML_RPC_Types'][$type] == 2) {
4023
+ $this->addArray($val);
4024
+ } elseif ($GLOBALS['XML_RPC_Types'][$type] == 3) {
4025
+ $this->addStruct($val);
4026
+ }
4027
+ }
4028
+ }
4029
+
4030
+ /**
4031
+ * @return int returns 1 if successful or 0 if there are problems
4032
+ */
4033
+ function addScalar($val, $type = 'string')
4034
+ {
4035
+ if ($this->mytype == 1) {
4036
+ $this->raiseError('Scalar can have only one value',
4037
+ XML_RPC_ERROR_INVALID_TYPE);
4038
+ return 0;
4039
+ }
4040
+ $typeof = $GLOBALS['XML_RPC_Types'][$type];
4041
+ if ($typeof != 1) {
4042
+ $this->raiseError("Not a scalar type (${typeof})",
4043
+ XML_RPC_ERROR_INVALID_TYPE);
4044
+ return 0;
4045
+ }
4046
+
4047
+ if ($type == $GLOBALS['XML_RPC_Boolean']) {
4048
+ if (strcasecmp($val, 'true') == 0
4049
+ || $val == 1
4050
+ || ($val == true && strcasecmp($val, 'false')))
4051
+ {
4052
+ $val = 1;
4053
+ } else {
4054
+ $val = 0;
4055
+ }
4056
+ }
4057
+
4058
+ if ($this->mytype == 2) {
4059
+ // we're adding to an array here
4060
+ $ar = $this->me['array'];
4061
+ $ar[] = new XML_RPC_Value($val, $type);
4062
+ $this->me['array'] = $ar;
4063
+ } else {
4064
+ // a scalar, so set the value and remember we're scalar
4065
+ $this->me[$type] = $val;
4066
+ $this->mytype = $typeof;
4067
+ }
4068
+ return 1;
4069
+ }
4070
+
4071
+ /**
4072
+ * @return int returns 1 if successful or 0 if there are problems
4073
+ */
4074
+ function addArray($vals)
4075
+ {
4076
+ if ($this->mytype != 0) {
4077
+ $this->raiseError(
4078
+ 'Already initialized as a [' . $this->kindOf() . ']',
4079
+ XML_RPC_ERROR_ALREADY_INITIALIZED);
4080
+ return 0;
4081
+ }
4082
+ $this->mytype = $GLOBALS['XML_RPC_Types']['array'];
4083
+ $this->me['array'] = $vals;
4084
+ return 1;
4085
+ }
4086
+
4087
+ /**
4088
+ * @return int returns 1 if successful or 0 if there are problems
4089
+ */
4090
+ function addStruct($vals)
4091
+ {
4092
+ if ($this->mytype != 0) {
4093
+ $this->raiseError(
4094
+ 'Already initialized as a [' . $this->kindOf() . ']',
4095
+ XML_RPC_ERROR_ALREADY_INITIALIZED);
4096
+ return 0;
4097
+ }
4098
+ $this->mytype = $GLOBALS['XML_RPC_Types']['struct'];
4099
+ $this->me['struct'] = $vals;
4100
+ return 1;
4101
+ }
4102
+
4103
+ /**
4104
+ * @return void
4105
+ */
4106
+ function dump($ar)
4107
+ {
4108
+ reset($ar);
4109
+ foreach ($ar as $key => $val) {
4110
+ echo "$key => $val<br />";
4111
+ if ($key == 'array') {
4112
+ foreach ($val as $key2 => $val2) {
4113
+ echo "-- $key2 => $val2<br />";
4114
+ }
4115
+ }
4116
+ }
4117
+ }
4118
+
4119
+ /**
4120
+ * @return string the data type of the current value
4121
+ */
4122
+ function kindOf()
4123
+ {
4124
+ switch ($this->mytype) {
4125
+ case 3:
4126
+ return 'struct';
4127
+
4128
+ case 2:
4129
+ return 'array';
4130
+
4131
+ case 1:
4132
+ return 'scalar';
4133
+
4134
+ default:
4135
+ return 'undef';
4136
+ }
4137
+ }
4138
+
4139
+ /**
4140
+ * @return string the data in XML format
4141
+ */
4142
+ function serializedata($typ, $val)
4143
+ {
4144
+ $rs = '';
4145
+ if (!array_key_exists($typ, $GLOBALS['XML_RPC_Types'])) {
4146
+ // XXX
4147
+ // need some way to report this error
4148
+ return;
4149
+ }
4150
+ switch ($GLOBALS['XML_RPC_Types'][$typ]) {
4151
+ case 3:
4152
+ // struct
4153
+ $rs .= "<struct>\n";
4154
+ reset($val);
4155
+ foreach ($val as $key2 => $val2) {
4156
+ $rs .= "<member><name>${key2}</name>\n";
4157
+ $rs .= $this->serializeval($val2);
4158
+ $rs .= "</member>\n";
4159
+ }
4160
+ $rs .= '</struct>';
4161
+ break;
4162
+
4163
+ case 2:
4164
+ // array
4165
+ $rs .= "<array>\n<data>\n";
4166
+ foreach ($val as $value) {
4167
+ $rs .= $this->serializeval($value);
4168
+ }
4169
+ $rs .= "</data>\n</array>";
4170
+ break;
4171
+
4172
+ case 1:
4173
+ switch ($typ) {
4174
+ case $GLOBALS['XML_RPC_Base64']:
4175
+ $rs .= "<${typ}>" . base64_encode($val) . "</${typ}>";
4176
+ break;
4177
+ case $GLOBALS['XML_RPC_Boolean']:
4178
+ $rs .= "<${typ}>" . ($val ? '1' : '0') . "</${typ}>";
4179
+ break;
4180
+ case $GLOBALS['XML_RPC_String']:
4181
+ $rs .= "<${typ}>" . htmlspecialchars($val). "</${typ}>";
4182
+ break;
4183
+ default:
4184
+ $rs .= "<${typ}>${val}</${typ}>";
4185
+ }
4186
+ }
4187
+ return $rs;
4188
+ }
4189
+
4190
+ /**
4191
+ * @return string the data in XML format
4192
+ */
4193
+ function serialize()
4194
+ {
4195
+ return $this->serializeval($this);
4196
+ }
4197
+
4198
+ /**
4199
+ * @return string the data in XML format
4200
+ */
4201
+ function serializeval($o)
4202
+ {
4203
+ if (!is_object($o) || empty($o->me) || !is_array($o->me)) {
4204
+ return '';
4205
+ }
4206
+ $ar = $o->me;
4207
+ reset($ar);
4208
+ list($typ, $val) = each($ar);
4209
+ return '<value>' . $this->serializedata($typ, $val) . "</value>\n";
4210
+ }
4211
+
4212
+ /**
4213
+ * @return mixed the contents of the element requested
4214
+ */
4215
+ function structmem($m)
4216
+ {
4217
+ return $this->me['struct'][$m];
4218
+ }
4219
+
4220
+ /**
4221
+ * @return void
4222
+ */
4223
+ function structreset()
4224
+ {
4225
+ reset($this->me['struct']);
4226
+ }
4227
+
4228
+ /**
4229
+ * @return the key/value pair of the struct's current element
4230
+ */
4231
+ function structeach()
4232
+ {
4233
+ return each($this->me['struct']);
4234
+ }
4235
+
4236
+ /**
4237
+ * @return mixed the current value
4238
+ */
4239
+ function getval()
4240
+ {
4241
+ // UNSTABLE
4242
+
4243
+ reset($this->me);
4244
+ $b = current($this->me);
4245
+
4246
+ // contributed by I Sofer, 2001-03-24
4247
+ // add support for nested arrays to scalarval
4248
+ // i've created a new method here, so as to
4249
+ // preserve back compatibility
4250
+
4251
+ if (is_array($b)) {
4252
+ foreach ($b as $id => $cont) {
4253
+ $b[$id] = $cont->scalarval();
4254
+ }
4255
+ }
4256
+
4257
+ // add support for structures directly encoding php objects
4258
+ if (is_object($b)) {
4259
+ $t = get_object_vars($b);
4260
+ foreach ($t as $id => $cont) {
4261
+ $t[$id] = $cont->scalarval();
4262
+ }
4263
+ foreach ($t as $id => $cont) {
4264
+ $b->$id = $cont;
4265
+ }
4266
+ }
4267
+
4268
+ // end contrib
4269
+ return $b;
4270
+ }
4271
+
4272
+ /**
4273
+ * @return mixed the current element's scalar value. If the value is
4274
+ * not scalar, FALSE is returned.
4275
+ */
4276
+ function scalarval()
4277
+ {
4278
+ reset($this->me);
4279
+ $v = current($this->me);
4280
+ if (!is_scalar($v)) {
4281
+ $v = false;
4282
+ }
4283
+ return $v;
4284
+ }
4285
+
4286
+ /**
4287
+ * @return string
4288
+ */
4289
+ function scalartyp()
4290
+ {
4291
+ reset($this->me);
4292
+ $a = key($this->me);
4293
+ if ($a == $GLOBALS['XML_RPC_I4']) {
4294
+ $a = $GLOBALS['XML_RPC_Int'];
4295
+ }
4296
+ return $a;
4297
+ }
4298
+
4299
+ /**
4300
+ * @return mixed the struct's current element
4301
+ */
4302
+ function arraymem($m)
4303
+ {
4304
+ return $this->me['array'][$m];
4305
+ }
4306
+
4307
+ /**
4308
+ * @return int the number of elements in the array
4309
+ */
4310
+ function arraysize()
4311
+ {
4312
+ reset($this->me);
4313
+ list($a, $b) = each($this->me);
4314
+ return sizeof($b);
4315
+ }
4316
+
4317
+ /**
4318
+ * Determines if the item submitted is an XML_RPC_Value object
4319
+ *
4320
+ * @param mixed $val the variable to be evaluated
4321
+ *
4322
+ * @return bool TRUE if the item is an XML_RPC_Value object
4323
+ *
4324
+ * @static
4325
+ * @since Method available since Release 1.3.0
4326
+ */
4327
+ function isValue($val)
4328
+ {
4329
+ return (strtolower(get_class($val)) == 'xml_rpc_value');
4330
+ }
4331
+ }
4332
+
4333
+ /**
4334
+ * Return an ISO8601 encoded string
4335
+ *
4336
+ * While timezones ought to be supported, the XML-RPC spec says:
4337
+ *
4338
+ * "Don't assume a timezone. It should be specified by the server in its
4339
+ * documentation what assumptions it makes about timezones."
4340
+ *
4341
+ * This routine always assumes localtime unless $utc is set to 1, in which
4342
+ * case UTC is assumed and an adjustment for locale is made when encoding.
4343
+ *
4344
+ * @return string the formatted date
4345
+ */
4346
+ function XML_RPC_iso8601_encode($timet, $utc = 0)
4347
+ {
4348
+ if (!$utc) {
4349
+ $t = strftime('%Y%m%dT%H:%M:%S', $timet);
4350
+ } else {
4351
+ if (function_exists('gmstrftime')) {
4352
+ // gmstrftime doesn't exist in some versions
4353
+ // of PHP
4354
+ $t = gmstrftime('%Y%m%dT%H:%M:%S', $timet);
4355
+ } else {
4356
+ $t = strftime('%Y%m%dT%H:%M:%S', $timet - date('Z'));
4357
+ }
4358
+ }
4359
+ return $t;
4360
+ }
4361
+
4362
+ /**
4363
+ * Convert a datetime string into a Unix timestamp
4364
+ *
4365
+ * While timezones ought to be supported, the XML-RPC spec says:
4366
+ *
4367
+ * "Don't assume a timezone. It should be specified by the server in its
4368
+ * documentation what assumptions it makes about timezones."
4369
+ *
4370
+ * This routine always assumes localtime unless $utc is set to 1, in which
4371
+ * case UTC is assumed and an adjustment for locale is made when encoding.
4372
+ *
4373
+ * @return int the unix timestamp of the date submitted
4374
+ */
4375
+ function XML_RPC_iso8601_decode($idate, $utc = 0)
4376
+ {
4377
+ $t = 0;
4378
+ if ($GLOBALS['XML_RPC_func_ereg']('([0-9]{4})([0-9]{2})([0-9]{2})T([0-9]{2}):([0-9]{2}):([0-9]{2})', $idate, $regs)) {
4379
+ if ($utc) {
4380
+ $t = gmmktime($regs[4], $regs[5], $regs[6], $regs[2], $regs[3], $regs[1]);
4381
+ } else {
4382
+ $t = mktime($regs[4], $regs[5], $regs[6], $regs[2], $regs[3], $regs[1]);
4383
+ }
4384
+ }
4385
+ return $t;
4386
+ }
4387
+
4388
+ /**
4389
+ * Converts an XML_RPC_Value object into native PHP types
4390
+ *
4391
+ * @param object $XML_RPC_val the XML_RPC_Value object to decode
4392
+ *
4393
+ * @return mixed the PHP values
4394
+ */
4395
+ function XML_RPC_decode($XML_RPC_val)
4396
+ {
4397
+ $kind = $XML_RPC_val->kindOf();
4398
+
4399
+ if ($kind == 'scalar') {
4400
+ return $XML_RPC_val->scalarval();
4401
+
4402
+ } elseif ($kind == 'array') {
4403
+ $size = $XML_RPC_val->arraysize();
4404
+ $arr = array();
4405
+ for ($i = 0; $i < $size; $i++) {
4406
+ $arr[] = XML_RPC_decode($XML_RPC_val->arraymem($i));
4407
+ }
4408
+ return $arr;
4409
+
4410
+ } elseif ($kind == 'struct') {
4411
+ $XML_RPC_val->structreset();
4412
+ $arr = array();
4413
+ while (list($key, $value) = $XML_RPC_val->structeach()) {
4414
+ $arr[$key] = XML_RPC_decode($value);
4415
+ }
4416
+ return $arr;
4417
+ }
4418
+ }
4419
+
4420
+ /**
4421
+ * Converts native PHP types into an XML_RPC_Value object
4422
+ *
4423
+ * @param mixed $php_val the PHP value or variable you want encoded
4424
+ *
4425
+ * @return object the XML_RPC_Value object
4426
+ */
4427
+ function XML_RPC_encode($php_val)
4428
+ {
4429
+ $type = gettype($php_val);
4430
+ $XML_RPC_val = new XML_RPC_Value;
4431
+
4432
+ switch ($type) {
4433
+ case 'array':
4434
+ if (empty($php_val)) {
4435
+ $XML_RPC_val->addArray($php_val);
4436
+ break;
4437
+ }
4438
+ $tmp = array_diff(array_keys($php_val), range(0, count($php_val)-1));
4439
+ if (empty($tmp)) {
4440
+ $arr = array();
4441
+ foreach ($php_val as $k => $v) {
4442
+ $arr[$k] = XML_RPC_encode($v);
4443
+ }
4444
+ $XML_RPC_val->addArray($arr);
4445
+ break;
4446
+ }
4447
+ // fall though if it's not an enumerated array
4448
+
4449
+ case 'object':
4450
+ $arr = array();
4451
+ foreach ($php_val as $k => $v) {
4452
+ $arr[$k] = XML_RPC_encode($v);
4453
+ }
4454
+ $XML_RPC_val->addStruct($arr);
4455
+ break;
4456
+
4457
+ case 'integer':
4458
+ $XML_RPC_val->addScalar($php_val, $GLOBALS['XML_RPC_Int']);
4459
+ break;
4460
+
4461
+ case 'double':
4462
+ $XML_RPC_val->addScalar($php_val, $GLOBALS['XML_RPC_Double']);
4463
+ break;
4464
+
4465
+ case 'string':
4466
+ case 'NULL':
4467
+ if ($GLOBALS['XML_RPC_func_ereg']('^[0-9]{8}\T{1}[0-9]{2}\:[0-9]{2}\:[0-9]{2}$', $php_val)) {
4468
+ $XML_RPC_val->addScalar($php_val, $GLOBALS['XML_RPC_DateTime']);
4469
+ } elseif ($GLOBALS['XML_RPC_auto_base64']
4470
+ && $GLOBALS['XML_RPC_func_ereg']("[^ -~\t\r\n]", $php_val))
4471
+ {
4472
+ // Characters other than alpha-numeric, punctuation, SP, TAB,
4473
+ // LF and CR break the XML parser, encode value via Base 64.
4474
+ $XML_RPC_val->addScalar($php_val, $GLOBALS['XML_RPC_Base64']);
4475
+ } else {
4476
+ $XML_RPC_val->addScalar($php_val, $GLOBALS['XML_RPC_String']);
4477
+ }
4478
+ break;
4479
+
4480
+ case 'boolean':
4481
+ // Add support for encoding/decoding of booleans, since they
4482
+ // are supported in PHP
4483
+ // by <G_Giunta_2001-02-29>
4484
+ $XML_RPC_val->addScalar($php_val, $GLOBALS['XML_RPC_Boolean']);
4485
+ break;
4486
+
4487
+ case 'unknown type':
4488
+ default:
4489
+ $XML_RPC_val = false;
4490
+ }
4491
+ return $XML_RPC_val;
4492
+ }
4493
+
4494
+ /*
4495
+ * Local variables:
4496
+ * tab-width: 4
4497
+ * c-basic-offset: 4
4498
+ * c-hanging-comment-ender-p: nil
4499
+ * End:
4500
+ */
4501
+ ?>
app/code/community/Klarna/KlarnaPaymentModule/Helper/pclasses.php ADDED
@@ -0,0 +1,153 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ function correct_currency($pclass, $curr){
3
+ switch($pclass){
4
+ case 338:
5
+ return (0 == $curr);
6
+ case 337:
7
+ return (0 == $curr);
8
+ case 336:
9
+ return (0 == $curr);
10
+ case 351:
11
+ return (3 == $curr);
12
+ case 350:
13
+ return (3 == $curr);
14
+ case 145:
15
+ return (2 == $curr);
16
+ case 146:
17
+ return (2 == $curr);
18
+ case 320:
19
+ return (2 == $curr);
20
+ }
21
+ }
22
+
23
+ function get_months($pclass){
24
+ switch($pclass){
25
+ case 338:
26
+ return 24;
27
+ case 337:
28
+ return 24;
29
+ case 336:
30
+ return 6;
31
+ case 351:
32
+ return 6;
33
+ case 350:
34
+ return 24;
35
+ case 145:
36
+ return 3;
37
+ case 146:
38
+ return 6;
39
+ case 320:
40
+ return 24;
41
+ }
42
+ }
43
+
44
+ function get_month_fee($pclass){
45
+ switch($pclass){
46
+ case 338:
47
+ return 2900;
48
+ case 337:
49
+ return 2900;
50
+ case 336:
51
+ return 2900;
52
+ case 351:
53
+ return 3900;
54
+ case 350:
55
+ return 3900;
56
+ case 145:
57
+ return 395;
58
+ case 146:
59
+ return 395;
60
+ case 320:
61
+ return 395;
62
+ }
63
+ }
64
+
65
+ function get_start_fee($pclass){
66
+ switch($pclass){
67
+ case 338:
68
+ return 0;
69
+ case 337:
70
+ return 29500;
71
+ case 336:
72
+ return 19500;
73
+ case 351:
74
+ return 19500;
75
+ case 350:
76
+ return 0;
77
+ case 145:
78
+ return 950;
79
+ case 146:
80
+ return 1950;
81
+ case 320:
82
+ return 0;
83
+ }
84
+ }
85
+
86
+ function get_rate($pclass){
87
+ switch($pclass){
88
+ case 338:
89
+ return 1950;
90
+ case 337:
91
+ return 995;
92
+ case 336:
93
+ return 0;
94
+ case 351:
95
+ return 0;
96
+ case 350:
97
+ return 2200;
98
+ case 145:
99
+ return 0;
100
+ case 146:
101
+ return 0;
102
+ case 320:
103
+ return 2200;
104
+ }
105
+ }
106
+
107
+ function get_type($pclass){
108
+ switch($pclass){
109
+ case 338:
110
+ return 1;
111
+ case 337:
112
+ return 0;
113
+ case 336:
114
+ return 0;
115
+ case 351:
116
+ return 0;
117
+ case 350:
118
+ return 1;
119
+ case 145:
120
+ return 0;
121
+ case 146:
122
+ return 0;
123
+ case 320:
124
+ return 1;
125
+ }
126
+ }
127
+
128
+ function get_min_sum($pclass){
129
+ switch($pclass){
130
+ case 338:
131
+ return 20000;
132
+ case 337:
133
+ return 100000;
134
+ case 336:
135
+ return 100000;
136
+ case 351:
137
+ return 100000;
138
+ case 350:
139
+ return 20000;
140
+ case 145:
141
+ return 10000;
142
+ case 146:
143
+ return 10000;
144
+ case 320:
145
+ return 2000;
146
+ }
147
+ }
148
+
149
+ function get_pclass_ids(){
150
+ return array(338, 337, 336, 351, 350, 145, 146, 320);
151
+ }
152
+
153
+ ?>
app/code/community/Klarna/KlarnaPaymentModule/Model/Config/Backend/Invoicefee.php ADDED
@@ -0,0 +1,121 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Klarna_KlarnaPaymentModule_Model_Config_Backend_Invoicefee extends Mage_Adminhtml_Model_System_Config_Backend_Serialized_Array
4
+ {
5
+
6
+
7
+ protected function _afterLoad()
8
+ {
9
+ $value = $this->getValue();
10
+ $value = $this->makeArrayFieldValue($value);
11
+ $this->setValue($value);
12
+ }
13
+
14
+ /**
15
+ * Prepare data before save
16
+ */
17
+ protected function _beforeSave()
18
+ {
19
+ $value = $this->getValue();
20
+ $value = $this->makeStorableArrayFieldValue($value);
21
+ $this->setValue($value);
22
+ }
23
+
24
+
25
+ protected function _encodeArrayFieldValue(array $value)
26
+ {
27
+ $result = array();
28
+ foreach ($value as $country => $fee) {
29
+ $_id = Mage::helper('core')->uniqHash('_');
30
+ $result[$_id] = array(
31
+ 'invoicefee_country' => $country,
32
+ 'invoicefee_fee' => $fee,
33
+ );
34
+ }
35
+ return $result;
36
+ }
37
+
38
+ protected function _unserializeValue($value)
39
+ {
40
+ if (is_string($value) && !empty($value)) {
41
+ return unserialize($value);
42
+ } else {
43
+ return array();
44
+ }
45
+ }
46
+
47
+ protected function _serializeValue($value)
48
+ {
49
+ if (is_numeric($value)) {
50
+ $data = (float)$value;
51
+ return (string)$data;
52
+ } else if (is_array($value)) {
53
+ $data = array();
54
+ foreach ($value as $country => $fee) {
55
+ if (!array_key_exists($country, $data)) {
56
+ $data[$country] = $fee;
57
+ }
58
+ }
59
+ return serialize($data);
60
+ } else {
61
+ return '';
62
+ }
63
+ }
64
+
65
+ protected function _isEncodedArrayFieldValue($value)
66
+ {
67
+ if (!is_array($value)) {
68
+ return false;
69
+ }
70
+ unset($value['__empty']);
71
+ foreach ($value as $_id => $row) {
72
+ if (!is_array($row) || !array_key_exists('invoicefee_country', $row) || !array_key_exists('invoicefee_fee', $row)) {
73
+ return false;
74
+ }
75
+ }
76
+ return true;
77
+ }
78
+
79
+ protected function _decodeArrayFieldValue(array $value)
80
+ {
81
+ $result = array();
82
+ unset($value['__empty']);
83
+ foreach ($value as $_id => $row) {
84
+ if (!is_array($row) || !array_key_exists('invoicefee_country', $row) || !array_key_exists('invoicefee_fee', $row)) {
85
+ continue;
86
+ }
87
+ $country = $row['invoicefee_country'];
88
+ $fee = $row['invoicefee_fee'];
89
+ $result[$country] = $fee;
90
+ }
91
+
92
+ return $result;
93
+ }
94
+
95
+ public function makeArrayFieldValue($value)
96
+ {
97
+ $value = $this->_unserializeValue($value);
98
+ if (!$this->_isEncodedArrayFieldValue($value)) {
99
+ $value = $this->_encodeArrayFieldValue($value);
100
+ }
101
+ return $value;
102
+ }
103
+
104
+ /**
105
+ * Make value ready for store
106
+ *
107
+ * @param mixed $value
108
+ * @return string
109
+ */
110
+ public function makeStorableArrayFieldValue($value)
111
+ {
112
+ if ($this->_isEncodedArrayFieldValue($value)) {
113
+ $value = $this->_decodeArrayFieldValue($value);
114
+ }
115
+ $value = $this->_serializeValue($value);
116
+ return $value;
117
+ }
118
+
119
+
120
+ }
121
+
app/code/community/Klarna/KlarnaPaymentModule/Model/Invoice/Tax.php ADDED
@@ -0,0 +1,65 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Klarna Module
4
+ *
5
+ * LICENSE AND USAGE INFORMATION
6
+ * It is NOT allowed to modify, copy or re-sell this file or any
7
+ * part of it. Please contact us by email at post@klarnaPaymentModule.no or
8
+ * visit us at www.klarnaPaymentModule.no if you have any questions about this.
9
+ * Klarna is not responsible for any problems caused by this file.
10
+ *
11
+ * Visit us at http://www.klarnaPaymentModule.no today!
12
+ *
13
+ * @category Klarna
14
+ * @package Klarna_KlarnaPaymentModule
15
+ * @copyright Copyright (c) 2010 Klarna (http://www.klarnaPaymentModule.no)
16
+ * @license Single-site License
17
+ *
18
+ */
19
+
20
+ class Klarna_KlarnaPaymentModule_Model_Invoice_Tax extends Mage_Sales_Model_Order_Invoice_Total_Abstract
21
+ {
22
+ public function collect(Mage_Sales_Model_Order_Invoice $invoice)
23
+ {
24
+ // $magentoversion = str_replace(".", "", Mage::getVersion());
25
+ //
26
+ // // As the versions differes in the hasInvoices method we need to do like
27
+ // // this.
28
+ // if($magentoversion <= 1401)
29
+ // $invoices += 1;
30
+
31
+ if($invoice->getOrder()->hasInvoices() != 0)
32
+ return $this;
33
+
34
+ $invoiceFeeTax = 0;
35
+ $baseInvoiceFeeTax = 0;
36
+
37
+ $info = $invoice->getOrder()->getPayment()->getMethodInstance()->getInfoInstance();
38
+
39
+ if (!$info) {
40
+ return $this;
41
+ }
42
+
43
+ $invoiceFeeTax = $info->getAdditionalInformation('invoice_tax_amount');
44
+ $baseInvoiceFeeTax = $info->getAdditionalInformation('base_invoice_tax_amount');
45
+
46
+ $invoice->setInvoiceFeeTaxAmount($invoiceFeeTax);
47
+ $invoice->setBaseInvoiceFeeTaxAmount($invoiceFeeTax);
48
+
49
+ $invoice->getOrder()->setInvoiceFeeTaxAmountInvoiced($invoiceFeeTax);
50
+ $invoice->getOrder()->setBaseInvoiceFeeTaxAmountInvoice($baseInvoiceFeeTax);
51
+
52
+ // // If we are making a part activation we need to add the tax again.
53
+ //
54
+ // if($invoice->getSubtotal() != $invoice->getOrder()->getSubtotal()) {
55
+ // $invoice->setTaxAmount($invoice->getTaxAmount() + $invoiceFeeTax + 10000);
56
+ // $invoice->setBaseTaxAmount($invoice->getBaseTaxAmount() + $baseInvoiceFeeTax);
57
+ //
58
+ //
59
+ // $invoice->setGrandTotal($invoice->getGrandTotal() + $invoiceFeeTax);
60
+ // $invoice->setBaseGrandTotal($invoice->getBaseGrandTotal() + $baseInvoiceFeeTax);
61
+ // }
62
+
63
+ return $this;
64
+ }
65
+ }
app/code/community/Klarna/KlarnaPaymentModule/Model/Invoice/Total.php ADDED
@@ -0,0 +1,79 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Klarna Module
4
+ *
5
+ * LICENSE AND USAGE INFORMATION
6
+ * It is NOT allowed to modify, copy or re-sell this file or any
7
+ * part of it. Please contact us by email at post@klarnaPaymentModule.no or
8
+ * visit us at www.klarnaPaymentModule.no if you have any questions about this.
9
+ * Klarna is not responsible for any problems caused by this file.
10
+ *
11
+ * Visit us at http://www.klarnaPaymentModule.no today!
12
+ *
13
+ * @category Klarna
14
+ * @package Klarna_KlarnaPaymentModule
15
+ * @copyright Copyright (c) 2010 Klarna (http://www.klarnaPaymentModule.no)
16
+ * @license Single-site License
17
+ *
18
+ */
19
+
20
+ class Klarna_KlarnaPaymentModule_Model_Invoice_Total extends Mage_Sales_Model_Order_Invoice_Total_Abstract
21
+ {
22
+ public function collect(Mage_Sales_Model_Order_Invoice $invoice)
23
+ {
24
+ $order = $invoice->getOrder();
25
+
26
+ if ($order->getPayment()->getMethodInstance()->getCode() != 'klarna_invoice') {
27
+ return $this;
28
+ }
29
+
30
+ // Only collect the invoice fee if we do not have any recent invoices
31
+ if($invoice->getOrder()->hasInvoices())
32
+ return $this;
33
+
34
+ $info = $invoice->getOrder()->getPayment()->getMethodInstance()->getInfoInstance();
35
+
36
+ if (!$info) {
37
+ return $this;
38
+ }
39
+
40
+ $invoiceFee = $info->getAdditionalInformation('invoice_fee');
41
+ $invoiceFeeTaxAmount = $info->getAdditionalInformation('invoice_tax_amount');
42
+ $baseInvoiceFee = $info->getAdditionalInformation('base_invoice_fee');
43
+ $baseInvoiceFeeTaxAmount = $info->getAdditionalInformation('base_invoice_tax_amount');
44
+
45
+ if (!$invoiceFee){
46
+ return $this;
47
+ }
48
+
49
+
50
+ $baseInvoiceTotal = $invoice->getBaseGrandTotal();
51
+ $invoiceTotal = $invoice->getGrandTotal();
52
+
53
+
54
+ $baseInvoiceTotal = $baseInvoiceTotal + $baseInvoiceFee;
55
+ $invoiceTotal = $invoiceTotal + $invoiceFee;
56
+
57
+ // $baseInvoiceTotal += $baseInvoiceFeeTaxAmount;
58
+ // $invoiceTotal += $invoiceFeeTaxAmount;
59
+
60
+ if(!$invoice->isLast()) {
61
+ $invoice->setBaseTaxAmount($invoice->getBaseTaxAmount() + $baseInvoiceFeeTaxAmount);
62
+ $invoice->setTaxAmount($invoice->getTaxAmount() + $invoiceFeeTaxAmount);
63
+
64
+ $invoice->setBaseGrandTotal($baseInvoiceTotal + $baseInvoiceFeeTaxAmount);
65
+ $invoice->setGrandTotal($invoiceTotal + $invoiceFeeTaxAmount);
66
+ } else {
67
+ $invoice->setBaseGrandTotal($baseInvoiceTotal);
68
+ $invoice->setGrandTotal($invoiceTotal);
69
+ }
70
+
71
+ $invoice->setBaseInvoiceFee($baseInvoiceFee);
72
+ $invoice->setInvoiceFee($invoiceFee);
73
+
74
+ $order->setBaseInvoiceFeeInvoiced($baseInvoiceFee);
75
+ $order->setInvoiceFeeInvoiced($invoiceFee);
76
+
77
+ return $this;
78
+ }
79
+ }
app/code/community/Klarna/KlarnaPaymentModule/Model/Klarna/Invoice.php ADDED
@@ -0,0 +1,105 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Klarna Module
4
+ *
5
+ * LICENSE AND USAGE INFORMATION
6
+ * It is NOT allowed to modify, copy or re-sell this file or any
7
+ * part of it. Please contact us by email at post@klarnaPaymentModule.no or
8
+ * visit us at www.klarnaPaymentModule.no if you have any questions about this.
9
+ * Klarna is not responsible for any problems caused by this file.
10
+ *
11
+ * Visit us at http://www.klarnaPaymentModule.no today!
12
+ *
13
+ * @category Klarna
14
+ * @package Klarna_KlarnaPaymentModule
15
+ * @copyright Copyright (c) 2010 Klarna (http://www.klarnaPaymentModule.no)
16
+ * @license Single-site License
17
+ *
18
+ */
19
+
20
+
21
+ /**
22
+ * Our test CC module adapter
23
+ */
24
+ class Klarna_KlarnaPaymentModule_Model_Klarna_Invoice extends Klarna_KlarnaPaymentModule_Model_Klarna_Shared
25
+ {
26
+ protected $_code = 'klarna_invoice';
27
+ protected $_formBlockType = 'klarnaPaymentModule/klarna_invoice_invoiceForm';
28
+ protected $_infoBlockType = 'klarnaPaymentModule/klarna_invoice_invoicePaymentInfo';
29
+ protected $_allowCurrencyCode = array('NOK', 'SEK', 'DKK', 'EUR');
30
+
31
+
32
+ //* Options *//
33
+ protected $_isGateway = false;
34
+ protected $_canAuthorize = true;
35
+ protected $_canCapture = true;
36
+ //protected $_canCapturePartial = false; // function is handeling this.
37
+ protected $_canRefund = true;
38
+ protected $_canRefundInvoicePartial = false;
39
+ protected $_canVoid = false;
40
+ protected $_canUseInternal = true;
41
+ protected $_canUseCheckout = true;
42
+ protected $_canUseForMultishipping = false;
43
+ protected $_canSaveCc = false;
44
+
45
+
46
+ /**
47
+ * Check partial capture availability
48
+ *
49
+ * @return bool
50
+ */
51
+ public function canCapturePartial()
52
+ {
53
+ return ($this->getIntegrationMode() == 'advanced');
54
+ }
55
+
56
+ /**
57
+ * Get Invoice fee
58
+ *
59
+ * @return int
60
+ */
61
+ public function getAddressInvoiceFee(Mage_Customer_Model_Address_Abstract $address)
62
+ {
63
+ $value = Mage::helper('klarnaPaymentModule')->getInvoiceFee(Mage::app()->getStore()->getId(), true);
64
+
65
+ // Return price without tax
66
+ $value = Mage::helper('klarnaPaymentModule')->getInvoiceFeePrice($value, false, $address, $address->getQuote()->getCustomerTaxClassId());
67
+
68
+ return $value;
69
+ }
70
+
71
+ /**
72
+ * Returns the predefined title for this payment option
73
+ *
74
+ * @return <string> The title for the payment option
75
+ */
76
+ public function getTitle()
77
+ {
78
+ $value = Mage::helper('klarnaPaymentModule')->getInvoiceFee(Mage::app()->getStore()->getId(), false);
79
+ $country = $this->getQuote()->getShippingAddress()->getCountry();
80
+ $api = Mage::helper('klarnaPaymentModule/api');
81
+ $settings = $api->getCountrySettings($country);
82
+ return $settings['title'] . ' (+' . Mage::helper('core')->formatPrice($value) . ')';
83
+ }
84
+
85
+
86
+ /**
87
+ * Using internal pages for input payment data
88
+ *
89
+ * @return bool
90
+ */
91
+ public function canUseInternal()
92
+ {
93
+ return $this->_canUseInternal;
94
+ }
95
+
96
+ /**
97
+ * Using for multiple shipping address
98
+ *
99
+ * @return bool
100
+ */
101
+ public function canUseForMultishipping()
102
+ {
103
+ return $this->_canUseForMultishipping;
104
+ }
105
+ }
app/code/community/Klarna/KlarnaPaymentModule/Model/Klarna/PartPayment.php ADDED
@@ -0,0 +1,94 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Our test CC module adapter
4
+ */
5
+ class Klarna_KlarnaPaymentModule_Model_Klarna_PartPayment extends Klarna_KlarnaPaymentModule_Model_Klarna_Shared
6
+ {
7
+ protected $_code = 'klarna_partpayment';
8
+ protected $_formBlockType = 'klarnaPaymentModule/klarna_partPayment_partPaymentForm';
9
+ protected $_infoBlockType = 'klarnaPaymentModule/klarna_partPayment_partPaymentInfo';
10
+ protected $_allowCurrencyCode = array('NOK', 'SEK', 'DKK', 'EUR');
11
+
12
+
13
+ //* Options *//
14
+ protected $_isGateway = false;
15
+ protected $_canAuthorize = true;
16
+ protected $_canCapture = true;
17
+ //protected $_canCapturePartial = false; // function is handeling this.
18
+ protected $_canRefund = true;
19
+ protected $_canRefundInvoicePartial = false;
20
+ protected $_canVoid = false;
21
+ protected $_canUseInternal = true;
22
+ protected $_canUseCheckout = true;
23
+ protected $_canUseForMultishipping = false;
24
+ protected $_canSaveCc = false;
25
+
26
+ /**
27
+ * Check partial capture availability
28
+ *
29
+ * @return bool
30
+ */
31
+ public function canCapturePartial()
32
+ {
33
+ return ($this->getIntegrationMode() == 'advanced');
34
+ }
35
+
36
+ public function getTitle()
37
+ {
38
+ $country = $this->getQuote()->getShippingAddress()->getCountry();
39
+ $api = Mage::helper('klarnaPaymentModule/api');
40
+ $settings = $api->getCountrySettings($country);
41
+ return $settings['title_pp'];
42
+ }
43
+
44
+
45
+
46
+
47
+ /**
48
+ * Using internal pages for input payment data
49
+ *
50
+ * @return bool
51
+ */
52
+ public function canUseInternal()
53
+ {
54
+ return $this->_canUseInternal;
55
+ }
56
+
57
+ /**
58
+ * Using for multiple shipping address
59
+ *
60
+ * @return bool
61
+ */
62
+ public function canUseForMultishipping()
63
+ {
64
+ return $this->_canUseForMultishipping;
65
+ }
66
+
67
+ /**
68
+ * Checks to see if there is any part payment option. If there is, we display the
69
+ * option to the customer
70
+ *
71
+ * @param <Mage_Sales_Model_Quote> $quote
72
+ * @return <bool> True if the payment option should be visible, otherwise false
73
+ */
74
+ public function isAvailable($quote = null) {
75
+
76
+ $available = parent::isAvailable($quote);
77
+ if($available) {
78
+ $helper = Mage::helper('klarnaPaymentModule');
79
+ $pclass = Mage::helper("klarnaPaymentModule/pclass");
80
+
81
+ if(!$quote->getShippingAddress()->getCountry())
82
+ return false;
83
+
84
+ $store = Mage::app()->getStore()->getId();
85
+
86
+ $pclasscollection = $pclass->getSortedPclassesForStoreAndCountry($quote->getGrandTotal()*100, strtoupper($helper->getCustomerCountry()), $store);
87
+
88
+ return (sizeof($pclasscollection) > 0);
89
+
90
+ } else
91
+ return false;
92
+ }
93
+
94
+ }
app/code/community/Klarna/KlarnaPaymentModule/Model/Klarna/Shared.php ADDED
@@ -0,0 +1,365 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Klarna_KlarnaPaymentModule_Model_Klarna_Shared extends Mage_Payment_Model_Method_Abstract
3
+ {
4
+ /**
5
+ * Get checkout session namespace
6
+ *
7
+ * @return Mage_Checkout_Model_Session
8
+ */
9
+ public function getCheckout()
10
+ {
11
+ return Mage::getSingleton('checkout/session');
12
+ }
13
+
14
+
15
+ /**
16
+ * To check shipping country is allowed for the payment method
17
+ *
18
+ * @return bool
19
+ */
20
+ public function canUseForCountry($country)
21
+ {
22
+
23
+ $country = $this->getShippingCountry();
24
+ $allowed = parent::canUseForCountry($country);
25
+ if ($allowed)
26
+ {
27
+ if (Mage::helper('klarnaPaymentModule')->isCountryAllowed($country)) {
28
+ // Check if the store has the same currency as the billing address.
29
+ $api = Mage::helper('klarnaPaymentModule/api');
30
+ $country_settings = $api->getCountrySettings($country);
31
+ $currency_code = Mage::app()->getStore()->getCurrentCurrencyCode();
32
+ $allowed = ($country_settings['currency_code'] == $currency_code);
33
+ }
34
+ else {
35
+ $allowed = false;
36
+ }
37
+ }
38
+
39
+ return $allowed;
40
+ }
41
+
42
+
43
+
44
+ /**
45
+ * Assign data to info model instance
46
+ *
47
+ * @param mixed $data
48
+ * @return Mage_Payment_Model_Info
49
+ */
50
+ public function assignData($data)
51
+ {
52
+ if (!($data instanceof Varien_Object)) {
53
+ $data = new Varien_Object($data);
54
+ }
55
+
56
+ $this->assignDataForCountry($data, $data->getMethod());
57
+
58
+ return $this;
59
+ }
60
+
61
+ function generatePersonalNumber($year, $month, $day, $gender)
62
+ {
63
+ $date = new DateTime();
64
+ $date->setDate($year, $month, $day);
65
+
66
+ if($gender == 'male') {
67
+ $gender = '1';
68
+ }
69
+ else {
70
+ $gender = '0';
71
+ }
72
+
73
+ return $date->format('dmY') . $gender;
74
+ }
75
+
76
+ function assignDataForCountry($data, $prefix)
77
+ {
78
+ $helper = Mage::helper('klarnaPaymentModule');
79
+ $api = Mage::helper('klarnaPaymentModule/api');
80
+ $pclasshelper = Mage::helper('klarnaPaymentModule/pclass');
81
+ $fields = $helper->getCountrySpecificFields();
82
+ $info = $this->getInfoInstance();
83
+ $integrationmode = $helper->getIntegrationMode(Mage::app()->getStore()->getId(), $data->getMethod());
84
+ $shippingaddress = $this->getQuote()->getShippingAddress();
85
+ $billingaddress = $this->getQuote()->getBillingAddress();
86
+ $separators = array('/','.',"_",',',':',';', ' ', '-', '\\');
87
+
88
+ if($shippingaddress->getCountry() == "SE") {
89
+ $shipping = explode("|", $data[$data->getMethod() . "_shippingaddress"]);
90
+ $billing = explode("|", $data[$data->getMethod() . "_billingaddress"]);
91
+
92
+ // If company
93
+ if($shipping[0] == '') {
94
+ $shippingaddress->setCompany(trim($shipping[1]));
95
+ } else {
96
+ $shippingaddress->setCompany('')->
97
+ setFirstname(trim($shipping[0]))->
98
+ setLastname(trim($shipping[1]));
99
+ }
100
+
101
+ if($integrationmode == "advanced") {
102
+
103
+ // If company
104
+ if($shipping[0] == '') {
105
+ $shippingaddress->setCompany(trim($shipping[1]));
106
+ } else {
107
+ $shippingaddress->setFirstname(trim($shipping[0]))->
108
+ setLastname(trim($shipping[1]));
109
+ }
110
+
111
+ $shippingaddress->setStreet(trim($shipping[2]))->
112
+ setPostcode(trim($shipping[3]))->
113
+ setCity(trim($shipping[4]))->save();
114
+
115
+ // If company
116
+ if($billing[0] == '') {
117
+ $billingaddress->setCompany(trim($billing[1]));
118
+ } else {
119
+ $billingaddress->setCompany('')->
120
+ setFirstname(trim($billing[0]))->
121
+ setLastname(trim($billing[1]));
122
+ }
123
+ $billingaddress->
124
+ setStreet(trim($billing[2]))->
125
+ setPostcode(trim($billing[3]))->
126
+ setCity(trim($billing[4]))->save();
127
+
128
+ } else {
129
+
130
+ $shippingaddress->setStreet(trim($shipping[2]))->
131
+ setPostcode(trim($shipping[3]))->
132
+ setCity(trim($shipping[4]))->save();
133
+
134
+ $billingaddress->setCompany($shippingaddress->getCompany())->setFirstname($shippingaddress->getFirstname())->
135
+ setLastname($shippingaddress->getLastname())->
136
+ setStreet($shippingaddress->getStreet())->
137
+ setPostcode($shippingaddress->getPostcode())->
138
+ setCity($shippingaddress->getCity())->save();
139
+ }
140
+ } else {
141
+ // If we arent using advanced integration we
142
+ // need to set the billing / shipping address to the same
143
+ if($integrationmode != 'advanced') {
144
+ $billingaddress->setCompany($shippingaddress->getCompany())->setFirstname($shippingaddress->getFirstname())->
145
+ setLastname($shippingaddress->getLastname())->
146
+ setStreet($shippingaddress->getStreet())->
147
+ setPostcode($shippingaddress->getPostcode())->
148
+ setCity($shippingaddress->getCity())->setCountryId($shippingaddress->getCountryId())->save();
149
+ }
150
+ }
151
+
152
+ if($data->getMethod() == "klarna_partpayment") {
153
+ $info->setAdditionalInformation("klarna_pclass", $data->getKlarnaPartpaymentPclass());
154
+ $pclass = $pclasshelper->getPclass($data->getKlarnaPartpaymentPclass());
155
+
156
+ $calc = Mage::helper('klarnaPaymentModule/calc_klarna');
157
+ $monthlycost = $calc->calc_monthly_cost($this->getQuote()->getGrandTotal()*100, $pclass[0], 0, $pclass[0]['country']);
158
+
159
+ if($monthlycost > 0)
160
+ $info->setAdditionalInformation("klarna_monthlycost", Mage::helper('core')->formatPrice(round($monthlycost/100)));
161
+ else {
162
+ $info->setAdditionalInformation("klarna_monthlycost", $pclass[0]['description']);
163
+ }
164
+
165
+ $info->setAdditionalInformation("klarna_pclasstype", $pclass[0]['type']);
166
+
167
+ } else
168
+ $info->setAdditionalInformation("klarna_pclass", -1);
169
+
170
+ foreach($fields as $field) {
171
+ if($field == 'dob') {
172
+ foreach(array('year', 'day', 'month') as $item) {
173
+ $key = 'klarna_dob_' . $item;
174
+ $info->setAdditionalInformation($key, $data->getData($prefix . "_dob_" . $item));
175
+ }
176
+ }
177
+ else {
178
+ $value = trim($data->getData($prefix . '_' . $field));
179
+ // Sanitize input
180
+ if($field == 'personalnumber' || $field == 'yearlysalary')
181
+ $value = str_replace($separators,'',$value);
182
+
183
+ $info->setAdditionalInformation('klarna_' . $field, $value);
184
+ }
185
+ }
186
+
187
+ $country = $helper->getCountry();
188
+ if(in_array($country, array('NL', 'DE'))) {
189
+ $personalnumber = $this->generatePersonalNumber(
190
+ $data->getData($prefix . '_dob_year'),
191
+ $data->getData($prefix . '_dob_month'),
192
+ $data->getData($prefix . '_dob_day'),
193
+ $data->getData($prefix . '_gender')
194
+ );
195
+
196
+ $info->setAdditionalInformation('klarna_personalnumber', $personalnumber);
197
+
198
+ // Update street address on billing and shippping.
199
+ $street = trim($data->getData($prefix . '_street')).' '.trim($data->getData($prefix . '_house_number'));
200
+ if ($country == "NL" and trim($data->getData($prefix . '_house_extension'))) {
201
+ $street .= ' '. trim($data->getData($prefix . '_house_extension'));
202
+ }
203
+
204
+ $shippingaddress->setStreet($street)->save();
205
+
206
+ }
207
+
208
+ $phone = str_replace($separators,"",$data->getData($prefix . '_phonenumber'));
209
+
210
+ $shippingaddress->setTelephone($phone)->save();
211
+ $billingaddress->setTelephone($phone)->save();
212
+
213
+
214
+ }
215
+
216
+
217
+ public function isAvailable($quote=null)
218
+ {
219
+ $active = $this->getConfigData('active');
220
+ if(!$active) {
221
+ return false;
222
+ }
223
+
224
+ if(is_null($quote)) {
225
+ return false;
226
+ }
227
+
228
+ $totals = $quote->getTotals();
229
+ if(!isset($totals['grand_total'])) {
230
+ return false;
231
+ }
232
+
233
+ $maximum_order_limit_nl = (int)Mage::getStoreConfig('advanced/klarna/maximum_order_amount_nl');
234
+ $maximum_order_limit_de = (int)Mage::getStoreConfig('advanced/klarna/maximum_order_amount_de');
235
+
236
+ if($maximum_order_limit_nl != -1 && $totals['grand_total']->getValue() > $maximum_order_limit_nl && Mage::helper("klarnaPaymentModule")->getCountry() == 'NL')
237
+ return false;
238
+
239
+ if($maximum_order_limit_de != -1 && $totals['grand_total']->getValue() > $maximum_order_limit_de && Mage::helper("klarnaPaymentModule")->getCountry() == 'DE')
240
+ return false;
241
+
242
+ // do not allow this payment to be available if total is below customer configurable value.
243
+ $allowedMin = (int)$this->getConfigData('minimum_order_cost');
244
+
245
+ if(Mage::app()->getStore()->roundPrice($totals['grand_total']->getValue()) < $allowedMin) {
246
+ return false;
247
+ }
248
+
249
+ return true;
250
+ }
251
+
252
+
253
+
254
+ public function getIntegrationMode()
255
+ {
256
+ $addinfo = $this->getInfoInstance()->getAdditionalInformation();
257
+ return $addinfo['klarna_integrationmode'];
258
+ }
259
+
260
+ public function authorize(Varien_Object $payment, $amount)
261
+ {
262
+ $data = $this->getInfoInstance();
263
+ $personal_number = $data->getAdditionalInformation('klarna_personalnumber');
264
+ $order = $payment->getOrder();
265
+ $integration_mode = $this->getConfigData("integration_mode", $this->getStore());
266
+ $api = Mage::helper('klarnaPaymentModule/api');
267
+ $api->loadConfig($order->getStoreId(), $payment->getMethod());
268
+
269
+ $api->setCountrySpecificFields($data);
270
+ $api->setOrder($order);
271
+
272
+ $api->setIntegrationMode($integration_mode);
273
+
274
+ $data->setAdditionalInformation('klarna_integrationmode', $integration_mode);
275
+
276
+ if ($this->getIntegrationMode() == 'standard') {
277
+ $result = $api->add_invoice();
278
+ // Remove the personalnumber
279
+ $data->setAdditionalInformation('klarna_personalnumber', '');
280
+ $this->getQuote()->getPayment()->setAdditionalInformation('klarna_personalnumber', '')->save();
281
+ }
282
+ elseif ($this->getIntegrationMode() == 'advanced') {
283
+ $result = $api->reserve_amount();
284
+ }
285
+
286
+ if($result['status'] == 'error') {
287
+ Mage::throwException($result['error']);
288
+ }
289
+ else {
290
+ if($this->getIntegrationMode() == 'standard') {
291
+ $data->setAdditionalInformation('klarna_invoice_id', $result['invoice_id']);
292
+ }
293
+ else {
294
+ $data->setAdditionalInformation('klarna_reservation_id', $result['reservation_id']);
295
+ }
296
+ }
297
+ }
298
+
299
+ public function validate()
300
+ {
301
+ $data = $this->getInfoInstance();
302
+ parent::validate();
303
+
304
+ /* Also we need to validate postnumber! */
305
+
306
+ /* Here we need to validate entered personalnumber */
307
+ $pno = $data->getAdditionalInformation('klarna_personalnumber');
308
+ $helper = Mage::helper('klarnaPaymentModule');
309
+ $country = $this->getQuote()->getShippingAddress()->getCountry();
310
+
311
+ /*
312
+ if(!$helper->validatePersonalNumber($pno, $country)) {
313
+ Mage::throwException('Please enter a valid personalnumber.');
314
+ }
315
+ */
316
+
317
+ return $this;
318
+ }
319
+
320
+ /**
321
+ * Get current quote
322
+ *
323
+ * @return Mage_Sales_Model_Quote
324
+ */
325
+ public function getQuote()
326
+ {
327
+ return $this->getCheckout()->getQuote();
328
+ }
329
+
330
+
331
+ public function getShippingCountry() {
332
+ return $this->getQuote()
333
+ ->getShippingAddress()
334
+ ->getCountryId();
335
+ }
336
+
337
+
338
+ public function capture(Varien_Object $payment, $amount) {
339
+ $info = $this->getInfoInstance();
340
+ $mode = $info->getAdditionalInformation('klarna_integrationmode');
341
+
342
+ if($mode == 'standard') {
343
+ $order = $payment->getOrder();
344
+ $api = Mage::helper('klarnaPaymentModule/api');
345
+ $api->loadConfig($order->getStoreId(), $payment->getMethod());
346
+ $api->setOrder($order);
347
+ $invoice_id = $info->getAdditionalInformation('klarna_invoice_id');
348
+ $result = $api->activate_invoice($invoice_id);
349
+
350
+ if($result['status'] == 'error') {
351
+ Mage::throwException('Unable to activate invoice, error: ' . $result['error']);
352
+ } else
353
+ Mage::getSingleton('adminhtml/session')->addSuccess('Invoice successfully activated. Click <a href="' . $result['invoice_id'] . '" target="_blank">here</a> to view it.');
354
+ }
355
+
356
+ return $this;
357
+ }
358
+
359
+
360
+
361
+
362
+ }
363
+
364
+
365
+ ?>
app/code/community/Klarna/KlarnaPaymentModule/Model/Observer.php ADDED
@@ -0,0 +1,156 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * @category Phoenix
16
+ * @package Phoenix_CashOnDelivery
17
+ * @copyright Copyright (c) 2010 Phoenix Medien GmbH & Co. KG (http://www.phoenix-medien.de)
18
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
19
+ */
20
+
21
+ class Klarna_KlarnaPaymentModule_Model_Observer extends Mage_Core_Model_Abstract {
22
+
23
+ /**
24
+ * Collects codFee from qoute/addresses to quote
25
+ *
26
+ * @param Varien_Event_Observer $observer
27
+ *
28
+ */
29
+
30
+ public function sales_quote_collect_totals_after(Varien_Event_Observer $observer) {
31
+ $quote = $observer->getEvent()->getQuote();
32
+ $data = $observer->getInput();
33
+ $quote->setInvoiceFee(0);
34
+ $quote->setBaseInvoiceFee(0);
35
+ $quote->setInvoiceTaxAmount(0);
36
+ $quote->setBaseInvoiceTaxAmount(0);
37
+
38
+ foreach ($quote->getAllAddresses() as $address) {
39
+ $quote->setInvoiceFee((float) $quote->getInvoiceFee()+$address->getInvoiceFee());
40
+ $quote->setBaseInvoiceFee((float) $quote->getBaseInvoiceFee()+$address->getBaseInvoiceFee());
41
+
42
+ $quote->setInvoiceTaxAmount((float) $quote->getInvoiceTaxAmount()+$address->getInvoiceTaxAmount());
43
+ $quote->setBaseInvoiceTaxAmount((float) $quote->getBaseInvoiceTaxAmount()+$address->getBaseInvoiceTaxAmount());
44
+ }
45
+ }
46
+
47
+ /**
48
+ * Adds codFee to order
49
+ * @param Varien_Event_Observer $observer
50
+ */
51
+
52
+ public function sales_order_payment_place_end(Varien_Event_Observer $observer) {
53
+ $payment = $observer->getPayment();
54
+ if ($payment->getMethodInstance()->getCode() != 'klarna_invoice'){
55
+ return;
56
+ }
57
+
58
+ $info = $payment->getMethodInstance()->getInfoInstance();
59
+ $quote = Mage::getSingleton('checkout/session')->getQuote();
60
+ if (! $quote->getId()) {
61
+ $quote = Mage::getSingleton('adminhtml/session_quote')->getQuote();
62
+ }
63
+
64
+ $info->setAdditionalInformation('invoice_fee', $quote->getInvoiceFee());
65
+ $info->setAdditionalInformation('base_invoice_fee', $quote->getBaseInvoiceFee());
66
+
67
+ $info->setAdditionalInformation('invoice_tax_amount', $quote->getInvoiceTaxAmount());
68
+ $info->setAdditionalInformation('base_invoice_tax_amount', $quote->getBaseInvoiceTaxAmount());
69
+
70
+ $info->save();
71
+ }
72
+
73
+ public function sales_order_invoice_pay($observer) {
74
+
75
+ $magentoversion = str_replace(".", "", Mage::getVersion());
76
+ // Get the invoice
77
+ $invoice = $observer->getEvent()->getInvoice();
78
+ $order = $invoice->getOrder();
79
+ $payment = $order->getPayment();
80
+ $addinfo = $payment->getAdditionalInformation();
81
+ $invoices = $invoice->getOrder()->hasInvoices();
82
+ $method = $payment->getMethod();
83
+
84
+
85
+ // As the versions differes in the hasInvoices method we need to do like
86
+ // this.
87
+ if($magentoversion <= 1401)
88
+ $invoices += 1;
89
+
90
+ if(($method != "klarna_invoice" && $method != "klarna_partpayment"))
91
+ return $this;
92
+
93
+ // Only proceed if we are handling a Klarna order and its made throug advanced
94
+ // integration. Enable this later
95
+ if(($payment->getMethod() == "klarna_invoice" || $payment->getMethod() == "klarna_partpayment") && $addinfo['klarna_integrationmode'] != "advanced")
96
+ return $this;
97
+
98
+ // The array that will hold the items that we are going to use
99
+ $items = array();
100
+
101
+ // Get the item ids that we are going to use in our call to Klarna
102
+ $itemkeys = array();
103
+ if(isset($_REQUEST['invoice']['items']))
104
+ $itemkeys = array_keys($_REQUEST['invoice']['items']);
105
+
106
+
107
+ // Loop through the item collection and check if its the object that we
108
+ // should send to Klarna
109
+ foreach($invoice->getAllItems() as $item) {
110
+ if(in_array($item->getOrderItemId(), $itemkeys))
111
+ $items[] = $item;
112
+ }
113
+
114
+ $api = Mage::helper("klarnaPaymentModule/api");
115
+ $api->loadConfig($order->getStoreId(), $payment->getMethod());
116
+ $api->setIntegrationMode('advanced');
117
+ $api->setOrder($invoice->getOrder());
118
+ $api->setCountrySpecificFields($payment->getMethodInstance()->getInfoInstance());
119
+ // Do the actual activation of the reservation
120
+ $result = $api->activate_reservation($addinfo['klarna_reservation_id'], $items, $invoices == 1);
121
+
122
+ if($result['status'] == "error")
123
+ Mage::throwException($result["error"]);
124
+
125
+
126
+ Mage::getSingleton('adminhtml/session')->addSuccess('Invoice with invoice number ' . $result['id'] . ' created at Klarna');
127
+
128
+ //$payment->setAdditionalInformation('klarna_invoiceno', $result['id']);
129
+
130
+
131
+ }
132
+
133
+ /**
134
+ * Method to handle the download the
135
+ *
136
+ * @param <type> $observer
137
+ */
138
+ public function admin_system_config_changed_section_payment($observer) {
139
+
140
+ $method = $_REQUEST['config_state'];
141
+
142
+ // If it is the part payment method we update we also update the pclasses
143
+ if(isset($method['payment_klarna_partpayment']) && $method['payment_klarna_partpayment'] == 1) {
144
+ $helpa = Mage::helper("klarnaPaymentModule/pclass"); //
145
+ $helpa->updatePclasses();
146
+ }
147
+
148
+
149
+
150
+
151
+
152
+ }
153
+
154
+ }
155
+
156
+ ?>
app/code/community/Klarna/KlarnaPaymentModule/Model/Quote/TaxTotal.php ADDED
@@ -0,0 +1,117 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Klarna Module
4
+ *
5
+ * LICENSE AND USAGE INFORMATION
6
+ * It is NOT allowed to modify, copy or re-sell this file or any
7
+ * part of it. Please contact us by email at post@klarnaPaymentModule.no or
8
+ * visit us at www.klarnaPaymentModule.no if you have any questions about this.
9
+ * Klarna is not responsible for any problems caused by this file.
10
+ *
11
+ * Visit us at http://www.klarnaPaymentModule.no today!
12
+ *
13
+ * @category Klarna
14
+ * @package Klarna_KlarnaPaymentModule
15
+ * @copyright Copyright (c) 2010 Klarna (http://www.klarnaPaymentModule.no)
16
+ * @license Single-site License
17
+ *
18
+ */
19
+
20
+ class Klarna_KlarnaPaymentModule_Model_Quote_TaxTotal extends Mage_Sales_Model_Quote_Address_Total_Tax {
21
+
22
+ public function collect(Mage_Sales_Model_Quote_Address $address)
23
+ {
24
+
25
+ if ($address->getQuote()->getId() == NULL) {
26
+ return $this;
27
+ }
28
+
29
+ if ($address->getAddressType() != "shipping") {
30
+ return $this;
31
+ }
32
+
33
+ /*
34
+ $paymentMethod = Mage::app()->getFrontController()->getRequest()->getParam('payment');
35
+ $paymentMethod = Mage::app()->getStore()->isAdmin() && isset($paymentMethod['method']) ? $paymentMethod['method'] : null;
36
+ */
37
+ $paymentMethod = $address->getQuote()->getPayment()->getMethod();
38
+ if ($paymentMethod != 'klarna_invoice' && (!count($address->getQuote()->getPaymentsCollection()) || !$address->getQuote()->getPayment()->hasMethodInstance())){
39
+ return $this;
40
+ }
41
+
42
+ $paymentMethod = $address->getQuote()->getPayment()->getMethodInstance();
43
+
44
+ if ($paymentMethod->getCode() != 'klarna_invoice') {
45
+ return $this;
46
+ }
47
+
48
+ $store = $address->getQuote()->getStore();
49
+
50
+ $items = $address->getAllItems();
51
+ if (!count($items)) {
52
+ return $this;
53
+ }
54
+
55
+ $custTaxClassId = $address->getQuote()->getCustomerTaxClassId();
56
+
57
+ $taxCalculationModel = Mage::getSingleton('tax/calculation');
58
+ /* @var $taxCalculationModel Mage_Tax_Model_Calculation */
59
+ $request = $taxCalculationModel->getRateRequest($address, $address->getQuote()->getBillingAddress(), $custTaxClassId, $store);
60
+ $invoiceTaxClass = Mage::helper('klarnaPaymentModule')->getTaxClass($store);
61
+
62
+ $invoiceTax = 0;
63
+ $invoiceBaseTax = 0;
64
+
65
+ if ($invoiceTaxClass) {
66
+ if ($rate = $taxCalculationModel->getRate($request->setProductClassId($invoiceTaxClass))) {
67
+
68
+ $invoiceTax = $taxCalculationModel->calcTaxAmount($address->getInvoiceFee(), $rate, false, true);
69
+ $invoiceBaseTax= $taxCalculationModel->calcTaxAmount($address->getBaseInvoiceFee(), $rate, false, true);
70
+
71
+ $address->setTaxAmount($address->getTaxAmount() + $invoiceTax);
72
+ $address->setBaseTaxAmount($address->getBaseTaxAmount() + $invoiceBaseTax);
73
+
74
+ $this->_saveAppliedTaxes(
75
+ $address,
76
+ $taxCalculationModel->getAppliedRates($request),
77
+ $invoiceTax,
78
+ $invoiceBaseTax,
79
+ $rate
80
+ );
81
+ }
82
+ }
83
+
84
+ $address->setInvoiceTaxAmount($invoiceTax);
85
+ $address->setBaseInvoiceTaxAmount($invoiceBaseTax);
86
+
87
+ $address->setGrandTotal($address->getGrandTotal());
88
+ $address->setBaseGrandTotal($address->getBaseGrandTotal());
89
+
90
+ return $this;
91
+ }
92
+
93
+ public function fetch(Mage_Sales_Model_Quote_Address $address)
94
+ {
95
+ $store = $address->getQuote()->getStore();
96
+ /**
97
+ * Modify subtotal
98
+ */
99
+ if (Mage::getSingleton('tax/config')->displayCartSubtotalBoth($store) || Mage::getSingleton('tax/config')->displayCartSubtotalInclTax($store)) {
100
+ if ($address->getSubtotalInclTax() > 0) {
101
+ $subtotalInclTax = $address->getSubtotalInclTax();
102
+ } else {
103
+ $subtotalInclTax = $address->getSubtotal()+$address->getTaxAmount()-$address->getShippingTaxAmount()-$address->getInvoiceTaxAmount();
104
+ }
105
+
106
+ $address->addTotal(array(
107
+ 'code' => 'subtotal',
108
+ 'title' => Mage::helper('sales')->__('Subtotal'),
109
+ 'value' => $subtotalInclTax,
110
+ 'value_incl_tax' => $subtotalInclTax,
111
+ 'value_excl_tax' => $address->getSubtotal(),
112
+ ));
113
+ }
114
+ return $this;
115
+ }
116
+
117
+ }
app/code/community/Klarna/KlarnaPaymentModule/Model/Quote/Total.php ADDED
@@ -0,0 +1,107 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Klarna Module
4
+ *
5
+ * LICENSE AND USAGE INFORMATION
6
+ * It is NOT allowed to modify, copy or re-sell this file or any
7
+ * part of it. Please contact us by email at post@klarnaPaymentModule.no or
8
+ * visit us at www.klarnaPaymentModule.no if you have any questions about this.
9
+ * Klarna is not responsible for any problems caused by this file.
10
+ *
11
+ * Visit us at http://www.klarnaPaymentModule.no today!
12
+ *
13
+ * @category Klarna
14
+ * @package Klarna_KlarnaPaymentModule
15
+ * @copyright Copyright (c) 2010 Klarna (http://www.klarnaPaymentModule.no)
16
+ * @license Single-site License
17
+ *
18
+ */
19
+
20
+ class Klarna_KlarnaPaymentModule_Model_Quote_Total extends Mage_Sales_Model_Quote_Address_Total_Abstract {
21
+
22
+ public function collect(Mage_Sales_Model_Quote_Address $address)
23
+ {
24
+ if ($address->getAddressType() != "shipping")
25
+ {
26
+ return $this;
27
+ }
28
+ $helper = Mage::helper("klarnaPaymentModule");
29
+
30
+ $address->setBaseInvoiceFee(0);
31
+ $address->setInvoiceFee(0);
32
+ $address->setInvoiceTaxAmount(0);
33
+ $address->setBaseInvoiceTaxAmount(0);
34
+
35
+ if ($address->getQuote()->getId() == NULL) {
36
+ return $this;
37
+ }
38
+
39
+ $paymentMethod = $address->getQuote()->getPayment()->getMethod();
40
+ if ($paymentMethod != 'klarna_invoice' && (!count($address->getQuote()->getPaymentsCollection()) || !$address->getQuote()->getPayment()->hasMethodInstance())){
41
+ return $this;
42
+ }
43
+
44
+ $paymentMethod = $address->getQuote()->getPayment()->getMethodInstance();
45
+
46
+ if ($paymentMethod->getCode() != 'klarna_invoice') {
47
+ return $this;
48
+ }
49
+
50
+ $items = $address->getAllItems();
51
+ if (!count($items)) {
52
+ return $this;
53
+ }
54
+
55
+ $baseTotal = $address->getBaseGrandTotal();
56
+
57
+ $baseInvoiceFee = $paymentMethod->getAddressInvoiceFee($address);
58
+
59
+ // Calculate the base invoice fee tax
60
+ $invoiceBaseTax = $helper->calculateInvoiceFeeTaxSum($address, $baseInvoiceFee, false);
61
+
62
+ if (!$baseInvoiceFee > 0 ) {
63
+ return $this;
64
+ }
65
+
66
+ // adress is the reference for grand total
67
+ $quote = $address->getQuote();
68
+
69
+ $store = $quote->getStore();
70
+
71
+ /*
72
+ if ($store->getCurrentCurrency() != $store->getBaseCurrency()) {
73
+ $rate = $store->getBaseCurrency()->getRate($store->getCurrentCurrency());
74
+ $baseInvoiceFee = $invoiceFee/$rate;
75
+ } else {
76
+ $baseInvoiceFee = $invoiceFee;
77
+ }
78
+ $baseInvoiceFee = $store->roundPrice($baseInvoiceFee);
79
+ */
80
+
81
+ $baseTotal = $baseInvoiceFee+$invoiceBaseTax;
82
+
83
+ $address->setBaseInvoiceFee($baseInvoiceFee);
84
+ $address->setInvoiceFee($store->convertPrice($baseInvoiceFee,false));
85
+ // $address->setInvoiceFee($invoiceFee);
86
+
87
+ // update totals
88
+ $address->setBaseGrandTotal($baseTotal);
89
+ $address->setGrandTotal($store->convertPrice($baseTotal, false));
90
+ return $this;
91
+ }
92
+
93
+ public function fetch(Mage_Sales_Model_Quote_Address $address) {
94
+
95
+ $amount = $address->getInvoiceFee();
96
+
97
+ if ($amount!=0) {
98
+ $quote = $address->getQuote();
99
+ $address->addTotal(array(
100
+ 'code' => $this->getCode(),
101
+ 'title' => Mage::helper('klarnaPaymentModule')->__('Klarna Invoice fee'),
102
+ 'value' => $amount,
103
+ ));
104
+ }
105
+ return $this;
106
+ }
107
+ }
app/code/community/Klarna/KlarnaPaymentModule/Model/Resource/Mysql4/Setup.php ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
1
+ <?php
2
+ class Klarna_KlarnaPaymentModule_Model_Resource_Mysql4_Setup extends Mage_Core_Model_Resource_Setup {
3
+
4
+ }
5
+
app/code/community/Klarna/KlarnaPaymentModule/Model/Source/Countries.php ADDED
@@ -0,0 +1,54 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * @category Mage
16
+ * @package Mage_Paygate
17
+ * @copyright Copyright (c) 2004-2007 Irubin Consulting Inc. DBA Varien (http://www.varien.com)
18
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
19
+ */
20
+
21
+ class Klarna_KlarnaPaymentModule_Model_Source_Countries
22
+ {
23
+ public function toOptionArray()
24
+ {
25
+ $countries = array(
26
+ array(
27
+ 'label' => Mage::helper('core')->__('Norway'),
28
+ 'value' => 'NO'
29
+ ),
30
+ array(
31
+ 'label' => Mage::helper('core')->__('Sweden'),
32
+ 'value' => 'SE',
33
+ ),
34
+ array(
35
+ 'label' => Mage::helper('core')->__('Finland'),
36
+ 'value' => 'FI',
37
+ ),
38
+ array(
39
+ 'label' => Mage::helper('core')->__('Denmark'),
40
+ 'value' => 'DK',
41
+ ),
42
+ array(
43
+ 'label' => Mage::helper('core')->__('Netherlands'),
44
+ 'value' => 'NL',
45
+ ),
46
+ array(
47
+ 'label' => Mage::helper('core')->__('Germany'),
48
+ 'value' => 'DE'
49
+ )
50
+ );
51
+
52
+ return $countries;
53
+ }
54
+ }
app/code/community/Klarna/KlarnaPaymentModule/Model/Source/Integrationmode.php ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * @category Mage
16
+ * @package Mage_Paygate
17
+ * @copyright Copyright (c) 2004-2007 Irubin Consulting Inc. DBA Varien (http://www.varien.com)
18
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
19
+ */
20
+
21
+ class Klarna_KlarnaPaymentModule_Model_Source_Integrationmode
22
+ {
23
+ public function toOptionArray()
24
+ {
25
+ return array(
26
+ array(
27
+ 'label' => 'Standard integration',
28
+ 'value' => 'standard'
29
+ ),
30
+ array(
31
+ 'label' => 'Advanced integration',
32
+ 'value' => 'advanced',
33
+ )
34
+ );
35
+ }
36
+ }
app/code/community/Klarna/KlarnaPaymentModule/controllers/AddressController.php ADDED
@@ -0,0 +1,49 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento Klarna extension
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category Klarna
22
+ * @package Klarna_KlarnaPaymentModule
23
+ * @author Daniel Hansen
24
+ * @copyright Copyright (c) 2009 Klarna AB (http://www.klarnaPaymentModule.com)
25
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
26
+ */
27
+
28
+ class Klarna_KlarnaPaymentModule_AddressController extends Mage_Core_Controller_Front_Action {
29
+
30
+ public function getAddressesAction() {
31
+ $api = Mage::helper("klarnaPaymentModule/api");
32
+ $api->loadConfig(Mage::app()->getStore()->getId(), $this->getRequest()->getParam('type'));
33
+
34
+ // xxx We start to call this with pno as 0 just to set the address to the one we already selected
35
+ if($this->getRequest()->getPost('pno') != "0")
36
+ $addresses = $api->get_addresses($this->getRequest()->getPost('pno'));
37
+ else
38
+ $addresses = array("status" => "error", "error" => $this->__("You must enter a valid social security number"));
39
+
40
+ Mage::register("addresses", $addresses);
41
+
42
+ $html = $this->getLayout()->createBlock('Mage_Core_Block_Template', 'addresslist', array('template' => 'klarna/checkout/address/list.phtml'))->toHtml();
43
+
44
+ echo($html);
45
+
46
+ }
47
+
48
+ }
49
+ ?>
app/code/community/Klarna/KlarnaPaymentModule/controllers/IndexController.php ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Klarna_KlarnaPaymentModule_IndexController extends Mage_Core_Controller_Front_Action
4
+ {
5
+
6
+ public function indexAction()
7
+ {
8
+ die('yeah!');
9
+ }
10
+ }
11
+
app/code/community/Klarna/KlarnaPaymentModule/etc/config.xml ADDED
@@ -0,0 +1,219 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <modules>
4
+ <Klarna_KlarnaPaymentModule>
5
+ <version>1.0.1e</version>
6
+ <depends>
7
+ <Mage_Payment />
8
+ </depends>
9
+ </Klarna_KlarnaPaymentModule>
10
+ </modules>
11
+
12
+ <global>
13
+
14
+ <blocks>
15
+ <klarnaPaymentModule><class>Klarna_KlarnaPaymentModule_Block</class></klarnaPaymentModule>
16
+ <catalog>
17
+ <rewrite>
18
+ <product_price>Klarna_KlarnaPaymentModule_Block_Product_Price</product_price>
19
+ </rewrite>
20
+ </catalog>
21
+ </blocks>
22
+
23
+ <models>
24
+ <klarnaPaymentModule>
25
+ <class>Klarna_KlarnaPaymentModule_Model</class>
26
+ </klarnaPaymentModule>
27
+ </models>
28
+
29
+ <helpers>
30
+ <klarnaPaymentModule><class>Klarna_KlarnaPaymentModule_Helper</class></klarnaPaymentModule>
31
+ </helpers>
32
+
33
+
34
+ <resources>
35
+ <klarnaPaymentModule_setup>
36
+ <setup>
37
+ <module>Klarna_KlarnaPaymentModule</module>
38
+ <class>Klarna_KlarnaPaymentModule_Model_Resource_Mysql4_Setup</class>
39
+ </setup>
40
+ <connection>
41
+ <use>core_setup</use>
42
+ </connection>
43
+ </klarnaPaymentModule_setup>
44
+
45
+ <klarnaPaymentModule_write>
46
+ <connection>
47
+ <use>core_write</use>
48
+ </connection>
49
+ </klarnaPaymentModule_write>
50
+
51
+ <klarnaPaymentModule_read>
52
+ <connection>
53
+ <use>core_read</use>
54
+ </connection>
55
+ </klarnaPaymentModule_read>
56
+ </resources>
57
+ <sales>
58
+ <quote>
59
+ <totals>
60
+ <klarnaPaymentModule>
61
+ <class>klarnaPaymentModule/quote_total</class>
62
+ <after>subtotal,discount,shipping</after>
63
+ <before>tax,grand_total</before>
64
+ <renderer>klarnaPaymentModule/checkout_fee</renderer>
65
+ <!--
66
+ <admin_renderer>klarnaPaymentModule/adminhtml_sales_order_create_totals_invoicefee</admin_renderer>
67
+ -->
68
+ </klarnaPaymentModule>
69
+ <klarnaPaymentModule_tax>
70
+ <class>klarnaPaymentModule/quote_taxTotal</class>
71
+ <after>subtotal,discount,shipping,tax</after>
72
+ <before>grand_total</before>
73
+ </klarnaPaymentModule_tax>
74
+ </totals>
75
+ </quote>
76
+
77
+ <order_invoice>
78
+ <totals>
79
+ <klarnaPaymentModule>
80
+ <class>klarnaPaymentModule/invoice_total</class>
81
+ </klarnaPaymentModule>
82
+ <klarnaPaymentModule_tax>
83
+ <class>klarnaPaymentModule/invoice_tax</class>
84
+ </klarnaPaymentModule_tax>
85
+ </totals>
86
+ </order_invoice>
87
+ <!--
88
+ <order_creditmemo>
89
+ <totals>
90
+ <cashondelivery>
91
+ <class>cashondelivery/creditmemo_total</class>
92
+ </cashondelivery>
93
+ </totals>
94
+ </order_creditmemo>
95
+ -->
96
+ </sales>
97
+
98
+ <events>
99
+ <sales_quote_collect_totals_after>
100
+ <observers>
101
+ <klarnaPaymentModule>
102
+ <type>singleton</type>
103
+ <class>klarnaPaymentModule/observer</class>
104
+ <method>sales_quote_collect_totals_after</method>
105
+ </klarnaPaymentModule>
106
+ </observers>
107
+ </sales_quote_collect_totals_after>
108
+ <sales_order_payment_place_end>
109
+ <observers>
110
+ <klarnaPaymentModule>
111
+ <type>singleton</type>
112
+ <class>klarnaPaymentModule/observer</class>
113
+ <method>sales_order_payment_place_end</method>
114
+ </klarnaPaymentModule>
115
+ </observers>
116
+ </sales_order_payment_place_end>
117
+ <sales_order_invoice_pay>
118
+ <observers>
119
+ <klarnaPaymentModule>
120
+ <type>singleton</type>
121
+ <class>klarnaPaymentModule/observer</class>
122
+ <method>sales_order_invoice_pay</method>
123
+ </klarnaPaymentModule>
124
+ </observers>
125
+ </sales_order_invoice_pay>
126
+ <admin_system_config_changed_section_payment>
127
+ <observers>
128
+ <klarnaPaymentModule>
129
+ <type>singleton</type>
130
+ <class>klarnaPaymentModule/observer</class>
131
+ <method>admin_system_config_changed_section_payment</method>
132
+ </klarnaPaymentModule>
133
+ </observers>
134
+ </admin_system_config_changed_section_payment>
135
+ </events>
136
+
137
+ </global>
138
+
139
+ <frontend>
140
+
141
+ <layout>
142
+ <updates>
143
+ <KlarnaPaymentModule module="Klarna_KlarnaPaymentModule">
144
+ <file>klarna.xml</file>
145
+ </KlarnaPaymentModule>
146
+ </updates>
147
+ </layout>
148
+
149
+ <routers>
150
+ <klarnaPaymentModule>
151
+ <use>standard</use>
152
+ <args>
153
+ <module>Klarna_KlarnaPaymentModule</module>
154
+ <frontName>klarna</frontName>
155
+ </args>
156
+ </klarnaPaymentModule>
157
+ </routers>
158
+ <translate>
159
+ <modules>
160
+ <Klarna_KlarnaPaymentModule>
161
+ <files>
162
+ <default>Klarna_KlarnaPaymentModule.csv</default>
163
+ </files>
164
+ </Klarna_KlarnaPaymentModule>
165
+ </modules>
166
+ </translate>
167
+ </frontend>
168
+ <adminhtml>
169
+ <translate>
170
+ <modules>
171
+ <Klarna_KlarnaPaymentModule>
172
+ <files>
173
+ <Klarna>Klarna_KlarnaPaymentModule.csv</Klarna>
174
+ </files>
175
+ </Klarna_KlarnaPaymentModule>
176
+ </modules>
177
+ </translate>
178
+ </adminhtml>
179
+ <default>
180
+ <payment>
181
+ <klarna_invoice>
182
+ <integration_mode>standard</integration_mode>
183
+ <active>0</active>
184
+ <sort_order>-100</sort_order>
185
+ <model>klarnaPaymentModule/klarna_invoice</model>
186
+ <order_status>pending</order_status>
187
+ <payment_action>authorize</payment_action>
188
+ <invoice_fee_including_vat>1</invoice_fee_including_vat>
189
+ <send_by_email>0</send_by_email>
190
+ </klarna_invoice>
191
+ </payment>
192
+ <payment>
193
+ <klarna_partpayment>
194
+ <integration_mode>standard</integration_mode>
195
+ <active>0</active>
196
+ <sort_order>-150</sort_order>
197
+ <model>klarnaPaymentModule/klarna_partPayment</model>
198
+ <order_status>pending</order_status>
199
+ <payment_action>authorize</payment_action>
200
+ <invoice_fee_including_vat>1</invoice_fee_including_vat>
201
+ <invoice_fee_se>0</invoice_fee_se>
202
+ <invoice_fee_no>0</invoice_fee_no>
203
+ <invoice_fee_dk>0</invoice_fee_dk>
204
+ <invoice_fee_fi>0</invoice_fee_fi>
205
+ <invoice_fee_de>0</invoice_fee_de>
206
+ <invoice_fee_nl>0</invoice_fee_nl>
207
+ <send_by_email>0</send_by_email>
208
+ </klarna_partpayment>
209
+ </payment>
210
+ <advanced>
211
+ <klarna>
212
+ <maximum_order_amount_nl>-1</maximum_order_amount_nl>
213
+ <maximum_order_amount_de>-1</maximum_order_amount_de>
214
+ </klarna>
215
+ </advanced>
216
+ </default>
217
+
218
+
219
+ </config>
app/code/community/Klarna/KlarnaPaymentModule/etc/system.xml ADDED
@@ -0,0 +1,370 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <sections>
4
+ <payment>
5
+ <groups>
6
+ <klarna_invoice translate="label" module="klarnaPaymentModule">
7
+ <label>Klarna invoice</label>
8
+ <sort_order>10</sort_order>
9
+ <show_in_default>1</show_in_default>
10
+ <show_in_store>1</show_in_store>
11
+ <show_in_website>1</show_in_website>
12
+ <comment>Current module version 1.0.1e</comment>
13
+ <fields>
14
+ <active translate="label">
15
+ <label>Enabled</label>
16
+ <frontend_type>select</frontend_type>
17
+ <source_model>adminhtml/system_config_source_yesno</source_model>
18
+ <sort_order>1</sort_order>
19
+ <show_in_default>1</show_in_default>
20
+ <show_in_store>1</show_in_store>
21
+ <show_in_website>1</show_in_website>
22
+ <comment>Enable/disable the payment method</comment>
23
+ </active>
24
+ <order_status translate="label">
25
+ <label>New order status</label>
26
+ <frontend_type>select</frontend_type>
27
+ <source_model>adminhtml/system_config_source_order_status</source_model>
28
+ <sort_order>3</sort_order>
29
+ <show_in_default>1</show_in_default>
30
+ <show_in_store>1</show_in_store>
31
+ <show_in_website>1</show_in_website>
32
+ <comment>The status that new orders shall have in Magento</comment>
33
+ </order_status>
34
+
35
+ <merchant_id translate="label">
36
+ <label>Merchant ID</label>
37
+ <frontend_type>text</frontend_type>
38
+ <sort_order>4</sort_order>
39
+ <show_in_default>1</show_in_default>
40
+ <show_in_store>1</show_in_store>
41
+ <show_in_website>1</show_in_website>
42
+ <comment>The merchant id that you have received from Klarna</comment>
43
+ </merchant_id>
44
+
45
+ <shared_secret translate="label">
46
+ <label>Shared secret</label>
47
+ <frontend_type>text</frontend_type>
48
+ <sort_order>5</sort_order>
49
+ <show_in_default>1</show_in_default>
50
+ <show_in_store>1</show_in_store>
51
+ <show_in_website>1</show_in_website>
52
+ <comment>The shared secret that you have received from Klarna</comment>
53
+ </shared_secret>
54
+
55
+ <send_by_email translate="label">
56
+ <label>Send invoice by email</label>
57
+ <frontend_type>select</frontend_type>
58
+ <source_model>adminhtml/system_config_source_yesno</source_model>
59
+ <sort_order>6</sort_order>
60
+ <show_in_default>1</show_in_default>
61
+ <show_in_store>1</show_in_store>
62
+ <show_in_website>1</show_in_website>
63
+ <comment>
64
+ If you enable this the invoice from Klarna will
65
+ be sent by email instead of regular mail.
66
+ </comment>
67
+ </send_by_email>
68
+
69
+ <minimum_order_cost translate="label">
70
+ <label>Minimum order amount</label>
71
+ <frontend_type>text</frontend_type>
72
+ <sort_order>10</sort_order>
73
+ <show_in_default>1</show_in_default>
74
+ <show_in_store>1</show_in_store>
75
+ <show_in_website>1</show_in_website>
76
+ <comment>The minimum order amount to display this payment option for</comment>
77
+ </minimum_order_cost>
78
+
79
+ <is_test translate="label">
80
+ <label>Test mode</label>
81
+ <frontend_type>select</frontend_type>
82
+ <source_model>adminhtml/system_config_source_yesno</source_model>
83
+ <sort_order>89</sort_order>
84
+ <show_in_default>1</show_in_default>
85
+ <show_in_store>1</show_in_store>
86
+ <show_in_website>1</show_in_website>
87
+ <comment>
88
+ Is this payment option in test mode? If yes, no real invoices will be created at Klarna.
89
+ Use this to test the payment option.
90
+ </comment>
91
+ </is_test>
92
+
93
+ <tax_class translate="label">
94
+ <label>Invoice fee tax class</label>
95
+ <frontend_type>select</frontend_type>
96
+ <source_model>adminhtml/system_config_source_shipping_taxclass</source_model>
97
+ <sort_order>32</sort_order>
98
+ <show_in_default>1</show_in_default>
99
+ <show_in_store>1</show_in_store>
100
+ <show_in_website>1</show_in_website>
101
+ <comment>The tax class to use to calculate the invoice fee tax</comment>
102
+ </tax_class>
103
+
104
+ <integration_mode translate="label">
105
+ <label>Integration mode</label>
106
+ <frontend_type>select</frontend_type>
107
+ <source_model>klarnaPaymentModule/source_integrationmode</source_model>
108
+ <sort_order>80</sort_order>
109
+ <show_in_default>1</show_in_default>
110
+ <show_in_store>1</show_in_store>
111
+ <show_in_website>1</show_in_website>
112
+ <comment>The type of integration that you want to use</comment>
113
+ </integration_mode>
114
+
115
+ <allowspecific translate="label">
116
+ <label>Allowed countries</label>
117
+ <frontend_type>allowspecific</frontend_type>
118
+ <sort_order>98</sort_order>
119
+ <source_model>adminhtml/system_config_source_payment_allspecificcountries</source_model>
120
+ <show_in_default>1</show_in_default>
121
+ <show_in_website>1</show_in_website>
122
+ <show_in_store>1</show_in_store>
123
+ <comment>For which countries shall Klarna Invoice be enabled</comment>
124
+ </allowspecific>
125
+
126
+ <specificcountry translate="label">
127
+ <label>Specific countries</label>
128
+ <frontend_type>multiselect</frontend_type>
129
+ <sort_order>99</sort_order>
130
+ <source_model>klarnaPaymentModule/source_countries</source_model>
131
+ <show_in_default>1</show_in_default>
132
+ <show_in_website>1</show_in_website>
133
+ <show_in_store>1</show_in_store>
134
+ <comment>Select specific countries to enable Klarna Invoice for</comment>
135
+ </specificcountry>
136
+
137
+ <invoice_fee_including_vat translate="label">
138
+ <label>Invoice fee including VAT</label>
139
+ <frontend_type>select</frontend_type>
140
+ <source_model>adminhtml/system_config_source_yesno</source_model>
141
+ <sort_order>34</sort_order>
142
+ <show_in_default>1</show_in_default>
143
+ <show_in_store>1</show_in_store>
144
+ <show_in_website>1</show_in_website>
145
+ <comment>Is the entered invoice fee including VAT or should VAT be added to the entered fee?</comment>
146
+ </invoice_fee_including_vat>
147
+
148
+ <invoice_fee_se translate="label">
149
+ <label>Swedish invoice fee</label>
150
+ <sort_order>33</sort_order>
151
+ <show_in_default>1</show_in_default>
152
+ <show_in_website>1</show_in_website>
153
+ <show_in_store>1</show_in_store>
154
+ <comment>Add invoice fees for all swedish customers here</comment>
155
+ </invoice_fee_se>
156
+
157
+ <invoice_fee_no translate="label">
158
+ <label>Norwegian invoice fee</label>
159
+ <sort_order>33</sort_order>
160
+ <show_in_default>1</show_in_default>
161
+ <show_in_website>1</show_in_website>
162
+ <show_in_store>1</show_in_store>
163
+ <comment>Add invoice fees for all norwegian customers here</comment>
164
+ </invoice_fee_no>
165
+
166
+ <invoice_fee_dk translate="label">
167
+ <label>Danish invoice fee</label>
168
+ <sort_order>33</sort_order>
169
+ <show_in_default>1</show_in_default>
170
+ <show_in_website>1</show_in_website>
171
+ <show_in_store>1</show_in_store>
172
+ <comment>Add invoice fees for all danish customers here</comment>
173
+ </invoice_fee_dk>
174
+
175
+ <invoice_fee_fi translate="label">
176
+ <label>Finnish invoice fee</label>
177
+ <sort_order>33</sort_order>
178
+ <show_in_default>1</show_in_default>
179
+ <show_in_website>1</show_in_website>
180
+ <show_in_store>1</show_in_store>
181
+ <comment>Add invoice fees for all finnish customers here</comment>
182
+ </invoice_fee_fi>
183
+
184
+ <invoice_fee_de translate="label">
185
+ <label>German invoice fee</label>
186
+ <sort_order>33</sort_order>
187
+ <show_in_default>1</show_in_default>
188
+ <show_in_website>1</show_in_website>
189
+ <show_in_store>1</show_in_store>
190
+ <comment>Add invoice fees for all german customers here</comment>
191
+ </invoice_fee_de>
192
+
193
+ <invoice_fee_nl translate="label">
194
+ <label>Dutch invoice fee</label>
195
+ <sort_order>33</sort_order>
196
+ <show_in_default>1</show_in_default>
197
+ <show_in_website>1</show_in_website>
198
+ <show_in_store>1</show_in_store>
199
+ <comment>Add invoice fees for all dutch customers here</comment>
200
+ </invoice_fee_nl>
201
+
202
+ <sort_order>
203
+ <label>Sort order</label>
204
+ <frontend_type>text</frontend_type>
205
+ <show_in_default>1</show_in_default>
206
+ <show_in_store>1</show_in_store>
207
+ <show_in_website>1</show_in_website>
208
+ </sort_order>
209
+
210
+ </fields>
211
+ </klarna_invoice>
212
+ <klarna_partpayment translate="label" module="klarnaPaymentModule">
213
+ <label>Klarna Partpayment</label>
214
+ <sort_order>5</sort_order>
215
+ <show_in_default>1</show_in_default>
216
+ <show_in_store>1</show_in_store>
217
+ <show_in_website>1</show_in_website>
218
+ <comment>Current module version 1.0.1e</comment>
219
+ <fields>
220
+ <active translate="label">
221
+ <label>Enabled</label>
222
+ <frontend_type>select</frontend_type>
223
+ <source_model>adminhtml/system_config_source_yesno</source_model>
224
+ <sort_order>1</sort_order>
225
+ <show_in_default>1</show_in_default>
226
+ <show_in_store>1</show_in_store>
227
+ <show_in_website>1</show_in_website>
228
+ </active>
229
+ <order_status translate="label">
230
+ <label>New order status</label>
231
+ <frontend_type>select</frontend_type>
232
+ <source_model>adminhtml/system_config_source_order_status</source_model>
233
+ <sort_order>3</sort_order>
234
+ <show_in_default>1</show_in_default>
235
+ <show_in_store>1</show_in_store>
236
+ <show_in_website>1</show_in_website>
237
+ </order_status>
238
+
239
+ <merchant_id translate="label">
240
+ <label>Merchant ID</label>
241
+ <frontend_type>text</frontend_type>
242
+ <sort_order>4</sort_order>
243
+ <show_in_default>1</show_in_default>
244
+ <show_in_store>1</show_in_store>
245
+ <show_in_website>1</show_in_website>
246
+ </merchant_id>
247
+
248
+ <send_by_email translate="label">
249
+ <label>Send invoice by email</label>
250
+ <frontend_type>select</frontend_type>
251
+ <source_model>adminhtml/system_config_source_yesno</source_model>
252
+ <sort_order>6</sort_order>
253
+ <show_in_default>1</show_in_default>
254
+ <show_in_store>1</show_in_store>
255
+ <show_in_website>1</show_in_website>
256
+ <comment>
257
+ If you enable this the invoice from Klarna will
258
+ be sent by email instead of regular mail.
259
+ </comment>
260
+ </send_by_email>
261
+
262
+ <shared_secret translate="label">
263
+ <label>Shared secret</label>
264
+ <frontend_type>text</frontend_type>
265
+ <sort_order>5</sort_order>
266
+ <show_in_default>1</show_in_default>
267
+ <show_in_store>1</show_in_store>
268
+ <show_in_website>1</show_in_website>
269
+ </shared_secret>
270
+
271
+ <minimum_order_cost translate="label">
272
+ <label>Minimum order amount</label>
273
+ <frontend_type>text</frontend_type>
274
+ <sort_order>10</sort_order>
275
+ <show_in_default>1</show_in_default>
276
+ <show_in_store>1</show_in_store>
277
+ <show_in_website>1</show_in_website>
278
+ </minimum_order_cost>
279
+
280
+ <is_test translate="label">
281
+ <label>Test mode</label>
282
+ <frontend_type>select</frontend_type>
283
+ <source_model>adminhtml/system_config_source_yesno</source_model>
284
+ <sort_order>89</sort_order>
285
+ <show_in_default>1</show_in_default>
286
+ <show_in_store>1</show_in_store>
287
+ <show_in_website>1</show_in_website>
288
+ </is_test>
289
+
290
+
291
+ <integration_mode translate="label">
292
+ <label>Integration mode</label>
293
+ <frontend_type>select</frontend_type>
294
+ <source_model>klarnaPaymentModule/source_integrationmode</source_model>
295
+ <sort_order>80</sort_order>
296
+ <show_in_default>1</show_in_default>
297
+ <show_in_store>1</show_in_store>
298
+ <show_in_website>1</show_in_website>
299
+ </integration_mode>
300
+
301
+ <allowspecific translate="label">
302
+ <label>Allowed countries</label>
303
+ <frontend_type>allowspecific</frontend_type>
304
+ <sort_order>98</sort_order>
305
+ <source_model>adminhtml/system_config_source_payment_allspecificcountries</source_model>
306
+ <show_in_default>1</show_in_default>
307
+ <show_in_website>1</show_in_website>
308
+ <show_in_store>1</show_in_store>
309
+ </allowspecific>
310
+
311
+ <specificcountry translate="label">
312
+ <label>Specific countries</label>
313
+ <frontend_type>multiselect</frontend_type>
314
+ <sort_order>99</sort_order>
315
+ <source_model>klarnaPaymentModule/source_countries</source_model>
316
+ <show_in_default>1</show_in_default>
317
+ <show_in_website>1</show_in_website>
318
+ <show_in_store>1</show_in_store>
319
+ </specificcountry>
320
+
321
+ <sort_order>
322
+ <label>Sort order</label>
323
+ <frontend_type>text</frontend_type>
324
+ <show_in_default>1</show_in_default>
325
+ <show_in_store>1</show_in_store>
326
+ <show_in_website>1</show_in_website>
327
+ </sort_order>
328
+
329
+
330
+ </fields>
331
+ </klarna_partpayment>
332
+ </groups>
333
+ </payment>
334
+ <advanced>
335
+ <groups>
336
+ <klarna translate="label">
337
+ <label>Klarna</label>
338
+ <frontend_type>text</frontend_type>
339
+ <sort_order>50</sort_order>
340
+ <show_in_default>1</show_in_default>
341
+ <show_in_website>1</show_in_website>
342
+ <show_in_store>0</show_in_store>
343
+ <fields>
344
+ <maximum_order_amount_nl translate="label">
345
+ <label>Maximum order amount (Netherlands)?</label>
346
+ <comment>Enter a value for which is the maximum order amount that you will
347
+ accept orders from dutch customers with Klarna. NOTE! This value should be entered in Euro.</comment>
348
+ <frontend_type>text</frontend_type>
349
+ <sort_order>0</sort_order>
350
+ <show_in_default>1</show_in_default>
351
+ <show_in_website>0</show_in_website>
352
+ <show_in_store>0</show_in_store>
353
+ </maximum_order_amount_nl>
354
+ <maximum_order_amount_de translate="label">
355
+ <label>Maximum order amount (Germany)?</label>
356
+ <comment>Enter a value for which is the maximum order amount that you will
357
+ accept orders from german customers with Klarna. NOTE! This value should be entered in Euro.</comment>
358
+ <frontend_type>text</frontend_type>
359
+ <sort_order>0</sort_order>
360
+ <show_in_default>1</show_in_default>
361
+ <show_in_website>0</show_in_website>
362
+ <show_in_store>0</show_in_store>
363
+ </maximum_order_amount_de>
364
+
365
+ </fields>
366
+ </klarna>
367
+ </groups>
368
+ </advanced>
369
+ </sections>
370
+ </config>
app/code/community/Klarna/KlarnaPaymentModule/sql/klarnaPaymentModule_setup/mysql4-install-1.0.0e.php ADDED
@@ -0,0 +1,52 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento Klarna extension
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category Klarna
22
+ * @package Klarna_KlarnaPaymentModule
23
+ * @copyright Copyright (c) 2009 Klarna Europe AB (http://www.klarnaPaymentModule.se)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ $installer = $this;
28
+
29
+ $installer->startSetup();
30
+
31
+ $installer->run("
32
+ -- DROP TABLE IF EXISTS `{$this->getTable('klarna_pclasses')}`;
33
+ CREATE TABLE IF NOT EXISTS `{$this->getTable('klarna_pclasses')}` (
34
+ `id` int(10) unsigned NOT NULL auto_increment,
35
+ `pclass_id` int,
36
+ `description` text,
37
+ `months` int,
38
+ `startfee` int,
39
+ `handlingfee` int,
40
+ `interest` int,
41
+ `minamount` int,
42
+ `maxamount` int default null,
43
+ `country` int not null,
44
+ `type` int not null,
45
+ `storeid` int not null,
46
+ PRIMARY KEY (`id`)
47
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
48
+
49
+ ");
50
+
51
+ $installer->endSetup();
52
+
app/design/adminhtml/default/default/template/klarna/paymentinfo-invoice.phtml ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ $country = strtolower($this->getInfo()->getOrder()->getShippingAddress()->getCountryId());
3
+ ?>
4
+ <img src="<?php echo Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_SKIN) . '/adminhtml/base/default/klarna/klarna_invoice_' . strtolower($country) . '.png'; ?>" style="margin-top: 5px; margin-bottom: 10px;" alt="Klarna" />
5
+ <br/>
6
+ <?php
7
+
8
+ $data = $this->getMethod()->getInfoInstance();
9
+
10
+ $integration_mode = $data->getAdditionalInformation('klarna_integrationmode');
11
+
12
+ echo 'Integration mode: ' . $integration_mode . "<br>";
13
+
14
+ if($integration_mode == 'standard') {
15
+ echo 'Klarna invoice ID: ' . $data->getAdditionalInformation('klarna_invoice_id') . "<br>";
16
+ }
17
+ elseif($integration_mode == 'advanced') {
18
+ echo 'Klarna reservation ID: ' . $data->getAdditionalInformation('klarna_reservation_id') . "<br>";
19
+ }
20
+
21
+ echo 'Invoice fee: ' . $this->getInvoiceFee() . "<br>";
22
+
23
+
app/design/adminhtml/default/default/template/klarna/paymentinfo-partpayment.phtml ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ $country = strtolower($this->getInfo()->getOrder()->getShippingAddress()->getCountryId());
3
+ ?>
4
+ <img src="<?php echo Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_SKIN) . 'adminhtml/base/default/klarna/klarna_part_' . strtolower($country) . '.png'; ?>" style="margin-top: 10px; margin-bottom: 10px;" alt="Klarna" />
5
+ <br />
6
+ <?php
7
+
8
+ $data = $this->getMethod()->getInfoInstance();
9
+
10
+ $integration_mode = $data->getAdditionalInformation('klarna_integrationmode');
11
+
12
+ echo 'Integration mode: ' . $integration_mode . "<br>";
13
+
14
+ if($integration_mode == 'standard') {
15
+ echo 'Klarna invoice ID: ' . $data->getAdditionalInformation('klarna_invoice_id') . "<br>";
16
+ }
17
+ elseif($integration_mode == 'advanced') {
18
+ echo 'Klarna reservation ID: ' . $data->getAdditionalInformation('klarna_reservation_id') . "<br>";
19
+ }
app/design/frontend/base/default/layout/klarna.xml ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <layout version="0.1.0">
3
+ <default>
4
+ <reference name="head">
5
+ <action method="addJs"><script>klarna.js</script></action>
6
+ </reference>
7
+ </default>
8
+
9
+ <sales_order_print>
10
+ <reference name="order_totals">
11
+ <block name="invoice_fee" type="klarnaPaymentModule/order_totals_fee" before="tax"/>
12
+ </reference>
13
+ </sales_order_print>
14
+
15
+ <sales_order_view>
16
+ <reference name="order_totals">
17
+ <block name="invoice_fee" type="klarnaPaymentModule/order_totals_fee" before="tax"/>
18
+ </reference>
19
+ </sales_order_view>
20
+
21
+ <sales_order_invoice>
22
+ <reference name="invoice_totals">
23
+ <block name="invoice_fee" type="klarnaPaymentModule/invoice_totals_fee" before="tax"/>
24
+ </reference>
25
+ </sales_order_invoice>
26
+
27
+ <sales_order_printinvoice>
28
+ <reference name="invoice_totals">
29
+ <block name="invoice_fee" type="klarnaPaymentModule/invoice_totals_fee" before="tax"/>
30
+ </reference>
31
+ </sales_order_printinvoice>
32
+
33
+ <sales_email_order_items>
34
+ <reference name="order_totals">
35
+ <block name="invoice_fee" type="klarnaPaymentModule/order_totals_fee" before="tax"/>
36
+ </reference>
37
+ </sales_email_order_items>
38
+
39
+ <sales_email_order_invoice_items>
40
+ <reference name="invoice_totals">
41
+ <block name="invoice_fee" type="klarnaPaymentModule/invoice_totals_fee" before="tax"/>
42
+ </reference>
43
+ </sales_email_order_invoice_items>
44
+ <klarnaPaymentModule_address_getAddresses>
45
+ <block type="klarnaPaymentModule/checkout_address_list" name="root" output="toHtml" template="klarna/checkout/address/list.phtml"/>
46
+ </klarnaPaymentModule_address_getAddresses>
47
+ </layout>
app/design/frontend/base/default/template/klarna/checkout/address/list.phtml ADDED
@@ -0,0 +1,79 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ $addresses = Mage::registry("addresses");
3
+ Mage::unregister("addresses");
4
+ $shippingaddress = Mage::getSingleton('checkout/session')->getQuote()->getShippingAddress();
5
+ $saddress = array(array($shippingaddress['firstname'], $shippingaddress['lastname'], $shippingaddress['street'], $shippingaddress['postcode'], $shippingaddress['city'], $shippingaddress['country_id']));
6
+ $billingaddress = Mage::getSingleton('checkout/session')->getQuote()->getBillingAddress();
7
+ $baddress = array(array($billingaddress['firstname'], $billingaddress['lastname'], $billingaddress['street'], $billingaddress['postcode'], $billingaddress['city'], $billingaddress['country_id']));
8
+
9
+ // Get the integration mode for the current payment method and store
10
+ $integrationmode = Mage::helper("klarnaPaymentModule")->getIntegrationMode(Mage::app()->getStore()->getId(), $_GET["type"]);
11
+
12
+ if($addresses["status"] == "error") {
13
+ echo($addresses["error"]);
14
+ return;
15
+ }
16
+
17
+ $addresses = $addresses["addresses"];
18
+
19
+ if($addresses) {
20
+ $fixaddr = array();
21
+ foreach($addresses as $address) {
22
+ $fixaddr[] = array(utf8_encode($address[0]), utf8_encode($address[1]), utf8_encode($address[2]), utf8_encode($address[3]), utf8_encode($address[4]), utf8_encode($address[5]));
23
+ }
24
+ $baddress = array_merge($baddress, $fixaddr);
25
+ $saddress = $fixaddr;
26
+ }
27
+ ?>
28
+ <style type="text/css" >
29
+ .address-table {
30
+ border: none;
31
+ }
32
+ .address-table td {
33
+ padding: 3px;
34
+ }
35
+
36
+ </style>
37
+ <table class="address-table">
38
+ <tr>
39
+ <td><label for="select-shipping"><?php echo Mage::helper('klarnaPaymentModule')->__("Shipping address") ?>:</label>&nbsp;</td>
40
+ <td>
41
+ <?php
42
+ if(sizeof($saddress) == 1) {
43
+ echo (utf8_encode($address[0] . " " . $address[1] . ", " . $address[2] . ", " . $address[3] . " " . $address[4]));
44
+ echo ('<input type="hidden" name="payment[' . $_GET['type'] . '_shippingaddress]" value="' . utf8_encode($address[0] . '|' . $address[1] . '|' . $address[2] . '|' . $address[3] . '|' . $address[4] . '|' . $address[5]) . '" />');
45
+ } else {
46
+ ?>
47
+ <select id="select-shipping" name="payment[<?php echo $_GET['type'] ?>_shippingaddress]">
48
+ <option value="0"><?php echo $this->__("Please select your shipping address"); ?></option>
49
+ <?php foreach ($saddress as $address): ?>
50
+ <option value="<?php echo ($address[0] . "|" . $address[1] . "|" . $address[2] . "|" . $address[3] . "|" . $address[4] . "|" . $address[5]); ?>">
51
+ <?php echo ($address[0] . " " . $address[1] . ", " . $address[2] . ", " . $address[3] . " " . $address[4]) ?>
52
+ </option>
53
+ <?php endforeach; ?>
54
+ </select>
55
+ <?php
56
+ }
57
+ ?>
58
+ </td>
59
+ <td>
60
+ <?php if($integrationmode == "advanced") { ?>
61
+ <input type="radio" id="toggle" onclick="$('select-billing').toggle();" />&nbsp;<?php echo Mage::helper('klarnaPaymentModule')->__("Change billing address"); } ?>
62
+ </td>
63
+ </tr>
64
+ <?php if($integrationmode == "advanced") { ?>
65
+ <tr id="select-billing" style="display: none;">
66
+ <td><label for="select-billing"><?php echo Mage::helper('klarnaPaymentModule')->__("Billing address") ?>:</label>&nbsp;</td>
67
+ <td colspan="2">
68
+ <select name="payment[<?php echo $_GET['type'] ?>_billingaddress]">
69
+ <?php foreach ($baddress as $address): ?>
70
+ <option value="<?php echo ($address[0] . "|" . $address[1] . "|" . $address[2] . "|" . $address[3] . "|" . $address[4]); ?>">
71
+ <?php echo ($address[0] . " " . $address[1] . ", " . $address[2] . ", " . $address[3] . " " . $address[4]); ?>
72
+ </option>
73
+ <?php endforeach; ?>
74
+ </select>
75
+ </td>
76
+ </tr>
77
+ <?php } ?>
78
+ </table>
79
+
app/design/frontend/base/default/template/klarna/checkout/fee.phtml ADDED
@@ -0,0 +1,56 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @var $this Klarna_KlarnaPaymentModule_Block_Checkout_Fee
4
+ * @see Klarna_KlarnaPaymentModule_Block_Checkout_Fee
5
+ */
6
+ ?>
7
+ <tr>
8
+ <td style="<?php echo $this->getStyle() ?>" class="a-right" colspan="<?php echo $this->getColspan(); ?>">
9
+ <?php echo $this->getTotal()->getTitle() ?>
10
+ </td>
11
+ <td style="<?php echo $this->getStyle() ?>" class="a-right">
12
+ <?php echo $this->helper('checkout')->formatPrice($this->getCodFeeExcludeTax()) ?>
13
+ </td>
14
+ </tr>
15
+
16
+ <?php
17
+ /*
18
+ <?php if ($this->displayBoth()):?>
19
+ <tr>
20
+ <td style="<?php echo $this->getStyle() ?>" class="a-right" colspan="<?php echo $this->getColspan(); ?>">
21
+ <?php echo $this->getExcludeTaxLabel() ?>
22
+ </td>
23
+ <td style="<?php echo $this->getStyle() ?>" class="a-right">
24
+ <?php echo $this->helper('checkout')->formatPrice($this->getCodFeeExcludeTax()) ?>
25
+ </td>
26
+ </tr>
27
+ <tr>
28
+ <td style="<?php echo $this->getStyle() ?>" class="a-right" colspan="<?php echo $this->getColspan(); ?>">
29
+ <?php echo $this->getIncludeTaxLabel() ?>
30
+ </td>
31
+ <td style="<?php echo $this->getStyle() ?>" class="a-right">
32
+ <?php echo $this->helper('checkout')->formatPrice($this->getCodFeeIncludeTax()) ?>
33
+ </td>
34
+ </tr>
35
+ <?php elseif($this->displayIncludeTax()) : ?>
36
+ <tr>
37
+ <td style="<?php echo $this->getStyle() ?>" class="a-right" colspan="<?php echo $this->getColspan(); ?>">
38
+ <?php echo $this->getTotal()->getTitle() ?>
39
+ </td>
40
+ <td style="<?php echo $this->getStyle() ?>" class="a-right">
41
+ <?php echo $this->helper('checkout')->formatPrice($this->getCodFeeIncludeTax()) ?>
42
+ </td>
43
+ </tr>
44
+ <?php else:?>
45
+ <tr>
46
+ <td style="<?php echo $this->getStyle() ?>" class="a-right" colspan="<?php echo $this->getColspan(); ?>">
47
+ <?php echo $this->getTotal()->getTitle() ?>
48
+ </td>
49
+ <td style="<?php echo $this->getStyle() ?>" class="a-right">
50
+ <?php echo $this->helper('checkout')->formatPrice($this->getCodFeeExcludeTax()) ?>
51
+ </td>
52
+ </tr>
53
+ <?php endif;?>
54
+ */
55
+ ?>
56
+
app/design/frontend/base/default/template/klarna/form-invoice.phtml ADDED
@@ -0,0 +1,151 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ $helper = Mage::helper('klarnaPaymentModule');
3
+ $fields = $helper->getCountrySpecificFields();
4
+ ?>
5
+
6
+ <?php
7
+ /* Each time the payment methods loads, we need to set some variables on the Klarna javascript object */
8
+ $merchant_id = $helper->getMerchantId("klarna_invoice", $this->getMethod()->getStore());
9
+ $element_id = 'klarna_invoice';
10
+ $country = strtolower($helper->getCustomerCountry());
11
+ $fee = $helper->getInvoiceFee();
12
+ $isTest = $helper->isTestMode($element_id, Mage::app()->getStore()->getId());
13
+ ?>
14
+ <script type="text/javascript" >
15
+ klarna.setMerchantId('<?php echo $merchant_id; ?>');
16
+ klarna.setElementId('<?php echo $element_id; ?>');
17
+ klarna.setCountry('<?php echo $country; ?>');
18
+ klarna.setFee('<?php echo $fee; ?>');
19
+ klarna.setUrl('<?php echo $this->getUrl('klarna/address/getAddresses') ?>');
20
+ </script>
21
+
22
+
23
+ <img src="<?php echo Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_SKIN) . '/frontend/base/default/klarna/klarna_invoice_' . strtolower($country) . '.png'; ?>" style="margin-top: 5px; margin-bottom: 10px;" alt="Klarna" />
24
+
25
+ <fieldset class="form-list">
26
+ <?php $_code=$this->getMethodCode() ?>
27
+ <?php if($isTest) { ?>
28
+ <div style="border: solid 3px red; background-color: white; padding: 5px; margin: 5px; clear: both;">
29
+ <h2 style="color: red;">
30
+ <strong><?php echo $this->__("Test mode"); ?></strong> <?php echo ('<a href="#" onclick="$(\'klarna_read_more_i\').toggle();">' . $this->__('Read more / Read less') . '</a>'); ?>
31
+ </h2>
32
+ <p>
33
+ <?php echo($this->__('Please observe. Module is in test mode and no real invoices will be created!')); ?>
34
+ </p>
35
+ <div id="klarna_read_more_i" style="display:none;">
36
+ <p>
37
+ <?php echo($this->__('The module is currently set to work in test mode. This means that all purchases that
38
+ are made through this payment option will be handled as test purchases and will not generate real
39
+ invoices at Klarna. You need to disable this in the payment options before going live. Remember that
40
+ you also need to remove test mode in Klarna Online before you can start generating real invoices
41
+ through Klarna.<br /><br />Please refer to <a href="http://integration.klarna.com" target="_blank">our integration guide</a>
42
+ for more information.')); ?>
43
+ </p>
44
+ </div>
45
+ </div>
46
+ <?php } ?>
47
+ <ul id="payment_form_<?php echo $_code ?>" style="display:none">
48
+ <li>
49
+ <a href="#" id="klarna_invoice" onclick="klarna.showTerms(); return false;"><?php echo $this->__('Klarna invoice terms'); ?></a>
50
+ </li>
51
+
52
+ <?php if(in_array('personalnumber', $fields)): ?>
53
+ <li>
54
+ <label class="required" for="id_klarna_personalnumber"><?php echo $this->__('Personal number'); ?></label>
55
+ <div class="input-box" style="width: 100%">
56
+ <input type="text" name="payment[klarna_invoice_personalnumber]" value="<?php echo $helper->getFieldValue('personalnumber', $this->getMethod()->getInfoInstance()); ?>" id="klarna_invoice_personalnumber" class="input-text required-entry" <?php echo (strtolower($country) == 'se' ? 'onblur="klarna.getAddresses($F(\'klarna_invoice_personalnumber\')); return false;"' : ''); ?> />
57
+ <?php
58
+ if($country == "se") {
59
+ ?>
60
+ <button onclick="klarna.getAddresses($F('klarna_invoice_personalnumber')); return false;" class="button" type="button"><span><span><?php echo Mage::helper('klarnaPaymentModule')->__("Get my addresses") ?></span></span></button><br /><br />
61
+ <div class="tool-tip" style="position: relative; padding: 5px 10px" class="tool-tip">
62
+ <div id="loadingmask-klarna_invoice" style="display: none;">
63
+ <div class="loader" style="text-align: center;" id="loading-mask-loader-klarna_invoice"><img src="<?php echo str_replace("index.php/","",$this->getUrl()) ?>skin/adminhtml/default/default/images/ajax-loader-tr.gif" alt="<?php echo Mage::helper("klarnaPaymentModule")->__('Retreiving your addresses...') ?>"/>&nbsp;<?php echo Mage::helper("klarnaPaymentModule")->__('Retreiving your addresses...') ?>
64
+ </div>
65
+ </div>
66
+ <div id="output-div-klarna_invoice">
67
+ <?php echo $this->__('Enter your personal number and click "Get my addresses" to retreive the addresses that Klarna have stored on your social security number. Your shipping and billing address will be updated when go to the next step in the checkout'); ?>
68
+ </div>
69
+ </div>
70
+ <?php
71
+ }
72
+ ?>
73
+ </div>
74
+ </li>
75
+
76
+ <?php endif; ?>
77
+
78
+ <?php if(in_array('phonenumber', $fields)): ?>
79
+ <li>
80
+ <label class="required" for="id_klarna_phonenumber"><?php echo $this->__('Phone number'); ?></label>
81
+ <div class="input-box">
82
+ <input type="text" name="payment[klarna_invoice_phonenumber]" value="<?php echo $helper->getFieldValue('phonenumber', $this->getMethod()->getInfoInstance()); ?>" id="id_klarna_phonenumber" class="input-text required-entry" />
83
+ </div>
84
+ </li>
85
+ <?php endif; ?>
86
+
87
+
88
+ <?php if(in_array('gender', $fields)): ?>
89
+ <li>
90
+ <label for=""><?php echo $this->__('Gender'); ?></label>
91
+ <div class="input-box">
92
+ <input type="radio" name="payment[klarna_invoice_gender]" value="male" id="id_klarna_gender_male" <?php if($helper->getFieldValue('gender', $this->getMethod()->getInfoInstance()) == 'male'): ?> checked="checked" <?php endif; ?> />
93
+ <label style="float: none;" for="id_klarna_gender_male"><?php echo $this->__('Male'); ?></label>
94
+ &nbsp;&nbsp;
95
+ <input type="radio" name="payment[klarna_invoice_gender]" value="female" id="id_klarna_gender_female" <?php if($helper->getFieldValue('gender', $this->getMethod()->getInfoInstance()) == 'female'): ?> checked="checked" <?php endif; ?> class="validate-one-required" />
96
+ <label style="float: none;" for="id_klarna_gender_female"><?php echo $this->__('Female'); ?></label>
97
+ </div>
98
+ </li>
99
+ <?php endif; ?>
100
+
101
+ <?php if(in_array('street', $fields)): ?>
102
+ <li>
103
+ <label class="required" for="id_klarna_street"><?php echo $this->__('Street') . " / " . $this->__('House number') . (in_array('house_extension', $fields) ? ' / ' . $this->__('House extension') : ''); ?></label>
104
+ <div class="input-box">
105
+ <input type="text" name="payment[klarna_invoice_street]" value="<?php echo $helper->getFieldValue('street', $this->getMethod()->getInfoInstance()); ?>" id="id_klarna_street" class="input-text required-entry" style="width: 100px !important; margin-right: 3px;" />
106
+ <?php if(in_array('house_number', $fields)): ?>
107
+ <input type="text" name="payment[klarna_invoice_house_number]" value="<?php echo $helper->getFieldValue('house_number', $this->getMethod()->getInfoInstance()); ?>" id="id_klarna_house_number" class="input-text" style="width: 30px !important; margin-right: 3px;" />
108
+ <?php endif; ?>
109
+ <?php if(in_array('house_extension', $fields)): ?>
110
+ <input type="text" name="payment[klarna_invoice_house_extension]" value="<?php echo $helper->getFieldValue('house_extension', $this->getMethod()->getInfoInstance()); ?>" id="id_klarna_house_extension" class="input-text" style="width: 30px !important;" />
111
+ <?php endif; ?>
112
+ </div>
113
+ </li>
114
+ <?php endif; ?>
115
+
116
+ <?php if(in_array('dob', $fields)): ?>
117
+ <li>
118
+ <?php
119
+ $_dob_year = $helper->getFieldValue('dob_year', $this->getMethod()->getInfoInstance());
120
+ $_dob_day = $helper->getFieldValue('dob_day', $this->getMethod()->getInfoInstance());
121
+ $_dob_month = $helper->getFieldValue('dob_month', $this->getMethod()->getInfoInstance());
122
+ ?>
123
+ <label for=""><?php echo $this->__('Date of birth'); ?></label>
124
+ <div class="input-box">
125
+
126
+ <select name="payment[klarna_invoice_dob_day]" class="required-entry" style="width: 70px !important; margin-right: 5px;">
127
+ <option value=""><?php echo $this->__('Day'); ?></option>
128
+ <?php for($x=1; $x <= 31; $x++): ?>
129
+ <option <?php if($_dob_day == $x): ?> selected="selected" <?php endif; ?> value="<?php echo $x; ?>"><?php echo $x; ?></option>
130
+ <?php endfor; ?>
131
+ </select>
132
+
133
+ <select name="payment[klarna_invoice_dob_month]" class="required-entry" style="width: 70px !important; margin-right: 5px;">
134
+ <option value=""><?php echo $this->__('Month'); ?></option>
135
+ <?php for($x=1; $x <= 12; $x++): ?>
136
+ <option <?php if($_dob_month == $x): ?> selected="selected" <?php endif; ?> value="<?php echo $x; ?>"><?php echo $x; ?></option>
137
+ <?php endfor; ?>
138
+ </select>
139
+
140
+ <select name="payment[klarna_invoice_dob_year]" class="required-entry" style="width: 80px !important;">
141
+ <option value=""><?php echo $this->__('Year'); ?></option>
142
+ <?php for($x=date('Y'); $x > (date('Y')-100); $x--): ?>
143
+ <option <?php if($_dob_year == $x): ?> selected="selected" <?php endif; ?> value="<?php echo $x; ?>"><?php echo $x; ?></option>
144
+ <?php endfor; ?>
145
+ </select>
146
+ </div>
147
+ </li>
148
+ <?php endif; ?>
149
+ </ul>
150
+ </fieldset>
151
+
app/design/frontend/base/default/template/klarna/form-partpayment.phtml ADDED
@@ -0,0 +1,190 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ $helper = Mage::helper('klarnaPaymentModule');
3
+ $api = Mage::helper("klarnaPaymentModule/api");
4
+ $calc = Mage::helper('klarnaPaymentModule/calc_klarna');
5
+ $fields = $helper->getCountrySpecificFields();
6
+ ?>
7
+
8
+ <?php
9
+ /* Each time the payment methods loads, we need to set some variables on the Klarna javascript object */
10
+ $merchant_id = $helper->getMerchantId("klarna_partpayment", $this->getMethod()->getStore());
11
+ $element_id = 'klarna_partpayment';
12
+ $country = strtolower($helper->getCustomerCountry());
13
+ $pclasshelper = Mage::helper("klarnaPaymentModule/pclass");
14
+ $ordersum = Mage::getSingleton('checkout/session')->getQuote()->getGrandTotal()*100;
15
+ $pclasses = $pclasshelper->getSortedPclassesForStoreAndCountry($ordersum, strtoupper($country), (int)$this->getMethod()->getStore());
16
+ $isTest = $helper->isTestMode($element_id, Mage::app()->getStore()->getId());
17
+
18
+ ?>
19
+ <script type="text/javascript" >
20
+ klarnapp.setMerchantId('<?php echo $merchant_id; ?>');
21
+ klarnapp.setElementId('<?php echo $element_id; ?>');
22
+ klarnapp.setCountry('<?php echo strtolower($country); ?>');
23
+ klarnapp.setFee('<?php echo $ordersum; ?>');
24
+ klarnapp.setUrl('<?php echo $this->getUrl('klarna/address/getAddresses') ?>');
25
+ </script>
26
+
27
+ <img src="<?php echo Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_SKIN) . 'frontend/base/default/klarna/klarna_part_' . strtolower($country) . '.png'; ?>" style="margin-top: 10px; margin-bottom: 3px;" alt="Klarna" />
28
+
29
+ <fieldset class="form-list">
30
+ <?php $_code=$this->getMethodCode() ?>
31
+ <?php if($isTest) { ?>
32
+ <div style="border: solid 3px red; background-color: white; padding: 5px; margin: 5px; clear: both;">
33
+ <h2 style="color: red;">
34
+ <strong><?php echo $this->__("Test mode"); ?></strong> <?php echo ('<a href="#" onclick="$(\'klarna_read_more_pp\').toggle();">' . $this->__('Read more / Read less') . '</a>'); ?>
35
+ </h2>
36
+ <p>
37
+ <?php echo($this->__('Please observe. Module is in test mode and no real invoices will be created!')); ?>
38
+ </p>
39
+ <div id="klarna_read_more_pp" style="display:none;">
40
+ <p>
41
+ <?php echo($this->__('The module is currently set to work in test mode. This means that all purchases that
42
+ are made through this payment option will be handled as test purchases and will not generate real
43
+ invoices at Klarna. You need to disable this in the payment options before going live. Remember that
44
+ you also need to remove test mode in Klarna Online before you can start generating real invoices
45
+ through Klarna.<br /><br />Please refer to <a href="http://integration.klarnaPaymentModule.com" target="_blank">our integration guide</a>
46
+ for more information.')); ?>
47
+ </p>
48
+ </div>
49
+ </div>
50
+ <?php } ?>
51
+ <ul id="payment_form_<?php echo $_code ?>" style="display:none">
52
+ <li>
53
+ <a href="#" id="klarna_partpayment" onclick="klarnapp.showPPTerms(); return false;"><?php echo $this->__("Part payment terms"); ?></a>
54
+ </li>
55
+
56
+ <li>
57
+ <select name="payment[klarna_partpayment_pclass]">
58
+ <?php
59
+
60
+ $tcpc = 0;
61
+ foreach($pclasses as $pclass) {
62
+
63
+ if(strtolower($country) == 'no' && $pclass[1]['type'] < 2)
64
+ {
65
+ $tcpc = $calc->total_credit_purchase_cost($ordersum, $pclass[1]['interest']/100, $pclass[1]['handlingfee'], $pclass[1]['minamount'], $pclass[1]['months'], $pclass[1]['startfee'], $pclass[1]['type'] == 1);
66
+ $tcpc = round($tcpc/100);
67
+ }
68
+ if($pclass[1]['type'] == 2)
69
+ echo('<option value="' . $pclass[1]["pclass_id"] . '">' . $pclass[1]['description'] . '</option>');
70
+ else
71
+ echo('<option value="' . $pclass[1]["pclass_id"] . '">' . $pclass[1]['description'] . " - " . Mage::helper("core")->formatPrice(round(ceil($pclass[0]))) . ' ' . $this->__(" per month.") . ($tcpc != 0 ? ' (*' . Mage::helper("core")->formatPrice(ceil($tcpc)) . ')' : '') . '</option>');
72
+
73
+ // Reset total credit purchase cost.
74
+ $tcpc = 0;
75
+ }
76
+ ?>
77
+ </select>
78
+ <?php if(strtolower($country) == 'no') echo ('<br /><br />' . $this->__('* Total credit purchase cost.')); ?>
79
+ </li>
80
+
81
+ <?php if(in_array('personalnumber', $fields)): ?>
82
+ <li>
83
+ <div class="input-box" style="width: 100%">
84
+ <label class="required" for="klarna_partpayment_personalnumber"><?php echo $this->__('Personal number'); ?></label>
85
+ <input type="text" name="payment[klarna_partpayment_personalnumber]" value="<?php echo $helper->getFieldValue('personalnumber', $this->getMethod()->getInfoInstance()); ?>" id="klarna_partpayment_personalnumber" class="input-text required-entry"<?php echo (strtolower($country) == 'se' ? 'onblur="klarnapp.getAddresses($F(\'klarna_partpayment_personalnumber\')); return false;"' : ''); ?> />
86
+ <?php
87
+ if($country == "se") {
88
+ ?>
89
+ <button onclick="klarnapp.getAddresses($F('klarna_partpayment_personalnumber')); return false;" class="button" type="button"><span><span><?php echo Mage::helper('klarnaPaymentModule')->__("Get my addresses") ?></span></span></button><br /><br />
90
+ <div class="tool-tip" style="position: relative; padding: 5px 10px" class="tool-tip">
91
+ <div id="loadingmask-klarna_partpayment" style="display: none;">
92
+ <div class="loader" style="text-align: center;" id="loading-mask-loader-klarna_partpayment"><img src="<?php echo str_replace("index.php/","",$this->getUrl()) ?>skin/adminhtml/default/default/images/ajax-loader-tr.gif" alt="<?php echo Mage::helper("klarnaPaymentModule")->__('Retreiving your addresses...') ?>"/>&nbsp;<?php echo Mage::helper("klarnaPaymentModule")->__('Retreiving your addresses...') ?>
93
+ </div>
94
+ </div>
95
+ <div id="output-div-klarna_partpayment">
96
+ <?php echo $this->__('Enter your personal number and click "Get my addresses" to retreive the addresses that Klarna have stored on your social security number. Your shipping and billing address will be updated when go to the next step in the checkout'); ?>
97
+ </div>
98
+ </div>
99
+ <?php
100
+ }
101
+ ?>
102
+ </div>
103
+
104
+ </li>
105
+ <?php endif; ?>
106
+
107
+ <?php if(in_array('phonenumber', $fields)): ?>
108
+ <li>
109
+ <label class="required" for="id_klarna_phonenumber"><?php echo $this->__('Phone number'); ?></label>
110
+ <div class="input-box">
111
+ <input type="text" name="payment[klarna_partpayment_phonenumber]" value="<?php echo $helper->getFieldValue('phonenumber', $this->getMethod()->getInfoInstance()); ?>" id="id_klarna_phonenumber" class="input-text required-entry" />
112
+ </div>
113
+ </li>
114
+ <?php endif; ?>
115
+
116
+ <?php if(in_array('gender', $fields)): ?>
117
+ <li>
118
+ <label for=""><?php echo $this->__('Gender'); ?></label>
119
+ <div class="input-box">
120
+ <input type="radio" name="payment[klarna_partpayment_gender]" value="male" id="id_klarna_gender_male" <?php if($helper->getFieldValue('gender', $this->getMethod()->getInfoInstance()) == 'male'): ?> checked="checked" <?php endif; ?> />
121
+ <label style="float: none;" for="id_klarna_gender_male"><?php echo $this->__('Male'); ?></label>
122
+ &nbsp;&nbsp;
123
+ <input type="radio" name="payment[klarna_partpayment_gender]" value="female" id="id_klarna_gender_female" <?php if($helper->getFieldValue('gender', $this->getMethod()->getInfoInstance()) == 'female'): ?> checked="checked" <?php endif; ?> class="validate-one-required" />
124
+ <label style="float: none;" for="id_klarna_gender_female"><?php echo $this->__('Female'); ?></label>
125
+ </div>
126
+ </li>
127
+ <?php endif; ?>
128
+
129
+ <?php if(in_array('street', $fields)): ?>
130
+
131
+ <li>
132
+ <label class="required" for="id_klarna_street" style="text-align: left;"><?php echo $this->__('Street') . " / " . $this->__('House number') . (in_array('house_extension', $fields) ? ' / ' . $this->__('House extension') : ''); ?></label>
133
+ <div class="input-box">
134
+ <input type="text" name="payment[klarna_partpayment_street]" value="<?php echo $helper->getFieldValue('street', $this->getMethod()->getInfoInstance()); ?>" id="id_klarna_street" class="input-text required-entry" style="width: 100px !important; margin-right: 3px;" />
135
+ <?php if(in_array('house_number', $fields)): ?>
136
+ &nbsp;&nbsp;&nbsp;<input type="text" name="payment[klarna_partpayment_house_number]" value="<?php echo $helper->getFieldValue('house_number', $this->getMethod()->getInfoInstance()); ?>" id="id_klarna_house_number" class="input-text" style="width: 30px !important; margin-right: 3px;" />
137
+ <?php endif; ?>
138
+ <?php if(in_array('house_extension', $fields)): ?>
139
+ &nbsp;&nbsp;&nbsp;<input type="text" name="payment[klarna_partpayment_house_extension]" value="<?php echo $helper->getFieldValue('house_extension', $this->getMethod()->getInfoInstance()); ?>" id="id_klarna_house_extension" class="input-text" style="width: 30px !important;" />
140
+ <?php endif; ?>
141
+ </div>
142
+ </li>
143
+ <?php endif; ?>
144
+
145
+
146
+ <?php if(in_array('yearlysalary', $fields)): ?>
147
+ <li>
148
+ <label for=""><?php echo $this->__('Yearly Salary'); ?></label>
149
+ <div class="input-box">
150
+ <input type="text" name="payment[klarna_partpayment_yearlysalary]" value="<?php echo $helper->getFieldValue('yearlysalary', $this->getMethod()->getInfoInstance()); ?>" id="id_klarna_yearlysalary" class="input-text" />
151
+ </div>
152
+ </li>
153
+ <?php endif; ?>
154
+
155
+ <?php if(in_array('dob', $fields)): ?>
156
+ <li>
157
+ <?php
158
+ $_dob_year = $helper->getFieldValue('dob_year', $this->getMethod()->getInfoInstance());
159
+ $_dob_day = $helper->getFieldValue('dob_day', $this->getMethod()->getInfoInstance());
160
+ $_dob_month = $helper->getFieldValue('dob_month', $this->getMethod()->getInfoInstance());
161
+ ?>
162
+ <label for=""><?php echo $this->__('Date of birth'); ?></label>
163
+ <div class="input-box">
164
+
165
+ <select name="payment[klarna_partpayment_dob_day]" class="required-entry" style="width: 70px !important; margin-right: 5px;">
166
+ <option value=""><?php echo $this->__('Day'); ?></option>
167
+ <?php for($x=1; $x <= 31; $x++): ?>
168
+ <option <?php if($_dob_day == $x): ?> selected="selected" <?php endif; ?> value="<?php echo $x; ?>"><?php echo $x; ?></option>
169
+ <?php endfor; ?>
170
+ </select>
171
+
172
+ <select name="payment[klarna_partpayment_dob_month]" class="required-entry" style="width: 70px !important; margin-right: 5px;">
173
+ <option value=""><?php echo $this->__('Month'); ?></option>
174
+ <?php for($x=1; $x <= 12; $x++): ?>
175
+ <option <?php if($_dob_month == $x): ?> selected="selected" <?php endif; ?> value="<?php echo $x; ?>"><?php echo $x; ?></option>
176
+ <?php endfor; ?>
177
+ </select>
178
+
179
+ <select name="payment[klarna_partpayment_dob_year]" class="required-entry" style="width: 80px !important;">
180
+ <option value=""><?php echo $this->__('Year'); ?></option>
181
+ <?php for($x=date('Y'); $x > (date('Y')-100); $x--): ?>
182
+ <option <?php if($_dob_year == $x): ?> selected="selected" <?php endif; ?> value="<?php echo $x; ?>"><?php echo $x; ?></option>
183
+ <?php endfor; ?>
184
+ </select>
185
+ </div>
186
+ </li>
187
+ <?php endif; ?>
188
+ </ul>
189
+ </fieldset>
190
+
app/design/frontend/base/default/template/klarna/order/totals.phtml ADDED
@@ -0,0 +1 @@
 
1
+ Dette er en linje
app/design/frontend/base/default/template/klarna/paymentinfo-invoice.phtml ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ $helper = Mage::helper("klarnaPaymentModule");
3
+ $country = $helper->getCustomerCountry();
4
+ $country = $country ? $country : $this->getInfo()->getOrder()->getShippingAddress()->getCountryId();
5
+ ?>
6
+ <img src="<?php echo Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_SKIN) . '/frontend/base/default/klarna/klarna_invoice_' . strtolower($country) . '.png'; ?>" style="margin-top: 5px; margin-bottom: 10px;" alt="Klarna" />
7
+ <p><b><?php echo $this->__('Invoice fee'); ?>:</b> <?php echo $this->getInvoiceFee(); ?></p>
8
+ <?php if ($this->getInvoiceNumber()): ?>
9
+ <p><b><?php echo $this->__('Invoice number'); ?>:</b> <?php echo $this->getInvoiceNumber(); ?></p>
10
+ <?php endif; ?>
app/design/frontend/base/default/template/klarna/paymentinfo-partpayment.phtml ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ $helper = Mage::helper("klarnaPaymentModule");
3
+ $api = Mage::helper('klarnaPaymentModule/api');
4
+ $country = $helper->getCustomerCountry();
5
+ $country = $country ? $country : $this->getInfo()->getOrder()->getShippingAddress()->getCountryId();
6
+
7
+ ?>
8
+ <img src="<?php echo Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_SKIN) . 'frontend/base/default/klarna/klarna_part_' . strtolower($country) . '.png'; ?>" style="margin-top: 10px; margin-bottom: 10px;" alt="Klarna" />
9
+
10
+ <?php if ($this->getInvoiceNumber()): ?>
11
+ <p><b><?php echo $this->__('Invoice number'); ?>:</b> <?php echo $this->getInvoiceNumber(); ?></p>
12
+ <?php endif; ?>
13
+ <?php if($this->getPclassType() == null || $this->getPclassType() != 2) { ?>
14
+ <p><b><?php echo $this->__('Cost per month'); ?>:</b> <?php echo $this->getMonthlyCost(); ?></p>
15
+
16
+ <?php } else echo '<br />' . $this->getMonthlyCost(); ?>
app/design/frontend/base/default/template/klarna/product/price.phtml ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ // xxx For some reason inline translation doesnt work
4
+ // when this is enabled so we skip it when using inline translation
5
+ if(Mage::getStoreConfig("dev/translate_inline/active") == 1)
6
+ return false;
7
+ $block = $this->getLayout()->getBlock('klarna_price_block');
8
+ $formattedtext = $block ? $this->__("From %s per month with Klarna") : $this->__('From %s/month');
9
+ if(!$block && ($this->getLang() == 'no' || $this->getLang() == 'nl'))
10
+ return;
11
+ ?>
12
+
13
+ <div class="klarna_pp_text"><?php echo sprintf($formattedtext, '<span style="color: red; font-weight: bold;" class="klarna_pp_cost">' . Mage::helper("core")->formatPrice(ceil($this->getMonthlycost())) . '</span>');?></div>
14
+ <?php
15
+
16
+ // Only display the link to the term and the image.
17
+ if($this->getLang() == 'nl') {
18
+ echo('<img src="' . Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_SKIN) . '/frontend/base/default/klarna/dutch_credit.jpg" style="margin-top: 5px; margin-bottom: 10px;" alt="Klarna" /><br />');
19
+ }
20
+
21
+ // xxx Only display the link on product pages
22
+ if(!$block) return;
23
+ ?>
24
+ <script type="text/javascript" src="https://integration.klarna.com/js/klarnapart.js"></script>
25
+ <script type="text/javascript">
26
+ addKlarnaPartPaymentEvent(function() { InitKlarnaPartPaymentElements('<?php echo $this->getNameInLayout()?>', <?php echo Mage::getStoreConfig('payment/klarna_partpayment/merchant_id', Mage::app()->getStore()->getId())?>, '<?php echo $this->getLang()?>', <?php echo $this->getSum()?>); });
27
+ </script>
28
+ <a href="#" id="<?php echo $this->getNameInLayout()?>" class="klarna_pp_link" onclick="ShowKlarnaPartPaymentPopup();return false;"></a>
29
+ <?php
30
+ // Display the total credit purchase cost for norwegian customers.
31
+ if($this->getLang() == 'no') {
32
+ $cost = 0;
33
+ $calc = Mage::helper('klarnaPaymentModule/calc_klarna');
34
+ $pclass = $this->getPclass();
35
+ $cost = $calc->total_credit_purchase_cost($this->getSum(), $pclass[1]['interest']/100, $pclass[1]['handlingfee'], $pclass[1]['minamount'], $pclass[1]['months'], $pclass[1]['startfee'], $pclass[1]['type'] == 1);
36
+ ?>
37
+ <p>
38
+ <i><?php echo $this->__("Total credit purchase cost: ") . Mage::helper('core')->formatPrice(ceil($cost/100)); ?></i>
39
+ </p>
40
+ <?php
41
+ }
42
+ ?>
43
+
app/etc/modules/Klarna_KlarnaPaymentModule.xml ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
1
+ <config>
2
+ <modules>
3
+ <Klarna_KlarnaPaymentModule>
4
+ <active>true</active>
5
+ <codePool>community</codePool>
6
+ </Klarna_KlarnaPaymentModule>
7
+ </modules>
8
+ </config>
app/locale/da_DK/Klarna_KlarnaPaymentModule.csv ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ "Klarna Invoice fee","Klarna Faktura gebyr"
2
+ "Shipping fee","Fragt"
3
+ "Invoice fee","Faktura gebyr"
4
+ "Invoice number","Faktura nummer"
5
+ "Klarna invoice terms","Faktura vilkår"
6
+ "Personal number","Personnummer"
7
+ "Gender","Køn"
8
+ "Male","Mand"
9
+ "Female","Kvinde"
10
+ "Street","Gade"
11
+ "House number","Husnummer"
12
+ "House extension","House extension"
13
+ "Date of birth","Fødselsdag"
14
+ "Day","Dag"
15
+ "Month","Måned"
16
+ "Year","År"
17
+ "Phone number","Telefonnummer"
18
+ " per month.","per måned"
19
+ "Part payment terms", "Vilkår for delbetaling"
20
+ "You must enter a valid social security number", "Du skal angive et gyldigt personnummer"
21
+ "Get my addresses", "Opdatér min adresse"
22
+ "Retreiving your addresses...", "Henter dine adresser"
23
+ "Enter your personal number and click ""Get my addresses"" to retreive the addresses that Klarna have stored on your social security number. Your shipping and billing address will be updated when go to the next step in the checkout","Angiv dit personnummer og vælg ""Opdatér min adresse"" for at hente de adresser der er registreret hos Klarna i dit personnummer. Din fakturerings- og leveringsadresse vil blive opdateret, når du går videre til næste trin."
24
+ "Shipping address", "Leveringsadresse"
25
+ "Please select your shipping address", "Vælg venligst din leveringsadresse"
26
+ "Change billing address", "Ændre faktureringsadresse"
27
+ "Billing address", "Faktureringsadresse"
28
+ "From %s per month with Klarna", "Delbetale fra %s/måned"
29
+ "From %s/month", "Fra %s/måned"
30
+ "Discount", "Rabat"
31
+ "* Total credit purchase cost.", "* Total kredit omkostning."
32
+ "Total credit purchase cost: ", "Total kredit omkostning: "
33
+ "Cost per month", "Omkostninger pr. Måned"
34
+ "Yearly Salary", "Årsindkomst"
35
+ "Test mode", "Testtilstand"
36
+ "Read more / Read less", "Læs mere / Læs mindre"
37
+ "Please observe. Module is in test mode and no real invoices will be created!", "OBS! Modulet er i testtilstand og der vil ikke blive skabt en rigtig faktura."
38
+ "The module is currently set to work in test mode. This means that all purchases that
39
+ are made through this payment option will be handled as test purchases and will not generate real
40
+ invoices at Klarna. You need to disable this in the payment options before going live. Remember that
41
+ you also need to remove test mode in Klarna Online before you can start generating real invoices
42
+ through Klarna.<br /><br />Please refer to <a href=""http://integration.klarna.com"" target=""_blank"">our integration guide</a>
43
+ for more information.", "Modulet er sat til at arbejde i testtilstand. Det betyder at alle køb gennemført gennem dette betalingsalternativ vil blive behandlet som et testkøb og ikke vil skabe en rigtig faktura hos Klarna. Du skal deaktivere dette i betalingsmulighederne før du går live. Husk at du også skal fjerne testtilstand i Klarna Online før du kan skabe rigtige faktura gennem Klarna.<br /><br />Anvend venligst vores <a href=""http://integration.klarna.com"" target=""_blank"">integrations guide</a> for yderligere information."
app/locale/de_DE/Klarna_KlarnaPaymentModule.csv ADDED
@@ -0,0 +1,48 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ "Klarna Invoice fee","Klarna Rechnungsgebühr"
2
+ "Shipping fee","Frachtgebühr"
3
+ "Invoice fee","Rechnungsgebühr"
4
+ "Invoice number", "Rechnungsnummer"
5
+ "Klarna invoice terms","Rechnungserläuterung"
6
+ "Personal number","Geburtsdatum"
7
+ "Gender","Geschlecht"
8
+ "Male","Mann"
9
+ "Female","Frau"
10
+ "Street","Straße"
11
+ "House number","Hausnummer"
12
+ "House extension","Hausteil"
13
+ "Date of birth","Geburtsdatum"
14
+ "Day","Tag"
15
+ "Month","Monat"
16
+ "Year","Jahr"
17
+ "Phone number","Handynummer / Mobilnummer"
18
+ " per month."," pro Monat"
19
+ "Part payment terms", "Bedingungen für Finanzierung"
20
+ "You must enter a valid social security number", "You must enter a valid social security number"
21
+ "Get my addresses", "Meine Adresse aktualisieren"
22
+ "Retreiving your addresses...", "Ihre Adressen werden geholt..."
23
+ "Enter your personal number and click ""Get my addresses"" to retreive the addresses that Klarna have stored on your social security number. Your shipping and billing address will be updated when go to the next step in the checkout","Enter your personal number and click ""Get my addresses"" to retreive the addresses that Klarna have stored on your social security number. Your shipping and billing address will be updated when go to the next step in the checkout"
24
+ "Shipping address", "Lieferadresse"
25
+ "Please select your shipping address", "Bitte wählen Sie Ihre Lieferadresse"
26
+ "Change billing address", "Rechnungsadresse ändern"
27
+ "Billing address", "Rechnungsadresse"
28
+ "From %s per month with Klarna", "Finanzierung ab %s/ Monat"
29
+ "From %s/month", "Ab %s/ Monat"
30
+ "Discount", "Rabatt"
31
+ "* Total credit purchase cost.", "* Gesamte Kosten des Kredits."
32
+ "Total credit purchase cost: ", "Gesamte Kosten des Kredits: "
33
+ "Cost per month", "monatliche Kosten"
34
+ "Yearly Salary", "Jahreseinkommen"
35
+ "Test mode", "Testphase"
36
+ "Read more / Read less", "Mehr lesen / Weniger lesen"
37
+ "Please observe. Module is in test mode and no real invoices will be created!", "Bitte beachten! Das Modul ist in der Testphase und es können keine echten Rechnungen erstellt werden."
38
+ "The module is currently set to work in test mode. This means that all purchases that
39
+ are made through this payment option will be handled as test purchases and will not generate real
40
+ invoices at Klarna. You need to disable this in the payment options before going live. Remember that
41
+ you also need to remove test mode in Klarna Online before you can start generating real invoices
42
+ through Klarna.<br /><br />Please refer to <a href=""http://integration.klarna.com"" target=""_blank"">our integration guide</a>
43
+ for more information.", "Dies bedeutet, dass alle Einkäufe, die über diese Bezahloption getätigt werden,
44
+ als Testeinkäufe gehandhabt werden, und bei Klarna keine echten Rechnungen generiert werden. Es ist
45
+ notwendig, dass Sie dies in den Bezahloptionen deaktivieren, bevor Sie live gehen. Denken Sie
46
+ auch daran, dass die Testphase in Klarna Online abgeschalten werden muss, bevor Sie damit beginnen
47
+ können, echte Rechnungen durch Klarna zu erstellen.
48
+ <br /><br />Bitte wenden Sie sich an unseren <a href=""http://integration.klarna.com"" target=""_blank"">Integrations-Service</a> für mehr Information."
app/locale/fi_FI/Klarna_KlarnaPaymentModule.csv ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ "Klarna Invoice fee","Klarna Laskutuslisä"
2
+ "Shipping fee","Toimitusmaksu"
3
+ "Invoice fee","Laskutuslisä"
4
+ "Invoice number","Laskunumero"
5
+ "Klarna invoice terms","Klarna laskun ehdot"
6
+ "Personal number","Henkilötunnus"
7
+ "Gender","Sukupuoli"
8
+ "Male","Mies"
9
+ "Female","Nainen"
10
+ "Street", "Katu"
11
+ "House number","Talon numero"
12
+ "House extension","Portaan tunnus ja huoneiston numero"
13
+ "Date of birth","Syntymäaika"
14
+ "Day","Päivä"
15
+ "Month","Kuukausi"
16
+ "Year","Vuosi"
17
+ "Phone number","Puhelinnumero"
18
+ " per month."," per kuukausi"
19
+ "Part payment terms", "Osamaksun ehdot"
20
+ "You must enter a valid social security number", "Sinun tulee antaa voimassaoleva henkilötunnus."
21
+ "Get my addresses", "Päivitä osoitteeni."
22
+ "Retreiving your addresses...", "Hakee osoitteesi...."
23
+ "Enter your personal number and click ""Get my addresses"" to retreive the addresses that Klarna have stored on your social security number. Your shipping and billing address will be updated when go to the next step in the checkout", "Anna henkilötunnuksesi ja valitse /"Hae osoitteeni"/ hakeaksesi Klarnan henkilötunnuksesi perusteella tallentamat osoitteet. Toimitus ja laskutusosoitteesi päivitetään siirtyessäsi tilauksen seuraavaan vaiheeseen."
24
+ "Shipping address", "Toimitusosoite"
25
+ "Please select your shipping address", "Ole hyvä ja valitse toimitusosoitteesi"
26
+ "Change billing address", "Vaihda laskutusosoite"
27
+ "Billing address", "Laskutusosoite"
28
+ "From %s per month with Klarna", "Maksa osissa alkaen %s/kuukausi."
29
+ "From %s/month", "Alkaen %s/kk"
30
+ "Discount", "Alennus"
31
+ "* Total credit purchase cost.", "* Luottohinta."
32
+ "Total credit purchase cost: ", "Luottohinta: "
33
+ "Cost per month","Kulut per kuukausi"
34
+ "Yearly Salary", "Vuositulot"
35
+ "Test mode", "Testitila"
36
+ "Read more / Read less", "Lue lisää / Piilota"
37
+ "Please observe. Module is in test mode and no real invoices will be created!", "Huomaa, että moduuli on testitilassa eikä oikeita laskuja luoda."
38
+ "The module is currently set to work in test mode. This means that all purchases that
39
+ are made through this payment option will be handled as test purchases and will not generate real
40
+ invoices at Klarna. You need to disable this in the payment options before going live. Remember that
41
+ you also need to remove test mode in Klarna Online before you can start generating real invoices
42
+ through Klarna.<br /><br />Please refer to <a href=""http://integration.klarna.com"" target=""_blank"">our integration guide</a>
43
+ for more information.", "Moduuli on tällä hetkellä asetettu toimimaan testitilassa. Tämä tarkoittaa sitä, että kaikki kyseisen maksutavan kautta tehdyt ostokset käsitellään testitilauksina, eikä niistä luoda oikeita laskuja Klarnassa. Sinun tulee poistaa moduuli testitilasta ennen maksutavan käyttöönottoa. Muista, että testitila tulee poistaa myös Klarna Onlinesta, ennen kuin voit luoda oikeita laskuja Klarnan kautta. <br /><br />Lisätietoja löydät <a href=""http://integration.klarna.com"" target=""_blank"">integrointioppaastamme</a>"
app/locale/nb_NO/Klarna_KlarnaPaymentModule.csv ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ "Klarna Invoice fee","Fakturavgift"
2
+ "Shipping fee","Fraktavgift"
3
+ "Invoice fee","Fakturavgift"
4
+ "Invoice number", "Fakturanummer"
5
+ "Klarna invoice terms","Vilkår for faktura"
6
+ "Personal number","Personnummer"
7
+ "Gender","Kjønn"
8
+ "Male","Mann"
9
+ "Female","Kvinne"
10
+ "Street","Gate"
11
+ "House number","Husnummer"
12
+ "House extension","House extension"
13
+ "Date of birth","Fødselsdato"
14
+ "Day","Dag"
15
+ "Month","Måned"
16
+ "Year","År"
17
+ "Phone number","Mobilnummer"
18
+ " per month."," per måned"
19
+ "Part payment terms", "Vilkår for delbetaling"
20
+ "You must enter a valid social security number", "Du må oppgi et gyldig personnummer"
21
+ "Get my addresses", "Oppdater min adresse"
22
+ "Retreiving your addresses...", "Henter dine adresser"
23
+ "Enter your personal number and click ""Get my addresses"" to retreive the addresses that Klarna have stored on your social security number. Your shipping and billing address will be updated when go to the next step in the checkout","Angi ditt personnummer och klikk på ""Oppdater min adresse"" for å hente de adresser som du har lagret hos Klarna. Din faktura og leveringsadresse vil oppdateres når du går til neste steg."
24
+ "Shipping address", " Leveringsadresse"
25
+ "Please select your shipping address", "Vennligst velg din leveringsadresse "
26
+ "Change billing address", "Endre faktureringsadresse"
27
+ "Billing address", "Faktureringsadresse"
28
+ "From %s per month with Klarna", "Delbetale fra %s/per måned"
29
+ "From %s/month", "Fra %s/måned"
30
+ "Discount", "Rabat"
31
+ "* Total credit purchase cost.", "* Total kredittkostnad."
32
+ "Total credit purchase cost: ", "Total kredittkostnad: "
33
+ "Cost per month","Kostnad per måned"
34
+ "Yearly Salary", "Årlig inntekt"
35
+ "Test mode", "Testmodus"
36
+ "Read more / Read less", "Les mer / Les mindre"
37
+ "Please observe. Module is in test mode and no real invoices will be created!", "Vær oppmerksom på at modul er i testmodus og ingen reelle fakturaer opprettes!"
38
+ "The module is currently set to work in test mode. This means that all purchases that
39
+ are made through this payment option will be handled as test purchases and will not generate real
40
+ invoices at Klarna. You need to disable this in the payment options before going live. Remember that
41
+ you also need to remove test mode in Klarna Online before you can start generating real invoices
42
+ through Klarna.<br /><br />Please refer to <a href=""http://integration.klarna.com"" target=""_blank"">our integration guide</a>
43
+ for more information.", "Modulen er for tilfellet satt til å fungere i testmodus.
44
+ Dette betyr at alle kjøp som legges gjennom dette betalingsalternativet vil behandles som testkjøp,
45
+ og kommer ikke til å skape reelle fakturaer hos Klarna. Du må endre dette i betalingsalternativene
46
+ før du går live. Husk at du også må fjerne testmodus i Klarna Online før du kan begynne å skape reelle fakturaer gjennom Klarna.
47
+ <br /><br />Vennligst se vår <a href=""http://integration.klarna.com"" target=""_blank"">integrasjonsguide</a> for mer informasjon."
app/locale/nl_NL/Klarna_KlarnaPaymentModule.csv ADDED
@@ -0,0 +1,44 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ "Klarna Invoice fee","Facturatiekost"
2
+ "Shipping fee","Verzendkosten"
3
+ "Invoice fee","Administratieve kosten"
4
+ "Invoice number","Factuurnummer"
5
+ "Klarna invoice terms","Factuurvoorwaarden"
6
+ "Personal number","Person- /org. nummer"
7
+ "Gender","Geslacht"
8
+ "Male","Man"
9
+ "Female","Vrouw"
10
+ "Street","Straat"
11
+ "House number","Huisnummer"
12
+ "House extension","Toevoeging"
13
+ "Date of birth","Geboortedatum"
14
+ "Day","Dag"
15
+ "Month","Maand"
16
+ "Year","Jaar"
17
+ "Phone number","Mobiel nummer"
18
+ " per month."," per maand"
19
+ "Part payment terms", "Voorwaarden voor deelbetaling"
20
+ "You must enter a valid social security number", "You must enter a valid social security number"
21
+ "Get my addresses", "Zoek mijn adres"
22
+ "Retreiving your addresses...", "Uw adres wordt opgezocht...."
23
+ "Enter your personal number and click ""Get my addresses"" to retreive the addresses that Klarna have stored on your social security number. Your shipping and billing address will be updated when go to the next step in the checkout","Enter your personal number and click ""Get my addresses"" to retreive the addresses that Klarna have stored on your social security number. Your shipping and billing address will be updated when go to the next step in the checkout."
24
+ "Shipping address", "Leveradres"
25
+ "Please select your shipping address", "Kies alstublieft uw leveradres"
26
+ "Change billing address", "Wijzig factuuradres"
27
+ "Billing address", "Factuuradres"
28
+ "From %s per month with Klarna", "Deelbetaling vanaf %s/ maand"
29
+ "From %s/month", "Vanaf %s/maand"
30
+ "Discount", "Korting"
31
+ "* Total credit purchase cost.", "* Totaal kredietkosten."
32
+ "Total credit purchase cost: ", "Totaal kredietkosten: "
33
+ "Cost per month","Maandelijkse kosten"
34
+ "Yearly Salary", "Jaarinkomen"
35
+ "Test mode", "Test modus"
36
+ "Read more / Read less", "Lees meer / Lees minder"
37
+ "Please observe. Module is in test mode and no real invoices will be created!", "Gelieve op te letten! De module is in test modus en daarom kunnen geen echte facturen worden gecreëerd!"
38
+ "The module is currently set to work in test mode. This means that all purchases that
39
+ are made through this payment option will be handled as test purchases and will not generate real
40
+ invoices at Klarna. You need to disable this in the payment options before going live. Remember that
41
+ you also need to remove test mode in Klarna Online before you can start generating real invoices
42
+ through Klarna.<br /><br />Please refer to <a href=""http://integration.klarna.com"" target=""_blank"">our integration guide</a>
43
+ for more information.", "Dit betekent dat alle aankopen die door deze betalingsoptie gedaan worden als testaankopen worden behandeld en er bij Klarna geen echte facturen worden gegenereerd. Het is belangrijk dat U dit in de betalingsopties deactiveerd voor U live gaat. Denk eraan dat U de test modus moet verwijderen voor U echte facturen kan beginnen genereren bij Klarna.
44
+ <br /><br />Gelieve onze <a href=""http://integration.klarna.com"" target=""_blank"">integratiegids</a> te raadplegen voor meer informatie."
app/locale/nn_NO/Klarna_KlarnaPaymentModule.csv ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ "Klarna Invoice fee","Fakturavgift"
2
+ "Shipping fee","Fraktavgift"
3
+ "Invoice fee","Fakturavgift"
4
+ "Invoice number", "Fakturanummer"
5
+ "Klarna invoice terms","Vilkår for faktura"
6
+ "Personal number","Personnummer"
7
+ "Gender","Kjønn"
8
+ "Male","Mann"
9
+ "Female","Kvinne"
10
+ "Street","Gate"
11
+ "House number","Husnummer"
12
+ "House extension","House extension"
13
+ "Date of birth","Fødselsdato"
14
+ "Day","Dag"
15
+ "Month","Måned"
16
+ "Year","År"
17
+ "Phone number","Mobilnummer"
18
+ " per month."," per måned"
19
+ "Part payment terms", "Vilkår for delbetaling"
20
+ "You must enter a valid social security number", "Du må oppgi et gyldig personnummer"
21
+ "Get my addresses", "Oppdater min adresse"
22
+ "Retreiving your addresses...", "Henter dine adresser"
23
+ "Enter your personal number and click ""Get my addresses"" to retreive the addresses that Klarna have stored on your social security number. Your shipping and billing address will be updated when go to the next step in the checkout","Angi ditt personnummer och klikk på ""Oppdater min adresse"" for å hente de adresser som du har lagret hos Klarna. Din faktura og leveringsadresse vil oppdateres når du går til neste steg."
24
+ "Shipping address", " Leveringsadresse"
25
+ "Please select your shipping address", "Vennligst velg din leveringsadresse "
26
+ "Change billing address", "Endre faktureringsadresse"
27
+ "Billing address", "Faktureringsadresse"
28
+ "From %s per month with Klarna", "Delbetale fra %s/per måned"
29
+ "From %s/month", "Fra %s/måned"
30
+ "Discount", "Rabat"
31
+ "* Total credit purchase cost.", "* Total kredittkostnad."
32
+ "Total credit purchase cost: ", "Total kredittkostnad: "
33
+ "Cost per month","Kostnad per måned"
34
+ "Yearly Salary", "Årlig inntekt"
35
+ "Test mode", "Testmodus"
36
+ "Read more / Read less", "Les mer / Les mindre"
37
+ "Please observe. Module is in test mode and no real invoices will be created!", "Vær oppmerksom på at modul er i testmodus og ingen reelle fakturaer opprettes!"
38
+ "The module is currently set to work in test mode. This means that all purchases that
39
+ are made through this payment option will be handled as test purchases and will not generate real
40
+ invoices at Klarna. You need to disable this in the payment options before going live. Remember that
41
+ you also need to remove test mode in Klarna Online before you can start generating real invoices
42
+ through Klarna.<br /><br />Please refer to <a href=""http://integration.klarna.com"" target=""_blank"">our integration guide</a>
43
+ for more information.", "Modulen er for tilfellet satt til å fungere i testmodus.
44
+ Dette betyr at alle kjøp som legges gjennom dette betalingsalternativet vil behandles som testkjøp,
45
+ og kommer ikke til å skape reelle fakturaer hos Klarna. Du må endre dette i betalingsalternativene
46
+ før du går live. Husk at du også må fjerne testmodus i Klarna Online før du kan begynne å skape reelle fakturaer gjennom Klarna.
47
+ <br /><br />Vennligst se vår <a href=""http://integration.klarna.com"" target=""_blank"">integrasjonsguide</a> for mer informasjon."
app/locale/sv_SE/Klarna_KlarnaPaymentModule.csv ADDED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ "Klarna Invoice fee","Fakturaavgift"
2
+ "Shipping fee","Fraktavgift"
3
+ "Invoice fee","Fakturaavgift"
4
+ "Invoice number", "Fakturanummer"
5
+ "Klarna invoice terms","Villkor för faktura"
6
+ "Personal number","Personnummer"
7
+ "Gender","Kön"
8
+ "Male","Man"
9
+ "Female","Kvinna"
10
+ "Street","Gata"
11
+ "House number","Husnummer"
12
+ "House extension","House extension"
13
+ "Date of birth","Födelsedatum"
14
+ "Day","Dag"
15
+ "Month","Månad"
16
+ "Year","År"
17
+ "Phone number","Mobilnummer"
18
+ " per month."," per månad"
19
+ "Part payment terms", "Villkor för delbetalning"
20
+ "You must enter a valid social security number", "Du måste ange ett giltigt personnummer"
21
+ "Get my addresses", "Uppdatera min adress"
22
+ "Retreiving your addresses...", "Hämtar dina adresser"
23
+ "Enter your personal number and click ""Get my addresses"" to retreive the addresses that Klarna have stored on your social security number. Your shipping and billing address will be updated when go to the next step in the checkout","Ange ditt personnummer och klicka på ""Uppdatera min adress"" för att hämta de adresser som du har lagrade hos Klarna. Din faktura och leveransadress kommer att uppdateras när du går till nästa steg."
24
+ "Shipping address", "Leveransadress"
25
+ "Please select your shipping address", "Vänligen välj din leveransadress"
26
+ "Change billing address", "Ändra faktureringsadress"
27
+ "Billing address", "Faktureringsadress"
28
+ "From %s per month with Klarna", "Delbetala från %s/månad"
29
+ "From %s/month", "Från %s/månad"
30
+ "Discount", "Rabatt"
31
+ "* Total credit purchase cost.", "* Total kreditkostnad."
32
+ "Total credit purchase cost: ", "Total kreditkostnad: "
33
+ "Cost per month","Kostnad per månad"
34
+ "Yearly Salary", "Årsinkomst"
35
+ "Test mode", "Testläge"
36
+ "Read more / Read less", "Läs mer / Läs mindre"
37
+ "Please observe. Module is in test mode and no real invoices will be created!", "OBS! Modulen är i testläge och inga riktiga fakturor kommer att skapas."
38
+ "The module is currently set to work in test mode. This means that all purchases that
39
+ are made through this payment option will be handled as test purchases and will not generate real
40
+ invoices at Klarna. You need to disable this in the payment options before going live. Remember that
41
+ you also need to remove test mode in Klarna Online before you can start generating real invoices
42
+ through Klarna.<br /><br />Please refer to <a href=""http://integration.klarna.com"" target=""_blank"">our integration guide</a>
43
+ for more information.", "Modulen är för närvarande ställd i testläge. Detta innebär att alla köp med detta betalsätt
44
+ kommer att flaggas som testköp och inte generera några riktiga fakturor hos Klarna. För att åtgärda detta måste du slå av detta läge i inställningarna för modulen.
45
+ Glöm ej att du även måste slå av testläget i Klarna Online för att det ska skapas riktiga fakturor.
46
+ <br /><br />Se vår <a href=""http://integration.klarna.com"" target=""_blank"">integrationsguide</a> för mer information."
js/klarna.js ADDED
@@ -0,0 +1,74 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ var Klarna = Class.create({
3
+ initialize: function() {
4
+ this.element_id = false;
5
+ this.merchant_id = false;
6
+ this.fee = false;
7
+ this.country = false;
8
+ this.url = false;
9
+ },
10
+
11
+ setMerchantId: function(merchant_id) {
12
+ this.merchant_id = merchant_id;
13
+ },
14
+
15
+ setElementId: function(element_id) {
16
+ this.element_id = element_id;
17
+ },
18
+
19
+ setFee: function(fee) {
20
+ this.fee = fee;
21
+ },
22
+
23
+ setCountry: function(country) {
24
+ this.country = country;
25
+ },
26
+
27
+ setUrl: function(url) {
28
+ this.url = url;
29
+ },
30
+
31
+ loadExternal: function() {
32
+ var script = new Element('script', {
33
+ src: 'https://integration.klarna.com/js/klarnainvoice.js'
34
+ });
35
+ $$('head').first().insert(script);
36
+ var scriptpp = new Element('script', {
37
+ src: 'https://integration.klarna.com/js/klarnapart.js'
38
+ });
39
+ $$('head').first().insert(scriptpp);
40
+ },
41
+
42
+ showTerms: function() {
43
+ var manager = this;
44
+ InitKlarnaInvoiceElements(manager.element_id, manager.merchant_id, manager.country, manager.fee);
45
+ ShowKlarnaInvoicePopup();
46
+ },
47
+
48
+ showPPTerms: function() {
49
+ var managerpp = this;
50
+ InitKlarnaPartPaymentElements(managerpp.element_id, managerpp.merchant_id, managerpp.country, managerpp.fee);
51
+ ShowKlarnaPartPaymentPopup();
52
+ },
53
+
54
+ getAddresses: function(pno) {
55
+ var elemt = this.element_id;
56
+ Element.show('loadingmask-' + this.element_id);
57
+ var reloadurl = this.url;
58
+ new Ajax.Updater('output-div-' + this.element_id, reloadurl + '?cache' + parseInt(Math.random() * 99999999) + '&type=' + this.element_id, {
59
+ parameters: 'pno=' + pno,
60
+ onComplete: function(response) {
61
+ Element.hide('loadingmask-' + elemt);
62
+ }
63
+ });
64
+ }
65
+ });
66
+
67
+ var klarna = new Klarna();
68
+ var klarnapp = new Klarna();
69
+
70
+ document.observe('dom:loaded', function() {
71
+ if(typeof klarnapartpaymentlang == 'undefined') {
72
+ klarna.loadExternal();
73
+ }
74
+ });
package.xml ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <package>
3
+ <name>Klarna_PaymentModule_EE19</name>
4
+ <version>1.0.1</version>
5
+ <stability>stable</stability>
6
+ <license>SBSD</license>
7
+ <channel>community</channel>
8
+ <extends/>
9
+ <summary>Klarna module for invoice and part payment. Use this module for Magento Enterprise</summary>
10
+ <description>Klarna (former Kreditor) payment module for invoice and part payments. This module works with both invoice and part payments in Sweden, Finland, Denmark and Norway, Germany and Netherlads. To use this module requires that you have a contract with Klarna.&#xD;
11
+ &#xD;
12
+ Please see integration.klarna.com for technical support and installation guide</description>
13
+ <notes>Changelog 1.0.1&#xD;
14
+ * Added the module version in the payment method settings for each payment method&#xD;
15
+ * Added a sort order field for both invoice and part paymentmethod&#xD;
16
+ * Updated the calc_monthly_cost method&#xD;
17
+ * Updated so the special price is used for the part payment price calculated when available.&#xD;
18
+ * Update so the part payment price is always calculated based on the product price incl. VAT&#xD;
19
+ * Updated so the part payment prices on the product pages and the checkout form always are rounded up to closest integer.</notes>
20
+ <authors><author><name>Daniel Hansen</name><user>auto-converted</user><email>ms.modules@klarna.com</email></author></authors>
21
+ <date>2011-03-04</date>
22
+ <time>14:06:53</time>
23
+ <contents><target name="magecommunity"><dir name="Klarna"><dir name="KlarnaPaymentModule"><dir name="Block"><dir name="Checkout"><dir name="Address"><file name="List.php" hash="74c6416d77b71332dcc3aeb949252e62"/></dir><file name="Fee.php" hash="9525cc9c3c6e1db1863dd4ea201a1f86"/></dir><dir name="Invoice"><dir name="Totals"><file name="Fee.php" hash="9ea2fba5fc863cc91f7d826dc31de9c7"/></dir></dir><dir name="Klarna"><dir name="Invoice"><file name="InvoiceForm.php" hash="6f6a833e4b85dd1d90e6faf332a3740c"/><file name="InvoicePaymentInfo.php" hash="9e7dbf95e443955796009213660cc0e8"/></dir><dir name="PartPayment"><file name="PartPaymentForm.php" hash="e78421c70b3739b75841c6de5a2aa54f"/><file name="PartPaymentInfo.php" hash="62f8086265d08a35582038c9144fa13e"/></dir></dir><dir name="Order"><dir name="Totals"><file name="Fee.php" hash="4c1db605fff8ffa6806e554ea2dfff5d"/></dir></dir><dir name="Product"><file name="Price.php" hash="71286acf0a61d457620525f822e7c498"/></dir></dir><dir name="Helper"><dir name="Calc"><file name="Klarna.php" hash="fb9e38a4aab0aee2fcbed9903a47762d"/></dir><file name="Api.php" hash="8b90328a786c772c823cad15c34b69df"/><file name="Data.php" hash="5dc6c8be772c8b7ea6187f1f8875c7b8"/><file name="Pclass.php" hash="774d7f82cd9aeb4203d5dd8bbbbbfc60"/><file name="klarnaapi.php" hash="98ab19bbee145833ecdcf056e8b6361b"/><file name="pclasses.php" hash="ba1143d072df960a1b01c8c69954bfa1"/></dir><dir name="Model"><dir name="Config"><dir name="Backend"><file name="Invoicefee.php" hash="51369f0524c944bc3549211f6fc7a929"/></dir></dir><dir name="Invoice"><file name="Tax.php" hash="bcd95110e74deefacc95c283246a8835"/><file name="Total.php" hash="c2eeb136e1051b250b1d4fab7ed7de09"/></dir><dir name="Klarna"><file name="Invoice.php" hash="05387e16882bbd6f9d921592dcb57a31"/><file name="PartPayment.php" hash="530e81384516b75a2124d10d0f373867"/><file name="Shared.php" hash="29deb01fc6cca223036e1d5584cef089"/></dir><dir name="Quote"><file name="TaxTotal.php" hash="8423d9abd9d641bdaea29ed29074179f"/><file name="Total.php" hash="7d30d4dfbcefea111fac1a5410bd375b"/></dir><dir name="Resource"><dir name="Mysql4"><file name="Setup.php" hash="7d3deb8a5d34ad39eed8271bf11ea7a0"/></dir></dir><dir name="Source"><file name="Countries.php" hash="88e3980b236b75f58c2f32183a4c2ef0"/><file name="Integrationmode.php" hash="8834537dbed7477996c1f8a3238b5461"/></dir><file name="Observer.php" hash="9a5d1920311043ec8220876e6f7ef234"/></dir><dir name="controllers"><file name="AddressController.php" hash="afc5ef41ed156600706e1ca211da7374"/><file name="IndexController.php" hash="531fd9970e34281320aa35404178fa5d"/></dir><dir name="etc"><file name="config.xml" hash="8bd9f49000b4df46933859ca4a6c28af"/><file name="system.xml" hash="f68e886a16cc306aa27cded70d0cd301"/></dir><dir name="sql"><dir name="klarnaPaymentModule_setup"><file name="mysql4-install-1.0.0e.php" hash="787c4bbb497a33066d62b29394718100"/></dir></dir></dir></dir></target><target name="magelocale"><dir name="da_DK"><file name="Klarna_KlarnaPaymentModule.csv" hash="ab656d960127a690f00d1b7d32a7fb1d"/></dir><dir name="de_DE"><file name="Klarna_KlarnaPaymentModule.csv" hash="cdc11317d456bd94e276a85f768dd6f4"/></dir><dir name="fi_FI"><file name="Klarna_KlarnaPaymentModule.csv" hash="c7458e6dce8eced67a07b5e475454691"/></dir><dir name="nb_NO"><file name="Klarna_KlarnaPaymentModule.csv" hash="1c285a281fd06af96b33cd872c00d522"/></dir><dir name="nn_NO"><file name="Klarna_KlarnaPaymentModule.csv" hash="1c285a281fd06af96b33cd872c00d522"/></dir><dir name="nl_NL"><file name="Klarna_KlarnaPaymentModule.csv" hash="a1ee2a09e287c6f0fad58feedbd241a3"/></dir><dir name="sv_SE"><file name="Klarna_KlarnaPaymentModule.csv" hash="8c6508258e9d7b2202a9e5a212be801c"/></dir></target><target name="mageskin"><dir name="adminhtml"><dir name="base"><dir name="default"><dir name="klarna"><file name="klarna_invoice_de.png" hash="2c7b69fcc4bf9953db7f31517db064f1"/><file name="klarna_invoice_dk.png" hash="91c3c941e628a0ad79994e316a1ca725"/><file name="klarna_invoice_fi.png" hash="5dd18840c2c2531c6d6a726c9fb0cea2"/><file name="klarna_invoice_nl.png" hash="55479d0b581d2aee68b18c0f75099b98"/><file name="klarna_invoice_no.png" hash="91c3c941e628a0ad79994e316a1ca725"/><file name="klarna_invoice_se.png" hash="91c3c941e628a0ad79994e316a1ca725"/><file name="klarna_part_de.png" hash="cbfda4edbc5660cbaa9c6fc38259a034"/><file name="klarna_part_dk.png" hash="d3be4f0fc8de16380c498f7819f5bd01"/><file name="klarna_part_fi.png" hash="7d14d7fb95050471ad8436afa27e93e3"/><file name="klarna_part_nl.png" hash="0be858250eccaf1ba45ee5aa639d3595"/><file name="klarna_part_no.png" hash="d3be4f0fc8de16380c498f7819f5bd01"/><file name="klarna_part_se.png" hash="d3be4f0fc8de16380c498f7819f5bd01"/></dir></dir></dir></dir><dir name="frontend"><dir name="base"><dir name="default"><dir name="klarna"><file name="dutch_credit.jpg" hash="620adf3aeebf2f6ac7ccfa6e0fba39fe"/><file name="klarna_invoice_de.png" hash="2c7b69fcc4bf9953db7f31517db064f1"/><file name="klarna_invoice_dk.png" hash="91c3c941e628a0ad79994e316a1ca725"/><file name="klarna_invoice_fi.png" hash="5dd18840c2c2531c6d6a726c9fb0cea2"/><file name="klarna_invoice_nl.png" hash="55479d0b581d2aee68b18c0f75099b98"/><file name="klarna_invoice_no.png" hash="91c3c941e628a0ad79994e316a1ca725"/><file name="klarna_invoice_se.png" hash="91c3c941e628a0ad79994e316a1ca725"/><file name="klarna_part_de.png" hash="cbfda4edbc5660cbaa9c6fc38259a034"/><file name="klarna_part_dk.png" hash="d3be4f0fc8de16380c498f7819f5bd01"/><file name="klarna_part_fi.png" hash="7d14d7fb95050471ad8436afa27e93e3"/><file name="klarna_part_nl.png" hash="0be858250eccaf1ba45ee5aa639d3595"/><file name="klarna_part_no.png" hash="d3be4f0fc8de16380c498f7819f5bd01"/><file name="klarna_part_se.png" hash="d3be4f0fc8de16380c498f7819f5bd01"/></dir></dir></dir></dir></target><target name="magedesign"><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="template"><dir name="klarna"><file name="paymentinfo-invoice.phtml" hash="3bd5e3df21e845387f5c512aa23b34eb"/><file name="paymentinfo-partpayment.phtml" hash="a9c989cec603597e827b64251f7ed4b9"/></dir></dir></dir></dir></dir><dir name="frontend"><dir name="base"><dir name="default"><dir name="template"><dir name="klarna"><dir name="checkout"><dir name="address"><file name="list.phtml" hash="410092a4b17c529d75efbc722552279d"/></dir><file name="fee.phtml" hash="e96a24dff1d636089d80b96425ef0cb6"/></dir><dir name="order"><file name="totals.phtml" hash="5bbadd4ba1119813b2e5cb79c81f7837"/></dir><dir name="product"><file name="price.phtml" hash="0c09992d57c1f9fe77d17144dacb67b2"/></dir><file name="form-invoice.phtml" hash="08dfdf373a6bd121d840c60b9e0f9c06"/><file name="form-partpayment.phtml" hash="503ca781d31519381f80c4873de29888"/><file name="paymentinfo-invoice.phtml" hash="dd7761e02a8a99efcf733e80ef8f0577"/><file name="paymentinfo-partpayment.phtml" hash="7711936a248d8a875c8bd16e2c8ee8eb"/></dir></dir><dir name="layout"><file name="klarna.xml" hash="94e4c192d5814a30585a75a4c7a5c6dd"/></dir></dir></dir></dir></target><target name="mage"><dir name="app"><dir name="etc"><dir name="modules"><file name="Klarna_KlarnaPaymentModule.xml" hash="22f98c3ef6e965e559f6e7d3daf91c5d"/></dir></dir></dir></target><target name="mageweb"><dir name="js"><file name="klarna.js" hash="dfa9276daf7a7ce86d5f8d90d96f12af"/></dir></target></contents>
24
+ <compatible/>
25
+ <dependencies/>
26
+ </package>
skin/adminhtml/base/default/klarna/klarna_invoice_de.png ADDED
Binary file
skin/adminhtml/base/default/klarna/klarna_invoice_dk.png ADDED
Binary file
skin/adminhtml/base/default/klarna/klarna_invoice_fi.png ADDED
Binary file
skin/adminhtml/base/default/klarna/klarna_invoice_nl.png ADDED
Binary file
skin/adminhtml/base/default/klarna/klarna_invoice_no.png ADDED
Binary file
skin/adminhtml/base/default/klarna/klarna_invoice_se.png ADDED
Binary file
skin/adminhtml/base/default/klarna/klarna_part_de.png ADDED
Binary file
skin/adminhtml/base/default/klarna/klarna_part_dk.png ADDED
Binary file
skin/adminhtml/base/default/klarna/klarna_part_fi.png ADDED
Binary file
skin/adminhtml/base/default/klarna/klarna_part_nl.png ADDED
Binary file
skin/adminhtml/base/default/klarna/klarna_part_no.png ADDED
Binary file
skin/adminhtml/base/default/klarna/klarna_part_se.png ADDED
Binary file
skin/frontend/base/default/klarna/dutch_credit.jpg ADDED
Binary file
skin/frontend/base/default/klarna/klarna_invoice_de.png ADDED
Binary file
skin/frontend/base/default/klarna/klarna_invoice_dk.png ADDED
Binary file
skin/frontend/base/default/klarna/klarna_invoice_fi.png ADDED
Binary file
skin/frontend/base/default/klarna/klarna_invoice_nl.png ADDED
Binary file
skin/frontend/base/default/klarna/klarna_invoice_no.png ADDED
Binary file
skin/frontend/base/default/klarna/klarna_invoice_se.png ADDED
Binary file
skin/frontend/base/default/klarna/klarna_part_de.png ADDED
Binary file
skin/frontend/base/default/klarna/klarna_part_dk.png ADDED
Binary file
skin/frontend/base/default/klarna/klarna_part_fi.png ADDED
Binary file
skin/frontend/base/default/klarna/klarna_part_nl.png ADDED
Binary file
skin/frontend/base/default/klarna/klarna_part_no.png ADDED
Binary file
skin/frontend/base/default/klarna/klarna_part_se.png ADDED
Binary file