function process($parameters) { $bitcoinPay = new Bitcoinpay(); if (!$bitcoinPay->checkLogin()) { $this->redirect('error'); } $paymentId = false; if (is_numeric($parameters[0])) { $paymentId = $parameters[0]; } else { $this->redirect('error'); } //allow delete only for admin $paymentUserId = $bitcoinPay->getPaymentUserId($paymentId); if (!$bitcoinPay->checkIfIsAdminOfUser($_SESSION['id_user'], $paymentUserId)) { $this->redirect('error'); } //disable delete invoice, which is already payed $fakturoid = new FakturoidWrapper(); $paymentFakturoidId = $fakturoid->getFakturoidInvoiceIdFromPaymentId($paymentId); $fakturoid->cancelInvoice($paymentFakturoidId); //TODO disable delete for already payed invoices $result = $bitcoinPay->deletePayment($paymentId); $this->messages[] = $result; //navigate to default view for this action $this->redirect('checkUsers'); }
function process($parameters) { $extras = new Extras(); $fakturoid = new FakturoidWrapper(); $action = $extras->sanitize($parameters[0]); switch ($action) { case 'add': $paymentId = $extras->sanitize($_POST['paymentId']); $price = $extras->sanitize($_POST['price']); $description = $extras->sanitize($_POST['description']); $result = $extras->checkAddValues($paymentId, $price, $description); if ($result['s'] == 'success') { $status = $extras->getStatusOfPayment($paymentId); //allow add extra only when new payment will be generated if (!in_array($status, ['unpaid', 'refund', 'timeout'])) { $this->messages[] = ['s' => 'error', 'cs' => 'Bohužel, položka nebyla přidána; platba se právě platí nebo je již zaplacená', 'en' => 'Sorry, we cannot add an extra; payment is processing']; } else { $invoiceFakturoidId = $fakturoid->getFakturoidInvoiceIdFromPaymentId($paymentId); $extraFakturoidId = $fakturoid->addExtra($invoiceFakturoidId, $price, $description); $result = $extras->addExtra($paymentId, $price, $description, $extraFakturoidId); $this->messages[] = $result; } } $this->redirect('checkUsers'); break; case 'addBlank': $userId = $extras->sanitize($_POST['userId']); $price = $extras->sanitize($_POST['price']); $description = $extras->sanitize($_POST['description']); $result = $extras->checkAddBlankValues($userId, $price, $description); if ($result['s'] == 'success') { $this->messages[] = $extras->addBlankExtra($userId, $price, $description); } else { $this->messages[] = $result; } $this->redirect('checkUsers'); break; case 'delete': $extraId = $parameters[1]; $status = $extras->getStatusOfPaymentFromExtraId($extraId); //allow add extra only when new payment will be generated or is blank if (!in_array($status, ['unpaid', 'refund', 'timeout', null])) { $this->messages[] = ['s' => 'error', 'cs' => 'Bohužel, položka nebyla zrušena; platba se právě platí nebo je již zaplacená', 'en' => 'Sorry, we cannot cancel an extra; payment is processing']; } else { $extraFakturoidId = $fakturoid->getExtraFakturoidId($extraId); $invoiceFakturoidId = $fakturoid->getInvoiceFakturoidIdFromExtraId($extraId); $fakturoid->deleteExtra($invoiceFakturoidId, $extraFakturoidId); $result = $extras->deleteExtra($extraId); $this->messages[] = $result; } $this->redirect('checkUsers'); break; default: $this->redirect('error'); } }