/** * Map payment information from IPN to payment object * Returns true if there were changes in information * * @return bool * @SuppressWarnings(PHPMD.CyclomaticComplexity) * @SuppressWarnings(PHPMD.NPathComplexity) */ protected function _importPaymentInformation() { $payment = $this->_order->getPayment(); $was = $payment->getAdditionalInformation(); // collect basic information $from = []; foreach ([Info::PAYER_ID, 'payer_email' => Info::PAYER_EMAIL, Info::PAYER_STATUS, Info::ADDRESS_STATUS, Info::PROTECTION_EL, Info::PAYMENT_STATUS, Info::PENDING_REASON] as $privateKey => $publicKey) { if (is_int($privateKey)) { $privateKey = $publicKey; } $value = $this->getRequestData($privateKey); if ($value) { $from[$publicKey] = $value; } } if (isset($from['payment_status'])) { $from['payment_status'] = $this->_filterPaymentStatus($this->getRequestData('payment_status')); } // collect fraud filters $fraudFilters = []; for ($i = 1; $value = $this->getRequestData("fraud_management_pending_filters_{$i}"); $i++) { $fraudFilters[] = $value; } if ($fraudFilters) { $from[Info::FRAUD_FILTERS] = $fraudFilters; } $this->_paypalInfo->importToPayment($from, $payment); /** * Detect pending payment, frauds * TODO: implement logic in one place * @see \Magento\Paypal\Model\Pro::importPaymentInfo() */ if ($this->_paypalInfo->isPaymentReviewRequired($payment)) { $payment->setIsTransactionPending(true); if ($fraudFilters) { $payment->setIsFraudDetected(true); } } if ($this->_paypalInfo->isPaymentSuccessful($payment)) { $payment->setIsTransactionApproved(true); } elseif ($this->_paypalInfo->isPaymentFailed($payment)) { $payment->setIsTransactionDenied(true); } return $was != $payment->getAdditionalInformation(); }
/** * Perform the payment review * * @param \Magento\Payment\Model\InfoInterface $payment * @param string $action * @return bool */ public function reviewPayment(\Magento\Payment\Model\InfoInterface $payment, $action) { $api = $this->getApi()->setTransactionId($payment->getLastTransId()); // check whether the review is still needed $api->callGetTransactionDetails(); $this->importPaymentInfo($api, $payment); if (!Info::isPaymentReviewRequired($payment)) { return false; } // perform the review action $api->setAction($action)->callManagePendingTransactionStatus(); $api->callGetTransactionDetails(); $this->importPaymentInfo($api, $payment); return true; }
/** * Check whether payment review is required * * @param \Magento\Payment\Model\Info $payment * @return bool */ protected function _isPaymentReviewRequired(\Magento\Payment\Model\Info $payment) { return \Magento\Paypal\Model\Info::isPaymentReviewRequired($payment); }