Skip to content

Commit 482d51e

Browse files
authored
Merge pull request #312 from khaaldrogo/master
Fix incorrect regex
2 parents 89691de + 0f0dbfa commit 482d51e

4 files changed

Lines changed: 57 additions & 5 deletions

File tree

lib/AuthorizeNetAIM.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ public function addLineItem($item_id, $item_name, $item_description, $item_quant
269269
$line_item = "";
270270
$delimiter = "";
271271
foreach (func_get_args() as $key => $value) {
272-
$line_item .= $delimiter . preg_replace('/|/', '_', $value);
272+
$line_item .= $delimiter . preg_replace('/\|/', '_', $value);
273273
$delimiter = "<|>";
274274
}
275275
$this->_additional_line_items[] = $line_item;

tests/AuthorizeNetAIM_Test.php

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -780,6 +780,58 @@ public function testSetBadField()
780780
}
781781
}
782782

783+
/**
784+
* Reproduces a bug introduced in
785+
* https://github.com/AuthorizeNet/sdk-php/commit/272c21d904dcac0c8147a5bbddd68578b4dee9b1
786+
*/
787+
public function testEscapeLineItem_doesNotMangleItems()
788+
{
789+
$qty = 1;
790+
$unitPrice = 19.99;
791+
$taxable = 'N';
792+
$sale = new AuthorizeNetAIM;
793+
$sale->setSandbox(true);
794+
$sale->addLineItem(
795+
'the-item-id',
796+
'the item name',
797+
'the item description',
798+
$qty,
799+
$unitPrice,
800+
$taxable);
801+
802+
$cardNum = '4111111111111111';
803+
$sale->authorizeOnly($qty * $unitPrice, $cardNum);
804+
$postString = $sale->getPostString();
805+
806+
$this->assertContains('the-item-id', $postString);
807+
$this->assertContains('the+item+name', $postString);
808+
}
809+
810+
/**
811+
* Reproduces a bug introduced in
812+
* https://github.com/AuthorizeNet/sdk-php/commit/272c21d904dcac0c8147a5bbddd68578b4dee9b1
813+
*/
814+
public function testEscapeLineItem_escapesPipeCharacterCorrectly()
815+
{
816+
$qty = 1;
817+
$unitPrice = 19.99;
818+
$taxable = 'N';
819+
$sale = new AuthorizeNetAIM;
820+
$sale->setSandbox(true);
821+
$sale->addLineItem(
822+
'the-item-id',
823+
'the item name',
824+
'the item description has a | pipe character',
825+
$qty,
826+
$unitPrice,
827+
$taxable);
828+
829+
$cardNum = '4111111111111111';
830+
$sale->authorizeOnly($qty * $unitPrice, $cardNum);
831+
$postString = $sale->getPostString();
832+
833+
$this->assertContains('description+has+a+_+pipe', $postString);
834+
}
783835
}
784836

785837

tests/AuthorizeNetARB_Test.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,13 @@ public function testCreateSubscriptionLong()
6565
$subscription->name = "test subscription";
6666
$subscription->intervalLength = "1";
6767
$subscription->intervalUnit = "months";
68-
$subscription->startDate = "2018-03-12";
68+
$subscription->startDate = (date("Y") + 1)."-03-12";
6969
$subscription->totalOccurrences = "14";
7070
$subscription->trialOccurrences = "";
7171
$subscription->amount = "6.99";
7272
$subscription->trialAmount = "";
7373
$subscription->creditCardCardNumber = "6011000000000012";
74-
$subscription->creditCardExpirationDate = "2018-10";
74+
$subscription->creditCardExpirationDate = (date("Y") + 2)."-10";
7575
$subscription->creditCardCardCode = "123";
7676
$subscription->bankAccountAccountType = "";
7777
$subscription->bankAccountRoutingNumber = "";

tests/AuthorizeNetCIM_Test.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -353,14 +353,14 @@ public function testAll()
353353
$paymentProfile = new AuthorizeNetPaymentProfile;
354354
$paymentProfile->customerType = "individual";
355355
$paymentProfile->payment->creditCard->cardNumber = "4111111111111111";
356-
$paymentProfile->payment->creditCard->expirationDate = "2019-10";
356+
$paymentProfile->payment->creditCard->expirationDate = (date("Y") + 5) ."-10";
357357
$response = $request->createCustomerPaymentProfile($customerProfileId, $paymentProfile);
358358
$this->assertTrue($response->isOk());
359359
$paymentProfileId = $response->getPaymentProfileId();
360360

361361
// Update payment profile.
362362
$paymentProfile->payment->creditCard->cardNumber = "4111111111111111";
363-
$paymentProfile->payment->creditCard->expirationDate = "2019-11";
363+
$paymentProfile->payment->creditCard->expirationDate = (date("Y") + 7) ."-11";
364364
$response = $request->updateCustomerPaymentProfile($customerProfileId,$paymentProfileId, $paymentProfile);
365365
$this->assertTrue($response->isOk());
366366

0 commit comments

Comments
 (0)