Skip to content

Commit 8e43670

Browse files
author
srathod
committed
Added support for unmaskExpirationDate to GetCustomerPaymentProfile request.
Applied changes from #117.
1 parent 9b7011b commit 8e43670

2 files changed

Lines changed: 77 additions & 1 deletion

File tree

lib/AuthorizeNetCIM.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,14 +193,19 @@ public function getCustomerProfile($customerProfileId)
193193
*
194194
* @param int $customerProfileId
195195
* @param int $customerPaymentProfileId
196+
* @param boolean $unmaskExpirationDate
196197
*
197198
* @return AuthorizeNetCIM_Response
198199
*/
199-
public function getCustomerPaymentProfile($customerProfileId, $customerPaymentProfileId)
200+
public function getCustomerPaymentProfile($customerProfileId, $customerPaymentProfileId, $unmaskExpirationDate = false)
200201
{
201202
$this->_constructXml("getCustomerPaymentProfileRequest");
202203
$this->_xml->addChild("customerProfileId", $customerProfileId);
203204
$this->_xml->addChild("customerPaymentProfileId", $customerPaymentProfileId);
205+
if ( $unmaskExpirationDate ) {
206+
$this->_xml->addChild("unmaskExpirationDate", true);
207+
}
208+
204209
return $this->_sendRequest();
205210
}
206211

tests/AuthorizeNetCIM_Test.php

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,77 @@ public function testUpdateCustomerPaymentProfile()
189189

190190
}
191191

192+
public function testGetCustomerPaymentProfile()
193+
{
194+
$expirationDate = "2015-10";
195+
$cardNumber = "4111111111111111";
196+
$expectedCardNumber = 'XXXX' . substr($cardNumber, -4);
197+
$expectedExpiration = 'XXXX';
198+
199+
// Create new customer profile
200+
$request = new AuthorizeNetCIM;
201+
$customerProfile = new AuthorizeNetCustomer;
202+
$customerProfile->description = "Description of customer";
203+
$customerProfile->merchantCustomerId = time().rand(1,100000);
204+
$customerProfile->email = "blahlah@domain.com";
205+
$response = $request->createCustomerProfile($customerProfile);
206+
$this->assertTrue($response->isOk());
207+
$customerProfileId = $response->getCustomerProfileId();
208+
209+
// Add payment profile.
210+
$paymentProfile = new AuthorizeNetPaymentProfile;
211+
$paymentProfile->customerType = "individual";
212+
$paymentProfile->payment->creditCard->cardNumber = $cardNumber;
213+
$paymentProfile->payment->creditCard->expirationDate = $expirationDate;
214+
$response = $request->createCustomerPaymentProfile($customerProfileId, $paymentProfile);
215+
$this->assertTrue($response->isOk());
216+
$paymentProfileId = $response->getPaymentProfileId();
217+
218+
$request = new AuthorizeNetCIM;
219+
$response = $request->getCustomerPaymentProfile($customerProfileId, $paymentProfileId);
220+
if ($response->isOk()) {
221+
$recdCardNumber = (string)$response->xml->paymentProfile->payment->creditCard->cardNumber;
222+
$recdExpiration = (string)$response->xml->paymentProfile->payment->creditCard->expirationDate;
223+
$this->assertEquals($expectedCardNumber, $recdCardNumber);
224+
$this->assertEquals($expectedExpiration, $recdExpiration);
225+
}
226+
}
227+
228+
public function testGetCustomerPaymentProfileWithUnmaskedExpiration()
229+
{
230+
$expirationDate = "2015-10";
231+
$cardNumber = "4111111111111111";
232+
$expectedCardNumber = 'XXXX' . substr($cardNumber, -4);
233+
234+
// Create new customer profile
235+
$request = new AuthorizeNetCIM;
236+
$customerProfile = new AuthorizeNetCustomer;
237+
$customerProfile->description = "Description of customer";
238+
$customerProfile->merchantCustomerId = time().rand(1,100000);
239+
$customerProfile->email = "blahlah@domain.com";
240+
$response = $request->createCustomerProfile($customerProfile);
241+
$this->assertTrue($response->isOk());
242+
$customerProfileId = $response->getCustomerProfileId();
243+
244+
// Add payment profile.
245+
$paymentProfile = new AuthorizeNetPaymentProfile;
246+
$paymentProfile->customerType = "individual";
247+
$paymentProfile->payment->creditCard->cardNumber = $cardNumber;
248+
$paymentProfile->payment->creditCard->expirationDate = $expirationDate;
249+
$response = $request->createCustomerPaymentProfile($customerProfileId, $paymentProfile, true);
250+
$this->assertTrue($response->isOk());
251+
$paymentProfileId = $response->getPaymentProfileId();
252+
253+
$request = new AuthorizeNetCIM;
254+
$response = $request->getCustomerPaymentProfile($customerProfileId, $paymentProfileId, true);
255+
if ($response->isOk()) {
256+
$recdCardNumber = (string)$response->xml->paymentProfile->payment->creditCard->cardNumber;
257+
$recdExpiration = (string)$response->xml->paymentProfile->payment->creditCard->expirationDate;
258+
$this->assertEquals($expectedCardNumber, $recdCardNumber);
259+
$this->assertEquals($expirationDate, $recdExpiration);
260+
}
261+
}
262+
192263
public function testCreateCustomerProfileWithValidationMode()
193264
{
194265
$this->markTestSkipped('Ignoring for Travis. Will fix after release.'); //TODO

0 commit comments

Comments
 (0)