Payment Error with Custom Options on Magento 2
Payment Error with Custom Options on Magento 2 version before v.2.1.10.
When a customer checkout a product with custom option via Authorize.net or PayPal, the customer will have an error “An error occurred on the server. Please try to place the order again.”. When you receive such an error, there are a lot of things it can trigger that kind of issue. However, in our case, we found out that the customer has custom option in the cart and need to fix in Magento core for the issue.
Go to vendor/magento/module-catalog/Model/Product.php and look for getOptionById method and replace the codes with below:
public function getOptionById($optionId)
{
$result = null;
if (is_array($this->getOptions())) {
/** @var \Magento\Catalog\Model\Product\Option $option */
foreach ($this->getOptions() as $option) {
if ($option->getId() == $optionId) {
$result = $option;
break;
}
}
}
return $result;
}
Reference: https://github.com/magento/magento2/commit/163efaee2382b1cc2255f2a9d007eb0a362c7569