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