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 Guzzle\Http\Message\Response; |
15
|
|
|
use Omnipay\Tests\TestCase; |
16
|
|
|
use Symfony\Component\HttpFoundation\Request as HttpRequest; |
17
|
|
|
|
18
|
|
|
class CompletePurchaseRequestTest extends TestCase |
19
|
|
|
{ |
20
|
|
|
private $request; |
21
|
|
|
|
22
|
|
|
private $purse = '[email protected]'; |
23
|
|
|
private $secret = '*&^^&$sdf&(23'; |
24
|
|
|
private $hash = '33bfff79d7eeffdca9a9ac7b34a78dfc'; |
|
|
|
|
25
|
|
|
private $description = 'Test Transaction long description'; |
26
|
|
|
private $transactionId = '12345ASD67890sd'; |
27
|
|
|
private $transactionReference = '12345678'; |
28
|
|
|
private $timestamp = '2016-02-02 16:56:56 UTC'; |
|
|
|
|
29
|
|
|
private $payer = '[email protected]'; |
30
|
|
|
private $amount = '1465.01'; |
31
|
|
|
private $testMode = false; |
32
|
|
|
private $response = 'VERIFIED'; |
33
|
|
|
|
34
|
|
|
public function setUp() |
35
|
|
|
{ |
36
|
|
|
parent::setUp(); |
37
|
|
|
|
38
|
|
|
$httpResponse = new Response(200, null, $this->response); |
39
|
|
|
|
40
|
|
|
$tmpRequest = $this->getMock('Guzzle\Http\Message\Request', ['send'], ['POST', '']); |
41
|
|
|
$tmpRequest->expects($this->any())->method('send')->will($this->returnValue($httpResponse)); |
42
|
|
|
|
43
|
|
|
$httpClient = $this->getMock('Guzzle\Http\Client', ['setConfig', 'post']); |
44
|
|
|
$httpClient->expects($this->any())->method('post')->will($this->returnValue($tmpRequest)); |
45
|
|
|
|
46
|
|
|
$httpRequest = new HttpRequest([], [ |
47
|
|
|
'business' => $this->purse, |
48
|
|
|
'payment_gross' => $this->amount, |
49
|
|
|
'item_name' => $this->description, |
50
|
|
|
'mc_currency' => $this->currency, |
51
|
|
|
'payer_email' => $this->payer, |
52
|
|
|
'payment_date' => $this->time, |
53
|
|
|
'item_number' => $this->transactionId, |
54
|
|
|
'txn_id' => $this->transactionReference, |
55
|
|
|
]); |
56
|
|
|
|
57
|
|
|
$this->request = new CompletePurchaseRequest($httpClient, $httpRequest); |
58
|
|
|
$this->request->initialize([ |
59
|
|
|
'purse' => $this->purse, |
60
|
|
|
'secret' => $this->secret, |
61
|
|
|
'testMode' => $this->testMode, |
62
|
|
|
]); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
public function testGetData() |
66
|
|
|
{ |
67
|
|
|
$data = $this->request->getData(); |
68
|
|
|
|
69
|
|
|
$this->assertSame($this->purse, $data['business']); |
70
|
|
|
$this->assertSame($this->description, $data['item_name']); |
71
|
|
|
$this->assertSame($this->transactionId, $data['item_number']); |
72
|
|
|
$this->assertSame($this->amount, $data['payment_gross']); |
73
|
|
|
$this->assertSame($this->time, $data['payment_date']); |
74
|
|
|
$this->assertSame($this->payer, $data['payer_email']); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
public function testSendData() |
78
|
|
|
{ |
79
|
|
|
$data = $this->request->getData(); |
80
|
|
|
$response = $this->request->sendData($data); |
81
|
|
|
$this->assertInstanceOf('Omnipay\PayPal\Message\CompletePurchaseResponse', $response); |
82
|
|
|
} |
83
|
|
|
} |
84
|
|
|
|
This check marks private properties in classes that are never used. Those properties can be removed.