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\Common\Exception\InvalidResponseException; |
15
|
|
|
use Omnipay\Common\Message\AbstractResponse; |
16
|
|
|
use Omnipay\Common\Message\RequestInterface; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* PayPal Complete Purchase Response. |
20
|
|
|
*/ |
21
|
|
|
class CompletePurchaseResponse extends AbstractResponse |
22
|
|
|
{ |
23
|
|
|
/** |
24
|
|
|
* @var CompletePurchaseRequest |
25
|
|
|
*/ |
26
|
|
|
public $request; |
27
|
|
|
|
28
|
4 |
|
public function __construct(RequestInterface $request, $data) |
29
|
|
|
{ |
30
|
4 |
|
parent::__construct($request, $data); |
31
|
|
|
|
32
|
4 |
|
if ($this->getResult() !== 'VERIFIED') { |
33
|
1 |
|
throw new InvalidResponseException('Not verified'); |
34
|
|
|
} |
35
|
|
|
|
36
|
3 |
|
if ($this->request->getTestMode() !== $this->getTestMode()) { |
37
|
1 |
|
throw new InvalidResponseException('Invalid test mode'); |
38
|
|
|
} |
39
|
2 |
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* Whether the payment is successful. |
43
|
|
|
* @return boolean |
44
|
|
|
*/ |
45
|
1 |
|
public function isSuccessful() |
46
|
|
|
{ |
47
|
1 |
|
return true; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* Whether the payment is test. |
52
|
|
|
* @return boolean |
53
|
|
|
*/ |
54
|
3 |
|
public function getTestMode() |
55
|
|
|
{ |
56
|
3 |
|
return (bool) $this->data['test_ipn']; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* {@inheritdoc} |
61
|
|
|
* @return string |
62
|
|
|
*/ |
63
|
1 |
|
public function getTransactionId() |
64
|
|
|
{ |
65
|
1 |
|
return $this->data['item_number']; |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* {@inheritdoc} |
70
|
|
|
* @return string |
71
|
|
|
*/ |
72
|
1 |
|
public function getTransactionReference() |
73
|
|
|
{ |
74
|
1 |
|
return $this->data['txn_id']; |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* Retruns the transatcion status. |
79
|
|
|
* @return string |
80
|
|
|
*/ |
81
|
1 |
|
public function getTransactionStatus() |
82
|
|
|
{ |
83
|
1 |
|
return $this->data['payment_status']; |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* {@inheritdoc} |
88
|
|
|
* @return string |
89
|
|
|
*/ |
90
|
1 |
|
public function getAmount() |
91
|
|
|
{ |
92
|
1 |
|
return $this->data['payment_gross']; |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* Returns the result, injected by [[CompletePurchaseRequest::sendData()]]. |
97
|
|
|
* @return mixed |
98
|
|
|
*/ |
99
|
4 |
|
public function getResult() |
100
|
|
|
{ |
101
|
4 |
|
return $this->data['_result']; |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
/** |
105
|
|
|
* {@inheritdoc} |
106
|
|
|
* @return string |
107
|
|
|
*/ |
108
|
1 |
|
public function getFee() |
109
|
|
|
{ |
110
|
1 |
|
return $this->data['payment_fee']; |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
/** |
114
|
|
|
* Returns the currency. |
115
|
|
|
* @return string |
116
|
|
|
*/ |
117
|
1 |
|
public function getCurrency() |
118
|
|
|
{ |
119
|
1 |
|
return strtoupper($this->data['mc_currency']); |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
/** |
123
|
|
|
* Returns the payer "name/email". |
124
|
|
|
* @return string |
125
|
|
|
*/ |
126
|
1 |
|
public function getPayer() |
127
|
|
|
{ |
128
|
1 |
|
$payer = $this->data['address_name'] . '/' . $this->data['payer_email']; |
129
|
1 |
|
$charset = strtoupper($this->data['charset']); |
130
|
1 |
|
if ($charset !== 'UTF-8') { |
131
|
1 |
|
$payer = iconv($charset, 'UTF-8//IGNORE', $payer); |
132
|
1 |
|
} |
133
|
|
|
|
134
|
1 |
|
return $payer; |
135
|
|
|
} |
136
|
|
|
|
137
|
|
|
/** |
138
|
|
|
* Returns the payment date. |
139
|
|
|
* @return string |
140
|
|
|
*/ |
141
|
1 |
|
public function getTime() |
142
|
|
|
{ |
143
|
1 |
|
return date('c', strtotime($this->data['payment_date'])); |
144
|
|
|
} |
145
|
|
|
} |
146
|
|
|
|