forked from opensdks/omnikassa2-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPaymentCompletedResponse.php
More file actions
74 lines (66 loc) · 2.16 KB
/
PaymentCompletedResponse.php
File metadata and controls
74 lines (66 loc) · 2.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
<?php namespace nl\rabobank\gict\payments_savings\omnikassa_sdk\model\response;
use nl\rabobank\gict\payments_savings\omnikassa_sdk\model\signing\InvalidSignatureException;
use nl\rabobank\gict\payments_savings\omnikassa_sdk\model\signing\SignedResponse;
use nl\rabobank\gict\payments_savings\omnikassa_sdk\model\signing\SigningKey;
class PaymentCompletedResponse extends SignedResponse
{
/** @var string */
protected $orderID;
/** @var string */
protected $status;
/**
* @param string $orderID
* @param string $status
* @param string $signature
*/
private function __construct($orderID, $status, $signature)
{
$this->orderID = $orderID;
$this->status = $status;
$this->setSignature($signature);
}
/**
* @return string
*/
public function getOrderID()
{
return $this->orderID;
}
/**
* @return string
*/
public function getStatus()
{
return $this->status;
}
/**
* Creates a new PaymentCompletedResponse instance.
* It sanitizes the input and validates the signature resulting in a valid instance or the value FALSE.
*
* @param string $orderID
* @param string $status
* @param string $signature
* @param SigningKey $signingKey
* @return bool|PaymentCompletedResponse Returns FALSE if the signature is invalid, otherwise the instance is returned.
*/
public static function createInstance($orderID, $status, $signature, SigningKey $signingKey)
{
//Sanitize input
$status = preg_replace('/[^A-Z_]/', '', $status);
$signature = preg_replace('/[^0-9a-f]/', '', $signature);
$instance = new PaymentCompletedResponse($orderID, $status, $signature);
try {
$instance->validateSignature($signingKey);
} catch (InvalidSignatureException $invalidSignatureException) {
return false;
}
return $instance;
}
/**
* @return array
*/
public function getSignatureData()
{
return array($this->orderID, $this->status);
}
}