Skip to content

Commit

Permalink
Merge pull request #7 from RentMoola/UpdatePaymentMethod
Browse files Browse the repository at this point in the history
Update payment method
  • Loading branch information
Shawg authored Jun 28, 2016
2 parents 45fa4f2 + 9ccaffc commit 29baf6c
Show file tree
Hide file tree
Showing 6 changed files with 134 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/Gateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,14 @@ public function fetchPaymentMethods(array $parameters = array())
);
}

public function updateCCPaymentMethod(array $parameters = array())
{
return $this->createRequest(
'\Omnipay\RentMoola\Message\UpdateCCPaymentMethodRequest',
$parameters
);
}

public function fetchUser(array $parameters = array())
{
return $this->createRequest(
Expand Down
30 changes: 30 additions & 0 deletions src/Message/UpdateCCPaymentMethodRequest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

namespace Omnipay\RentMoola\Message;

class UpdateCCPaymentMethodRequest extends AbstractRequest
{
public function getData()
{
$this->validate('userId');
$this->validate('paymentMethodId');

$data = array();

return $data;
}

public function sendData($data)
{
$httpResponse = $this->sendRequest(
'PUT',
'/users/'.$this->getUserId().'/payments/'.$this->getPaymentMethodId().'/cc',
$data
);

if ($httpResponse->isSuccessful()) {
return $this->response = new Response($this, json_decode('[]'));
}
return $this->response = new Response($this, $httpResponse->json());
}
}
10 changes: 10 additions & 0 deletions tests/GatewayTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,16 @@ public function testFetchPaymentMethods()
);
}

public function testUpdateCCPaymentMethod()
{
$request = $this->gateway->updateCCPaymentMethod();

$this->assertInstanceOf(
'Omnipay\RentMoola\Message\UpdateCCPaymentMethodRequest',
$request
);
}

public function testFetchPayment()
{
$request = $this->gateway->fetchPayment();
Expand Down
55 changes: 55 additions & 0 deletions tests/Message/UpdateCCPaymentMethodRequestTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?php

namespace Omnipay\RentMoola\Message;

use Omnipay\Tests\TestCase;

class UpdateCCPaymentMethodRequestTest extends TestCase
{
public function setUp()
{
$this->request = new UpdateCCPaymentMethodRequest(
$this->getHttpClient(),
$this->getHttpRequest()
);
$this->request->initialize(
array(
'userId' => '24a58d3c-4774-48bb-803a-b0ccc6b2d8d5',
'paymentMethodId' => 'd502ad2d-e103-4e04-b2a2-fdd7c547eb06',
'name' => 'Joe Smith',
'number' => '4444333322221111',
'cvc' => '212',
'expiryMonth' => '09',
'expiryYear' => '2018',
'destinationAccountId' => '41fcd0ff-7c57-403a-9bd5-e850056fdc2a',
'state' => 'WA',
'country' => 'USA',
'zip' => '90210',
'city' => 'Tampa',
'address1' => '124 West Street',
'address2' => '126 West Street',
)
);
}

public function testSendSuccess()
{
$this->setMockHttpResponse('UpdateCCPaymentMethodSuccess.txt');
$response = $this->request->send();

$this->assertTrue($response->isSuccessful());
$this->assertFalse($response->isRedirect());
$this->assertNull($response->getErrorMessage());
$this->assertNull($response->getErrorCode());
}

public function testSendFailure()
{
$this->setMockHttpResponse('UpdateCCPaymentMethodFailure.txt');
$response = $this->request->send();

$this->assertFalse($response->isSuccessful());
$this->assertFalse($response->isRedirect());
$this->assertEquals("may not be empty", $response->getErrorMessage());
}
}
23 changes: 23 additions & 0 deletions tests/Mock/UpdateCCPaymentMethodFailure.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
HTTP/1.1 400 Bad Request
Connection = keep-alive
Content-Encoding = gzip
Content-Length = 154
Content-Type = application/json
Date = Tue, 10 May 2016 16:32:47 GMT
Vary = Accept-Encoding
X-Frame-Options = SAMEORIGIN

{
"error": [
{
"path": "updatePaymentMethodCC.arg3.name",
"message": "may not be empty",
"value": ""
},
{
"path": "updatePaymentMethodCC.arg3.number",
"message": "Enter your credit card number",
"value": ""
}
]
}
8 changes: 8 additions & 0 deletions tests/Mock/UpdateCCPaymentMethodSuccess.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
HTTP/1.1 200 OK
Connection = keep-alive
Content-Encoding = gzip
Content-Length = 154
Content-Type = application/json
Date = Tue, 10 May 2016 16:32:47 GMT
Vary = Accept-Encoding
X-Frame-Options = SAMEORIGIN

0 comments on commit 29baf6c

Please sign in to comment.