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