Skip to content

Commit 5ff842e

Browse files
committed
Add PayPal Express line items
1 parent f25a32c commit 5ff842e

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

src/Omnipay/PayPal/Message/ExpressAuthorizeRequest.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,15 @@ public function getData()
5050
$data['EMAIL'] = $card->getEmail();
5151
}
5252

53+
$items = $this->getItems();
54+
if ($items) {
55+
foreach ($items as $n => $item) {
56+
$data["PAYMENTREQUEST_0_NAME$n"] = $item->getName();
57+
$data["PAYMENTREQUEST_0_QTY$n"] = $item->getQuantity();
58+
$data["PAYMENTREQUEST_0_AMT$n"] = $item->getPrice();
59+
}
60+
}
61+
5362
return $data;
5463
}
5564

tests/Omnipay/PayPal/Message/ExpressAuthorizeRequestTest.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,23 @@ public function testGetDataWithCard()
120120
$this->assertEquals($expected, $this->request->getData());
121121
}
122122

123+
public function testGetDataWithItems()
124+
{
125+
$this->request->setItems(array(
126+
array('name' => 'Floppy Disk', 'quantity' => 2, 'price' => '10.00'),
127+
array('name' => 'CD-ROM', 'quantity' => 1, 'price' => '40.00'),
128+
));
129+
130+
$data = $this->request->getData();
131+
$this->assertSame('Floppy Disk', $data['PAYMENTREQUEST_0_NAME0']);
132+
$this->assertSame(2, $data['PAYMENTREQUEST_0_QTY0']);
133+
$this->assertSame('10.00', $data['PAYMENTREQUEST_0_AMT0']);
134+
135+
$this->assertSame('CD-ROM', $data['PAYMENTREQUEST_0_NAME1']);
136+
$this->assertSame(1, $data['PAYMENTREQUEST_0_QTY1']);
137+
$this->assertSame('40.00', $data['PAYMENTREQUEST_0_AMT1']);
138+
}
139+
123140
public function testHeaderImageUrl()
124141
{
125142
$this->assertSame($this->request, $this->request->setHeaderImageUrl('https://www.example.com/header.jpg'));

0 commit comments

Comments
 (0)