Проверка статуса счёта.

@param Order $order

@return array
343951
public function showStatus($order)
	{
		$gate = new Gateway($this->makeCurl());
		$isSuccess = $gate->doRequestBillStatus($order->id);

		if ($isSuccess) {
			$order->changeStatus($gate->getValueBillStatus());

			$message = 'Текущий статус счета - '
				. Dictionary::statusRussian($order->status);

			return $this->resultMessage($message, 'Сообщение');

		}

		return $this->resultMessage($gate->getError());
	}
1037264
public function findByOrderId($orderId, $locale)
    {
        $result = array();
        $items = $this->getShippingRepository()->findByOrderId($orderId, $locale);
        foreach ($items as $item) {
            $result[] = $this->shippingFactory->createApiEntity($item, $locale);
        }
        return $result;
    }
81602
final protected static function validateOrder (string $order="DESC") : string
	{
		$order = strtoupper($order);
		return (!in_array($order, ["DESC", "ASC"])) ? "DESC" : $order;
	}
882198
public function edit(Order $order)
    {
        Shop::instance($order->shop_id);
        $paymentMethods = Shop::getPaymentMethods()->flatten()->mapWithKeys(function($method) {
            return [$method::getId() => $method::getName()];
        })->all();
        return view('order::admin.orders.edit', compact('order', 'paymentMethods'));
    }
1293821
public function getAllSimpleItems($order)
    {
        $items = array();

        foreach ($order->getAllItems() as $item) {
            if ($item->getProductType() == 'simple') {
                $items[] = $item;
            }
        }

        return $items;
    }
375755
public function order($order, $context) {
		if (!$order) {
			return [];
		}
		if (is_string($order)) {
			return [$order => 1];
		}
		if (!is_array($order)) {
			return [];
		}
		foreach ($order as $key => $value) {
			if (!is_string($key)) {
				unset($order[$key]);
				$order[$value] = 1;
				continue;
			}
			if (is_string($value)) {
				$order[$key] = strtolower($value) === 'asc' ? 1 : -1;
			}
		}
		return $order;
	}
1267584
protected function getItemListForOrder(Order $order): array
    {
        $items = [];

        $priceCheck = 0;
        $count = -1;

        /** @var LineItem $item */
        foreach ($order->lineItems as $item) {
            $price = Currency::round($item->salePrice);
            // Can not accept zero amount items. See item (4) here:
            // https://developer.paypal.com/docs/classic/express-checkout/integration-guide/ECCustomizing/#setting-order-details-on-the-paypal-review-page

            if ($price !== 0) {
                $count++;
                /** @var Purchasable $purchasable */
                $purchasable = $item->getPurchasable();
                $defaultDescription = Craft::t('commerce', 'Item ID').' '.$item->id;
                $purchasableDescription = $purchasable ? $purchasable->getDescription() : $defaultDescription;
                $description = isset($item->snapshot['description']) ? $item->snapshot['description'] : $purchasableDescription;
                $description = empty($description) ? 'Item '.$count : $description;
                $items[] = [
                    'name' => $description,
                    'description' => $description,
                    'quantity' => $item->qty,
                    'price' => $price,
                ];

                $priceCheck += ($item->qty * $item->salePrice);
            }
        }

        $count = -1;

        /** @var OrderAdjustment $adjustment */
        foreach ($order->adjustments as $adjustment) {
            $price = Currency::round($adjustment->amount);

            // Do not include the 'included' adjustments, and do not send zero value items
            // See item (4) https://developer.paypal.com/docs/classic/express-checkout/integration-guide/ECCustomizing/#setting-order-details-on-the-paypal-review-page
            if (($adjustment->included == 0 || $adjustment->included == false) && $price !== 0) {
                $count++;
                $items[] = [
                    'name' => empty($adjustment->name) ? $adjustment->type." ".$count : $adjustment->name,
                    'description' => empty($adjustment->description) ? $adjustment->type.' '.$count : $adjustment->description,
                    'quantity' => 1,
                    'price' => $price,
                ];
                $priceCheck += $adjustment->amount;
            }
        }

        $priceCheck = Currency::round($priceCheck);
        $totalPrice = Currency::round($order->totalPrice);
        $same = (bool)($priceCheck === $totalPrice);

        if (!$same) {
            Craft::error('Item bag total price does not equal the orders totalPrice, some payment gateways will complain.', __METHOD__);
        }

        return $items;
    }
1210752
public function orderBy($columns, string $order = 'ASC')
	{
		$this->orderings[] =
		[
			'column' => is_array($columns) ? $columns : [$columns],
			'order'  => ($order === 'ASC' || $order === 'asc') ? 'ASC' : 'DESC',
		];

		return $this;
	}
664849
public function isPaymentModuleFor(Order $order)
    {
        $model = $this->getModuleModel();

        return $order->getPaymentModuleId() == $model->getId();
    }
1239539
public function createBill($order)
	{
		if (!$order->isNew()) {
			return $this->resultMessage('Статус заказа не "Новый"');
		}

		$gate = new Gateway($this->makeCurl());
		$isSuccess = $gate->createBill(
			$order->id, $order->tel, $order->sum, $order->comment, $order->lifetime
		);

		if (!$isSuccess) {
			return $this->resultMessage($gate->getError());
		}
		$order->changeStatus(Order::C_ORDER_STATUS_PAYABLE);

		if ($order->status == Order::C_ORDER_STATUS_PAYABLE) {
			$message = 'Счёт выставлен';

			return $this->resultMessage($message, 'Сообщение');
		}

		return $this->resultMessage('Счёт не выставлен');
	}
686291
public function acceptAction(Order $order)
    {
        $order->acceptBySeller();

        $em = $this->getDoctrine()->getEntityManager();
        $em->persist($order);
        $em->flush();

#        $this->get('notifier')->notify(new OrderAcceptedBySellerEvent($order), $this->getUser());

        return $this->redirect($this->generateUrl('Order_show', array(
            'id' => $order->getNumberForPath()
        )));
    }
74404
public function all($order = null)
    {
        $query = $this->createBuilder();

        if ( ! empty($order) and is_string($order)) {
            return $this->prepareQuery($query)->orderBy($order)->get();
        }

        if ( ! empty($order) and is_array($order)) {
            $build = $this->prepareQuery($query);

            foreach ($order as $orderItem) {
                $build = $build->orderBy($orderItem);
            }

            return $build->with($this->withs)->get();
        }

        return $this->prepareQuery($query)->get();
    }
892462
public function cancelAction(Order $order)
    {
        $order->cancelByBuyer();

        $em = $this->getDoctrine()->getEntityManager();
        $em->persist($order);
        $em->flush();

        return $this->redirect($this->generateUrl('Order_show', array(
            'id' => $order->getNumberForPath()
        )));
    }
770123
private function toPayPalItems($order)
    {
        $items = [];

        foreach ($order->items as $shopItem) {

            if ($shopItem->price > 0) {

                $item = new Item();

                $item->setName(substr($shopItem->displayName, 0, 127))
                    ->setDescription($shopItem->sku)
                    ->setCurrency($shopItem->currency)
                    ->setQuantity($shopItem->quantity)
                    ->setTax($shopItem->tax)
                    ->setPrice($shopItem->price);

                $items[] = $item;
            }
        }

        return $items;
    }
316432
protected function parseOrder(Query $query, $order)
    {
        if (empty($order)) {
            return ' ORDER BY rand()';
        }

        $array = [];

        foreach ($order as $key => $val) {
            if ($val instanceof Expression) {
                $array[] = $val->getValue();
            } elseif ('[rand]' == $val) {
                $array[] = $this->parseRand($query);
            } else {
                if (is_numeric($key)) {
                    list($key, $sort) = explode(' ', strpos($val, ' ') ? $val : $val . ' ');
                } else {
                    $sort = $val;
                }

                $sort    = in_array(strtolower($sort), ['asc', 'desc'], true) ? ' ' . $sort : '';
                $array[] = $this->parseKey($query, $key, true) . $sort;
            }
        }

        return ' ORDER BY ' . implode(',', $array);
    }
224664
public function create(Order &$order)
    {
        $data = $order->exportData();
        $endpoint = '/admin/orders.json';
        $response = $this->request(
            $endpoint, 'POST', array(
            'order' => $data
            )
        );
        $order->setData($response['order']);
    }
129128
public function createdToCustomer($order)
    {
        $store = $this->store->get($order['store_id']);
        $url = $this->store->getUrl($store);
        $user = $this->user->get($order['user_id']);
        $store_name = $this->store->getTranslation('title', $this->translation->getLangcode(), $store);

        $options = $this->store->getConfig(null, $store);
        $options['from'] = reset($store['data']['email']);

        $vars = array(
            '@store' => $store_name,
            '@order_id' => $order['order_id'],
            '@order' => "$url/account/{$order['user_id']}",
            '@status' => $this->order->getStatusName($order['status']),
        );

        $subject = $this->translation->text('Order #@order_id on @store', $vars);
        $message = $this->translation->text("Thank you for ordering on @store\r\n\r\nOrder ID: @order_id\r\nOrder status: @status\r\nView orders: @order", $vars);
        $message .= $this->getSignature($options);

        return array($user['email'], $subject, $message, $options);
    }