|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* PayPal driver for Omnipay PHP payment library |
|
5
|
|
|
* |
|
6
|
|
|
* @link https://github.com/hiqdev/omnipay-paypal |
|
7
|
|
|
* @package omnipay-paypal |
|
8
|
|
|
* @license MIT |
|
9
|
|
|
* @copyright Copyright (c) 2015-2016, HiQDev (http://hiqdev.com/) |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace Omnipay\PayPal\Message; |
|
13
|
|
|
|
|
14
|
|
|
use Omnipay\Tests\TestCase; |
|
15
|
|
|
|
|
16
|
|
|
class CompletePurchaseResponseTest extends TestCase |
|
17
|
|
|
{ |
|
18
|
|
|
private $request; |
|
19
|
|
|
private $response = 'VERIFIED'; |
|
20
|
|
|
|
|
21
|
|
|
private $purse = '[email protected]'; |
|
22
|
|
|
private $secret = '22SAD#-78G8sdf$88'; |
|
23
|
|
|
private $description = 'Test Transaction long description'; |
|
24
|
|
|
private $transactionId = '1SD672345A890sd'; |
|
25
|
|
|
private $transactionStatus = 'Completed'; |
|
26
|
|
|
private $transactionReference = 'sdfa1SD672345A8'; |
|
27
|
|
|
private $time = '2016-02-02T18:50:20+00:00'; |
|
28
|
|
|
private $payer = '[email protected]'; |
|
29
|
|
|
private $address = 'Somewhere str, 123'; |
|
30
|
|
|
private $fee = '1.01'; |
|
31
|
|
|
private $amount = '1465.01'; |
|
32
|
|
|
private $currency = 'USD'; |
|
33
|
|
|
private $testMode = true; |
|
34
|
|
|
|
|
35
|
|
|
public function setUp() |
|
36
|
|
|
{ |
|
37
|
|
|
parent::setUp(); |
|
38
|
|
|
|
|
39
|
|
|
$this->request = new CompletePurchaseRequest($this->getHttpClient(), $this->getHttpRequest()); |
|
40
|
|
|
$this->request->initialize([ |
|
41
|
|
|
'purse' => $this->purse, |
|
42
|
|
|
'secret' => $this->secret, |
|
43
|
|
|
'testMode' => $this->testMode, |
|
44
|
|
|
]); |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
public function testNotVerifiedException() |
|
48
|
|
|
{ |
|
49
|
|
|
$this->setExpectedException('Omnipay\Common\Exception\InvalidResponseException', 'Not verified'); |
|
50
|
|
|
new CompletePurchaseResponse($this->request, [ |
|
51
|
|
|
'description' => $this->description, |
|
52
|
|
|
]); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
public function testInvalidTestModeException() |
|
56
|
|
|
{ |
|
57
|
|
|
$this->setExpectedException('Omnipay\Common\Exception\InvalidResponseException', 'Invalid test mode'); |
|
58
|
|
|
new CompletePurchaseResponse($this->request, [ |
|
59
|
|
|
'item_name' => $this->description, |
|
60
|
|
|
'_result' => $this->response, |
|
61
|
|
|
]); |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
public function testSuccess() |
|
65
|
|
|
{ |
|
66
|
|
|
$response = new CompletePurchaseResponse($this->request, [ |
|
67
|
|
|
'test_ipn' => $this->testMode, |
|
68
|
|
|
'business' => $this->purse, |
|
69
|
|
|
'payment_fee' => $this->fee, |
|
70
|
|
|
'payment_gross' => $this->amount, |
|
71
|
|
|
'item_name' => $this->description, |
|
72
|
|
|
'mc_currency' => $this->currency, |
|
73
|
|
|
'payer_email' => $this->payer, |
|
74
|
|
|
'address_name' => $this->address, |
|
75
|
|
|
'payment_date' => $this->time, |
|
76
|
|
|
'item_number' => $this->transactionId, |
|
77
|
|
|
'payment_status' => $this->transactionStatus, |
|
78
|
|
|
'txn_id' => $this->transactionReference, |
|
79
|
|
|
'_result' => $this->response, |
|
80
|
|
|
]); |
|
81
|
|
|
|
|
82
|
|
|
$this->assertTrue($response->isSuccessful()); |
|
83
|
|
|
$this->assertTrue($response->getTestMode()); |
|
84
|
|
|
$this->assertNull($response->getMessage()); |
|
85
|
|
|
$this->assertNull($response->getCode()); |
|
86
|
|
|
$this->assertSame($this->transactionId, $response->getTransactionId()); |
|
87
|
|
|
$this->assertSame($this->transactionStatus, $response->getTransactionStatus()); |
|
88
|
|
|
$this->assertSame($this->transactionReference, $response->getTransactionReference()); |
|
89
|
|
|
$this->assertSame($this->fee, $response->getFee()); |
|
90
|
|
|
$this->assertSame($this->amount, $response->getAmount()); |
|
91
|
|
|
$this->assertSame($this->currency, $response->getCurrency()); |
|
92
|
|
|
$this->assertSame($this->time, $response->getTime()); |
|
93
|
|
|
$this->assertSame($this->address . '/' . $this->payer, $response->getPayer()); |
|
94
|
|
|
} |
|
95
|
|
|
} |
|
96
|
|
|
|