Completed
Push — master ( 085f89...a587cf )
by Aimeos
11:11
created

PayPalExpressTest::testUpdateSync()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 21
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 12
nc 1
nop 0
dl 0
loc 21
rs 9.3142
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * @license LGPLv3, http://opensource.org/licenses/LGPL-3.0
5
 * @copyright Metaways Infosystems GmbH, 2012
6
 * @copyright Aimeos (aimeos.org), 2015-2017
7
 */
8
9
10
namespace Aimeos\MShop\Service\Provider\Payment;
11
12
13
class PayPalExpressTest extends \PHPUnit\Framework\TestCase
14
{
15
	private $context;
16
	private $object;
17
	private $serviceItem;
18
	private $orderMock;
19
	private $order;
20
21
22
	protected function setUp()
23
	{
24
		$this->context = \TestHelperMShop::getContext();
25
		$serviceManager = \Aimeos\MShop\Service\Manager\Factory::createManager( $this->context );
26
27
		$search = $serviceManager->createSearch();
28
		$search->setConditions( $search->compare( '==', 'service.code', 'paypalexpress' ) );
29
30
		$serviceItems = $serviceManager->searchItems( $search );
31
32
		if( ( $this->serviceItem = reset( $serviceItems ) ) === false ) {
33
			throw new \RuntimeException( 'No paypalexpress service item available' );
34
		}
35
36
		$this->object = new \Aimeos\MShop\Service\Provider\Payment\PayPalExpress( $this->context, $this->serviceItem );
37
38
39
		$orderManager = \Aimeos\MShop\Order\Manager\Factory::createManager( $this->context );
40
41
		$search = $orderManager->createSearch();
42
		$expr = array(
43
			$search->compare( '==', 'order.type', \Aimeos\MShop\Order\Item\Base::TYPE_WEB ),
44
			$search->compare( '==', 'order.statuspayment', \Aimeos\MShop\Order\Item\Base::PAY_AUTHORIZED )
45
		);
46
		$search->setConditions( $search->combine( '&&', $expr ) );
47
		$orderItems = $orderManager->searchItems( $search );
48
49
		if( ( $this->order = reset( $orderItems ) ) === false ) {
50
			throw new \RuntimeException( sprintf( 'No Order found with statuspayment "%1$s" and type "%2$s"', \Aimeos\MShop\Order\Item\Base::PAY_AUTHORIZED, \Aimeos\MShop\Order\Item\Base::TYPE_WEB ) );
51
		}
52
53
54
		$this->orderMock = $this->getMockBuilder( '\\Aimeos\\MShop\\Order\\Manager\\Standard' )
55
			->setConstructorArgs( array( $this->context ) )
56
			->setMethods( array( 'saveItem' ) )
57
			->getMock();
58
59
		$this->context->getConfig()->set( 'mshop/order/manager/name', 'MockPayPal' );
60
		\Aimeos\MShop\Order\Manager\Factory::injectManager( '\\Aimeos\\MShop\\Order\\Manager\\MockPayPal', $this->orderMock );
61
	}
62
63
64
	protected function tearDown()
65
	{
66
		unset( $this->object );
67
		unset( $this->serviceItem );
68
		unset( $this->order );
69
	}
70
71
72
	public function testGetConfigBE()
73
	{
74
		$result = $this->object->getConfigBE();
75
76
		$this->assertEquals( 12, count( $result ) );
77
78
		foreach( $result as $key => $item ) {
79
			$this->assertInstanceOf( 'Aimeos\MW\Criteria\Attribute\Iface', $item );
80
		}
81
	}
82
83
84
	public function testCheckConfigBE()
85
	{
86
		$attributes = array(
87
			'paypalexpress.ApiUsername' => 'user',
88
			'paypalexpress.AccountEmail' => '[email protected]',
89
			'paypalexpress.ApiPassword' => 'pw',
90
			'paypalexpress.ApiSignature' => '1df23eh67',
91
			'payment.url-cancel' => 'http://cancelUrl',
92
			'payment.url-success' => 'http://returnUrl'
93
		);
94
95
		$result = $this->object->checkConfigBE( $attributes );
96
97
		$this->assertEquals( 12, count( $result ) );
98
		$this->assertEquals( null, $result['paypalexpress.ApiUsername'] );
99
		$this->assertEquals( null, $result['paypalexpress.AccountEmail'] );
100
		$this->assertEquals( null, $result['paypalexpress.ApiPassword'] );
101
		$this->assertEquals( null, $result['paypalexpress.ApiSignature'] );
102
	}
103
104
	public function testIsImplemented()
105
	{
106
		$this->assertTrue( $this->object->isImplemented( \Aimeos\MShop\Service\Provider\Payment\Base::FEAT_CANCEL ) );
107
		$this->assertTrue( $this->object->isImplemented( \Aimeos\MShop\Service\Provider\Payment\Base::FEAT_CAPTURE ) );
108
		$this->assertTrue( $this->object->isImplemented( \Aimeos\MShop\Service\Provider\Payment\Base::FEAT_QUERY ) );
109
		$this->assertTrue( $this->object->isImplemented( \Aimeos\MShop\Service\Provider\Payment\Base::FEAT_REFUND ) );
110
111
		$this->assertFalse( $this->object->isImplemented( -1 ) );
112
	}
113
114
115
	public function testProcess()
116
	{
117
		$what = array( 'PAYMENTREQUEST_0_AMT' => 18.50 );
118
		$error = '&ACK=Error&VERSION=87.0&BUILD=3136725&CORRELATIONID=1234567890&L_ERRORCODE0=0000&L_SHORTMESSAGE0=process method error';
119
		$success = '&ACK=Success&VERSION=87.0&BUILD=3136725&CORRELATIONID=1234567890&TOKEN=UT-99999999';
120
121
		$com = new TestPayPalExpress();
122
		$com->addRule( $what, $error, $success );
123
		$this->object->setCommunication( $com );
124
125
		$helperForm = $this->object->process( $this->order );
126
127
		$orderManager = \Aimeos\MShop\Order\Manager\Factory::createManager( $this->context );
128
		$orderBaseManager = $orderManager->getSubManager( 'base' );
129
130
		$refOrderBase = $orderBaseManager->load( $this->order->getBaseId() );
131
132
		$attributes = $refOrderBase->getService( 'payment', 'paypalexpress' )->getAttributes();
133
134
		$attributeList = [];
135
		foreach( $attributes as $attribute ) {
136
			$attributeList[$attribute->getCode()] = $attribute;
137
		}
138
139
		$this->assertInstanceOf( '\\Aimeos\\MShop\\Common\\Item\\Helper\\Form\\Iface', $helperForm );
140
		$this->assertEquals( 'https://www.sandbox.paypal.com/webscr&cmd=_express-checkout&useraction=commit&token=UT-99999999', $helperForm->getUrl() );
141
		$this->assertEquals( 'POST', $helperForm->getMethod() );
142
		$this->assertEquals( [], $helperForm->getValues() );
143
144
		$testData = array(
145
			'TOKEN' => 'UT-99999999'
146
		);
147
148
		foreach( $testData as $key => $value ) {
149
			$this->assertEquals( $attributeList[$key]->getValue(), $testData[$key] );
150
		}
151
	}
152
153
154
	public function testUpdateSync()
155
	{
156
		//DoExpressCheckout
157
158
		$what = array( 'TOKEN' => 'UT-99999999' );
159
160
		$error = '&ACK=Error&VERSION=87.0&BUILD=3136725&CORRELATIONID=1234567890&L_ERRORCODE0=0000&L_SHORTMESSAGE0=updatesync method error';
161
		$success = '&TOKEN=UT-99999999&CORRELATIONID=1234567890&ACK=Success&VERSION=87.0&BUILD=3136725&PAYERID=PaypalUnitTestBuyer&TRANSACTIONID=111111110&PAYMENTSTATUS=Pending&PENDINGREASON=authorization&INVNUM=' . $this->order->getId();
162
163
		$com = new TestPayPalExpress();
164
		$com->addRule( $what, $error, $success );
165
		$this->object->setCommunication( $com );
166
167
		$params = array(
168
			'token' => 'UT-99999999',
169
			'PayerID' => 'PaypalUnitTestBuyer',
170
			'orderid' => $this->order->getId()
171
		);
172
173
		$this->assertInstanceOf( '\\Aimeos\\MShop\\Order\\Item\\Iface', $this->object->updateSync( $params ) );
174
	}
175
176
177
	public function testUpdatePush()
178
	{
179
		//IPN Call
180
		$orderManager = \Aimeos\MShop\Order\Manager\Factory::createManager( $this->context );
181
		$orderBaseManager = $orderManager->getSubManager( 'base' );
182
183
		$price = $orderBaseManager->getItem( $this->order->getBaseId() )->getPrice();
184
		$amount = $price->getValue() + $price->getCosts();
185
		$what = array(
186
			'residence_country' => 'US',
187
			'address_city' => 'San+Jose',
188
			'first_name' => 'John',
189
			'payment_status' => 'Completed',
190
			'invoice' => $this->order->getId(),
191
			'txn_id' => '111111111',
192
			'payment_amount' => $amount,
193
			'receiver_email' => '[email protected]',
194
		);
195
		$error = 'INVALID';
196
		$success = 'VERIFIED';
197
198
		$com = new TestPayPalExpress();
199
		$com->addRule( $what, $error, $success );
200
		$this->object->setCommunication( $com );
201
202
203
		$params = array(
204
			'residence_country' => 'US',
205
			'receiver_email' => '[email protected]',
206
			'address_city' => 'San+Jose',
207
			'first_name' => 'John',
208
			'payment_status' => 'Completed',
209
			'invoice' => $this->order->getId(),
210
			'txn_id' => '111111111',
211
			'payment_amount' => $amount
212
		);
213
		$testData = array(
214
			'TRANSACTIONID' => '111111111',
215
			'PAYERID' => 'PaypalUnitTestBuyer',
216
			'111111110' => 'Pending',
217
			'111111111' => 'Completed'
218
		);
219
220
		$request = $this->getMockBuilder( '\Psr\Http\Message\ServerRequestInterface' )->getMock();
221
		$response = $this->getMockBuilder( '\Psr\Http\Message\ResponseInterface' )->getMock();
222
223
		$request->expects( $this->once() )->method( 'getQueryParams' )->will( $this->returnValue( $params ) );
224
		$response->expects( $this->once() )->method( 'withStatus' )
225
			->will( $this->returnValue( $response ) )
226
			->with( $this->equalTo( 200 ) );
227
228
		$this->orderMock->expects( $this->once() )->method( 'saveItem' )
229
			->with( $this->callback( function( $subject ) {
230
				return $subject->getPaymentStatus() === \Aimeos\MShop\Order\Item\Base::PAY_RECEIVED;
231
			} )
232
		);
233
234
		$result = $this->object->updatePush( $request, $response );
235
		$this->assertInstanceOf( '\Psr\Http\Message\ResponseInterface', $result );
236
237
		$refOrderBase = $orderBaseManager->load( $this->order->getBaseId(), \Aimeos\MShop\Order\Item\Base\Base::PARTS_SERVICE );
238
		$attributes = $refOrderBase->getService( 'payment', 'paypalexpress' )->getAttributes();
239
		$attrManager = $orderBaseManager->getSubManager( 'service' )->getSubManager( 'attribute' );
240
241
		$attributeList = [];
242
		foreach( $attributes as $attribute ) {
243
			//remove attr where txn ids as keys, because next test with same txn id would fail
244
			if( $attribute->getCode() === '111111110' || $attribute->getCode() === '111111111' ) {
245
				$attrManager->deleteItem( $attribute->getId() );
246
			}
247
248
			$attributeList[$attribute->getCode()] = $attribute;
249
		}
250
251
		foreach( $testData as $key => $value ) {
252
			$this->assertEquals( $attributeList[$key]->getValue(), $testData[$key] );
253
		}
254
	}
255
256
257
	public function testRefund()
258
	{
259
		$what = array(
260
			'METHOD' => 'RefundTransaction',
261
			'REFUNDSOURCE' => 'instant',
262
			'REFUNDTYPE' => 'Full',
263
			'TRANSACTIONID' => '111111111',
264
			'INVOICEID' => $this->order->getId()
265
		);
266
		$error = '&ACK=Error&VERSION=87.0&BUILD=3136725&CORRELATIONID=1234567890&L_ERRORCODE0=0000&L_SHORTMESSAGE0=refund method error';
267
		$success = 'REFUNDTRANSACTIONID=88888888&FEEREFUNDAMT=2.00&TOTALREFUNDAMT=24.00&CURRENCYCODE=EUR&REFUNDSTATUS=delayed&PENDINGREASON=echeck&CORRELATIONID=1234567890&ACK=Success&VERSION=87.0&BUILD=3136725';
268
269
		$com = new TestPayPalExpress();
270
		$com->addRule( $what, $error, $success );
271
		$this->object->setCommunication( $com );
272
273
		$this->object->refund( $this->order );
274
275
		$testData = array(
276
			'TOKEN' => 'UT-99999999',
277
			'TRANSACTIONID' => '111111111',
278
			'REFUNDTRANSACTIONID' => '88888888'
279
		);
280
281
		$orderManager = \Aimeos\MShop\Order\Manager\Factory::createManager( $this->context );
282
		$orderBaseManager = $orderManager->getSubManager( 'base' );
283
284
		$refOrderBase = $orderBaseManager->load( $this->order->getBaseId() );
285
		$attributes = $refOrderBase->getService( 'payment', 'paypalexpress' )->getAttributes();
286
287
		$attributeList = [];
288
		foreach( $attributes as $attribute ) {
289
			$attributeList[$attribute->getCode()] = $attribute;
290
		}
291
292
		foreach( $testData as $key => $value ) {
293
			$this->assertEquals( $attributeList[$key]->getValue(), $testData[$key] );
294
		}
295
296
		$this->assertEquals( \Aimeos\MShop\Order\Item\Base::PAY_REFUND, $this->order->getPaymentStatus() );
297
	}
298
299
300
	public function testCapture()
301
	{
302
		$orderManager = \Aimeos\MShop\Order\Manager\Factory::createManager( $this->context );
303
		$orderBaseManager = $orderManager->getSubManager( 'base' );
304
		$baseItem = $orderBaseManager->getItem( $this->order->getBaseId() );
305
306
		$what = array(
307
			'METHOD' => 'DoCapture',
308
			'COMPLETETYPE' => 'Complete',
309
			'AUTHORIZATIONID' => '111111111',
310
			'INVNUM' => $this->order->getId(),
311
			'CURRENCYCODE' => $baseItem->getPrice()->getCurrencyId(),
312
			'AMT' => ( $baseItem->getPrice()->getValue() + $baseItem->getPrice()->getCosts() )
313
		);
314
		$error = '&ACK=Error&VERSION=87.0&BUILD=3136725&CORRELATIONID=1234567890&L_ERRORCODE0=0000&L_SHORTMESSAGE0=capture method error';
315
		$success = 'AUTHORIZATIONID=112233&TRANSACTIONID=111111111&PARENTTRANSACTIONID=12212AD&TRANSACTIONTYPE=express-checkout&AMT=22.30&FEEAMT=3.33&PAYMENTSTATUS=Completed&PENDINGREASON=None&CORRELATIONID=1234567890&ACK=Success&VERSION=87.0&BUILD=3136725';
316
317
		$com = new TestPayPalExpress();
318
		$com->addRule( $what, $error, $success );
319
		$this->object->setCommunication( $com );
320
321
		$this->object->capture( $this->order );
322
323
		$this->assertEquals( \Aimeos\MShop\Order\Item\Base::PAY_RECEIVED, $this->order->getPaymentStatus() );
324
	}
325
326
	public function testQueryPaymentReceived()
327
	{
328
		$what = array(
329
			'METHOD' => 'GetTransactionDetails',
330
			'TRANSACTIONID' => '111111111'
331
		);
332
		$error = '&ACK=Error&VERSION=87.0&BUILD=3136725&CORRELATIONID=1234567890&L_ERRORCODE0=0000&L_SHORTMESSAGE0=query payment received test method error';
333
		$success = 'SHIPPINGCALCULATIONMODE=Callback&INSURANCEOPTIONSELECTED=false&RECEIVERID=unit_1340199666_biz_api1.yahoo.de&PAYERID=unittest&PAYERSTATUS=verified&COUNTRYCODE=DE&FIRSTNAME=Unit&LASTNAME=Test&SHIPTOSTREET=Unitteststr. 11&TRANSACTIONID=111111111&PARENTTRANSACTIONID=111111111&TRANSACTIONTYPE=express-checkout&AMT=22.50CURRENCYCODE=EUR&FEEAMT=4.44&PAYMENTSTATUS=Completed&PENDINGREASON=None&INVNUM=34&CORRELATIONID=1f4b8e2c86ead&ACK=Success&VERSION=87.0&BUILD=3136725';
334
335
		$com = new TestPayPalExpress();
336
		$com->addRule( $what, $error, $success );
337
		$this->object->setCommunication( $com );
338
339
		$this->object->query( $this->order );
340
341
		$this->assertEquals( \Aimeos\MShop\Order\Item\Base::PAY_RECEIVED, $this->order->getPaymentStatus() );
342
	}
343
344
345
	public function testQueryPaymentRefused()
346
	{
347
		$what = array(
348
			'METHOD' => 'GetTransactionDetails',
349
			'TRANSACTIONID' => '111111111',
350
		);
351
		$error = '&ACK=Error&VERSION=87.0&BUILD=3136725&CORRELATIONID=1234567890&L_ERRORCODE0=0000&L_SHORTMESSAGE0=query payment refused test method error';
352
		$success = 'SHIPPINGCALCULATIONMODE=Callback&INSURANCEOPTIONSELECTED=false&RECEIVERID=unit_1340199666_biz_api1.yahoo.de&PAYERID=unittest&PAYERSTATUS=verified&COUNTRYCODE=DE&FIRSTNAME=Unit&LASTNAME=Test&SHIPTOSTREET=Unitteststr. 11&TRANSACTIONID=111111111&PARENTTRANSACTIONID=111111111&TRANSACTIONTYPE=express-checkout&AMT=22.50CURRENCYCODE=EUR&FEEAMT=4.44&PAYMENTSTATUS=Expired&PENDINGREASON=None&INVNUM=34&CORRELATIONID=1f4b8e2c86ead&ACK=Success&VERSION=87.0&BUILD=3136725';
353
354
		$com = new TestPayPalExpress();
355
		$com->addRule( $what, $error, $success );
356
		$this->object->setCommunication( $com );
357
358
		$this->object->query( $this->order );
359
360
		$this->assertEquals( \Aimeos\MShop\Order\Item\Base::PAY_REFUSED, $this->order->getPaymentStatus() );
361
	}
362
363
364
	public function testCancel()
365
	{
366
		$what = array(
367
			'METHOD' => 'DoVoid',
368
			'AUTHORIZATIONID' => '111111111',
369
		);
370
		$error = '&ACK=Error&VERSION=87.0&BUILD=3136725&CORRELATIONID=1234567890&L_ERRORCODE0=0000&L_SHORTMESSAGE0=cancel test method error';
371
		$success = 'CORRELATIONID=1234567890&ACK=Success&VERSION=87.0&BUILD=3136725';
372
373
		$com = new TestPayPalExpress();
374
		$com->addRule( $what, $error, $success );
375
		$this->object->setCommunication( $com );
376
377
		$this->object->cancel( $this->order );
378
379
		$this->assertEquals( \Aimeos\MShop\Order\Item\Base::PAY_CANCELED, $this->order->getPaymentStatus() );
380
	}
381
382
383
	public function testQueryPaymentAuthorized()
384
	{
385
		$what = array(
386
			'METHOD' => 'GetTransactionDetails',
387
			'TRANSACTIONID' => '111111111',
388
		);
389
		$error = '&ACK=Error&VERSION=87.0&BUILD=3136725&CORRELATIONID=1234567890&L_ERRORCODE0=0000&L_SHORTMESSAGE0=query payment authorized test method error';
390
		$success = 'SHIPPINGCALCULATIONMODE=Callback&INSURANCEOPTIONSELECTED=false&RECEIVERID=unit_1340199666_biz_api1.yahoo.de&PAYERID=unittest&PAYERSTATUS=verified&COUNTRYCODE=DE&FIRSTNAME=Unit&LASTNAME=Test&SHIPTOSTREET=Unitteststr. 11&TRANSACTIONID=111111111&PARENTTRANSACTIONID=111111111&TRANSACTIONTYPE=express-checkout&AMT=22.50CURRENCYCODE=EUR&FEEAMT=4.44&PAYMENTSTATUS=Pending&PENDINGREASON=authorization&INVNUM=34&CORRELATIONID=1234567890&ACK=Success&VERSION=87.0&BUILD=3136725';
391
392
		$com = new TestPayPalExpress();
393
		$com->addRule( $what, $error, $success );
394
		$this->object->setCommunication( $com );
395
396
		$this->object->query( $this->order );
397
398
		$this->assertEquals( \Aimeos\MShop\Order\Item\Base::PAY_AUTHORIZED, $this->order->getPaymentStatus() );
399
	}
400
401
402
	public function testWrongAuthorization()
403
	{
404
		$what = array(
405
			'VERSION' => '87.0',
406
			'SIGNATURE' => 'signature',
407
			'USER' => 'name',
408
			'PWD' => 'pw',
409
		);
410
		$error = '&ACK=Error&VERSION=87.0&BUILD=3136725&CORRELATIONID=1234567890&L_ERRORCODE0=0000&L_SHORTMESSAGE0=wrong authorization test method error';
411
		$success = 'SHIPPINGCALCULATIONMODE=Callback&INSURANCEOPTIONSELECTED=false&RECEIVERID=unit_1340199666_biz_api1.yahoo.de&PAYERID=unittest&PAYERSTATUS=verified&COUNTRYCODE=DE&FIRSTNAME=Unit&LASTNAME=Test&SHIPTOSTREET=Unitteststr. 11&TRANSACTIONID=111111111&PARENTTRANSACTIONID=111111111&TRANSACTIONTYPE=express-checkout&AMT=22.50CURRENCYCODE=EUR&FEEAMT=4.44&PAYMENTSTATUS=Pending&PENDINGREASON=authorization&INVNUM=34&CORRELATIONID=1234567890&ACK=Success&VERSION=87.0&BUILD=3136725';
412
413
		$com = new TestPayPalExpress();
414
		$com->addRule( $what, $error, $success );
415
		$this->object->setCommunication( $com );
416
417
		$this->setExpectedException( '\\Aimeos\\MShop\\Service\\Exception' );
418
		$this->object->process( $this->order );
419
	}
420
421
422
	public function testSetPaymentStatusNone()
423
	{
424
		$class = new \ReflectionClass( '\Aimeos\MShop\Service\Provider\Payment\PayPalExpress' );
425
		$method = $class->getMethod( 'setPaymentStatus' );
426
		$method->setAccessible( true );
427
428
		$method->invokeArgs( $this->object, array( $this->order, [] ) );
429
430
		$this->assertEquals( \Aimeos\MShop\Order\Item\Base::PAY_AUTHORIZED, $this->order->getPaymentStatus() );
431
	}
432
433
434
	public function testSetPaymentPending()
435
	{
436
		$class = new \ReflectionClass( '\Aimeos\MShop\Service\Provider\Payment\PayPalExpress' );
437
		$method = $class->getMethod( 'setPaymentStatus' );
438
		$method->setAccessible( true );
439
440
		$method->invokeArgs( $this->object, array( $this->order, array( 'PAYMENTSTATUS' => 'Pending', 'PENDINGREASON' => 'error' ) ) );
441
442
		$this->assertEquals( \Aimeos\MShop\Order\Item\Base::PAY_PENDING, $this->order->getPaymentStatus() );
443
	}
444
445
446
	public function testSetPaymentRefunded()
447
	{
448
		$class = new \ReflectionClass( '\Aimeos\MShop\Service\Provider\Payment\PayPalExpress' );
449
		$method = $class->getMethod( 'setPaymentStatus' );
450
		$method->setAccessible( true );
451
452
		$method->invokeArgs( $this->object, array( $this->order, array( 'PAYMENTSTATUS' => 'Refunded' ) ) );
453
454
		$this->assertEquals( \Aimeos\MShop\Order\Item\Base::PAY_REFUND, $this->order->getPaymentStatus() );
455
	}
456
457
458
	public function testSetPaymentCanceled()
459
	{
460
		$class = new \ReflectionClass( '\Aimeos\MShop\Service\Provider\Payment\PayPalExpress' );
461
		$method = $class->getMethod( 'setPaymentStatus' );
462
		$method->setAccessible( true );
463
464
		$method->invokeArgs( $this->object, array( $this->order, array( 'PAYMENTSTATUS' => 'Voided' ) ) );
465
466
		$this->assertEquals( \Aimeos\MShop\Order\Item\Base::PAY_CANCELED, $this->order->getPaymentStatus() );
467
	}
468
469
470
	public function testSetPaymentInvalid()
471
	{
472
		$class = new \ReflectionClass( '\Aimeos\MShop\Service\Provider\Payment\PayPalExpress' );
473
		$method = $class->getMethod( 'setPaymentStatus' );
474
		$method->setAccessible( true );
475
476
		$method->invokeArgs( $this->object, array( $this->order, array( 'PAYMENTSTATUS' => 'Invalid' ) ) );
477
478
		$this->assertEquals( \Aimeos\MShop\Order\Item\Base::PAY_AUTHORIZED, $this->order->getPaymentStatus() );
479
	}
480
}
481
482
483
class TestPayPalExpress implements \Aimeos\MW\Communication\Iface
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class should be in its own file to aid autoloaders.

Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.

Loading history...
484
{
485
	private $rules = [];
486
487
488
	/**
489
	 * Adds rules to the communication object.
490
	 *
491
	 * @param array $what List of rules for the unit tests.
492
	 * @param string $error Error message if some of the tests fails.
493
	 * @param string $success Success message if all tests were passed.
494
	 */
495
	public function addRule( array $what, $error, $success )
496
	{
497
		$this->rules['set'] = $what;
498
		$this->rules['error'] = $error;
499
		$this->rules['success'] = $success;
500
	}
501
502
503
	/**
504
	 * Get rules of the communication object.
505
	 *
506
	 * @return array rules for internal check
507
	 */
508
	public function getRules()
509
	{
510
		return $this->rules;
511
	}
512
513
514
	/**
515
	 * Sends request parameters to the providers interface.
516
	 *
517
	 * @param string $target Receivers address e.g. url.
518
	 * @param string $method Initial method (e.g. post or get)
519
	 * @param mixed $payload Update information whose format depends on the payment provider
520
	 * @return string response body of a http request
521
	 */
522
	public function transmit( $target, $method, $payload )
523
	{
524
		if( !isset( $this->rules['set'] ) ) {
525
			throw new \Aimeos\MW\Communication\Exception( sprintf( 'No rules for unit tests was set' ) );
526
		}
527
528
		if( !isset( $this->rules['error'] ) ) {
529
			throw new \Aimeos\MW\Communication\Exception( sprintf( 'No error message for unit tests was set' ) );
530
		}
531
532
		if( !isset( $this->rules['success'] ) ) {
533
			throw new \Aimeos\MW\Communication\Exception( sprintf( 'No success message for unit tests was set' ) );
534
		}
535
536
		$params = [];
537
		parse_str( $payload, $params );
538
539
		foreach( $this->rules['set'] as $key => $value )
540
		{
541
			if( $params[$key] != $value ) {
542
				return $this->rules['error'];
543
			}
544
		}
545
546
		return $this->rules['success'];
547
	}
548
}