Jump to content
Sign in to follow this  
Web Host Pro

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

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.

Share this post


Link to post
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");

Share this post


Link to post
Share on other sites

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...

Share this post


Link to post
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).

Share this post


Link to post
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...)

Share this post


Link to post
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 ?

Share this post


Link to post
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...

 

Share this post


Link to post
Share on other sites
Posted (edited)
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!

Share this post


Link to post
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)

Share this post


Link to post
Share on other sites

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.

Sign in to follow this  

  • Similar Content

    • By ramf
      Hi,
      When I'm creating a client I'm using the ClientAdd hook so that any information added when creating the client will be sent to another system as a webhook.
      I can do it without a problem and everything is working well - except getting the client custom fields information.
      I know that I can call this information separately with a nother get command - but this is not what I'm looking for. 
      In the hook documentation it is only mentioned that the customFields Variable is a array Type.
      Can someone give me a code example to show how can I incorporate the custom fields information that got added when creating the client?
      This is the code I'm using now - sorry this is a picture since I'm getting 403 Forbidden when trying to add it directly to the ticket....

       
      The only part missing is the information added to the  custom fields during the client creation and got triggered with the ClientAdd hook.
      Thanks!
      Ram
    • By Dreza
      Hello,
      I created a hook file for the 'OrderPaid' event and it seems like the $vars variable that is being passed to it always comes up empty. Does anyone know why this is happening?
    • By Dreza
      Hello,
      I created a hook file for one of my addon modules and it seems like the hook event is always happening. The hook event is 'OrderPaid'.
      When I look at the module logs there is an entry for this hook event every minute even though no orders have been paid for during this time.
      I need to know why this is happening. If anyone can help me I would appreciate it.
    • By rogerr
      Hi!
      I have created a hook to embed a new link in the primary navigation.
      this is an external link, so i would like to add an  target="_blank" to open a new tab for this link.

      may someone can give me a hint?
      here my code:
       
      if (!is_null($primaryNavbar->getChild('Support'))) { $primaryNavbar->getChild('Support')->addChild('FAQ-extern') ->setUri('https://www.example.com/') ->setOrder(30); }  
      Thank you!
    • By Marcos
      Hi All
      First of all, I cannot locate any hook that is triggered upon changing a Client's Ownership.  UserEdit is fired but seemingly BEFORE the User is assigned the Client, and no Client details are passed to the hook (I access them directly via de DB).
      Any suggestions on how to trap this event?
      Thank you in advance.
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • 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