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: 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 913592d..500ea12 100644 --- a/src/Message/ServerPurchaseRequest.php +++ b/src/Message/ServerPurchaseRequest.php @@ -7,5 +7,13 @@ */ class ServerPurchaseRequest extends ServerAuthorizeRequest { + protected $action = 'PAYMENT'; + + public function getData() + { + $data = parent::getData(); + + 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 new file mode 100644 index 0000000..2f416a4 --- /dev/null +++ b/tests/Message/ServerPurchaseRequestTest.php @@ -0,0 +1,46 @@ +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(); + } + + public function testSetSurchargeXml() + { + $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