From 2bedd1a36de2686604ec8526a2d2abb3d4fdacec Mon Sep 17 00:00:00 2001 From: Sankar Vijay Date: Mon, 25 Jun 2018 13:50:10 +0200 Subject: [PATCH 01/11] update redirect after checkout --- .../controller/extension/payment/lemonway.php | 86 +++++-------------- 1 file changed, 20 insertions(+), 66 deletions(-) diff --git a/lemonway.ocmod/upload/catalog/controller/extension/payment/lemonway.php b/lemonway.ocmod/upload/catalog/controller/extension/payment/lemonway.php index 1ebda3d..718a908 100644 --- a/lemonway.ocmod/upload/catalog/controller/extension/payment/lemonway.php +++ b/lemonway.ocmod/upload/catalog/controller/extension/payment/lemonway.php @@ -21,8 +21,9 @@ class ControllerExtensionPaymentLemonWay extends Controller private $money_in_trans_details; - private function prefix() { - return (version_compare(VERSION, '3.0', '>=')) ? 'payment_' : ''; + private function prefix() + { + return (version_compare(VERSION, '3.0', '>=')) ? 'payment_' : ''; } /* @@ -63,7 +64,7 @@ private function postValue($key) private function getLemonWayConfig() { $config = array(); - + if ($this->config->get($this->prefix() . 'lemonway_is_test_mode')) { // TEST $config['dkURL'] = $this->config->get($this->prefix() . 'lemonway_directkit_url_test'); //DIRECT KIT URL TEST @@ -116,19 +117,21 @@ private function getMoneyInTransDetails($wkToken) /* Check the real paid amount */ - private function checkAmount($amount, $realAmount) { + private function checkAmount($amount, $realAmount) + { return ($amount == $realAmount); } /* Double check */ - private function doublecheckAmount($amount, $wkToken) { + private function doublecheckAmount($amount, $wkToken) + { $details = $this->getMoneyInTransDetails($wkToken); // CREDIT + COMMISSION $realAmountDoublecheck = $details->TRANS->HPAY[0]->CRED + $details->TRANS->HPAY[0]->COM; - + // Status 3 means success return (($details->TRANS->HPAY[0]->STATUS == '3') && ($amount == $realAmountDoublecheck)); } @@ -170,7 +173,7 @@ public function index() $data['lemonway_oneclick_enabled'] = $this->config->get($this->prefix() . 'lemonway_oneclick_enabled'); $data['customerId'] = empty($this->customer->getId()) ? 0 : $this->customer->getId(); // A guest customer has no Id, we consider it 0 - + $data['card'] = $this->model_extension_payment_lemonway->getCustomerCard($this->customer->getId()); return $this->load->view('extension/payment/lemonway', $data); @@ -182,18 +185,13 @@ public function index() */ public function checkout() { - $available_cards = array('CB', 'VISA', 'MASTERCARD'); if ((!$this->cart->hasProducts() && empty($this->session->data['vouchers'])) || (!$this->cart->hasStock() && !$this->config->get('config_stock_checkout'))) { // Redirect to the cart $this->response->redirect($this->url->link('checkout/cart', '', true)); } - if (!isset($this->request->post['cc_type']) || !in_array($this->request->post['cc_type'], $available_cards)) { - // Redirect to the cart and display error - $this->session->data['error'] = $this->language->get('error_card_type'); - $this->response->redirect($this->url->link('checkout/cart', '', true)); - } + //Load Language $this->load->language('extension/payment/lemonway'); @@ -211,7 +209,7 @@ public function checkout() $this->session->data['error'] = $this->language->get('error_order_not_found'); $this->response->redirect($this->url->link('checkout/cart', '', true)); } - + // Lemon Way config $config = $this->getLemonWayConfig(); @@ -224,11 +222,11 @@ public function checkout() ); $params = array(); - + $params['wallet'] = $config['wallet']; $total = number_format((float)$order_info['total'], 2, '.', ''); $params['amountTot'] = $total; - $params['comment'] = $this->config->get('config_name') . " (OpenCart) - " . $order_id . " - " . + $params['comment'] = $this->config->get('config_name') . " - " . $order_id . " - " . $this->customer->getLastName() . " " . $this->customer->getFirstName() . " - " . $this->customer->getEmail(); $params['autoCommission'] = $config['autoCommission']; @@ -236,7 +234,7 @@ public function checkout() $customerId = empty($this->customer->getId()) ? 0 : $this->customer->getId(); // A guest customer has no Id, we consider it 0 $useCard = ( - $this->config->get($this->prefix() . 'lemonway_oneclick_enabled') && + $this->config->get($this->prefix() . 'lemonway_oneclick_enabled') && $customerId && $this->postValue('lemonway_oneclick') === 'use_card' ); @@ -304,52 +302,8 @@ public function checkout() $lang = array_key_exists($lang, $this->supportedLangs) ? $this->supportedLangs[$lang] : self::DEFAULT_LANG; $lwUrl = $config['wkURL'] . '?moneyintoken=' . $moneyInToken . '&p=' . urlencode($config['cssURL']) . '&lang=' . $lang; + $this->response->redirect($lwUrl); - $cc_type = $this->request->post['cc_type']; - - $ch = curl_init(); - curl_setopt($ch, CURLOPT_URL, $lwUrl); - curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); - curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); - curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY); - curl_setopt($ch, CURLOPT_TIMEOUT, 30); - curl_setopt($ch, CURLOPT_CAINFO, DIR_SYSTEM . "/library/lemonway/cacert.pem"); - - $response = curl_exec($ch); - - $matches = array(); - - $patternFormActionAndData = '/(action="|name=data value=")([^"]*)"/i'; - if (preg_match_all($patternFormActionAndData, $response, $matches)) { - if (isset($matches[2])) { - list($actionUrl, $data) = $matches[2]; - $postFields = array( - 'DATA' => $data, - $cc_type => 1 - ); - - $text_redirect = $this->language->get('text_redirect'); - - $html = '' . "\n"; - $html .= '' . "\n"; - $html .= ' ' . "\n"; - $html .= ' '; - $html .= ' '; - $html .= '

' . $text_redirect . '
' . "\n"; - $html .= ' ' . "\n"; - $html .= ' ' . "\n"; - $html .= ' ' . "\n"; - $html .= ''; - - die($html); - } - } } else { // If the client use a saved card => MoneyInWithCardId if (($card = $this->model_extension_payment_lemonway->getCustomerCard($this->customer->getId())) && $this->customer->isLogged()) { //Call API for MoneyInWithCardId @@ -402,8 +356,8 @@ public function checkoutReturn() if ($this->isGet()) { // If redirection // GET params if ($this->config->get($this->prefix() . 'lemonway_debug')) { - $debug_log = new Log('lemonway_debug.log'); - $debug_log->write('GET params: ' . print_r($this->request->get, true)); + $debug_log = new Log('lemonway_debug.log'); + $debug_log->write('GET params: ' . print_r($this->request->get, true)); } $wkToken = $this->getValue('response_wkToken'); @@ -457,8 +411,8 @@ public function checkoutReturn() } elseif ($this->isPost()) { // If IPN // Get response by IPN if ($this->config->get($this->prefix() . 'lemonway_debug')) { - $debug_log = new Log('lemonway_debug.log'); - $debug_log->write('IPN: ' . print_r($this->request->post, true)); + $debug_log = new Log('lemonway_debug.log'); + $debug_log->write('IPN: ' . print_r($this->request->post, true)); } $response_code = $this->postValue('response_code'); From 24db2170b63507b97065d55f09f023d8666b63f0 Mon Sep 17 00:00:00 2001 From: Sankar Vijay Date: Mon, 25 Jun 2018 13:50:39 +0200 Subject: [PATCH 02/11] rm image --- .../view/theme/default/image/lemonway_cb.gif | Bin 1867 -> 0 bytes 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 lemonway.ocmod/upload/catalog/view/theme/default/image/lemonway_cb.gif diff --git a/lemonway.ocmod/upload/catalog/view/theme/default/image/lemonway_cb.gif b/lemonway.ocmod/upload/catalog/view/theme/default/image/lemonway_cb.gif deleted file mode 100644 index cbbd626d0b44ff47ee17835bfaf9e3ad1fcec54b..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1867 zcmchW{Zkb88Niq0W$+Hp;}Bdx3M&Lz0v;QTdZG?2BInwf$c|O#FyzPqo~|h5tTAjX za4auT;|s2DnJ?ueT%yAArYl7_!%N+O(ABi*nuhiot@W6K9+T3XCKC(GvE2n zGtc*VzCS!q-nOml^+oHT1jq|50>c=BzzBjO2&O>@6oq|P3`I~B!%#hf;uwm^DaU(zr zIjqouQ5>-k7+KQDkrYqTPO{`;m6Zcl+JRHP5J&pHLOb=0fL9G0Str4Y6mXJ2G&)4H zL$q={#fc6h>V{!AjJi>uxF;C$Xdo{Nd2vW4eQLZo>>*Jvsb`J2Yz~$w4NoC13gIYJ zwxYmFdT7#1TV>iRGMLN|fU(L9E3>e~>KS$s8K4{hvV)Kur0lRdI1+F)&jE&~B%Wq? zhT#G0WEp`30x1e4BTzuF$`U3^xL2ZO7cKEX5`aepUK+5BL*^U~fs@^wEOQLt8J=eZ zo@IHK_f_S6NFwhMd9TaK0097j1A@#83@@@y5eOnLilS3=OQOdu%AzQHMOhXZLE?Px zL`iZAK>)roBtF-W@jz#$8W0T}bjaq~|MgtIo@Y^z1sV z!g!U@%2;-@Eid)hmg9t`G&ell<|jn#GS$@8MHUWUjWAVDBMrMv755rro8Z>^SaLm5 zRI)eB+_3u;B7D63ctss-uCB=6BF*gyiYlN)U?&LzUdZTSMc|L5SaXv-G#wJoI} zyEvM-k^N0{Y4x_PQ3u*8gbRCGYo6sei$B|M>ZA8{zSV_czX-|L;u$1+GykS)icEXc}sJdVZ+za_FsI9emZ5UEYVFKF|N|t zwL(h!LUU(PSjH{szzp|0*PS5U^&7(zUA^l6yxv_lkEiIqO>Cd-ojCNT?J*_2cV=2g z)RZNoEqZkJ_WjNCDqZu@AKTl@s()&~Uirr8^E*px3SJC!sxv!!j{nfRx^K#2F6;k# z!@N=_iv@>cyqzH zy9Vd~xVEczJjp)RG@i7pfctgQm7R(c%ddRcv@PM2olPGlz1g&w@>|ZBs0Ex;P1bE z6kq$|r0$Djo{YVsV*aal)T7F~4nC1zYO^+zbhD4n&xZ~-4Kl)^IOpwF zQ5w4y3;UPWMy)XYM3&o@4Q2f%)sU?$DYwmCIGmia^YN3<-p?GXPzS|K+Cz5DDHg7O z7nnMjS+m42W(#L`1m+$rQsvu6BCcfxrX-%sG34Hh3vEMGma}gM1VB*ce*wd< BDM0`L From 5b429637cc749470aab496662315eac4300f870e Mon Sep 17 00:00:00 2001 From: Sankar Vijay Date: Mon, 25 Jun 2018 13:50:49 +0200 Subject: [PATCH 03/11] rm image --- .../theme/default/image/lemonway_mastercard.gif | Bin 1174 -> 0 bytes 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 lemonway.ocmod/upload/catalog/view/theme/default/image/lemonway_mastercard.gif diff --git a/lemonway.ocmod/upload/catalog/view/theme/default/image/lemonway_mastercard.gif b/lemonway.ocmod/upload/catalog/view/theme/default/image/lemonway_mastercard.gif deleted file mode 100644 index 9dc0ccfdfee00ef260de87d1e87bcc3384cdcb4c..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1174 zcmWlY@oy7#96Vad;;4oFYaLcL=q(ITCl~h--jAP8CY9(h8-wY;e}0M}%k_I=mp71(#*n?Y4#0h^kts>zD*Amuu-B zi~voKHk(ES_#p^|eHo-Ek6T1lB{rh1Gfb_W>p)@!0#&={EGI)P@SthdYWk$$t$;rh zjT1sBS789svaGgRrU7nL%SOTN>&WpCM@6A2(Fb{}=wy1*#ImX>zZ*)}YT*!tG_5Fl zHakfQP=g-i`8aUJVvCf(wy_6tQ&T3Y`Vy%{nu(3dj4RWol2iuhtusL8F86R?-+gXyNDQp!< zJ})paoXoSVLgFAn7!?jnCCp|^Y(!!sUMQd{=LQ%Y8>prIq*}$MP=p9!ARHdUOop(m zWmqXr!8(hL2FZb(43Qw*81G!ASUehX-b}Ux+cw{D2#&Eb0k4lLU z$RY#DL_9TP2T=mV=aN8g?{NwM3_(>$+xXZKKF>GB4v8Q_nKG zZsjS)ibO5S)6NzRgP5jmdR;TkcinJ0X5xpXH&?j%M6U~BaG_`2so`^Pxb9f;tZR5= zjf3i5e{5Y~)84l{55Drl)l=PYaQ5n1uF$aK8`d{x|J=p&Z(lo>2W0o5*ItIV7d>$O z@?8FW zKRUDfa_3W@PE2c!!H)R6)89_d{jBq^+lF1+w;lX` Date: Mon, 25 Jun 2018 13:50:57 +0200 Subject: [PATCH 04/11] rm image --- .../view/theme/default/image/lemonway_visa.gif | Bin 1389 -> 0 bytes 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 lemonway.ocmod/upload/catalog/view/theme/default/image/lemonway_visa.gif diff --git a/lemonway.ocmod/upload/catalog/view/theme/default/image/lemonway_visa.gif b/lemonway.ocmod/upload/catalog/view/theme/default/image/lemonway_visa.gif deleted file mode 100644 index cd93a68f9c9b3c713281639331ff82e2a62bbbaa..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1389 zcmZ?wbhEHbG-ps|_|Cxa9|*pGPj)ig>csFonc;o4!24o`_fs_A&oO+z)bRiR=l}no z`~QFMz4!m;Y`wO2@3rbFdo7cfDtb*3ux#0S?D>?X$Ie}Q9#y=S!>~ufvPZ(OIx2gq zfMzv^Vljh6u~X2LmY%KI#dA0$l8dX?MkUV)ikiZ}k-T;5xur|@1_kvnFeoxG7&0(8 zF)#$RR4*+~p7Q_ue}+*o8UpkR0mYvzj0_CS3_2hSL3x6K;~xY25ebhC3l27O2y6Lh z7_c?83n+Wd@z}WNXeWz))}0d*A024dj@TmMIjQyJWR2i1lbcPcrzdJAE(&@0;GsK% zu2IU21DlthpYPDjC3K_$MBaV|eDe{9>8V!~`bxUzHuf*+Nqjnp!uinm5&c$b8}yr2WC{VV$7Q z7Dx7rOARii>lP#|a#e79!c?GE!*H?YJL7`J7G91_DQ-EF3k(bj2Yw{h2=9F$#x1yZ zN<7cxtpbxccsmw2l`^c^?$jf0tKi6K=4au^sbCY*$Rb=Ia4<*2XM(beNXmjI)B03z z1y1ZTTP4oGrl9b0$&|3HmrG})bvZB!+;wqaT+pWVYQ>UiS+7>I3LH4Fm__EntJOXm zj%mGKv*lV<10(l_tk>)IeCt}hZZDhmo7MZfz6Pv5taf@e<7z2x21Yg)?YCR5gk`_o idPB;=Vcj{aSGg{dwZGpw@am?#+xbGu#KD1q!5RQ1a8JGf From f4b427308453eacce89b38060c17e457c4e5ab77 Mon Sep 17 00:00:00 2001 From: Sankar Vijay Date: Mon, 25 Jun 2018 13:51:28 +0200 Subject: [PATCH 05/11] rm choose card display --- .../template/extension/payment/lemonway.tpl | 46 +++++++++---------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/lemonway.ocmod/upload/catalog/view/theme/default/template/extension/payment/lemonway.tpl b/lemonway.ocmod/upload/catalog/view/theme/default/template/extension/payment/lemonway.tpl index bd66eb2..d362a85 100644 --- a/lemonway.ocmod/upload/catalog/view/theme/default/template/extension/payment/lemonway.tpl +++ b/lemonway.ocmod/upload/catalog/view/theme/default/template/extension/payment/lemonway.tpl @@ -41,28 +41,28 @@ -
-
-
- -
-
- -
-
- -
-
-
+ {*
*} + {*
*} + {*
*} + {**} + {*
*} + {*
*} + {**} + {*
*} + {*
*} + {**} + {*
*} + {*
*} + {*
*}
@@ -103,4 +103,4 @@ $('#card_choosing_container').show(300); }) }); - \ No newline at end of file + From aba8baf52e73dc5e8b8d8b5d7a68269004e5871d Mon Sep 17 00:00:00 2001 From: Sankar Vijay Date: Mon, 25 Jun 2018 13:51:56 +0200 Subject: [PATCH 06/11] rm choose card display --- .../template/extension/payment/lemonway.twig | 50 +++++++++---------- 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/lemonway.ocmod/upload/catalog/view/theme/default/template/extension/payment/lemonway.twig b/lemonway.ocmod/upload/catalog/view/theme/default/template/extension/payment/lemonway.twig index d164b58..5422cae 100644 --- a/lemonway.ocmod/upload/catalog/view/theme/default/template/extension/payment/lemonway.twig +++ b/lemonway.ocmod/upload/catalog/view/theme/default/template/extension/payment/lemonway.twig @@ -35,30 +35,30 @@ {% endif %} {% endif %} - - -
-
-
- -
-
- -
-
- -
-
-
+ {##} + {##} + {#
#} + {#
#} + {#
#} + {##} + {#
#} + {#
#} + {##} + {#
#} + {#
#} + {##} + {#
#} + {#
#} + {#
#}
@@ -95,4 +95,4 @@ $('#card_choosing_container').show(300); }) }); - \ No newline at end of file + From 4d36baa4c367676bc69d5629ca20bb636dc1ebd5 Mon Sep 17 00:00:00 2001 From: Sankar Vijay Date: Tue, 26 Jun 2018 10:03:01 +0200 Subject: [PATCH 07/11] add template name --- .../catalog/controller/extension/payment/lemonway.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lemonway.ocmod/upload/catalog/controller/extension/payment/lemonway.php b/lemonway.ocmod/upload/catalog/controller/extension/payment/lemonway.php index 718a908..a86e0f6 100644 --- a/lemonway.ocmod/upload/catalog/controller/extension/payment/lemonway.php +++ b/lemonway.ocmod/upload/catalog/controller/extension/payment/lemonway.php @@ -77,9 +77,10 @@ private function getLemonWayConfig() $config['login'] = $this->config->get($this->prefix() . 'lemonway_api_login'); $config['pass'] = $this->config->get($this->prefix() . 'lemonway_api_password'); - $config['wallet'] = empty($this->config->get($this->prefix() . 'lemonway_environment_name')) ? - $this->config->get($this->prefix() . 'lemonway_wallet') : $this->config->get($this->prefix() . 'lemonway_custom_wallet'); + $config['wallet'] = empty($this->config->get($this->prefix() . 'lemonway_environment_name')) ? $this->config->get($this->prefix() . 'lemonway_wallet') : $this->config->get($this->prefix() . 'lemonway_custom_wallet'); $config['cssURL'] = $this->config->get($this->prefix() . 'lemonway_css_url'); + $config['tplName'] = $this->config->get($this->prefix() . 'lemonway_template_name'); + $config['autoCommission'] = (int)!empty($this->config->get($this->prefix() . 'lemonway_environment_name')); // Autocom = 0 if lwecommerce, 1 if custom environment @@ -192,7 +193,6 @@ public function checkout() } - //Load Language $this->load->language('extension/payment/lemonway'); @@ -300,8 +300,8 @@ public function checkout() $moneyInToken = (string)$res->MONEYINWEB->TOKEN; $lang = substr($this->language->get('code'), 0, 2); $lang = array_key_exists($lang, $this->supportedLangs) ? $this->supportedLangs[$lang] : self::DEFAULT_LANG; - - $lwUrl = $config['wkURL'] . '?moneyintoken=' . $moneyInToken . '&p=' . urlencode($config['cssURL']) . '&lang=' . $lang; +// . '&tpl=' . urlencode($config['tplName']) + $lwUrl = $config['wkURL'] . '?moneyintoken=' . $moneyInToken . '&p=' . urlencode($config['cssURL']) . '&lang=' . $lang . '&tpl=' . urlencode($config['tplName']); $this->response->redirect($lwUrl); } else { // If the client use a saved card => MoneyInWithCardId From 0dc4aad97d94e40a0804347545466bbb0558fe86 Mon Sep 17 00:00:00 2001 From: Sankar Vijay Date: Tue, 26 Jun 2018 10:28:30 +0200 Subject: [PATCH 08/11] add template name --- .../upload/admin/controller/extension/payment/lemonway.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lemonway.ocmod/upload/admin/controller/extension/payment/lemonway.php b/lemonway.ocmod/upload/admin/controller/extension/payment/lemonway.php index 719dbd9..cf85996 100644 --- a/lemonway.ocmod/upload/admin/controller/extension/payment/lemonway.php +++ b/lemonway.ocmod/upload/admin/controller/extension/payment/lemonway.php @@ -46,6 +46,8 @@ public function index() $this->variables['lemonway_custom_wallet'] = $this->model_setting_setting->getSettingValue($this->prefix() . 'lemonway_custom_wallet'); $this->variables['lemonway_status'] = $this->model_setting_setting->getSettingValue($this->prefix() . 'lemonway_status'); $this->variables['lemonway_oneclick_enabled'] = $this->model_setting_setting->getSettingValue($this->prefix() . 'lemonway_oneclick_enabled'); + $this->variables['lemonway_template_name'] = $this->model_setting_setting->getSettingValue($this->prefix() . 'lemonway_template_name'); + // Alerts $this->variables['no_permission'] = false; @@ -61,7 +63,6 @@ public function index() } else { // If no method enabled $this->variables['no_method'] = true; } - // Load tabs // About us $this->variables['about_us'] = $this->load->view('extension/payment/lemonway_aboutus', $this->variables); @@ -170,6 +171,7 @@ private function testConfig() } $res = $lemonwayService->getWalletDetails($params); + //var_dump($res->WALLET->ID); if (empty($this->variables['lemonway_environment_name'])) { // If lwecommerce, get wallet if (isset($res->WALLET->ID)) { From e1d0446729568735e991e3a59eb227d758f560be Mon Sep 17 00:00:00 2001 From: Sankar Vijay Date: Tue, 26 Jun 2018 10:29:35 +0200 Subject: [PATCH 09/11] view input template name --- .../extension/payment/lemonway_config.twig | 45 ++++++++++++++----- 1 file changed, 34 insertions(+), 11 deletions(-) diff --git a/lemonway.ocmod/upload/admin/view/template/extension/payment/lemonway_config.twig b/lemonway.ocmod/upload/admin/view/template/extension/payment/lemonway_config.twig index 9570e59..9dfab1b 100644 --- a/lemonway.ocmod/upload/admin/view/template/extension/payment/lemonway_config.twig +++ b/lemonway.ocmod/upload/admin/view/template/extension/payment/lemonway_config.twig @@ -16,7 +16,8 @@ - +

{{ text_help_login }} @@ -34,7 +35,8 @@ - +

{{ text_help_password }} @@ -44,11 +46,12 @@

- +

{{ text_help_test_mode }}

@@ -76,7 +79,7 @@ - +

{{ text_help_css }} @@ -109,11 +112,11 @@ {{ text_custom_environment }}

{{ error_custom_env }}
- +
@@ -121,7 +124,8 @@ - +
@@ -138,12 +142,31 @@ - - + +
+ + +
+ + +
+
+ + + + + +
+
+
- \ No newline at end of file + From 4dd0f943b02bc7585684cafdf538c0ca3a23eb9e Mon Sep 17 00:00:00 2001 From: Sankar Vijay Date: Tue, 26 Jun 2018 10:29:59 +0200 Subject: [PATCH 10/11] variable template name --- .../upload/admin/language/en-gb/extension/payment/lemonway.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lemonway.ocmod/upload/admin/language/en-gb/extension/payment/lemonway.php b/lemonway.ocmod/upload/admin/language/en-gb/extension/payment/lemonway.php index c3fb256..f4387dd 100644 --- a/lemonway.ocmod/upload/admin/language/en-gb/extension/payment/lemonway.php +++ b/lemonway.ocmod/upload/admin/language/en-gb/extension/payment/lemonway.php @@ -39,6 +39,8 @@ $_['text_custom_environment'] = 'CUSTOM ENVIRONMENT'; $_['text_environment_name'] = 'Custom environment name'; $_['text_wallet'] = 'Technical wallet name'; +$_['tpl_name'] = 'Template name'; + // CREDIT CARD $_['text_method_config'] = 'METHOD CONFIGURATION '; From a6c5373330c4066b2e60e41065499e6bba9ae782 Mon Sep 17 00:00:00 2001 From: Sankar Date: Wed, 25 Jul 2018 15:00:55 +0200 Subject: [PATCH 11/11] sofort payment --- .../controller/extension/payment/lemonway.php | 31 +- .../en-gb/extension/payment/lemonway.php | 4 +- .../extension/payment/lemonway_cc.twig | 10 +- .../extension/payment/lemonway_sofort.twig | 18 + .../controller/extension/payment/lemonway.php | 3 +- .../extension/payment/lemonway_sofort.php | 344 ++++++++++++++++++ .../en-gb/extension/payment/lemonway.php | 1 + .../model/extension/payment/lemonway.php | 1 + .../extension/payment/lemonway_sofort.php | 117 ++++++ .../template/extension/payment/lemonway.twig | 136 +++---- .../extension/payment/lemonway_sofort.twig | 102 ++++++ .../library/lemonway/LemonWayService.php | 21 +- 12 files changed, 704 insertions(+), 84 deletions(-) create mode 100644 lemonway.ocmod/upload/admin/view/template/extension/payment/lemonway_sofort.twig create mode 100644 lemonway.ocmod/upload/catalog/controller/extension/payment/lemonway_sofort.php create mode 100644 lemonway.ocmod/upload/catalog/model/extension/payment/lemonway_sofort.php create mode 100644 lemonway.ocmod/upload/catalog/view/theme/default/template/extension/payment/lemonway_sofort.twig diff --git a/lemonway.ocmod/upload/admin/controller/extension/payment/lemonway.php b/lemonway.ocmod/upload/admin/controller/extension/payment/lemonway.php index cf85996..07e7174 100644 --- a/lemonway.ocmod/upload/admin/controller/extension/payment/lemonway.php +++ b/lemonway.ocmod/upload/admin/controller/extension/payment/lemonway.php @@ -15,7 +15,7 @@ class ControllerExtensionPaymentLemonway extends Controller private $variables = array(); public function index() - { + { // Load settings $this->load->model('setting/setting'); @@ -45,6 +45,7 @@ public function index() $this->variables['lemonway_environment_name'] = $this->model_setting_setting->getSettingValue($this->prefix() . 'lemonway_environment_name'); $this->variables['lemonway_custom_wallet'] = $this->model_setting_setting->getSettingValue($this->prefix() . 'lemonway_custom_wallet'); $this->variables['lemonway_status'] = $this->model_setting_setting->getSettingValue($this->prefix() . 'lemonway_status'); + $this->variables['lemonway_sofort_status'] = $this->model_setting_setting->getSettingValue($this->prefix() . 'lemonway_sofort_status'); $this->variables['lemonway_oneclick_enabled'] = $this->model_setting_setting->getSettingValue($this->prefix() . 'lemonway_oneclick_enabled'); $this->variables['lemonway_template_name'] = $this->model_setting_setting->getSettingValue($this->prefix() . 'lemonway_template_name'); @@ -63,6 +64,15 @@ public function index() } else { // If no method enabled $this->variables['no_method'] = true; } + + if ($this->variables['lemonway_sofort_status']) { // If enabled + // Test the config + if ($this->testConfig()) { + $this->variables['success'] = true; + } + } else { // If no method enabled + $this->variables['no_method'] = true; + } // Load tabs // About us $this->variables['about_us'] = $this->load->view('extension/payment/lemonway_aboutus', $this->variables); @@ -70,12 +80,16 @@ public function index() $this->variables['config'] = $this->load->view('extension/payment/lemonway_config', $this->variables); // Credit Card $this->variables['cc'] = $this->load->view('extension/payment/lemonway_cc', $this->variables); + // Sofort + $this->variables['sofort'] = $this->load->view('extension/payment/lemonway_sofort', $this->variables); + $this->response->setOutput($this->load->view('extension/payment/lemonway', $this->variables)); } - private function prefix() { - return (version_compare(VERSION, '3.0', '>=')) ? 'payment_' : ''; + private function prefix() + { + return (version_compare(VERSION, '3.0', '>=')) ? 'payment_' : ''; } private function validate() @@ -110,7 +124,7 @@ private function validate() // If custom environment $env_name = $this->request->post['lemonway_environment_name']; } - + // Generate API links $this->request->post['lemonway_directkit_url'] = sprintf(self::LEMONWAY_DIRECTKIT_FORMAT_URL_PROD, $env_name); $this->request->post['lemonway_webkit_url'] = sprintf(self::LEMONWAY_WEBKIT_FORMAT_URL_PROD, $env_name); @@ -121,7 +135,13 @@ private function validate() if (!isset($this->request->post['lemonway_status'])) { $this->request->post['lemonway_status'] = 0; } - + + //Sofort status + if (!isset($this->request->post['lemonway_sofort_status'])) { + $this->request->post['lemonway_sofort_status'] = 0; + } + + // One-click if (!isset($this->request->post['lemonway_oneclick_enabled'])) { $this->request->post['lemonway_oneclick_enabled'] = 0; @@ -197,6 +217,7 @@ public function install() $this->load->model('setting/setting'); $this->model_setting_setting->editSetting($this->prefix() . 'lemonway', [ $this->prefix() . 'lemonway_status' => 1, + $this->prefix() . 'lemonway_sofort_status' => 1, $this->prefix() . 'lemonway_css_url' => self::CSS_URL_DEFAULT, $this->prefix() . 'lemonway_directkit_url' => sprintf(self::LEMONWAY_DIRECTKIT_FORMAT_URL_PROD, self::LEMONWAY_ENVIRONMENT_DEFAULT), $this->prefix() . 'lemonway_webkit_url' => sprintf(self::LEMONWAY_WEBKIT_FORMAT_URL_PROD, self::LEMONWAY_ENVIRONMENT_DEFAULT), diff --git a/lemonway.ocmod/upload/admin/language/en-gb/extension/payment/lemonway.php b/lemonway.ocmod/upload/admin/language/en-gb/extension/payment/lemonway.php index f4387dd..7688b34 100644 --- a/lemonway.ocmod/upload/admin/language/en-gb/extension/payment/lemonway.php +++ b/lemonway.ocmod/upload/admin/language/en-gb/extension/payment/lemonway.php @@ -38,7 +38,7 @@ $_['text_debug_mode'] = 'Debug Mode'; $_['text_custom_environment'] = 'CUSTOM ENVIRONMENT'; $_['text_environment_name'] = 'Custom environment name'; -$_['text_wallet'] = 'Technical wallet name'; +$_['text_wallet'] = 'Wallet name'; $_['tpl_name'] = 'Template name'; @@ -51,6 +51,8 @@ $_['tab_about_us'] = 'ABOUT US'; $_['tab_config'] = 'CONFIGURATION'; $_['tab_cc'] = 'CREDIT CARD'; +$_['tab_sofort'] = 'SOFORT'; + // Error $_['error_permission'] = 'You do not have permission to modify the configuration!'; diff --git a/lemonway.ocmod/upload/admin/view/template/extension/payment/lemonway_cc.twig b/lemonway.ocmod/upload/admin/view/template/extension/payment/lemonway_cc.twig index 6dc18d8..673e209 100644 --- a/lemonway.ocmod/upload/admin/view/template/extension/payment/lemonway_cc.twig +++ b/lemonway.ocmod/upload/admin/view/template/extension/payment/lemonway_cc.twig @@ -11,19 +11,21 @@
- +
- +
- +

- {{ text_help_oneclick }} + {{ text_help_oneclick }}

diff --git a/lemonway.ocmod/upload/admin/view/template/extension/payment/lemonway_sofort.twig b/lemonway.ocmod/upload/admin/view/template/extension/payment/lemonway_sofort.twig new file mode 100644 index 0000000..895e62f --- /dev/null +++ b/lemonway.ocmod/upload/admin/view/template/extension/payment/lemonway_sofort.twig @@ -0,0 +1,18 @@ +
+
+ + {{ text_method_config }} +
+ +
+
+ + +
+ +
+
+
+
\ No newline at end of file diff --git a/lemonway.ocmod/upload/catalog/controller/extension/payment/lemonway.php b/lemonway.ocmod/upload/catalog/controller/extension/payment/lemonway.php index a86e0f6..286e9e6 100644 --- a/lemonway.ocmod/upload/catalog/controller/extension/payment/lemonway.php +++ b/lemonway.ocmod/upload/catalog/controller/extension/payment/lemonway.php @@ -275,6 +275,7 @@ public function checkout() $params['cancelUrl'] = $this->url->link('extension/payment/lemonway/checkoutReturn&' . $cancelParams, '', true); $params['errorUrl'] = $this->url->link('extension/payment/lemonway/checkoutReturn&' . $errorParams, '', true); + // Money In $res = $lemonwayService->moneyInWebInit($params); @@ -298,9 +299,9 @@ public function checkout() } $moneyInToken = (string)$res->MONEYINWEB->TOKEN; +// $moneyInToken = (string)$res->SOFORTINIT->ID; $lang = substr($this->language->get('code'), 0, 2); $lang = array_key_exists($lang, $this->supportedLangs) ? $this->supportedLangs[$lang] : self::DEFAULT_LANG; -// . '&tpl=' . urlencode($config['tplName']) $lwUrl = $config['wkURL'] . '?moneyintoken=' . $moneyInToken . '&p=' . urlencode($config['cssURL']) . '&lang=' . $lang . '&tpl=' . urlencode($config['tplName']); $this->response->redirect($lwUrl); diff --git a/lemonway.ocmod/upload/catalog/controller/extension/payment/lemonway_sofort.php b/lemonway.ocmod/upload/catalog/controller/extension/payment/lemonway_sofort.php new file mode 100644 index 0000000..68768e9 --- /dev/null +++ b/lemonway.ocmod/upload/catalog/controller/extension/payment/lemonway_sofort.php @@ -0,0 +1,344 @@ + 'da', // Danish + 'de' => 'ge', // German + 'en' => 'en', // English + 'es' => 'sp', // Spanish + 'fi' => 'fi', // Finnish + 'fr' => 'fr', // French + 'it' => 'it', // Italian + 'ko' => 'ko', // Korean + 'no' => 'no', // Norwegian + 'pt' => 'po', // Portuguese + 'sv' => 'sw' // Swedish + ); + const DEFAULT_LANG = 'en'; + + private function prefix() + { + return (version_compare(VERSION, '3.0', '>=')) ? 'payment_' : ''; + } + + /* + Check if there are GET params + */ + private function isGet() + { + return (strtoupper($this->request->server['REQUEST_METHOD']) == 'GET'); + } + + /* + Get GET param with $key + */ + private function getValue($key) + { + return (isset($this->request->get[$key]) ? $this->request->get[$key] : null); + } + + /* + Check if there are POST params + */ + private function isPost() + { + return (strtoupper($this->request->server['REQUEST_METHOD']) == 'POST'); + } + + /* + Get POST param with $key + */ + private function postValue($key) + { + return (isset($this->request->post[$key]) ? $this->request->post[$key] : null); + } + + /* + Get the config + */ + private function getLemonWayConfig() + { + $config = array(); + + if ($this->config->get($this->prefix() . 'lemonway_is_test_mode')) { + // TEST + $config['dkURL'] = $this->config->get($this->prefix() . 'lemonway_directkit_url_test'); //DIRECT KIT URL TEST + $config['wkURL'] = $this->config->get($this->prefix() . 'lemonway_webkit_url_test'); //WEB KIT URL TEST + } else { + // PROD + $config['dkURL'] = $this->config->get($this->prefix() . 'lemonway_directkit_url'); // DIRECT KIT URL PROD + $config['wkURL'] = $this->config->get($this->prefix() . 'lemonway_webkit_url'); // WEBKIT URL PROD + } + + $config['login'] = $this->config->get($this->prefix() . 'lemonway_api_login'); + $config['pass'] = $this->config->get($this->prefix() . 'lemonway_api_password'); + $config['wallet'] = empty($this->config->get($this->prefix() . 'lemonway_environment_name')) ? $this->config->get($this->prefix() . 'lemonway_wallet') : $this->config->get($this->prefix() . 'lemonway_custom_wallet'); + $config['cssURL'] = $this->config->get($this->prefix() . 'lemonway_css_url'); + + $config['autoCommission'] = (int)!empty($this->config->get($this->prefix() . 'lemonway_environment_name')); + // Autocom = 0 if lwecommerce, 1 if custom environment + + return $config; + } + + /* + Check the real paid amount + */ + private function checkAmount($amount, $realAmount) + { + return ($amount == $realAmount); + } + + /* + Call the API with a wkToken to check the details of a payment + */ + private function getMoneyInTransDetails($wkToken) + { + if (is_null($this->money_in_trans_details)) { + // Call API to get transaction detail for this wkToken + $config = $this->getLemonWayConfig(); + + $lemonwayService = new LemonWayService( + $config['dkURL'], + $config['login'], + $config['pass'], + substr($this->language->get('code'), 0, 2), + $this->config->get($this->prefix() . 'lemonway_debug') + ); + + $params = array( + 'transactionMerchantToken' => $wkToken + ); + $res = $lemonwayService->getMoneyInTransDetails($params); + + $this->money_in_trans_details = $res; + } + + return $this->money_in_trans_details; + } + + /* + Double check + */ + private function doublecheckAmount($amount, $wkToken) + { + $details = $this->getMoneyInTransDetails($wkToken); + + // CREDIT + COMMISSION + $realAmountDoublecheck = $details->TRANS->HPAY[0]->CRED + $details->TRANS->HPAY[0]->COM; + + // Status 3 means success + return (($details->TRANS->HPAY[0]->STATUS == '3') && ($amount == $realAmountDoublecheck)); + } + + /* + Retrieve and update saved card info + */ + private function updateSavedCardInfo($customerId, $wkToken) + { + $card = $this->model_extension_payment_lemonway->getCustomerCard($customerId); + if (!$card) { + $card = array(); + } + + $card['customer_id'] = $customerId; + $details = $this->getMoneyInTransDetails($wkToken); + $card['card_num'] = $details->TRANS->HPAY[0]->EXTRA->NUM; + $card['card_type'] = $details->TRANS->HPAY[0]->EXTRA->TYP; + $card['card_exp'] = $details->TRANS->HPAY[0]->EXTRA->EXP; + + $this->model_extension_payment_lemonway->insertOrUpdateCard($card); + } + + /* + The view in the checkout page with the card choosing. + By clicking on "Continue" a payment will be created in checkout() + */ + public function index() + { + // Load language + $data = $this->load->language('extension/payment/lemonway'); + + // Load Model + $this->load->model('extension/payment/lemonway_sofort'); + + $data['link_checkout'] = $this->url->link('extension/payment/lemonway_sofort/checkout', '', true); + $data['lemonway_is_test_mode'] = $this->config->get($this->prefix() . 'lemonway_is_test_mode'); + $data['lemonway_oneclick_enabled'] = $this->config->get($this->prefix() . 'lemonway_oneclick_enabled'); + $data['customerId'] = empty($this->customer->getId()) ? 0 : $this->customer->getId(); + + return $this->load->view('extension/payment/lemonway_sofort', $data); + } + + /* + A payment is created here, the user is redirected to the payment page. + After putting the card information, the user will be redirected to checkoutReturn() + */ + public function checkout() + { + + //Load Language + $this->load->language('extension/payment/lemonway'); + + // Load Model + $this->load->model('extension/payment/lemonway_sofort'); + $this->load->model('checkout/order'); + + // Order info + $order_id = $this->session->data['order_id']; + $order_info = $this->model_checkout_order->getOrder($order_id); + + if (!$order_info) { + // Redirect to the cart and display error + $this->session->data['error'] = $this->language->get('error_order_not_found'); + $this->response->redirect($this->url->link('checkout/cart', '', true)); + } + + // Lemon Way config + $config = $this->getLemonWayConfig(); + + $lemonwayService = new LemonWayService( + $config['dkURL'], + $config['login'], + $config['pass'], + substr($this->language->get('code'), 0, 2), + $this->config->get($this->prefix() . 'lemonway_debug') + ); + + $params = array(); + + $params['wallet'] = $config['wallet']; + $total = number_format((float)$order_info['total'], 2, '.', ''); + $params['amountTot'] = $total; + $params['comment'] = $this->config->get('config_name') . " - " . $order_id . " - " . + $this->customer->getLastName() . " " . $this->customer->getFirstName() . " - " . + $this->customer->getEmail(); + $params['autoCommission'] = $config['autoCommission']; + + $customerId = empty($this->customer->getId()) ? 0 : $this->customer->getId(); // A guest customer has no Id, we consider it 0 + + $useCard = ( + $this->config->get($this->prefix() . 'lemonway_oneclick_enabled') && + $customerId && + $this->postValue('lemonway_oneclick') === 'use_card' + ); + + if (!$useCard) {// If the client use a new card => MoneyInWebInit + // Whether the client save a card + $registerCard = (int)( + $this->config->get($this->prefix() . 'lemonway_oneclick_enabled') && + $customerId && + $this->postValue('lemonway_oneclick') === 'register_card' + ); + $params['registerCard'] = $registerCard; + + // Associate order id with a wkToken + $wkToken = $this->model_extension_payment_lemonway_sofort->saveWkToken($order_id, $registerCard); + $params['wkToken'] = $wkToken; + + // GET Params + // returnUrl + $returnParams = array( + 'action' => 'return' + ); + $returnParams = http_build_query($returnParams); + + $params['returnUrl'] = $this->url->link('extension/payment/lemonway_sofort/checkoutReturn&' . $returnParams, '', true); + $res = $lemonwayService->moneyInSofortInit($params); + + // Error + if (isset($res->E)) { + // Redirect to the cart and display error + $this->session->data['error'] = $lemonwayService->printError($res->E); + $this->response->redirect($this->url->link('checkout/cart', '', true)); + } + $this->response->redirect(utf8_decode(urldecode($res->SOFORTINIT->actionUrl))); + } + } + + + /* + This page receive the response of Lemon Way about the payment then redirect the user to the appropriate order page + (success, failure or back to checkout) + */ + public function checkoutReturn() + { + //Load Language + $this->load->language('extension/payment/lemonway'); + + //Load Model + $this->load->model('extension/payment/lemonway_sofort'); + $this->load->model('checkout/order'); + + if ($this->isGet()) { // If redirection + // GET params + if ($this->config->get($this->prefix() . 'lemonway_debug')) { + $debug_log = new Log('lemonway_debug.log'); + $debug_log->write('GET params: ' . print_r($this->request->get, true)); + } + + $wkToken = $this->getValue('response_wkToken'); + $action = $this->getValue('action'); + + + if (!isset($wkToken)) { + // Redirect to the cart and display error + $this->session->data['error'] = $this->language->get('error_get'); + $this->response->redirect($this->url->link('checkout/cart', '', true)); + } + + // Get order info + $order_id = $this->model_extension_payment_lemonway_sofort->getOrderIdFromToken($wkToken); + $order_info = $this->model_checkout_order->getOrder($order_id); + + if (!$order_info) { + // Redirect to the cart and display error + $this->session->data['error'] = $this->language->get('error_order_not_found'); + $this->response->redirect($this->url->link('checkout/cart', '', true)); + } + $total = number_format((float)$order_info['total'], 2, '.', ''); + + switch ($action) { + case 'return': + // Success => Order status 5 : Complete + $this->model_checkout_order->addOrderHistory($order_id, 5); + $customerId = $order_info['customer_id']; + $this->response->redirect($this->url->link('checkout/success', '', true)); + + default: + $this->session->data['error'] = $this->language->get('error_action'); + $this->response->redirect($this->url->link('checkout/cart', '', true)); + } + } elseif ($this->isPost()) { // If IPN + // Get response by IPN + if ($this->config->get($this->prefix() . 'lemonway_debug')) { + $debug_log = new Log('lemonway_debug.log'); + $debug_log->write('IPN: ' . print_r($this->request->post, true)); + } + + $response_code = $this->postValue('response_code'); + $wkToken = $this->postValue('response_wkToken'); + $realAmount = $this->postValue('response_transactionAmount'); + + // Get order info + $order_id = $this->model_extension_payment_lemonway_sofort->getOrderIdFromToken($wkToken); + $order_info = $this->model_checkout_order->getOrder($order_id); + $total = number_format((float)$order_info['total'], 2, '.', ''); + + if (($response_code == "0000") && $this->checkAmount($total, $realAmount) && $this->doublecheckAmount($total, $wkToken)) { + // Success => Order status 5 : Complete + $this->model_checkout_order->addOrderHistory($order_id, 5); + } else { + // Error => Order status 10 : Failed + $this->model_checkout_order->addOrderHistory($order_id, 10); + } + } else { + // Redirect to the cart and display error + $this->session->data['error'] = $this->language->get('error_param'); + $this->response->redirect($this->url->link('checkout/cart', '', true)); + } + } +} diff --git a/lemonway.ocmod/upload/catalog/language/en-gb/extension/payment/lemonway.php b/lemonway.ocmod/upload/catalog/language/en-gb/extension/payment/lemonway.php index d13c78d..9013907 100644 --- a/lemonway.ocmod/upload/catalog/language/en-gb/extension/payment/lemonway.php +++ b/lemonway.ocmod/upload/catalog/language/en-gb/extension/payment/lemonway.php @@ -2,6 +2,7 @@ // Text $_['text_redirect'] = 'You will be redirected to payment page in a few seconds'; $_['text_card'] = 'Credit Card'; +$_['text_sofort'] = 'Sofort Card'; $_['text_use_card'] = 'Use my saved card'; $_['text_save_new_card'] = 'Save new card data'; $_['text_not_use_card'] = 'Not use saved card data'; diff --git a/lemonway.ocmod/upload/catalog/model/extension/payment/lemonway.php b/lemonway.ocmod/upload/catalog/model/extension/payment/lemonway.php index 9545ede..6358c19 100644 --- a/lemonway.ocmod/upload/catalog/model/extension/payment/lemonway.php +++ b/lemonway.ocmod/upload/catalog/model/extension/payment/lemonway.php @@ -90,6 +90,7 @@ private function checkIfOrderHasWkToken($order_id) FROM `" . DB_PREFIX . "lemonway_wktoken` lw WHERE lw.`order_id` = " . (int)$this->db->escape($order_id) )->num_rows; + } /* diff --git a/lemonway.ocmod/upload/catalog/model/extension/payment/lemonway_sofort.php b/lemonway.ocmod/upload/catalog/model/extension/payment/lemonway_sofort.php new file mode 100644 index 0000000..b222434 --- /dev/null +++ b/lemonway.ocmod/upload/catalog/model/extension/payment/lemonway_sofort.php @@ -0,0 +1,117 @@ +=')) ? 'payment_' : ''; + } + + /* + This function is required for OpenCart to show the method in the checkout page + */ + public function getMethod($address, $total) + { + $this->load->language('extension/payment/lemonway'); + + $mode = $this->config->get($this->prefix() . 'lemonway_is_test_mode') ? " (Test)" : ""; + + $method_data = array( + 'code' => 'lemonway_sofort', + 'title' => $this->language->get('text_sofort') . $mode, + 'terms' => '', + 'sort_order' => '' /*TODO: $this->config->get($this->prefix() . 'lemonway_cc_sort_order')*/ + ); + + return $method_data; + } + + + + /* + Private function to generate a random wkToken + */ + private function generateUniqueToken($order_id) + { + return $order_id . "-" . time() . "-" . uniqid(); + } + + /* + Check if this order has a wkToken + */ + private function checkIfOrderHasWkToken($order_id) + { + return (bool)$this->db->query( + "SELECT `wktoken` + FROM `" . DB_PREFIX . "lemonway_wktoken` lw + WHERE lw.`order_id` = " . (int)$this->db->escape($order_id) + )->num_rows; + } + + /* + Associate a random wkToken for an order + */ + public function saveWkToken($order_id, $registerCard) + { + $wkToken = $this->generateUniqueToken($order_id); + + // Whether the order has a wkToken + if ($this->checkIfOrderHasWkToken($order_id)) { + $query = "UPDATE `" . DB_PREFIX . "lemonway_wktoken` SET + `wktoken` = '" . $this->db->escape($wkToken) . "', + `register_card` = " . (int)$this->db->escape($registerCard) . " + WHERE `order_id` = " . (int)$this->db->escape($order_id); + } else { + $query = "INSERT INTO `" . DB_PREFIX . "lemonway_wktoken` (`order_id`, `wktoken`, `register_card`) + VALUES ( + " . (int)$this->db->escape($order_id) . ", + '" . $this->db->escape($wkToken) . "', + " . (int)$this->db->escape($registerCard) . " + )"; + } + + $this->db->query($query); + + return $wkToken; + } + +// /* +// Get the saved card of a customer +// */ +// public function getCustomerCard($customerId) +// { +// var_dump($customerId); +// return $this->db->query( +// "SELECT * +// FROM `" . DB_PREFIX . "lemonway_oneclick` lo +// WHERE lo.`customer_id` = " . (int)$this->db->escape($customerId) +// )->row; +// } + + /* + Get the order ID by its unique wkToken + */ + public function getOrderIdFromToken($wkToken) + { + $order_id = $this->db->query( + "SELECT `order_id` + FROM `" . DB_PREFIX . "lemonway_wktoken` lw + WHERE lw.`wktoken` = '" . $this->db->escape($wkToken) . "'" + )->row['order_id']; +// var_dump($wkToken); + + return $order_id; + } + + /* + Check if the user has chosen to save a card for this order by using the wkToken + */ + public function getRegisterCardFromToken($wkToken) + { + $registerCard = $this->db->query( + "SELECT `register_card` + FROM `" . DB_PREFIX . "lemonway_wktoken` lw + WHERE lw.`wktoken` = '" . $this->db->escape($wkToken) . "'" + )->row['register_card']; + + return (bool)$registerCard; + } +} diff --git a/lemonway.ocmod/upload/catalog/view/theme/default/template/extension/payment/lemonway.twig b/lemonway.ocmod/upload/catalog/view/theme/default/template/extension/payment/lemonway.twig index 5422cae..b852366 100644 --- a/lemonway.ocmod/upload/catalog/view/theme/default/template/extension/payment/lemonway.twig +++ b/lemonway.ocmod/upload/catalog/view/theme/default/template/extension/payment/lemonway.twig @@ -1,77 +1,84 @@
{% if lemonway_is_test_mode %} -
{{ error_test_mode }} - -
+
{{ error_test_mode }} + +
{% endif %} - -

- {{ text_card }} {{ (lemonway_is_test_mode) ? "(Test)" : "" }} -

+ +

+ {{ text_card }} {{ (lemonway_is_test_mode) ? "(Test)" : "" }} +

+ +
- {% if lemonway_oneclick_enabled and customerId %} {# Hide One-click form from guest #} - {% if card %} {# User already have a saved card. He can choose to use it or not #} -
-
- -
-
- -
-
- -
-
+ {% if lemonway_oneclick_enabled and customerId %} Hide One-click form from guest + {% if card %} User already have a saved card. He can choose to use it or not +
+
+ +
+ +
+ +
+ +
+ +
+ +
{% endif %} {% endif %} - {##} - {##} + + {#
#} - {#
#} - {#
#} - {##} - {#
#} - {#
#} - {##} - {#
#} - {#
#} - {##} - {#
#} - {#
#} + {#
#} + {#
#} + {##} + {#
#} + {#
#} + {##} + {#
#} + {#
#} + {##} + {#
#} + {#
#} {#
#}
- {% if lemonway_oneclick_enabled and customerId %} {# Hide One-click form from guest #} - {% if not card %} {# If no saved card => Ask to save the card #} - - + {% if lemonway_oneclick_enabled and customerId %} Hide One-click form from guest + {% if not card %} If no saved card => Ask to save the card + + {% endif %} {% endif %} -
@@ -81,18 +88,15 @@
+ \ No newline at end of file diff --git a/lemonway.ocmod/upload/catalog/view/theme/default/template/extension/payment/lemonway_sofort.twig b/lemonway.ocmod/upload/catalog/view/theme/default/template/extension/payment/lemonway_sofort.twig new file mode 100644 index 0000000..3dc851f --- /dev/null +++ b/lemonway.ocmod/upload/catalog/view/theme/default/template/extension/payment/lemonway_sofort.twig @@ -0,0 +1,102 @@ +
+ {% if lemonway_is_test_mode %} +
{{ error_test_mode }} + +
+ {% endif %} + +

+ {{ text_sofort }} {{ (lemonway_is_test_mode) ? "(Test)" : "" }} +

+ + +
+ + {% if lemonway_oneclick_enabled and customerId %} Hide One-click form from guest + {% if card %} User already have a saved card. He can choose to use it or not +
+
+ +
+ +
+ +
+ +
+ +
+ +
+ {% endif %} + {% endif %} + + + + {#
#} + {#
#} + {#
#} + {##} + {#
#} + {#
#} + {##} + {#
#} + {#
#} + {##} + {#
#} + {#
#} + {#
#} + +
+
+ {% if lemonway_oneclick_enabled and customerId %} Hide One-click form from guest + {% if not card %} If no saved card => Ask to save the card + + + {% endif %} + {% endif %} + +
+
+ +
+
+ + \ No newline at end of file diff --git a/lemonway.ocmod/upload/system/library/lemonway/LemonWayService.php b/lemonway.ocmod/upload/system/library/lemonway/LemonWayService.php index b6958d8..71365ad 100644 --- a/lemonway.ocmod/upload/system/library/lemonway/LemonWayService.php +++ b/lemonway.ocmod/upload/system/library/lemonway/LemonWayService.php @@ -1,6 +1,7 @@ dkUrl = $dkurl; $this->wlLogin = $wlLogin; @@ -37,11 +38,12 @@ public function __construct ($dkurl, $wlLogin, $wlPass, $lang = self::DEFAULT_LA } } - private function logRequest($serviceUrl, $request) { + private function logRequest($serviceUrl, $request) + { $this->debug_log->write('Service URL: ' . $serviceUrl); $request_debug = json_decode($request)->p; - unset($request_debug->wlPass); // Mask Password + //unset($request_debug->wlPass); // Mask Password $this->debug_log->write('Request: ' . json_encode($request_debug, JSON_PRETTY_PRINT)); } @@ -96,7 +98,6 @@ private function sendRequest($methodName, $params) curl_setopt($ch, CURLOPT_POSTFIELDS, $request); curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); curl_setopt($ch, CURLOPT_CAINFO, DIR_SYSTEM . "/library/lemonway/cacert.pem"); - $response = curl_exec($ch); if (curl_errno($ch)) { // Curl Error @@ -125,7 +126,7 @@ private function sendRequest($methodName, $params) $this->debug_log->write($error->E->Msg); $this->logRequest($serviceUrl, $request); } - + return $error; } else { // Success if ($this->isLogEnabled) { @@ -137,7 +138,8 @@ private function sendRequest($methodName, $params) } } - public function printError($e) { + public function printError($e) + { $str = !empty($e->Code) ? $e->Code . ": " : ""; $str .= $e->Msg; $str .= !empty($e->Error) ? " (" . $e->Error . ")" : ""; @@ -155,6 +157,11 @@ public function moneyInWebInit($params) return self::sendRequest('MoneyInWebInit', $params); } + public function moneyInSofortInit($params) + { + return self::sendRequest('MoneyInSofortInit', $params); + } + public function moneyInWithCardId($params) { return self::sendRequest('MoneyInWithCardId', $params);