paytrail/api-documentation

Item.unitPrice doesn't allow negative values?

asiksami opened this issue · 8 comments

Describe the bug

  • First, document https://docs.paytrail.com/#/?id=item doesn't say that item.unitPrice must have minimum value of 0.

  • Second, old E2 Interface field ITEM_UNIT_PRICE allowed prices to be negative. You ask why this is needed? Well in our store (Zen Cart) user can use his/hers accounts tokens in their order. These tokens are acquired by gift vouchers and are processed as negative items in the order. Other items that fall in to this category are customer group discounts and coupons that make discounts from the totals etc. They both are also processed as negative items.

Here's payload that fails:

[stamp] => 69-691805221041180
[reference] => 691805221041180
[amount] => 1750
[currency] => EUR
[language] => FI
[orderId] => 69
[items] => Array
(
    [0] => Array
        (
            [unitPrice] => 850
            [units] => 1
            [vatPercentage] => 24
            [productCode] => A123456789
            [description] => Asetoni 1 l
        )

    [1] => Array
        (
            [unitPrice] => 1000
            [units] => 1
            [vatPercentage] => 24
            [productCode] => -1
            [description] => Posti (Kotipaketti - kotiovelle klo 21 mennessä)
        )

    [2] => Array
        (
            [unitPrice] => -100
            [units] => 1
            [vatPercentage] => 0
            [productCode] => -1
            [description] => Tilin varat
        )

)
..

Paytrail Response:

Array (
    [status] => error
    [message] => Request payload schema validation failed. Validate request against the provided schema.
    [meta] => Array
        (
            [0] => instance.items[2].unitPrice must have a minimum value of 0
        )

)

Question: How can I get this to work with new API?
If I take this negative items[2] out of the payload or zero it, then the amount is not going to match total sum of items.

  [status] => error
  [message] => Sum of purchase item amounts does not match total amount.

Expected behaviour

item.unitPrice should also allow negative values.

Actual behaviour

item.unitPrice must have a minimum value of 0.

You can send negative prices such as discounts to the API by giving negative value as the item.units parameter.

The API documentation should be more clear about this issue.

@asiksami You are right, we need to update the documentation on that front. The new API doesn't support negative item.unitPrice.

@teemumantynen Even though it's technically possible to send negative value in the item.units, it's not supported scenario. Some of the payment methods will fail if you use negative units.

@loueranta-paytrail Checkout Finland's Magento 2 Module does use negative item.units. Paytrail's new API is directly based on Checkout Finland's API, so I've thought it should be just fine.
https://github.com/CheckoutFinland/checkout-finland-for-magento-2

C'mon. Your own module used negative item.units, and NOW you are telling others not to?

How do you plan to solve this issue? And when? A solution has been promised since at least 2019.

Negative row prices are absolutely needed! Customers will be furious if order info must combined into one item row, and they loose the ability to send actual VAT info per product.

@loueranta-paytrail So what is the supported scenario?

Please don't say that we need to do discount splitting for unitPrices? I'm no Magento specialist but looks like there is a test case for it in paytrail-for-adobe-commerce. If we could get prices eventually levelled to each item, this still would create a mismatch to the store and Paytrail's reports, right?

@teemumantynen We have removed the use of negative units in our own plugins a while back.

@asiksami All the discounts need to be calculated before you create the payment request.

I understand that the lack of support for negative rows makes things more complicated and we do have plans on supporting them in the future, but that requires major modifications to some of our background services, which is why I can't give an estimation when this will happen.

@loueranta-paytrail Ok. Thanks for answers! Good to know Paytrail has some plans to restore this property. 👍

We made a decision that we don't send item rows trough new Paytrail API, at least for now. The complexity calculating discounts to the items are too time consuming and even so it makes different reports on each end. Additional thing with this - at least with Zen Cart webstore - is that it allows you to sort or set where discount is calculated in the order. Discount can be calculated from sub total or it can be sub total + shipping + small packaging fees etc. This together with tokens used, which are straight currency from the order total, makes already my head hurt. 😅

But to not just whine about missing properties, the new Paytrail API compared to E2 has advantages that are welcomed, like keeping client information "behind the scenes" when creating new payments. So looking forward!

We just bumped into this "feature", annoying but with minor adjustments and calculations we can "work around" this.

@loueranta-paytrail What you absolutely must do is update paytrail documentation (https://docs.paytrail.com/#/?id=create-payment) to mention that item.unitPrice (an other similar) fields do not support negative values, this would clear confusion in cases where shops are have used discounts ant others as items.