1

I'm facing an issue where I'm adding a custom fee to totals and updating paypal with the following plugin:

class UpdateCustomFeeForOrderPayPal
{
    protected $_checkoutSession;
    const AMOUNT_SUBTOTAL = 'subtotal';
    public function __construct(
        \Magento\Checkout\Model\Session $checkoutSession
    ) {
        $this->_checkoutSession = $checkoutSession;
    }

    public function afterGetAmounts($cart,$result)
    {
        $quote = $this->_checkoutSession->getQuote();
        $paymentMethod = $quote->getPayment()->getMethod();
        $paypalMehodList = ['payflowpro','payflow_link','payflow_advanced','braintree_paypal','paypal_express_bml','payflow_express_bml','payflow_express','paypal_express'];

        // to check the paypal payment method
        if(in_array($paymentMethod,$paypalMehodList)){
            $result[self::AMOUNT_SUBTOTAL] = $result[self::AMOUNT_SUBTOTAL] + $quote->getFee();

        }

        return $result;
    }

    public function beforeGetAllItems($cart)
    {
        $quote      = $this->_checkoutSession->getQuote();

        $feePrice = $quote->getFee();

        if ($feePrice > 0) {
            $cart->addCustomItem(__("Extra Fee"), 1, $feePrice);
        }
    }
}

This unfortunately doesn't play well with PayPal, I'm getting the following response:

main.DEBUG: array (
  'url' => 'https://api-3t.sandbox.paypal.com/nvp',
  'SetExpressCheckout' => 
  array (
    'PAYMENTACTION' => 'Sale',
    'AMT' => '108.85',
    'CURRENCYCODE' => 'USD',
    'RETURNURL' => 'http://test.com/us/paypal/express/return/',
    'CANCELURL' => 'http://test.com/us/paypal/express/cancel/',
    'INVNUM' => 'US-00050186',
    'SOLUTIONTYPE' => 'Mark',
    'GIROPAYCANCELURL' => 'http://test.com/us/paypal/express/cancel/',
    'GIROPAYSUCCESSURL' => 'http://test.com/us/checkout/onepage/success/',
    'BANKTXNPENDINGURL' => 'http://test.com/us/checkout/onepage/success/',
    'SHIPPINGAMT' => '9.99',
    'ITEMAMT' => '85.43',
    'TAXAMT' => '7.99',
    'L_NUMBER0' => NULL,
    'L_NAME0' => 'ExtraFee',
    'L_QTY0' => 1,
    'L_AMT0' => '5.44',
    'BUSINESS' => NULL,
    'NOTETEXT' => NULL,
    'EMAIL' => 'test@gmail.com',
    'FIRSTNAME' => 'test',
    'LASTNAME' => 'test',
    'MIDDLENAME' => NULL,
    'SALUTATION' => NULL,
    'SUFFIX' => NULL,
    'COUNTRYCODE' => 'US',
    'STATE' => 'NY',
    'CITY' => 'New York',
    'STREET' => 'New York',
    'ZIP' => '10013',
    'PHONENUM' => '17623838372',
    'SHIPTOCOUNTRYCODE' => 'US',
    'SHIPTOSTATE' => 'NY',
    'SHIPTOCITY' => 'New York',
    'SHIPTOSTREET' => 'New York',
    'SHIPTOZIP' => '10013',
    'SHIPTOPHONENUM' => '17623838372',
    'SHIPTOSTREET2' => '',
    'STREET2' => '',
    'SHIPTONAME' => 'test test',
    'ADDROVERRIDE' => 1,
    'METHOD' => 'SetExpressCheckout',
    'VERSION' => '72.0',
    'USER' => '****',
    'PWD' => '****',
    'SIGNATURE' => '****',
    'BUTTONSOURCE' => 'Magento_Cart_Community',
  ),
  'response' => 
  array (
    'TIMESTAMP' => '2019-02-08T15:31:17Z',
    'CORRELATIONID' => 'de43685675249',
    'ACK' => 'Failure',
    'VERSION' => '72.0',
    'BUILD' => '51752370',
    'L_ERRORCODE0' => '10413',
    'L_SHORTMESSAGE0' => 'Transaction refused because of an invalid argument. See additional error messages for details.',
    'L_LONGMESSAGE0' => 'The totals of the cart item amounts do not match order amounts.',
    'L_SEVERITYCODE0' => 'Error',
  ),
) [] []

But the totals of the cart do match: 9.99 + 85.43 + 7.99 + 5.44 = 108.85

I don't understand what is the issue. Does anyone have an idea what's going on?

closed as off-topic by Jai, liyakat, Aasim Goriya, Mohit Kumar Arora, saravanavelu Feb 11 at 5:26

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions about third-party modules are generally off-topic because the scope of functionality and code are not available. For more information, see this meta post/answer." – Jai, liyakat, Aasim Goriya, Mohit Kumar Arora, saravanavelu
If this question can be reworded to fit the rules in the help center, please edit the question.

Browse other questions tagged or ask your own question.