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

Commit

Permalink
Adds ability to use credit_card as a key to replace pan
Browse files Browse the repository at this point in the history
  • Loading branch information
Craig Paul committed Oct 20, 2016
1 parent 241d984 commit 0fff829
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 11 deletions.
20 changes: 15 additions & 5 deletions src/Transaction.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,11 @@ class Transaction
*
* @param \CraigPaul\Moneris\Gateway $gateway
* @param array $params
* @param bool $prepare
*/
public function __construct(Gateway $gateway, array $params = [], $prepare = true)
public function __construct(Gateway $gateway, array $params = [])
{
$this->gateway = $gateway;
$this->params = $prepare ? $this->prepare($params) : $params;
$this->params = $this->prepare($params);
}

/**
Expand Down Expand Up @@ -84,8 +83,19 @@ protected function prepare(array $params)
}
}

if (isset($params['pan'])) {
$params['pan'] = preg_replace('/\D/', '', $params['pan']);
if (isset($params['credit_card'])) {
$params['pan'] = preg_replace('/\D/', '', $params['credit_card']);
unset($params['credit_card']);
}

if (isset($params['description'])) {
$params['dynamic_descriptor'] = $params['description'];
unset($params['description']);
}

if (isset($params['expiry_month']) && isset($params['expiry_year']) && !isset($params['expdate'])) {
$params['expdate'] = sprintf('%02%02d', $params['expiry_year'], $params['expiry_monthp']);
unset($params['expiry_year'], $params['expiry_month']);
}

return $params;
Expand Down
2 changes: 1 addition & 1 deletion tests/GatewayTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public function it_can_make_a_purchase_and_receive_a_response()
$params = [
'order_id' => uniqid('1234-56789', true),
'amount' => '1.00',
'pan' => $this->visa,
'credit_card' => $this->visa,
'expdate' => '2012',
];

Expand Down
2 changes: 1 addition & 1 deletion tests/ProcessorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public function setUp()
'crypt_type' => Crypt::SSL_ENABLED_MERCHANT,
'order_id' => uniqid('1234-56789', true),
'amount' => '1.00',
'pan' => $this->visa,
'credit_card' => $this->visa,
'expdate' => '2012',
];
$this->transaction = new Transaction($this->gateway, $this->params);
Expand Down
2 changes: 1 addition & 1 deletion tests/ResponseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public function setUp()
'crypt_type' => Crypt::SSL_ENABLED_MERCHANT,
'order_id' => uniqid('1234-56789', true),
'amount' => '1.00',
'pan' => $this->visa,
'credit_card' => $this->visa,
'expdate' => '2012',
];
$this->transaction = new Transaction($this->gateway, $this->params);
Expand Down
10 changes: 7 additions & 3 deletions tests/TransactionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function setUp()
'type' => 'purchase',
'order_id' => uniqid('1234-56789', true),
'amount' => '1.00',
'pan' => $this->visa,
'credit_card' => $this->visa,
'expdate' => '2012',
];
$this->transaction = new Transaction($this->gateway, $this->params);
Expand All @@ -50,8 +50,12 @@ public function setUp()
/** @test */
public function it_can_access_properties_of_the_class()
{
$params = $this->params;
$params['pan'] = $params['credit_card'];
unset($params['credit_card']);

$this->assertEquals($this->gateway, $this->transaction->gateway);
$this->assertEquals($this->params, $this->transaction->params);
$this->assertEquals($params, $this->transaction->params);
}

/** @test */
Expand All @@ -63,7 +67,7 @@ public function it_can_prepare_parameters_that_were_submitted_improperly()
'type' => 'purchase',
'order_id' => $order,
'amount' => '1.00',
'pan' => $card,
'credit_card' => $card,
'expdate' => '2012',
]);

Expand Down

0 comments on commit 0fff829

Please sign in to comment.