Skip to content

Commit 23458a4

Browse files
authored
Merge pull request #121 from alberto1el/master
OpaqueData on CIM CreatePaymentProfile/UpdatePaymentProfile
2 parents 8c7ca9c + 66a83f1 commit 23458a4

7 files changed

+58
-23
lines changed

src/CIMGateway.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,11 @@ public function createCard(array $parameters = array())
4646
return $this->createRequest('\Omnipay\AuthorizeNet\Message\CIMCreateCardRequest', $parameters);
4747
}
4848

49+
public function updateCard(array $parameters = array())
50+
{
51+
return $this->createRequest('\Omnipay\AuthorizeNet\Message\CIMUpdatePaymentProfileRequest', $parameters);
52+
}
53+
4954
public function getPaymentProfile(array $parameters = array())
5055
{
5156
return $this->createRequest('\Omnipay\AuthorizeNet\Message\CIMGetPaymentProfileRequest', $parameters);

src/Message/CIMCreateCardRequest.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,8 +214,11 @@ public function createPaymentProfile(CIMCreateCardResponse $createCardResponse)
214214
$createPaymentProfileResponse = $this->makeCreatePaymentProfileRequest($parameters);
215215
if ($createPaymentProfileResponse->isSuccessful()) {
216216
$parameters['customerPaymentProfileId'] = $createPaymentProfileResponse->getCustomerPaymentProfileId();
217-
} elseif ($this->getForceCardUpdate() !== true) {
217+
} elseif ($this->getForceCardUpdate() !== true ||
218+
($this->getOpaqueDataDescriptor() && $this->getOpaqueDataValue())
219+
) {
218220
// force card update flag turned off. No need to further process.
221+
// also if opaque data is being used we are not able to update existing payment profiles
219222
return $createCardResponse;
220223
}
221224

src/Message/CIMCreatePaymentProfileRequest.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,7 @@ class CIMCreatePaymentProfileRequest extends CIMCreateCardRequest
1414
public function getData()
1515
{
1616
$this->validate('card', 'customerProfileId');
17-
18-
/** @var CreditCard $card */
19-
$card = $this->getCard();
20-
$card->validate();
21-
17+
$this->cardValidate();
2218
$data = $this->getBaseData();
2319
$data->customerProfileId = $this->getCustomerProfileId();
2420
$this->addPaymentProfileData($data);

src/Message/CIMUpdatePaymentProfileRequest.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,7 @@ public function getData()
1515
{
1616
$this->validate('card', 'customerProfileId', 'customerPaymentProfileId');
1717

18-
/** @var CreditCard $card */
19-
$card = $this->getCard();
20-
$card->validate();
18+
$this->cardValidate();
2119

2220
$data = $this->getBaseData();
2321
$data->customerProfileId = $this->getCustomerProfileId();

tests/CIMGatewayTest.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,21 @@ public function testShouldCreateCardIfDuplicateCustomerProfileExists()
130130
$this->assertSame('Successful.', $response->getMessage());
131131
}
132132

133+
public function testShouldCreateCardFromOpaqueDataIfDuplicateCustomerProfileExists()
134+
{
135+
$this->setMockHttpResponse(array('CIMCreateCardFailureWithDuplicate.txt', 'CIMCreatePaymentProfileSuccess.txt',
136+
'CIMGetProfileSuccess.txt', 'CIMGetPaymentProfileSuccess.txt'));
137+
138+
$response = $this->gateway->createCard($this->createCardFromOpaqueDataOptions)->send();
139+
140+
$this->assertTrue($response->isSuccessful());
141+
$this->assertSame(
142+
'{"customerProfileId":"28775801","customerPaymentProfileId":"26485433"}',
143+
$response->getCardReference()
144+
);
145+
$this->assertSame('Successful.', $response->getMessage());
146+
}
147+
133148
public function testShouldUpdateExistingPaymentProfileIfDuplicateExistsAndForceCardUpdateIsSet()
134149
{
135150
// Duplicate **payment** profile
@@ -146,6 +161,17 @@ public function testShouldUpdateExistingPaymentProfileIfDuplicateExistsAndForceC
146161
$this->assertSame('Successful.', $response->getMessage());
147162
}
148163

164+
public function testDoesntUpdateExistingPaymentProfileFromOpaqueData()
165+
{
166+
// Duplicate **payment** profile
167+
$this->setMockHttpResponse(array('CIMCreateCardFailureWithDuplicate.txt', 'CIMCreatePaymentProfileFailure.txt',
168+
'CIMGetProfileSuccess.txt', 'CIMUpdatePaymentProfileSuccess.txt', 'CIMGetPaymentProfileSuccess.txt'));
169+
170+
$response = $this->gateway->createCard($this->createCardFromOpaqueDataOptions)->send();
171+
172+
$this->assertFalse($response->isSuccessful());
173+
}
174+
149175
public function testShouldUpdateExistingPaymentProfileIfDuplicateExistsAndMaxPaymentProfileLimitIsMet()
150176
{
151177
$this->setMockHttpResponse(array('CIMCreateCardFailureWithDuplicate.txt',

tests/Message/CIMCreateCardResponseTest.php

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -43,18 +43,4 @@ 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-
}
6046
}

tests/Message/CIMCreatePaymentProfileRequestTest.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,25 @@ public function testGetData()
3131
$this->assertEquals($card['number'], $data->paymentProfile->payment->creditCard->cardNumber);
3232
$this->assertEquals('testMode', $data->validationMode);
3333
}
34+
35+
public function testGetDataOpaqueData()
36+
{
37+
$validCard = $this->getValidCard();
38+
unset($validCard['number'],$validCard['expiryMonth'],$validCard['expiryYear'],$validCard['cvv']);
39+
//remove the actual card data since we are setting opaque values
40+
$this->request->initialize(
41+
array(
42+
'customerProfileId' => '28775801',
43+
'email' => "[email protected]",
44+
'card' => $validCard,
45+
'opaqueDataDescriptor' => 'COMMON.ACCEPT.INAPP.PAYMENT',
46+
'opaqueDataValue' => 'jb2RlIjoiNTB',
47+
'developerMode' => true
48+
)
49+
);
50+
51+
$data = $this->request->getData();
52+
$this->assertEquals('COMMON.ACCEPT.INAPP.PAYMENT', $data->paymentProfile->payment->opaqueData->dataDescriptor);
53+
$this->assertEquals('jb2RlIjoiNTB', $data->paymentProfile->payment->opaqueData->dataValue);
54+
}
3455
}

0 commit comments

Comments
 (0)