diff --git a/src/Gateway.php b/src/Gateway.php index 1b54a18..ed7484a 100644 --- a/src/Gateway.php +++ b/src/Gateway.php @@ -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. * diff --git a/src/Transaction.php b/src/Transaction.php index 87cc41a..c53b034 100644 --- a/src/Transaction.php +++ b/src/Transaction.php @@ -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.';