From f64c215ef76890ffcbb2951a93641222552bd6a2 Mon Sep 17 00:00:00 2001 From: Kotlyar Maksim Date: Thu, 11 Dec 2014 11:02:54 +0000 Subject: [PATCH] [klarna-checkout] Mark failed if error_code set in details. --- Action/StatusAction.php | 17 ++++++--- Tests/Action/StatusActionTest.php | 60 ++++++++++++++++++++++++++++++- 2 files changed, 72 insertions(+), 5 deletions(-) diff --git a/Action/StatusAction.php b/Action/StatusAction.php index 4ee060f..bdecbfb 100644 --- a/Action/StatusAction.php +++ b/Action/StatusAction.php @@ -19,6 +19,19 @@ public function execute($request) RequestNotSupportedException::assertSupports($this, $request); $model = ArrayObject::ensureArrayObject($request->getModel()); + + if ($model['error_code']) { + $request->markFailed(); + + return; + } + + if ($model['invoice_number']) { + $request->markCaptured(); + + return; + } + if (false == $model['status'] || Constants::STATUS_CHECKOUT_INCOMPLETE == $model['status']) { $request->markNew(); @@ -31,11 +44,7 @@ public function execute($request) return; } - if (Constants::STATUS_CREATED == $model['status'] && $model['invoice_number']) { - $request->markCaptured(); - return; - } if (Constants::STATUS_CREATED == $model['status']) { $request->markAuthorized(); diff --git a/Tests/Action/StatusActionTest.php b/Tests/Action/StatusActionTest.php index 2c363da..5b43797 100644 --- a/Tests/Action/StatusActionTest.php +++ b/Tests/Action/StatusActionTest.php @@ -130,7 +130,6 @@ public function shouldMarkCapturedIfInvoiceNumberSet() $action = new StatusAction(); $status = new GetBinaryStatus(array( - 'status' => Constants::STATUS_CREATED, 'invoice_number' => 'aNum' )); @@ -141,4 +140,63 @@ public function shouldMarkCapturedIfInvoiceNumberSet() $this->assertTrue($status->isCaptured()); } + + /** + * @test + */ + public function shouldMarkFailedIfErrorCodeSet() + { + $action = new StatusAction(); + + $status = new GetBinaryStatus(array( + 'error_code' => 'aCode' + )); + + //guard + $status->markUnknown(); + + $action->execute($status); + + $this->assertTrue($status->isFailed()); + } + + /** + * @test + */ + public function shouldMarkFailedEvenIfInvoceNumberAndErrorCodeSet() + { + $action = new StatusAction(); + + $status = new GetBinaryStatus(array( + 'error_code' => 'aCode', + 'invoice_number' => 'aNum' + )); + + //guard + $status->markUnknown(); + + $action->execute($status); + + $this->assertTrue($status->isFailed()); + } + + /** + * @test + */ + public function shouldMarkFailedEvenIfStatusCreatedAndErrorCodeSet() + { + $action = new StatusAction(); + + $status = new GetBinaryStatus(array( + 'error_code' => 'aCode', + 'status' => Constants::STATUS_CREATED, + )); + + //guard + $status->markUnknown(); + + $action->execute($status); + + $this->assertTrue($status->isFailed()); + } } \ No newline at end of file