-
Notifications
You must be signed in to change notification settings - Fork 8
/
RedsysMethod.php
167 lines (145 loc) · 3.48 KB
/
RedsysMethod.php
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
<?php
/*
* This file is part of the PaymentSuite package.
*
* Copyright (c) 2013-2016 Marc Morera
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* Feel free to edit as you please, and have fun.
*
* @author Marc Morera <[email protected]>
*/
namespace PaymentSuite\RedsysBundle;
use PaymentSuite\PaymentCoreBundle\PaymentMethodInterface;
/**
* RedsysMethod class.
*/
final class RedsysMethod implements PaymentMethodInterface
{
/**
* @var array
*
* Decoded dsMerchantParameters array
*/
private $dsMerchantParametersDecoded;
/**
* @var string
*
* Base64 encoded json string representation of payment parameters
*/
private $dsMerchantParameters;
/**
* @var string
*
* Transmission version type
*/
private $dsSignatureVersion;
/**
* @var string
*
* Encrypted payment signature
*/
private $dsSignature;
/**
* @var string
*/
private $paymentName;
/**
* RedsysMethod constructor.
*
* @param string $paymentName
*/
private function __construct(string $paymentName)
{
$this->paymentName = $paymentName;
}
/**
* @param string $paymentName
*
* @return RedsysMethod
*/
public static function createEmpty(string $paymentName): self
{
return new self($paymentName);
}
/**
* @param string $paymentName
* @param array $dsMerchantParametersDecoded
* @param string $dsMerchantParameters
* @param string $dsSignatureVersion
* @param string $dsSignature
*
* @return RedsysMethod
*/
public static function create(
string $paymentName,
array $dsMerchantParametersDecoded,
string $dsMerchantParameters,
string $dsSignatureVersion,
string $dsSignature
): self {
$instance = new self($paymentName);
$instance->dsMerchantParametersDecoded = $dsMerchantParametersDecoded;
$instance->dsMerchantParameters = $dsMerchantParameters;
$instance->dsSignatureVersion = $dsSignatureVersion;
$instance->dsSignature = $dsSignature;
return $instance;
}
/**
* @return array|null
*/
public function getDsMerchantParametersDecoded(): ?array
{
return $this->dsMerchantParametersDecoded;
}
/**
* @return string|null
*/
public function getDsMerchantParameters(): ?string
{
return $this->dsMerchantParameters;
}
/**
* @return string|null
*/
public function getDsSignatureVersion(): ?string
{
return $this->dsSignatureVersion;
}
/**
* @return string|null
*/
public function getDsSignature(): ?string
{
return $this->dsSignature;
}
/**
* @return bool
*/
public function isTransactionSuccessful()
{
if (is_null($this->dsMerchantParametersDecoded)) {
return false;
}
$dsResponse = intval($this->dsMerchantParametersDecoded['Ds_Response']);
return $dsResponse >= 0 && $dsResponse <= 99;
}
/**
* @return string|null
*/
public function getDsOrder(): ?string
{
return $this->dsMerchantParametersDecoded['Ds_Order'] ?? null;
}
/**
* Returns the method's type name.
*
* @return string
*/
public function getPaymentName()
{
return $this->paymentName;
}
}