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..dac33ed 100644 --- a/src/Message/UpdatePaymentMethodRequest.php +++ b/src/Message/UpdatePaymentMethodRequest.php @@ -13,12 +13,12 @@ class UpdatePaymentMethodRequest extends AbstractRequest { public function getData() { - $parameters = array(); - $parameters += $this->getOptionData(); - + $data = array(); $data['token'] = $this->getToken(); - if (!empty($parameters)) { - $data['parameters'] = $parameters; + $options = $this->parameters->get('paymentMethodOptions'); + + if (null !== $options) { + $data['options'] = $options; } return $data; @@ -32,8 +32,28 @@ 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); } + + /** + * @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); + } } 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(