Author Topic: Payment method plugin with user input field  (Read 670 times)

vmfyelloq19

  • Beginner
  • *
  • Posts: 11
  • A beginner
Payment method plugin with user input field
« on: August 13, 2019, 11:46:57 am »
Hi folks,

I need to have a user input field for a payment method, baisally a text input filed that's presented when the payment method is selected.
( ) paypal
() other 1
(x) my payment method
     Please enter code [___________]

Any hints?

TIA!

GJC Web Design

  • 3rd party VirtueMart Developer
  • Super Hero
  • *
  • Posts: 9389
  • Virtuemart, Joomla & php developer
    • GJC Web Design
  • VirtueMart Version: 3.6.8
Re: Payment method plugin with user input field
« Reply #1 on: August 13, 2019, 16:17:25 pm »
you can over ride the protected function getPluginHtml () and provide a field but I assume there is a lot more to it than that.. what is the field supposed to do?
GJC Web Design
VirtueMart and Joomla Developers - php developers http://www.gjcwebdesign.com
VM3 AusPost Shipping Plugin - e-go Shipping Plugin - VM3 Postcode Shipping Plugin - Radius Shipping Plugin - VM3 NZ Post Shipping Plugin - AusPost Estimator
Samport Payment Plugin - EcomMerchant Payment Plugin - ccBill payment Plugin
VM2 Product Lock Extension - VM2 Preconfig Adresses Extension - TaxCloud USA Taxes Plugin - Virtuemart  Product Review Component
http://extensions.joomla.org/profile/profile/details/67210
Contact for any VirtueMart or Joomla development & customisation

vmfyelloq19

  • Beginner
  • *
  • Posts: 11
  • A beginner
Re: Payment method plugin with user input field
« Reply #2 on: August 13, 2019, 18:53:51 pm »
Hi GJC Web Design,

thank your for your reply.
This particular "payment method" just needs to pass a string with the customer's account number along with the order.
A shopper field would be fit the case better, as it would be stored into the customer's profile, but shopper fields are not be conditional for the specify payment method.

Cheers!

GJC Web Design

  • 3rd party VirtueMart Developer
  • Super Hero
  • *
  • Posts: 9389
  • Virtuemart, Joomla & php developer
    • GJC Web Design
  • VirtueMart Version: 3.6.8
Re: Payment method plugin with user input field
« Reply #3 on: August 13, 2019, 23:18:17 pm »
in that case u could use some JS to show/hide and enforce the shopper field if that radio is chosen
GJC Web Design
VirtueMart and Joomla Developers - php developers http://www.gjcwebdesign.com
VM3 AusPost Shipping Plugin - e-go Shipping Plugin - VM3 Postcode Shipping Plugin - Radius Shipping Plugin - VM3 NZ Post Shipping Plugin - AusPost Estimator
Samport Payment Plugin - EcomMerchant Payment Plugin - ccBill payment Plugin
VM2 Product Lock Extension - VM2 Preconfig Adresses Extension - TaxCloud USA Taxes Plugin - Virtuemart  Product Review Component
http://extensions.joomla.org/profile/profile/details/67210
Contact for any VirtueMart or Joomla development & customisation

vmfyelloq19

  • Beginner
  • *
  • Posts: 11
  • A beginner
Re: Payment method plugin with user input field
« Reply #4 on: August 14, 2019, 08:49:59 am »
I never use Javascript for required functionality, as it is possibly disabled.

Cheers!

jenkinhill

  • UK Web Developer & Consultant
  • Global Moderator
  • Super Hero
  • *
  • Posts: 27637
  • Always on vacation
    • Jenkin Hill Internet
Re: Payment method plugin with user input field
« Reply #5 on: August 14, 2019, 11:29:17 am »
I never use Javascript for required functionality, as it is possibly disabled.

As VirtueMart makes heavy use of JavaScript then AFAIK someone with js "disabled" would be unable to use the store, anyway.
Kelvyn

Jenkin Hill Internet,
Lowestoft, Suffolk, UK

Unsolicited PMs/emails will be ignored.

Please mention your VirtueMart, Joomla and PHP versions when asking a question in this forum

Currently using VM 3.6.11 10252 on Joomla 3.9.14 PHP 7.0.33

vmfyelloq19

  • Beginner
  • *
  • Posts: 11
  • A beginner
Re: Payment method plugin with user input field
« Reply #6 on: January 31, 2020, 08:08:21 am »
Hi jenkinhill,

You are right, and I adjusted my opinion on requiring JS with VM.

I've added some custom user text fields, added some JS to hide them via CSS if the payment mezhod does not match.
But that's causing several issues:
- I cannot set the fields to required
- there is no way to add a custom validation

Any hints anyone?

TIA!

GJC Web Design

  • 3rd party VirtueMart Developer
  • Super Hero
  • *
  • Posts: 9389
  • Virtuemart, Joomla & php developer
    • GJC Web Design
  • VirtueMart Version: 3.6.8
Re: Payment method plugin with user input field
« Reply #7 on: January 31, 2020, 10:08:19 am »
just do it with JS

example

      if(jQuery('#companyreg_field').prop('checked')) {
         jQuery('#first_name_field').removeClass('required');
         jQuery('#first_name_field').removeAttr('required aria-required');
      }else{
         jQuery('#first_name_field').addClass('required')
         jQuery('#first_name_field').attr('required', 'required');
         jQuery('#first_name_field').attr('aria-required', 'true');
      }


validation can be handled the same way  with e.g.

jQuery('input#your_input ').bind("focusout keyup change", function() {
   // do stuff
});

or on submit etc
GJC Web Design
VirtueMart and Joomla Developers - php developers http://www.gjcwebdesign.com
VM3 AusPost Shipping Plugin - e-go Shipping Plugin - VM3 Postcode Shipping Plugin - Radius Shipping Plugin - VM3 NZ Post Shipping Plugin - AusPost Estimator
Samport Payment Plugin - EcomMerchant Payment Plugin - ccBill payment Plugin
VM2 Product Lock Extension - VM2 Preconfig Adresses Extension - TaxCloud USA Taxes Plugin - Virtuemart  Product Review Component
http://extensions.joomla.org/profile/profile/details/67210
Contact for any VirtueMart or Joomla development & customisation

vmfyelloq19

  • Beginner
  • *
  • Posts: 11
  • A beginner
Re: Payment method plugin with user input field
« Reply #8 on: February 04, 2020, 23:18:48 pm »
Thank you GJC Web Design,
that helped a lot!

After some consideration I'm giving the paymnet plugin another go.

I managed to display the required user input fields using plgVmDisplayListFEPayment().
I can check user input just fine in plgVmOnSelectCheckPayment() by checking the values I get from vRequest::getString([...]).

Still I'm stuck with re-displaying user input in the layout called from plgVmDisplayListFEPayment().
It seems user input is empty here.
I also tried to settting a class variable ($this->myformdata) in plgVmOnSelectCheckPayment() but it this var is empty in plgVmDisplayListFEPayment(). Might be a method-call ordering thing.

So what's the proper way to fill in the former user input in the form fields?
<input type... value="<insert former user input here>" ... />


What I have so far in plugins/vmpayment/mypayment/mypayment.php is:

class plgVmpaymentMypayment extends vmPSPlugin {
    [...]
    public function plgVmDisplayListFEPayment(VirtueMartCart $cart, $selected=0, &$htmlIn) {
        if ($this->getPluginMethods($cart->vendorId) === 0) {
            if (empty($this->_name)) {
                $app=JFactory::getApplication();
                $app->enqueueMessage(vmText::_('COM_VIRTUEMART_CART_NO_' . strtoupper($this->_psType)));
                return false;
            } else {
                return false;
            }
        }
        $htmlarray=[];
        foreach ($this->methods as $this->_currentMethod) {
            if($this->checkConditions($cart, $this->_currentMethod, $cart->cartPrices)) {
            $cartPrices=$cart->cartPrices;
                $methodSalesPrice=$this->calculateSalesPrice($cart, $this->_currentMethod, $cartPrices);
                $payment_cost='';
                if ($methodSalesPrice) {
                    $payment_cost=$currency->priceDisplay($methodSalesPrice);
                }
                if ($selected == $this->_currentMethod->virtuemart_paymentmethod_id) {
                    $checked='checked="checked"';
                } else {
                    $checked='';
                }
                /*
                 *
                 *  Need to pass former user input into layout here
                 *  If possible: also result of validation to highlight bad input fields
                 *
                 */

                $html=$this->renderByLayout('display_payment', [
                    'plugin' => $this->_currentMethod
                   ,'checked' => $checked
                   ,'payment_cost' => $payment_cost
                ]);
                $htmlarray[]=$html;
                if (!empty($htmlarray)) {
                    $htmlIn[]=$htmlarray;
                }
            }
        }
        return true;
    } // plgVmDisplayListFEPayment()

    [...]

    public function plgVmOnSelectCheckPayment(VirtueMartCart $cart,  &$msg) {
        if(! $this->selectedThisByMethodId($cart->virtuemart_paymentmethod_id)) {
            return NULL; // Another method was selected, do nothing
        }
        [...] // [my checks here]
        if($errors) {
            vmWarn($errormessage);
       return false;
        } else {
            // Just return true?
            return $this->OnSelectCheck($cart);
        }
    } // plgVmOnSelectCheckPayment()