Skip to content

Commit

Permalink
Amazon - minimum order total bug
Browse files Browse the repository at this point in the history
  • Loading branch information
chris-wm committed Apr 3, 2015
1 parent 6b3e3a6 commit 6e1de66
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 14 deletions.
15 changes: 9 additions & 6 deletions upload/catalog/controller/module/amazon_pay.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
<?php
class ControllerModuleAmazonPay extends Controller {

public function index() {

$this->load->model('payment/amazon_login_pay');

if ($this->config->get('amazon_login_pay_status') && $this->config->get('amazon_pay_status') && !empty($this->request->server['HTTPS'])) {
if (!$this->customer->isLogged() && isset($this->request->cookie['amazon_login_state_cache'])) {
setcookie('amazon_login_state_cache', '', time() - 4815162342);
if ($this->config->get('amazon_login_pay_status') && $this->config->get('amazon_pay_status') && !empty($_SERVER['HTTPS']) && !($this->config->get('amazon_login_pay_minimum_total') > 0 && $this->config->get('amazon_login_pay_minimum_total') > $this->cart->getTotal())) {
if (!$this->customer->isLogged() && isset($this->request->cookie['amazon_Login_state_cache'])) {
setcookie('amazon_Login_state_cache', '', time() - 4815162342);
}

$amazon_payment_js = $this->model_payment_amazon_login_pay->getWidgetJs();
Expand Down Expand Up @@ -113,6 +114,7 @@ public function login() {
$last_name = array_pop($full_name);
$first_name = implode(' ', $full_name);


$data = array(
'customer_group_id' => (int)$this->config->get('config_customer_group_id'),
'firstname' => $first_name,
Expand Down Expand Up @@ -174,8 +176,8 @@ public function logout() {
unset($this->session->data['lpa']);
unset($this->session->data['access_token']);

if (isset($this->request->cookie['amazon_login_state_cache'])) {
setcookie('amazon_login_state_cache', '', time() - 4815162342);
if (isset($this->request->cookie['amazon_Login_state_cache'])) {
setcookie('amazon_Login_state_cache', '', time() - 4815162342);
}
}

Expand All @@ -196,4 +198,5 @@ protected function validate($email) {
return false;
}
}
}

}
31 changes: 23 additions & 8 deletions upload/catalog/controller/payment/amazon_login_pay.php
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
<?php

class ControllerPaymentAmazonLoginPay extends Controller {

public function address() {
$this->load->language('payment/amazon_login_pay');
$this->document->setTitle($this->language->get('heading_title'));

$this->load->model('payment/amazon_login_pay');

if (!$this->customer->isLogged() || !isset($this->request->cookie['amazon_login_state_cache'])) {
if (!$this->customer->isLogged() || !isset($this->request->cookie['amazon_Login_state_cache'])) {
$this->session->data['lpa']['error'] = $this->language->get('error_login');
$this->response->redirect($this->url->link('payment/amazon_login_pay/failure', '', 'SSL'));
}

if ($this->config->get('amazon_login_pay_minimum_total') > 0 && $this->config->get('amazon_login_pay_minimum_total') > $this->cart->getTotal()) {
$this->failure(sprintf($this->language->get('error_minimum'), $this->currency->format($this->config->get('amazon_login_pay_minimum_total'))));
}

$data['heading_title'] = $this->language->get('heading_title');
$data['heading_address'] = $this->language->get('heading_address');
$data['text_back'] = $this->language->get('text_back');
Expand All @@ -30,6 +36,7 @@ public function address() {
$data['cart'] = $this->url->link('checkout/cart');
$data['text_cart'] = $this->language->get('text_cart');


$data['amazon_login_pay_merchant_id'] = $this->config->get('amazon_login_pay_merchant_id');
$data['amazon_login_pay_client_id'] = $this->config->get('amazon_login_pay_client_id');
$data['amazon_login_pay_client_secret'] = $this->config->get('amazon_login_pay_client_secret');
Expand Down Expand Up @@ -60,11 +67,15 @@ public function paymentMethod() {

$this->load->model('payment/amazon_login_pay');

if (!$this->customer->isLogged() || !isset($this->request->cookie['amazon_login_state_cache'])) {
if (!$this->customer->isLogged() || !isset($this->request->cookie['amazon_Login_state_cache'])) {
$this->session->data['lpa']['error'] = $this->language->get('error_login');
$this->response->redirect($this->url->link('payment/amazon_login_pay/failure', '', 'SSL'));
}

if ($this->config->get('amazon_login_pay_minimum_total') > 0 && $this->config->get('amazon_login_pay_minimum_total') > $this->cart->getTotal()) {
$this->failure(sprintf($this->language->get('error_minimum'), $this->currency->format($this->config->get('amazon_login_pay_minimum_total'))));
}

$data['heading_title'] = $this->language->get('heading_title');
$data['heading_payment'] = $this->language->get('heading_payment');
$data['text_back'] = $this->language->get('text_back');
Expand Down Expand Up @@ -108,11 +119,15 @@ public function confirm() {
$this->load->model('extension/extension');
$this->load->model('payment/amazon_login_pay');

if (!$this->customer->isLogged() || !isset($this->request->cookie['amazon_login_state_cache'])) {
if (!$this->customer->isLogged() || !isset($this->request->cookie['amazon_Login_state_cache'])) {
$this->session->data['lpa']['error'] = $this->language->get('error_login');
$this->response->redirect($this->url->link('payment/amazon_login_pay/loginFailure', '', 'SSL'));
}

if ($this->config->get('amazon_login_pay_minimum_total') > 0 && $this->config->get('amazon_login_pay_minimum_total') > $this->cart->getTotal()) {
$this->failure(sprintf($this->language->get('error_minimum'), $this->currency->format($this->config->get('amazon_login_pay_minimum_total'))));
}

$data['amazon_login_pay_merchant_id'] = $this->config->get('amazon_login_pay_merchant_id');
$data['amazon_login_pay_client_id'] = $this->config->get('amazon_login_pay_client_id');
if ($this->config->get('amazon_login_pay_test') == 'sandbox') {
Expand All @@ -122,6 +137,7 @@ public function confirm() {
$amazon_payment_js = $this->model_payment_amazon_login_pay->getWidgetJs();
$this->document->addScript($amazon_payment_js);


if (isset($this->session->data['lpa']['AmazonOrderReferenceId'])) {
$data['AmazonOrderReferenceId'] = $this->session->data['lpa']['AmazonOrderReferenceId'];
} else {
Expand Down Expand Up @@ -253,6 +269,7 @@ public function confirm() {
$order_data['telephone'] = $address['telephone'];
$order_data['fax'] = '';


if (isset($this->session->data['coupon'])) {
$this->load->model('checkout/coupon');

Expand Down Expand Up @@ -489,6 +506,7 @@ public function processOrder() {
$this->load->model('account/order');
$this->load->model('payment/amazon_login_pay');


if (!isset($this->session->data['order_id'])) {
$this->response->redirect($this->url->link('common/home'));
}
Expand Down Expand Up @@ -582,10 +600,6 @@ public function failure($error) {
unset($this->session->data['lpa']);
$this->session->data['error'] = $error;
$this->response->redirect($this->url->link('checkout/cart', '', 'SSL'));

unset($this->session->data['lpa']);
$this->session->data['error'] = $this->language->get('error_process_order');
$this->response->redirect($this->url->link('checkout/cart', '', 'SSL'));
}

public function loginFailure() {
Expand Down Expand Up @@ -878,4 +892,5 @@ public function capture($order_id) {
}
}
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,5 @@
$_['error_process_order'] = 'There was an error processing your order. Please contact the shop administrator for help.';
$_['error_login'] = 'Login failed';
$_['error_login_email'] = 'Login failed: %s account email address did not match Amazon account email address';
$_['error_minimum'] = 'Minimum order amount for Login and Pay with Amazon is %s!';

0 comments on commit 6e1de66

Please sign in to comment.