Skip to content

Commit

Permalink
Merge pull request #91 from academe/pr39
Browse files Browse the repository at this point in the history
Support SurchargeXML field
  • Loading branch information
judgej authored Sep 5, 2017
2 parents 4ca4847 + 79ce04d commit 8e14e23
Show file tree
Hide file tree
Showing 6 changed files with 91 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
language: php

php:
- 5.3
- 5.4
- 5.5
- 5.6
- 7.1
- hhvm

before_script:
Expand Down
25 changes: 25 additions & 0 deletions src/Message/DirectAuthorizeRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,12 @@ protected function getBaseAuthorizeData()
}
}

$surchargeXml = $this->getSurchargeXml();

if ($surchargeXml) {
$data['surchargeXml'] = $this->getSurchargeXml();
}

return $data;
}

Expand Down Expand Up @@ -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');
}
}
8 changes: 8 additions & 0 deletions src/Message/ServerPurchaseRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,13 @@
*/
class ServerPurchaseRequest extends ServerAuthorizeRequest
{

protected $action = 'PAYMENT';

public function getData()
{
$data = parent::getData();

return $data;
}
}
4 changes: 4 additions & 0 deletions tests/Message/DirectAuthorizeRequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

class DirectAuthorizeRequestTest extends TestCase
{
const SURCHARGE_XML = '<surcharges><surcharge><paymentType>VISA</paymentType><percentage>2.50</percentage></surcharge></surcharges>';

/**
* @var \Omnipay\Common\Message\AbstractRequest $request
*/
Expand All @@ -21,6 +23,7 @@ public function setUp()
'amount' => '12.00',
'currency' => 'GBP',
'transactionId' => '123',
'surchargeXml' => self::SURCHARGE_XML,
'card' => $this->getValidCard(),
)
);
Expand Down Expand Up @@ -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()
Expand Down
8 changes: 7 additions & 1 deletion tests/Message/ServerAuthorizeRequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

class ServerAuthorizeRequestTest extends TestCase
{
const SURCHARGE_XML = '<surcharges><surcharge><paymentType>VISA</paymentType><percentage>2.50</percentage></surcharge></surcharges>';

public function setUp()
{
parent::setUp();
Expand All @@ -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',
)
);
}
Expand All @@ -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']);
}
}
46 changes: 46 additions & 0 deletions tests/Message/ServerPurchaseRequestTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php

namespace Omnipay\SagePay\Message;

use Omnipay\Tests\TestCase;

class ServerPurchaseRequestTest extends TestCase
{

const SURCHARGE_XML = '<surcharges><surcharge><paymentType>VISA</paymentType><percentage>2.50</percentage></surcharge></surcharges>';

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']);
}

}

0 comments on commit 8e14e23

Please sign in to comment.