Skip to content

Commit

Permalink
credit card: extract test card generation
Browse files Browse the repository at this point in the history
Since there's no way to inform a valid cardhash in the backend. This
will return a card object for e2e tests only if the `PAGARME_DEVELOPMENT` environment variable has the value `enabled`. Otherwise throw an exception
  • Loading branch information
Leonam Pereira Dias committed Jun 22, 2018
1 parent d65eecb commit e75bdb6
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions app/code/community/PagarMe/CreditCard/Model/Creditcard.php
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,21 @@ public function isInstallmentsValid($installments)
}
}

private function getTestCard()
{
$card = null;
if (getenv('PAGARME_DEVELOPMENT') === 'enabled') {
$card = $this->sdk->card()->create(
'4242424242424242',
'Livia Nascimento',
'0224',
'123'
);
}

return $card;
}

/**
* @param string $cardHash
*
Expand All @@ -194,15 +209,7 @@ public function generateCard($cardHash)
->createFromHash($cardHash);
return $card;
} catch (\Exception $exception) {
$card = null;
if (getenv('PAGARME_DEVELOPMENT') === 'enabled') {
$card = $this->sdk->card()->create(
'4242424242424242',
'Livia Nascimento',
'0224',
'123'
);
}
$card = $this->getTestCard();
if($card instanceof \PagarMe\Sdk\Card\Card) {
return $card;
}
Expand Down

0 comments on commit e75bdb6

Please sign in to comment.