Is it possible to limit the total sales amount for a credit card purchase

I want to limit the total order amount for any combination of products to less then a set amount, for example $5000.



I know I can limit the quantity amount of any one item, but I need a cumulative limit on the $ amount of the order.



I don't want to accept any credit card orders over $5000, is that possible?



Thanks for your reply.



Jacson

Would be a fairly simply “post” checkout controller that would not allow the user to checkout if the order total were above some threshold. I.e. something like this in addons/my_changes/controllers/customer/checkout.post.php

Note, this should be considered pseudo code. It has not been tested, just how it comes out of my head.

```php

if( !defined('AREA') ) die('Access denied');
define('MY_ORDER_THRESHOLD', 5000.00);
if( $_SERVER['REQUEST_METHOD'] != 'POST' && $mode == 'checkout' ) {
$o = $view->get_var('order_info');
if( $o['total'] > MY_ORDER_THRESHOLD ) {
fn_set_notification('E', "Checkout", "Maximum amount for checkout is restricted to $".MY_ORDER_THRESHOLD.". Please contact us for help or reduce your order.", true);
fn_redirect("?dispatch=checkout.cart");
}
}
return array(CONTROLLER_STATUS_OK);
?>

```

Thanks so much for the reply! Sorry for the late response. I created the file and added it to /controllers/customer. Controllers is not under addons or my_changes though, that's why I put the file there.



I get the below error:



Parse error: syntax error, unexpected $end in /home/mywebsite/public_html/store/controllers/customer/checkout.post.php on line 11.



Line 11 is just the last line with ?>



I am sorry, this may be above my head, I am not so good at PHP.



Thanks for your effort and help!



Jacson

Hire a developer to deploy it for you. It was intended (as I said above) to be an example. And yes, you probably have to create the path controllers/customer in the addons/my_changes directory.

I updated the code segment to resolve the syntax error reported.

OK - I did some fiddling, the issue was the variables and the redirect, had to play with them, but it seems to be working great. This has NOT been thoroughly tested in case anyone else implements as I have not gone through a live transaction, but it certainly seems to be good to me, it pops the warning and then prevents from getting to checkout.



Thanks for your help!! Here is what I used:


```php

if( !defined('AREA') ) {die('Access denied'); }
define('MY_ORDER_THRESHOLD', 5000.00);
if( $_SERVER['REQUEST_METHOD'] != 'POST' && $mode == 'checkout' ) {
$o = $view->get_var('cart');
if( $o['subtotal'] > MY_ORDER_THRESHOLD ) {
fn_set_notification('E', "Checkout", "Maximum amount for checkout is restricted to $".MY_ORDER_THRESHOLD.". Please contact us for help or reduce your order.", true);
fn_redirect('checkout.cart', true);
}
}
return array(CONTROLLER_STATUS_OK);
?>

```

I know this topic is old now, but this does not work with 4.0.1, it might be that the addons are located in a different area so I am not sure where to upload the checkout.post.php file.



Has anyone tried this on 4.0.1?



Thanks!



Jacson

Should now be located in app/addons/my_changes/frontend directory.

Hi tbirnseth - thanks for still following! I appreciate it very much. Unfortunately it does not work. I created the frontend directory in my_changes. But i think the code does not work any more because of something deprecated. I stuck the file into the controllers directory for the heck of it and i got this:



Deprecated: File: /home/content/25/7593725/html/app/controllers/frontend/checkout.post.php, line: 5: Called method 'get_var' of deprecated global object $view. Please get access to templater through the Registry object. in /home/content/25/7593725/html/app/Tygh/SmartyEngine/ViewDeprecated.php on line 46



If I look at the viewdeprecated.php file then i see something about the 'view", so i think this line in the code is now wrong:



$o = $view->get_var('cart');



This is beyond me, so if you can help great.



Jacson

You may be able to configure this within your payment processor settings instead of going through the hassle of making code changes.?

Thanks for the suggestion Tool. I CAN limit the maximum amount per transaction via the payment processor, at least i can with Authorize.net, but all it can do is decline the order, so it leaves the customer with no indication why it was declined. I guess i could add some text on the check out page that we do not accept orders over a certain amount.



The solution in this thread worked so slick in V3, as it popped up a warning message that the max amount was reached, so it was real clear to the customer, just wish I could get it to work in V4.



Jacson

You might be able to change the line to read

$view->getTemplateVars('cart')

instead. Just another useless change…

@tool - but then you pay for the transaction and you have to deal with a DECLINEd order. Much easier to alert the customer before even entering checkout process.

I'm not aware of different processor's policies but I only pay for transactions that go through successfully. As for dealing with declined orders, I am not sure what there is to deal with…it's just a declined order.



I will agree however, that it would be less trouble on all parties to catch it before hand.

Hi Guys - thanks for the input. Getting somewhere with this. I used the line tbirnseth suggested: $view->getTemplateVars('cart').



Nothing happened. So I then stuck the checkout.post.php in the app/controllers/ directory. So now it DOES pop up the warning message, but only after I hit the check out button, not the add to cart button, and it gives the below error briefly before going to the check out page and displaying the warning.



Called method 'getTemplateVars' of deprecated global object $view. Please get access to the templater through the global registry object in home/content/html/app/tygh/smartyEngine/ViewDeprecated.php on line 46



I think the issue is 'view' is deprecated, but I don't know how to get the replacement for 'view' out of the ViewDeprecated.php file.



Also, I have read the entire beta release topic, and I must say I really agree with so much that tbirnseth was talking about. Seems like so many things changed for no real good reason. I just want to thank you tbirnseth for all the help you graciously offer and its a sad thing to see you possibly move out of the forum to a new solution.

Change $view to Registry::get('view') then.

But in V4 you'll have to add

use Tygh\Registry;

to the top of the file you are including.

Once again, THANKS! So, with a little tweak that worked!



In review, I added the file:



checkout.post.php



directly into the app/controllers/ frontend folder.



Below is the content of the checkout.post.php file.


if( !defined('AREA') ) {die('Access denied'); }
define('MY_ORDER_THRESHOLD', 5000.00);
if( $_SERVER['REQUEST_METHOD'] != 'POST' && $mode == 'checkout' ) {
$o = Tygh\Registry::get('view')->getTemplateVars('cart');
if( $o['subtotal'] > MY_ORDER_THRESHOLD ) {
fn_set_notification('E', "Checkout", "Maximum amount for checkout is restricted to $".MY_ORDER_THRESHOLD.". Please contact us for help or reduce your order.", true);
fn_redirect('checkout.cart', true);
}
}
return array(CONTROLLER_STATUS_OK);
?>

This pops the warning box when ever you try to click the "Check out" button and returns the viewer back to the cart page, so they are stuck at the cart page and can not proceed.

I have not tested it too much as the store is just getting started, like I have not bounced around all the pages, but sure seems to work just fine.

Thanks guys!

You don't need it in the app/controllers/frontend directory. It is bad practice to do so. My bet is that if your my_changes addon is active and you put it in the proper place (app/addons/my_changes/controllers/frontend/checkout.post.php) it will behave properly.



And you didn't use the “use” verb, but instead forced it directly to use the Tygh directory. Again, bad practice.

Again thanks, this is helping me and anyone else who may need this, but I am a MAJOR rookie at this, I am a UI and front end designer, so I muddle around and try so hard to figure code out, but basically I am a newbie at best.



So, as expected you are RIGHT! Works fine, putting in the folder you suggested: app/addons/my_changes/controllers/frontend/checkout.post.php



Sorry to say, I did not understand the “use” verb part either, so I just tried different things to get it to work. Certainly no where near your expertise on the matter, so I did not know where to put the “Tygh\Registry;” part.



Shoot! I am trying!





Jacson

OK - I understand the “use” part now. Sorry to anyone following this topic. This is the final code I used and works great:



FOR VERSION 4.0.1!


```php

use Tygh\Registry;
if( !defined('AREA') ) {die('Access denied'); }
define('MY_ORDER_THRESHOLD', 5000.00);
if( $_SERVER['REQUEST_METHOD'] != 'POST' && $mode == 'checkout' ) {
$o = Registry::get('view')->getTemplateVars('cart');
if( $o['subtotal'] > MY_ORDER_THRESHOLD ) {
fn_set_notification('E', "Checkout", "Maximum amount for checkout is restricted to $".MY_ORDER_THRESHOLD.". Please contact us for help or reduce your order.", true);
fn_redirect('checkout.cart', true);
}
}
return array(CONTROLLER_STATUS_OK);
?>

```

In V4 they force you to use namespaces. This means that that the top of every file that uses a standard class (like Registry) you have to tell it where the instnace of that class can be found. I.e. a line that looks like

use Tygh\Registry;



That's it. Then you can just use Registry::get(…)



While INMHO, this enables addon developers to have their own class named Registry it seems pretty pointless since cs-cart classes are used all over the place. They also adopted yet another coding standard and instead of providing compatibility, force everyone to change to their standards.