Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix - Payment Profile Card requests (Add and Update) #12

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
13 changes: 10 additions & 3 deletions src/Message/CreateProfileCardRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,14 @@ public function getEndpoint()

public function getData()
{
$data = array();
$this->getCard()->validate();
$data = array(
'comment' => $this->getComment()
);

if ($this->getCard()) {
$data = array(
$this->getCard()->validate();

$data['card'] = array(
'number' => $this->getCard()->getNumber(),
'name' => $this->getCard()->getName(),
'expiry_month' => $this->getCard()->getExpiryDate('m'),
Expand All @@ -22,6 +25,10 @@ public function getData()
);
}

if ($this->getToken()) {
$data['token'] = $this->getToken();
}

return $data;
}

Expand Down
29 changes: 24 additions & 5 deletions tests/Message/CreateProfileCardRequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,35 @@ public function testEndpoint()
$this->assertSame('https://www.beanstream.com/api/v1/profiles/' . $this->request->getProfileId(). '/cards', $this->request->getEndpoint());
}

public function testComment()
{
$this->assertSame($this->request, $this->request->setComment('test'));
$this->assertSame('test', $this->request->getComment());
}

public function testCard()
{
$card = $this->getValidCard();
$this->assertSame($this->request, $this->request->setCard($card));
$data = $this->request->getData();
$this->assertSame($card['number'], $data['number']);
$this->assertSame($card['cvv'], $data['cvd']);
$this->assertSame(sprintf("%02d", $card['expiryMonth']), $data['expiry_month']);
$this->assertSame(substr($card['expiryYear'], -2), $data['expiry_year']);
$this->assertSame($card['firstName'] . ' ' . $card['lastName'], $data['name']);
$this->assertSame($card['number'], $data['card']['number']);
$this->assertSame($card['cvv'], $data['card']['cvd']);
$this->assertSame(sprintf("%02d", $card['expiryMonth']), $data['card']['expiry_month']);
$this->assertSame(substr($card['expiryYear'], -2), $data['card']['expiry_year']);
$this->assertSame($card['firstName'] . ' ' . $card['lastName'], $data['card']['name']);
}

public function testToken()
{
$token = array(
'name' => 'token-test-name',
'code' => 'token-test-code'
);

$this->assertSame($this->request, $this->request->setToken($token));
$this->assertSame($token, $this->request->getToken());
$data = $this->request->getData();
$this->assertSame($token, $data['token']);
}

public function testHttpMethod()
Expand Down
56 changes: 56 additions & 0 deletions tests/Message/UpdateProfileCardRequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,34 @@ public function setUp()
$this->request->initialize();
}

public function testSendSuccess()
{
$this->request->setProfileId('9ba60541d32648B1A3581670123dF2Ef');
$this->request->setCardId('1');
$card = $this->getValidCard();
$this->assertSame($this->request, $this->request->setCard($card));
$this->setMockHttpResponse('UpdateProfileCardSuccess.txt');
$response = $this->request->send();
$this->assertTrue($response->isSuccessful());
$this->assertSame(1, $response->getCode());
$this->assertSame('Operation Successful', $response->getMessage());
$this->assertSame('9ba60541d32648B1A3581670123dF2Ef', $response->getCustomerCode());
}

public function testSendError()
{
$this->request->setProfileId('9ba60541d32648B1A3581670123dF2Ef');
$this->request->setCardId('1');
$card = $this->getValidCard();
$this->assertSame($this->request, $this->request->setCard($card));
$this->setMockHttpResponse('UpdateProfileCardFailure.txt');
$response = $this->request->send();
$this->assertFalse($response->isSuccessful());
$this->assertSame(19, $response->getCode());
$this->assertSame(3, $response->getCategory());
$this->assertSame('Customer information failed data validation', $response->getMessage());
}

public function testEndpoint()
{
$this->assertSame($this->request, $this->request->setProfileId('1'));
Expand All @@ -21,10 +49,38 @@ public function testEndpoint()
$this->assertSame('https://www.beanstream.com/api/v1/profiles/' . $this->request->getProfileId() . '/cards/' . $this->request->getCardId(), $this->request->getEndpoint());
}

public function testComment()
{
$this->assertSame($this->request, $this->request->setComment('test'));
$this->assertSame('test', $this->request->getComment());
}

public function testCard()
{
$this->request->setProfileId('8F10Ab54FC434b71972cF2E442c0fb4f');
$this->request->setCardId('1');
$card = $this->getValidCard();
$this->assertSame($this->request, $this->request->setCard($card));
$data = $this->request->getData();
$this->assertSame($card['number'], $data['card']['number']);
$this->assertSame($card['cvv'], $data['card']['cvd']);
$this->assertSame(sprintf("%02d", $card['expiryMonth']), $data['card']['expiry_month']);
$this->assertSame(substr($card['expiryYear'], -2), $data['card']['expiry_year']);
$this->assertSame($card['firstName'] . ' ' . $card['lastName'], $data['card']['name']);
}

public function testToken()
{
$this->request->setProfileId('8F10Ab54FC434b71972cF2E442c0fb4f');
$this->request->setCardId('1');
$token = array(
'name' => 'token-test-name',
'code' => 'token-test-code'
);
$this->assertSame($this->request, $this->request->setToken($token));
$this->assertSame($token, $this->request->getToken());
$data = $this->request->getData();
$this->assertSame($token, $data['token']);
}

public function testHttpMethod()
Expand Down
10 changes: 10 additions & 0 deletions tests/Mock/UpdateProfileCardFailure.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
HTTP/1.1 400 Bad Request
Content-Type: application/json

{
"code": 19,
"category": 3,
"message": "Customer information failed data validation",
"reference": null,
"details": []
}
1 change: 0 additions & 1 deletion tests/Mock/UpdateProfileCardSuccess.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ Server: Microsoft-IIS/8.5
X-AspNet-Version: 4.0.30319
X-Powered-By: ASP.NET


{
"code": 1,
"message": "Operation Successful",
Expand Down