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

Commit

Permalink
Adds initial Moneris and Gateway classes
Browse files Browse the repository at this point in the history
  • Loading branch information
Craig Paul committed Oct 19, 2016
1 parent 0cce230 commit a31b636
Show file tree
Hide file tree
Showing 2 changed files with 164 additions and 0 deletions.
43 changes: 43 additions & 0 deletions src/Gateway.php
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;
}
}
121 changes: 121 additions & 0 deletions src/Moneris.php
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.']');
}
}

0 comments on commit a31b636

Please sign in to comment.