Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add sofort card title #14

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand Down Expand Up @@ -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)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 ';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
<span class="input-group-addon">
<i class="fa fa-user"></i>
</span>
<input type="text" name="lemonway_api_login" value="{{ lemonway_api_login }}" class="form-control" required />
<input type="text" name="lemonway_api_login" value="{{ lemonway_api_login }}"
class="form-control" required/>
</div>
<p class="help-block">
{{ text_help_login }}
Expand All @@ -34,7 +35,8 @@
<span class="input-group-addon">
<i class="fa fa-lock"></i>
</span>
<input type="password" name="lemonway_api_password" class="form-control" {{ (lemonway_api_password is empty) ? "required" : "placeholder='#{text_masked}'" }} />
<input type="password" name="lemonway_api_password"
class="form-control" {{ (lemonway_api_password is empty) ? "required" : "placeholder='#{text_masked}'" }} />
</div>
<p class="help-block">
{{ text_help_password }}
Expand All @@ -44,11 +46,12 @@

<div class="form-group">
<label class="control-label col-lg-3">
{{ text_test_mode }}
{{ text_test_mode }}
</label>

<div class="col-lg-7">
<input type="checkbox" name="lemonway_is_test_mode" value="1" {{ lemonway_is_test_mode ? 'checked' : '' }} />
<input type="checkbox" name="lemonway_is_test_mode"
value="1" {{ lemonway_is_test_mode ? 'checked' : '' }} />
<p class="help-block">
{{ text_help_test_mode }}
</p>
Expand Down Expand Up @@ -76,7 +79,7 @@
<span class="input-group-addon">
<i class="fa fa-css3"></i>
</span>
<input type="text" name="lemonway_css_url" class="form-control" value="{{ lemonway_css_url }}" />
<input type="text" name="lemonway_css_url" class="form-control" value="{{ lemonway_css_url }}"/>
</div>
<p class="help-block">
{{ text_help_css }}
Expand Down Expand Up @@ -109,19 +112,20 @@
<i class="fa fa-wrench"></i> {{ text_custom_environment }}
</div>
<div class="alert alert-warning"><i class="fa fa-exclamation-triangle"></i> {{ error_custom_env }}</div>

<!-- Custom environment name -->
<div class="form-group">
<label class="control-label col-lg-3">
{{ text_environment_name }}
{{ text_environment_name }}
</label>

<div class="col-lg-7">
<div class="input-group">
<span class="input-group-addon">
<i class="fa fa-leaf"></i>
</span>
<input type="text" name="lemonway_environment_name" value="{{ lemonway_environment_name }}" class="form-control" />
<input type="text" name="lemonway_environment_name" value="{{ lemonway_environment_name }}"
class="form-control"/>
</div>
</div>
</div>
Expand All @@ -138,12 +142,31 @@
<span class="input-group-addon">
<i class="fa fa-google-wallet"></i>
</span>
<input type="hidden" name="lemonway_wallet" />
<input type="text" name="lemonway_custom_wallet" value="{{ lemonway_custom_wallet }}" class="form-control" />
<input type="hidden" name="lemonway_wallet"/>
<input type="text" name="lemonway_custom_wallet" value="{{ lemonway_custom_wallet }}"
class="form-control"/>
</div>
</div>
</div>
<!-- End Wallet ID -->

<!-- Template name Atos v2-->
<div class="form-group">
<label class="control-label col-lg-3">
{{ tpl_name }}
</label>

<div class="col-lg-7">
<div class="input-group">
<span class="input-group-addon">
<i class="fa fa fa-file-archive-o"></i>
</span>
<input type="hidden" name="lemonway_template"/>
<input type="text" name="lemonway_template_name" value="{{ lemonway_template_name }}"
class="form-control"/>
</div>
</div>
</div>
</div>
<!-- End Custom environment panel -->
</div>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -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_' : '';
}

/*
Expand Down Expand Up @@ -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
Expand All @@ -76,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

Expand Down Expand Up @@ -116,19 +118,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));
}
Expand Down Expand Up @@ -170,7 +174,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);
Expand All @@ -182,18 +186,12 @@ 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');
Expand All @@ -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();

Expand All @@ -224,19 +222,19 @@ 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'];

$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'
);
Expand Down Expand Up @@ -302,54 +300,10 @@ 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;
// . '&tpl=' . urlencode($config['tplName'])
$lwUrl = $config['wkURL'] . '?moneyintoken=' . $moneyInToken . '&p=' . urlencode($config['cssURL']) . '&lang=' . $lang . '&tpl=' . urlencode($config['tplName']);
$this->response->redirect($lwUrl);

$lwUrl = $config['wkURL'] . '?moneyintoken=' . $moneyInToken . '&p=' . urlencode($config['cssURL']) . '&lang=' . $lang;

$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 = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">' . "\n";
$html .= '<html>' . "\n";
$html .= ' <head>' . "\n";
$html .= ' </head>';
$html .= ' <body>';
$html .= ' <div align="center"><br />' . $text_redirect . '</div>' . "\n";
$html .= ' <div id="buttons" style="display: none;">' . "\n";
$html .= ' <form id="lemonway_payment_redirect" action="' . $actionUrl . '" method="post">' . "\n";
$html .= ' <input type="hidden" name="' . $cc_type . '_x" value="1" />' . "\n";
$html .= ' <input type="hidden" name="' . $cc_type . '_y" value="1" />' . "\n";
$html .= ' <input type="hidden" name="DATA" value="' . $data . '" />' . "\n";
$html .= ' </form>' . "\n";
$html .= ' </div>' . "\n";
$html .= ' <script type="text/javascript">document.getElementById("lemonway_payment_redirect").submit();</script>' . "\n";
$html .= ' </body>' . "\n";
$html .= '</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
Expand Down Expand Up @@ -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');
Expand Down Expand Up @@ -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');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading