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

Commit

Permalink
Adds stubbed out purchase functionality and needed classes
Browse files Browse the repository at this point in the history
  • Loading branch information
Craig Paul committed Oct 19, 2016
1 parent 0bb5293 commit 9a51ec5
Show file tree
Hide file tree
Showing 4 changed files with 102 additions and 0 deletions.
75 changes: 75 additions & 0 deletions src/Gateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

namespace CraigPaul\Moneris;

use CraigPaul\Moneris\Validators\Purchase;
use CraigPaul\Moneris\Validators\Validatable;

/**
* CraigPaul\Moneris\Gateway
*
Expand Down Expand Up @@ -34,6 +37,13 @@ class Gateway
*/
protected $token;

/**
* The current transaction.
*
* @var \CraigPaul\Moneris\Transaction
*/
protected $transaction;

/**
* Create a new Moneris instance.
*
Expand All @@ -49,4 +59,69 @@ public function __construct(string $id, string $token, string $environment)
$this->token = $token;
$this->environment = $environment;
}

/**
* Make a purchase.
*
* @param array $params
*
* @return \CraigPaul\Moneris\Response
*/
public function purchase(array $params = [])
{
$this->validate(Purchase::class, $params);

array_merge($params, [
'type' => 'purchase',
'crypt_type' => Crypt::SSL_ENABLED_MERCHANT,
]);

$transaction = $this->transaction($params);

return $this->process($transaction);
}

/**
* Process a transaction through the Moneris API.
*
* @param \CraigPaul\Moneris\Transaction $transaction
*
* @return \CraigPaul\Moneris\Response
*/
protected function process(Transaction $transaction)
{
return Processor::process($transaction);
}

/**
* Get or create a new Transaction instance.
*
* @param array|null $params
*
* @return \CraigPaul\Moneris\Transaction
*/
protected function transaction(array $params = null)
{
if (is_null($this->transaction) || !is_null($params)) {
return $this->transaction = new Transaction($this, $params);
}

return $this->transaction;
}

/**
* Validate the supplied parameters against a provided class.
*
* @param string $class
* @param array $params
*
* @return void
*/
protected function validate(string $class, array $params = [])
{
/** @var Validatable $class */
$class = new $class;

$class->validate($params);
}
}
11 changes: 11 additions & 0 deletions src/Processor.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

namespace CraigPaul\Moneris;

class Processor
{
public static function process(Transaction $transaction)
{
return new Response();
}
}
8 changes: 8 additions & 0 deletions src/Response.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

namespace CraigPaul\Moneris;

class Response
{

}
8 changes: 8 additions & 0 deletions src/Transaction.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

namespace CraigPaul\Moneris;

class Transaction
{

}

0 comments on commit 9a51ec5

Please sign in to comment.