ReferenceError: payment is not defined on checkout page

ReferenceError: payment is not defined on checkout page

July 30, 2026 · Illustrated author avatarBy Stefan Bogdanescu
ReferenceError: payment is not defined on checkout page

ReferenceError: payment is not defined on Checkout Page

Understanding the Issue

If you’re encountering a ReferenceError: payment is not defined error on your checkout page in Magento, it usually signifies that the payment.js file isn’t loading properly or the payment object is being initialized incorrectly. This often happens when you have multiple payment methods enabled—like PayPal Express Checkout and Authorize.net—and there’s an issue with the JavaScript initialization of the payment options.

Investigating Your Code

Let’s break down your provided code to understand what might be causing the error:

<script type="text/javascript">
    //<![CDATA[
    <?php echo $this->getChildChildHtml('scripts'); ?>
    payment.init();
    <?php if (is_string($oneMethod)): ?>
    payment.switchMethod('<?php echo $oneMethod; ?>');
        <?php endif; ?>
    //]]>
</script>

The payment.init() function is responsible for initializing the payment methods and the payment.switchMethod() function handles switching between different payment options. The issue seems to be with how these functions are being called.

Common Causes of the Error

  1. Payment.js File Not Loading: Ensure that the payment.js file is properly loaded before the JavaScript code in your checkout page. You can check this by inspecting the network tab in your browser’s developer tools.

  2. Payment Object Not Defined: The error implies that the payment object isn’t defined or has been deleted somewhere in your code. Check for any JavaScript errors or console logs that might indicate a problem with the payment object.

  3. Conflict With Other Scripts: If you have other scripts running on your checkout page, they could potentially conflict with the payment.js script and cause this error to occur.

Troubleshooting Steps

  1. Check for JavaScript Errors: Open your browser’s developer tools console (right-click > Inspect Element > Console tab) and look for any errors or warnings related to the payment object. This can help you pinpoint where the issue is occurring in your code.

  2. Manually Include payment.js: If the payment.js file isn’t being loaded automatically, you can manually include it in your header:

<script type="text/javascript" src="https://your-store.com/js/payment.js"></script>

Replace https://your-store.com with your actual store URL.

  1. Initialize payment Object Manually: If the payment object isn’t being initialized correctly, you can try initializing it manually:
var payment = new Payment({
    // Your payment configuration here
});
  1. Check for Conflicting Scripts: Disable any custom or third-party scripts running on your checkout page one by one to see if they’re causing the conflict.

Resolving the Issue

To resolve this issue, I recommend following these steps:

  1. Check the network tab in your browser’s developer tools to ensure that the payment.js file is loading correctly and without errors.

  2. Open the JavaScript console (right-click > Inspect Element > Console tab) and look for any errors or warnings related to the payment object.

  3. If the payment.js file isn’t being loaded automatically, manually include it in your header as shown above.

  4. Try initializing the payment object manually using the code provided if the automatic initialization fails.

  5. If you have other scripts running on your checkout page, disable them one by one to check for conflicts.

Remember that the payment.js file should be loaded before the JavaScript code in your checkout page. If it isn’t being loaded automatically, make sure to include it manually.

Conclusion

The ReferenceError: payment is not defined error on the checkout page usually occurs due to issues with loading or initializing the payment.js file and the payment object. By following the troubleshooting steps outlined above, you should be able to identify and resolve the issue in your specific case.

If you’re still encountering difficulties, I recommend reaching out to a Magento developer for further assistance. They can help you diagnose and solve this issue more efficiently.

For more information on managing payment methods in Magento, I suggest checking out our comprehensive guide at https://laravelcompany.com/magento-payment-methods.

Happy coding!

Checkout Errors JavaScript

Our network