![]() Server : Apache System : Linux server2.corals.io 4.18.0-348.2.1.el8_5.x86_64 #1 SMP Mon Nov 15 09:17:08 EST 2021 x86_64 User : corals ( 1002) PHP Version : 7.4.33 Disable Function : exec,passthru,shell_exec,system Directory : /home/corals/cartforge.co/vendor/paypal/module-braintree-graph-ql/Plugin/ |
<?php /** * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ declare(strict_types=1); namespace PayPal\BraintreeGraphQl\Plugin; use PayPal\Braintree\Gateway\Command\GetPaymentNonceCommand; use PayPal\Braintree\Model\Ui\ConfigProvider; use Magento\Framework\GraphQl\Exception\GraphQlInputException; use Psr\Log\LoggerInterface; /** * Plugin creating nonce from Magento Vault Braintree public hash */ class SetVaultPaymentNonce { /** * @var GetPaymentNonceCommand */ private $command; /** * @var LoggerInterface */ private $logger; /** * @param GetPaymentNonceCommand $command * @param LoggerInterface $logger */ public function __construct( GetPaymentNonceCommand $command, LoggerInterface $logger ) { $this->command = $command; $this->logger = $logger; } /** * Set Braintree nonce from public hash * * @param \Magento\QuoteGraphQl\Model\Cart\SetPaymentMethodOnCart $subject * @param \Magento\Quote\Model\Quote $quote * @param array $paymentData * @return array * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ public function beforeExecute( \Magento\QuoteGraphQl\Model\Cart\SetPaymentMethodOnCart $subject, \Magento\Quote\Model\Quote $quote, array $paymentData ): array { if ($paymentData['code'] !== ConfigProvider::CC_VAULT_CODE || !isset($paymentData[ConfigProvider::CC_VAULT_CODE]) || !isset($paymentData[ConfigProvider::CC_VAULT_CODE]['public_hash']) ) { return [$quote, $paymentData]; } $subject = [ 'public_hash' => $paymentData[ConfigProvider::CC_VAULT_CODE]['public_hash'], 'customer_id' => $quote->getCustomerId(), 'store_id' => $quote->getStoreId(), ]; try { $result = $this->command->execute($subject)->get(); $paymentData[ConfigProvider::CC_VAULT_CODE]['payment_method_nonce'] = $result['paymentMethodNonce']; } catch (\Exception $e) { $this->logger->critical($e); throw new GraphQlInputException(__('Sorry, but something went wrong')); } return [$quote, $paymentData]; } }