15
15
//use Magento\Vault\Model\CreditCardTokenFactory;
16
16
use Magento \Payment \Model \InfoInterface ;
17
17
use CardknoxDevelopment \Cardknox \Gateway \Config \Config ;
18
+ use Magento \Payment \Model \Method \Logger ;
18
19
19
20
class VaultHandler implements HandlerInterface
20
21
{
@@ -26,7 +27,7 @@ class VaultHandler implements HandlerInterface
26
27
/**
27
28
* @var CreditCardTokenFactory
28
29
*/
29
- // protected $creditCardTokenFactory;
30
+ // protected $creditCardTokenFactory;
30
31
31
32
protected $ paymentTokenFactory ;
32
33
/**
@@ -35,6 +36,16 @@ class VaultHandler implements HandlerInterface
35
36
protected $ paymentExtensionFactory ;
36
37
37
38
protected $ config ;
39
+
40
+ /**
41
+ * @var Logger
42
+ */
43
+ private $ logger ;
44
+
45
+ /**
46
+ * @param Logger $logger
47
+ */
48
+
38
49
/**
39
50
* Constructor
40
51
*
@@ -44,11 +55,13 @@ class VaultHandler implements HandlerInterface
44
55
public function __construct (
45
56
PaymentTokenInterfaceFactory $ paymentTokenFactory ,
46
57
OrderPaymentExtensionInterfaceFactory $ paymentExtensionFactory ,
47
- Config $ config
58
+ Config $ config ,
59
+ Logger $ logger
48
60
) {
49
61
$ this ->paymentTokenFactory = $ paymentTokenFactory ;
50
62
$ this ->paymentExtensionFactory = $ paymentExtensionFactory ;
51
63
$ this ->config = $ config ;
64
+ $ this ->logger = $ logger ;
52
65
}
53
66
54
67
/**
@@ -60,7 +73,8 @@ public function __construct(
60
73
*/
61
74
public function handle (array $ handlingSubject , array $ response )
62
75
{
63
- if (!isset ($ handlingSubject ['payment ' ])
76
+ if (
77
+ !isset ($ handlingSubject ['payment ' ])
64
78
|| !$ handlingSubject ['payment ' ] instanceof PaymentDataObjectInterface
65
79
) {
66
80
throw new \InvalidArgumentException ('Payment data object should be provided ' );
@@ -71,6 +85,12 @@ public function handle(array $handlingSubject, array $response)
71
85
72
86
$ payment = $ paymentDO ->getPayment ();
73
87
88
+ if ($ payment ->getAdditionalInformation ("is_active_payment_token_enabler " ) == "" ) {
89
+ return ;
90
+ }
91
+
92
+ $ log ['VaultHandler save card ' ] = true ;
93
+
74
94
$ xExp = "" ;
75
95
if (isset ($ response [$ this ::xExp])) {
76
96
$ xExp = $ response [$ this ::xExp];
@@ -86,6 +106,8 @@ public function handle(array $handlingSubject, array $response)
86
106
$ extensionAttributes ->setVaultPaymentToken ($ paymentToken );
87
107
}
88
108
}
109
+
110
+ $ this ->logger ->debug ($ log );
89
111
}
90
112
91
113
/**
@@ -97,7 +119,7 @@ public function handle(array $handlingSubject, array $response)
97
119
private function getVaultPaymentToken (array $ response , string $ xExp )
98
120
{
99
121
// Check token existing in gateway response
100
- if (isset ($ response [$ this ::xToken])){
122
+ if (isset ($ response [$ this ::xToken])) {
101
123
$ token = $ response [$ this ::xToken];
102
124
if (empty ($ token )) {
103
125
return null ;
@@ -106,7 +128,6 @@ private function getVaultPaymentToken(array $response, string $xExp)
106
128
return null ;
107
129
}
108
130
109
-
110
131
/** @var PaymentTokenInterface $paymentToken */
111
132
$ paymentToken = $ this ->paymentTokenFactory ->create ();
112
133
$ paymentToken ->setGatewayToken ($ token );
@@ -128,15 +149,14 @@ private function getExpirationDate(string $xExp)
128
149
{
129
150
$ expDate = new \DateTime (
130
151
'20 ' . substr ($ xExp , -2 )
131
- . '- '
132
- . substr ($ xExp , 0 , 2 )
133
- . '- '
134
- . '01 '
135
- . ' '
136
- . '00:00:00 ' ,
152
+ . '- '
153
+ . substr ($ xExp , 0 , 2 )
154
+ . '- '
155
+ . '01 '
156
+ . ' '
157
+ . '00:00:00 ' ,
137
158
new \DateTimeZone ('UTC ' )
138
159
);
139
- // $expDate->add(new \DateInterval('P1M'));
140
160
return $ expDate ->format ('Y-m-d 00:00:00 ' );
141
161
}
142
162
/**
@@ -158,7 +178,6 @@ private function convertDetailsToJSON($details)
158
178
*/
159
179
private function getCreditCardType ($ type )
160
180
{
161
- // $replaced = str_replace(' ', '-', strtolower($type));
162
181
$ mapper = $ this ->config ->getCctypesMapper ();
163
182
return $ mapper [$ type ];
164
183
}
0 commit comments