This repository has been archived by the owner on Oct 30, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds initial Moneris and Gateway classes
- Loading branch information
Craig Paul
committed
Oct 19, 2016
1 parent
0cce230
commit a31b636
Showing
2 changed files
with
164 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?php | ||
|
||
namespace CraigPaul\Moneris; | ||
|
||
class Gateway | ||
{ | ||
/** | ||
* The environment used for connecting to the Moneris API. | ||
* | ||
* @var string | ||
*/ | ||
protected $environment; | ||
|
||
/** | ||
* The Moneris Store ID. | ||
* | ||
* @var string | ||
*/ | ||
protected $id; | ||
|
||
/** | ||
* The Moneris API Token. | ||
* | ||
* @var string | ||
*/ | ||
protected $token; | ||
|
||
/** | ||
* Create a new Moneris instance. | ||
* | ||
* @param string $id | ||
* @param string $token | ||
* @param string $environment | ||
* | ||
* @return void | ||
*/ | ||
public function __construct(string $id, string $token, string $environment) | ||
{ | ||
$this->id = $id; | ||
$this->token = $token; | ||
$this->environment = $environment; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
<?php | ||
|
||
namespace CraigPaul\Moneris; | ||
|
||
/** | ||
* CraigPaul\Moneris\Moneris | ||
* | ||
* @property-read string $id | ||
* @property-read string $token | ||
* @property-read string $environment | ||
* @property-read string $params | ||
*/ | ||
class Moneris | ||
{ | ||
/** | ||
* The live Moneris API. | ||
* | ||
* @var string | ||
*/ | ||
const ENV_LIVE = 'live'; | ||
|
||
/** | ||
* The sandbox Moneris API. | ||
* | ||
* @var string | ||
*/ | ||
const ENV_STAGING = 'staging'; | ||
|
||
/** | ||
* The mocked Moneris API. | ||
* | ||
* @var string | ||
*/ | ||
const ENV_TESTING = 'testing'; | ||
|
||
/** | ||
* The environment used for connecting to the Moneris API. | ||
* | ||
* @var string | ||
*/ | ||
protected $environment; | ||
|
||
/** | ||
* The Moneris Store ID. | ||
* | ||
* @var string | ||
*/ | ||
protected $id; | ||
|
||
/** | ||
* The extra parameters needed for Moneris. | ||
* | ||
* @var array | ||
*/ | ||
protected $params; | ||
|
||
/** | ||
* The Moneris API Token. | ||
* | ||
* @var string | ||
*/ | ||
protected $token; | ||
|
||
/** | ||
* Create a new Moneris instance. | ||
* | ||
* @param string $id | ||
* @param string $token | ||
* @param string $environment | ||
* | ||
* @return void | ||
*/ | ||
public function __construct(string $id, string $token, array $params = []) | ||
{ | ||
$this->id = $id; | ||
$this->token = $token; | ||
$this->environment = $params['environment'] ?? self::ENV_LIVE; | ||
$this->params = $params; | ||
} | ||
|
||
/** | ||
* Create a new Moneris instance. | ||
* | ||
* @param string $id | ||
* @param string $token | ||
* @param array $params | ||
* | ||
* @return static | ||
*/ | ||
public static function create(string $id, string $token, array $params = []) | ||
{ | ||
return new static($id, $token, $params); | ||
} | ||
|
||
/** | ||
* Create and return a new Gateway instance. | ||
* | ||
* @return \CraigPaul\Moneris\Gateway | ||
*/ | ||
public function gateway() | ||
{ | ||
return new Gateway($this->id, $this->token, $this->environment); | ||
} | ||
|
||
/** | ||
* Retrieve a property off of the class. | ||
* | ||
* @param string $property | ||
* | ||
* @throws \InvalidArgumentException | ||
* @return mixed | ||
*/ | ||
public function __get(string $property) | ||
{ | ||
if (property_exists($this, $property)) { | ||
return $this->$property; | ||
} | ||
|
||
throw new \InvalidArgumentException('['.get_class($this).'] does not contain a property named ['.$property.']'); | ||
} | ||
} |