Jump to content

Is there a hook that could disable a payment option just for public checkout?


Web Host Pro

Recommended Posts

We have two credit card processors. One is only for existing customers and one is for new sign ups. I was wondering if we could disable a processor just in the public checkout, but still have it for existing customers that have a product.

Basically disable a processor in the main checkout, then have it when adding products after the customer has a product.

Link to comment
Share on other sites

16 hours ago, Web Host Pro said:

We have two credit card processors. One is only for existing customers and one is for new sign ups. I was wondering if we could disable a processor just in the public checkout, but still have it for existing customers that have a product.

any of the 114 gateway unset hooks that i've previously posted could be modified for this - it's just down to working out the conditional if statement that removes the gateways..

<?php

# Remove Gateways for Non-Clients
# Written by brian!
 
function cart_gateway_removal_for_non_clients($vars) {
	
	$client = Menu::context('client');
	if ($vars['templatefile'] == 'viewcart'){
		$gateways = $vars['gateways'];
		$disallowed = array('banktransfer');
		foreach ($gateways as $k => $item) {
			if ((!$client && in_array($item['sysname'],$disallowed)) || ($client && in_array($item['sysname'],$disallowed) && count($vars['products']) == 0)) {
				unset($gateways[$k]);
			}
		} 
		return array("gateways" => $gateways);
	}
}
add_hook("ClientAreaPageCart", 1, "cart_gateway_removal_for_non_clients");
Link to comment
Share on other sites

  • 1 year later...

Note: to fully remove a gateway for a customer, it's required to check (and apply this hook) in other pages too...

I changed this:

if ($vars['templatefile'] == 'viewcart')

into this:

	if ($vars['templatefile'] == 'viewcart' or $vars['templatefile'] == 'clientareaaddfunds' or $vars['templatefile'] == 'upgradesummary' or $vars['templatefile'] == 'masspay' ){

and added also  this:

add_hook("ClientAreaPageUpgrade", 1, "cart_gateway_removal_for_non_clients");

(so the very same function is called from two different hookpoints...)

Don't know if there may be other points where it may be required to add this hook...

Link to comment
Share on other sites

1 hour ago, Remitur said:

(so the very same function is called from two different hookpoints...)

clientareapagecart wouldn't be triggered on the addfunds, masspay and upgradesummary pages - so you'd either have to call multiple hookpoints (granted CAPU takes care of the upgrade, but not the other two), or just use clientareapage and let the if statement trigger when it works (though might look neater to use in_array instead of multiple or's).

1 hour ago, Remitur said:

Don't know if there may be other points where it may be required to add this hook...

the obvious one would be on the invoices - suspect the above would work for 21, but you would need another hook is using Six (or a child based on it).

Link to comment
Share on other sites

On 3/27/2021 at 3:20 PM, brian! said:

clientareapagecart wouldn't be triggered on the addfunds, masspay and upgradesummary pages - so you'd either have to call multiple hookpoints (granted CAPU takes care of the upgrade, but not the other two), or just use clientareapage and let the if statement trigger when it works (though might look neater to use in_array instead of multiple or's).

Does exist any trick, using  the ClientAreaPageCart hook, to inject some HTML in page?

Or the only way is using  ShoppingCartCheckoutOutput hook? (But doing so it' necessary to use and "syncronize" between them two hooks...)

Link to comment
Share on other sites

16 hours ago, Remitur said:

Does exist any trick, using  the ClientAreaPageCart hook, to inject some HTML in page?

generally speaking, if you're going to inject HTML into a client page using a hook, you have two main avenues...

  1. there are hook points that return HTML by default in set locations of specific templates - ClientAreaHomePage is one, there are a handful of options for the cart and a few for the details pages.... the location of this output is determined in the template.
  2. there are output hook points, usually footer or header, that would allow you to use JS to add HTML to the template output - however, the problem is usually not adding the HTML, it's being able to define exactly in the appropriate template where you want the output to be... depending on where that is, it might be simple... or an absolute pain in the proverbial to get it right.
16 hours ago, Remitur said:

Or the only way is using  ShoppingCartCheckoutOutput hook? (But doing so it' necessary to use and "synchronize" between them two hooks...)

as I said, there are multiple cart output hooks depending upon which template, e.g stage of the cart process, you want to return the content.

what are you trying to achieve ?

Link to comment
Share on other sites

3 hours ago, brian! said:

what are you trying to achieve ?

I want to disable partial payment using credit: if a user has enough credit, he can pay using it. If the credit is not sufficient, he is forced to pay the full amount in a different way.

Doing this is easy, using ClientAreaPageCart.

But I would like to add a warning to the user, such as "You have 4,56 of available prepaid credit, that is not enought to pay this: pay in a different way, or do a credit refill in order to pay the full amount using credit"... but this is impossible in ClientAreaPageCart

I guess that maybe the best fix could be using ShoppingCartCheckoutOutput to inject a condiional Smarty code...

 

Link to comment
Share on other sites

2 hours ago, Remitur said:

Doing this is easy, using ClientAreaPageCart.

how are you doing it ? are you falsifying the variables to ensure the credit part isn't shown/applied ?

2 hours ago, Remitur said:

But I would like to add a warning to the user, such as "You have 4,56 of available prepaid credit, that is not enough to pay this: pay in a different way, or do a credit refill in order to pay the full amount using credit"... but this is impossible in ClientAreaPageCart

nothing is impossible... well WHMCS releasing less buggy updates might be, but let's not go there before Easter. 🐰

<?php

# Checkout Credit Balance Filter Hook
# Written by brian!

function cart_checkout_credit_filter_hook($vars) {
	$client = Menu::context('client');
	if ($client && $vars['templatefile'] == 'viewcart' && $vars['action'] == 'checkout') {
		if ($vars['creditBalance']->toNumeric() < $vars['total']->toNumeric()) {
			$hookoutput = $vars['hookOutput'];
			$message = '<div class="alert alert-danger text-center">You have '.$vars['creditBalance'].' of available prepaid credit, that is not enough to pay this: pay in a different way, or do a credit refill in order to pay the full amount using credit.</div>';
			array_push($hookoutput,$message);
			return array("canUseCreditOnCheckout" => false, "applyCredit" => false, "hookOutput" => $hookoutput);
		}
	}	
}
add_hook("ClientAreaPageCart", 1, "cart_checkout_credit_filter_hook");

oOCBfRw.png

$hookOutput is the array that ShoppingCartCheckoutOutput would modify with it's HTML, but you can modify it with CAPC directly if you have to... in the above hook, it's taking the current value of the array and adding another element to it.

if your site is multilingual (which I know it is), then you might have to use a language override for that message variable...

$_LANG['creditbalancecheckout'] = "You have %s of available prepaid credit, that is not enough to pay this: pay in a different way, or do a credit refill in order to pay the full amount using credit.";

and then change $message to...

$message = '<div class="alert alert-danger text-center">'.sprintf(Lang::trans('creditbalancecheckout'),$vars['creditBalance']).'</div>';

I suppose it's then possible you might need another similar hook to prevent them from manually adding the credit at the invoice stage - I imagine that's just a ClientAreaPageViewInvoice hook, performing a similar comparison and then nulls the relevant variable if comparison condition met.

EhsKI29.png

Edited by brian!
Link to comment
Share on other sites

1 hour ago, brian! said:

$hookOutput is the array that ShoppingCartCheckoutOutput would modify with it's HTML, but you can modify it with CAPC directly if you have to... in the above hook, it's taking the current value of the array and adding another element to it.

This is genious.

Real genious.

(Maybe a better documentation from WHMCS would help to  find solutions like this with a little less genious requirement but, being so, I need to blame WHMCS about his documentation, and praise your genius)

Link to comment
Share on other sites

  • 1 year later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated