2121use Magento \Vault \Api \PaymentTokenManagementInterface ;
2222use Magento \Vault \Block \Form ;
2323use Magento \Vault \Model \VaultPaymentInterface ;
24+ use Magento \Framework \Serialize \Serializer \Json ;
2425
2526/**
2627 * Class Vault
@@ -103,6 +104,11 @@ class Vault implements VaultPaymentInterface
103104 */
104105 private $ code ;
105106
107+ /**
108+ * @var Json
109+ */
110+ private $ jsonSerializer ;
111+
106112 /**
107113 * Constructor
108114 *
@@ -116,6 +122,7 @@ class Vault implements VaultPaymentInterface
116122 * @param PaymentTokenManagementInterface $tokenManagement
117123 * @param OrderPaymentExtensionInterfaceFactory $paymentExtensionFactory
118124 * @param string $code
125+ * @param Json $jsonSerializer
119126 *
120127 * @SuppressWarnings(PHPMD.ExcessiveParameterList)
121128 */
@@ -129,7 +136,8 @@ public function __construct(
129136 Command \CommandManagerPoolInterface $ commandManagerPool ,
130137 PaymentTokenManagementInterface $ tokenManagement ,
131138 OrderPaymentExtensionInterfaceFactory $ paymentExtensionFactory ,
132- $ code
139+ $ code ,
140+ Json $ jsonSerializer
133141 ) {
134142 $ this ->config = $ config ;
135143 $ this ->configFactory = $ configFactory ;
@@ -141,21 +149,14 @@ public function __construct(
141149 $ this ->tokenManagement = $ tokenManagement ;
142150 $ this ->paymentExtensionFactory = $ paymentExtensionFactory ;
143151 $ this ->code = $ code ;
144- }
145-
146- /**
147- * @return MethodInterface
148- */
149- private function getVaultProvider ()
150- {
151- return $ this ->vaultProvider ;
152+ $ this ->jsonSerializer = $ jsonSerializer ;
152153 }
153154
154155 /**
155156 * Unifies configured value handling logic
156157 *
157158 * @param string $field
158- * @param null $storeId
159+ * @param int| null $storeId
159160 * @return mixed
160161 */
161162 private function getConfiguredValue ($ field , $ storeId = null )
@@ -226,8 +227,8 @@ public function canOrder()
226227 */
227228 public function canAuthorize ()
228229 {
229- return $ this ->getVaultProvider () ->canAuthorize ()
230- && $ this ->getVaultProvider () ->getConfigData (static ::CAN_AUTHORIZE );
230+ return $ this ->vaultProvider ->canAuthorize ()
231+ && $ this ->vaultProvider ->getConfigData (static ::CAN_AUTHORIZE );
231232 }
232233
233234 /**
@@ -236,8 +237,8 @@ public function canAuthorize()
236237 */
237238 public function canCapture ()
238239 {
239- return $ this ->getVaultProvider () ->canCapture ()
240- && $ this ->getVaultProvider () ->getConfigData (static ::CAN_CAPTURE );
240+ return $ this ->vaultProvider ->canCapture ()
241+ && $ this ->vaultProvider ->getConfigData (static ::CAN_CAPTURE );
241242 }
242243
243244 /**
@@ -255,7 +256,7 @@ public function canCapturePartial()
255256 */
256257 public function canCaptureOnce ()
257258 {
258- return $ this ->getVaultProvider () ->canCaptureOnce ();
259+ return $ this ->vaultProvider ->canCaptureOnce ();
259260 }
260261
261262 /**
@@ -294,7 +295,7 @@ public function canUseInternal()
294295 $ isInternalAllowed = $ this ->getConfiguredValue ('can_use_internal ' );
295296 // if config has't been specified for Vault, need to check payment provider option
296297 if ($ isInternalAllowed === null ) {
297- return $ this ->getVaultProvider () ->canUseInternal ();
298+ return $ this ->vaultProvider ->canUseInternal ();
298299 }
299300 return (bool ) $ isInternalAllowed ;
300301 }
@@ -305,7 +306,7 @@ public function canUseInternal()
305306 */
306307 public function canUseCheckout ()
307308 {
308- return $ this ->getVaultProvider () ->canUseCheckout ();
309+ return $ this ->vaultProvider ->canUseCheckout ();
309310 }
310311
311312 /**
@@ -314,7 +315,7 @@ public function canUseCheckout()
314315 */
315316 public function canEdit ()
316317 {
317- return $ this ->getVaultProvider () ->canEdit ();
318+ return $ this ->vaultProvider ->canEdit ();
318319 }
319320
320321 /**
@@ -341,7 +342,7 @@ public function fetchTransactionInfo(InfoInterface $payment, $transactionId)
341342 */
342343 public function isGateway ()
343344 {
344- return $ this ->getVaultProvider () ->isGateway ();
345+ return $ this ->vaultProvider ->isGateway ();
345346 }
346347
347348 /**
@@ -350,7 +351,7 @@ public function isGateway()
350351 */
351352 public function isOffline ()
352353 {
353- return $ this ->getVaultProvider () ->isOffline ();
354+ return $ this ->vaultProvider ->isOffline ();
354355 }
355356
356357 /**
@@ -359,7 +360,7 @@ public function isOffline()
359360 */
360361 public function isInitializeNeeded ()
361362 {
362- return $ this ->getVaultProvider () ->isInitializeNeeded ();
363+ return $ this ->vaultProvider ->isInitializeNeeded ();
363364 }
364365
365366 /**
@@ -368,7 +369,7 @@ public function isInitializeNeeded()
368369 */
369370 public function canUseForCountry ($ country )
370371 {
371- return $ this ->getVaultProvider () ->canUseForCountry ($ country );
372+ return $ this ->vaultProvider ->canUseForCountry ($ country );
372373 }
373374
374375 /**
@@ -377,7 +378,7 @@ public function canUseForCountry($country)
377378 */
378379 public function canUseForCurrency ($ currencyCode )
379380 {
380- return $ this ->getVaultProvider () ->canUseForCurrency ($ currencyCode );
381+ return $ this ->vaultProvider ->canUseForCurrency ($ currencyCode );
381382 }
382383
383384 /**
@@ -386,7 +387,7 @@ public function canUseForCurrency($currencyCode)
386387 */
387388 public function getInfoBlockType ()
388389 {
389- return $ this ->getVaultProvider () ->getInfoBlockType ();
390+ return $ this ->vaultProvider ->getInfoBlockType ();
390391 }
391392
392393 /**
@@ -395,7 +396,7 @@ public function getInfoBlockType()
395396 */
396397 public function getInfoInstance ()
397398 {
398- return $ this ->getVaultProvider () ->getInfoInstance ();
399+ return $ this ->vaultProvider ->getInfoInstance ();
399400 }
400401
401402 /**
@@ -404,7 +405,7 @@ public function getInfoInstance()
404405 */
405406 public function setInfoInstance (InfoInterface $ info )
406407 {
407- $ this ->getVaultProvider () ->setInfoInstance ($ info );
408+ $ this ->vaultProvider ->setInfoInstance ($ info );
408409 }
409410
410411 /**
@@ -413,7 +414,7 @@ public function setInfoInstance(InfoInterface $info)
413414 */
414415 public function validate ()
415416 {
416- return $ this ->getVaultProvider () ->validate ();
417+ return $ this ->vaultProvider ->validate ();
417418 }
418419
419420 /**
@@ -437,9 +438,10 @@ public function authorize(\Magento\Payment\Model\InfoInterface $payment, $amount
437438 /** @var $payment OrderPaymentInterface */
438439
439440 $ this ->attachTokenExtensionAttribute ($ payment );
441+ $ this ->attachCreditCardInfo ($ payment );
440442
441443 $ commandExecutor = $ this ->commandManagerPool ->get (
442- $ this ->getVaultProvider () ->getCode ()
444+ $ this ->vaultProvider ->getCode ()
443445 );
444446
445447 $ commandExecutor ->executeByCode (
@@ -450,7 +452,7 @@ public function authorize(\Magento\Payment\Model\InfoInterface $payment, $amount
450452 ]
451453 );
452454
453- $ payment ->setMethod ($ this ->getVaultProvider () ->getCode ());
455+ $ payment ->setMethod ($ this ->vaultProvider ->getCode ());
454456
455457 return $ this ;
456458 }
@@ -473,7 +475,7 @@ public function capture(\Magento\Payment\Model\InfoInterface $payment, $amount)
473475 $ this ->attachTokenExtensionAttribute ($ payment );
474476
475477 $ commandExecutor = $ this ->commandManagerPool ->get (
476- $ this ->getVaultProvider () ->getCode ()
478+ $ this ->vaultProvider ->getCode ()
477479 );
478480
479481 $ commandExecutor ->executeByCode (
@@ -484,10 +486,12 @@ public function capture(\Magento\Payment\Model\InfoInterface $payment, $amount)
484486 ]
485487 );
486488
487- $ payment ->setMethod ($ this ->getVaultProvider () ->getCode ());
489+ $ payment ->setMethod ($ this ->vaultProvider ->getCode ());
488490 }
489491
490492 /**
493+ * Attaches token extension attribute.
494+ *
491495 * @param OrderPaymentInterface $orderPayment
492496 * @return void
493497 */
@@ -514,6 +518,8 @@ private function attachTokenExtensionAttribute(OrderPaymentInterface $orderPayme
514518 }
515519
516520 /**
521+ * Returns Payment's extension attributes.
522+ *
517523 * @param OrderPaymentInterface $payment
518524 * @return \Magento\Sales\Api\Data\OrderPaymentExtensionInterface
519525 */
@@ -528,6 +534,20 @@ private function getPaymentExtensionAttributes(OrderPaymentInterface $payment)
528534 return $ extensionAttributes ;
529535 }
530536
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+
531551 /**
532552 * @inheritdoc
533553 * @since 100.1.0
@@ -615,7 +635,7 @@ public function assignData(\Magento\Framework\DataObject $data)
615635 ]
616636 );
617637
618- return $ this ->getVaultProvider () ->assignData ($ data );
638+ return $ this ->vaultProvider ->assignData ($ data );
619639 }
620640
621641 /**
@@ -624,7 +644,7 @@ public function assignData(\Magento\Framework\DataObject $data)
624644 */
625645 public function isAvailable (\Magento \Quote \Api \Data \CartInterface $ quote = null )
626646 {
627- return $ this ->getVaultProvider () ->isAvailable ($ quote )
647+ return $ this ->vaultProvider ->isAvailable ($ quote )
628648 && $ this ->config ->getValue (self ::$ activeKey , $ this ->getStore () ?: ($ quote ? $ quote ->getStoreId () : null ));
629649 }
630650
@@ -634,7 +654,7 @@ public function isAvailable(\Magento\Quote\Api\Data\CartInterface $quote = null)
634654 */
635655 public function isActive ($ storeId = null )
636656 {
637- return $ this ->getVaultProvider () ->isActive ($ storeId )
657+ return $ this ->vaultProvider ->isActive ($ storeId )
638658 && $ this ->config ->getValue (self ::$ activeKey , $ this ->getStore () ?: $ storeId );
639659 }
640660
@@ -653,7 +673,7 @@ public function initialize($paymentAction, $stateObject)
653673 */
654674 public function getConfigPaymentAction ()
655675 {
656- return $ this ->getVaultProvider () ->getConfigPaymentAction ();
676+ return $ this ->vaultProvider ->getConfigPaymentAction ();
657677 }
658678
659679 /**
@@ -662,6 +682,6 @@ public function getConfigPaymentAction()
662682 */
663683 public function getProviderCode ()
664684 {
665- return $ this ->getVaultProvider () ->getCode ();
685+ return $ this ->vaultProvider ->getCode ();
666686 }
667687}
0 commit comments