Skip to content

Commit e65fbbb

Browse files
committed
Merge branch 'fix-pipe-escape' of https://github.com/ianfp/sdk-php
2 parents e82f8a8 + 113c77a commit e65fbbb

2 files changed

Lines changed: 53 additions & 1 deletion

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

0 commit comments

Comments
 (0)