5
5
*/
6
6
namespace Magento \Vault \Model \Method ;
7
7
8
+ use Exception ;
8
9
use Magento \Framework \Event \ManagerInterface ;
9
10
use Magento \Framework \ObjectManagerInterface ;
10
11
use Magento \Payment \Gateway \Command ;
21
22
use Magento \Vault \Api \PaymentTokenManagementInterface ;
22
23
use Magento \Vault \Block \Form ;
23
24
use Magento \Vault \Model \VaultPaymentInterface ;
25
+ use Magento \Framework \Serialize \Serializer \Json ;
24
26
25
27
/**
26
28
* Class Vault
@@ -103,6 +105,11 @@ class Vault implements VaultPaymentInterface
103
105
*/
104
106
private $ code ;
105
107
108
+ /**
109
+ * @var Json
110
+ */
111
+ private $ jsonSerializer ;
112
+
106
113
/**
107
114
* Constructor
108
115
*
@@ -116,6 +123,7 @@ class Vault implements VaultPaymentInterface
116
123
* @param PaymentTokenManagementInterface $tokenManagement
117
124
* @param OrderPaymentExtensionInterfaceFactory $paymentExtensionFactory
118
125
* @param string $code
126
+ * @param Json|null $jsonSerializer
119
127
*
120
128
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
121
129
*/
@@ -129,7 +137,8 @@ public function __construct(
129
137
Command \CommandManagerPoolInterface $ commandManagerPool ,
130
138
PaymentTokenManagementInterface $ tokenManagement ,
131
139
OrderPaymentExtensionInterfaceFactory $ paymentExtensionFactory ,
132
- $ code
140
+ $ code ,
141
+ Json $ jsonSerializer = null
133
142
) {
134
143
$ this ->config = $ config ;
135
144
$ this ->configFactory = $ configFactory ;
@@ -141,21 +150,14 @@ public function __construct(
141
150
$ this ->tokenManagement = $ tokenManagement ;
142
151
$ this ->paymentExtensionFactory = $ paymentExtensionFactory ;
143
152
$ this ->code = $ code ;
144
- }
145
-
146
- /**
147
- * @return MethodInterface
148
- */
149
- private function getVaultProvider ()
150
- {
151
- return $ this ->vaultProvider ;
153
+ $ this ->jsonSerializer = $ jsonSerializer ?: $ this ->objectManager ->get (Json::class);
152
154
}
153
155
154
156
/**
155
157
* Unifies configured value handling logic
156
158
*
157
159
* @param string $field
158
- * @param null $storeId
160
+ * @param int| null $storeId
159
161
* @return mixed
160
162
*/
161
163
private function getConfiguredValue ($ field , $ storeId = null )
@@ -226,8 +228,8 @@ public function canOrder()
226
228
*/
227
229
public function canAuthorize ()
228
230
{
229
- return $ this ->getVaultProvider () ->canAuthorize ()
230
- && $ this ->getVaultProvider () ->getConfigData (static ::CAN_AUTHORIZE );
231
+ return $ this ->vaultProvider ->canAuthorize ()
232
+ && $ this ->vaultProvider ->getConfigData (static ::CAN_AUTHORIZE );
231
233
}
232
234
233
235
/**
@@ -236,8 +238,8 @@ public function canAuthorize()
236
238
*/
237
239
public function canCapture ()
238
240
{
239
- return $ this ->getVaultProvider () ->canCapture ()
240
- && $ this ->getVaultProvider () ->getConfigData (static ::CAN_CAPTURE );
241
+ return $ this ->vaultProvider ->canCapture ()
242
+ && $ this ->vaultProvider ->getConfigData (static ::CAN_CAPTURE );
241
243
}
242
244
243
245
/**
@@ -255,7 +257,7 @@ public function canCapturePartial()
255
257
*/
256
258
public function canCaptureOnce ()
257
259
{
258
- return $ this ->getVaultProvider () ->canCaptureOnce ();
260
+ return $ this ->vaultProvider ->canCaptureOnce ();
259
261
}
260
262
261
263
/**
@@ -294,7 +296,7 @@ public function canUseInternal()
294
296
$ isInternalAllowed = $ this ->getConfiguredValue ('can_use_internal ' );
295
297
// if config has't been specified for Vault, need to check payment provider option
296
298
if ($ isInternalAllowed === null ) {
297
- return $ this ->getVaultProvider () ->canUseInternal ();
299
+ return $ this ->vaultProvider ->canUseInternal ();
298
300
}
299
301
return (bool ) $ isInternalAllowed ;
300
302
}
@@ -305,7 +307,7 @@ public function canUseInternal()
305
307
*/
306
308
public function canUseCheckout ()
307
309
{
308
- return $ this ->getVaultProvider () ->canUseCheckout ();
310
+ return $ this ->vaultProvider ->canUseCheckout ();
309
311
}
310
312
311
313
/**
@@ -314,7 +316,7 @@ public function canUseCheckout()
314
316
*/
315
317
public function canEdit ()
316
318
{
317
- return $ this ->getVaultProvider () ->canEdit ();
319
+ return $ this ->vaultProvider ->canEdit ();
318
320
}
319
321
320
322
/**
@@ -341,7 +343,7 @@ public function fetchTransactionInfo(InfoInterface $payment, $transactionId)
341
343
*/
342
344
public function isGateway ()
343
345
{
344
- return $ this ->getVaultProvider () ->isGateway ();
346
+ return $ this ->vaultProvider ->isGateway ();
345
347
}
346
348
347
349
/**
@@ -350,7 +352,7 @@ public function isGateway()
350
352
*/
351
353
public function isOffline ()
352
354
{
353
- return $ this ->getVaultProvider () ->isOffline ();
355
+ return $ this ->vaultProvider ->isOffline ();
354
356
}
355
357
356
358
/**
@@ -359,7 +361,7 @@ public function isOffline()
359
361
*/
360
362
public function isInitializeNeeded ()
361
363
{
362
- return $ this ->getVaultProvider () ->isInitializeNeeded ();
364
+ return $ this ->vaultProvider ->isInitializeNeeded ();
363
365
}
364
366
365
367
/**
@@ -368,7 +370,7 @@ public function isInitializeNeeded()
368
370
*/
369
371
public function canUseForCountry ($ country )
370
372
{
371
- return $ this ->getVaultProvider () ->canUseForCountry ($ country );
373
+ return $ this ->vaultProvider ->canUseForCountry ($ country );
372
374
}
373
375
374
376
/**
@@ -377,7 +379,7 @@ public function canUseForCountry($country)
377
379
*/
378
380
public function canUseForCurrency ($ currencyCode )
379
381
{
380
- return $ this ->getVaultProvider () ->canUseForCurrency ($ currencyCode );
382
+ return $ this ->vaultProvider ->canUseForCurrency ($ currencyCode );
381
383
}
382
384
383
385
/**
@@ -386,7 +388,7 @@ public function canUseForCurrency($currencyCode)
386
388
*/
387
389
public function getInfoBlockType ()
388
390
{
389
- return $ this ->getVaultProvider () ->getInfoBlockType ();
391
+ return $ this ->vaultProvider ->getInfoBlockType ();
390
392
}
391
393
392
394
/**
@@ -395,7 +397,7 @@ public function getInfoBlockType()
395
397
*/
396
398
public function getInfoInstance ()
397
399
{
398
- return $ this ->getVaultProvider () ->getInfoInstance ();
400
+ return $ this ->vaultProvider ->getInfoInstance ();
399
401
}
400
402
401
403
/**
@@ -404,7 +406,7 @@ public function getInfoInstance()
404
406
*/
405
407
public function setInfoInstance (InfoInterface $ info )
406
408
{
407
- $ this ->getVaultProvider () ->setInfoInstance ($ info );
409
+ $ this ->vaultProvider ->setInfoInstance ($ info );
408
410
}
409
411
410
412
/**
@@ -413,7 +415,7 @@ public function setInfoInstance(InfoInterface $info)
413
415
*/
414
416
public function validate ()
415
417
{
416
- return $ this ->getVaultProvider () ->validate ();
418
+ return $ this ->vaultProvider ->validate ();
417
419
}
418
420
419
421
/**
@@ -437,9 +439,10 @@ public function authorize(\Magento\Payment\Model\InfoInterface $payment, $amount
437
439
/** @var $payment OrderPaymentInterface */
438
440
439
441
$ this ->attachTokenExtensionAttribute ($ payment );
442
+ $ this ->attachCreditCardInfo ($ payment );
440
443
441
444
$ commandExecutor = $ this ->commandManagerPool ->get (
442
- $ this ->getVaultProvider () ->getCode ()
445
+ $ this ->vaultProvider ->getCode ()
443
446
);
444
447
445
448
$ commandExecutor ->executeByCode (
@@ -450,7 +453,7 @@ public function authorize(\Magento\Payment\Model\InfoInterface $payment, $amount
450
453
]
451
454
);
452
455
453
- $ payment ->setMethod ($ this ->getVaultProvider () ->getCode ());
456
+ $ payment ->setMethod ($ this ->vaultProvider ->getCode ());
454
457
455
458
return $ this ;
456
459
}
@@ -473,7 +476,7 @@ public function capture(\Magento\Payment\Model\InfoInterface $payment, $amount)
473
476
$ this ->attachTokenExtensionAttribute ($ payment );
474
477
475
478
$ commandExecutor = $ this ->commandManagerPool ->get (
476
- $ this ->getVaultProvider () ->getCode ()
479
+ $ this ->vaultProvider ->getCode ()
477
480
);
478
481
479
482
$ commandExecutor ->executeByCode (
@@ -484,10 +487,12 @@ public function capture(\Magento\Payment\Model\InfoInterface $payment, $amount)
484
487
]
485
488
);
486
489
487
- $ payment ->setMethod ($ this ->getVaultProvider () ->getCode ());
490
+ $ payment ->setMethod ($ this ->vaultProvider ->getCode ());
488
491
}
489
492
490
493
/**
494
+ * Attaches token extension attribute.
495
+ *
491
496
* @param OrderPaymentInterface $orderPayment
492
497
* @return void
493
498
*/
@@ -514,6 +519,8 @@ private function attachTokenExtensionAttribute(OrderPaymentInterface $orderPayme
514
519
}
515
520
516
521
/**
522
+ * Returns Payment's extension attributes.
523
+ *
517
524
* @param OrderPaymentInterface $payment
518
525
* @return \Magento\Sales\Api\Data\OrderPaymentExtensionInterface
519
526
*/
@@ -528,6 +535,27 @@ private function getPaymentExtensionAttributes(OrderPaymentInterface $payment)
528
535
return $ extensionAttributes ;
529
536
}
530
537
538
+ /**
539
+ * Attaches credit card info.
540
+ *
541
+ * @param OrderPaymentInterface $payment
542
+ * @return void
543
+ */
544
+ private function attachCreditCardInfo (OrderPaymentInterface $ payment ): void
545
+ {
546
+ try {
547
+ $ paymentToken = $ payment ->getExtensionAttributes ()
548
+ ->getVaultPaymentToken ();
549
+ if ($ paymentToken ) {
550
+ $ tokenDetails = $ this ->jsonSerializer ->unserialize ($ paymentToken ->getTokenDetails ());
551
+ if ($ tokenDetails && is_array ($ tokenDetails )) {
552
+ $ payment ->addData ($ tokenDetails );
553
+ }
554
+ }
555
+ } catch (Exception $ e ) {
556
+ }
557
+ }
558
+
531
559
/**
532
560
* @inheritdoc
533
561
* @since 100.1.0
@@ -615,7 +643,7 @@ public function assignData(\Magento\Framework\DataObject $data)
615
643
]
616
644
);
617
645
618
- return $ this ->getVaultProvider () ->assignData ($ data );
646
+ return $ this ->vaultProvider ->assignData ($ data );
619
647
}
620
648
621
649
/**
@@ -624,7 +652,7 @@ public function assignData(\Magento\Framework\DataObject $data)
624
652
*/
625
653
public function isAvailable (\Magento \Quote \Api \Data \CartInterface $ quote = null )
626
654
{
627
- return $ this ->getVaultProvider () ->isAvailable ($ quote )
655
+ return $ this ->vaultProvider ->isAvailable ($ quote )
628
656
&& $ this ->config ->getValue (self ::$ activeKey , $ this ->getStore () ?: ($ quote ? $ quote ->getStoreId () : null ));
629
657
}
630
658
@@ -634,7 +662,7 @@ public function isAvailable(\Magento\Quote\Api\Data\CartInterface $quote = null)
634
662
*/
635
663
public function isActive ($ storeId = null )
636
664
{
637
- return $ this ->getVaultProvider () ->isActive ($ storeId )
665
+ return $ this ->vaultProvider ->isActive ($ storeId )
638
666
&& $ this ->config ->getValue (self ::$ activeKey , $ this ->getStore () ?: $ storeId );
639
667
}
640
668
@@ -653,7 +681,7 @@ public function initialize($paymentAction, $stateObject)
653
681
*/
654
682
public function getConfigPaymentAction ()
655
683
{
656
- return $ this ->getVaultProvider () ->getConfigPaymentAction ();
684
+ return $ this ->vaultProvider ->getConfigPaymentAction ();
657
685
}
658
686
659
687
/**
@@ -662,6 +690,6 @@ public function getConfigPaymentAction()
662
690
*/
663
691
public function getProviderCode ()
664
692
{
665
- return $ this ->getVaultProvider () ->getCode ();
693
+ return $ this ->vaultProvider ->getCode ();
666
694
}
667
695
}
0 commit comments