Skip to content

Commit

Permalink
[klarna-checkout] Mark failed if error_code set in details.
Browse files Browse the repository at this point in the history
  • Loading branch information
makasim committed Dec 11, 2014
1 parent c605159 commit f64c215
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 5 deletions.
17 changes: 13 additions & 4 deletions Action/StatusAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand All @@ -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();
Expand Down
60 changes: 59 additions & 1 deletion Tests/Action/StatusActionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,6 @@ public function shouldMarkCapturedIfInvoiceNumberSet()
$action = new StatusAction();

$status = new GetBinaryStatus(array(
'status' => Constants::STATUS_CREATED,
'invoice_number' => 'aNum'
));

Expand All @@ -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());
}
}

0 comments on commit f64c215

Please sign in to comment.