Skip to content

Commit

Permalink
Issue #3 Support isCancelled()
Browse files Browse the repository at this point in the history
  • Loading branch information
judgej committed Aug 20, 2018
1 parent 925575c commit 5e24d8f
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 12 deletions.
10 changes: 10 additions & 0 deletions src/Traits/HasCompleteResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,16 @@ public function isSuccessful()
return $status === Gateway::STATUS_SUCCESS || $status === Gateway::STATUS_ACCEPTED;
}

/**
* @return bool
*/
public function isCancelled()
{
$status = $this->getStatus();

return $status === Gateway::STATUS_CANCEL;
}

/**
* CHECKME: is the virtualCardno the same thing, but for specific payment methods?
*
Expand Down
53 changes: 41 additions & 12 deletions tests/Message/CompleteResponseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public function setUp()
{
parent::setUp();

$this->response = new CompleteResponse(
$this->responseSuccess = new CompleteResponse(
$this->getMockRequest(),
[
"merchantId" => "1100016000",
Expand Down Expand Up @@ -44,20 +44,49 @@ public function setUp()
"expm" => "12",
]
);

$this->responseCancel = new CompleteResponse(
$this->getMockRequest(),
[
"maskedCC" => "424242xxxxxx4242",
"merchantId" => "1100016183",
"aliasCC" => "70119122433810042",
"uppTermsLink" => "https://example.co.uk/",
"currency" => "GBP",
"amount" => "2250",
"uppReturnMaskedCC" => "yes",
"uppWebResponseMethod" => "POST",
"uppTransactionId" => "180820155020472779",
"language" => "en",
"theme" => "DT2015",
"refno" => "134655588975",
"testOnly" => "yes",
"pmethod" => "VIS",
"sign" => "66e480fd751555d707103fe0f66b7bfef8e55a416a57ff6f33f4d2daf58469d5",
"status" => "cancel",
"uppMsgType" => "web",
]
);
}

public function testSuccess()
{
$this->assertSame('4242', $this->response->getNumberLastFour());
$this->assertSame('XXXXXXXXXXXX4242', $this->response->getNumberMasked());
$this->assertSame('424242xxxxxx4242', $this->response->getNumberMasked(null));
$this->assertTrue($this->response->isSuccessful());
$this->assertFalse($this->response->isRedirect());
$this->assertSame(12, $this->response->getExpiryMonth());
$this->assertSame(18, $this->response->getExpiryYear());
$this->assertSame('12/18', $this->response->getExpiryDate('m/y'));
$this->assertSame('e7e86bee-0ced-43b8-9ee9-e7fbb8d4ef31', $this->response->getTransactionId());
$this->assertSame('180317175618647060', $this->response->getTransactionReference());
$this->assertSame('VIS', $this->response->getUsedPaymentMethod());
$this->assertSame('4242', $this->responseSuccess->getNumberLastFour());
$this->assertSame('XXXXXXXXXXXX4242', $this->responseSuccess->getNumberMasked());
$this->assertSame('424242xxxxxx4242', $this->responseSuccess->getNumberMasked(null));
$this->assertTrue($this->responseSuccess->isSuccessful());
$this->assertFalse($this->responseSuccess->isRedirect());
$this->assertSame(12, $this->responseSuccess->getExpiryMonth());
$this->assertSame(18, $this->responseSuccess->getExpiryYear());
$this->assertSame('12/18', $this->responseSuccess->getExpiryDate('m/y'));
$this->assertSame('e7e86bee-0ced-43b8-9ee9-e7fbb8d4ef31', $this->responseSuccess->getTransactionId());
$this->assertSame('180317175618647060', $this->responseSuccess->getTransactionReference());
$this->assertSame('VIS', $this->responseSuccess->getUsedPaymentMethod());
}

public function testCancelled()
{
$this->assertFalse($this->responseCancel->isSuccessful());
$this->assertTrue($this->responseCancel->isCancelled());
}
}

0 comments on commit 5e24d8f

Please sign in to comment.