|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * Copyright © 2016 Magento. All rights reserved. |
| 4 | + * See COPYING.txt for license details. |
| 5 | + */ |
| 6 | + |
| 7 | +// @codingStandardsIgnoreFile |
| 8 | + |
| 9 | +namespace Bitpay\Core\Model\Order; |
| 10 | + |
| 11 | +/** |
| 12 | + * Order payment information |
| 13 | + * |
| 14 | + * @method \Magento\Sales\Model\ResourceModel\Order\Payment _getResource() |
| 15 | + * @method \Magento\Sales\Model\ResourceModel\Order\Payment getResource() |
| 16 | + * @SuppressWarnings(PHPMD.ExcessivePublicCount) |
| 17 | + * @SuppressWarnings(PHPMD.ExcessiveClassComplexity) |
| 18 | + * @SuppressWarnings(PHPMD.CouplingBetweenObjects) |
| 19 | + */ |
| 20 | +class Payment extends \Magento\Sales\Model\Order\Payment |
| 21 | +{ |
| 22 | + |
| 23 | + |
| 24 | + /** |
| 25 | + * Authorize or authorize and capture payment on gateway, if applicable |
| 26 | + * This method is supposed to be called only when order is placed |
| 27 | + * |
| 28 | + * @return $this |
| 29 | + * @SuppressWarnings(PHPMD.NPathComplexity) |
| 30 | + * @SuppressWarnings(PHPMD.CyclomaticComplexity) |
| 31 | + */ |
| 32 | + public function place() |
| 33 | + { |
| 34 | + $this->_eventManager->dispatch('sales_order_payment_place_start', ['payment' => $this]); |
| 35 | + $order = $this->getOrder(); |
| 36 | + |
| 37 | + $this->setAmountOrdered($order->getTotalDue()); |
| 38 | + $this->setBaseAmountOrdered($order->getBaseTotalDue()); |
| 39 | + $this->setShippingAmount($order->getShippingAmount()); |
| 40 | + $this->setBaseShippingAmount($order->getBaseShippingAmount()); |
| 41 | + |
| 42 | + $methodInstance = $this->getMethodInstance(); |
| 43 | + $methodInstance->setStore($order->getStoreId()); |
| 44 | + |
| 45 | + $orderState = \Magento\Sales\Model\Order::STATE_NEW; |
| 46 | + $orderStatus = $methodInstance->getConfigData('order_status'); |
| 47 | + $isCustomerNotified = $order->getCustomerNoteNotify(); |
| 48 | + |
| 49 | + // Do order payment validation on payment method level |
| 50 | + $methodInstance->validate(); |
| 51 | + $action = $methodInstance->getConfigPaymentAction(); |
| 52 | + $payment = $order -> getPayment(); |
| 53 | + $paymentMethodCode = $payment -> getMethodInstance() -> getCode(); |
| 54 | + |
| 55 | + if ($action) { |
| 56 | + if ($methodInstance->isInitializeNeeded()) { |
| 57 | + $stateObject = new \Magento\Framework\DataObject(); |
| 58 | + // For method initialization we have to use original config value for payment action |
| 59 | + $methodInstance->initialize($methodInstance->getConfigData('payment_action'), $stateObject); |
| 60 | + if ($paymentMethodCode != 'bitpay'){ |
| 61 | + $orderState = $stateObject->getData('state') ?: $orderState; |
| 62 | + $orderStatus = $stateObject->getData('status') ?: $orderStatus; |
| 63 | + } |
| 64 | + $isCustomerNotified = $stateObject->hasData('is_notified') |
| 65 | + ? $stateObject->getData('is_notified') |
| 66 | + : $isCustomerNotified; |
| 67 | + } else { |
| 68 | + $this->processAction($action, $order); |
| 69 | + if ($paymentMethodCode != 'bitpay'){ |
| 70 | + $orderState = \Magento\Sales\Model\Order::STATE_PROCESSING; |
| 71 | + $orderState = $order->getState() ? $order->getState() : $orderState; |
| 72 | + $orderStatus = $order->getStatus() ? $order->getStatus() : $orderStatus; |
| 73 | + } |
| 74 | + |
| 75 | + } |
| 76 | + } else { |
| 77 | + $order->setState($orderState) |
| 78 | + ->setStatus($orderStatus); |
| 79 | + } |
| 80 | + |
| 81 | + $isCustomerNotified = $isCustomerNotified ?: $order->getCustomerNoteNotify(); |
| 82 | + |
| 83 | + if (!array_key_exists($orderStatus, $order->getConfig()->getStateStatuses($orderState))) { |
| 84 | + $orderStatus = $order->getConfig()->getStateDefaultStatus($orderState); |
| 85 | + } |
| 86 | + |
| 87 | + $this->updateOrder($order, $orderState, $orderStatus, $isCustomerNotified); |
| 88 | + |
| 89 | + $this->_eventManager->dispatch('sales_order_payment_place_end', ['payment' => $this]); |
| 90 | + |
| 91 | + return $this; |
| 92 | + } |
| 93 | + |
| 94 | + |
| 95 | + public function addTransactionCommentsToOrder($transaction, $message) |
| 96 | + { |
| 97 | + $order = $this->getOrder(); |
| 98 | + $payment = $order -> getPayment(); |
| 99 | + $paymentMethodCode = $payment -> getMethodInstance() -> getCode(); |
| 100 | + |
| 101 | + $message = $this->_appendTransactionToMessage($transaction, $message); |
| 102 | + if ($paymentMethodCode != 'bitpay'){ |
| 103 | + $order->addStatusHistoryComment($message); |
| 104 | + } |
| 105 | + } |
| 106 | + |
| 107 | + |
| 108 | + //@codeCoverageIgnoreEnd |
| 109 | +} |
0 commit comments