111 private $orderStateResolver;
116 private $creditmemoManager =
null;
141 \
Magento\Framework\Api\ExtensionAttributesFactory $extensionFactory,
155 CreditmemoManager $creditmemoManager =
null 162 $this->orderPaymentProcessor = $paymentProcessor;
226 $this->
setData(
'transaction_id', $transactionId);
238 return $this->
getData(
'transaction_id');
249 $this->
setData(
'is_transaction_closed', (
bool)$isClosed);
261 return $this->
getData(self::PARENT_TXN_ID);
272 return $this->
setData(self::PARENT_TXN_ID, $txnId);
287 if ($authTransaction && $authTransaction->getIsClosed()) {
288 $orderTransaction = $this->transactionRepository->getByTransactionType(
293 if (!$orderTransaction) {
335 $this->_eventManager->dispatch(
'sales_order_payment_place_start', [
'payment' => $this]);
344 $methodInstance->setStore(
$order->getStoreId());
347 $orderStatus = $methodInstance->getConfigData(
'order_status');
348 $isCustomerNotified =
$order->getCustomerNoteNotify();
351 $methodInstance->validate();
352 $action = $methodInstance->getConfigPaymentAction();
355 if ($methodInstance->isInitializeNeeded()) {
356 $stateObject = new \Magento\Framework\DataObject();
358 $methodInstance->initialize($methodInstance->getConfigData(
'payment_action'), $stateObject);
359 $orderState = $stateObject->getData(
'state') ?: $orderState;
361 $isCustomerNotified = $stateObject->hasData(
'is_notified')
362 ? $stateObject->getData(
'is_notified')
363 : $isCustomerNotified;
367 $orderState =
$order->getState() ?
$order->getState() : $orderState;
371 $order->setState($orderState)
375 $isCustomerNotified = $isCustomerNotified ?:
$order->getCustomerNoteNotify();
377 if (!array_key_exists(
$orderStatus,
$order->getConfig()->getStateStatuses($orderState))) {
383 $this->_eventManager->dispatch(
'sales_order_payment_place_end', [
'payment' => $this]);
401 $originalOrderState =
$order->getState();
402 $originalOrderStatus =
$order->getStatus();
406 $order->addStatusToHistory($originalOrderStatus,
$message, $isCustomerNotified);
409 case ($originalOrderState &&
$message):
410 case ($originalOrderState != $orderState):
412 $order->setState($orderState)
415 ->setIsCustomerNotified($isCustomerNotified);
431 $totalDue =
$order->getTotalDue();
432 $baseTotalDue =
$order->getBaseTotalDue();
435 case \Magento\Payment\Model\Method\AbstractMethod::ACTION_ORDER:
436 $this->
_order($baseTotalDue);
438 case \Magento\Payment\Model\Method\AbstractMethod::ACTION_AUTHORIZE:
443 case \Magento\Payment\Model\Method\AbstractMethod::ACTION_AUTHORIZE_CAPTURE:
465 return $this->orderPaymentProcessor->capture($this,
$invoice);
481 return $this->orderPaymentProcessor->registerCaptureNotification($this,
$amount, $skipFraudDetection);
504 $totals = $this->collectTotalAmounts(
506 [
'grand_total',
'base_grand_total',
'shipping_amount',
'base_shipping_amount']
512 $this->_eventManager->dispatch(
'sales_order_payment_pay', [
'payment' => $this,
'invoice' =>
$invoice]);
527 'amount_paid' => -1 *
$invoice->getGrandTotal(),
528 'base_amount_paid' => -1 *
$invoice->getBaseGrandTotal(),
529 'shipping_captured' => -1 *
$invoice->getShippingAmount(),
530 'base_shipping_captured' => -1 *
$invoice->getBaseShippingAmount(),
533 $this->_eventManager->dispatch(
534 'sales_order_payment_cancel_invoice',
535 [
'payment' => $this,
'invoice' =>
$invoice]
567 if (
null === $this->_canVoidLookup) {
569 if ($this->_canVoidLookup) {
571 $this->_canVoidLookup = (bool)$authTransaction && !(
int)$authTransaction->getIsClosed();
588 $this->_eventManager->dispatch(
'sales_order_payment_void', [
'payment' => $this,
'invoice' => $document]);
602 if (!$this->hasMessage()) {
603 $this->setMessage(
__(
'Registered a Void notification.'));
617 $this->
setData(
'creditmemo', $creditmemo);
656 if ($gateway->canRefund()) {
662 $captureTxn = $this->transactionRepository->getByTransactionId(
668 $this->setTransactionIdsForRefund($captureTxn);
676 $this->setRefundTransactionId(
$invoice->getTransactionId());
677 $gateway->refund($this, $baseAmountToRefund);
682 throw new \Magento\Framework\Exception\LocalizedException(
683 __(
'If the invoice was created offline, try creating an offline credit memo.'),
690 }
elseif ($gateway->isOffline()) {
694 $gateway->refund($this, $baseAmountToRefund);
702 'base_amount_refunded' => $baseAmountToRefund,
703 'base_amount_refunded_online' => $isOnline ? $baseAmountToRefund :
null,
704 'shipping_refunded' =>
$creditmemo->getShippingAmount(),
705 'base_shipping_refunded' =>
$creditmemo->getBaseShippingAmount(),
718 $message = $this->hasMessage() ? $this->getMessage() :
__(
719 'We refunded %1 offline.',
725 $orderState = $this->getOrderStateResolver()->getStateForOrder($this->
getOrder());
727 ->addStatusHistoryComment(
730 )->setIsCustomerNotified(
$creditmemo->getOrder()->getCustomerNoteNotify());
731 $this->_eventManager->dispatch(
732 'sales_order_payment_refund',
756 $this->transactionManager->generateTransactionId(
759 $this->transactionRepository->getByTransactionId(
760 $this->getParentTransactionId(),
774 $baseGrandTotal = $salesEntity->getBaseGrandTotal();
775 $amountRefundLeft = $baseGrandTotal - $salesEntity->getBaseTotalRefunded();
777 if ($amountRefundLeft <
$amount) {
781 if (
$amount != $baseGrandTotal) {
782 $order->addStatusHistoryComment(
784 'IPN "Refunded". Refund issued by merchant. ' 785 .
'Registered notification about refunded amount of %1. Transaction ID: "%2". ' 786 .
'Credit Memo has not been created. Please create offline Credit Memo.',
799 )->setAutomaticallyCreated(
802 __(
'The credit memo has been created automatically.')
805 $this->creditmemoManager->refund(
$creditmemo,
false);
808 [
'amount_refunded' =>
$creditmemo->getGrandTotal(),
'base_amount_refunded_online' =>
$amount]
836 'amount_refunded' => -1 *
$creditmemo->getGrandTotal(),
837 'base_amount_refunded' => -1 *
$creditmemo->getBaseGrandTotal(),
838 'shipping_refunded' => -1 *
$creditmemo->getShippingAmount(),
839 'base_shipping_refunded' => -1 *
$creditmemo->getBaseShippingAmount(),
842 $this->_eventManager->dispatch(
843 'sales_order_payment_cancel_creditmemo',
863 if (!$this->hasMessage()) {
864 $this->setMessage($isOnline ?
__(
'Canceled order online') :
__(
'Canceled order offline'));
868 $this->
_void($isOnline,
null,
'cancel');
871 $this->_eventManager->dispatch(
'sales_order_payment_cancel', [
'payment' => $this]);
899 public function accept()
906 if (
$method->acceptPayment($this)) {
932 public function deny($isOnline =
true)
943 $result = (bool)$this->getNotificationResult();
955 'There is no need to deny this payment.' :
'Registered notification about denied payment.';
981 $method->fetchTransactionInfo($this, $transactionId);
984 if ($this->getIsTransactionApproved()) {
991 }
elseif ($this->getIsTransactionDenied()) {
1017 $totals = $this->collectTotalAmounts($this->
getOrder(), [
'base_grand_total']);
1032 ->addStatusHistoryComment(
$message);
1060 ->addStatusHistoryComment(
$message);
1064 if ($transactionId) {
1091 return $this->orderPaymentProcessor->order($this,
$amount);
1107 return $this->orderPaymentProcessor->authorize($this, $isOnline,
$amount);
1123 protected function _void($isOnline,
$amount =
null, $gatewayCallback =
'void')
1136 $method->{$gatewayCallback}($this);
1144 if ($authTransaction &&
1148 if ($authTransaction->canVoidAuthorizationCompletely()) {
1159 $message = $this->hasMessage() ? $this->getMessage() :
__(
'Voided authorization.');
1166 $order->setDataChanges(
true);
1181 $builder = $this->transactionBuilder->setPayment($this)
1182 ->setOrder($this->getOrder())
1183 ->setFailSafe($failSafe)
1184 ->setTransactionId($this->getTransactionId())
1185 ->setAdditionalInformation($this->transactionAdditionalInfo);
1186 if ($salesDocument) {
1187 $builder->setSalesDocument($salesDocument);
1190 return $builder->build(
$type);
1197 $order = $this->getOrder();
1210 $method = $this->getMethodInstance();
1256 $message .=
' ' .
__(
'Transaction ID: "%1"', $txnId);
1271 $preparedMessage = $this->getPreparedMessage();
1272 if ($preparedMessage) {
1273 if (is_string($preparedMessage)
1274 || $preparedMessage instanceof \
Magento\Framework\Phrase
1276 return $preparedMessage .
' ' . $messagePrependTo;
1277 }
elseif (is_object($preparedMessage)
1280 $comment = $preparedMessage->getComment() .
' ' . $messagePrependTo;
1281 $preparedMessage->setComment($comment);
1287 return $messagePrependTo;
1311 return $this->getOrder()->getBaseCurrency()->formatTxt(
$amount);
1320 return $this->transactionManager->getAuthorizationTransaction(
1321 $this->getParentTransactionId(),
1323 $this->getOrder()->
getId()
1335 $total = $this->getOrder()->getBaseTotalDue();
1337 return $this->formatAmount($total,
true) == $this->formatAmount($amountToCapture,
true);
1347 return !$this->getCurrencyCode() || $this->getCurrencyCode() == $this->getOrder()->getBaseCurrencyCode();
1359 $this->transactionAdditionalInfo[$key] =
$value;
1369 return $this->transactionAdditionalInfo;
1379 $this->transactionAdditionalInfo = [];
1395 if (
$entity->getBaseTotalRefunded() > 0) {
1396 $adjustment = [
'adjustment_positive' =>
$amount];
1398 $adjustment = [
'adjustment_negative' => $baseGrandTotal -
$amount];
1401 $creditMemo = $this->creditmemoFactory->createByInvoice(
$invoice, $adjustment);
1403 $creditMemo = $this->creditmemoFactory->createByOrder($this->getOrder(), $adjustment);
1406 $totalRefunded =
$entity->getBaseTotalRefunded() + $creditMemo->getBaseGrandTotal();
1407 $this->setShouldCloseParentTransaction(
$entity->getBaseGrandTotal() <= $totalRefunded);
1420 return $this->transactionManager->isTransactionExists(
1421 $this->getTransactionId(),
1423 $this->getOrder()->
getId()
1436 if (
$invoice->getTransactionId() == $transactionId) {
1443 foreach ($this->getOrder()->getInvoiceCollection() as
$invoice) {
1444 if (
$invoice->getState() == \Magento\Sales\Model\Order\Invoice::STATE_OPEN
1447 $invoice->setTransactionId($transactionId);
1460 private function getOrderStateResolver()
1462 if ($this->orderStateResolver ===
null) {
1466 return $this->orderStateResolver;
2442 $this->
setData(
'is_transaction_pending', (
bool)$flag);
2455 return (
bool)$this->
getData(
'is_transaction_pending');
2466 $this->
setData(
'is_fraud_detected', (
bool)$flag);
2479 return (
bool)$this->
getData(
'is_fraud_detected');
2490 $this->
setData(
'should_close_parent_transaction', (
bool)$flag);
2503 return (
bool)$this->
getData(
'should_close_parent_transaction');
2513 if (!$this->getTransactionId()) {
2514 $this->setTransactionId(
2515 $this->transactionManager->generateTransactionId(
2522 $this->setParentTransactionId(
$transaction->getTxnId());
2535 private function collectTotalAmounts(Order
$order, array $keys)
2537 $result = array_fill_keys($keys, 0.00);
2538 $invoiceCollection =
$order->getInvoiceCollection();
2540 foreach ($invoiceCollection as
$invoice) {
2541 foreach ($keys as $key) {
getBaseAmountAuthorized()
setAmountRefunded($amountRefunded)
const BASE_AMOUNT_REFUNDED_ONLINE
setAnetTransMethod($anetTransMethod)
const REVIEW_ACTION_UPDATE
addTransactionCommentsToOrder($transaction, $message)
setCcAvsStatus($ccAvsStatus)
setProtectionEligibility($protectionEligibility)
getData($key='', $index=null)
const BASE_SHIPPING_REFUNDED
__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\Encryption\EncryptorInterface $encryptor, \Magento\Sales\Model\Order\CreditmemoFactory $creditmemoFactory, PriceCurrencyInterface $priceCurrency, \Magento\Sales\Api\TransactionRepositoryInterface $transactionRepository, ManagerInterface $transactionManager, \Magento\Sales\Model\Order\Payment\Transaction\BuilderInterface $transactionBuilder, \Magento\Sales\Model\Order\Payment\Processor $paymentProcessor, OrderRepositoryInterface $orderRepository, \Magento\Framework\Model\ResourceModel\AbstractResource $resource=null, \Magento\Framework\Data\Collection\AbstractDb $resourceCollection=null, array $data=[], CreditmemoManager $creditmemoManager=null)
setBaseAmountAuthorized($baseAmountAuthorized)
setBaseAmountPaidOnline($baseAmountPaidOnline)
const CC_DEBUG_REQUEST_BODY
_getExtensionAttributes()
cancelCreditmemo($creditmemo)
elseif(isset( $params[ 'redirect_parent']))
const PROTECTION_ELIGIBILITY
setAmountPaid($amountPaid)
prependMessage($messagePrependTo)
getDataUsingMethod($key, $args=null)
setShippingAmount($amount)
const BASE_SHIPPING_AMOUNT
registerVoidNotification($amount=null)
setCcApproval($ccApproval)
setEcheckAccountName($echeckAccountName)
resetTransactionAdditionalInfo()
setEcheckRoutingNumber($echeckRoutingNumber)
void(\Magento\Framework\DataObject $document)
addTransaction($type, $salesDocument=null, $failSafe=false)
const CC_DEBUG_RESPONSE_SERIALIZED
getBaseAmountRefundedOnline()
_setExtensionAttributes(\Magento\Framework\Api\ExtensionAttributesInterface $extensionAttributes)
setCcStatusDescription($description)
getProtectionEligibility()
setParentTransactionId($txnId)
setAdditionalData($additionalData)
setAmountCanceled($amountCanceled)
const BASE_AMOUNT_CANCELED
setShippingCaptured($shippingCaptured)
setBaseShippingCaptured($baseShippingCaptured)
authorize($isOnline, $amount)
updateBaseAmountPaidOnlineTotal($invoice)
setShouldCloseParentTransaction($flag)
registerCaptureNotification($amount, $skipFraudDetection=false)
setAdditionalInformation($key, $value)
getBaseShippingRefunded()
isCaptureFinal($amountToCapture)
setCcSsStartYear($ccSsStartYear)
setCcNumberEnc($ccNumberEnc)
setIsFraudDetected($flag)
const BASE_AMOUNT_PAID_ONLINE
const BASE_SHIPPING_CAPTURED
getTransactionAdditionalInfo()
registerRefundNotification($amount)
setShippingRefunded($shippingRefunded)
const CC_DEBUG_RESPONSE_BODY
setCcDebugResponseSerialized($ccDebugResponseSerialized)
updateOrder(Order $order, $orderState, $orderStatus, $isCustomerNotified)
getIsTransactionPending()
prepareCreditMemo($amount, $baseGrandTotal, $invoice)
getShouldCloseParentTransaction()
checkIfTransactionExists()
setOrderStatePaymentReview($message, $transactionId)
const BASE_AMOUNT_ORDERED
setCcSsStartMonth($ccSsStartMonth)
setEcheckType($echeckType)
setAddressStatus($addressStatus)
$transactionAdditionalInfo
const ECHECK_ROUTING_NUMBER
_appendTransactionToMessage($transaction, $message)
setCcCidStatus($ccCidStatus)
const REVIEW_ACTION_ACCEPT
setCcDebugRequestBody($ccDebugRequestBody)
getBaseShippingCaptured()
const ECHECK_ACCOUNT_NAME
setBaseShippingAmount($amount)
setCreditmemo(Creditmemo $creditmemo)
const CC_STATUS_DESCRIPTION
registerAuthorizationNotification($amount)
setTransactionId($transactionId)
const BASE_AMOUNT_AUTHORIZED
setIsTransactionClosed($isClosed)
canFetchTransactionInfo()
setData($key, $value=null)
getData($key='', $index=null)
setBaseShippingRefunded($baseShippingRefunded)
const ECHECK_ACCOUNT_TYPE
const STATE_PAYMENT_REVIEW
processAction($action, Order $order)
setIsTransactionPending($flag)
setTransactionAdditionalInfo($key, $value)
setCcSecureVerify($ccSecureVerify)
setBaseAmountPaid($baseAmountPaid)
setOrderStateProcessing($message)
getAuthorizationTransaction()
cancelInvoiceAndRegisterCancellation($invoice, $message)
getBaseAmountPaidOnline()
const BASE_AMOUNT_REFUNDED
getCcDebugResponseSerialized()
setAmountOrdered($amountOrdered)
setCcDebugResponseBody($ccDebugResponseBody)
setBaseAmountRefundedOnline($baseAmountRefundedOnline)
setBaseAmountOrdered($baseAmountOrdered)
setDataUsingMethod($key, $args=[])
setAmountAuthorized($amountAuthorized)
formatAmount($amount, $asFloat=false)
setCcExpMonth($ccExpMonth)
canRefundPartialPerInvoice()
setBaseAmountCanceled($baseAmountCanceled)
setEcheckBankName($echeckBankName)
importTransactionInfo(Transaction $transactionTo)
setAccountStatus($accountStatus)
_void($isOnline, $amount=null, $gatewayCallback='void')
setEcheckAccountType($echeckAccountType)
setExtensionAttributes(\Magento\Sales\Api\Data\OrderPaymentExtensionInterface $extensionAttributes)
_getInvoiceForTransactionId($transactionId)
setBaseAmountRefunded($baseAmountRefunded)