Exemple #1
0
 public function create()
 {
     // Only for logged users
     if (!$this->auth->isLogged()) {
         $this->security_log->write('Try to order product from guest request');
         exit;
     }
     // Check request
     if (!$this->request->isAjax()) {
         $this->security_log->write('Try to order product without ajax request');
         exit;
     }
     // Check dependencies
     if (!isset($this->request->post['product_id'])) {
         $this->security_log->write('Try to order product without product_id parameter');
         exit;
     }
     // Check dependencies
     if (!isset($this->request->post['license']) || !in_array($this->request->post['license'], array('regular', 'exclusive'))) {
         $this->security_log->write('Try to order product without license parameter');
         exit;
     }
     // Try to get product
     if (!($product_info = $this->model_catalog_product->getProduct((int) $this->request->post['product_id'], $this->language->getId(), $this->auth->getId(), ORDER_APPROVED_STATUS_ID))) {
         $this->security_log->write('Try to order not exists product');
         exit;
     }
     // Try to get denied product
     if (!$product_info->status) {
         $this->security_log->write('Try to order product ' . (int) $this->request->post['product_id'] . ' with status ' . $product_info->status);
         exit;
     }
     // Check if product already ordered
     if ($product_info->order_status_id == ORDER_APPROVED_STATUS_ID) {
         $this->security_log->write('Try to order ordered product');
         exit;
     }
     // Check if order self product
     if ($product_info->user_id == $this->auth->getId()) {
         $this->security_log->write('Try to order self product');
         exit;
     }
     // Check regular price
     if ($this->request->post['license'] == 'regular' && ($product_info->regular_price > 0 || $product_info->special_regular_price > 0)) {
         $amount = (double) $product_info->special_regular_price > 0 ? $product_info->special_regular_price : $product_info->regular_price;
         // Check exclusive price
     } else {
         if ($this->request->post['license'] == 'exclusive' && ($product_info->exclusive_price > 0 || $product_info->special_exclusive_price > 0)) {
             $amount = (double) $product_info->special_exclusive_price > 0 ? $product_info->special_exclusive_price : $product_info->exclusive_price;
             // License parameter error
         } else {
             $this->security_log->write('Try to purchase product by undefined license');
             exit;
         }
     }
     // Init variables
     $json = array('status' => false);
     // Create a new order in DB
     if (!($order_id = $this->model_common_order->createOrder($this->auth->getId(), $product_info->product_id, $this->request->post['license'], $amount, FEE_PER_ORDER, ORDER_PENDING_STATUS_ID, DEFAULT_CURRENCY_ID))) {
         $this->security_log->write('Can not create the order');
         exit;
     }
     // Generate label
     $label = sprintf('%s Order #%s', PROJECT_NAME, $order_id);
     // Get order address if exists
     $order_info = $this->model_common_order->getOrder($order_id);
     if ($order_info->address) {
         $address = $order_info->address;
         // Create a new BitCoin Address
     } else {
         try {
             $electrum = new Electrum(ELECTRUM_RPC_HOST, ELECTRUM_RPC_PORT);
             $response = $electrum->addrequest(array('amount' => $amount, 'memo' => $label, 'force' => true));
             if (isset($response['result']['address'])) {
                 $address = $response['result']['address'];
                 $this->model_common_order->updateAddress($order_id, $address);
             } else {
                 $this->security_log->write($response);
             }
         } catch (Exception $e) {
             $this->security_log->write($e->getMessage());
         }
     }
     if (isset($address)) {
         $json = array('status' => true, 'address' => $address, 'amount' => $amount, 'label' => $label, 'text' => sprintf(tt('Send %s or more to this address:'), $this->currency->format($amount)), 'href' => sprintf('bitcoin:%s?amount=%s&label=%s', $address, $amount, $label), 'src' => $this->url->link('common/image/qr', 'code=' . $address), 'amounts' => array(array('label' => $this->currency->format($amount_1 = round($amount + $amount * 10 / 100, 4)), 'amount' => $amount_1, 'href' => sprintf('bitcoin:%s?amount=%s&label=%s', $address, $amount_1, $label)), array('label' => $this->currency->format($amount_2 = round($amount + $amount * 25 / 100, 4)), 'amount' => $amount_2, 'href' => sprintf('bitcoin:%s?amount=%s&label=%s', $address, $amount_2, $label)), array('label' => $this->currency->format($amount_3 = round($amount + $amount * 50 / 100, 4)), 'amount' => $amount_3, 'href' => sprintf('bitcoin:%s?amount=%s&label=%s', $address, $amount_3, $label)), array('label' => $this->currency->format($amount_4 = round($amount + $amount * 100 / 100, 4)), 'amount' => $amount_4, 'href' => sprintf('bitcoin:%s?amount=%s&label=%s', $address, $amount_4, $label))));
     }
     $this->response->addHeader('Content-Type: application/json');
     $this->response->setOutput(json_encode($json));
 }
Exemple #2
0
 public function verification()
 {
     // Redirect if user is not logged
     if (!$this->auth->isLogged()) {
         $this->response->redirect($this->url->link('account/account/login', 'redirect=' . urlencode($this->url->getCurrentLink())));
     }
     // Redirect if user is already verified
     if ($this->auth->isVerified()) {
         $this->response->redirect($this->url->link('account/account'));
     }
     $this->document->setTitle(tt('Account verification'));
     $data = array();
     $code = md5(PROJECT_NAME . $this->auth->getId());
     // Get verification address if exists
     $user_info = $this->model_account_user->getUser($this->auth->getId());
     if ($user_info->verification_address) {
         $address = $user_info->verification_address;
         // Create a new BitCoin Address
     } else {
         try {
             $electrum = new Electrum(ELECTRUM_RPC_HOST, ELECTRUM_RPC_PORT);
             $response = $electrum->addrequest(array('amount' => FEE_USER_VERIFICATION, 'memo' => sprintf('Verification Request for Account ID %s', $this->auth->getId()), 'force' => true));
             if (isset($response['result']['address'])) {
                 $address = $response['result']['address'];
                 $this->model_account_user->updateVerificationAddress($this->auth->getId(), $address);
             } else {
                 $this->security_log->write($response);
             }
         } catch (Exception $e) {
             $this->security_log->write($e->getMessage());
         }
     }
     if ('POST' == $this->request->getRequestMethod() && $this->_validateVerification()) {
         // Save verification request into the DB
         if ($this->model_account_user->addVerificationRequest($this->auth->getId(), $this->currency->getId(), FEE_USER_VERIFICATION, 'pending', $code, $this->request->post['proof'])) {
             // Add notification
             if ($user_notification_id = $this->model_account_notification->addNotification($this->auth->getId(), 'common')) {
                 // Add notification description for each system language
                 foreach ($this->_languages as $language_id => $code) {
                     $translation = $this->language->loadTranslation($language_id);
                     $this->model_account_notification->addNotificationDescription($user_notification_id, $language_id, tt('Your verification request was sent successfully', $translation), tt('We will process the request as quickly as possible.', $translation));
                 }
             }
             // Admin alert
             $this->mail->setFrom($this->auth->getEmail());
             $this->mail->setSender($this->auth->getEmail());
             $this->mail->setTo(MAIL_EMAIL_SUPPORT_ADDRESS);
             $this->mail->setSubject(sprintf(tt('Account Verification Request - %s'), PROJECT_NAME));
             $this->mail->setText(tt('A new verification was requested.'));
             $this->mail->send();
             // Success message
             $this->session->setUserMessage(array('success' => tt('Your verification request was sent successfully!')));
         }
     }
     $data['error'] = $this->_error;
     $data['action'] = $this->url->link('account/account/verification');
     $data['proof'] = isset($this->request->post['proof']) ? $this->request->post['proof'] : false;
     $data['accept_1'] = isset($this->request->post['accept_1']) ? $this->request->post['accept_1'] : false;
     $data['accept_2'] = isset($this->request->post['accept_2']) ? $this->request->post['accept_2'] : false;
     // Step 1
     if (isset($address)) {
         $data['payment_instruction'] = sprintf(tt('Send exactly %s to this address:'), $this->currency->format(FEE_USER_VERIFICATION));
         $data['payment_address'] = $address;
         $data['payment_qr_href'] = $this->url->link('common/image/qr', 'code=' . $address);
         $data['payment_wallet_href'] = sprintf('bitcoin:%s?amount=%s&label=%s Verification Request for Account ID %s', $address, FEE_USER_VERIFICATION, PROJECT_NAME, $this->auth->getId());
     }
     // Step 3
     $data['confirmation_code'] = $code;
     $data['href_cancel'] = $this->url->link('account/account');
     $data['footer'] = $this->load->controller('common/footer');
     $data['header'] = $this->load->controller('common/header');
     $data['alert_danger'] = $this->load->controller('common/alert/danger');
     $data['alert_success'] = $this->load->controller('common/alert/success');
     $data['alert_warning'] = $this->load->controller('common/alert/warning');
     $data['module_account'] = $this->load->controller('module/account');
     $data['module_breadcrumbs'] = $this->load->controller('module/breadcrumbs', array(array('name' => tt('Home'), 'href' => $this->url->link('common/home'), 'active' => false), array('name' => tt('Account'), 'href' => $this->url->link('account/account'), 'active' => false), array('name' => tt('Verification'), 'href' => $this->url->link('account/account/verification'), 'active' => true)));
     // Renter the template
     $this->response->setOutput($this->load->view('account/account/verification.tpl', $data));
 }