From 3c27417122b53e9c60b3dbe21cd59fb613a8f1dd Mon Sep 17 00:00:00 2001 From: Noel Light-Hilary Date: Fri, 1 Sep 2017 12:41:39 +0100 Subject: [PATCH] GP-657 - Provide `getCardType()` for Notifications --- .../WorldpayCGHosted/Message/Notification.php | 14 ++++++++++++++ .../WorldpayCGHosted/Message/NotificationTest.php | 1 + 2 files changed, 15 insertions(+) diff --git a/src/Omnipay/WorldpayCGHosted/Message/Notification.php b/src/Omnipay/WorldpayCGHosted/Message/Notification.php index 9faecd3..ef89f42 100644 --- a/src/Omnipay/WorldpayCGHosted/Message/Notification.php +++ b/src/Omnipay/WorldpayCGHosted/Message/Notification.php @@ -92,6 +92,20 @@ public function isValid() return ($this->originIsValid() && $this->hasStatus()); } + /** + * Gets the card type code in Worldpay format (e.g. 'ECMC-SSL') if available. + * + * @return string|null + */ + public function getCardType() + { + if (empty($this->getOrder()->payment->paymentMethod)) { + return null; + } + + return $this->getOrder()->payment->paymentMethod->__toString(); + } + /** * Gets the body of the response your app should provide to the Worldpay bot for this request. * diff --git a/tests/Omnipay/WorldpayCGHosted/Message/NotificationTest.php b/tests/Omnipay/WorldpayCGHosted/Message/NotificationTest.php index abcb747..90eb981 100644 --- a/tests/Omnipay/WorldpayCGHosted/Message/NotificationTest.php +++ b/tests/Omnipay/WorldpayCGHosted/Message/NotificationTest.php @@ -26,6 +26,7 @@ public function testAuthorisedValid() $this->assertEquals('AUTHORISED', $notification->getStatus()); $this->assertInternalType('string', $notification->getTransactionId()); $this->assertEquals('11001100-0000-0000-0000-000011110101', $notification->getTransactionId()); + $this->assertEquals('ECMC-SSL', $notification->getCardType()); $this->assertEquals('[OK]', $notification->getResponseBody()); $this->assertEquals(200, $notification->getResponseStatusCode());