Skip to content

Commit b49f9b2

Browse files
authored
Merge pull request #11 from intuit/develop
Develop
2 parents eb57469 + d269122 commit b49f9b2

File tree

3 files changed

+49
-0
lines changed

3 files changed

+49
-0
lines changed

src/Operations/CardOperations.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,18 @@ public static function getAllCards($customerID, string $requestId, $context): Re
5252
return $request;
5353
}
5454

55+
/**
56+
* Get a card associated with a Customer
57+
*/
58+
public static function getCard($customerID, string $cardId, string $requestId, $context): RequestInterface
59+
{
60+
$request = RequestFactory::createStandardIntuitRequest(RequestType::CARD);
61+
$request->setMethod(RequestInterface::GET)
62+
->setUrl($context->getBaseUrl() . EndpointUrls::CUSTOMER_URL . "/" . $customerID . "/cards" . "/" . $cardId)
63+
->setHeader($context->getStandardHeaderWithRequestID($requestId));
64+
return $request;
65+
}
66+
5567
/**
5668
* Create a Card from Token
5769
*/

src/PaymentClient.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,20 @@ public function createCard(Card $card, $customerID, string $requestId = ""): Res
185185
return $response;
186186
}
187187

188+
public function getCard($customerID, string $cardId, string $requestId = ""): ResponseInterface
189+
{
190+
if (empty($requestId)) {
191+
$requestId = ClientContext::generateRequestID();
192+
}
193+
$request = CardOperations::getCard($customerID, $cardId, $requestId, $this->getContext());
194+
$this->before($request, $this);
195+
$response = $this->httpClient->send($request);
196+
$this->after($response, $this);
197+
$this->intercept($request, $response);
198+
OperationsConverter::updateResponseBodyToObj($response);
199+
return $response;
200+
}
201+
188202
public function deleteCard($customerID, string $cardId, string $requestId = ""): ResponseInterface
189203
{
190204
if (empty($requestId)) {

tests/CardTest.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,29 @@ public function testallCardsOnSandbox(): void
115115
$client->deleteCard($customerId, $id2);
116116
}
117117

118+
public function testFindACustomerCardOnSandbox(): void
119+
{
120+
$client = $this->createInstance();
121+
$card = $this->createCardBody();
122+
$customerId = rand();
123+
124+
/** Add a test card */
125+
$response = $client->createCard($card, $customerId);
126+
$id1 = $response->getBody()->id;
127+
$secureCardNumber1 = $response->getBody()->number;
128+
129+
/** Retrieve the test card */
130+
$response2 = $client->getCard($customerId, $id1);
131+
$id2 = $response2->getBody()->id;
132+
$secureCardNumber2 = $response->getBody()->number;
133+
134+
/** Make sure the retrieved secure card matches the originally added card */
135+
$this->assertEquals($id1, $id2);
136+
$this->assertEquals($secureCardNumber1, $secureCardNumber2);
137+
138+
$client->deleteCard($customerId, $id1);
139+
}
140+
118141
public function testCreateCardToken(): void
119142
{
120143
$client = $this->createInstance();

0 commit comments

Comments
 (0)