/** * {inheritdoc} */ public function handle(InfoInterface $payment, DataObject $response) { $importObject = []; foreach ($this->fieldsToHandle as $field) { if ($response->getData($field)) { $importObject[$field] = $response->getData($field); } } $this->paypalInfoManager->importToPayment($importObject, $payment); }
/** * {inheritdoc} */ public function handle(InfoInterface $payment, Object $response) { if (!in_array($response->getData('result'), [Payflowpro::RESPONSE_CODE_DECLINED_BY_FILTER, Payflowpro::RESPONSE_CODE_FRAUDSERVICE_FILTER])) { return; } $fraudMessages = ['RESPMSG' => $response->getData(self::RESPONSE_MESSAGE)]; if ($response->getData(self::FRAUD_RULES_XML)) { $fraudMessages = array_merge($fraudMessages, $this->getFraudRulesDictionary($response->getData(self::FRAUD_RULES_XML))); } $this->paypalInfoManager->importToPayment([Info::FRAUD_FILTERS => array_merge($fraudMessages, (array) $payment->getAdditionalInformation(Info::FRAUD_FILTERS))], $payment); }
/** * @dataProvider importToPaymentDataProvider * @param array $mapping * @param array $expectation */ public function testExportFromPaymentCustomMapping($mapping, $expectation) { /** @var \Magento\Payment\Model\InfoInterface $paymentInfo */ $paymentInfo = $this->objectManagerHelper->getObject('Magento\\Payment\\Model\\Info'); $paymentInfo->setAdditionalInformation($expectation); // we create $to empty object $to = new \Magento\Framework\DataObject(); $this->info->exportFromPayment($paymentInfo, $to, array_flip($mapping)); $this->assertEquals($mapping, $to->getData()); }
/** * 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; }
/** * Update quote when returned from PayPal * rewrite billing address by paypal * save old billing address for new customer * export shipping address in case address absence * * @param string $token * @return void * @SuppressWarnings(PHPMD.CyclomaticComplexity) */ public function returnFromPaypal($token) { $this->_getApi(); $this->_api->setToken($token)->callGetExpressCheckoutDetails(); $quote = $this->_quote; $this->ignoreAddressValidation(); // import shipping address $exportedShippingAddress = $this->_api->getExportedShippingAddress(); if (!$quote->getIsVirtual()) { $shippingAddress = $quote->getShippingAddress(); if ($shippingAddress) { if ($exportedShippingAddress && $quote->getPayment()->getAdditionalInformation(self::PAYMENT_INFO_BUTTON) == 1) { $this->_setExportedAddressData($shippingAddress, $exportedShippingAddress); // PayPal doesn't provide detailed shipping info: prefix, middlename, lastname, suffix $shippingAddress->setPrefix(null); $shippingAddress->setMiddlename(null); $shippingAddress->setLastname(null); $shippingAddress->setSuffix(null); $shippingAddress->setCollectShippingRates(true); $shippingAddress->setSameAsBilling(0); } // import shipping method $code = ''; if ($this->_api->getShippingRateCode()) { $code = $this->_matchShippingMethodCode($shippingAddress, $this->_api->getShippingRateCode()); if ($code) { // possible bug of double collecting rates :-/ $shippingAddress->setShippingMethod($code)->setCollectShippingRates(true); } } $quote->getPayment()->setAdditionalInformation(self::PAYMENT_INFO_TRANSPORT_SHIPPING_METHOD, $code); } } // import billing address $portBillingFromShipping = $quote->getPayment()->getAdditionalInformation(self::PAYMENT_INFO_BUTTON) == 1 && $this->_config->getValue('requireBillingAddress') != \Magento\Paypal\Model\Config::REQUIRE_BILLING_ADDRESS_ALL && !$quote->isVirtual(); if ($portBillingFromShipping) { $billingAddress = clone $shippingAddress; $billingAddress->unsAddressId()->unsAddressType()->setCustomerAddressId(null); $data = $billingAddress->getData(); $data['save_in_address_book'] = 0; $quote->getBillingAddress()->addData($data); $quote->getShippingAddress()->setSameAsBilling(1); } else { $billingAddress = $quote->getBillingAddress(); } $exportedBillingAddress = $this->_api->getExportedBillingAddress(); $this->_setExportedAddressData($billingAddress, $exportedBillingAddress); $billingAddress->setCustomerNote($exportedBillingAddress->getData('note')); $quote->setBillingAddress($billingAddress); // import payment info $payment = $quote->getPayment(); $payment->setMethod($this->_methodType); $this->_paypalInfo->importToPayment($this->_api, $payment); $payment->setAdditionalInformation(self::PAYMENT_INFO_TRANSPORT_PAYER_ID, $this->_api->getPayerId())->setAdditionalInformation(self::PAYMENT_INFO_TRANSPORT_TOKEN, $token); $quote->collectTotals(); $this->quoteRepository->save($quote); }
/** * 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); }