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

Commit

Permalink
Adds purchase with customer info tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Craig Paul committed Oct 26, 2016
1 parent 01846f8 commit fbff9e7
Show file tree
Hide file tree
Showing 2 changed files with 114 additions and 46 deletions.
79 changes: 56 additions & 23 deletions tests/GatewayTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,20 @@

class GatewayTest extends TestCase
{
/**
* The billing / shipping info for customer info requests.
*
* @var array
*/
protected $billing;

/**
* The customer info for customer info requests.
*
* @var array
*/
protected $customer;

/**
* The Moneris gateway.
*
Expand All @@ -31,6 +45,7 @@ public function setUp()
{
parent::setUp();

$faker = Faker::create();
$params = ['environment' => $this->environment];
$this->gateway = Moneris::create($this->id, $this->token, $params);
$this->params = [
Expand All @@ -39,6 +54,28 @@ public function setUp()
'credit_card' => $this->visa,
'expdate' => '2012',
];
$this->billing = [
'first_name' => $faker->firstName,
'last_name' => $faker->lastName,
'company_name' => $faker->company,
'address' => $faker->streetAddress,
'city' => $faker->city,
'province' => 'SK',
'postal_code' => 'X0X0X0',
'country' => 'Canada',
'phone_number' => '555-555-5555',
'fax' => '555-555-5555',
'tax1' => '1.01',
'tax2' => '1.02',
'tax3' => '1.03',
'shipping_cost' => '9.99',
];
$this->customer = [
'email' => '[email protected]',
'instructions' => $faker->sentence(mt_rand(3, 6)),
'billing' => $this->billing,
'shipping' => $this->billing
];
}

/** @test */
Expand Down Expand Up @@ -69,6 +106,23 @@ public function it_can_make_a_purchase_and_receive_a_response()
$this->assertTrue($response->successful);
}

/** @test */
public function it_can_make_a_purchase_with_provided_customer_information_and_receive_a_response()
{
$params = array_merge($this->params, [
'cust_id' => uniqid('customer-', true),
'cust_info' => $this->customer,
]);

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

$this->assertEquals(Response::class, get_class($response));
$this->assertTrue($response->successful);
$this->assertTrue($receipt->read('complete'));
$this->assertNotNull($receipt->read('transaction'));
}

/** @test */
public function it_can_make_a_cvd_secured_purchase_and_receive_a_response()
{
Expand Down Expand Up @@ -119,32 +173,11 @@ public function it_can_pre_authorize_a_purchase_and_receive_a_response()
/** @test */
public function it_can_pre_authorize_a_purchase_with_provided_customer_information_and_receive_a_response()
{
$faker = Faker::create();
$customer = [
'first_name' => $faker->firstName,
'last_name' => $faker->lastName,
'company_name' => $faker->company,
'address' => $faker->streetAddress,
'city' => $faker->city,
'province' => 'SK',
'postal_code' => 'X0X0X0',
'country' => 'Canada',
'phone_number' => '555-555-5555',
'fax' => '555-555-5555',
'tax1' => '1.01',
'tax2' => '1.02',
'tax3' => '1.03',
'shipping_cost' => '9.99',
];
$params = array_merge($this->params, [
'cust_id' => uniqid('customer-', true),
'cust_info' => [
'email' => '[email protected]',
'instructions' => $faker->sentence(mt_rand(3, 6)),
'billing' => $customer,
'shipping' => $customer
],
'cust_info' => $this->customer,
]);

$response = $this->gateway->preauth($params);
$receipt = $response->receipt();

Expand Down
81 changes: 58 additions & 23 deletions tests/VaultTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,25 @@

class VaultTest extends TestCase
{
/**
* The billing / shipping info for customer info requests.
*
* @var array
*/
protected $billing;

/**
* @var \CraigPaul\Moneris\CreditCard
*/
protected $card;

/**
* The customer info for customer info requests.
*
* @var array
*/
protected $customer;

/**
* @var array
*/
Expand All @@ -32,12 +46,35 @@ public function setUp()
{
parent::setUp();

$faker = Faker::create();
$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);
$this->billing = [
'first_name' => $faker->firstName,
'last_name' => $faker->lastName,
'company_name' => $faker->company,
'address' => $faker->streetAddress,
'city' => $faker->city,
'province' => 'SK',
'postal_code' => 'X0X0X0',
'country' => 'Canada',
'phone_number' => '555-555-5555',
'fax' => '555-555-5555',
'tax1' => '1.01',
'tax2' => '1.02',
'tax3' => '1.03',
'shipping_cost' => '9.99',
];
$this->customer = [
'email' => '[email protected]',
'instructions' => $faker->sentence(mt_rand(3, 6)),
'billing' => $this->billing,
'shipping' => $this->billing
];
}

/** @test */
Expand Down Expand Up @@ -245,6 +282,26 @@ public function it_can_make_a_purchase_with_a_credit_card_stored_in_the_moneris_
$this->assertEquals(true, $receipt->read('complete'));
}

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

$params = array_merge($this->params, [
'data_key' => $key,
'cust_id' => uniqid('customer-', true),
'cust_info' => $this->customer,
]);

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

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

/** @test */
public function it_can_submit_a_cvd_secured_purchase_with_a_credit_card_stored_in_the_moneris_vault()
{
Expand Down Expand Up @@ -315,32 +372,10 @@ public function it_can_pre_authorize_a_credit_card_stored_in_the_moneris_vault_a
$response = $this->vault->add($this->card);
$key = $response->receipt()->read('key');

$faker = Faker::create();
$customer = [
'first_name' => $faker->firstName,
'last_name' => $faker->lastName,
'company_name' => $faker->company,
'address' => $faker->streetAddress,
'city' => $faker->city,
'province' => 'SK',
'postal_code' => 'X0X0X0',
'country' => 'Canada',
'phone_number' => '555-555-5555',
'fax' => '555-555-5555',
'tax1' => '1.01',
'tax2' => '1.02',
'tax3' => '1.03',
'shipping_cost' => '9.99',
];
$params = array_merge($this->params, [
'data_key' => $key,
'cust_id' => uniqid('customer-', true),
'cust_info' => [
'email' => '[email protected]',
'instructions' => $faker->sentence(mt_rand(3, 6)),
'billing' => $customer,
'shipping' => $customer
],
'cust_info' => $this->customer,
]);

$response = $this->vault->preauth($params);
Expand Down

0 comments on commit fbff9e7

Please sign in to comment.