From 19b92638cf223d9d69322519eff4d30faf60d350 Mon Sep 17 00:00:00 2001 From: James Willans Date: Mon, 17 Aug 2015 11:46:29 +0100 Subject: [PATCH 1/8] Added support for SurchargeXML purchase parameter --- src/Message/ServerPurchaseRequest.php | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/Message/ServerPurchaseRequest.php b/src/Message/ServerPurchaseRequest.php index 913592d..bfbebb1 100644 --- a/src/Message/ServerPurchaseRequest.php +++ b/src/Message/ServerPurchaseRequest.php @@ -8,4 +8,28 @@ class ServerPurchaseRequest extends ServerAuthorizeRequest { protected $action = 'PAYMENT'; + + public function setSurchargeXml($surchargeXml) + { + $this->setParameter('SurchargeXML', $surchargeXml); + } + + public function getSurchargeXml() + { + return $this->getParameter('SurchargeXML'); + } + + public function getData() + { + $data = parent::getData(); + + $surchargeXml = $this->getSurchargeXml(); + if($surchargeXml){ + $data['SurchargeXML'] = $this->getSurchargeXml(); + } + + return $data; + } + + } From 8e86038747518921582985df810b0b9d96d75b7f Mon Sep 17 00:00:00 2001 From: James Willans Date: Mon, 17 Aug 2015 12:11:42 +0100 Subject: [PATCH 2/8] Added unit test for SurchargeXML purchase parameter --- tests/Message/ServerPurchaseRequestTest.php | 47 +++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 tests/Message/ServerPurchaseRequestTest.php diff --git a/tests/Message/ServerPurchaseRequestTest.php b/tests/Message/ServerPurchaseRequestTest.php new file mode 100644 index 0000000..1d7d7d0 --- /dev/null +++ b/tests/Message/ServerPurchaseRequestTest.php @@ -0,0 +1,47 @@ +VISA2.50'; + + public function testInitialize() + { + $request = new ServerPurchaseRequest($this->getHttpClient(), $this->getHttpRequest()); + $request->initialize( + array( + 'returnUrl' => 'http://www.example.com/return', + 'amount' => '12.00', + 'transactionId' => '123', + 'SurchargeXML' => self::SURCHARGE_XML, + 'card' => $this->getValidCard(), + ) + ); + + $data = $request->getData(); + $this->assertSame(self::SURCHARGE_XML, $data['SurchargeXML']); + } + + public function setSetSurchargeXml() + { + $request = new ServerPurchaseRequest($this->getHttpClient(), $this->getHttpRequest()); + $request->initialize( + array( + 'returnUrl' => 'https://www.example.com/return', + 'amount' => '12.00', + 'transactionId' => '123', + 'card' => $this->getValidCard(), + ) + ); + + $request->setSurchargeXml(self::SURCHARGE_XML); + + $data = $request->getData(); + $this->assertSame(self::SURCHARGE_XML, $data['SurchargeXML']); + } + +} \ No newline at end of file From d4e2bf1cbc0f088ce6a7f4a70145af2927f438ea Mon Sep 17 00:00:00 2001 From: James Willans Date: Mon, 17 Aug 2015 12:51:30 +0100 Subject: [PATCH 3/8] Cleaned up whitespace to comply with PSR-2 CS --- src/Message/ServerPurchaseRequest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Message/ServerPurchaseRequest.php b/src/Message/ServerPurchaseRequest.php index bfbebb1..79044bb 100644 --- a/src/Message/ServerPurchaseRequest.php +++ b/src/Message/ServerPurchaseRequest.php @@ -7,6 +7,7 @@ */ class ServerPurchaseRequest extends ServerAuthorizeRequest { + protected $action = 'PAYMENT'; public function setSurchargeXml($surchargeXml) @@ -31,5 +32,4 @@ public function getData() return $data; } - -} +} \ No newline at end of file From 2e844e5fdd4eb39c67835ab7e8e9034fe4c6e2b5 Mon Sep 17 00:00:00 2001 From: James Willans Date: Mon, 17 Aug 2015 13:02:22 +0100 Subject: [PATCH 4/8] PSR-2 CS fix --- src/Message/ServerPurchaseRequest.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Message/ServerPurchaseRequest.php b/src/Message/ServerPurchaseRequest.php index 79044bb..a534adc 100644 --- a/src/Message/ServerPurchaseRequest.php +++ b/src/Message/ServerPurchaseRequest.php @@ -25,7 +25,8 @@ public function getData() $data = parent::getData(); $surchargeXml = $this->getSurchargeXml(); - if($surchargeXml){ + if($surchargeXml) + { $data['SurchargeXML'] = $this->getSurchargeXml(); } From 3b0710c8613d8f2d92bf9fd234065e17b7b53374 Mon Sep 17 00:00:00 2001 From: James Willans Date: Mon, 17 Aug 2015 14:05:47 +0100 Subject: [PATCH 5/8] Changed SurchargeXML parameter to surchargeXml --- src/Message/ServerPurchaseRequest.php | 12 +++++------- tests/Message/ServerPurchaseRequestTest.php | 6 +++--- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/src/Message/ServerPurchaseRequest.php b/src/Message/ServerPurchaseRequest.php index a534adc..b33a31b 100644 --- a/src/Message/ServerPurchaseRequest.php +++ b/src/Message/ServerPurchaseRequest.php @@ -12,12 +12,12 @@ class ServerPurchaseRequest extends ServerAuthorizeRequest public function setSurchargeXml($surchargeXml) { - $this->setParameter('SurchargeXML', $surchargeXml); + $this->setParameter('surchargeXml', $surchargeXml); } public function getSurchargeXml() { - return $this->getParameter('SurchargeXML'); + return $this->getParameter('surchargeXml'); } public function getData() @@ -25,12 +25,10 @@ public function getData() $data = parent::getData(); $surchargeXml = $this->getSurchargeXml(); - if($surchargeXml) - { - $data['SurchargeXML'] = $this->getSurchargeXml(); + if ($surchargeXml) { + $data['surchargeXml'] = $this->getSurchargeXml(); } return $data; } - -} \ No newline at end of file +} diff --git a/tests/Message/ServerPurchaseRequestTest.php b/tests/Message/ServerPurchaseRequestTest.php index 1d7d7d0..8d7628e 100644 --- a/tests/Message/ServerPurchaseRequestTest.php +++ b/tests/Message/ServerPurchaseRequestTest.php @@ -17,13 +17,13 @@ public function testInitialize() 'returnUrl' => 'http://www.example.com/return', 'amount' => '12.00', 'transactionId' => '123', - 'SurchargeXML' => self::SURCHARGE_XML, + 'surchargeXml' => self::SURCHARGE_XML, 'card' => $this->getValidCard(), ) ); $data = $request->getData(); - $this->assertSame(self::SURCHARGE_XML, $data['SurchargeXML']); + $this->assertSame(self::SURCHARGE_XML, $data['surchargeXml']); } public function setSetSurchargeXml() @@ -41,7 +41,7 @@ public function setSetSurchargeXml() $request->setSurchargeXml(self::SURCHARGE_XML); $data = $request->getData(); - $this->assertSame(self::SURCHARGE_XML, $data['SurchargeXML']); + $this->assertSame(self::SURCHARGE_XML, $data['surchargeXml']); } } \ No newline at end of file From ef4fe637b36d65bd39b365367d471b2ffbbf5735 Mon Sep 17 00:00:00 2001 From: James Willans Date: Fri, 21 Aug 2015 16:30:25 +0100 Subject: [PATCH 6/8] Fixed typo in unit test --- tests/Message/ServerPurchaseRequestTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Message/ServerPurchaseRequestTest.php b/tests/Message/ServerPurchaseRequestTest.php index 8d7628e..ba74410 100644 --- a/tests/Message/ServerPurchaseRequestTest.php +++ b/tests/Message/ServerPurchaseRequestTest.php @@ -26,7 +26,7 @@ public function testInitialize() $this->assertSame(self::SURCHARGE_XML, $data['surchargeXml']); } - public function setSetSurchargeXml() + public function testSetSurchargeXml() { $request = new ServerPurchaseRequest($this->getHttpClient(), $this->getHttpRequest()); $request->initialize( From e54937968a624d0f890378f76e34e6e85e1f338b Mon Sep 17 00:00:00 2001 From: Jason Judge Date: Tue, 5 Sep 2017 16:15:32 +0100 Subject: [PATCH 7/8] PR #39 Move Surcharge XML stuff to higher level. Moved to the DirectAuthorize class so it can be used for all transaction types, rather than just Server Purchase. --- src/Message/DirectAuthorizeRequest.php | 25 ++++++++++++++++++++ src/Message/ServerPurchaseRequest.php | 15 ------------ tests/Message/DirectAuthorizeRequestTest.php | 4 ++++ tests/Message/ServerAuthorizeRequestTest.php | 8 ++++++- tests/Message/ServerPurchaseRequestTest.php | 1 - 5 files changed, 36 insertions(+), 17 deletions(-) diff --git a/src/Message/DirectAuthorizeRequest.php b/src/Message/DirectAuthorizeRequest.php index a1b3b84..35b8b54 100644 --- a/src/Message/DirectAuthorizeRequest.php +++ b/src/Message/DirectAuthorizeRequest.php @@ -79,6 +79,12 @@ protected function getBaseAuthorizeData() } } + $surchargeXml = $this->getSurchargeXml(); + + if ($surchargeXml) { + $data['surchargeXml'] = $this->getSurchargeXml(); + } + return $data; } @@ -157,4 +163,23 @@ protected function getCardBrand() return $brand; } + + /** + * Set the raw surcharge XML field. + * + * @param string $surchargeXml The XML data formatted as per Sage Pay documentation. + * @return $this + */ + public function setSurchargeXml($surchargeXml) + { + return $this->setParameter('surchargeXml', $surchargeXml); + } + + /** + * @return string The XML surchange data as set. + */ + public function getSurchargeXml() + { + return $this->getParameter('surchargeXml'); + } } diff --git a/src/Message/ServerPurchaseRequest.php b/src/Message/ServerPurchaseRequest.php index b33a31b..500ea12 100644 --- a/src/Message/ServerPurchaseRequest.php +++ b/src/Message/ServerPurchaseRequest.php @@ -10,25 +10,10 @@ class ServerPurchaseRequest extends ServerAuthorizeRequest protected $action = 'PAYMENT'; - public function setSurchargeXml($surchargeXml) - { - $this->setParameter('surchargeXml', $surchargeXml); - } - - public function getSurchargeXml() - { - return $this->getParameter('surchargeXml'); - } - public function getData() { $data = parent::getData(); - $surchargeXml = $this->getSurchargeXml(); - if ($surchargeXml) { - $data['surchargeXml'] = $this->getSurchargeXml(); - } - return $data; } } diff --git a/tests/Message/DirectAuthorizeRequestTest.php b/tests/Message/DirectAuthorizeRequestTest.php index 4c98f7b..815d2d9 100644 --- a/tests/Message/DirectAuthorizeRequestTest.php +++ b/tests/Message/DirectAuthorizeRequestTest.php @@ -6,6 +6,8 @@ class DirectAuthorizeRequestTest extends TestCase { + const SURCHARGE_XML = 'VISA2.50'; + /** * @var \Omnipay\Common\Message\AbstractRequest $request */ @@ -21,6 +23,7 @@ public function setUp() 'amount' => '12.00', 'currency' => 'GBP', 'transactionId' => '123', + 'surchargeXml' => self::SURCHARGE_XML, 'card' => $this->getValidCard(), ) ); @@ -60,6 +63,7 @@ public function testGetData() $this->assertSame('3F7A4119-8671-464F-A091-9E59EB47B80C', $data['ReferrerID']); $this->assertSame('Vendor secret codes', $data['VendorData']); $this->assertSame('Mr E User', $data['CardHolder']); + $this->assertSame(self::SURCHARGE_XML, $data['surchargeXml']); } public function testNoBasket() diff --git a/tests/Message/ServerAuthorizeRequestTest.php b/tests/Message/ServerAuthorizeRequestTest.php index 5e78024..8f689b9 100644 --- a/tests/Message/ServerAuthorizeRequestTest.php +++ b/tests/Message/ServerAuthorizeRequestTest.php @@ -6,6 +6,8 @@ class ServerAuthorizeRequestTest extends TestCase { + const SURCHARGE_XML = 'VISA2.50'; + public function setUp() { parent::setUp(); @@ -15,7 +17,10 @@ public function setUp() array( 'amount' => '12.00', 'transactionId' => '123', + 'surchargeXml' => self::SURCHARGE_XML, 'card' => $this->getValidCard(), + 'notifyUrl' => 'https://www.example.com/return', + 'profile' => 'LOW', ) ); } @@ -26,11 +31,12 @@ public function testProfile() $this->assertSame('NORMAL', $this->request->getProfile()); } - public function getData() + public function testGetData() { $data = $this->request->getData(); $this->assertSame('https://www.example.com/return', $data['NotificationURL']); $this->assertSame('LOW', $data['Profile']); + $this->assertSame(self::SURCHARGE_XML, $data['surchargeXml']); } } diff --git a/tests/Message/ServerPurchaseRequestTest.php b/tests/Message/ServerPurchaseRequestTest.php index ba74410..2f416a4 100644 --- a/tests/Message/ServerPurchaseRequestTest.php +++ b/tests/Message/ServerPurchaseRequestTest.php @@ -23,7 +23,6 @@ public function testInitialize() ); $data = $request->getData(); - $this->assertSame(self::SURCHARGE_XML, $data['surchargeXml']); } public function testSetSurchargeXml() From 79ce04d312a3f3ed6856113fa5cef4dbbf149538 Mon Sep 17 00:00:00 2001 From: Jason Judge Date: Tue, 5 Sep 2017 16:26:53 +0100 Subject: [PATCH 8/8] Removed PHP 5.3 from travis, as this does not seem to be fully working now. --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 67753ce..828c859 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,10 +1,10 @@ language: php php: - - 5.3 - 5.4 - 5.5 - 5.6 + - 7.1 - hhvm before_script: