How to hide/show payment method based on total amount range

If you are runnig Joomla 3.x and Virtuemart 3.x please post to this forum your questions or support tickets about One Page Checkout

How to hide/show payment method based on total amount range

Postby info@.....cz » Thu May 13, 2021 11:16 am

Hello, is there any possibility how to show payment method only for defined range of total amount?
Usage: We want to offer payment PlatimPak which is supported by payment gate only for range 500 - 25000 CZK.
Thank you.
info@.....cz
 
Posts: 13
Joined: Thu Feb 28, 2019 9:22 pm

Re: How to hide/show payment method based on total amount range

Postby admin » Mon May 17, 2021 10:01 am

hello, the simplest way to handle this is to ask your payment plugin provider to copy/implement the same logic as used in standard payment plugin - i.e. it needs to add a few items within the XML and then call generic "check restrictions" function for this.

OPC got it's own filtering system, but since VM had implemented most of it's featuers into the core and most of the new payment plugins are a clone of some of the core VM plugin, i believe it is a better solution to adjust the plugin instead of writing a new global filter functions for this inside OPC core.

best regards, stan
admin
Site Admin
 
Posts: 2708
Joined: Wed Jan 06, 2010 11:43 pm

Re: How to hide/show payment method based on total amount range

Postby info@.....cz » Tue May 18, 2021 10:29 am

Thank you, Because i am not sure if i will reach the developer i will try it by myself. Do you have any tip for documentation where to start? Thank you.
info@.....cz
 
Posts: 13
Joined: Thu Feb 28, 2019 9:22 pm

Re: How to hide/show payment method based on total amount range

Postby info@.....cz » Tue May 18, 2021 11:02 am

payment php:
Code: Select all
   
added in constructor:   
                $varsToPush = $this->getVarsToPush ();
      $this->setConfigParameterable ($this->_configTableFieldName, $varsToPush);
      $this->setConvertable(array('min_amount','max_amount','cost_per_transaction','cost_min_transaction'));
      $this->setConvertDecimal(array('min_amount','max_amount','cost_per_transaction','cost_min_transaction','cost_percent_total'));      

+ new function:
   /**
    * Check if the payment conditions are fulfilled for this payment method
    *
    * @author: Valerie Isaksen
    *
    * @param $cart_prices: cart prices
    * @param $payment
    * @return true: if the conditions are fulfilled, false otherwise
    *
    */
   protected function checkConditions ($cart, $method, $cart_prices) {

      $this->convert_condition_amount($method);
      $amount = $this->getCartAmount($cart_prices);

      if($this->_toConvert){
         $this->convertToVendorCurrency($method);
      }
      //vmdebug('standard checkConditions',  $amount, $cart_prices['salesPrice'],  $cart_prices['salesPriceCoupon']);
      $amount_cond = ($amount >= $method->min_amount AND $amount <= $method->max_amount
         OR
         ($method->min_amount <= $amount AND ($method->max_amount == 0)));
      if (!$amount_cond) {
         return FALSE;
      }
      
      return TRUE;
   }



payment XML change:
Code: Select all
added:
<fieldset name="restrictions" >
                <field name="countries" multiple="true" type="vmcountries" scope="com_virtuemart" default=""
                       label="VMPAYMENT_STANDARD_COUNTRIES" description="VMPAYMENT_STANDARD_COUNTRIES_TIP"/>
                <field name="min_amount" type="text" label="VMPAYMENT_STANDARD_MIN_AMOUNT"
                       description="VMPAYMENT_STANDARD_MIN_AMOUNT_TIP"/>
                <field name="max_amount" type="text" label="VMPAYMENT_STANDARD_MAX_AMOUNT"
                       description="VMPAYMENT_STANDARD_MAX_AMOUNT_TIP"/>
            </fieldset>
info@.....cz
 
Posts: 13
Joined: Thu Feb 28, 2019 9:22 pm

Re: How to hide/show payment method based on total amount range

Postby admin » Tue May 25, 2021 8:51 am

hello, did it work for you ?

the normal way is to include missing XML items from weight_countries.xml, and merge weight_countries.php into your plugin (checkConditions + all missing functions). plugins are using a parent class of vmpsplugin initialized in VM admin directory which includes functions accessible with $this-> as well.

best regards, stan
admin
Site Admin
 
Posts: 2708
Joined: Wed Jan 06, 2010 11:43 pm


Return to One Page Checkout for Virtuemart 3 on Joomla 3.x

cron