From 116d5f15af1029b13763571ad7353e9b4ca5d500 Mon Sep 17 00:00:00 2001 From: Konstantinos Christofilos Date: Tue, 7 Jun 2016 11:07:16 +0300 Subject: [PATCH 1/3] Fix update payment method --- .idea/copyright/profiles_settings.xml | 3 +++ README.md | 25 +++++++++++++++++++ src/Message/UpdatePaymentMethodRequest.php | 28 +++++++++++++++++----- 3 files changed, 50 insertions(+), 6 deletions(-) create mode 100644 .idea/copyright/profiles_settings.xml diff --git a/.idea/copyright/profiles_settings.xml b/.idea/copyright/profiles_settings.xml new file mode 100644 index 0000000..e7bedf3 --- /dev/null +++ b/.idea/copyright/profiles_settings.xml @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/README.md b/README.md index 2d8df28..a72c9ab 100644 --- a/README.md +++ b/README.md @@ -69,6 +69,31 @@ $customer = $gateway->findCustomer(1)->send(); ``` You can find full list of options [here](https://developers.braintreepayments.com/reference/request/customer/find/php) +### Create payment method + +```php +$method = $gateway->createPaymentMethod([ + 'customerId' => $user->getId(), + 'paymentMethodNonce' => 'paymentnonce', + 'options' => [ + 'verifyCard' => true + ] +]); +``` +You can find full list of options [here](https://developers.braintreepayments.com/reference/request/payment-method/create/php). + +### Update payment method + +```php +$method = $gateway->updatePaymentMethod([ + 'paymentMethodToken' => 'token123', + 'options' => [ + 'paymentMethodNonce' => 'paymentnonce' + ] +]); +``` +You can find full list of options [here](https://developers.braintreepayments.com/reference/request/payment-method/update/php). + ###Create subscription ```php diff --git a/src/Message/UpdatePaymentMethodRequest.php b/src/Message/UpdatePaymentMethodRequest.php index d225cdd..a81fb6a 100644 --- a/src/Message/UpdatePaymentMethodRequest.php +++ b/src/Message/UpdatePaymentMethodRequest.php @@ -13,13 +13,9 @@ class UpdatePaymentMethodRequest extends AbstractRequest { public function getData() { - $parameters = array(); - $parameters += $this->getOptionData(); - + $data = array(); $data['token'] = $this->getToken(); - if (!empty($parameters)) { - $data['parameters'] = $parameters; - } + $data['parameters'] = $this->parameters->get('paymentMethodOptions'); return $data; } @@ -36,4 +32,24 @@ public function sendData($data) return $this->createResponse($response); } + + /** + * @param string $value + * + * @return \Omnipay\Common\Message\AbstractRequest + */ + public function setPaymentMethodToken($value) + { + return $this->setParameter('token', $value); + } + + /** + * @param array $options + * + * @return \Omnipay\Common\Message\AbstractRequest + */ + public function setOptions(array $options = array()) + { + return $this->setParameter('paymentMethodOptions', $options); + } } From 04eb8c3cb18cfa817572e3aad4cd93b9e9b4b3d1 Mon Sep 17 00:00:00 2001 From: Konstantinos Christofilos Date: Tue, 7 Jun 2016 11:07:16 +0300 Subject: [PATCH 2/3] Change update payment method in order to take more options than those defined in AbstractRequest::getOptionsData() --- .idea/copyright/profiles_settings.xml | 3 +++ README.md | 25 +++++++++++++++++++ src/Message/UpdatePaymentMethodRequest.php | 28 +++++++++++++++++----- 3 files changed, 50 insertions(+), 6 deletions(-) create mode 100644 .idea/copyright/profiles_settings.xml diff --git a/.idea/copyright/profiles_settings.xml b/.idea/copyright/profiles_settings.xml new file mode 100644 index 0000000..e7bedf3 --- /dev/null +++ b/.idea/copyright/profiles_settings.xml @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/README.md b/README.md index 2d8df28..a72c9ab 100644 --- a/README.md +++ b/README.md @@ -69,6 +69,31 @@ $customer = $gateway->findCustomer(1)->send(); ``` You can find full list of options [here](https://developers.braintreepayments.com/reference/request/customer/find/php) +### Create payment method + +```php +$method = $gateway->createPaymentMethod([ + 'customerId' => $user->getId(), + 'paymentMethodNonce' => 'paymentnonce', + 'options' => [ + 'verifyCard' => true + ] +]); +``` +You can find full list of options [here](https://developers.braintreepayments.com/reference/request/payment-method/create/php). + +### Update payment method + +```php +$method = $gateway->updatePaymentMethod([ + 'paymentMethodToken' => 'token123', + 'options' => [ + 'paymentMethodNonce' => 'paymentnonce' + ] +]); +``` +You can find full list of options [here](https://developers.braintreepayments.com/reference/request/payment-method/update/php). + ###Create subscription ```php diff --git a/src/Message/UpdatePaymentMethodRequest.php b/src/Message/UpdatePaymentMethodRequest.php index d225cdd..a81fb6a 100644 --- a/src/Message/UpdatePaymentMethodRequest.php +++ b/src/Message/UpdatePaymentMethodRequest.php @@ -13,13 +13,9 @@ class UpdatePaymentMethodRequest extends AbstractRequest { public function getData() { - $parameters = array(); - $parameters += $this->getOptionData(); - + $data = array(); $data['token'] = $this->getToken(); - if (!empty($parameters)) { - $data['parameters'] = $parameters; - } + $data['parameters'] = $this->parameters->get('paymentMethodOptions'); return $data; } @@ -36,4 +32,24 @@ public function sendData($data) return $this->createResponse($response); } + + /** + * @param string $value + * + * @return \Omnipay\Common\Message\AbstractRequest + */ + public function setPaymentMethodToken($value) + { + return $this->setParameter('token', $value); + } + + /** + * @param array $options + * + * @return \Omnipay\Common\Message\AbstractRequest + */ + public function setOptions(array $options = array()) + { + return $this->setParameter('paymentMethodOptions', $options); + } } From 365b970c51bd5354a95ae9b0dfdc4a60064cf48b Mon Sep 17 00:00:00 2001 From: Konstantinos Christofilos Date: Tue, 7 Jun 2016 11:24:31 +0300 Subject: [PATCH 3/3] Fix UpdatePaymentMethodRequest unit test --- src/Message/UpdatePaymentMethodRequest.php | 8 ++++++-- tests/Message/UpdatePaymentMethodRequestTest.php | 14 +++++++------- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/src/Message/UpdatePaymentMethodRequest.php b/src/Message/UpdatePaymentMethodRequest.php index a81fb6a..dac33ed 100644 --- a/src/Message/UpdatePaymentMethodRequest.php +++ b/src/Message/UpdatePaymentMethodRequest.php @@ -15,7 +15,11 @@ public function getData() { $data = array(); $data['token'] = $this->getToken(); - $data['parameters'] = $this->parameters->get('paymentMethodOptions'); + $options = $this->parameters->get('paymentMethodOptions'); + + if (null !== $options) { + $data['options'] = $options; + } return $data; } @@ -28,7 +32,7 @@ public function getData() */ public function sendData($data) { - $response = $this->braintree->paymentMethod()->update($data['token'], $data['parameters']); + $response = $this->braintree->paymentMethod()->update($data['token'], $data['options']); return $this->createResponse($response); } diff --git a/tests/Message/UpdatePaymentMethodRequestTest.php b/tests/Message/UpdatePaymentMethodRequestTest.php index edb115d..1888dc8 100644 --- a/tests/Message/UpdatePaymentMethodRequestTest.php +++ b/tests/Message/UpdatePaymentMethodRequestTest.php @@ -20,16 +20,16 @@ public function testGetData() { $this->request->initialize( array( - 'token' => 'abcd1234', - 'makeDefault' => true, + 'paymentMethodToken' => 'abcd1234', + 'options' => array( + 'makeDefault' => true, + ) ) ); $expected = array( 'token' => 'abcd1234', - 'parameters' => array( - 'options' => array( - 'makeDefault' => true, - ), + 'options' => array( + 'makeDefault' => true, ), ); $this->assertSame($expected, $this->request->getData()); @@ -39,7 +39,7 @@ public function testGetDataNoParameters() { $this->request->initialize( array( - 'token' => 'abcd1234', + 'paymentMethodToken' => 'abcd1234', ) ); $expected = array(