} */ public static function context(Order $order, GatewayConfig $config): array { global $CFG, $OUTPUT; $request = new PaymentRequest( accountId: $config->accountNumber, transactionId: AssistantTransactionId::build($order->merchantOrderId), amount: $order->amount, subscriberId: $order->subscriberId(), testMode: $order->snapshot->testMode, signature: $config->signature(), description: $order->snapshot->description, successUrl: (new moodle_url(self::RETURN_PATH, ['outcome' => 'success']))->out(false), failUrl: (new moodle_url(self::RETURN_PATH, ['outcome' => 'fail']))->out(false), returnUrl: (new moodle_url(self::RETURN_PATH, ['outcome' => 'cancel']))->out(false), server: $config->paymentServer, locale: AssistantProtocol::normalizeLocale(current_language()), cms: CmsInfo::getCmsModuleVersion(), ); $fields = []; foreach ($request->getFields() as $name => $value) { $fields[] = ['name' => $name, 'value' => $value]; } return [ 'action' => empty($CFG->paygw_moneta_assistant_url) ? $request->getActionUrl() : (string) $CFG->paygw_moneta_assistant_url, // Сумма для покупателя — как в остальном Moodle: «120,25 ₽». 'cost' => helper::get_cost_as_string((float) $order->amount->toDecimal(), $order->currency), 'description' => $order->snapshot->description, 'iscourse' => $order->component === 'enrol_fee', 'logourl' => $OUTPUT->image_url('img', 'paygw_moneta')->out(false), 'fields' => $fields, ]; } /** * Можно ли продолжить оплату открытого заказа по ссылке из письма: реквизиты, * тестовый режим и цена те же, что при создании, — иначе Pay URL всё равно * отклонит оплату (`PayHandler`). */ public static function canResume(Order $order, ?GatewayConfig $config, CurrentPrice $currentPrice): bool { return $order->status->isOpen() && $config !== null && $config->acceptsNewOrders() && $config->accountNumber === $order->snapshot->accountNumber && $config->testMode === $order->snapshot->testMode && $currentPrice->matches($order); } /** * Адрес страницы продолжения оплаты — его получает покупатель в письме. */ public static function resumeUrl(Order $order): moodle_url { return new moodle_url('/payment/gateway/moneta/checkout.php', ['order' => $order->merchantOrderId]); } }