Skip to content

Commit

Permalink
Merge pull request #121 from alberto1el/master
Browse files Browse the repository at this point in the history
OpaqueData on CIM CreatePaymentProfile/UpdatePaymentProfile
  • Loading branch information
judgej authored Jan 5, 2019
2 parents 8c7ca9c + 66a83f1 commit 23458a4
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 23 deletions.
5 changes: 5 additions & 0 deletions src/CIMGateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ public function createCard(array $parameters = array())
return $this->createRequest('\Omnipay\AuthorizeNet\Message\CIMCreateCardRequest', $parameters);
}

public function updateCard(array $parameters = array())
{
return $this->createRequest('\Omnipay\AuthorizeNet\Message\CIMUpdatePaymentProfileRequest', $parameters);
}

public function getPaymentProfile(array $parameters = array())
{
return $this->createRequest('\Omnipay\AuthorizeNet\Message\CIMGetPaymentProfileRequest', $parameters);
Expand Down
5 changes: 4 additions & 1 deletion src/Message/CIMCreateCardRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -214,8 +214,11 @@ public function createPaymentProfile(CIMCreateCardResponse $createCardResponse)
$createPaymentProfileResponse = $this->makeCreatePaymentProfileRequest($parameters);
if ($createPaymentProfileResponse->isSuccessful()) {
$parameters['customerPaymentProfileId'] = $createPaymentProfileResponse->getCustomerPaymentProfileId();
} elseif ($this->getForceCardUpdate() !== true) {
} elseif ($this->getForceCardUpdate() !== true ||
($this->getOpaqueDataDescriptor() && $this->getOpaqueDataValue())
) {
// force card update flag turned off. No need to further process.
// also if opaque data is being used we are not able to update existing payment profiles
return $createCardResponse;
}

Expand Down
6 changes: 1 addition & 5 deletions src/Message/CIMCreatePaymentProfileRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,7 @@ class CIMCreatePaymentProfileRequest extends CIMCreateCardRequest
public function getData()
{
$this->validate('card', 'customerProfileId');

/** @var CreditCard $card */
$card = $this->getCard();
$card->validate();

$this->cardValidate();
$data = $this->getBaseData();
$data->customerProfileId = $this->getCustomerProfileId();
$this->addPaymentProfileData($data);
Expand Down
4 changes: 1 addition & 3 deletions src/Message/CIMUpdatePaymentProfileRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@ public function getData()
{
$this->validate('card', 'customerProfileId', 'customerPaymentProfileId');

/** @var CreditCard $card */
$card = $this->getCard();
$card->validate();
$this->cardValidate();

$data = $this->getBaseData();
$data->customerProfileId = $this->getCustomerProfileId();
Expand Down
26 changes: 26 additions & 0 deletions tests/CIMGatewayTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,21 @@ public function testShouldCreateCardIfDuplicateCustomerProfileExists()
$this->assertSame('Successful.', $response->getMessage());
}

public function testShouldCreateCardFromOpaqueDataIfDuplicateCustomerProfileExists()
{
$this->setMockHttpResponse(array('CIMCreateCardFailureWithDuplicate.txt', 'CIMCreatePaymentProfileSuccess.txt',
'CIMGetProfileSuccess.txt', 'CIMGetPaymentProfileSuccess.txt'));

$response = $this->gateway->createCard($this->createCardFromOpaqueDataOptions)->send();

$this->assertTrue($response->isSuccessful());
$this->assertSame(
'{"customerProfileId":"28775801","customerPaymentProfileId":"26485433"}',
$response->getCardReference()
);
$this->assertSame('Successful.', $response->getMessage());
}

public function testShouldUpdateExistingPaymentProfileIfDuplicateExistsAndForceCardUpdateIsSet()
{
// Duplicate **payment** profile
Expand All @@ -146,6 +161,17 @@ public function testShouldUpdateExistingPaymentProfileIfDuplicateExistsAndForceC
$this->assertSame('Successful.', $response->getMessage());
}

public function testDoesntUpdateExistingPaymentProfileFromOpaqueData()
{
// Duplicate **payment** profile
$this->setMockHttpResponse(array('CIMCreateCardFailureWithDuplicate.txt', 'CIMCreatePaymentProfileFailure.txt',
'CIMGetProfileSuccess.txt', 'CIMUpdatePaymentProfileSuccess.txt', 'CIMGetPaymentProfileSuccess.txt'));

$response = $this->gateway->createCard($this->createCardFromOpaqueDataOptions)->send();

$this->assertFalse($response->isSuccessful());
}

public function testShouldUpdateExistingPaymentProfileIfDuplicateExistsAndMaxPaymentProfileLimitIsMet()
{
$this->setMockHttpResponse(array('CIMCreateCardFailureWithDuplicate.txt',
Expand Down
14 changes: 0 additions & 14 deletions tests/Message/CIMCreateCardResponseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,18 +43,4 @@ public function testCreateCardFailure()

$this->assertNull($response->getCardReference());
}

public function testCreateCardSuccessFromOpaqueData()
{
$httpResponse = $this->getMockHttpResponse('CIMCreateCardSuccess.txt');
$response = new CIMCreateCardResponse($this->getMockRequest(), $httpResponse->getBody());

$this->assertTrue($response->isSuccessful());
$this->assertEquals('I00001', $response->getReasonCode());
$this->assertEquals("1", $response->getResultCode());
$this->assertEquals("Successful.", $response->getMessage());

$this->assertEquals('28972084', $response->getCustomerProfileId());
$this->assertEquals('26317840', $response->getCustomerPaymentProfileId());
}
}
21 changes: 21 additions & 0 deletions tests/Message/CIMCreatePaymentProfileRequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,25 @@ public function testGetData()
$this->assertEquals($card['number'], $data->paymentProfile->payment->creditCard->cardNumber);
$this->assertEquals('testMode', $data->validationMode);
}

public function testGetDataOpaqueData()
{
$validCard = $this->getValidCard();
unset($validCard['number'],$validCard['expiryMonth'],$validCard['expiryYear'],$validCard['cvv']);
//remove the actual card data since we are setting opaque values
$this->request->initialize(
array(
'customerProfileId' => '28775801',
'email' => "[email protected]",
'card' => $validCard,
'opaqueDataDescriptor' => 'COMMON.ACCEPT.INAPP.PAYMENT',
'opaqueDataValue' => 'jb2RlIjoiNTB',
'developerMode' => true
)
);

$data = $this->request->getData();
$this->assertEquals('COMMON.ACCEPT.INAPP.PAYMENT', $data->paymentProfile->payment->opaqueData->dataDescriptor);
$this->assertEquals('jb2RlIjoiNTB', $data->paymentProfile->payment->opaqueData->dataValue);
}
}

0 comments on commit 23458a4

Please sign in to comment.