From b66ea0dc98f707dd54a542f8f65159f1aa6b9d0d Mon Sep 17 00:00:00 2001 From: Alberto Date: Sun, 30 Dec 2018 01:58:35 -0800 Subject: [PATCH 01/11] Add opaqueData to createCard on CIM --- src/Message/CIMAbstractRequest.php | 38 ++++++++++++++++++++++++ src/Message/CIMCreateCardRequest.php | 43 +++++++++++++++++++++------- 2 files changed, 70 insertions(+), 11 deletions(-) diff --git a/src/Message/CIMAbstractRequest.php b/src/Message/CIMAbstractRequest.php index 7e055c43..acb47c4a 100644 --- a/src/Message/CIMAbstractRequest.php +++ b/src/Message/CIMAbstractRequest.php @@ -72,6 +72,44 @@ public function getCustomerPaymentProfileId() return $this->getParameter('customerPaymentProfileId'); } + /** + * @link http://developer.authorize.net/api/reference/features/acceptjs.html Documentation on opaque data + * @return string + */ + public function getOpaqueDataDescriptor() + { + return $this->getParameter('opaqueDataDescriptor'); + } + + /** + * @link http://developer.authorize.net/api/reference/features/acceptjs.html Documentation on opaque data + * @return string + */ + public function getOpaqueDataValue() + { + return $this->getParameter('opaqueDataValue'); + } + + /** + * @link http://developer.authorize.net/api/reference/features/acceptjs.html Documentation on opaque data + * @param string + * @return string + */ + public function setOpaqueDataDescriptor($value) + { + return $this->setParameter('opaqueDataDescriptor', $value); + } + + /** + * @link http://developer.authorize.net/api/reference/features/acceptjs.html Documentation on opaque data + * @param string + * @return string + */ + public function setOpaqueDataValue($value) + { + return $this->setParameter('opaqueDataValue', $value); + } + /** * Flag to force update consumer payment profile if duplicate is found * diff --git a/src/Message/CIMCreateCardRequest.php b/src/Message/CIMCreateCardRequest.php index 99313b66..69f9c2ba 100644 --- a/src/Message/CIMCreateCardRequest.php +++ b/src/Message/CIMCreateCardRequest.php @@ -13,19 +13,34 @@ class CIMCreateCardRequest extends CIMAbstractRequest public function getData() { - $this->validate('card'); - - /** @var CreditCard $card */ - $card = $this->getCard(); - $card->validate(); $data = $this->getBaseData(); + $this->validateCard($data); $this->addProfileData($data); $this->addTransactionSettings($data); return $data; } + /** + * Validate card or skip if opaque data is available + * + * @param \SimpleXMLElement $data + */ + protected function validateCard(\SimpleXMLElement $data){ + + if ($this->getOpaqueDataDescriptor() && $this->getOpaqueDataValue()) { + return; + } + + $this->validate('card'); + + /** @var CreditCard $card */ + $card = $this->getCard(); + $card->validate(); + + } + /** * Add customer profile data to the specified xml element * @@ -97,12 +112,18 @@ protected function addBillingData(\SimpleXMLElement $data) } $req = $data->addChild('payment'); - $req->creditCard->cardNumber = $card->getNumber(); - $req->creditCard->expirationDate = $card->getExpiryDate('Y-m'); - if ($card->getCvv()) { - $req->creditCard->cardCode = $card->getCvv(); - } else { - $this->setValidationMode(self::VALIDATION_MODE_NONE); + if ($this->getOpaqueDataDescriptor() && $this->getOpaqueDataValue()) { + //Use opaqueData if available instead of card data + $req->opaqueData->dataDescriptor = $this->getOpaqueDataDescriptor(); + $req->opaqueData->dataValue = $this->getOpaqueDataValue(); + }else{ + $req->creditCard->cardNumber = $card->getNumber(); + $req->creditCard->expirationDate = $card->getExpiryDate('Y-m'); + if ($card->getCvv()) { + $req->creditCard->cardCode = $card->getCvv(); + } else { + $this->setValidationMode(self::VALIDATION_MODE_NONE); + } } } } From af657cefb0b52639a87dd1d10480f5e5384d561f Mon Sep 17 00:00:00 2001 From: Alberto Date: Sun, 30 Dec 2018 02:46:10 -0800 Subject: [PATCH 02/11] Fix psr2 style errors --- src/Message/CIMCreateCardRequest.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Message/CIMCreateCardRequest.php b/src/Message/CIMCreateCardRequest.php index 69f9c2ba..eca8a75f 100644 --- a/src/Message/CIMCreateCardRequest.php +++ b/src/Message/CIMCreateCardRequest.php @@ -27,7 +27,8 @@ public function getData() * * @param \SimpleXMLElement $data */ - protected function validateCard(\SimpleXMLElement $data){ + protected function validateCard(\SimpleXMLElement $data) + { if ($this->getOpaqueDataDescriptor() && $this->getOpaqueDataValue()) { return; @@ -38,7 +39,6 @@ protected function validateCard(\SimpleXMLElement $data){ /** @var CreditCard $card */ $card = $this->getCard(); $card->validate(); - } /** @@ -116,7 +116,7 @@ protected function addBillingData(\SimpleXMLElement $data) //Use opaqueData if available instead of card data $req->opaqueData->dataDescriptor = $this->getOpaqueDataDescriptor(); $req->opaqueData->dataValue = $this->getOpaqueDataValue(); - }else{ + } else { $req->creditCard->cardNumber = $card->getNumber(); $req->creditCard->expirationDate = $card->getExpiryDate('Y-m'); if ($card->getCvv()) { From fe3f20ccc90872902f40e163480a39c96fd921f1 Mon Sep 17 00:00:00 2001 From: Alberto Date: Sun, 30 Dec 2018 03:05:34 -0800 Subject: [PATCH 03/11] go back to previous getData order on CIMCreateCardRequest --- src/Message/CIMCreateCardRequest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Message/CIMCreateCardRequest.php b/src/Message/CIMCreateCardRequest.php index eca8a75f..3077558f 100644 --- a/src/Message/CIMCreateCardRequest.php +++ b/src/Message/CIMCreateCardRequest.php @@ -14,8 +14,8 @@ class CIMCreateCardRequest extends CIMAbstractRequest public function getData() { - $data = $this->getBaseData(); $this->validateCard($data); + $data = $this->getBaseData(); $this->addProfileData($data); $this->addTransactionSettings($data); From 87d07ae566bdf8d437483a3b3ae42fd8cdec1406 Mon Sep 17 00:00:00 2001 From: Alberto Date: Sun, 30 Dec 2018 03:09:20 -0800 Subject: [PATCH 04/11] remove data variable not used on validateCard method --- src/Message/CIMCreateCardRequest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Message/CIMCreateCardRequest.php b/src/Message/CIMCreateCardRequest.php index 3077558f..512cd853 100644 --- a/src/Message/CIMCreateCardRequest.php +++ b/src/Message/CIMCreateCardRequest.php @@ -14,7 +14,7 @@ class CIMCreateCardRequest extends CIMAbstractRequest public function getData() { - $this->validateCard($data); + $this->validateCard(); $data = $this->getBaseData(); $this->addProfileData($data); $this->addTransactionSettings($data); @@ -27,7 +27,7 @@ public function getData() * * @param \SimpleXMLElement $data */ - protected function validateCard(\SimpleXMLElement $data) + protected function validateCard() { if ($this->getOpaqueDataDescriptor() && $this->getOpaqueDataValue()) { From 989feddd5242d65c84fd8198f77cb3ed6bc489ef Mon Sep 17 00:00:00 2001 From: Alberto Date: Sun, 30 Dec 2018 03:15:04 -0800 Subject: [PATCH 05/11] leave validate card which only validates the presence of the card param --- src/Message/CIMCreateCardRequest.php | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/Message/CIMCreateCardRequest.php b/src/Message/CIMCreateCardRequest.php index 512cd853..ea0e02de 100644 --- a/src/Message/CIMCreateCardRequest.php +++ b/src/Message/CIMCreateCardRequest.php @@ -14,7 +14,8 @@ class CIMCreateCardRequest extends CIMAbstractRequest public function getData() { - $this->validateCard(); + $this->validate('card'); + $this->cardValidate(); $data = $this->getBaseData(); $this->addProfileData($data); $this->addTransactionSettings($data); @@ -27,15 +28,13 @@ public function getData() * * @param \SimpleXMLElement $data */ - protected function validateCard() + protected function cardValidate() { if ($this->getOpaqueDataDescriptor() && $this->getOpaqueDataValue()) { return; } - $this->validate('card'); - /** @var CreditCard $card */ $card = $this->getCard(); $card->validate(); From 408773ad91d7ebfd78c2bfe1aa031ecb2cc0b229 Mon Sep 17 00:00:00 2001 From: Alberto Date: Sun, 30 Dec 2018 23:31:37 -0800 Subject: [PATCH 06/11] remove duplicated methods from extended AIMAbstractRequest --- src/Message/CIMAbstractRequest.php | 38 ------------------------------ 1 file changed, 38 deletions(-) diff --git a/src/Message/CIMAbstractRequest.php b/src/Message/CIMAbstractRequest.php index acb47c4a..7e055c43 100644 --- a/src/Message/CIMAbstractRequest.php +++ b/src/Message/CIMAbstractRequest.php @@ -72,44 +72,6 @@ public function getCustomerPaymentProfileId() return $this->getParameter('customerPaymentProfileId'); } - /** - * @link http://developer.authorize.net/api/reference/features/acceptjs.html Documentation on opaque data - * @return string - */ - public function getOpaqueDataDescriptor() - { - return $this->getParameter('opaqueDataDescriptor'); - } - - /** - * @link http://developer.authorize.net/api/reference/features/acceptjs.html Documentation on opaque data - * @return string - */ - public function getOpaqueDataValue() - { - return $this->getParameter('opaqueDataValue'); - } - - /** - * @link http://developer.authorize.net/api/reference/features/acceptjs.html Documentation on opaque data - * @param string - * @return string - */ - public function setOpaqueDataDescriptor($value) - { - return $this->setParameter('opaqueDataDescriptor', $value); - } - - /** - * @link http://developer.authorize.net/api/reference/features/acceptjs.html Documentation on opaque data - * @param string - * @return string - */ - public function setOpaqueDataValue($value) - { - return $this->setParameter('opaqueDataValue', $value); - } - /** * Flag to force update consumer payment profile if duplicate is found * From 55b60383ff7ec80aab66347e4874a1775e190d1d Mon Sep 17 00:00:00 2001 From: Alberto Date: Mon, 31 Dec 2018 00:26:08 -0800 Subject: [PATCH 07/11] Add tests for CIM create card feature using Opaque Data --- tests/CIMGatewayTest.php | 26 +++++++++++++++++++++ tests/Message/CIMCreateCardRequestTest.php | 21 +++++++++++++++++ tests/Message/CIMCreateCardResponseTest.php | 14 +++++++++++ 3 files changed, 61 insertions(+) diff --git a/tests/CIMGatewayTest.php b/tests/CIMGatewayTest.php index 3d4a85dd..1ba63b9a 100644 --- a/tests/CIMGatewayTest.php +++ b/tests/CIMGatewayTest.php @@ -31,6 +31,18 @@ public function setUp() 'forceCardUpdate' => true ); + $validCard = $this->getValidCard(); + unset($validCard['number'],$validCard['expiryMonth'],$validCard['expiryYear'],$validCard['cvv']); + //remove the actual card data since we are setting opaque values + $this->createCardFromOpaqueDataOptions = array( + 'email' => "kaylee@serenity.com", + 'card' => $validCard, + 'opaqueDataDescriptor' => 'COMMON.ACCEPT.INAPP.PAYMENT', + 'opaqueDataValue' => 'jb2RlIjoiNTB', + 'testMode' => true, + 'forceCardUpdate' => true + ); + $this->authorizeOptions = array( 'cardReference' => '{"customerProfileId":"28972084","customerPaymentProfileId":"26317840","customerShippingAddressId":"27057149"}', 'amount' => 10.00, @@ -89,6 +101,20 @@ public function testCreateCardSuccess() $this->assertSame('Successful.', $response->getMessage()); } + public function testCreateCardFromOpaqueDataSuccess() + { + $this->setMockHttpResponse(array('CIMCreateCardSuccess.txt','CIMGetPaymentProfileSuccess.txt')); + + $response = $this->gateway->createCard($this->createCardFromOpaqueDataOptions)->send(); + + $this->assertTrue($response->isSuccessful()); + $this->assertSame( + '{"customerProfileId":"28972084","customerPaymentProfileId":"26485433"}', + $response->getCardReference() + ); + $this->assertSame('Successful.', $response->getMessage()); + } + public function testShouldCreateCardIfDuplicateCustomerProfileExists() { $this->setMockHttpResponse(array('CIMCreateCardFailureWithDuplicate.txt', 'CIMCreatePaymentProfileSuccess.txt', diff --git a/tests/Message/CIMCreateCardRequestTest.php b/tests/Message/CIMCreateCardRequestTest.php index 92911b00..f97eee6b 100644 --- a/tests/Message/CIMCreateCardRequestTest.php +++ b/tests/Message/CIMCreateCardRequestTest.php @@ -59,4 +59,25 @@ public function testGetDataShouldSetValidationModeToNoneIfNoCvvProvided() $this->assertFalse(isset($data->profile->paymentProfiles->payment->creditCard->cardCode)); $this->assertEquals(CIMCreatePaymentProfileRequest::VALIDATION_MODE_NONE, $this->request->getValidationMode()); } + + 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->params = array( + 'email' => "kaylee@serenity.com", + 'card' => $validCard, + 'opaqueDataDescriptor' => 'COMMON.ACCEPT.INAPP.PAYMENT', + 'opaqueDataValue' => 'jb2RlIjoiNTB', + 'developerMode' => true + ); + $this->request->initialize($this->params); + + $data = $this->request->getData(); + + $this->assertEquals('COMMON.ACCEPT.INAPP.PAYMENT', $data->profile->paymentProfiles->payment->opaqueData->dataDescriptor); + $this->assertEquals('jb2RlIjoiNTB', $data->profile->paymentProfiles->payment->opaqueData->dataValue); + } } diff --git a/tests/Message/CIMCreateCardResponseTest.php b/tests/Message/CIMCreateCardResponseTest.php index a68942cf..e2f80d89 100644 --- a/tests/Message/CIMCreateCardResponseTest.php +++ b/tests/Message/CIMCreateCardResponseTest.php @@ -43,4 +43,18 @@ 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()); + } } From 598894884fd9ba45f0e74c99b30a7657e5188015 Mon Sep 17 00:00:00 2001 From: Alberto Date: Mon, 31 Dec 2018 00:51:10 -0800 Subject: [PATCH 08/11] adds example of opaque data on CIM createCard --- README.md | 58 +++++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 54 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 9c289280..53803e18 100644 --- a/README.md +++ b/README.md @@ -26,7 +26,7 @@ The following gateways are provided by this package: * AuthorizeNet_SIM * AuthorizeNet_DPM -In addition, `Accept.JS` is supported by the AIM driver. More details are provided below. +In addition, `Accept.JS` is supported by the AIM driver and CIM (create card). More details are provided below. For general usage instructions, please see the main [Omnipay](https://github.com/thephpleague/omnipay) repository. @@ -45,15 +45,15 @@ The card is tokenized into two values returned in `opaqueData` object from Accep These two values must be POSTed back to the merchant application, usually as a part of the payment form. Make sure the raw credit card details are NOT posted back to your site. -How this is handled is beyond this short note, but examples are always welcome in the documentation. +How this is handled is beyond this short note, but examples are always welcomed in the documentation. -On the server, the tokenized detailt are passed into the `payment` or `authorize` request object. +On the server, the tokenized details are passed into the `payment` or `authorize` request object. You will still need to pass in the `CreditCard` object, as that contains details of the payee and recipient, but just leave the credit card details of that object blank. For example: ```php // $gateway is an instantiation of the AIM driver. -// $dataDescriptor and $dataValue come from the paymentr form at the front end. +// $dataDescriptor and $dataValue come from the payment form at the front end. $request = $gateway->purchase( [ @@ -66,6 +66,56 @@ $request = $gateway->purchase( ); ``` +CIM Create Card feature usage: +Accept.js must be implemented on your frontend payment form, once Accept.js 'tokenizes' the customer's +card, just send the two opaque fields and remove the Card's (Number, Expiration and CVV) from your post request. + +Accept.js goal is to remove the need of Card information from ever going into your server so be sure to remove that data +before posting to your server. + +The create card feature on CIM will automatically create a Customer Profile and a Payment Profile with the +'tokenized' card for each customer you request it for on your authorize.net account, you can use these Payment Profiles +later to request payments from your customers. + +In order to create a Customer & Payment Profile pass the opaque fields and the card array with the billing information +to the createCard method on the CIM driver: + +```php +// $gateway is an instantiation of the CIM driver. //Omnipay::create( 'AuthorizeNet_CIM' ) +// $dataDescriptor and $dataValue come from the payment form at the front end. + +$request = $gateway->createCard( + [ + 'opaqueDataDescriptor' => $dataDescriptor, + 'opaqueDataValue' => $dataValue, + 'name' => $name, + 'email' => $email, //Authorize.net will use the email to identify the CustomerProfile + 'customerType' => 'individual', + 'customerId' => $user_customer_id,//a customer ID generated by your system or send null + 'description' => 'MEMBER',//whichever description you wish to send + 'forceCardUpdate' => true + 'card' => [ + 'billingFirstName' => $name, + 'billingLastName' => $last_name, + 'billingAddress1' => $address, + 'billingCity' => $city, + 'billingState' => $state, + 'billingPostcode' => $zipcode, + 'billingPhone' => '', + //... may include shipping info but do not include card (number, cvv or expiration) + ], + ] +); +$response = $request->send(); +$data = $response->getData(); + +$data['paymentProfile']['customerProfileId']; +$data['paymentProfile']['customerPaymentProfileId']; +//Now you can use these 2 fields to reference this customer and this payment profile for later use with +//the rest of the CIM driver features as usual. +``` + + ## Support If you are having general issues with Omnipay, we suggest posting on From 079a991ee571139027a106879254ce5e981eb5c0 Mon Sep 17 00:00:00 2001 From: Alberto Date: Sat, 5 Jan 2019 01:11:43 -0800 Subject: [PATCH 09/11] Allow CreatePaymentProfile from opaque data --- src/Message/CIMCreateCardRequest.php | 6 ++++- .../CIMCreatePaymentProfileRequest.php | 6 +---- tests/CIMGatewayTest.php | 26 +++++++++++++++++++ tests/Message/CIMCreateCardResponseTest.php | 14 ---------- .../CIMCreatePaymentProfileRequestTest.php | 21 +++++++++++++++ 5 files changed, 53 insertions(+), 20 deletions(-) diff --git a/src/Message/CIMCreateCardRequest.php b/src/Message/CIMCreateCardRequest.php index ea0e02de..cb3ba6aa 100644 --- a/src/Message/CIMCreateCardRequest.php +++ b/src/Message/CIMCreateCardRequest.php @@ -214,8 +214,12 @@ 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; } diff --git a/src/Message/CIMCreatePaymentProfileRequest.php b/src/Message/CIMCreatePaymentProfileRequest.php index f2c4ed92..4c399146 100644 --- a/src/Message/CIMCreatePaymentProfileRequest.php +++ b/src/Message/CIMCreatePaymentProfileRequest.php @@ -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); diff --git a/tests/CIMGatewayTest.php b/tests/CIMGatewayTest.php index 1ba63b9a..5c6e1a21 100644 --- a/tests/CIMGatewayTest.php +++ b/tests/CIMGatewayTest.php @@ -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 @@ -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', diff --git a/tests/Message/CIMCreateCardResponseTest.php b/tests/Message/CIMCreateCardResponseTest.php index e2f80d89..a68942cf 100644 --- a/tests/Message/CIMCreateCardResponseTest.php +++ b/tests/Message/CIMCreateCardResponseTest.php @@ -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()); - } } diff --git a/tests/Message/CIMCreatePaymentProfileRequestTest.php b/tests/Message/CIMCreatePaymentProfileRequestTest.php index cf407618..eaad61a7 100644 --- a/tests/Message/CIMCreatePaymentProfileRequestTest.php +++ b/tests/Message/CIMCreatePaymentProfileRequestTest.php @@ -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' => "kaylee@serenity.com", + '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); + } } From 55b6f52e641c6ad5ef86d84bf50935f5543d25c0 Mon Sep 17 00:00:00 2001 From: Alberto Date: Sat, 5 Jan 2019 01:19:49 -0800 Subject: [PATCH 10/11] Fix psr2 style --- src/Message/CIMCreateCardRequest.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Message/CIMCreateCardRequest.php b/src/Message/CIMCreateCardRequest.php index cb3ba6aa..e87638a2 100644 --- a/src/Message/CIMCreateCardRequest.php +++ b/src/Message/CIMCreateCardRequest.php @@ -214,8 +214,7 @@ 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. From 66a83f18ad2b0b08615ac742ab4f8308017f1c23 Mon Sep 17 00:00:00 2001 From: Alberto Date: Sat, 5 Jan 2019 03:04:05 -0800 Subject: [PATCH 11/11] Enable CIM UpdatePaymentProfile --- src/CIMGateway.php | 5 +++++ src/Message/CIMUpdatePaymentProfileRequest.php | 4 +--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/CIMGateway.php b/src/CIMGateway.php index b515f5b2..ee824974 100644 --- a/src/CIMGateway.php +++ b/src/CIMGateway.php @@ -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); diff --git a/src/Message/CIMUpdatePaymentProfileRequest.php b/src/Message/CIMUpdatePaymentProfileRequest.php index 4677adfb..fe6e8973 100644 --- a/src/Message/CIMUpdatePaymentProfileRequest.php +++ b/src/Message/CIMUpdatePaymentProfileRequest.php @@ -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();