Skip to content

Commit

Permalink
PR #39 Move Surcharge XML stuff to higher level.
Browse files Browse the repository at this point in the history
Moved to the DirectAuthorize class so it can be used for all
transaction types, rather than just Server Purchase.
  • Loading branch information
judgej committed Sep 5, 2017
1 parent e3d3dc9 commit e549379
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 17 deletions.
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');
}
}
15 changes: 0 additions & 15 deletions src/Message/ServerPurchaseRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
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']);
}
}
1 change: 0 additions & 1 deletion tests/Message/ServerPurchaseRequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ public function testInitialize()
);

$data = $request->getData();
$this->assertSame(self::SURCHARGE_XML, $data['surchargeXml']);
}

public function testSetSurchargeXml()
Expand Down

0 comments on commit e549379

Please sign in to comment.