Skip to content
This repository has been archived by the owner on Mar 1, 2023. It is now read-only.

Commit

Permalink
Merge pull request #17 from comicrelief/better-notify-messages
Browse files Browse the repository at this point in the history
More specific error messages when failing to load a Notification's data; switch to `InvalidRequestException`
  • Loading branch information
ayanozturk authored Feb 7, 2018
2 parents f199682 + 760c8d4 commit 05af6eb
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 11 deletions.
13 changes: 7 additions & 6 deletions src/Omnipay/WorldpayCGHosted/Message/Notification.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace Omnipay\WorldpayCGHosted\Message;

use DOMDocument;
use Omnipay\Common\Exception\InvalidResponseException;
use Omnipay\Common\Exception\InvalidRequestException;
use Omnipay\Common\Message\AbstractResponse;

/**
Expand All @@ -28,23 +28,23 @@ class Notification extends AbstractResponse
/** @noinspection PhpMissingParentConstructorInspection
* @param string $data
* @param string $notificationOriginIp
* @throws InvalidResponseException on missing data
* @throws InvalidRequestException on missing or invalid data
*/
public function __construct($data, $notificationOriginIp)
{
$this->originIp = $notificationOriginIp;

if (empty($data)) {
throw new InvalidResponseException();
throw new InvalidRequestException('Notification data empty');
}

if (!is_string($data)) {
throw new InvalidResponseException('Data must be provided as a string');
throw new InvalidRequestException('Notification data not a string');
}

$responseDom = new DOMDocument;
if (!@$responseDom->loadXML($data)) {
throw new InvalidResponseException('Non-XML notification body received');
throw new InvalidRequestException('Notification data not loaded as XML');
}

$document = simplexml_import_dom($responseDom->documentElement);
Expand Down Expand Up @@ -139,7 +139,8 @@ public function getResponseStatusCode()
}

/**
* Indicates whether the given origin IP address matches *.worldpay.com based on reverse DNS.
* Indicates whether the given origin IP address matches *.worldpay.com based on reverse DNS, or IP as a fallback
* on containers that can't gethostbyaddr().
*
* @return bool
*/
Expand Down
2 changes: 1 addition & 1 deletion src/Omnipay/WorldpayCGHosted/Message/Response.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public function __construct(RequestInterface $request, $data)

$responseDom = new DOMDocument;
if (!@$responseDom->loadXML($data)) {
throw new InvalidResponseException('Non-XML notification response received');
throw new InvalidResponseException('Non-XML response received');
}

$this->data = @simplexml_import_dom(
Expand Down
8 changes: 4 additions & 4 deletions tests/Omnipay/WorldpayCGHosted/Message/NotificationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -219,8 +219,8 @@ public function testRefundRequest()
}

/**
* @expectedException \Omnipay\Common\Exception\InvalidResponseException
* @expectedExceptionMessage Non-XML notification body received
* @expectedException \Omnipay\Common\Exception\InvalidRequestException
* @expectedExceptionMessage Notification data not loaded as XML
*/
public function testNonXmlResponse()
{
Expand Down Expand Up @@ -251,8 +251,8 @@ public function testUnexpectedXmlBody()
}

/**
* @expectedException \Omnipay\Common\Exception\InvalidResponseException
* @expectedExceptionMessage Invalid response from payment gateway
* @expectedException \Omnipay\Common\Exception\InvalidRequestException
* @expectedExceptionMessage Notification data empty
*/
public function testEmptyData()
{
Expand Down

0 comments on commit 05af6eb

Please sign in to comment.