Skip to content

Commit 55b6038

Browse files
committed
Add tests for CIM create card feature using Opaque Data
1 parent 408773a commit 55b6038

File tree

3 files changed

+61
-0
lines changed

3 files changed

+61
-0
lines changed

tests/CIMGatewayTest.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,18 @@ public function setUp()
3131
'forceCardUpdate' => true
3232
);
3333

34+
$validCard = $this->getValidCard();
35+
unset($validCard['number'],$validCard['expiryMonth'],$validCard['expiryYear'],$validCard['cvv']);
36+
//remove the actual card data since we are setting opaque values
37+
$this->createCardFromOpaqueDataOptions = array(
38+
'email' => "[email protected]",
39+
'card' => $validCard,
40+
'opaqueDataDescriptor' => 'COMMON.ACCEPT.INAPP.PAYMENT',
41+
'opaqueDataValue' => 'jb2RlIjoiNTB',
42+
'testMode' => true,
43+
'forceCardUpdate' => true
44+
);
45+
3446
$this->authorizeOptions = array(
3547
'cardReference' => '{"customerProfileId":"28972084","customerPaymentProfileId":"26317840","customerShippingAddressId":"27057149"}',
3648
'amount' => 10.00,
@@ -89,6 +101,20 @@ public function testCreateCardSuccess()
89101
$this->assertSame('Successful.', $response->getMessage());
90102
}
91103

104+
public function testCreateCardFromOpaqueDataSuccess()
105+
{
106+
$this->setMockHttpResponse(array('CIMCreateCardSuccess.txt','CIMGetPaymentProfileSuccess.txt'));
107+
108+
$response = $this->gateway->createCard($this->createCardFromOpaqueDataOptions)->send();
109+
110+
$this->assertTrue($response->isSuccessful());
111+
$this->assertSame(
112+
'{"customerProfileId":"28972084","customerPaymentProfileId":"26485433"}',
113+
$response->getCardReference()
114+
);
115+
$this->assertSame('Successful.', $response->getMessage());
116+
}
117+
92118
public function testShouldCreateCardIfDuplicateCustomerProfileExists()
93119
{
94120
$this->setMockHttpResponse(array('CIMCreateCardFailureWithDuplicate.txt', 'CIMCreatePaymentProfileSuccess.txt',

tests/Message/CIMCreateCardRequestTest.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,4 +59,25 @@ public function testGetDataShouldSetValidationModeToNoneIfNoCvvProvided()
5959
$this->assertFalse(isset($data->profile->paymentProfiles->payment->creditCard->cardCode));
6060
$this->assertEquals(CIMCreatePaymentProfileRequest::VALIDATION_MODE_NONE, $this->request->getValidationMode());
6161
}
62+
63+
public function testGetDataOpaqueData()
64+
{
65+
66+
$validCard = $this->getValidCard();
67+
unset($validCard['number'],$validCard['expiryMonth'],$validCard['expiryYear'],$validCard['cvv']);
68+
//remove the actual card data since we are setting opaque values
69+
$this->params = array(
70+
'email' => "[email protected]",
71+
'card' => $validCard,
72+
'opaqueDataDescriptor' => 'COMMON.ACCEPT.INAPP.PAYMENT',
73+
'opaqueDataValue' => 'jb2RlIjoiNTB',
74+
'developerMode' => true
75+
);
76+
$this->request->initialize($this->params);
77+
78+
$data = $this->request->getData();
79+
80+
$this->assertEquals('COMMON.ACCEPT.INAPP.PAYMENT', $data->profile->paymentProfiles->payment->opaqueData->dataDescriptor);
81+
$this->assertEquals('jb2RlIjoiNTB', $data->profile->paymentProfiles->payment->opaqueData->dataValue);
82+
}
6283
}

tests/Message/CIMCreateCardResponseTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,18 @@ public function testCreateCardFailure()
4343

4444
$this->assertNull($response->getCardReference());
4545
}
46+
47+
public function testCreateCardSuccessFromOpaqueData()
48+
{
49+
$httpResponse = $this->getMockHttpResponse('CIMCreateCardSuccess.txt');
50+
$response = new CIMCreateCardResponse($this->getMockRequest(), $httpResponse->getBody());
51+
52+
$this->assertTrue($response->isSuccessful());
53+
$this->assertEquals('I00001', $response->getReasonCode());
54+
$this->assertEquals("1", $response->getResultCode());
55+
$this->assertEquals("Successful.", $response->getMessage());
56+
57+
$this->assertEquals('28972084', $response->getCustomerProfileId());
58+
$this->assertEquals('26317840', $response->getCustomerPaymentProfileId());
59+
}
4660
}

0 commit comments

Comments
 (0)