|
| 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