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()