Skip to content

Commit 1c7ac31

Browse files
committed
Let request classes specify METHOD and PAYMENTACTION directly
1 parent e0dc791 commit 1c7ac31

12 files changed

+247
-22
lines changed

src/Message/AbstractRequest.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,10 +122,9 @@ public function setAddressOverride($value)
122122
return $this->setParameter('addressOverride', $value);
123123
}
124124

125-
protected function getBaseData($method)
125+
protected function getBaseData()
126126
{
127127
$data = array();
128-
$data['METHOD'] = $method;
129128
$data['VERSION'] = static::API_VERSION;
130129
$data['USER'] = $this->getUsername();
131130
$data['PWD'] = $this->getPassword();

src/Message/CaptureRequest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ class CaptureRequest extends AbstractRequest
99
{
1010
public function getData()
1111
{
12-
$data = $this->getBaseData('DoCapture');
13-
1412
$this->validate('transactionReference', 'amount');
1513

14+
$data = $this->getBaseData();
15+
$data['METHOD'] = 'DoCapture';
1616
$data['AMT'] = $this->getAmount();
1717
$data['CURRENCYCODE'] = $this->getCurrency();
1818
$data['AUTHORIZATIONID'] = $this->getTransactionReference();

src/Message/ExpressAuthorizeRequest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ class ExpressAuthorizeRequest extends AbstractRequest
99
{
1010
public function getData()
1111
{
12-
$data = $this->getBaseData('SetExpressCheckout');
13-
1412
$this->validate('amount', 'returnUrl', 'cancelUrl');
1513

14+
$data = $this->getBaseData();
15+
$data['METHOD'] = 'SetExpressCheckout';
1616
$data['PAYMENTREQUEST_0_PAYMENTACTION'] = 'Authorization';
1717
$data['PAYMENTREQUEST_0_AMT'] = $this->getAmount();
1818
$data['PAYMENTREQUEST_0_CURRENCYCODE'] = $this->getCurrency();

src/Message/ExpressCompleteAuthorizeRequest.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,13 @@
77
*/
88
class ExpressCompleteAuthorizeRequest extends AbstractRequest
99
{
10-
protected $action = 'Authorization';
11-
1210
public function getData()
1311
{
14-
$data = $this->getBaseData('DoExpressCheckoutPayment');
15-
1612
$this->validate('amount');
1713

18-
$data['PAYMENTREQUEST_0_PAYMENTACTION'] = $this->action;
14+
$data = $this->getBaseData();
15+
$data['METHOD'] = 'DoExpressCheckoutPayment';
16+
$data['PAYMENTREQUEST_0_PAYMENTACTION'] = 'Authorization';
1917
$data['PAYMENTREQUEST_0_AMT'] = $this->getAmount();
2018
$data['PAYMENTREQUEST_0_CURRENCYCODE'] = $this->getCurrency();
2119
$data['PAYMENTREQUEST_0_INVNUM'] = $this->getTransactionId();

src/Message/ExpressCompletePurchaseRequest.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,11 @@
77
*/
88
class ExpressCompletePurchaseRequest extends ExpressCompleteAuthorizeRequest
99
{
10-
protected $action = 'Sale';
10+
public function getData()
11+
{
12+
$data = parent::getData();
13+
$data['PAYMENTREQUEST_0_PAYMENTACTION'] = 'Sale';
14+
15+
return $data;
16+
}
1117
}

src/Message/FetchTransactionRequest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ class FetchTransactionRequest extends AbstractRequest
99
{
1010
public function getData()
1111
{
12-
$data = $this->getBaseData('GetTransactionDetails');
13-
1412
$this->validate('transactionReference');
1513

14+
$data = $this->getBaseData();
15+
$data['METHOD'] = 'GetTransactionDetails';
1616
$data['TRANSACTIONID'] = $this->getTransactionReference();
1717

1818
return $data;

src/Message/ProAuthorizeRequest.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,14 @@
77
*/
88
class ProAuthorizeRequest extends AbstractRequest
99
{
10-
protected $action = 'Authorization';
11-
1210
public function getData()
1311
{
14-
$data = $this->getBaseData('DoDirectPayment');
15-
1612
$this->validate('amount', 'card');
1713
$this->getCard()->validate();
1814

19-
$data['PAYMENTACTION'] = $this->action;
15+
$data = $this->getBaseData();
16+
$data['METHOD'] = 'DoDirectPayment';
17+
$data['PAYMENTACTION'] = 'Authorization';
2018
$data['AMT'] = $this->getAmount();
2119
$data['CURRENCYCODE'] = $this->getCurrency();
2220
$data['INVNUM'] = $this->getTransactionId();

src/Message/ProPurchaseRequest.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,11 @@
77
*/
88
class ProPurchaseRequest extends ProAuthorizeRequest
99
{
10-
protected $action = 'Sale';
10+
public function getData()
11+
{
12+
$data = parent::getData();
13+
$data['PAYMENTACTION'] = 'Sale';
14+
15+
return $data;
16+
}
1117
}

src/Message/RefundRequest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ class RefundRequest extends AbstractRequest
99
{
1010
public function getData()
1111
{
12-
$data = $this->getBaseData('RefundTransaction');
13-
1412
$this->validate('transactionReference');
1513

14+
$data = $this->getBaseData();
15+
$data['METHOD'] = 'RefundTransaction';
1616
$data['TRANSACTIONID'] = $this->getTransactionReference();
1717
$data['REFUNDTYPE'] = 'Full';
1818
if ($this->getAmount() > 0) {
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
<?php
2+
3+
namespace Omnipay\PayPal\Message;
4+
5+
use Omnipay\PayPal\Message\ExpressCompletePurchaseRequest;
6+
use Omnipay\Tests\TestCase;
7+
8+
class ExpressCompletePurchaseRequestTest extends TestCase
9+
{
10+
/**
11+
* @var \Omnipay\PayPal\Message\ExpressCompletePurchaseRequest
12+
*/
13+
private $request;
14+
15+
public function setUp()
16+
{
17+
$client = $this->getHttpClient();
18+
19+
$request = $this->getHttpRequest();
20+
$request->query->set('PayerID', 'Payer-1234');
21+
$request->query->set('token', 'TOKEN1234');
22+
23+
$this->request = new ExpressCompletePurchaseRequest($client, $request);
24+
}
25+
26+
public function testGetData()
27+
{
28+
$this->request->setAmount('1.23');
29+
$this->request->setCurrency('USD');
30+
$this->request->setTransactionId('ABC-123');
31+
$this->request->setUsername('testuser');
32+
$this->request->setPassword('testpass');
33+
$this->request->setSignature('SIG');
34+
$this->request->setSubject('SUB');
35+
$this->request->setDescription('DESC');
36+
$this->request->setNotifyUrl('https://www.example.com/notify');
37+
38+
$expected = array();
39+
$expected['METHOD'] = 'DoExpressCheckoutPayment';
40+
$expected['PAYMENTREQUEST_0_PAYMENTACTION'] = 'Sale';
41+
$expected['PAYMENTREQUEST_0_AMT'] = '1.23';
42+
$expected['PAYMENTREQUEST_0_CURRENCYCODE'] = 'USD';
43+
$expected['PAYMENTREQUEST_0_INVNUM'] = 'ABC-123';
44+
$expected['PAYMENTREQUEST_0_DESC'] = 'DESC';
45+
$expected['PAYMENTREQUEST_0_NOTIFYURL'] = 'https://www.example.com/notify';
46+
$expected['USER'] = 'testuser';
47+
$expected['PWD'] = 'testpass';
48+
$expected['SIGNATURE'] = 'SIG';
49+
$expected['SUBJECT'] = 'SUB';
50+
$expected['VERSION'] = ExpressCompletePurchaseRequest::API_VERSION;
51+
$expected['TOKEN'] = 'TOKEN1234';
52+
$expected['PAYERID'] = 'Payer-1234';
53+
54+
$this->assertEquals($expected, $this->request->getData());
55+
}
56+
57+
public function testGetDataWithItems()
58+
{
59+
$this->request->setAmount('50.00');
60+
$this->request->setCurrency('USD');
61+
$this->request->setTransactionId('ABC-123');
62+
$this->request->setUsername('testuser');
63+
$this->request->setPassword('testpass');
64+
$this->request->setSignature('SIG');
65+
$this->request->setSubject('SUB');
66+
$this->request->setDescription('DESC');
67+
68+
$this->request->setItems(array(
69+
array('name' => 'Floppy Disk', 'description' => 'MS-DOS', 'quantity' => 2, 'price' => 10),
70+
array('name' => 'CD-ROM', 'description' => 'Windows 95', 'quantity' => 1, 'price' => 40),
71+
));
72+
73+
$data = $this->request->getData();
74+
$this->assertSame('Floppy Disk', $data['L_PAYMENTREQUEST_0_NAME0']);
75+
$this->assertSame('MS-DOS', $data['L_PAYMENTREQUEST_0_DESC0']);
76+
$this->assertSame(2, $data['L_PAYMENTREQUEST_0_QTY0']);
77+
$this->assertSame('10.00', $data['L_PAYMENTREQUEST_0_AMT0']);
78+
79+
$this->assertSame('CD-ROM', $data['L_PAYMENTREQUEST_0_NAME1']);
80+
$this->assertSame('Windows 95', $data['L_PAYMENTREQUEST_0_DESC1']);
81+
$this->assertSame(1, $data['L_PAYMENTREQUEST_0_QTY1']);
82+
$this->assertSame('40.00', $data['L_PAYMENTREQUEST_0_AMT1']);
83+
}
84+
}

0 commit comments

Comments
 (0)