Available in more than 200 markets & trusted by 200 million customers around the world, Paypal enables consumers and merchants to send & receive money in more than different currencies, PayPal is worth considering option when it comes to choosing payment Gateway for business. And, PayPal Express Checkout offered by PayPal allows the store customer to perform faster checkout in Ecommerce store with an enhanced layer of security. During the checkout, the customer is redirected to the secure PayPal webpage to complete the payment information. And once the transaction is completed, the customer is redirected back to your store. Adding PayPal Express Checkout to your Magento 2 store showcase the familiar PayPal button on your store, which has been reported to increase sales.
But several times it happens that while charging some extra fees on order doesn’t match with PayPal order total and it throws an error and doesn’t allow the customers to proceed further. To fix this issue, you need to manage this custom amount with PayPal Express Checkout by adding a piece of code in your Magento 2 store.
To do the same, first we need create “events.xml” file inside our custom extension folder.
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">
<observer name="vendor_extension_payment_collect_total" instance="Vendor\Extension\Observer\AddCustomAmountItem" />
Now, we need to create one more file, for adding a custom amount in Paypal Checkout and display in subtotal.
class AddCustomAmountItem implements ObserverInterface
public function execute(Observer $observer)
/** @var \Magento\Payment\Model\Cart $cart */
$cart = $observer->getEvent()->getCart();
$customAmount = 100;
$cart->addCustomItem(__('Custom Amount'), 1, -1.00 * $customAmount, 'customfee');
That’s it! You have successfully manage your custom amount with Paypal Express Checkout. If you found this blog helpful, don’t forget to share it with your colleagues and Magento Friends.
And, Let us know if you are facing an issue while implementing this code.