asInteger(); if ($price < 2000) { return null; } return path('hellobank_calc', ['price' => $price]); } public function getPaymentUrl(int $step = 1): string { return createScriptURL([ 's' => 'payment', 'IDo' => $this->order->id, 'cf' => $this->order->getSecurityCode(), 'step' => $step, 'class' => $this->class, ]); } public function getGatewayUrl() { return $this->url; } public function getData() { return [ 'kodProdejce' => $this->config['kodProdejce'], 'cenaZbozi' => roundPrice($this->order->getRemainingPaymentInCZK(), -1, 'DB', 0)->asInteger(), 'calc' => '1', 'url_back_ok' => createScriptURL([ 's' => 'payment', 'IDo' => $this->order->id, 'cf' => $this->order->getSecurityCode(), 'step' => 5, 'class' => $this->class, 'absolute' => true, ]), 'url_back_ko' => createScriptURL([ 's' => 'payment', 'IDo' => $this->order->id, 'cf' => $this->order->getSecurityCode(), 'step' => 6, 'class' => $this->class, 'absolute' => true, ]), 'obj' => $this->orderId, 'numklient' => $this->order->id_user, 'doprava' => '1', // $this->order->getDeliveryType()->isInPerson() ? '0' : '1', ]; } public function accept($totalPrice, $freeDelivery) { $totalPrice = $totalPrice->getPriceWithVat()->asFloat(); if ($totalPrice <= 0 && $this->order) { $totalPrice = $this->order->total_price; } return parent::accept($totalPrice, $freeDelivery) && $totalPrice >= 2000; } public function processStep_1() { } public function processStep_5() { // success - authorized $this->processResult(true); $this->success('Žádost o úvěr byla schválena'); } public function processStep_6() { // not authorized yet $this->processResult(false); $this->error('Žádost o úvěr zatím nebyla autorizována'); } protected function processResult(bool $ok = false) { $remainingPayment = roundPrice($this->order->getRemainingPayment())->asFloat(); if ($remainingPayment > 0.00) { $session = getVal('numwrk').'_'.uniqid(); $this->createPayment( $session, $remainingPayment, ['paymentClass' => self::class] ); // save return params $returnParams = ['stav', 'numaut', 'vdr', 'numwrk', 'jmeno', 'prijmeni', 'splatka', 'numklient', 'obj']; $paymentRow = sqlQueryBuilder()->select('*')->from('order_payments') ->where(\Query\Operator::equals(['id' => $this->paymentId]))->execute()->fetch(); $data = json_decode($paymentRow['payment_data'] ?? '{}'); $data->returnParams = []; foreach ($returnParams as $param) { $data->returnParams[$param] = getVal($param); } sqlQueryBuilder()->update('order_payments')->directValues(['payment_data' => json_encode($data)]) ->where(\Query\Operator::equals(['id' => $this->paymentId]))->execute(); $paymentStatus = $ok ? Payment::STATUS_FINISHED : Payment::STATUS_PENDING; // change payment status if (!$this->setStatus($paymentStatus, $session)) { logError(__FILE__, __LINE__, 'PayPal::updatePaymentStatus: setStatus failed!'); throw new \Exception('Set status failed'); } } } public function startPayment() { return false; } public function hasOnlinePayment() { return true; } public static function isEnabled($className) { $cfg = Config::get(); if (empty($cfg['Modules']['payments'][$className])) { return false; } return true; } }