10 use Magento\Payment\Model\Method\ConfigInterfaceFactory;
153 \
Magento\Framework\Module\ModuleListInterface $moduleList,
154 \
Magento\Framework\Stdlib\DateTime\TimezoneInterface $localeDate,
159 \
Magento\Framework\Math\Random $mathRandom,
160 \
Magento\Paypal\Model\Payflow\RequestFactory $requestFactory,
162 \
Magento\Sales\Model\OrderFactory $orderFactory,
170 $this->_requestFactory = $requestFactory;
172 $this->_orderFactory = $orderFactory;
173 $this->_requestHttp = $requestHttp;
174 $this->_websiteFactory = $websiteFactory;
180 $customAttributeFactory,
194 $this->mathRandom = $mathRandom;
227 return (
bool)(int)$this->getConfigData(
'active',
$storeId);
237 public function initialize($paymentAction, $stateObject)
239 switch ($paymentAction) {
240 case \Magento\Paypal\Model\Config::PAYMENT_ACTION_AUTH:
241 case \Magento\Paypal\Model\Config::PAYMENT_ACTION_SALE:
242 $payment = $this->getInfoInstance();
245 $order->setCanSendNewEmailFlag(
false);
249 $this->setStore(
$order->getStoreId());
255 $order->setCanSendNewEmailFlag(
false);
258 $stateObject->setStatus(
'pending_payment');
259 $stateObject->setIsNotified(
false);
273 if (!$this->_response) {
274 $this->_response = $this->_requestFactory->create();
289 $debugData = [
'response' => $responseData];
290 $this->_debug($debugData);
315 $canSendNewOrderEmail =
true;
316 if (
$response->getResult() == self::RESPONSE_CODE_FRAUDSERVICE_FILTER ||
319 $canSendNewOrderEmail =
false;
321 $payment->setIsTransactionPending(
true)
322 ->setIsFraudDetected(
true);
324 $fraudMessage =
$response->getData(
'respmsg');
325 if (
$response->getData(
'fps_prexmldata')) {
326 $xml = new \SimpleXMLElement(
$response->getData(
'fps_prexmldata'));
327 $fraudMessage = (string)$xml->rule->triggeredMessage;
335 if (
$response->getData(
'avsdata') && strstr(substr(
$response->getData(
'avsdata'), 0, 2),
'N')) {
345 $payment->registerAuthorizationNotification(
$payment->getBaseAmountAuthorized());
356 if ($canSendNewOrderEmail) {
357 $this->orderSender->send(
$order);
359 $quote = $this->quoteRepository->get(
$order->getQuoteId())->setIsActive(
false);
360 $this->quoteRepository->save(
$quote);
362 throw new \Magento\Framework\Exception\LocalizedException(
__(
'We cannot send the new order email.'));
377 $order = $this->_orderFactory->create()->loadByIncrementId(
$response->getInvnum());
381 ) !=
$response->getData(
'user2') || $this->_code !=
$order->getPayment()->getMethodInstance()->getCode()
386 if (
$response->getResult() != self::RESPONSE_CODE_FRAUDSERVICE_FILTER &&
387 $response->getResult() != self::RESPONSE_CODE_DECLINED_BY_FILTER &&
393 throw new \Magento\Framework\Exception\LocalizedException(
__(
$response->getRespmsg()));
396 $amountCompared =
$response->getAmt() ==
$order->getPayment()->getBaseAmountAuthorized() ? true :
false;
401 throw new \Magento\Framework\Exception\LocalizedException(
402 __(
'Payment error. %value was not found.', [
'value' =>
'Order'])
407 if (!isset($fetchData[
'custref']) || $fetchData[
'custref'] !=
$order->getIncrementId()) {
408 throw new \Magento\Framework\Exception\LocalizedException(
409 __(
'Payment error. %value was not found.', [
'value' =>
'Transaction'])
424 $request = $this->buildBasicRequest();
426 ->setSecuretokenid($this->mathRandom->getUniqueHash())
429 $order = $payment->getOrder();
431 ->setCurrency(
$order->getBaseCurrencyCode());
454 return $this->storeManager->getStore($this->getStore())->getId();
462 public function buildBasicRequest()
465 $request = $this->_requestFactory->create();
466 $cscEditable = $this->getConfigData(
'csc_editable');
468 $data = parent::buildBasicRequest();
473 $this->_getCallbackUrl(
'cancelPayment')
475 $this->_getCallbackUrl(
'returnUrl')
479 $this->_getCallbackUrl(
'silentPost')
481 $this->_getCallbackUrl(
'returnUrl')
483 self::LAYOUT_TEMPLATE
484 )->setDisablereceipt(
487 $cscEditable && $this->getConfigData(
'csc_required') ?
'TRUE' :
'FALSE' 489 $cscEditable ?
'TRUE' :
'FALSE' 491 $this->getConfigData(
'email_confirmation') ?
'TRUE' :
'FALSE' 493 $this->getConfigData(
'url_method')
505 switch ($this->getConfigData(
'payment_action')) {
506 case \Magento\Paypal\Model\Config::PAYMENT_ACTION_AUTH:
508 case \Magento\Paypal\Model\Config::PAYMENT_ACTION_SALE:
527 $response->getResult() != self::RESPONSE_CODE_APPROVED &&
530 throw new \Magento\Framework\Exception\LocalizedException(
__(
$response->getRespmsg()));
535 )->setAdditionalInformation(
550 return $payment->getAdditionalInformation($this->_secureSilentPostHashKey);
561 $secureHash = md5($this->mathRandom->getRandomString(10));
562 $payment->setAdditionalInformation($this->_secureSilentPostHashKey, $secureHash);
572 protected function _getCallbackUrl($actionName)
574 if ($this->_requestHttp->getParam(
'website')) {
576 $website = $this->_websiteFactory->create()->load($this->_requestHttp->getParam(
'website'));
577 $secure = $this->_scopeConfig->isSetFlag(
585 $websiteUrl = $this->_scopeConfig->getValue(
591 $secure = $this->_scopeConfig->isSetFlag(
595 $websiteUrl = $this->storeManager->getStore()->getBaseUrl(
601 return $websiteUrl .
'paypal/' . $this->_callbackController .
'/' . $actionName;
fetchTransactionInfo(InfoInterface $payment, $transactionId)
$_secureSilentPostHashKey
mapGatewayResponse(array $postData, DataObject $response)
_processOrder(\Magento\Sales\Model\Order $order)
isAvailable(\Magento\Quote\Api\Data\CartInterface $quote=null)
fillCustomerContacts(DataObject $order, DataObject $request)
_getSecureSilentPostHash($payment)
const XML_PATH_SECURE_BASE_LINK_URL
addRequestOrderInfo(DataObject $request, Order $order)
const STATE_PENDING_PAYMENT
const XML_PATH_UNSECURE_BASE_LINK_URL
const XML_PATH_SECURE_IN_FRONTEND
_buildTokenRequest(\Magento\Sales\Model\Order\Payment $payment)
isAvailable(\Magento\Quote\Api\Data\CartInterface $quote=null)
postRequest(DataObject $request, ConfigInterface $config)
const RESPONSE_CODE_DECLINED_BY_FILTER
const RESPONSE_CODE_APPROVED
const TRANSACTION_PAYFLOW_URL
const RESPONSE_CODE_FRAUDSERVICE_FILTER
_processTokenErrors($response, $payment)
_generateSecureSilentPostHash($payment)
__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, \Magento\Framework\Module\ModuleListInterface $moduleList, \Magento\Framework\Stdlib\DateTime\TimezoneInterface $localeDate, \Magento\Store\Model\StoreManagerInterface $storeManager, ConfigInterfaceFactory $configFactory, \Magento\Paypal\Model\Payflow\Service\Gateway $gateway, HandlerInterface $errorHandler, \Magento\Framework\Math\Random $mathRandom, \Magento\Paypal\Model\Payflow\RequestFactory $requestFactory, \Magento\Quote\Api\CartRepositoryInterface $quoteRepository, \Magento\Sales\Model\OrderFactory $orderFactory, \Magento\Framework\App\RequestInterface $requestHttp, \Magento\Store\Model\WebsiteFactory $websiteFactory, OrderSender $orderSender, \Magento\Framework\Model\ResourceModel\AbstractResource $resource=null, \Magento\Framework\Data\Collection\AbstractDb $resourceCollection=null, array $data=[])
const PAYPAL_FRAUD_FILTERS