|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* InterKassa driver for the Omnipay PHP payment processing library |
|
4
|
|
|
* |
|
5
|
|
|
* @link https://github.com/hiqdev/omnipay-interkassa |
|
6
|
|
|
* @package omnipay-interkassa |
|
7
|
|
|
* @license MIT |
|
8
|
|
|
* @copyright Copyright (c) 2015-2017, HiQDev (http://hiqdev.com/) |
|
9
|
|
|
*/ |
|
10
|
|
|
|
|
11
|
|
|
namespace Omnipay\InterKassa\Message; |
|
12
|
|
|
|
|
13
|
|
|
use Omnipay\Common\Exception\InvalidResponseException; |
|
14
|
|
|
use Omnipay\Common\Message\AbstractResponse; |
|
15
|
|
|
use Omnipay\Common\Message\RequestInterface; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* InterKassa Complete Purchase Response. |
|
19
|
|
|
*/ |
|
20
|
|
|
class CompletePurchaseResponse extends AbstractResponse |
|
21
|
|
|
{ |
|
22
|
|
|
/** |
|
23
|
|
|
* {@inheritdoc} |
|
24
|
|
|
* @var CompletePurchaseRequest |
|
25
|
|
|
*/ |
|
26
|
|
|
public $request; |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* {@inheritdoc} |
|
30
|
|
|
*/ |
|
31
|
8 |
|
public function __construct(RequestInterface $request, $data) |
|
32
|
|
|
{ |
|
33
|
8 |
|
parent::__construct($request, $data); |
|
34
|
|
|
|
|
35
|
8 |
|
$signKey = $this->request->getTestMode() ? $this->request->getTestKey() : $this->request->getSignKey(); |
|
36
|
8 |
|
$signExpected = $this->request->calculateSign($this->data, $signKey); |
|
37
|
|
|
|
|
38
|
8 |
|
if ($this->getCheckoutId() !== $this->request->getCheckoutId()) { |
|
39
|
|
|
throw new InvalidResponseException('Wrong checkout ID'); |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
8 |
|
if ($this->getSign() !== $signExpected) { |
|
43
|
2 |
|
throw new InvalidResponseException('Failed to validate signature'); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
6 |
|
if ($this->getState() !== 'success') { |
|
47
|
2 |
|
throw new InvalidResponseException('The payment was not success'); |
|
48
|
|
|
} |
|
49
|
4 |
|
} |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* Whether the payment is successful. |
|
53
|
|
|
* |
|
54
|
|
|
* @return boolean |
|
55
|
|
|
*/ |
|
56
|
2 |
|
public function isSuccessful() |
|
57
|
|
|
{ |
|
58
|
2 |
|
return $this->getState() === 'success'; |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
/** |
|
62
|
|
|
* The checkout ID. |
|
63
|
|
|
* |
|
64
|
|
|
* @return string |
|
65
|
|
|
*/ |
|
66
|
4 |
|
public function getCheckoutId() |
|
67
|
|
|
{ |
|
68
|
4 |
|
return $this->data['ik_co_id']; |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
/** |
|
72
|
|
|
* @return string |
|
73
|
|
|
*/ |
|
74
|
4 |
|
public function getSign() |
|
75
|
|
|
{ |
|
76
|
4 |
|
return $this->data['ik_sign']; |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
/** |
|
80
|
|
|
* The transaction identifier generated by the merchant website. |
|
81
|
|
|
* |
|
82
|
|
|
* @return string |
|
83
|
|
|
*/ |
|
84
|
1 |
|
public function getTransactionId() |
|
85
|
|
|
{ |
|
86
|
1 |
|
return $this->data['ik_pm_no']; |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
/** |
|
90
|
|
|
* {@inheritdoc} |
|
91
|
|
|
*/ |
|
92
|
1 |
|
public function getTransactionReference() |
|
93
|
|
|
{ |
|
94
|
1 |
|
return $this->data['ik_inv_id']; |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
/** |
|
98
|
|
|
* The amount of payment. |
|
99
|
|
|
* |
|
100
|
|
|
* @return mixed |
|
101
|
|
|
*/ |
|
102
|
1 |
|
public function getAmount() |
|
103
|
|
|
{ |
|
104
|
1 |
|
return $this->data['ik_am']; |
|
105
|
|
|
} |
|
106
|
|
|
|
|
107
|
|
|
/** |
|
108
|
|
|
* The currency of the payment. |
|
109
|
|
|
* @return string |
|
110
|
|
|
*/ |
|
111
|
1 |
|
public function getCurrency() |
|
112
|
|
|
{ |
|
113
|
1 |
|
return strtoupper($this->data['ik_cur']); |
|
114
|
|
|
} |
|
115
|
|
|
|
|
116
|
|
|
/** |
|
117
|
|
|
* The time of request processing. |
|
118
|
|
|
* |
|
119
|
|
|
* @return string |
|
120
|
|
|
*/ |
|
121
|
1 |
|
public function getTime() |
|
122
|
|
|
{ |
|
123
|
1 |
|
$date = new \DateTime($this->data['ik_inv_prc'], new \DateTimeZone('Europe/Moscow')); |
|
124
|
|
|
return $date->format('c'); |
|
125
|
1 |
|
} |
|
126
|
|
|
|
|
127
|
|
|
/** |
|
128
|
|
|
* @return string the payment method inside a gateway (Visa, WebMoney, etc) |
|
129
|
|
|
*/ |
|
130
|
|
|
public function getPayer() |
|
131
|
1 |
|
{ |
|
132
|
|
|
return $this->data['ik_pw_via']; |
|
133
|
1 |
|
} |
|
134
|
|
|
|
|
135
|
|
|
/** |
|
136
|
|
|
* The state of the payment. |
|
137
|
|
|
* Possible results: |
|
138
|
|
|
* - `new`: newly created payment |
|
139
|
|
|
* - `waitAccept`: waits for the payment |
|
140
|
|
|
* - `process`: the payment is being processed |
|
141
|
|
|
* - `success`: the payment processed successfully |
|
142
|
|
|
* - `canceled`: the payment have been canceled |
|
143
|
|
|
* - `fail`: the payment failed. |
|
144
|
|
|
* |
|
145
|
|
|
* @return string |
|
146
|
|
|
* @see isSuccessful |
|
147
|
|
|
*/ |
|
148
|
|
|
public function getState() |
|
149
|
3 |
|
{ |
|
150
|
|
|
return $this->data['ik_inv_st']; |
|
151
|
3 |
|
} |
|
152
|
|
|
} |
|
153
|
|
|
|