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