Page 1 of 1

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

PostPosted: Thu May 13, 2021 11:16 am
by info@.....cz
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.

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

PostPosted: Mon May 17, 2021 10:01 am
by admin
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

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

PostPosted: Tue May 18, 2021 10:29 am
by info@.....cz
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.

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

PostPosted: Tue May 18, 2021 11:02 am
by info@.....cz
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>

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

PostPosted: Tue May 25, 2021 8:51 am
by admin
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