MultiSafepay / Magento2Msp

MultiSafepay plugin for Magento 2 (Deprecated) see: https://github.com/MultiSafepay/magento2
Open Software License 3.0
29 stars 25 forks source link

Using coupons and paying with Klarna results in error code 1031 #137

Closed thompalstra closed 3 years ago

thompalstra commented 3 years ago

When selecting Klarna as payment method and using a coupon code, the sent items seem to be formatted incorrectly.

This results in a code 1031, incorrect price for specific item.

Klarna:

{
    "name":"AmastyCoupon",
    "description":"AmastyCoupon",
    "unit_price":[
        {"coupon_code":"SHOPPINGNIGHT2020","coupon_amount":"-\u20ac\u00a032,20"}
    ],
    "quantity":"1",
    "merchant_item_id":"amasty_coupon_amount",
    "tax_table_selector":"CustomTotalTax_amasty_coupon_amount",
    "weight":{"unit":"KG","value":"0"}
}

Other payment method (iDeal)

{
    "cashback": "",
    "currency": "EUR",
    "description": "AmastyCoupon",
    "image": "",
    "merchant_item_id": "amasty_coupon_amount",
    "name": "AmastyCoupon",
    "options": [],
    "product_url": "",
    "quantity": 1,
    "tax_table_selector": "CustomTotalTax_amasty_coupon_amount",
    "unit_price": "",
    "weight": {"unit": "KG","value": 0}
}

How would we approach resolving this issue?

vinodsowdagar commented 3 years ago

Hi @thompalstra ,

The way Amasty has build their Coupon Total is different from what our module expects. We expect the unit_price to have a single price value and instead the Amasty Coupon module is giving us an array with a coupon code in it as well, so that is where it fails.

You could try to create an observer based on the 'before_send_msp_transaction_request' event. We fire this event right before the moment we send the transaction to MultiSafepay. See: https://github.com/MultiSafepay/Magento2Msp/blob/master/Model/Connect.php#L662-L664

In the event observer you can then access the transaction data and change the unit_price before it is being sent.

We also have an example of this concept available which i can send you via e-mail. If you need more help, please let us know.