60 \
Magento\Framework\HTTP\Adapter\CurlFactory $curlFactory,
61 \
Magento\Sales\Model\OrderFactory $orderFactory,
68 $this->_orderFactory = $orderFactory;
69 $this->_paypalInfo = $paypalInfo;
107 $this->_config = $this->_configFactory->create($parameters);
108 if (!$this->_config->isMethodActive(
$methodCode) || !$this->_config->isMethodAvailable()) {
114 $merchantEmail = $this->_config->getValue(
'businessAccount');
115 if (!$merchantEmail) {
119 if (strtolower($merchantEmail) != strtolower($receiver)) {
122 'The requested "%s" and the configured "%s" merchant emails don\'t match.',
141 $this->_order = $this->_orderFactory->create()->loadByIncrementId($incrementId);
142 if (!$this->_order->getId()) {
143 throw new Exception(sprintf(
'The "%s" order ID is incorrect. Verify the ID and try again.', $incrementId));
162 switch ($transactionType) {
190 $reasonComment = $this->_paypalInfo->explainReasonCode($this->
getRequestData(
'reason_code'));
192 $caseTypeLabel = $this->_paypalInfo->getCaseTypeLabel($caseType);
196 'IPN "%1". Case type "%2". Case ID "%3" %4',
202 $this->_order->addStatusHistoryComment(
$message)->setIsCustomerNotified(
false)->save();
213 $reasonComment = $this->_paypalInfo->explainReasonCode($reasonCode);
214 $notificationAmount = $this->_order->getBaseCurrency()->formatTxt($this->
getRequestData(
'mc_gross'));
217 'IPN "%1". A dispute has been resolved and closed. %2 Transaction amount %3.',
218 ucfirst($reasonCode),
222 $this->_order->addStatusHistoryComment(
$message)->setIsCustomerNotified(
false)->save();
237 switch ($paymentStatus) {
273 throw new Exception(
"The '{$paymentStatus}' payment status couldn't be handled.");
290 $payment = $this->_order->getPayment();
294 $payment->setParentTransactionId($parentTransactionId);
296 $payment->setIsTransactionClosed(0);
297 $payment->registerCaptureNotification(
299 $skipFraudDetection && $parentTransactionId
301 $this->_order->save();
305 if (
$invoice && !$this->_order->getEmailSent()) {
306 $this->orderSender->send($this->_order);
307 $this->_order->addStatusHistoryComment(
308 __(
'You notified customer about invoice #%1.',
$invoice->getIncrementId())
310 ->setIsCustomerNotified(
true)
325 $this->_order->getPayment()
327 ->setNotificationResult(
true)
328 ->setIsTransactionClosed(
true)
330 $this->_order->save();
332 if ($e->getMessage() !=
__(
'We cannot cancel this order.')) {
358 if (
'authorization' === $reason) {
359 $this->_registerPaymentAuthorization();
362 if (
'order' === $reason) {
363 throw new Exception(
'The "order" authorizations aren\'t implemented.');
375 $this->_order->getPayment()
376 ->setPreparedMessage($this->
_createIpnComment($this->_paypalInfo->explainPendingReason($reason)))
378 ->setIsTransactionClosed(0)
380 $this->_order->save();
388 protected function _registerPaymentAuthorization()
391 $payment = $this->_order->getPayment();
392 if ($this->_order->canFetchPaymentReviewUpdate()) {
400 ->setIsTransactionClosed(0)
401 ->registerAuthorizationNotification($this->
getRequestData(
'mc_gross'));
403 if (!$this->_order->getEmailSent()) {
404 $this->orderSender->send($this->_order);
406 $this->_order->save();
428 $reasonComment = $this->_paypalInfo->explainReasonCode($reasonCode);
429 $notificationAmount = $this->_order->getBaseCurrency()
438 'IPN "%1". %2 Transaction amount %3. Transaction ID: "%4"',
446 ->setIsCustomerNotified(
false)
459 $isRefundFinal = !$this->_paypalInfo->isReversalDisputable($reason);
460 $payment = $this->_order->getPayment()
461 ->setPreparedMessage($this->
_createIpnComment($this->_paypalInfo->explainReasonCode($reason)))
464 ->setIsTransactionClosed($isRefundFinal)
465 ->registerRefundNotification(-1 * $this->
getRequestData(
'mc_gross'));
466 $this->_order->save();
470 $creditMemo =
$payment->getCreatedCreditmemo();
472 $this->creditmemoSender->send($creditMemo);
473 $this->_order->addStatusHistoryComment(
474 __(
'You notified customer about creditmemo #%1.', $creditMemo->getIncrementId())
476 ->setIsCustomerNotified(
true)
490 $parentTxnId = $this->
getRequestData(
'transaction_entity') ==
'auth' 494 $this->_order->getPayment()
496 ->setParentTransactionId($parentTxnId)
497 ->registerVoidNotification();
499 $this->_order->save();
512 $payment = $this->_order->getPayment();
513 $was =
$payment->getAdditionalInformation();
525 ] as $privateKey => $publicKey) {
526 if (is_int($privateKey)) {
527 $privateKey = $publicKey;
531 $from[$publicKey] =
$value;
534 if (isset($from[
'payment_status'])) {
547 $this->_paypalInfo->importToPayment($from,
$payment);
555 $payment->setIsTransactionPending(
true);
561 $payment->setIsTransactionApproved(
true);
563 $payment->setIsTransactionDenied(
true);
566 return $was !=
$payment->getAdditionalInformation();
585 $message->setIsCustomerNotified(
null);
const PAYMENTSTATUS_COMPLETED
static isPaymentReviewRequired(\Magento\Payment\Model\InfoInterface $payment)
const PAYMENTSTATUS_PENDING
const ORDER_STATUS_REVERSED
elseif(isset( $params[ 'redirect_parent']))
_createIpnComment($comment='', $addToHistory=false)
const TXN_TYPE_ADJUSTMENT
const PAYMENTSTATUS_PROCESSED
const PAYMENTSTATUS_FAILED
__construct(\Magento\Paypal\Model\ConfigFactory $configFactory, \Psr\Log\LoggerInterface $logger, \Magento\Framework\HTTP\Adapter\CurlFactory $curlFactory, \Magento\Sales\Model\OrderFactory $orderFactory, Info $paypalInfo, OrderSender $orderSender, CreditmemoSender $creditmemoSender, array $data=[])
const ORDER_STATUS_CANCELED_REVERSAL
static isPaymentFailed(\Magento\Payment\Model\InfoInterface $payment)
const PAYMENTSTATUS_DENIED
_importPaymentInformation()
_registerPaymentCapture($skipFraudDetection=false)
_registerPaymentReversal()
getRequestData($key=null)
_filterPaymentStatus($ipnPaymentStatus)
const STATE_PENDING_PAYMENT
const PAYMENTSTATUS_UNREVERSED
_registerPaymentFailure()
static isPaymentSuccessful(\Magento\Payment\Model\InfoInterface $payment)
_registerPaymentPending()
const PAYMENTSTATUS_VOIDED
_registerMasspaymentsSuccess()
const PAYMENTSTATUS_REFUNDED
const PAYMENTSTATUS_REVERSED
const PAYMENTSTATUS_EXPIRED
_addDebugData($key, $value)