Skip to content

Commit

Permalink
Merge pull request #28 from c0nstantx/update_payment
Browse files Browse the repository at this point in the history
Update payment fix
  • Loading branch information
delatbabel authored Jun 22, 2016
2 parents a0c8b21 + 82b1686 commit 54846f2
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 13 deletions.
3 changes: 3 additions & 0 deletions .idea/copyright/profiles_settings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 25 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
32 changes: 26 additions & 6 deletions src/Message/UpdatePaymentMethodRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
}
}
14 changes: 7 additions & 7 deletions tests/Message/UpdatePaymentMethodRequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand All @@ -39,7 +39,7 @@ public function testGetDataNoParameters()
{
$this->request->initialize(
array(
'token' => 'abcd1234',
'paymentMethodToken' => 'abcd1234',
)
);
$expected = array(
Expand Down

0 comments on commit 54846f2

Please sign in to comment.