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

Commit

Permalink
Adds capture transaction functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
Craig Paul committed Oct 20, 2016
1 parent 306f094 commit c35dc53
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
29 changes: 29 additions & 0 deletions src/Gateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,35 @@ public function __construct(string $id, string $token, string $environment)
$this->environment = $environment;
}

/**
* Capture a pre-authorized a transaction.
*
* @param \CraigPaul\Moneris\Transaction|string $transaction
* @param string|null $order
*
* @return \CraigPaul\Moneris\Response
*/
public function capture($transaction, string $order = null, $amount = null)
{
if ($transaction instanceof Transaction) {
$order = $transaction->order();
$amount = $amount ?? $transaction->amount();
$transaction = $transaction->number();
}

$params = [
'type' => 'completion',
'crypt_type' => Crypt::SSL_ENABLED_MERCHANT,
'comp_amount' => $amount,
'txn_number' => $transaction,
'order_id' => $order,
];

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

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

/**
* Pre-authorize a purchase.
*
Expand Down
6 changes: 6 additions & 0 deletions src/Transaction.php
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,12 @@ public function valid()
$errors[] = Validator::set($params, 'order_id') ? null : 'Order id not provided.';
$errors[] = Validator::set($params, 'txn_number') ? null : 'Transaction number not provided.';

break;
case 'completion':
$errors[] = Validator::set($params, 'comp_amount') ? null : 'Amount not provided.';
$errors[] = Validator::set($params, 'order_id') ? null : 'Order id not provided.';
$errors[] = Validator::set($params, 'txn_number') ? null : 'Transaction number not provided.';

break;
case 'refund':
$errors[] = Validator::set($params, 'amount') ? null : 'Amount not provided.';
Expand Down

0 comments on commit c35dc53

Please sign in to comment.