_paypalInfoFactory = $paypalInfoFactory; } /** * EC PE won't be available if the EC is available * * @param \Magento\Quote\Api\Data\CartInterface|\Magento\Quote\Model\Quote|null $quote * @return bool */ public function isAvailable(\Magento\Quote\Api\Data\CartInterface $quote = null) { if (!parent::isAvailable($quote)) { return false; } if (!$this->_ecInstance) { $this->_ecInstance = $this->_paymentData->getMethodInstance( Config::METHOD_WPP_EXPRESS ); } if ($quote) { $this->_ecInstance->setStore($quote->getStoreId()); } return !$this->_ecInstance->isAvailable(); } /** * Import payment info to payment * * @param Api\Nvp $api * @param \Magento\Sales\Model\Order\Payment $payment * @return void */ protected function _importToPayment($api, $payment) { $payment->setTransactionId( $api->getPaypalTransactionId() )->setIsTransactionClosed( 0 )->setAdditionalInformation( Express\Checkout::PAYMENT_INFO_TRANSPORT_REDIRECT, $api->getRedirectRequired() || $api->getRedirectRequested() )->setIsTransactionPending( $api->getIsPaymentPending() )->setTransactionAdditionalInfo( Payflow\Pro::TRANSPORT_PAYFLOW_TXN_ID, $api->getTransactionId() ); $payment->setPreparedMessage(__('Payflow PNREF: #%1.', $api->getTransactionId())); $this->_paypalInfoFactory->create()->importToPayment($api, $payment); } /** * Checkout redirect URL getter for onepage checkout (hardcode) * * @see \Magento\Checkout\Controller\Onepage::savePaymentAction() * @see \Magento\Quote\Model\Quote\Payment::getCheckoutRedirectUrl() * @return string */ public function getCheckoutRedirectUrl() { return $this->_urlBuilder->getUrl('paypal/payflowexpress/start'); } /** * Check refund availability. * The main factor is that the last capture transaction exists and has an Payflow\Pro::TRANSPORT_PAYFLOW_TXN_ID in * additional information(needed to perform online refund. Requirement of the Payflow gateway) * * @return bool */ public function canRefund() { /** @var \Magento\Sales\Model\Order\Payment $payment */ $payment = $this->getInfoInstance(); // we need the last capture transaction was made $captureTransaction = $this->transactionRepository->getByTransactionType( Transaction::TYPE_CAPTURE, $payment->getId(), $payment->getOrder()->getId() ); return $captureTransaction && $captureTransaction->getAdditionalInformation( Payflow\Pro::TRANSPORT_PAYFLOW_TXN_ID ) && $this->_canRefund; } }