thephpleague / omnipay-mollie

Mollie driver for the Omnipay PHP payment processing library
MIT License
62 stars 38 forks source link

CreateOrderRequest does not allow negative discount amount #61

Closed villermen closed 5 years ago

villermen commented 5 years ago

When I supply negative amounts for the discount line in an order, an exception is thrown indicating this is not allowed. It is though: https://docs.mollie.com/orders/handling-discounts#discounts-and-vouchers.

lines parameter supplied to Gateway::createOrder():

array:5 [▼
  0 => array:6 [▼
    "name" => "***"
    "unitPrice" => "34.23"
    "quantity" => 3
    "totalAmount" => "102.69"
    "vatRate" => 21
    "vatAmount" => "17.82"
  ]
  1 => array:6 [▼
    "name" => "***"
    "unitPrice" => "9.99"
    "quantity" => 1
    "totalAmount" => "9.99"
    "vatRate" => 6
    "vatAmount" => "0.57"
  ]
  2 => array:6 [▼
    "name" => "***"
    "unitPrice" => "17.50"
    "quantity" => 1
    "totalAmount" => "17.50"
    "vatRate" => 6
    "vatAmount" => "0.99"
  ]
  3 => array:7 [▼
    "name" => "Verzendkosten"
    "unitPrice" => "7.50"
    "quantity" => 1
    "type" => "shipping_fee"
    "totalAmount" => "7.50"
    "vatRate" => 21
    "vatAmount" => "1.30"
  ]
  4 => array:7 [▼
    "name" => "Kortingscode 5EUROKORTING"
    "unitPrice" => "-5.00"
    "quantity" => 1
    "type" => "discount"
    "totalAmount" => "-5.00"
    "vatRate" => 21
    "vatAmount" => "-0.87"
  ]
]

Error information:

A negative amount is not allowed.

/code/vendor/omnipay/common/src/Common/Message/AbstractRequest.php:342
#0 /code/vendor/omnipay/common/src/Common/Message/AbstractRequest.php(488): Omnipay\Common\Message\AbstractRequest->getMoney('-5.00')
#1 /code/vendor/omnipay/mollie/src/Message/Request/AbstractMollieRequest.php(109): Omnipay\Common\Message\AbstractRequest->formatCurrency('-5.00')
#2 /code/vendor/omnipay/mollie/src/Message/Request/CreateOrderRequest.php(261): Omnipay\Mollie\Message\Request\AbstractMollieRequest->createAmountObject('-5.00')
#3 /code/vendor/omnipay/mollie/src/Message/Request/CreateOrderRequest.php(179): Omnipay\Mollie\Message\Request\CreateOrderRequest->getLines(Object(Omnipay\Common\ItemBag))
#4 /code/vendor/omnipay/common/src/Common/Message/AbstractRequest.php(732): Omnipay\Mollie\Message\Request\CreateOrderRequest->getData()
...: Omnipay\Common\Message\AbstractRequest->send()
villermen commented 5 years ago

As the amounts are required to be negative for this type of orderline, it is probably best to handle this inside this package. (The first thing that came to mind was allowing AbstractRequest::getMoney() in omnipay/common to format negative values.) It's probably better to just take the absolute value of the supplied amount and add the minus sign after formatting.

barryvdh commented 5 years ago

Does https://github.com/thephpleague/omnipay-mollie/pull/62 fix you issue?

villermen commented 5 years ago

Yeah, thanks.