예제 #1
0
 /**
  * @param int $configValue
  * @param bool|null $forceSyncMode
  * @param bool|null $emailSendingResult
  * @dataProvider sendDataProvider
  * @return void
  */
 public function testSend($configValue, $forceSyncMode, $emailSendingResult)
 {
     $address = 'address_test';
     $configPath = 'sales_email/general/async_sending';
     $this->orderMock->expects($this->once())->method('setSendEmail')->with(true);
     $this->globalConfig->expects($this->once())->method('getValue')->with($configPath)->willReturn($configValue);
     if (!$configValue || $forceSyncMode) {
         $this->identityContainerMock->expects($this->once())->method('isEnabled')->willReturn($emailSendingResult);
         if ($emailSendingResult) {
             $addressMock = $this->getMock('Magento\\Sales\\Model\\Order\\Address', [], [], '', false);
             $this->addressRenderer->expects($this->any())->method('format')->with($addressMock, 'html')->willReturn($address);
             $this->orderMock->expects($this->any())->method('getBillingAddress')->willReturn($addressMock);
             $this->orderMock->expects($this->any())->method('getShippingAddress')->willReturn($addressMock);
             $this->templateContainerMock->expects($this->once())->method('setTemplateVars')->with(['order' => $this->orderMock, 'billing' => $addressMock, 'payment_html' => 'payment', 'store' => $this->storeMock, 'formattedShippingAddress' => $address, 'formattedBillingAddress' => $address]);
             $this->senderBuilderFactoryMock->expects($this->once())->method('create')->willReturn($this->senderMock);
             $this->senderMock->expects($this->once())->method('send');
             $this->senderMock->expects($this->once())->method('sendCopyTo');
             $this->orderMock->expects($this->once())->method('setEmailSent')->with(true);
             $this->orderResourceMock->expects($this->once())->method('saveAttribute')->with($this->orderMock, ['send_email', 'email_sent']);
             $this->assertTrue($this->sender->send($this->orderMock));
         } else {
             $this->orderResourceMock->expects($this->once())->method('saveAttribute')->with($this->orderMock, 'send_email');
             $this->assertFalse($this->sender->send($this->orderMock));
         }
     } else {
         $this->orderResourceMock->expects($this->once())->method('saveAttribute')->with($this->orderMock, 'send_email');
         $this->assertFalse($this->sender->send($this->orderMock));
     }
 }
예제 #2
0
 public function testSendFailure()
 {
     $this->orderSenderMock->expects($this->once())->method('send')->willThrowException(new \Magento\Framework\Exception\MailException(__('test message')));
     $this->messageManagerMock->expects($this->once())->method('addWarning');
     $this->loggerMock->expects($this->once())->method('critical');
     $this->assertFalse($this->emailSender->send($this->orderMock));
 }
 public function testSendEmailWhenRedirectUrlExists()
 {
     $this->paymentMock->expects($this->once())->method('getOrderPlaceRedirectUrl')->willReturn(false);
     $this->orderMock->expects($this->once())->method('getCanSendNewEmailFlag');
     $this->orderSenderMock->expects($this->never())->method('send');
     $this->loggerMock->expects($this->never())->method('critical');
     $this->model->execute($this->observerMock);
 }
예제 #4
0
 /**
  * Send email about new order.
  * Process mail exception
  *
  * @param Order $order
  * @return bool
  */
 public function send(Order $order)
 {
     try {
         $this->orderSender->send($order);
     } catch (\Magento\Framework\Mail\Exception $exception) {
         $this->logger->logException($exception);
         $this->messageManager->addWarning(__('You did not email your customer. Please check your email settings.'));
         return false;
     }
     return true;
 }
예제 #5
0
 /**
  * Create orders per each quote address
  *
  * @return \Magento\Multishipping\Model\Checkout\Type\Multishipping
  * @throws \Exception
  */
 public function createOrders()
 {
     $orderIds = [];
     $this->_validate();
     $shippingAddresses = $this->getQuote()->getAllShippingAddresses();
     $orders = [];
     if ($this->getQuote()->hasVirtualItems()) {
         $shippingAddresses[] = $this->getQuote()->getBillingAddress();
     }
     try {
         foreach ($shippingAddresses as $address) {
             $order = $this->_prepareOrder($address);
             $orders[] = $order;
             $this->_eventManager->dispatch('checkout_type_multishipping_create_orders_single', ['order' => $order, 'address' => $address, 'quote' => $this->getQuote()]);
         }
         foreach ($orders as $order) {
             $order->place();
             $order->save();
             if ($order->getCanSendNewEmailFlag()) {
                 $this->orderSender->send($order);
             }
             $orderIds[$order->getId()] = $order->getIncrementId();
         }
         $this->_session->setOrderIds($orderIds);
         $this->_checkoutSession->setLastQuoteId($this->getQuote()->getId());
         $this->getQuote()->setIsActive(false);
         $this->quoteRepository->save($this->getQuote());
         $this->_eventManager->dispatch('checkout_submit_all_after', ['orders' => $orders, 'quote' => $this->getQuote()]);
         return $this;
     } catch (\Exception $e) {
         $this->_eventManager->dispatch('checkout_multishipping_refund_all', ['orders' => $orders]);
         throw $e;
     }
 }
예제 #6
0
 public function execute()
 {
     $skipFraudDetection = false;
     \Paynl\Config::setApiToken($this->_config->getApiToken());
     $params = $this->getRequest()->getParams();
     if (!isset($params['order_id'])) {
         $this->_logger->critical('Exchange: order_id is not set in the request', $params);
         die('FALSE| order_id is not set in the request');
     }
     try {
         $transaction = \Paynl\Transaction::get($params['order_id']);
     } catch (\Exception $e) {
         $this->_logger->critical($e, $params);
         die('FALSE| Error fetching transaction. ' . $e->getMessage());
     }
     if ($transaction->isPending()) {
         die("TRUE| Ignoring pending");
     }
     $orderId = $transaction->getDescription();
     $order = $this->_orderFactory->create()->loadByIncrementId($orderId);
     if (empty($order)) {
         $this->_logger->critical('Cannot load order: ' . $orderId);
         die('FALSE| Cannot load order');
     }
     if ($order->getTotalDue() <= 0) {
         $this->_logger->debug('Total due <= 0, so iam not touching the status of the order: ' . $orderId);
         die('TRUE| Total due <= 0, so iam not touching the status of the order');
     }
     if ($transaction->isPaid()) {
         $payment = $order->getPayment();
         $payment->setTransactionId($transaction->getId());
         $payment->setCurrencyCode($transaction->getPaidCurrency());
         $payment->setIsTransactionClosed(0);
         $payment->registerCaptureNotification($transaction->getPaidCurrencyAmount(), $skipFraudDetection);
         $order->save();
         // notify customer
         $invoice = $payment->getCreatedInvoice();
         if ($invoice && !$order->getEmailSent()) {
             $this->_orderSender->send($order);
             $order->addStatusHistoryComment(__('You notified customer about invoice #%1.', $invoice->getIncrementId()))->setIsCustomerNotified(true)->save();
         }
         die("TRUE| PAID");
     } elseif ($transaction->isCanceled()) {
         $order->cancel()->save();
         die("TRUE| CANCELED");
     }
 }
 /**
  * @param \Magento\Framework\Event\Observer $observer
  *
  * @return void
  */
 public function execute(\Magento\Framework\Event\Observer $observer)
 {
     /** @var  \Magento\Quote\Model\Quote $quote */
     $quote = $observer->getEvent()->getQuote();
     /** @var  \Magento\Sales\Model\Order $order */
     $order = $observer->getEvent()->getOrder();
     /**
      * a flag to set that there will be redirect to third party after confirmation
      */
     $redirectUrl = $quote->getPayment()->getOrderPlaceRedirectUrl();
     if (!$redirectUrl && $order->getCanSendNewEmailFlag()) {
         try {
             $this->orderSender->send($order);
         } catch (\Exception $e) {
             $this->logger->critical($e);
         }
     }
 }
예제 #8
0
 public function execute()
 {
     $skipFraudDetection = false;
     \Paynl\Config::setApiToken($this->_config->getApiToken());
     $transaction = \Paynl\Transaction::getForExchange();
     if ($transaction->isPending()) {
         die("TRUE| Ignoring pending");
     }
     $orderId = $transaction->getDescription();
     $order = $this->_orderFactory->create()->loadByIncrementId($orderId);
     if (empty($order)) {
         die('FALSE| Cannot load order');
     }
     if ($order->getTotalDue() <= 0) {
         die('TRUE| Total due <= 0, so iam not touching the status if the order');
     }
     if ($transaction->isPaid()) {
         if ($order->getOrderCurrencyCode() != 'EUR') {
             $skipFraudDetection = true;
         }
         $payment = $order->getPayment();
         $payment->setTransactionId($transaction->getId());
         $payment->setCurrencyCode($transaction->getPaidCurrency());
         $payment->setIsTransactionClosed(0);
         $payment->registerCaptureNotification($transaction->getPaidAmount(), $skipFraudDetection);
         $order->save();
         // notify customer
         $invoice = $payment->getCreatedInvoice();
         if ($invoice && !$order->getEmailSent()) {
             $this->_orderSender->send($order);
             $order->addStatusHistoryComment(__('You notified customer about invoice #%1.', $invoice->getIncrementId()))->setIsCustomerNotified(true)->save();
         }
         die("TRUE| PAID");
     } elseif ($transaction->isCanceled()) {
         $order->cancel()->save();
         die("TRUE| CANCELED");
     }
 }
예제 #9
0
파일: Ipn.php 프로젝트: nja78/magento2
 /**
  * Register authorized payment
  *
  * @return void
  */
 protected function _registerPaymentAuthorization()
 {
     /** @var $payment \Magento\Sales\Model\Order\Payment */
     $payment = $this->_order->getPayment();
     if ($this->_order->canFetchPaymentReviewUpdate()) {
         $payment->update(true);
     } else {
         $this->_importPaymentInformation();
         $payment->setPreparedMessage($this->_createIpnComment(''))->setTransactionId($this->getRequestData('txn_id'))->setParentTransactionId($this->getRequestData('parent_txn_id'))->setCurrencyCode($this->getRequestData('mc_currency'))->setIsTransactionClosed(0)->registerAuthorizationNotification($this->getRequestData('mc_gross'));
     }
     if (!$this->_order->getEmailSent()) {
         $this->orderSender->send($this->_order);
     }
     $this->_order->save();
 }
예제 #10
0
 public function testSendTrueForGuest()
 {
     $billingAddress = $this->getMock('\\Magento\\Sales\\Model\\Order\\Address', [], [], '', false);
     $billingAddress->expects($this->any())->method('getName')->will($this->returnValue('name'));
     $this->orderMock->expects($this->once())->method('getCustomerIsGuest')->will($this->returnValue(true));
     $this->orderMock->expects($this->any())->method('getBillingAddress')->will($this->returnValue($billingAddress));
     $paymentInfoMock = $this->getMock('\\Magento\\Payment\\Model\\Info', [], [], '', false);
     $this->orderMock->expects($this->once())->method('getPayment')->will($this->returnValue($paymentInfoMock));
     $this->identityContainerMock->expects($this->once())->method('isEnabled')->will($this->returnValue(true));
     $this->templateContainerMock->expects($this->once())->method('setTemplateVars')->with($this->equalTo(['order' => $this->orderMock, 'billing' => $billingAddress, 'payment_html' => 'payment', 'store' => $this->storeMock]));
     $senderMock = $this->getMock('Magento\\Sales\\Model\\Order\\Email\\Sender', ['send', 'sendCopyTo'], [], '', false);
     $senderMock->expects($this->once())->method('send');
     $senderMock->expects($this->once())->method('sendCopyTo');
     $this->senderBuilderFactoryMock->expects($this->once())->method('create')->will($this->returnValue($senderMock));
     $result = $this->sender->send($this->orderMock);
     $this->assertTrue($result);
 }
예제 #11
0
 /**
  * @param bool $isVirtualOrder
  * @param int $formatCallCount
  * @param string|null $expectedShippingAddress
  * @dataProvider sendVirtualOrderDataProvider
  */
 public function testSendVirtualOrder($isVirtualOrder, $formatCallCount, $expectedShippingAddress)
 {
     $address = 'address_test';
     $this->orderMock->setData(\Magento\Sales\Api\Data\OrderInterface::IS_VIRTUAL, $isVirtualOrder);
     $this->orderMock->expects($this->once())->method('setSendEmail')->with(true);
     $this->globalConfig->expects($this->once())->method('getValue')->with('sales_email/general/async_sending')->willReturn(false);
     $this->identityContainerMock->expects($this->once())->method('isEnabled')->willReturn(true);
     $addressMock = $this->getMock('Magento\\Sales\\Model\\Order\\Address', [], [], '', false);
     $this->addressRenderer->expects($this->exactly($formatCallCount))->method('format')->with($addressMock, 'html')->willReturn($address);
     $this->stepAddressFormat($addressMock, $isVirtualOrder);
     $this->templateContainerMock->expects($this->once())->method('setTemplateVars')->with(['order' => $this->orderMock, 'billing' => $addressMock, 'payment_html' => 'payment', 'store' => $this->storeMock, 'formattedShippingAddress' => $expectedShippingAddress, 'formattedBillingAddress' => $address]);
     $this->senderBuilderFactoryMock->expects($this->once())->method('create')->willReturn($this->senderMock);
     $this->senderMock->expects($this->once())->method('send');
     $this->senderMock->expects($this->once())->method('sendCopyTo');
     $this->orderMock->expects($this->once())->method('setEmailSent')->with(true);
     $this->orderResourceMock->expects($this->once())->method('saveAttribute')->with($this->orderMock, ['send_email', 'email_sent']);
     $this->assertTrue($this->sender->send($this->orderMock));
 }
예제 #12
0
 /**
  * Operate with order using information from Authorize.net.
  * Authorize order or authorize and capture it.
  *
  * @param \Magento\Sales\Model\Order $order
  * @return void
  * @throws \Magento\Framework\Model\Exception
  * @throws \Exception
  */
 protected function _authOrder(\Magento\Sales\Model\Order $order)
 {
     try {
         $this->checkResponseCode();
         $this->checkTransId();
     } catch (\Exception $e) {
         //decline the order (in case of wrong response code) but don't return money to customer.
         $message = $e->getMessage();
         $this->_declineOrder($order, $message, false);
         throw $e;
     }
     $response = $this->getResponse();
     //create transaction. need for void if amount will not match.
     $payment = $order->getPayment();
     $this->_fillPaymentByResponse($payment);
     $payment->addTransaction(\Magento\Sales\Model\Order\Payment\Transaction::TYPE_AUTH);
     // Set transaction approval message
     $message = __('Amount of %1 approved by payment gateway. Transaction ID: "%2".', $order->getBaseCurrency()->formatTxt($payment->getBaseAmountAuthorized()), $response->getXTransId());
     $orderState = \Magento\Sales\Model\Order::STATE_PROCESSING;
     $orderStatus = $this->getConfigData('order_status');
     if (!$orderStatus || $order->getIsVirtual()) {
         $orderStatus = $order->getConfig()->getStateDefaultStatus($orderState);
     }
     $order->setState($orderState, $orderStatus ? $orderStatus : true, $message, false)->save();
     //match amounts. should be equals for authorization.
     //decline the order if amount does not match.
     if (!$this->_matchAmount($payment->getBaseAmountAuthorized())) {
         $message = __('Something went wrong: the paid amount doesn\'t match the order amount. Please correct this and try again.');
         $this->_declineOrder($order, $message, true);
         throw new \Magento\Framework\Model\Exception($message);
     }
     //capture order using AIM if needed
     $this->_captureOrder($order);
     try {
         if (!$response->hasOrderSendConfirmation() || $response->getOrderSendConfirmation()) {
             $this->orderSender->send($order);
         }
         $this->_quoteFactory->create()->load($order->getQuoteId())->setIsActive(false)->save();
     } catch (\Exception $e) {
         // do not cancel order if we couldn't send email
     }
 }
예제 #13
0
파일: Ipn.php 프로젝트: aiesh/magento2
 /**
  * Process notification from recurring payments
  *
  * @return void
  * @throws \Magento\Framework\Model\Exception
  * @throws Exception
  */
 protected function _processRecurringPayment()
 {
     $this->_getConfig();
     try {
         // handle payment_status
         $paymentStatus = $this->_filterPaymentStatus($this->getRequestData('payment_status'));
         if ($paymentStatus != \Magento\Paypal\Model\Info::PAYMENTSTATUS_COMPLETED) {
             throw new Exception("Cannot handle payment status '{$paymentStatus}'.");
         }
         // Register recurring payment notification, create and process order
         $price = $this->getRequestData('mc_gross') - $this->getRequestData('tax') - $this->getRequestData('shipping');
         $productItemInfo = new \Magento\Framework\Object();
         $type = trim($this->getRequestData('period_type'));
         if ($type == 'Trial') {
             $productItemInfo->setPaymentType(\Magento\RecurringPayment\Model\PaymentTypeInterface::TRIAL);
         } elseif ($type == 'Regular') {
             $productItemInfo->setPaymentType(\Magento\RecurringPayment\Model\PaymentTypeInterface::REGULAR);
         }
         $productItemInfo->setTaxAmount($this->getRequestData('tax'));
         $productItemInfo->setShippingAmount($this->getRequestData('shipping'));
         $productItemInfo->setPrice($price);
         $order = $this->_recurringPayment->createOrder($productItemInfo);
         $payment = $order->getPayment()->setTransactionId($this->getRequestData('txn_id'))->setCurrencyCode($this->getRequestData('mc_currency'))->setPreparedMessage($this->_createIpnComment(''))->setIsTransactionClosed(0);
         $order->save();
         $this->_recurringPayment->addOrderRelation($order->getId());
         $payment->registerCaptureNotification($this->getRequestData('mc_gross'));
         $order->save();
         // notify customer
         $invoice = $payment->getCreatedInvoice();
         if ($invoice) {
             $message = __('You notified customer about invoice #%1.', $invoice->getIncrementId());
             $this->orderSender->send($order);
             $order->addStatusHistoryComment($message)->setIsCustomerNotified(true)->save();
         }
     } catch (\Magento\Framework\Model\Exception $e) {
         $comment = $this->_createIpnComment(__('Note: %1', $e->getMessage()), true);
         //TODO: add to payment comments
         //$comment->save();
         throw $e;
     }
 }
예제 #14
0
파일: Api.php 프로젝트: aiesh/magento2
 /**
  * Process exception action by Ogone exception url
  *
  * @return void
  */
 public function _exceptionProcess()
 {
     $params = $this->getRequest()->getParams();
     $order = $this->_getOrder();
     if (!$this->_isOrderValid($order)) {
         return;
     }
     switch ($params['STATUS']) {
         case \Magento\Ogone\Model\Api::OGONE_PAYMENT_UNCERTAIN_STATUS:
             $exception = __('Something went wrong during the payment process, and so the result is unpredictable.');
             break;
         case \Magento\Ogone\Model\Api::OGONE_AUTH_UKNKOWN_STATUS:
             $exception = __('Something went wrong during the authorization process, and so the result is unpredictable.');
             break;
         default:
             $exception = __('Unknown exception');
             break;
     }
     if (!empty($exception)) {
         try {
             $this->_getCheckout()->setLastSuccessQuoteId($order->getQuoteId());
             $this->_prepareCCInfo($order, $params);
             $order->getPayment()->setLastTransId($params['PAYID']);
             //to send new order email only when state is pending payment
             if ($order->getState() == \Magento\Sales\Model\Order::STATE_PENDING_PAYMENT) {
                 $this->orderSender->send($order);
                 $order->setState(\Magento\Sales\Model\Order::STATE_PROCESSING, \Magento\Ogone\Model\Api::PROCESSING_OGONE_STATUS, $exception);
             } else {
                 $order->addStatusToHistory(\Magento\Ogone\Model\Api::PROCESSING_OGONE_STATUS, $exception);
             }
             $order->save();
         } catch (\Exception $e) {
             $this->messageManager->addError(__('Something went wrong while saving this order.'));
         }
     } else {
         $this->messageManager->addError(__('Exception not defined'));
     }
     $this->_redirect('checkout/onepage/success');
 }
예제 #15
0
 /**
  *
  */
 protected function _authorizePayment()
 {
     $this->_debugData['_authorizePayment'] = 'Authorisation of the order';
     //        $this->_uncancelOrder($order); // not implemented in magento v2.0
     $fraudManualReviewStatus = $this->_getFraudManualReviewStatus();
     // If manual review is active and a seperate status is used then ignore the pre authorized status
     if ($this->_fraudManualReview != true || $fraudManualReviewStatus == "") {
         $this->_setPrePaymentAuthorized();
     } else {
         $this->_debugData['_authorizePayment info'] = 'Ignore the pre authorized status because the order is under manual review and use the Manual review status';
     }
     $this->_prepareInvoice();
     $_paymentCode = $this->_paymentMethodCode();
     // for boleto confirmation mail is send on order creation
     if ($this->_paymentMethod != "adyen_boleto") {
         // send order confirmation mail after invoice creation so merchant can add invoicePDF to this mail
         //            $this->_order->sendNewOrderEmail(); // send order email
         $this->_orderSender->send($this->_order);
     }
     if ($this->_paymentMethod == "c_cash" && $this->_getConfigData('create_shipment', 'adyen_cash', $this->_order->getStoreId()) || $this->_getConfigData('create_shipment', 'adyen_pos', $this->_order->getStoreId()) && $_paymentCode == "adyen_pos") {
         $this->_createShipment();
     }
 }
 protected function _createInvoice($params)
 {
     try {
         if ($this->_order->canInvoice()) {
             $payment = $this->_order->getPayment();
             $payment->setTransactionId($params['invoice_id']);
             $payment->setCurrencyCode($params['list_currency']);
             $payment->setParentTransactionId($params['sale_id']);
             $payment->setShouldCloseParentTransaction(true);
             $payment->setIsTransactionClosed(0);
             $payment->registerCaptureNotification($params['invoice_list_amount'], true);
             $this->_order->save();
             // notify customer
             $invoice = $payment->getCreatedInvoice();
             if ($invoice && !$this->_order->getEmailSent()) {
                 $this->orderSender->send($this->_order);
                 $this->_order->addStatusHistoryComment(__('You notified customer about invoice #%1.', $invoice->getIncrementId()))->setIsCustomerNotified(true)->save();
             }
         }
     } catch (Exception $e) {
         throw new Exception(sprintf('Error Creating Invoice: "%s"', $e->getMessage()));
     }
 }
예제 #17
0
 /**
  * authorize payment
  */
 protected function _authorizePayment()
 {
     $this->_adyenLogger->addAdyenNotificationCronjob('Authorisation of the order');
     $fraudManualReviewStatus = $this->_getFraudManualReviewStatus();
     // If manual review is active and a seperate status is used then ignore the pre authorized status
     if ($this->_fraudManualReview != true || $fraudManualReviewStatus == "") {
         $this->_setPrePaymentAuthorized();
     } else {
         $this->_adyenLogger->addAdyenNotificationCronjob('Ignore the pre authorized status because the order is ' . 'under manual review and use the Manual review status');
     }
     $this->_prepareInvoice();
     $_paymentCode = $this->_paymentMethodCode();
     // for boleto confirmation mail is send on order creation
     if ($this->_paymentMethod != "adyen_boleto") {
         // send order confirmation mail after invoice creation so merchant can add invoicePDF to this mail
         if (!$this->_order->getEmailSent()) {
             $this->_orderSender->send($this->_order);
             $this->_adyenLogger->addAdyenNotificationCronjob('Send orderconfirmation email to shopper');
         }
     }
     if ($this->_paymentMethod == "c_cash" && $this->_getConfigData('create_shipment', 'adyen_cash', $this->_order->getStoreId()) || $this->_getConfigData('create_shipment', 'adyen_pos', $this->_order->getStoreId()) && $_paymentCode == "adyen_pos") {
         $this->_createShipment();
     }
 }
예제 #18
0
파일: Onepage.php 프로젝트: nja78/magento2
 /**
  * Create order based on checkout type. Create customer if necessary.
  *
  * @return $this
  */
 public function saveOrder()
 {
     $this->validate();
     $isNewCustomer = false;
     switch ($this->getCheckoutMethod()) {
         case self::METHOD_GUEST:
             $this->_prepareGuestQuote();
             break;
         case self::METHOD_REGISTER:
             $this->_prepareNewCustomerQuote();
             $isNewCustomer = true;
             break;
         default:
             $this->_prepareCustomerQuote();
             break;
     }
     $order = $this->quoteManagement->submit($this->getQuote());
     if ($isNewCustomer) {
         try {
             $this->_involveNewCustomer();
         } catch (\Exception $e) {
             $this->_logger->critical($e);
         }
     }
     $this->_checkoutSession->setLastQuoteId($this->getQuote()->getId())->setLastSuccessQuoteId($this->getQuote()->getId())->clearHelperData();
     if ($order) {
         $this->_eventManager->dispatch('checkout_type_onepage_save_order_after', ['order' => $order, 'quote' => $this->getQuote()]);
         /**
          * a flag to set that there will be redirect to third party after confirmation
          */
         $redirectUrl = $this->getQuote()->getPayment()->getOrderPlaceRedirectUrl();
         /**
          * we only want to send to customer about new order when there is no redirect to third party
          */
         if (!$redirectUrl && $order->getCanSendNewEmailFlag()) {
             try {
                 $this->orderSender->send($order);
             } catch (\Exception $e) {
                 $this->_logger->critical($e);
             }
         }
         // add order information to the session
         $this->_checkoutSession->setLastOrderId($order->getId())->setRedirectUrl($redirectUrl)->setLastRealOrderId($order->getIncrementId())->setLastOrderStatus($order->getStatus());
     }
     $this->_eventManager->dispatch('checkout_submit_all_after', ['order' => $order, 'quote' => $this->getQuote()]);
     return $this;
 }
예제 #19
0
 /**
  * Operate with order using information from silent post
  *
  * @param \Magento\Sales\Model\Order $order
  * @return void
  * @throws \Magento\Framework\Exception\LocalizedException
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  * @SuppressWarnings(PHPMD.NPathComplexity)
  */
 protected function _processOrder(\Magento\Sales\Model\Order $order)
 {
     $response = $this->getResponse();
     $payment = $order->getPayment();
     $payment->setTransactionId($response->getPnref())->setIsTransactionClosed(0);
     $canSendNewOrderEmail = true;
     if ($response->getResult() == self::RESPONSE_CODE_FRAUDSERVICE_FILTER || $response->getResult() == self::RESPONSE_CODE_DECLINED_BY_FILTER) {
         $canSendNewOrderEmail = false;
         $payment->setIsTransactionPending(true)->setIsFraudDetected(true);
         $fraudMessage = $response->getData('respmsg');
         if ($response->getData('fps_prexmldata')) {
             $xml = new \SimpleXMLElement($response->getData('fps_prexmldata'));
             $fraudMessage = (string) $xml->rule->triggeredMessage;
         }
         $payment->setAdditionalInformation(Info::PAYPAL_FRAUD_FILTERS, $fraudMessage);
     }
     if ($response->getData('avsdata') && strstr(substr($response->getData('avsdata'), 0, 2), 'N')) {
         $payment->setAdditionalInformation(Info::PAYPAL_AVS_CODE, substr($response->getData('avsdata'), 0, 2));
     }
     if ($response->getData('cvv2match') && $response->getData('cvv2match') != 'Y') {
         $payment->setAdditionalInformation(Info::PAYPAL_CVV_2_MATCH, $response->getData('cvv2match'));
     }
     switch ($response->getType()) {
         case self::TRXTYPE_AUTH_ONLY:
             $payment->registerAuthorizationNotification($payment->getBaseAmountAuthorized());
             break;
         case self::TRXTYPE_SALE:
             $payment->registerCaptureNotification($payment->getBaseAmountAuthorized());
             break;
         default:
             break;
     }
     $order->save();
     try {
         if ($canSendNewOrderEmail) {
             $this->orderSender->send($order);
         }
         $quote = $this->quoteRepository->get($order->getQuoteId())->setIsActive(false);
         $this->quoteRepository->save($quote);
     } catch (\Exception $e) {
         throw new \Magento\Framework\Exception\LocalizedException(__('We cannot send the new order email.'));
     }
 }
예제 #20
0
 /**
  * Place the order when customer returned from PayPal until this moment all quote data must be valid.
  *
  * @param string $token
  * @param string|null $shippingMethodCode
  * @return void
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  * @SuppressWarnings(PHPMD.NPathComplexity)
  */
 public function place($token, $shippingMethodCode = null)
 {
     if ($shippingMethodCode) {
         $this->updateShippingMethod($shippingMethodCode);
     }
     if ($this->getCheckoutMethod() == \Magento\Checkout\Model\Type\Onepage::METHOD_GUEST) {
         $this->prepareGuestQuote();
     }
     $this->ignoreAddressValidation();
     $this->_quote->collectTotals();
     $order = $this->quoteManagement->submit($this->_quote);
     if (!$order) {
         return;
     }
     // commence redirecting to finish payment, if paypal requires it
     if ($order->getPayment()->getAdditionalInformation(self::PAYMENT_INFO_TRANSPORT_REDIRECT)) {
         $this->_redirectUrl = $this->_config->getExpressCheckoutCompleteUrl($token);
     }
     switch ($order->getState()) {
         // even after placement paypal can disallow to authorize/capture, but will wait until bank transfers money
         case \Magento\Sales\Model\Order::STATE_PENDING_PAYMENT:
             // TODO
             break;
             // regular placement, when everything is ok
         // regular placement, when everything is ok
         case \Magento\Sales\Model\Order::STATE_PROCESSING:
         case \Magento\Sales\Model\Order::STATE_COMPLETE:
         case \Magento\Sales\Model\Order::STATE_PAYMENT_REVIEW:
             $this->orderSender->send($order);
             $this->_checkoutSession->start();
             break;
         default:
             break;
     }
     $this->_order = $order;
 }
예제 #21
0
 /**
  * Operate with order using information from Authorize.net.
  * Authorize order or authorize and capture it.
  *
  * @param \Magento\Sales\Model\Order $order
  * @return void
  * @throws \Magento\Framework\Exception\LocalizedException
  * @throws \Exception
  * @SuppressWarnings(PHPMD.NPathComplexity)
  */
 protected function processOrder(\Magento\Sales\Model\Order $order)
 {
     try {
         $this->checkResponseCode();
         $this->checkTransId();
     } catch (\Exception $e) {
         //decline the order (in case of wrong response code) but don't return money to customer.
         $message = $e->getMessage();
         $this->declineOrder($order, $message, false);
         throw $e;
     }
     $response = $this->getResponse();
     //create transaction. need for void if amount will not match.
     $payment = $order->getPayment();
     $this->fillPaymentByResponse($payment);
     $payment->getMethodInstance()->setIsInitializeNeeded(false);
     $payment->getMethodInstance()->setResponseData($response->getData());
     $this->processPaymentFraudStatus($payment);
     $payment->place();
     $this->addStatusComment($payment);
     $order->save();
     //match amounts. should be equals for authorization.
     //decline the order if amount does not match.
     if (!$this->matchAmount($payment->getBaseAmountAuthorized())) {
         $message = __('Something went wrong: the paid amount doesn\'t match the order amount.' . ' Please correct this and try again.');
         $this->declineOrder($order, $message, true);
         throw new \Magento\Framework\Exception\LocalizedException($message);
     }
     try {
         if (!$response->hasOrderSendConfirmation() || $response->getOrderSendConfirmation()) {
             $this->orderSender->send($order);
         }
         $quote = $this->quoteRepository->get($order->getQuoteId())->setIsActive(false);
         $this->quoteRepository->save($quote);
     } catch (\Exception $e) {
         // do not cancel order if we couldn't send email
     }
 }
예제 #22
0
 /**
  * Place the order when customer returned from PayPal until this moment all quote data must be valid.
  *
  * @param string $token
  * @param string|null $shippingMethodCode
  * @return void
  */
 public function place($token, $shippingMethodCode = null)
 {
     if ($shippingMethodCode) {
         $this->updateShippingMethod($shippingMethodCode);
     }
     $isNewCustomer = false;
     switch ($this->getCheckoutMethod()) {
         case \Magento\Checkout\Model\Type\Onepage::METHOD_GUEST:
             $this->_prepareGuestQuote();
             break;
         case \Magento\Checkout\Model\Type\Onepage::METHOD_REGISTER:
             $this->_prepareNewCustomerQuote();
             $isNewCustomer = true;
             break;
         default:
             $this->_prepareCustomerQuote();
             break;
     }
     $this->_ignoreAddressValidation();
     $this->_quote->collectTotals();
     $parameters = array('quote' => $this->_quote);
     $service = $this->_serviceQuoteFactory->create($parameters);
     $service->submitAllWithDataObject();
     $this->_quote->save();
     if ($isNewCustomer) {
         try {
             $this->_involveNewCustomer();
         } catch (\Exception $e) {
             $this->_logger->logException($e);
         }
     }
     $order = $service->getOrder();
     if (!$order) {
         return;
     }
     // commence redirecting to finish payment, if paypal requires it
     if ($order->getPayment()->getAdditionalInformation(self::PAYMENT_INFO_TRANSPORT_REDIRECT)) {
         $this->_redirectUrl = $this->_config->getExpressCheckoutCompleteUrl($token);
     }
     switch ($order->getState()) {
         // even after placement paypal can disallow to authorize/capture, but will wait until bank transfers money
         case \Magento\Sales\Model\Order::STATE_PENDING_PAYMENT:
             // TODO
             break;
             // regular placement, when everything is ok
         // regular placement, when everything is ok
         case \Magento\Sales\Model\Order::STATE_PROCESSING:
         case \Magento\Sales\Model\Order::STATE_COMPLETE:
         case \Magento\Sales\Model\Order::STATE_PAYMENT_REVIEW:
             $this->orderSender->send($order);
             break;
         default:
             break;
     }
     $this->_order = $order;
 }
예제 #23
0
 /**
  * Operate with order using information from silent post
  *
  * @param \Magento\Sales\Model\Order $order
  * @return void
  * @throws \Magento\Framework\Model\Exception
  */
 protected function _processOrder(\Magento\Sales\Model\Order $order)
 {
     $response = $this->getResponse();
     $payment = $order->getPayment();
     $payment->setTransactionId($response->getPnref())->setIsTransactionClosed(0);
     $canSendNewOrderEmail = true;
     if ($response->getResult() == self::RESPONSE_CODE_FRAUDSERVICE_FILTER || $response->getResult() == self::RESPONSE_CODE_DECLINED_BY_FILTER) {
         $canSendNewOrderEmail = false;
         $fraudMessage = $this->_getFraudMessage() ? $response->getFraudMessage() : $response->getRespmsg();
         $payment->setIsTransactionPending(true)->setIsFraudDetected(true)->setAdditionalInformation('paypal_fraud_filters', $fraudMessage);
     }
     if ($response->getAvsdata() && strstr(substr($response->getAvsdata(), 0, 2), 'N')) {
         $payment->setAdditionalInformation('paypal_avs_code', substr($response->getAvsdata(), 0, 2));
     }
     if ($response->getCvv2match() && $response->getCvv2match() != 'Y') {
         $payment->setAdditionalInformation('paypal_cvv2_match', $response->getCvv2match());
     }
     switch ($response->getType()) {
         case self::TRXTYPE_AUTH_ONLY:
             $payment->registerAuthorizationNotification($payment->getBaseAmountAuthorized());
             break;
         case self::TRXTYPE_SALE:
             $payment->registerCaptureNotification($payment->getBaseAmountAuthorized());
             break;
         default:
             break;
     }
     $order->save();
     try {
         if ($canSendNewOrderEmail) {
             $this->orderSender->send($order);
         }
         $this->_quoteFactory->create()->load($order->getQuoteId())->setIsActive(false)->save();
     } catch (\Exception $e) {
         throw new \Magento\Framework\Model\Exception(__('We cannot send the new order email.'));
     }
 }
예제 #24
0
 protected function _updateStatus($order, $helper, $status, $message)
 {
     if ($order->getState() !== \Magento\Sales\Model\Order::STATE_COMPLETE) {
         $statusOrder = $helper->getStatusOrder($status);
         $order->setState($helper->_getAssignedState($statusOrder));
         $order->addStatusToHistory($statusOrder, $message, true);
         $this->_orderSender->send($order, true, $message);
     }
 }