Skip to content

Commit 345e7f0

Browse files
committed
[*] MO : New features and a few issues addressed
Newsletter box Encoding issue for product names Documentation improved Added support for possible cronjob status checks pending orders
1 parent e92655b commit 345e7f0

13 files changed

+397
-16
lines changed

CHANGELOG

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.8.29Update to carrier validation1.8.28Improvements on documentation1.8.27Removed some notices.Imporved company customer support in KPM.Added purifyHTML to voucher code.Changed the terms text for netherlands1.8.26Changed the flag for discountChanged the terms text for germanyFixed issue with genderlink to kco hidden if kco not active for selected country in default checkout.Fixed settings for checkout logo1.8.25changes to javascript for correct layout of discount prices in cart rows1.8.24Changes to orderstatuses on install1.8.23Autofix of default addresses on checkout pages.1.8.22Improvements to security1.8.21Reverse birthday year-month-day to day-month-year for Germany1.8.20move sum to variable.1.8.19pSQL added to push1.8.18Added simple hook for paymentEU.1.8.17Added issue with special chars in message field1.8.16Change expire field from int to varchar in install script.1.8.15Change expire field from int to varchar, due to Klarna sometimes sending - instead of empty value.1.8.14Added Deactivate for status selections.1.8.13Added support for gb iso code1.8.12Added support for minimum amount on orders.1.8.11Moved SQL Install script to sql folder.Added id_cart to klarna_orders table.Made some changes as to in what order klarna order information is saved to module tables. mainly to support different EIDs for SBM system.1.8.10Changed a link1.8.9Fixed an & sign1.8.8changed some tabs to spaces.1.8.7Added automatic meta on installation.1.8.6Fixed issue in kco_height.tpl1.8.5Name changesfilename changescoding standardsoptimization1.8.4Coding standardsUpdate on library1.8.3Save function for test flag moved.1.8.2moved libraries into libraries folder.1.8.1Removed a link in the backoffice.Moved test flag to common settings.1.8.0Cleaned up some more.1.7.0Added readmeCleaned up markupAdded texts explanations1.6.0Escape variablessome sql changesgetaddress fix1.5.0Fixed pclasses for Denmark1.4.0Added so that links are not replaced when KCO is not active.Added button for KCO address check.1.3.0Fixed some issues with kco UK1.2.0Changes to the layout1.1.0UK EID not always int.1.0.0First version for 1.6
1+
1.8.31Newsletter boxEncoding issue for product namesDocumentation improvedAdded support for possible cronjob status checks pending orders1.8.30Link to legacy checkout in case of Klarna service interuption.1.8.29Update to carrier validation1.8.28Improvements on documentation1.8.27Removed some notices.Imporved company customer support in KPM.Added purifyHTML to voucher code.Changed the terms text for netherlands1.8.26Changed the flag for discountChanged the terms text for germanyFixed issue with genderlink to kco hidden if kco not active for selected country in default checkout.Fixed settings for checkout logo1.8.25changes to javascript for correct layout of discount prices in cart rows1.8.24Changes to orderstatuses on install1.8.23Autofix of default addresses on checkout pages.1.8.22Improvements to security1.8.21Reverse birthday year-month-day to day-month-year for Germany1.8.20move sum to variable.1.8.19pSQL added to push1.8.18Added simple hook for paymentEU.1.8.17Added issue with special chars in message field1.8.16Change expire field from int to varchar in install script.1.8.15Change expire field from int to varchar, due to Klarna sometimes sending - instead of empty value.1.8.14Added Deactivate for status selections.1.8.13Added support for gb iso code1.8.12Added support for minimum amount on orders.1.8.11Moved SQL Install script to sql folder.Added id_cart to klarna_orders table.Made some changes as to in what order klarna order information is saved to module tables. mainly to support different EIDs for SBM system.1.8.10Changed a link1.8.9Fixed an & sign1.8.8changed some tabs to spaces.1.8.7Added automatic meta on installation.1.8.6Fixed issue in kco_height.tpl1.8.5Name changesfilename changescoding standardsoptimization1.8.4Coding standardsUpdate on library1.8.3Save function for test flag moved.1.8.2moved libraries into libraries folder.1.8.1Removed a link in the backoffice.Moved test flag to common settings.1.8.0Cleaned up some more.1.7.0Added readmeCleaned up markupAdded texts explanations1.6.0Escape variablessome sql changesgetaddress fix1.5.0Fixed pclasses for Denmark1.4.0Added so that links are not replaced when KCO is not active.Added button for KCO address check.1.3.0Fixed some issues with kco UK1.2.0Changes to the layout1.1.0UK EID not always int.1.0.0First version for 1.6

checkpendingorders.php

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
require_once(dirname(__FILE__). '/../../config/config.inc.php');
3+
require_once(_PS_ROOT_DIR_.'/init.php');
4+
require_once(dirname(__FILE__).'/klarnaofficial.php');
5+
6+
$shops = Shop::getShops(true,null,true);
7+
$order_status_ids = "";
8+
foreach ($shops as $shop) {
9+
$order_status_ids .= Configuration::get('KPM_PENDING_PP', null, null, $shop).",";
10+
$order_status_ids .= Configuration::get('KPM_PENDING_INVOICE', null, null, $shop).",";
11+
}
12+
$order_status_ids = rtrim($order_status_ids, ",");
13+
$order_status_ids = pSQL($order_status_ids);
14+
$sql = "SELECT id_order FROM "._DB_PREFIX_."orders WHERE current_state IN ($order_status_ids);";
15+
$result = Db::getInstance()->executeS($sql);
16+
17+
foreach ($result as $row) {
18+
$id_order = (int)$row["id_order"];
19+
try {
20+
$klarnaofficial = new KlarnaOfficial();
21+
$klarnaofficial->checkPendingStatus($id_order);
22+
} catch (Exception $e) {
23+
$msg = "Check pending: $id_order " . $e->getMessage();
24+
Logger::addLog($msg, 1, null, 'klarnaofficial', $id_order, true);
25+
}
26+
}
27+
echo "Done";
28+
?>

config.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<module>
33
<name>klarnaofficial</name>
44
<displayName><![CDATA[Klarna]]></displayName>
5-
<version><![CDATA[1.8.29]]></version>
5+
<version><![CDATA[1.8.31]]></version>
66
<description><![CDATA[Gateway for Klarna (KCO and KPM).]]></description>
77
<author><![CDATA[Prestaworks AB]]></author>
88
<tab><![CDATA[payments_gateways]]></tab>

controllers/front/checkoutklarna.php

+19-2
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,9 @@ public function postProcess()
136136
$vouchererrors = Tools::displayError('This voucher does not exists');
137137
}
138138
}
139+
//FORCE html_entity_decode SINCE PRESTASHOP Demand escape:html in tpl files but already does this on displayError..
139140
$this->context->smarty->assign(array(
140-
'vouchererrors' => $vouchererrors,
141+
'vouchererrors' => html_entity_decode($vouchererrors),
141142
'discount_name' => Tools::safeOutput($code),
142143
));
143144
} elseif (($id_cart_rule = (int) Tools::getValue('deleteDiscount')) &&
@@ -502,6 +503,15 @@ public function initContent()
502503
$create['merchant']['push_uri'] = $pushPage;
503504
$create['merchant_reference']['orderid2'] = ''.(int) ($this->context->cart->id);
504505

506+
if ((int)Configuration::get('KCO_ADD_NEWSLETTERBOX') == 0) {
507+
$create['options']['additional_checkbox']['text'] = $this->module->getL('Subscribe to our newsletter.');
508+
$create['options']['additional_checkbox']['checked'] = false;
509+
$create['options']['additional_checkbox']['required'] = false;
510+
} elseif ((int)Configuration::get('KCO_ADD_NEWSLETTERBOX') == 1) {
511+
$create['options']['additional_checkbox']['text'] = $this->module->getL('Subscribe to our newsletter.');
512+
$create['options']['additional_checkbox']['checked'] = true;
513+
$create['options']['additional_checkbox']['required'] = false;
514+
}
505515
if (Configuration::get('KCO_COLORBUTTON') != '') {
506516
$create['options']['color_button'] = ''.
507517
Configuration::get('KCO_COLORBUTTON');
@@ -682,7 +692,14 @@ public function initContent()
682692
'back' => ''
683693
));
684694
} catch (Exception $e) {
685-
$this->context->smarty->assign('klarna_error', $e->getMessage());
695+
$message = $e->getMessage();
696+
if($message == "Connection to 'https://checkout.klarna.com/checkout/orders' failed.") {
697+
$connectionerror = true;
698+
} else {
699+
$connectionerror = false;
700+
}
701+
$this->context->smarty->assign('connectionerror', $connectionerror);
702+
$this->context->smarty->assign('klarna_error', $message);
686703
}
687704
}
688705
} else {

controllers/front/checkoutklarnauk.php

+11-2
Original file line numberDiff line numberDiff line change
@@ -153,8 +153,9 @@ public function postProcess()
153153
$vouchererrors = Tools::displayError('This voucher does not exists');
154154
}
155155
}
156+
//FORCE html_entity_decode SINCE PRESTASHOP Demand escape:html in tpl files but already does this on displayError..
156157
$this->context->smarty->assign(array(
157-
'vouchererrors' => $vouchererrors,
158+
'vouchererrors' => html_entity_decode($vouchererrors),
158159
'discount_name' => Tools::safeOutput($code),
159160
));
160161
} elseif (($id_cart_rule = (int) Tools::getValue('deleteDiscount')) &&
@@ -518,7 +519,15 @@ public function initContent()
518519
$create['merchant_urls']['confirmation'] = $callbackPage;
519520
$create['merchant_urls']['push'] = $pushPage;
520521
$create['merchant_reference2'] = ''.(int) ($this->context->cart->id);
521-
522+
if ((int)Configuration::get('KCO_ADD_NEWSLETTERBOX') == 0) {
523+
$create['options']['additional_checkbox']['text'] = $this->module->getL('Subscribe to our newsletter.');
524+
$create['options']['additional_checkbox']['checked'] = false;
525+
$create['options']['additional_checkbox']['required'] = false;
526+
} elseif ((int)Configuration::get('KCO_ADD_NEWSLETTERBOX') == 1) {
527+
$create['options']['additional_checkbox']['text'] = $this->module->getL('Subscribe to our newsletter.');
528+
$create['options']['additional_checkbox']['checked'] = true;
529+
$create['options']['additional_checkbox']['required'] = false;
530+
}
522531
if (Configuration::get('KCO_COLORBUTTON') != '') {
523532
$create['options']['color_button'] = ''.Configuration::get('KCO_COLORBUTTON');
524533
}

controllers/front/kpmpartpayment.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ public function initContent()
176176
$k->addArticle(
177177
1,
178178
'shipping',
179-
''.Tools::getValue('kpmshipping'),
179+
''.utf8_decode(pSQL(Tools::getValue('kpmshipping'))),
180180
$total_shipping_wt,
181181
$shipping_tax,
182182
0,
@@ -192,7 +192,7 @@ public function initContent()
192192
$k->addArticle(
193193
1,
194194
'wrapping',
195-
''.Tools::getValue('kpmwrapping'),
195+
''.utf8_decode(pSQL(Tools::getValue('kpmwrapping'))),
196196
$total_wrapping_cost_wt,
197197
$wrapping_fees_tax,
198198
0,
@@ -217,7 +217,7 @@ public function initContent()
217217
$k->addArticle(
218218
$product['cart_quantity'],
219219
''.$product['reference'],
220-
''.$name,
220+
''.utf8_decode($name),
221221
(float)$product['price_wt'],
222222
$product['rate'],
223223
0,

controllers/front/push.php

+14-2
Original file line numberDiff line numberDiff line change
@@ -155,10 +155,22 @@ public function postProcess()
155155
if (!Validate::isEmail($shipping['email'])) {
156156
$shipping['email'] = 'ingen_mejl_'.$id_cart.'@ingendoman.cc';
157157
}
158-
158+
$newsletter = 0;
159+
$newsletter_setting = (int)Configuration::get('KCO_ADD_NEWSLETTERBOX', null, $cart->id_shop);
160+
if ($newsletter_setting == 0 || $newsletter_setting == 1) {
161+
if(isset($klarnaorder['merchant_requested']) && isset($klarnaorder['merchant_requested']['additional_checkbox']) && $klarnaorder['merchant_requested']['additional_checkbox'] == true) {
162+
$newsletter = 1;
163+
}
164+
} elseif ($newsletter_setting == 2) {
165+
$newsletter = 1;
166+
}
159167
$id_customer = (int) (Customer::customerExists($shipping['email'], true, true));
160168
if ($id_customer > 0) {
161169
$customer = new Customer($id_customer);
170+
if ($newsletter == 1) {
171+
$sql_update_customer = "UPDATE "._DB_PREFIX_."customer SET newsletter=1 WHERE id_customer=$id_customer;";
172+
Db::getInstance()->execute(pSQL($sql_update_customer));
173+
}
162174
} else {
163175
//add customer
164176
$password = Tools::passwdGen(8);
@@ -170,7 +182,7 @@ public function postProcess()
170182
$customer->is_guest = 0;
171183
$customer->id_default_group = (int) (Configuration::get('PS_CUSTOMER_GROUP', null, $cart->id_shop));
172184
//$customer->id_default_group = (int)(Configuration::get('PS_GUEST_GROUP', null, $cart->id_shop));
173-
$customer->newsletter = 0;
185+
$customer->newsletter = $newsletter;
174186
$customer->optin = 0;
175187
$customer->active = 1;
176188
$customer->id_gender = 9;

controllers/front/pushuk.php

+15-1
Original file line numberDiff line numberDiff line change
@@ -136,10 +136,24 @@ public function postProcess()
136136
if (!Validate::isEmail($shipping['email'])) {
137137
$shipping['email'] = 'ingen_mejl_'.$id_cart.'@ingendoman.cc';
138138
}
139+
140+
$newsletter = 0;
141+
$newsletter_setting = (int)Configuration::get('KCO_ADD_NEWSLETTERBOX', null, $cart->id_shop);
142+
if ($newsletter_setting == 0 || $newsletter_setting == 1) {
143+
if(isset($klarnaorder['merchant_requested']) && isset($klarnaorder['merchant_requested']['additional_checkbox']) && $klarnaorder['merchant_requested']['additional_checkbox'] == true) {
144+
$newsletter = 1;
145+
}
146+
} elseif ($newsletter_setting == 2) {
147+
$newsletter = 1;
148+
}
139149

140150
$id_customer = (int) (Customer::customerExists($shipping['email'], true, true));
141151
if ($id_customer > 0) {
142152
$customer = new Customer($id_customer);
153+
if ($newsletter == 1) {
154+
$sql_update_customer = "UPDATE "._DB_PREFIX_."customer SET newsletter=1 WHERE id_customer=$id_customer;";
155+
Db::getInstance()->execute(pSQL($sql_update_customer));
156+
}
143157
} else {
144158
//add customer
145159
$password = Tools::passwdGen(8);
@@ -155,7 +169,7 @@ public function postProcess()
155169
$cart->id_shop
156170
));
157171

158-
$customer->newsletter = 0;
172+
$customer->newsletter = $newsletter;
159173
$customer->optin = 0;
160174
$customer->active = 1;
161175
$customer->id_gender = 9;

doc/index.html

+46
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,45 @@ <h4 class="alert-heading">NOTE!</h4>
205205
It is possible to enable both services (KCO & KPM) at the same time in the same store. Just make sure to submit your information in corresponding tab for KCO & KPM. If no information is submitted to e.g. Klarna Payment Method (KPM) tab, it will be disabled in the front-office.
206206
The same goes with Klarna Checkout - that require you to set <strong>"Active KCO in this shop"</strong> to <strong>Yes</strong> while you've also make sure to submit your Klarna information to corresponding countries within the tab.
207207
</div>
208+
209+
<h3>Configure your store to add a invoice fee for Klarna (KPM only)</h3>
210+
<p>To create an invoice fee for Klarna KPM (invoice) orders, you need to create a new product in the store with the following parameters:</p>
211+
212+
<ul>
213+
<li>Provide a proper name, e.g: Invoice fee</li>
214+
<li>Make sure to assign a quiet high quantity for this article, e.g: 99999999</li>
215+
<li>Submit the price for the fee in the price field</li>
216+
<li>Make sure the product is active and visibility is set to "nowhere"</li>
217+
<li><strong>It's very important that this product has the same reference code as you've submitted in the Klarna Official-module under tab KLARNA PAYMENT METHOD (KPM) - field: "Invoice fee product".</strong></li>
218+
</ul>
219+
220+
<h3>Configure backend calls (activate and cancel)</h3>
221+
<p>It is possible to work with backend calls to Klarna to activate and cancel orders. Navigate to the integration configuration page and go to tab <strong>"COMMON SETTINGS"</strong>:</p>
222+
223+
<table id="tabs_desc" class="table table-bordered table-striped">
224+
<thead>
225+
<tr>
226+
<th>Setting</th>
227+
<th>Description</th>
228+
</tr>
229+
</thead>
230+
<tbody>
231+
<tr>
232+
<td class="tabs_topic">Activate order status</td>
233+
<td>In this drop-down you simply choose which order status you would like to trigger the call to Klarna for activating the invoice at Klarna. If you would like to disable this feature you will have to choose: <strong>"Deactivated"</strong>.</td>
234+
</tr>
235+
<tr>
236+
<td class="tabs_topic">Cancel reservation status</td>
237+
<td>In this drop-down you simply choose which order status you would like to trigger the call to Klarna for cancel the invoice at Klarna. If you would like to disable this feature you will have to choose: <strong>"Deactivated"</strong>.</td>
238+
</tr>
239+
</tbody>
240+
</table>
241+
242+
<div class="alert alert-block">
243+
<a class="close" data-dismiss="alert">×</a>
244+
<h4 class="alert-heading">NOTE!</h4>
245+
This feature concerns KCO and KCO.
246+
</div>
208247

209248
</section>
210249

@@ -224,6 +263,13 @@ <h3>Template problems</h3>
224263
<li>Font Icons - Many third party templates use different core for font icons within the template. The font icons used in our integration is mainly built together with default icons used in the bootstrap template. You will have to go through the template files (.tpl) in our integration to patch the source for icons in the integration if the icons won't appear in front-office.</li>
225264
</ul>
226265

266+
<h3>Important about callbacks</h3>
267+
<p>The following callbacks are not implemented.</p>
268+
<ul>
269+
<li>Re-send invoice - Handled from Klarna Online.</li>
270+
<li>Partial refund - Handled from Klarna Online.</li>
271+
</ul>
272+
227273
</section>
228274

229275
<section id="changelog">

0 commit comments

Comments
 (0)