From e685eff15ae9cb0bf3eb2a356ff22ac32856fd08 Mon Sep 17 00:00:00 2001 From: Thorben Nissen Date: Thu, 12 Jul 2018 11:22:00 +0200 Subject: [PATCH 1/3] [BUGFIX] Add missing (optional) parameters for PayDirekt * add `shippingAmount` and `orderAmount`: both are provided externally in `$data` array on initialize of request * remove `Giropay` from AuthorizeRequest: Giropay does not use AUTH and CAPTURE, so `PurchaseRequest` should be used instead --- src/Message/AuthorizeRequest.php | 46 +++++++++++++++++++++++++++++--- 1 file changed, 42 insertions(+), 4 deletions(-) diff --git a/src/Message/AuthorizeRequest.php b/src/Message/AuthorizeRequest.php index daf1b0d..81e7ff6 100644 --- a/src/Message/AuthorizeRequest.php +++ b/src/Message/AuthorizeRequest.php @@ -65,7 +65,6 @@ class AuthorizeRequest extends AbstractRequest Gateway::PAYMENT_TYPE_CREDIT_CARD, Gateway::PAYMENT_TYPE_DIRECTDEBIT, Gateway::PAYMENT_TYPE_MAESTRO, - Gateway::PAYMENT_TYPE_GIROPAY, Gateway::PAYMENT_TYPE_EPS, Gateway::PAYMENT_TYPE_PAYDIREKT, Gateway::PAYMENT_TYPE_PAYMENTPAGE, @@ -129,7 +128,9 @@ public function getPaydirektData($data = []) $data['customerId'] = $customerId; } - // TODO: shippingAmount - can we get this from the cart? Probably not. + if ($shippingAmount = $this->getShippingAmount()) { + $data['shippingAmount'] = $shippingAmount; + } if ($card = $this->getCard()) { if ($shippingFirstName = $card->getShippingFirstName()) { @@ -181,8 +182,9 @@ public function getPaydirektData($data = []) } } - // TODO: orderAmount probably from the cart, not the card. - // This is the total amount minus any shipping. + if ($orderAmount = $this->getOrderAmount()) { + $data['orderAmount'] = $orderAmount; + } // TODO: validate this is set (this is mandatory). $orderId = $this->getOrderId(); @@ -1023,6 +1025,42 @@ public function setOrderId($value) return $this->setParameter('orderId', $value); } + /** + * @return int|float The shipping amount + */ + public function getShippingAmount() + { + return $this->getParameter('shippingAmount'); + } + + /** + * @param int|float $shippingAmount + * + * @return $this + */ + public function setShippingAmount($shippingAmount) + { + return $this->setParameter('shippingAmount', $shippingAmount); + } + + /** + * @return int|float The order amount + */ + public function getOrderAmount() + { + return $this->getParameter('orderAmount'); + } + + /** + * @param int|float $orderAmount + * + * @return $this + */ + public function setOrderAmount($orderAmount) + { + return $this->setParameter('orderAmount', $orderAmount); + } + /** * @return string For Paydirekt */ From 053c5cfe7fd81f544e9f234e13f87d9bbe155321 Mon Sep 17 00:00:00 2001 From: Thorben Nissen Date: Thu, 12 Jul 2018 11:28:22 +0200 Subject: [PATCH 2/3] [BUGFIX] Add missing (optional) parameters for PayDirekt * use spaces for indent --- src/Message/AuthorizeRequest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Message/AuthorizeRequest.php b/src/Message/AuthorizeRequest.php index 81e7ff6..dc83fd1 100644 --- a/src/Message/AuthorizeRequest.php +++ b/src/Message/AuthorizeRequest.php @@ -1058,7 +1058,7 @@ public function getOrderAmount() */ public function setOrderAmount($orderAmount) { - return $this->setParameter('orderAmount', $orderAmount); + return $this->setParameter('orderAmount', $orderAmount); } /** From 856496072ff7cfa1815682d02408945a7387e713 Mon Sep 17 00:00:00 2001 From: Jason Judge Date: Thu, 12 Jul 2018 17:04:06 +0100 Subject: [PATCH 3/3] Added tests for PR #10 --- .../Message/AuthorizeRequestPaydirektTest.php | 18 +++++++++++++++++- tests/Message/PurchaseRequestPaydirektTest.php | 2 +- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/tests/Message/AuthorizeRequestPaydirektTest.php b/tests/Message/AuthorizeRequestPaydirektTest.php index 8d4d1dd..4fec91e 100644 --- a/tests/Message/AuthorizeRequestPaydirektTest.php +++ b/tests/Message/AuthorizeRequestPaydirektTest.php @@ -59,6 +59,8 @@ public function setUp() 'card' => $card, 'items' => $items, 'orderId' => 'ORD-123', + 'shippingAmount' => 1234, + 'orderAmount' => 5678, ]); } @@ -124,7 +126,7 @@ public function testHash() // This hash will change if the initializartion data changes. $data = $this->request->getData(); - $this->assertSame('c4c1c3581f266e3e0cb17b832685fa4c', $data['hash']); + $this->assertSame('1b1c0deca31a2a97c167bd7f9a116564', $data['hash']); $data = [ 'merchantId' => '1234567', @@ -198,4 +200,18 @@ public function testCurrencyDerived() $this->request->setCurrency('GBP'); $this->assertSame('GBP', $this->request->getCurrencyFallback()); } + + /** + * See https://github.com/academe/Omnipay-GiroCheckout/pull/10 + */ + public function testOrderAmounts() + { + //$this->request->setShippingAmount(1234); + //$this->request->setOrderAmount(5678); + + $data = $this->request->getData(); + + $this->assertSame(1234, $data['shippingAmount']); + $this->assertSame(5678, $data['orderAmount']); + } } diff --git a/tests/Message/PurchaseRequestPaydirektTest.php b/tests/Message/PurchaseRequestPaydirektTest.php index e6d6c2a..ffc9374 100644 --- a/tests/Message/PurchaseRequestPaydirektTest.php +++ b/tests/Message/PurchaseRequestPaydirektTest.php @@ -18,7 +18,7 @@ public function testHash() // This hash will change if the initializartion data changes. $data = $this->request->getData(); - $this->assertSame('239da494f2e276bb2c91b5a8aef79f42', $data['hash']); + $this->assertSame('152d3e9f968ffa14436fa09c8e97e67a', $data['hash']); } }