示例#1
0
文件: Ipn.php 项目: nja78/magento2
 /**
  * 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();
 }
示例#2
0
 /**
  * Transfer transaction/payment information from API instance to order payment
  *
  * @param \Magento\Framework\DataObject|AbstractApi $from
  * @param \Magento\Payment\Model\InfoInterface $to
  * @return $this
  */
 public function importPaymentInfo(\Magento\Framework\DataObject $from, \Magento\Payment\Model\InfoInterface $to)
 {
     // update PayPal-specific payment information in the payment object
     $this->getInfo()->importToPayment($from, $to);
     /**
      * Detect payment review and/or frauds
      * PayPal pro API returns fraud results only in the payment call response
      */
     if ($from->getDataUsingMethod(\Magento\Paypal\Model\Info::IS_FRAUD)) {
         $to->setIsTransactionPending(true);
         $to->setIsFraudDetected(true);
     } elseif (Info::isPaymentReviewRequired($to)) {
         $to->setIsTransactionPending(true);
     }
     // give generic info about transaction state
     if (Info::isPaymentSuccessful($to)) {
         $to->setIsTransactionApproved(true);
     } elseif (Info::isPaymentFailed($to)) {
         $to->setIsTransactionDenied(true);
     }
     return $this;
 }