Checkout Payment – Show Payment Child HTML Form Based on Selection

checkoutpayment

I'm adding payment information section in custom theme. I've update chechout phtml code and All enabled payment methods are visible in payment information section.

enter image description here

I've my template code referenced from app/design/frontend/base/default/teplate/checkout/onepage/payment/methods.phtml file. I'm overwriting block Mage_Payment_Block_Form_Container.In my console I see error Uncaught ReferenceError: payment is not defined due to payment.init(); line in

   <?php echo $this->getChildChildHtml('scripts'); ?>
    payment.init();
    <?php if (is_string($oneMethod)): ?>
    payment.switchMethod('<?php echo $oneMethod ?>');
        <?php endif; ?>
    //]]>

On clicking on any particular payment method I want to load it's corresponding child html. but onclick of payment.switchMethod('<?php echo $oneMethod ?>'); the corresponding child form is not being loaded. What I need to do to load corresponding child html of any payment method given that I'm not using Magento default theme?

I'm not getting form html from my block function which is defined as

   public function getPaymentMethodFormHtml(Mage_Payment_Model_Method_Abstract $method)
    {
         return $this->getChildHtml('payment.method.' . $method->getCode());
    }

Best Answer

In my console I see error Uncaught ReferenceError: payment is not defined due to payment.init();

It looks like you need to check if the following source code is present when you open your checkout page:

var payment = new Payment('co-payment-form', '<?php echo $this->getUrl('checkout/onepage/savePayment') ?>');

You can't switch payment method because javascript object "payment" is not initialised. So that is why payment.init() gives you an error. Also please make sure that opcheckout.js script is loaded, because it contains the "Payment" class. When you get it fixed, we can move on further.

Related Topic