1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* InterKassa driver for the Omnipay PHP payment processing library |
5
|
|
|
* |
6
|
|
|
* @link https://github.com/ange007/omnipay-interkassa |
7
|
|
|
* @package omnipay-interkassa |
8
|
|
|
* @license MIT |
9
|
|
|
* @copyright Copyright (c) 2017, ange007 ( original author: HiQDev - http://hiqdev.com/ ) |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Omnipay\InterKassa\Message; |
13
|
|
|
|
14
|
|
|
use Omnipay\Common\Message\RequestInterface; |
15
|
|
|
use Omnipay\Common\Message\NotificationInterface; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* InterKassa NotificationResponse. |
19
|
|
|
* |
20
|
|
|
* https://www.interkassa.com/documentation-sci/#sci-pay-notify |
21
|
|
|
*/ |
22
|
|
|
class NotificationResponse extends AbstractResponse implements NotificationInterface |
23
|
|
|
{ |
24
|
|
|
/** |
25
|
|
|
* |
26
|
|
|
*/ |
27
|
|
|
private $errorMessage; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* {@inheritdoc} |
31
|
|
|
*/ |
32
|
|
|
public function __construct( RequestInterface $request, $data ) |
33
|
|
|
{ |
34
|
|
|
parent::__construct( $request, $data ); |
35
|
|
|
|
36
|
|
|
$signKey = $this->request->getTestMode( ) ? $this->request->getTestKey( ) : $this->request->getSignKey( ); |
37
|
|
|
$signExpected = $this->request->calculateSign( $this->data, $signKey ); |
38
|
|
|
|
39
|
|
|
if( $this->getCheckoutId( ) !== $this->request->getCheckoutId( ) ) |
40
|
|
|
{ |
41
|
|
|
$this->errorMessage = 'Wrong checkout ID'; |
42
|
|
|
} |
43
|
|
|
else if( $this->getSign( ) !== $signExpected ) |
44
|
|
|
{ |
45
|
|
|
$this->errorMessage = 'Failed to validate signature'; |
46
|
|
|
} |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* Whether the payment is successful. |
51
|
|
|
* |
52
|
|
|
* @return boolean |
53
|
|
|
*/ |
54
|
|
|
public function isSuccessful( ) |
55
|
|
|
{ |
56
|
|
|
if( !empty( $this->errorMessage ) ) |
57
|
|
|
{ |
58
|
|
|
return false; |
59
|
|
|
} |
60
|
|
|
else |
61
|
|
|
{ |
62
|
|
|
return $this->getTransactionStatus( ) === 'success'; |
63
|
|
|
} |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* @return string |
68
|
|
|
*/ |
69
|
|
|
public function getSign( ) |
70
|
|
|
{ |
71
|
|
|
return isset( $this->data[ 'ik_sign' ] ) ? $this->data[ 'ik_sign' ] : null; |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* |
76
|
|
|
*/ |
77
|
|
|
public function getMessage( ) |
78
|
|
|
{ |
79
|
|
|
return $this->errorMessage; |
80
|
|
|
} |
81
|
|
|
} |
82
|
|
|
|