Magento – Error place an order with credit card payment method

checkoutcredit-cardmagento-2.1orders

In checkout section i try to place an order using a credit card payment method, my cc data is valid, but when i click place order button the page stuck at loading circle gif, and when i inspect network to find the error i got this error response from payment-information :

Fatal error: Call to a member function formatPrice() on null in
/home/project/public_html/vendor/magento/module-weee/view/frontend/templates/email/items/price/row.phtml
on line 25

{"messages":{"error":[{"code":500,"message":"Server internal error.
See details in report api/1309099902234"}]}}

i try to open the row.phtml file at row 25, i've found this line of code:

  <?= /* @escapeNotVerified */  $_order->formatPrice($block->getRowDisplayPriceExclTax()) ?>

when i try to print the $block->getRowDisplayPriceExclTax() it prints 25.5, and when i try to comment the code like this:

<?//= /* @escapeNotVerified */  $_order->formatPrice($block->getRowDisplayPriceExclTax()) ?>

place an order is working just fine and sending email

Best Answer

You are facing this error while you are using custom module so the line which you commented is formatting price only.

So instead of commenting, you can replace this line:

<?= /* @escapeNotVerified */  $_order->formatPrice($block->getRowDisplayPriceExclTax()) ?>

with this below code:

<?php
$objectManager = \Magento\Framework\App\ObjectManager::getInstance(); 
$priceHelper = $objectManager->create('Magento\Framework\Pricing\Helper\Data'); 
$formattedPrice = $priceHelper->currency($block->getRowDisplayPriceExclTax(), true, false);
echo $formattedPrice;?>

Hope this was useful