/** * Generate an "IPN" comment with additional explanation. * Returns the generated comment or order status history object * * @param string $comment * @param bool $addToHistory * @return string|\Magento\Sales\Model\Order\Status\History */ protected function _createIpnComment($comment = '', $addToHistory = false) { $message = __('IPN "%1"', $this->getRequestData('payment_status')); if ($comment) { $message .= ' ' . $comment; } if ($addToHistory) { $message = $this->_order->addStatusHistoryComment($message); $message->setIsCustomerNotified(null); } return $message; }
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())); } }
/** * Confirm the payment of an order * * @param \Magento\Sales\Model\Order $order * @param \WirecardCEE_Stdlib_Return_ReturnAbstract $return * @param bool $fraudDetected * * @return Order * * @throws \Magento\Framework\Exception\LocalizedException */ public function confirmOrder($order, $return, $fraudDetected) { /** @var \Magento\Sales\Model\Order\Payment $payment */ $payment = $order->getPayment(); /** @var \Wirecard\CheckoutPage\Model\AbstractPayment $paymentInstance */ $paymentInstance = $payment->getMethodInstance(); $additionalInformation = array(); foreach ($return->getReturned() as $fieldName => $fieldValue) { $additionalInformation[htmlentities($fieldName)] = htmlentities($fieldValue); } $payment->setAdditionalInformation($additionalInformation); if ($fraudDetected) { $order->setStatus(\Magento\Sales\Model\Order::STATUS_FRAUD); $message = $this->_dataHelper->__('fraud attemmpt detected, cart has been modified during checkout!'); $this->_logger->debug(__METHOD__ . ':' . $message); $order->addStatusHistoryComment($message); } $doCapture = false; if (!$this->isOrderProcessed($order)) { if ($return->getPaymentState() == \WirecardCEE_QPay_ReturnFactory::STATE_PENDING) { /** @var \WirecardCEE_QPay_Return_Pending $return */ $order->setState(\Magento\Sales\Model\Order::STATE_PENDING_PAYMENT); $message = $this->_dataHelper->__('The payment authorization is pending.'); } else { /** @var \WirecardCEE_QPay_Return_Success $return */ $order->setState(\Magento\Sales\Model\Order::STATE_PROCESSING); $order->setStatus(\Magento\Sales\Model\Order::STATE_PROCESSING); $message = $this->_dataHelper->__('The payment has been successfully completed.'); // invoice payment if ($order->canInvoice()) { $invoice = $order->prepareInvoice(); $invoice->register(); /* capture invoice if toolkit is not availble */ if (!$this->_dataHelper->isBackendAvailable()) { $doCapture = true; } else { $hasBackedOps = false; $orderDetails = $paymentInstance->getOrderDetails($payment->getAdditionalInformation('orderNumber')); foreach ($orderDetails->getOrder()->getPayments() as $wdPayment) { /** @var \WirecardCEE_QPay_Response_Toolkit_Order_Payment $wdPayment */ $this->_logger->debug(__METHOD__ . ':payment-state:' . $wdPayment->getState() . ' allowed operations:' . implode(',', $wdPayment->getOperationsAllowed())); if (count($wdPayment->getOperationsAllowed())) { $hasBackedOps = true; break; } } if (count($orderDetails->getOrder()->getOperationsAllowed())) { $this->_logger->debug(__METHOD__ . ':order allowed operations: ' . implode(',', $orderDetails->getOrder()->getOperationsAllowed())); $hasBackedOps = true; } /* no backend ops allowed anymore, assume final state of payment, capture invoice */ if (!$hasBackedOps) { $doCapture = true; } } if ($doCapture && !$fraudDetected) { $invoice->capture(); } $order->addRelatedObject($invoice); } $this->_orderSender->send($order); } $type = $doCapture ? Transaction::TYPE_CAPTURE : Transaction::TYPE_AUTH; $this->saveTransaction($type, $message, $order, $return); } $order->save(); return $order; }
/** * @param bool $manualReviewComment * @param bool $createInvoice * @throws Exception */ protected function _setPaymentAuthorized($manualReviewComment = true, $createInvoice = false) { $this->_adyenLogger->addAdyenNotificationCronjob('Set order to authorised'); // if full amount is captured create invoice $currency = $this->_order->getOrderCurrencyCode(); $amount = $this->_value; $orderAmount = (int) $this->_adyenHelper->formatAmount($this->_order->getGrandTotal(), $currency); // create invoice for the capture notification if you are on manual capture if ($createInvoice == true && $amount == $orderAmount) { $this->_adyenLogger->addAdyenNotificationCronjob('amount notification:' . $amount . ' amount order:' . $orderAmount); $this->_createInvoice(); } // if you have capture on shipment enabled don't set update the status of the payment $captureOnShipment = $this->_getConfigData('capture_on_shipment', 'adyen_abstract', $this->_order->getStoreId()); if (!$captureOnShipment) { $status = $this->_getConfigData('payment_authorized', 'adyen_abstract', $this->_order->getStoreId()); } // virtual order can have different status if ($this->_order->getIsVirtual()) { $this->_adyenLogger->addAdyenNotificationCronjob('Product is a virtual product'); $virtualStatus = $this->_getConfigData('payment_authorized_virtual'); if ($virtualStatus != "") { $status = $virtualStatus; } } // check for boleto if payment is totally paid if ($this->_paymentMethodCode() == "adyen_boleto") { // check if paid amount is the same as orginal amount $orginalAmount = $this->_boletoOriginalAmount; $paidAmount = $this->_boletoPaidAmount; if ($orginalAmount != $paidAmount) { // not the full amount is paid. Check if it is underpaid or overpaid // strip the BRL of the string $orginalAmount = str_replace("BRL", "", $orginalAmount); $orginalAmount = floatval(trim($orginalAmount)); $paidAmount = str_replace("BRL", "", $paidAmount); $paidAmount = floatval(trim($paidAmount)); if ($paidAmount > $orginalAmount) { $overpaidStatus = $this->_getConfigData('order_overpaid_status', 'adyen_boleto'); // check if there is selected a status if not fall back to the default $status = !empty($overpaidStatus) ? $overpaidStatus : $status; } else { $underpaidStatus = $this->_getConfigData('order_underpaid_status', 'adyen_boleto'); // check if there is selected a status if not fall back to the default $status = !empty($underpaidStatus) ? $underpaidStatus : $status; } } } $comment = "Adyen Payment Successfully completed"; // if manual review is true use the manual review status if this is set if ($manualReviewComment == true && $this->_fraudManualReview) { // check if different status is selected $fraudManualReviewStatus = $this->_getFraudManualReviewStatus(); if ($fraudManualReviewStatus != "") { $status = $fraudManualReviewStatus; $comment = "Adyen Payment is in Manual Review check the Adyen platform"; } } $status = !empty($status) ? $status : $this->_order->getStatus(); $this->_order->addStatusHistoryComment(__($comment), $status); $this->_adyenLogger->addAdyenNotificationCronjob('Order status is changed to authorised status, status is ' . $status); }