Skip to content
This repository has been archived by the owner on Oct 30, 2020. It is now read-only.

Commit

Permalink
Adds vault purchase test
Browse files Browse the repository at this point in the history
  • Loading branch information
Craig Paul committed Oct 23, 2016
1 parent 8f186ef commit 35c0a40
Showing 1 changed file with 46 additions and 20 deletions.
66 changes: 46 additions & 20 deletions tests/VaultTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,16 @@

class VaultTest extends TestCase
{
/**
* @var \CraigPaul\Moneris\CreditCard
*/
protected $card;

/**
* @var array
*/
protected $params;

/**
* @var \CraigPaul\Moneris\Vault
*/
Expand All @@ -20,6 +30,11 @@ public function setUp()
{
parent::setUp();

$this->card = CreditCard::create($this->visa, '2012');
$this->params = [
'order_id' => uniqid('1234-567890', true),
'amount' => '1.00',
];
$this->vault = Vault::create($this->id, $this->token, $this->environment);
}

Expand Down Expand Up @@ -48,9 +63,7 @@ public function it_can_instantiate_via_a_static_create_method()
/** @test */
public function it_can_add_a_credit_card_to_the_moneris_vault_and_returns_a_data_key_for_storage()
{
$card = CreditCard::create($this->visa, '2012');

$response = $this->vault->add($card);
$response = $this->vault->add($this->card);
$receipt = $response->receipt();

$this->assertTrue($response->successful);
Expand All @@ -60,16 +73,14 @@ public function it_can_add_a_credit_card_to_the_moneris_vault_and_returns_a_data
/** @test */
public function it_can_update_a_credit_card_in_the_moneris_vault_and_returns_a_data_key_for_storage()
{
$card = CreditCard::create($this->visa, '2012');

$response = $this->vault->add($card);
$response = $this->vault->add($this->card);
$key = $response->receipt()->DataKey;

$this->assertEquals('2012', $response->transaction->params['expdate']);

$card->expiry = '2112';
$this->card->expiry = '2112';

$response = $this->vault->update($key, $card);
$response = $this->vault->update($key, $this->card);
$receipt = $response->receipt();

$this->assertTrue($response->successful);
Expand All @@ -81,9 +92,7 @@ public function it_can_update_a_credit_card_in_the_moneris_vault_and_returns_a_d
/** @test */
public function it_can_delete_a_credit_card_from_the_moneris_vault_and_returns_a_data_key_for_storage()
{
$card = CreditCard::create($this->visa, '2012');

$response = $this->vault->add($card);
$response = $this->vault->add($this->card);
$key = $response->receipt()->DataKey;

$response = $this->vault->delete($key);
Expand All @@ -95,7 +104,8 @@ public function it_can_delete_a_credit_card_from_the_moneris_vault_and_returns_a
}

/** @test */
public function it_can_tokenize_a_previous_transaction_to_add_the_transactions_credit_card_in_the_moneris_vault_and_returns_a_data_key_for_storage()
public function it_can_tokenize_a_previous_transaction_to_add_the_transactions_credit_card_in_the_moneris_vault_and_returns_a_data_key_for_storage(
)
{
$gateway = Moneris::create($this->id, $this->token, ['environment' => Moneris::ENV_TESTING]);

Expand All @@ -114,11 +124,10 @@ public function it_can_tokenize_a_previous_transaction_to_add_the_transactions_c
}

/** @test */
public function it_can_peek_into_the_vault_and_retrieve_a_masked_credit_card_from_the_moneris_vault_with_a_valid_data_key()
public function it_can_peek_into_the_vault_and_retrieve_a_masked_credit_card_from_the_moneris_vault_with_a_valid_data_key(
)
{
$card = CreditCard::create($this->visa, '2012');

$response = $this->vault->add($card);
$response = $this->vault->add($this->card);
$key = $response->receipt()->DataKey;

$response = $this->vault->peek($key);
Expand All @@ -134,11 +143,10 @@ public function it_can_peek_into_the_vault_and_retrieve_a_masked_credit_card_fro
}

/** @test */
public function it_can_peek_into_the_vault_and_retrieve_a_full_credit_card_from_the_moneris_vault_with_a_valid_data_key()
public function it_can_peek_into_the_vault_and_retrieve_a_full_credit_card_from_the_moneris_vault_with_a_valid_data_key(
)
{
$card = CreditCard::create($this->visa, '2012');

$response = $this->vault->add($card);
$response = $this->vault->add($this->card);
$key = $response->receipt()->DataKey;

$response = $this->vault->peek($key, true);
Expand Down Expand Up @@ -168,4 +176,22 @@ public function it_can_retrieve_all_expiring_credit_cards_from_the_moneris_vault
$this->assertTrue($response->successful);
$this->assertGreaterThan(0, count($receipt->ResolveData));
}

/** @test */
public function it_can_make_a_purchase_with_a_credit_card_stored_in_the_moneris_vault()
{
$response = $this->vault->add($this->card);
$key = $response->receipt()->DataKey;

$params = array_merge($this->params, [
'data_key' => $key,
]);

$response = $this->vault->purchase($params);
$receipt = $response->receipt();

$this->assertTrue($response->successful);
$this->assertEquals($key, $receipt->DataKey);
$this->assertEquals('true', $receipt->Complete);
}
}

0 comments on commit 35c0a40

Please sign in to comment.