getConfigValue('is_initialized', false)) { $database = new Database($con); $database->insertSql(null, [__DIR__ . "/Config/thelia.sql"]); } } public function update($currentVersion, $newVersion, ConnectionInterface $con = null) { $finder = Finder::create() ->name('*.sql') ->depth(0) ->sortByName() ->in(__DIR__ . DS . 'Config' . DS . 'update'); $database = new Database($con); /** @var \SplFileInfo $file */ foreach ($finder as $file) { if (version_compare($currentVersion, $file->getBasename('.sql'), '<')) { $database->insertSql(null, [$file->getPathname()]); } } } public function isValidPayment() { /** @var PaymentService $paymentService */ $paymentService = $this->container->get('payplugmodule_payment_service'); return $paymentService->isPayPlugAvailable(); } /** * @inheritDoc */ public function pay(Order $order) { try { /** @var PaymentService $paymentService */ $paymentService = $this->container->get('payplugmodule_payment_service'); $slice = 1; $isMultiPayment = $this->getRequest()->getSession()->get(OrderFormListener::PAY_PLUG_MULTI_PAYMENT_FIELD_NAME, 0); if ($isMultiPayment) { $orderTotalAmount = $order->getTotalAmount(); $minAmount = PayPlugModule::getConfigValue(PayPlugConfigValue::MULTI_PAYMENT_MINIMUM); $maxAmount = PayPlugModule::getConfigValue(PayPlugConfigValue::MULTI_PAYMENT_MAXIMUM); if ($minAmount <= $orderTotalAmount && $maxAmount >= $orderTotalAmount) { $slice = PayPlugModule::getConfigValue(PayPlugConfigValue::MULTI_PAYMENT_TIMES); } } $payment = $paymentService->sendOrderPayment( $order, PayPlugModule::getConfigValue(PayPlugConfigValue::DIFFERED_PAYMENT_ENABLED, false), PayPlugModule::getConfigValue(PayPlugConfigValue::ONE_CLICK_PAYMENT_ENABLED, false), $slice ); $forceRedirect = false; if (true === $payment['isPaid']) { $forceRedirect = true; $payment['url'] = URL::getInstance()->absoluteUrl('/order/placed/'.$order->getId()); } if ($this->getRequest()->isXmlHttpRequest()) { return new JsonResponse( [ 'paymentUrl' => $payment['url'], 'forceRedirect' => $forceRedirect ] ); } } catch (\Exception $exception) { if ($this->getRequest()->isXmlHttpRequest()) { return new JsonResponse(['error' => $exception->getMessage()], 400); } return RedirectResponse::create(URL::getInstance()->absoluteUrl('error')); } return new RedirectResponse($payment['url']); } public function getHooks() { return [ [ "type" => TemplateDefinition::BACK_OFFICE, "code" => "payplugmodule.configuration.bottom", "title" => [ "en_US" => "Bottom of PayPlug configuration page", "fr_FR" => "Bas de la page de configuration PayPlug", ], "block" => false, "active" => true, ] ]; } }