From 74a8ed2773c6185226b4d845a11e18e29c15b42b Mon Sep 17 00:00:00 2001 From: Avik Aghajanyan Date: Thu, 24 May 2018 19:59:30 +0400 Subject: [PATCH 1/5] Upgrade for v3 --- src/Gateway.php | 2 +- src/MerchantBusiness.php | 2 -- src/MerchantFunding.php | 2 -- src/Message/AbstractRequest.php | 2 +- src/Message/CreateCustomerRequest.php | 2 -- src/Message/FindCustomerRequest.php | 17 +++++++++++++---- src/Message/UpdatePaymentMethodRequest.php | 14 ++++++++++++-- 7 files changed, 27 insertions(+), 14 deletions(-) diff --git a/src/Gateway.php b/src/Gateway.php index bc45852..1ece244 100644 --- a/src/Gateway.php +++ b/src/Gateway.php @@ -5,7 +5,7 @@ use Omnipay\Common\AbstractGateway; use Braintree_Gateway; use Braintree_Configuration; -use Guzzle\Http\ClientInterface; +use Omnipay\Common\Http\ClientInterface; use Symfony\Component\HttpFoundation\Request as HttpRequest; /** * Braintree Gateway diff --git a/src/MerchantBusiness.php b/src/MerchantBusiness.php index 1165323..7aaf2e6 100644 --- a/src/MerchantBusiness.php +++ b/src/MerchantBusiness.php @@ -2,8 +2,6 @@ namespace Omnipay\Braintree; -use DateTime; -use DateTimeZone; use Omnipay\Common\Helper; use Symfony\Component\HttpFoundation\ParameterBag; diff --git a/src/MerchantFunding.php b/src/MerchantFunding.php index 008b7d2..6cc4eb0 100644 --- a/src/MerchantFunding.php +++ b/src/MerchantFunding.php @@ -2,8 +2,6 @@ namespace Omnipay\Braintree; -use DateTime; -use DateTimeZone; use Omnipay\Common\Helper; use Symfony\Component\HttpFoundation\ParameterBag; diff --git a/src/Message/AbstractRequest.php b/src/Message/AbstractRequest.php index c58724d..35eca0f 100644 --- a/src/Message/AbstractRequest.php +++ b/src/Message/AbstractRequest.php @@ -3,7 +3,7 @@ namespace Omnipay\Braintree\Message; use Braintree_Gateway; -use Guzzle\Http\ClientInterface; +use Omnipay\Common\Http\ClientInterface; use Omnipay\Common\Exception\InvalidRequestException; use Symfony\Component\HttpFoundation\Request as HttpRequest; use Omnipay\Common\Message\AbstractRequest as BaseAbstractRequest; diff --git a/src/Message/CreateCustomerRequest.php b/src/Message/CreateCustomerRequest.php index 16bf780..abacc6c 100644 --- a/src/Message/CreateCustomerRequest.php +++ b/src/Message/CreateCustomerRequest.php @@ -1,8 +1,6 @@ braintree->customer()->find($this->getCustomerId()); + try { + $response = $this->braintree->customer()->find($this->getCustomerId()); + } catch (NotFound $exception) { + throw new NotFoundHttpException($exception->getMessage()); + } return $this->response = new CustomerResponse($this, $response); } diff --git a/src/Message/UpdatePaymentMethodRequest.php b/src/Message/UpdatePaymentMethodRequest.php index dac33ed..325320a 100644 --- a/src/Message/UpdatePaymentMethodRequest.php +++ b/src/Message/UpdatePaymentMethodRequest.php @@ -6,7 +6,6 @@ /** * Update PaymentMethod Request - * * @method Response send() */ class UpdatePaymentMethodRequest extends AbstractRequest @@ -28,11 +27,12 @@ public function getData() * Send the request with specified data * * @param mixed $data The data to send + * * @return ResponseInterface */ public function sendData($data) { - $response = $this->braintree->paymentMethod()->update($data['token'], $data['options']); + $response = $this->braintree->paymentMethod()->update($data['token'], $data); return $this->createResponse($response); } @@ -47,6 +47,16 @@ public function setPaymentMethodToken($value) return $this->setParameter('token', $value); } + /** + * @param $value + * + * @return \Omnipay\Common\Message\AbstractRequest + */ + public function setMakeDefault($value) + { + return $this->setOptions(['makeDefault' => (bool) $value]); + } + /** * @param array $options * From 013056d676062070e176edc4be876c3e57723764 Mon Sep 17 00:00:00 2001 From: Avik Aghajanyan Date: Thu, 24 May 2018 20:09:06 +0400 Subject: [PATCH 2/5] Updated composer json --- composer.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index 33c2634..24db36b 100644 --- a/composer.json +++ b/composer.json @@ -31,11 +31,11 @@ "psr-4": { "Omnipay\\Braintree\\" : "src/" } }, "require": { - "omnipay/common": "~2.0", + "omnipay/common": "^3", "braintree/braintree_php": "^2.39|^3.0" }, "require-dev": { - "omnipay/tests": "~2.0" + "omnipay/tests": "^3" }, "extra": { "branch-alias": { From 34b128999a0780067dc09f108afa50a5212e283c Mon Sep 17 00:00:00 2001 From: Avik Aghajanyan Date: Fri, 25 May 2018 13:28:24 +0400 Subject: [PATCH 3/5] Throw Omnipay NotFound in case resource not found on gateway --- src/Message/FindCustomerRequest.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Message/FindCustomerRequest.php b/src/Message/FindCustomerRequest.php index 8b83efd..c2809b8 100644 --- a/src/Message/FindCustomerRequest.php +++ b/src/Message/FindCustomerRequest.php @@ -3,7 +3,7 @@ namespace Omnipay\Braintree\Message; use Braintree\Exception\NotFound; -use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; +use Omnipay\Common\Exception\NotFoundException; /** * Find Customer Request @@ -22,14 +22,14 @@ public function getData() * @param mixed $data * * @return \Omnipay\Braintree\Message\CustomerResponse|\Omnipay\Common\Message\ResponseInterface - * @throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException + * @throws \Omnipay\Common\Exception\NotFoundException */ public function sendData($data) { try { $response = $this->braintree->customer()->find($this->getCustomerId()); } catch (NotFound $exception) { - throw new NotFoundHttpException($exception->getMessage()); + throw new NotFoundException($exception->getMessage()); } return $this->response = new CustomerResponse($this, $response); From 31c68f58152c0a2d81948d63a9f7b13f33083a59 Mon Sep 17 00:00:00 2001 From: Avik Aghajanyan Date: Fri, 25 May 2018 14:58:00 +0400 Subject: [PATCH 4/5] Reverted back to Symphony's NotFoundHttpException until the release of Omnipay Common --- src/Message/FindCustomerRequest.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Message/FindCustomerRequest.php b/src/Message/FindCustomerRequest.php index c2809b8..8b83efd 100644 --- a/src/Message/FindCustomerRequest.php +++ b/src/Message/FindCustomerRequest.php @@ -3,7 +3,7 @@ namespace Omnipay\Braintree\Message; use Braintree\Exception\NotFound; -use Omnipay\Common\Exception\NotFoundException; +use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; /** * Find Customer Request @@ -22,14 +22,14 @@ public function getData() * @param mixed $data * * @return \Omnipay\Braintree\Message\CustomerResponse|\Omnipay\Common\Message\ResponseInterface - * @throws \Omnipay\Common\Exception\NotFoundException + * @throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException */ public function sendData($data) { try { $response = $this->braintree->customer()->find($this->getCustomerId()); } catch (NotFound $exception) { - throw new NotFoundException($exception->getMessage()); + throw new NotFoundHttpException($exception->getMessage()); } return $this->response = new CustomerResponse($this, $response); From d1e1aed544189048806b5e7e067cbb9d288693c3 Mon Sep 17 00:00:00 2001 From: Avik Aghajanyan Date: Fri, 25 May 2018 15:46:11 +0400 Subject: [PATCH 5/5] Reverted back the exception part --- src/Message/FindCustomerRequest.php | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/src/Message/FindCustomerRequest.php b/src/Message/FindCustomerRequest.php index 8b83efd..c0b6e8d 100644 --- a/src/Message/FindCustomerRequest.php +++ b/src/Message/FindCustomerRequest.php @@ -2,9 +2,6 @@ namespace Omnipay\Braintree\Message; -use Braintree\Exception\NotFound; -use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; - /** * Find Customer Request * @method CustomerResponse send() @@ -22,16 +19,11 @@ public function getData() * @param mixed $data * * @return \Omnipay\Braintree\Message\CustomerResponse|\Omnipay\Common\Message\ResponseInterface - * @throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException */ public function sendData($data) { - try { - $response = $this->braintree->customer()->find($this->getCustomerId()); - } catch (NotFound $exception) { - throw new NotFoundHttpException($exception->getMessage()); - } + $response = $this->braintree->customer()->find($this->getCustomerId()); return $this->response = new CustomerResponse($this, $response); } -} \ No newline at end of file +}