Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
PayflowExpress.php
Go to the documentation of this file.
1 <?php
7 namespace Magento\Paypal\Model;
8 
10 
15 {
20 
24  protected $_formBlockType = \Magento\Paypal\Block\PayflowExpress\Form::class;
25 
31  protected $_ecInstance = null;
32 
37 
43  protected $_canFetchTransactionInfo = false;
44 
50  protected $_canReviewPayment = false;
51 
74  public function __construct(
75  \Magento\Framework\Model\Context $context,
76  \Magento\Framework\Registry $registry,
77  \Magento\Framework\Api\ExtensionAttributesFactory $extensionFactory,
79  \Magento\Payment\Helper\Data $paymentData,
80  \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig,
81  \Magento\Payment\Model\Method\Logger $logger,
82  ProFactory $proFactory,
84  \Magento\Framework\UrlInterface $urlBuilder,
85  CartFactory $cartFactory,
86  \Magento\Checkout\Model\Session $checkoutSession,
87  \Magento\Framework\Exception\LocalizedExceptionFactory $exception,
90  InfoFactory $paypalInfoFactory,
91  \Magento\Framework\Model\ResourceModel\AbstractResource $resource = null,
92  \Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null,
93  array $data = []
94  ) {
95  parent::__construct(
96  $context,
97  $registry,
98  $extensionFactory,
100  $paymentData,
101  $scopeConfig,
102  $logger,
103  $proFactory,
105  $urlBuilder,
106  $cartFactory,
107  $checkoutSession,
108  $exception,
111  $resource,
112  $resourceCollection,
113  $data
114  );
115  $this->_paypalInfoFactory = $paypalInfoFactory;
116  }
117 
124  public function isAvailable(\Magento\Quote\Api\Data\CartInterface $quote = null)
125  {
126  if (!parent::isAvailable($quote)) {
127  return false;
128  }
129  if (!$this->_ecInstance) {
130  $this->_ecInstance = $this->_paymentData->getMethodInstance(
132  );
133  }
134  if ($quote) {
135  $this->_ecInstance->setStore($quote->getStoreId());
136  }
137  return !$this->_ecInstance->isAvailable();
138  }
139 
147  protected function _importToPayment($api, $payment)
148  {
149  $payment->setTransactionId(
150  $api->getPaypalTransactionId()
151  )->setIsTransactionClosed(
152  0
153  )->setAdditionalInformation(
155  $api->getRedirectRequired() || $api->getRedirectRequested()
156  )->setIsTransactionPending(
157  $api->getIsPaymentPending()
158  )->setTransactionAdditionalInfo(
159  Payflow\Pro::TRANSPORT_PAYFLOW_TXN_ID,
160  $api->getTransactionId()
161  );
162  $payment->setPreparedMessage(__('Payflow PNREF: #%1.', $api->getTransactionId()));
163  $this->_paypalInfoFactory->create()->importToPayment($api, $payment);
164  }
165 
173  public function getCheckoutRedirectUrl()
174  {
175  return $this->_urlBuilder->getUrl('paypal/payflowexpress/start');
176  }
177 
185  public function canRefund()
186  {
188  $payment = $this->getInfoInstance();
189  // we need the last capture transaction was made
190  $captureTransaction = $this->transactionRepository->getByTransactionType(
192  $payment->getId(),
193  $payment->getOrder()->getId()
194  );
195  return $captureTransaction && $captureTransaction->getAdditionalInformation(
196  Payflow\Pro::TRANSPORT_PAYFLOW_TXN_ID
197  ) && $this->_canRefund;
198  }
199 }
__construct(\Magento\Framework\Model\Context $context, \Magento\Framework\Registry $registry, \Magento\Framework\Api\ExtensionAttributesFactory $extensionFactory, \Magento\Framework\Api\AttributeValueFactory $customAttributeFactory, \Magento\Payment\Helper\Data $paymentData, \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig, \Magento\Payment\Model\Method\Logger $logger, ProFactory $proFactory, \Magento\Store\Model\StoreManagerInterface $storeManager, \Magento\Framework\UrlInterface $urlBuilder, CartFactory $cartFactory, \Magento\Checkout\Model\Session $checkoutSession, \Magento\Framework\Exception\LocalizedExceptionFactory $exception, \Magento\Sales\Api\TransactionRepositoryInterface $transactionRepository, \Magento\Sales\Model\Order\Payment\Transaction\BuilderInterface $transactionBuilder, InfoFactory $paypalInfoFactory, \Magento\Framework\Model\ResourceModel\AbstractResource $resource=null, \Magento\Framework\Data\Collection\AbstractDb $resourceCollection=null, array $data=[])
isAvailable(\Magento\Quote\Api\Data\CartInterface $quote=null)
$quote
$storeManager
__()
Definition: __.php:13
$resource
Definition: bulk.php:12
$payment
Definition: order.php:17