«PayPal gateway has rejected request. The totals of the cart item amounts do not match order amounts» (2)

In a Magento 2.1 store we programmatically add a discount to the order. Paypal, however, refuses the transaction with the message

PayPal gateway has rejected request. The totals of the cart item amounts do not match order amounts (#10413: Transaction refused because of an invalid argument. See additional error messages for details).

When adding a discount code manually in the frontend Paypal works fine. Looking at the database comparing the quotes with the programmatic discount and the discount code there is no difference.

Other payment gateways work correctly.

Looks like a Magento (Paypal?) bug. Any hints?

Thanks

It is not a PayPal or Magento bug. It is your bug.
You should reread the message:

The totals of the cart item amounts do not match order amounts

PayPal does check these amounts, and if you do some hacks, you should match the total amount and the cart items amouts.

Dmitry, thank you. We fully understand this. That is why we compared quotes with our discounts to quotes with user-added discounts. There is no difference at all in database. Do we have to look for other tables where information is stored concerning pricing / discounts?