Skip to content

Commit c08f766

Browse files
committed
Remove hardcoded values in ExpressAuthorizeRequest (Fixes thephpleague#121)
1 parent 3aef8e5 commit c08f766

File tree

3 files changed

+42
-5
lines changed

3 files changed

+42
-5
lines changed

src/Omnipay/PayPal/Message/AbstractRequest.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,26 @@ public function setHeaderImageUrl($value)
9191
return $this->setParameter('headerImageUrl', $value);
9292
}
9393

94+
public function getNoShipping()
95+
{
96+
return $this->getParameter('noShipping');
97+
}
98+
99+
public function setNoShipping($value)
100+
{
101+
return $this->setParameter('noShipping', $value);
102+
}
103+
104+
public function getAllowNote()
105+
{
106+
return $this->getParameter('allowNote');
107+
}
108+
109+
public function setAllowNote($value)
110+
{
111+
return $this->setParameter('allowNote', $value);
112+
}
113+
94114
protected function getBaseData($method)
95115
{
96116
$data = array();

src/Omnipay/PayPal/Message/ExpressAuthorizeRequest.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,21 @@ public function getData()
3232
// pp express specific fields
3333
$data['SOLUTIONTYPE'] = $this->getSolutionType();
3434
$data['LANDINGPAGE'] = $this->getLandingPage();
35-
$data['NOSHIPPING'] = 1;
36-
$data['ALLOWNOTE'] = 0;
3735
$data['RETURNURL'] = $this->getReturnUrl();
3836
$data['CANCELURL'] = $this->getCancelUrl();
3937

4038
if ($headerImageUrl = $this->getHeaderImageUrl()) {
4139
$data['HDRIMG'] = $headerImageUrl;
4240
}
4341

42+
if (null !== ($noShipping = $this->getNoShipping())) {
43+
$data['NOSHIPPING'] = $noShipping;
44+
}
45+
46+
if (null !== ($allowNote = $this->getAllowNote())) {
47+
$data['ALLOWNOTE'] = $allowNote;
48+
}
49+
4450
if ($card = $this->getCard()) {
4551
$data['PAYMENTREQUEST_0_SHIPTONAME'] = $card->getName();
4652
$data['PAYMENTREQUEST_0_SHIPTOSTREET'] = $card->getAddress1();

tests/Omnipay/PayPal/Message/ExpressAuthorizeRequestTest.php

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@
1616

1717
class ExpressAuthorizeRequestTest extends TestCase
1818
{
19+
/**
20+
* @var ExpressAuthorizeRequest
21+
*/
22+
private $request;
23+
1924
public function setUp()
2025
{
2126
parent::setUp();
@@ -42,6 +47,8 @@ public function testGetDataWithoutCard()
4247
'notifyUrl' => 'https://www.example.com/notify',
4348
'subject' => 'demo@example.com',
4449
'headerImageUrl' => 'https://www.example.com/header.jpg',
50+
'noShipping' => 0,
51+
'allowNote' => 0,
4552
));
4653

4754
$data = $this->request->getData();
@@ -55,9 +62,11 @@ public function testGetDataWithoutCard()
5562
$this->assertSame('https://www.example.com/notify', $data['PAYMENTREQUEST_0_NOTIFYURL']);
5663
$this->assertSame('demo@example.com', $data['SUBJECT']);
5764
$this->assertSame('https://www.example.com/header.jpg', $data['HDRIMG']);
65+
$this->assertSame(0, $data['NOSHIPPING']);
66+
$this->assertSame(0, $data['ALLOWNOTE']);
5867
}
5968

60-
public function testGetDataWitCard()
69+
public function testGetDataWithCard()
6170
{
6271
$this->request->initialize(array(
6372
'amount' => '10.00',
@@ -69,6 +78,8 @@ public function testGetDataWitCard()
6978
'notifyUrl' => 'https://www.example.com/notify',
7079
'subject' => 'demo@example.com',
7180
'headerImageUrl' => 'https://www.example.com/header.jpg',
81+
'noShipping' => 2,
82+
'allowNote' => 1,
7283
));
7384

7485
$card = new CreditCard(array(
@@ -93,8 +104,8 @@ public function testGetDataWitCard()
93104
'PAYMENTREQUEST_0_PAYMENTACTION' => 'Authorization',
94105
'SOLUTIONTYPE' => null,
95106
'LANDINGPAGE' => null,
96-
'NOSHIPPING' => 1,
97-
'ALLOWNOTE' => 0,
107+
'NOSHIPPING' => 2,
108+
'ALLOWNOTE' => 1,
98109
'PAYMENTREQUEST_0_AMT' => '10.00',
99110
'PAYMENTREQUEST_0_CURRENCYCODE' => 'AUD',
100111
'PAYMENTREQUEST_0_INVNUM' => '111',

0 commit comments

Comments
 (0)