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

Commit

Permalink
Adds prepare functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
Craig Paul committed Oct 19, 2016
1 parent 67f21b9 commit b868a88
Showing 1 changed file with 55 additions and 0 deletions.
55 changes: 55 additions & 0 deletions src/Transaction.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,62 @@

namespace CraigPaul\Moneris;

/**
* CraigPaul\Moneris\Gateway
*
* @property-read \CraigPaul\Moneris\Gateway $gateway
* @property-read array $params
*/
class Transaction
{
use Gettable;

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

/**
* @var array
*/
protected $params;

/**
* Create a new Transaction instance.
*
* @param \CraigPaul\Moneris\Gateway $gateway
* @param array $params
* @param bool $prepare
*/
public function __construct(Gateway $gateway, array $params = [], $prepare = true)
{
$this->gateway = $gateway;
$this->params = $prepare ? $this->prepare($params) : $params;
}

/**
* Prepare the transaction parameters.
*
* @param array $params
*
* @return array
*/
protected function prepare(array $params)
{
foreach ($params as $key => $value) {
if (is_string($value)) {
$params[$key] = trim($value);
}

if ($params[$key] == '') {
unset($params[$key]);
}
}

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

return $params;
}
}

0 comments on commit b868a88

Please sign in to comment.