From 166b6d3fa8c7d16705b04ef54ce35706913fa7f2 Mon Sep 17 00:00:00 2001 From: Daniel Camargo Date: Tue, 13 Aug 2013 14:19:28 -0300 Subject: [PATCH 1/2] partial #1381 --- .../crunchbutton/api/restaurant/index.php | 3 ++ include/library/Crunchbutton/Restaurant.php | 1 + .../default/cockpit/restaurants/pay.phtml | 30 ++++++++++++++----- 3 files changed, 27 insertions(+), 7 deletions(-) diff --git a/include/controllers/default/crunchbutton/api/restaurant/index.php b/include/controllers/default/crunchbutton/api/restaurant/index.php index 18a7dd580..1cc7348de 100644 --- a/include/controllers/default/crunchbutton/api/restaurant/index.php +++ b/include/controllers/default/crunchbutton/api/restaurant/index.php @@ -148,6 +148,7 @@ class Controller_api_restaurant extends Crunchbutton_Controller_Rest { if ($r->id_restaurant) { $r->balanced_id = c::config()->balanced->sharedMerchant; $r->save(); + echo json_encode( [ 'success' => 'success' ] ); } break; @@ -155,6 +156,7 @@ class Controller_api_restaurant extends Crunchbutton_Controller_Rest { if ($r->id_restaurant) { $r->balanced_id = null; $r->save(); + echo json_encode( [ 'success' => 'success' ] ); } break; @@ -162,6 +164,7 @@ class Controller_api_restaurant extends Crunchbutton_Controller_Rest { if ($r->id_restaurant) { $r->balanced_bank = null; $r->save(); + echo json_encode( [ 'success' => 'success' ] ); } break; diff --git a/include/library/Crunchbutton/Restaurant.php b/include/library/Crunchbutton/Restaurant.php index 9d2c47068..58b191d49 100644 --- a/include/library/Crunchbutton/Restaurant.php +++ b/include/library/Crunchbutton/Restaurant.php @@ -271,6 +271,7 @@ class Crunchbutton_Restaurant extends Cana_Table_Trackchange { $info = $this->merchant()->addBankAccount($bank); $this->balanced_bank = $bank->id; $this->save(); + echo json_encode( [ 'success' => 'success' ] ); } catch (Exception $e) { print_r($e); exit; diff --git a/include/views/default/cockpit/restaurants/pay.phtml b/include/views/default/cockpit/restaurants/pay.phtml index 3e91daf27..7a03f4597 100644 --- a/include/views/default/cockpit/restaurants/pay.phtml +++ b/include/views/default/cockpit/restaurants/pay.phtml @@ -52,6 +52,7 @@
+     @@ -369,13 +370,28 @@ $('.restaurant-bank-info-button').click(function() { var form = $(this).closest('form'); - $.post('/api/restaurant/restaurant->id_restaurant?>/bankinfo', { - routing: form.find('[name="routing"]').val(), - account: form.find('[name="account"]').val(), - type: form.find('[name="type"]').val(), - name: form.find('[name="name"]').val() - }, function() { - location.href = location.href; + $( '.restaurant-bank-info-button-loading' ).show(); + $.ajax({ + type: 'POST', + url: '/api/restaurant/restaurant->id_restaurant?>/bankinfo', + data: { + routing: form.find('[name="routing"]').val(), + account: form.find('[name="account"]').val(), + type: form.find('[name="type"]').val(), + name: form.find('[name="name"]').val() + } + }).done(function( data ) { + if( data.success ){ + location.href = location.href; + } else { + $( '.restaurant-bank-info-button-loading' ).hide(); + alert( 'Error: see the console!' ); + console.log('Err:', data ); + } + }).fail(function(jqXHR, textStatus) { + $( '.restaurant-bank-info-button-loading' ).hide(); + alert( 'Error: see the console!' ); + console.log('Err:', jqXHR.responseText); }); }); From 651b33f7024f12a1b42e064e100426f1cdde2413 Mon Sep 17 00:00:00 2001 From: Daniel Camargo Date: Tue, 13 Aug 2013 16:54:17 -0300 Subject: [PATCH 2/2] partial #1551 --- include/library/Crunchbutton/Order.php | 6 +++--- www/assets/js/services.giftcard.js | 6 +++++- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/include/library/Crunchbutton/Order.php b/include/library/Crunchbutton/Order.php index 7a13b011b..9c7e2daf6 100644 --- a/include/library/Crunchbutton/Order.php +++ b/include/library/Crunchbutton/Order.php @@ -216,7 +216,7 @@ class Crunchbutton_Order extends Cana_Table { } } - Log::debug(['giftcardValue'=> $this->giftcardValue]); + Log::debug([ 'issue' => '#1551', 'method' => 'process', '$this->final_price' => $this->final_price, 'giftcardValue'=> $this->giftcardValue ]); $res = $this->verifyPayment(); @@ -382,11 +382,10 @@ class Crunchbutton_Order extends Cana_Table { $chargedByCredit = Crunchbutton_Credit::calcDebitFromUserCredit( $final_price, $this->id_user, $this->id_restaurant, $this->id_order, true ); $final_price = $final_price - $chargedByCredit; } - Log::debug([ '$this->final_price' => $this->final_price, 'giftcardValue'=> $this->giftcardValue, 'final_price' => $final_price, ]); + Log::debug([ 'issue' => '#1551', 'method' => 'calcFinalPriceMinusUsersCredit', '$this->final_price' => $this->final_price, 'giftcardValue'=> $this->giftcardValue, 'final_price' => $final_price, ]); if( $final_price < 0 ){ $final_price = 0; } return Util::ceil( $final_price, 2 ); } - return $final_price; } @@ -476,6 +475,7 @@ class Crunchbutton_Order extends Cana_Table { } $amount = $this->calcFinalPriceMinusUsersCredit(); + Log::debug([ 'issue' => '#1551', 'method' => 'verifyPayment', '$this->final_price' => $this->final_price, 'giftcardValue'=> $this->giftcardValue, 'amount' => $amount ]); // If the amount is 0 it means that the user used his credit. if( $amount > 0 ){ diff --git a/www/assets/js/services.giftcard.js b/www/assets/js/services.giftcard.js index d4ac124a9..af75a552f 100644 --- a/www/assets/js/services.giftcard.js +++ b/www/assets/js/services.giftcard.js @@ -87,7 +87,11 @@ NGApp.factory( 'GiftCardService', function( $http, $location, AccountModalServic service.giftCardModal.open(); service.processModal(); } - service.accountModal.signinOpen(); + service.modal.close(); + setTimeout( function(){ + service.accountModal.signinOpen(); + }, 500 ); + } service.modal.close = function(){