From fbff9e7f0dea5065980bb5ace1df6da7a3dd9d5c Mon Sep 17 00:00:00 2001 From: Craig Paul Date: Tue, 25 Oct 2016 20:29:28 -0600 Subject: [PATCH] Adds purchase with customer info tests --- tests/GatewayTest.php | 79 +++++++++++++++++++++++++++++------------ tests/VaultTest.php | 81 +++++++++++++++++++++++++++++++------------ 2 files changed, 114 insertions(+), 46 deletions(-) diff --git a/tests/GatewayTest.php b/tests/GatewayTest.php index f20b70c..76064e3 100644 --- a/tests/GatewayTest.php +++ b/tests/GatewayTest.php @@ -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. * @@ -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 = [ @@ -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' => 'example@email.com', + 'instructions' => $faker->sentence(mt_rand(3, 6)), + 'billing' => $this->billing, + 'shipping' => $this->billing + ]; } /** @test */ @@ -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() { @@ -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' => 'example@email.com', - 'instructions' => $faker->sentence(mt_rand(3, 6)), - 'billing' => $customer, - 'shipping' => $customer - ], + 'cust_info' => $this->customer, ]); + $response = $this->gateway->preauth($params); $receipt = $response->receipt(); diff --git a/tests/VaultTest.php b/tests/VaultTest.php index 9385edf..4477fb8 100644 --- a/tests/VaultTest.php +++ b/tests/VaultTest.php @@ -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 */ @@ -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' => 'example@email.com', + 'instructions' => $faker->sentence(mt_rand(3, 6)), + 'billing' => $this->billing, + 'shipping' => $this->billing + ]; } /** @test */ @@ -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() { @@ -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' => 'example@email.com', - 'instructions' => $faker->sentence(mt_rand(3, 6)), - 'billing' => $customer, - 'shipping' => $customer - ], + 'cust_info' => $this->customer, ]); $response = $this->vault->preauth($params);