Skip to content

Commit 07749f7

Browse files
committed
XOL-2799 give preference to track data over customer profile
1 parent 4953d3d commit 07749f7

File tree

4 files changed

+50
-18
lines changed

4 files changed

+50
-18
lines changed

src/Message/AIMAbstractRequest.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,4 +255,10 @@ protected function addExtraOptions(\SimpleXMLElement $data)
255255
}
256256
return $data;
257257
}
258+
259+
protected function isCardPresent()
260+
{
261+
// If the credit card has track data, then consider this a "card present" scenario
262+
return ($card = $this->getCard()) && $card->getTracks();
263+
}
258264
}

src/Message/AIMAuthorizeRequest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ protected function addCustomerIP(\SimpleXMLElement $data)
5757

5858
protected function addRetail(\SimpleXMLElement $data)
5959
{
60-
if ($this->getCard()->getTracks()) {
60+
if ($this->isCardPresent()) {
6161
// Retail element is required for card present transactions
6262
$data->transactionRequest->retail->marketType = 2;
6363
$data->transactionRequest->retail->deviceType = 1;

src/Message/CIMAuthorizeRequest.php

Lines changed: 28 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,29 +11,40 @@ class CIMAuthorizeRequest extends AIMAuthorizeRequest
1111
{
1212
protected function addPayment(\SimpleXMLElement $data)
1313
{
14-
$this->validate('cardReference');
15-
16-
/** @var mixed $req */
17-
$req = $data->transactionRequest;
18-
/** @var CardReference $cardRef */
19-
$cardRef = $this->getCardReference(false);
20-
$req->profile->customerProfileId = $cardRef->getCustomerProfileId();
21-
$req->profile->paymentProfile->paymentProfileId = $cardRef->getPaymentProfileId();
22-
if ($shippingProfileId = $cardRef->getShippingProfileId()) {
23-
$req->profile->shippingProfileId = $shippingProfileId;
24-
}
14+
if ($this->isCardPresent()) {
15+
// Prefer the track data if present over the payment profile (better rate)
16+
return parent::addPayment($data);
17+
18+
} else {
19+
$this->validate('cardReference');
20+
21+
/** @var mixed $req */
22+
$req = $data->transactionRequest;
23+
/** @var CardReference $cardRef */
24+
$cardRef = $this->getCardReference(false);
25+
$req->profile->customerProfileId = $cardRef->getCustomerProfileId();
26+
$req->profile->paymentProfile->paymentProfileId = $cardRef->getPaymentProfileId();
27+
if ($shippingProfileId = $cardRef->getShippingProfileId()) {
28+
$req->profile->shippingProfileId = $shippingProfileId;
29+
}
2530

26-
$desc = $this->getDescription();
27-
if (!empty($desc)) {
28-
$req->order->description = $desc;
31+
$desc = $this->getDescription();
32+
if (!empty($desc)) {
33+
$req->order->description = $desc;
34+
}
35+
36+
return $data;
2937
}
3038

31-
return $data;
3239
}
3340

3441
protected function addBillingData(\SimpleXMLElement $data)
3542
{
36-
// Do nothing since billing information is already part of the customer profile
37-
return $data;
43+
if ($this->isCardPresent()) {
44+
return parent::addBillingData($data);
45+
} else {
46+
// Do nothing since billing information is already part of the customer profile
47+
return $data;
48+
}
3849
}
3950
}

tests/Message/CIMAuthorizeRequestTest.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,19 @@ public function testShouldReturnExtraOptionsToDisableDuplicateWindowPeriod()
3838
$data = $this->request->getData();
3939
$this->assertEquals('x_duplicate_window=0', strip_tags($data->extraOptions));
4040
}
41+
42+
public function testShouldUseTrackDataIfCardPresent()
43+
{
44+
$card = $this->getValidCard();
45+
$card['tracks'] = '%B4242424242424242^SMITH/JOHN ^2511126100000000000000444000000?;4242424242424242=25111269999944401?';
46+
$this->request->initialize(array(
47+
'card' => $card,
48+
'amount' => 21.00
49+
));
50+
51+
$data = $this->request->getData();
52+
53+
$this->assertObjectNotHasAttribute('profile', $data->transactionRequest);
54+
$this->assertObjectHasAttribute('trackData', $data->transactionRequest->payment);
55+
}
4156
}

0 commit comments

Comments
 (0)