Skip to content
This repository was archived by the owner on Oct 30, 2020. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@
}
],
"require": {
"php": ">=5.6",
"guzzlehttp/guzzle": "^6.2"
"php": ">=7.4",
"guzzlehttp/guzzle": "^7.2"
},
"require-dev": {
"phpunit/phpunit": "~5.0",
"mockery/mockery": "~0.9",
"phpunit/phpunit": "~9.0",
"mockery/mockery": "~1.4",
"symfony/var-dumper": "^3.1",
"fzaninotto/faker": "^1.6",
"fzaninotto/faker": "^1.9",
"squizlabs/php_codesniffer": "^2.7"
},
"autoload": {
Expand Down
4 changes: 3 additions & 1 deletion src/Receipt.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public function __construct($data)
['property' => 'transaction', 'key' => 'TransID', 'cast' => 'string'],
['property' => 'type', 'key' => 'TransType', 'cast' => 'string'],
['property' => 'issuer_id', 'key' => 'IssuerId', 'cast' => 'string'],
['property' => 'recur', 'key' => 'RecurSuccess', 'cast' => 'boolean'],
]);
}

Expand All @@ -45,8 +46,9 @@ public function successful()
$complete = $this->read('complete');
$valid_code = $this->read('code') !== 'null';
$code = (int)$this->read('code');
$recur = $this->read('recur');

return $complete && $valid_code && $code >= 0 && $code < 50;
return $complete && ($valid_code || $recur) && $code >= 0 && $code < 50;
}

/**
Expand Down
94 changes: 94 additions & 0 deletions tests/RecurringTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
<?php

use Faker\Factory as Faker;
use CraigPaul\Moneris\Gateway;
use CraigPaul\Moneris\Moneris;
use CraigPaul\Moneris\Response;
use CraigPaul\Moneris\Receipt;

class RecurringTest extends \PHPUnit\Framework\TestCase
{
/**
* @var string
*/
protected $environment;

/**
* @var string
*/
protected $id;

/**
* @var string
*/
protected $token;

/**
* The Moneris gateway.
*
* @var \CraigPaul\Moneris\Gateway
*/
protected $gateway;

/**
* The Moneris API parameters.
*
* @var array
*/
protected $params;

/**
* Set up the test environment.
*
* @return void
*/
public function setUp()
{
parent::setUp();

$this->id = 'store2';
$this->token = 'yesguy';
$this->environment = Moneris::ENV_TESTING;

$faker = Faker::create();
$params = ['environment' => $this->environment];
$this->gateway = Moneris::create($this->id, $this->token, $params);
$this->params = [
'order_id' => uniqid('1234-56789', true),
'amount' => '1.00',
'credit_card' => '4242424242424242',
'expdate' => '2012',
'recur' => [
'recur_unit' => 'day',
'num_recurs' => 1,
'start_now' => 'false',
'period' => 1,
'recur_amount' => '1.00'
]
];
}

/** @test */
public function it_can_make_a_recurring_purchase () {
$d = new DateTime();
$d->add(new DateInterval('P2D'));
$this->params['recur']['start_date'] = $d->format('Y/m/d');
$response = $this->gateway->purchase($this->params);

$this->assertEquals(Response::class, get_class($response));
$this->assertEquals(Receipt::class,get_class($receipt = $response->receipt()));
$this->assertTrue($receipt->successful());
}

/** @test */
public function it_can_fail_with_a_recurring_purchase () {
// fails on date being the same as today
$this->params['recur']['start_date'] = date('Y/m/d');
$response = $this->gateway->purchase($this->params);

$this->assertEquals(Response::class, get_class($response));
$this->assertEquals(Receipt::class,get_class($receipt = $response->receipt()));
$this->assertFalse($receipt->successful());
}

}