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

Commit

Permalink
add credential on file support
Browse files Browse the repository at this point in the history
  • Loading branch information
njaw committed Aug 23, 2019
1 parent 5b4ce61 commit 4e09982
Show file tree
Hide file tree
Showing 7 changed files with 164 additions and 6 deletions.
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ $params = [
'environment' => Moneris::ENV_TESTING, // default: Moneris::ENV_LIVE
'avs' => true, // default: false
'cvd' => true, // default: false
'cof' => true, // default: false
];

$gateway = (new Moneris($id, $token, $params))->connect();
Expand All @@ -52,6 +53,7 @@ $params = [
'environment' => Moneris::ENV_TESTING, // default: Moneris::ENV_LIVE
'avs' => true, // default: false
'cvd' => true, // default: false
'cof' => true, // default: false
];

$gateway = Moneris::create($id, $token, $params);
Expand Down Expand Up @@ -222,6 +224,23 @@ if ($response->successful && ($response->failedAvs || $response->failedCvd)) {
}
```

### Credential On File

The credential on file is part of the new Visa requirements to pass the CVD/CVV2 data for transactions.

```php
$params = [
'order_id' => uniqid('1234-56789', true),
'amount' => '1.00',
'data_key' => $key,
'payment_indicator' => 'U',
'payment_information' => '2',
'issuer_id' => $issuer_id // this is optional
];

$response = $vault->purchase($params); // could be purchase, preauth, etc.
```

## Vault

The Moneris Vault allows you create and maintain credit card profiles on the Moneris servers instead of your own. To access the Vault, you will need to have your instantiated Gateway ([see above](#instantiation)).
Expand Down
12 changes: 12 additions & 0 deletions src/Gateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
* @property-read string $id
* @property-read string $token
* @property \CraigPaul\Moneris\Transaction $transaction
* @property bool $cof
*/
class Gateway
{
Expand Down Expand Up @@ -72,6 +73,13 @@ class Gateway
*/
protected $transaction;

/**
* Determine if we will use Credential On File.
*
* @var bool
*/
protected $cof = false;

/**
* Create a new Moneris instance.
*
Expand Down Expand Up @@ -135,6 +143,10 @@ public function cards()
$vault->cvd = boolval($this->cvd);
}

if (isset($this->cof)) {
$vault->cof = boolval($this->cof);
}

return $vault;
}

Expand Down
4 changes: 4 additions & 0 deletions src/Moneris.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,10 @@ public function connect()
$gateway->cvd = boolval($this->params['cvd']);
}

if (isset($this->params['cof'])) {
$gateway->cof = boolval($this->params['cof']);
}

return $gateway;
}
}
1 change: 1 addition & 0 deletions src/Receipt.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public function __construct($data)
['property' => 'time', 'key' => 'TransTime', 'cast' => 'string'],
['property' => 'transaction', 'key' => 'TransID', 'cast' => 'string'],
['property' => 'type', 'key' => 'TransType', 'cast' => 'string'],
['property' => 'issuer_id', 'key' => 'IssuerId', 'cast' => 'string'],
]);
}

Expand Down
83 changes: 83 additions & 0 deletions src/Transaction.php
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,14 @@ public function toXml()
'res_preauth_cc'
]
);

$cc_action = in_array(
$params['type'],
[
'res_add_cc',
'res_update_cc'
]
);
unset($params['type']);

if ($gateway->cvd && $efraud) {
Expand All @@ -229,6 +237,23 @@ public function toXml()
}
}

if ($gateway->cof && ($efraud || $cc_action)) {
$cofInfo = $type->addChild('cof_info');
if (!empty($params['payment_indicator'])) {
$cofInfo->addChild('payment_indicator', $params['payment_indicator']);
}

if (!empty($params['payment_information'])) {
$cofInfo->addChild('payment_information', $params['payment_information']);
}

if (!empty($params['issuer_id'])) {
$cofInfo->addChild('issuer_id', $params['issuer_id']);
}

unset($params['payment_indicator'], $params['payment_information'], $params['issuer_id']);
}

$this->append($params, $type);

return $xml->asXML();
Expand Down Expand Up @@ -297,6 +322,20 @@ public function valid()
];
}

if ($this->gateway->cof) {
$errors[] = isset($params['payment_indicator']) ? null : [
'field' => 'payment_indicator',
'code' => self::PARAMETER_NOT_SET,
'title' => 'not_set'
];

$errors[] = isset($params['payment_information']) ? null : [
'field' => 'payment_information',
'code' => self::PARAMETER_NOT_SET,
'title' => 'not_set'
];
}

break;
case 'preauth':
case 'purchase':
Expand Down Expand Up @@ -352,6 +391,20 @@ public function valid()
];
}

if ($this->gateway->cof) {
$errors[] = isset($params['payment_indicator']) ? null : [
'field' => 'payment_indicator',
'code' => self::PARAMETER_NOT_SET,
'title' => 'not_set'
];

$errors[] = isset($params['payment_information']) ? null : [
'field' => 'payment_information',
'code' => self::PARAMETER_NOT_SET,
'title' => 'not_set'
];
}

break;
case 'res_tokenize_cc':
case 'purchasecorrection':
Expand Down Expand Up @@ -421,6 +474,14 @@ public function valid()
'title' => 'not_set'
];

if ($this->gateway->cof) {
$errors[] = isset($params['issuer_id']) ? null : [
'field' => 'issuer_id',
'code' => self::PARAMETER_NOT_SET,
'title' => 'not_set'
];
}

break;
case 'res_update_cc':
$errors[] = isset($params['data_key']) ? null : [
Expand All @@ -441,6 +502,14 @@ public function valid()
'title' => 'not_set'
];

if ($this->gateway->cof) {
$errors[] = isset($params['issuer_id']) ? null : [
'field' => 'issuer_id',
'code' => self::PARAMETER_NOT_SET,
'title' => 'not_set'
];
}

break;
case 'res_delete':
case 'res_lookup_full':
Expand Down Expand Up @@ -500,6 +569,20 @@ public function valid()
];
}

if ($this->gateway->cof) {
$errors[] = isset($params['payment_indicator']) ? null : [
'field' => 'payment_indicator',
'code' => self::PARAMETER_NOT_SET,
'title' => 'not_set'
];

$errors[] = isset($params['payment_information']) ? null : [
'field' => 'payment_information',
'code' => self::PARAMETER_NOT_SET,
'title' => 'not_set'
];
}

break;
default:
$errors[] = [
Expand Down
14 changes: 8 additions & 6 deletions src/Vault.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,18 @@ public function __construct($id = '', $token = '', $environment = '')
* Add a credit card to the Vault.
*
* @param \CraigPaul\Moneris\CreditCard $card
* @param array $extra_params
*
* @return \CraigPaul\Moneris\Response
*/
public function add(CreditCard $card)
public function add(CreditCard $card, $extra_params = [])
{
$params = [
$params = array_merge($extra_params, [
'type' => 'res_add_cc',
'crypt_type' => $card->crypt,
'pan' => $card->number,
'expdate' => $card->expiry,
];
]);

if (!is_null($card->customer)) {
$params = array_merge($params, [
Expand Down Expand Up @@ -194,18 +195,19 @@ public function tokenize($transaction, $order = null)
*
* @param string $key
* @param \CraigPaul\Moneris\CreditCard $card
* @param array $extra_params
*
* @return \CraigPaul\Moneris\Response
*/
public function update($key = '', CreditCard $card)
public function update($key = '', CreditCard $card, $extra_params = [])
{
$params = [
$params = array_merge($extra_params, [
'type' => 'res_update_cc',
'data_key' => $key,
'crypt_type' => $card->crypt,
'pan' => $card->number,
'expdate' => $card->expiry,
];
]);

if (!is_null($card->customer)) {
$params = array_merge($params, [
Expand Down
37 changes: 37 additions & 0 deletions tests/VaultTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -472,4 +472,41 @@ public function it_can_capture_a_pre_authorized_credit_card_stored_in_the_moneri
$this->assertTrue($response->successful);
$this->assertEquals(true, $receipt->read('complete'));
}

/** @test */
public function it_can_make_a_purchase_for_a_credit_card_stored_in_the_moneris_vault_using_credential_on_file()
{
$params = ['environment' => Moneris::ENV_TESTING, 'cof' => true];
$gateway = Moneris::create($this->id, $this->token, $params);
$vault = $gateway->cards();

$preauth_params = [
'order_id' => uniqid('1234-56789', true),
'amount' => '1.00',
'credit_card' => $this->visa,
'expdate' => '2012',
'payment_indicator' => 'C',
'payment_information' => '0'
];

$response = $gateway->preauth($preauth_params);
$issuer_id = $response->receipt()->read('issuer_id');
$response = $vault->add($this->card, ['issuer_id' => $issuer_id]);
$key = $response->receipt()->read('key');

$params = array_merge($this->params, [
'data_key' => $key,
'payment_indicator' => 'U',
'payment_information' => '2',
'issuer_id' => $issuer_id
]);

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

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

0 comments on commit 4e09982

Please sign in to comment.