From 9caba33f531982981892a8abd259f99a653f5d85 Mon Sep 17 00:00:00 2001 From: Paul Chubatyy Date: Mon, 25 Apr 2016 21:14:49 +0300 Subject: [PATCH] Add ability to search for transaction. Currently implemented on ->is criteria --- src/Gateway.php | 18 ++++++++++++++++++ src/Message/FindTransactions.php | 30 ++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+) create mode 100644 src/Message/FindTransactions.php diff --git a/src/Gateway.php b/src/Gateway.php index bc45852..a9bebb4 100644 --- a/src/Gateway.php +++ b/src/Gateway.php @@ -290,4 +290,22 @@ public function fetchTransaction(array $parameters = array()) { return $this->createRequest('\Omnipay\Braintree\Message\FindRequest', $parameters); } + + /** + * Find transactions by criteria + * + * Example usage: + * + * $collections = $brainTree->findTransactions(['customerId' => '12345678']); + * + * The parameter key has to one of the static methods from \Braintree\TransactionSearch + * @see https://developers.braintreepayments.com/reference/request/transaction/search/php + * + * @param array $parameters + * @return mixed|\Omnipay\Common\Message\AbstractRequest + */ + public function findTransactions(array $parameters = array()) + { + return $this->createRequest('\Omnipay\Braintree\Message\FindTransactions', $parameters); + } } diff --git a/src/Message/FindTransactions.php b/src/Message/FindTransactions.php new file mode 100644 index 0000000..92254ab --- /dev/null +++ b/src/Message/FindTransactions.php @@ -0,0 +1,30 @@ +getParameters(); + + $data = array(); + + foreach ($parameters as $parameterName => $value) { + if (method_exists('Braintree_TransactionSearch', $parameterName)) { + $search = call_user_func("\Braintree_TransactionSearch::$parameterName"); + $data[] = $search->is($value); + } + } + return $data; + } + + public function sendData($data) + { + $response = $this->braintree->transaction()->search($data); + + return $this->createResponse($response); + } +}