Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
PaymentConfiguration.php
Go to the documentation of this file.
1 <?php
7 
13 
21 {
22  const MARKER = 'instant-purchase';
23 
27  private $integrationManager;
28 
33  public function __construct(
34  IntegrationsManager $integrationsManager
35  ) {
36  $this->integrationManager = $integrationsManager;
37  }
38 
48  public function configurePayment(
49  Quote $quote,
51  ): Quote {
52  $paymentMethod = $this->getVaultPaymentMethodCode(
54  $quote->getStoreId()
55  );
56 
57  $payment = $quote->getPayment();
58  $payment->setQuote($quote);
59  $payment->importData(['method' => $paymentMethod]);
60  $payment->setAdditionalInformation($this->buildPaymentAdditionalInformation(
62  $quote->getStoreId()
63  ));
64 
65  return $quote;
66  }
67 
76  private function getVaultPaymentMethodCode(PaymentTokenInterface $paymentToken, int $storeId): string
77  {
78  try {
79  $integration = $this->integrationManager->getByToken($paymentToken, $storeId);
80  $vaultPaymentMethodCode = $integration->getVaultCode();
81  return $vaultPaymentMethodCode;
82  } catch (LocalizedException $e) {
83  throw new LocalizedException(__('Specified payment method is not available now.'), $e);
84  }
85  }
86 
94  private function buildPaymentAdditionalInformation(PaymentTokenInterface $paymentToken, int $storeId): array
95  {
96  $common = [
100 
101  // mark payment
102  self::MARKER => 'true',
103  ];
104 
105  $integration = $this->integrationManager->getByToken($paymentToken, $storeId);
106  $specific = $integration->getAdditionalInformation($paymentToken);
107 
108  $additionalInformation = array_merge($common, $specific);
109  return $additionalInformation;
110  }
111 }
configurePayment(Quote $quote, PaymentTokenInterface $paymentToken)
$quote
__()
Definition: __.php:13
$payment
Definition: order.php:17