public function insert_into_db()
 {
     if (!$this->initialized) {
         return false;
     }
     if ($this->id) {
         return false;
     }
     $data = array('email' => $this->email, 'otp_code' => $this->otp_code, 'last_activity_time' => RM_Utilities::get_current_time(), 'created_date' => RM_Utilities::get_current_time());
     $data_specifiers = array('%s', '%s', '%s', '%s');
     $result = RM_DBManager::insert_row('FRONT_USERS', $data, $data_specifiers);
     if (!$result) {
         return false;
     }
     $this->id = $result;
     return $result;
 }
 public function charge($data, $pricing_details)
 {
     $curr_date = RM_Utilities::get_current_time();
     $stripe_api_key = $this->options->get_value_of('stripe_api_key');
     if ($stripe_api_key == null) {
         return false;
     }
     if ($pricing_details->total_price <= 0.0) {
         return true;
     }
     //Zero amount case.
     $global_options = new RM_Options();
     // Get the credit card details submitted by the form
     $error = '';
     $success = '';
     // Create the charge on Stripe's servers - this will charge the user's card
     $items = array();
     foreach ($pricing_details->billing as $detail) {
         $items[] = $detail->label;
     }
     $response = '';
     $items_str = implode(',', $items);
     try {
         \Stripe\Stripe::setApiKey($stripe_api_key);
         //sk_test_GsT4d690JZzbFk48w0GhsrIX
         $charge = \Stripe\Charge::create(array("amount" => $pricing_details->total_price * 100, "currency" => strtolower($this->currency), "source" => $data->stripeToken, "description" => $items_str));
         $response = $charge->getLastResponse();
         $response_body = json_decode($response->body);
     } catch (Stripe_InvalidRequestError $e) {
         return false;
     } catch (\Stripe\Error\Card $e) {
         //echo 'test'; die;
         $log_entry_id = RM_DBManager::insert_row('PAYPAL_LOGS', array('submission_id' => $data->submission_id, 'form_id' => $data->form_id, 'txn_id' => '', 'status' => 'Card Declined', 'total_amount' => $pricing_details->total_price, 'currency' => $this->currency, 'posted_date' => $curr_date), array('%d', '%d', '%s', '%s', '%f', '%s', '%s'));
         return false;
     }
     if ($response->code == "200") {
         $log_entry_id = RM_DBManager::insert_row('PAYPAL_LOGS', array('submission_id' => $data->submission_id, 'form_id' => $data->form_id, 'txn_id' => $response_body->balance_transaction, 'status' => $response_body->status, 'total_amount' => $pricing_details->total_price, 'currency' => $this->currency, 'posted_date' => $curr_date), array('%d', '%d', '%s', '%s', '%f', '%s', '%s'));
         return true;
     }
     return false;
 }
 public function charge($data, $pricing_details)
 {
     $form_id = $data->form_id;
     $this_script = get_permalink();
     if (false == $this_script) {
         $this_script = admin_url('admin-ajax.php?action=registrationmagic_embedform&form_id=' . $data->form_id);
     }
     $sign = strpos($this_script, '?') ? '&' : '?';
     $i = 1;
     foreach ($pricing_details->billing as $item) {
         $this->paypal->add_field('item_name_' . $i, $item->label);
         $i++;
     }
     $i = 1;
     $total_amount = 0.0;
     foreach ($pricing_details->billing as $item) {
         $this->paypal->add_field('amount_' . $i, $item->price);
         $total_amount += floatval($item->price);
         $i++;
     }
     $invoice = (string) date("His") . rand(1234, 9632);
     $this->paypal->add_field('business', $this->paypal_email);
     // Call the facilitator eaccount
     $this->paypal->add_field('cmd', '_cart');
     // cmd should be _cart for cart checkout
     $this->paypal->add_field('upload', '1');
     $this->paypal->add_field('return', $this_script . $sign . 'rm_pproc=success&rm_pproc_id=0');
     // return URL after the transaction got over
     $this->paypal->add_field('cancel_return', $this_script . $sign . 'rm_pproc=cancel&rm_pproc_id=0');
     // cancel URL if the trasaction was cancelled during half of the transaction
     $this->paypal->add_field('notify_url', $this_script . $sign . 'rm_pproc=ipn&rm_pproc_id=0');
     // Notify URL which received IPN (Instant Payment Notification)
     $this->paypal->add_field('currency_code', $this->currency);
     $this->paypal->add_field('invoice', $invoice);
     $this->paypal->add_field('page_style', $this->paypal_page_style);
     //Insert into PayPal log table
     $curr_date = RM_Utilities::get_current_time();
     //date_i18n(get_option('date_format'));
     if ($total_amount <= 0.0) {
         $log_entry_id = RM_DBManager::insert_row('PAYPAL_LOGS', array('submission_id' => $data->submission_id, 'form_id' => $form_id, 'invoice' => $invoice, 'status' => 'Completed', 'total_amount' => $total_amount, 'currency' => $this->currency, 'posted_date' => $curr_date), array('%d', '%d', '%s', '%s', '%f', '%s', '%s'));
         return true;
     } else {
         $log_entry_id = RM_DBManager::insert_row('PAYPAL_LOGS', array('submission_id' => $data->submission_id, 'form_id' => $form_id, 'invoice' => $invoice, 'status' => 'Pending', 'total_amount' => $total_amount, 'currency' => $this->currency, 'posted_date' => $curr_date), array('%d', '%d', '%s', '%s', '%f', '%s', '%s'));
     }
     if (isset($data->user_id)) {
         $cstm_data = $log_entry_id . "|" . $data->user_id;
     } else {
         $cstm_data = $log_entry_id . "|0";
     }
     $this->paypal->add_field('custom', $cstm_data);
     $this->paypal->add_field('return', $this_script . $sign . 'rm_pproc=success&rm_pproc_id=' . $log_entry_id);
     // return URL after the transaction got over
     $this->paypal->add_field('cancel_return', $this_script . $sign . 'rm_pproc=cancel&rm_pproc_id=' . $log_entry_id);
     // cancel URL if the trasaction was cancelled during half of the transaction
     $this->paypal->add_field('notify_url', $this_script . $sign . 'rm_pproc=ipn&rm_pproc_id=' . $log_entry_id);
     // Notify URL which received IPN (Instant Payment Notification)
     $this->paypal->submit_paypal_post();
     // POST it to paypal
     return 'do_not_redirect';
     //We do not want form redirect to work in case paypal processing is going on.
 }
 public function insert_into_db()
 {
     if (!$this->initialized) {
         return false;
     }
     if ($this->field_id) {
         return false;
     }
     if ($this->field_type == 'File' || $this->field_type == 'Repeatable') {
         return true;
     }
     $data = array('form_id' => $this->form_id, 'field_label' => $this->field_label, 'field_type' => $this->field_type, 'field_value' => $this->field_value, 'field_order' => $this->field_order, 'field_show_on_user_page' => $this->field_show_on_user_page, 'is_field_primary' => $this->is_field_primary ? $this->is_field_primary : 0, 'field_options' => $this->get_field_options());
     $data_specifiers = array('%d', '%s', '%s', '%s', '%d', '%d', '%d', '%s');
     $result = RM_DBManager::insert_row('FIELDS', $data, $data_specifiers);
     if (!$result) {
         return false;
     }
     $this->field_id = $result;
     return $result;
 }
 public function insert_into_db()
 {
     if (!$this->initialized) {
         return false;
     }
     if ($this->submission_id) {
         return false;
     }
     $this->unique_token = $this->form_id . time() . rand(100, 10000);
     $data = array('form_id' => $this->form_id, 'data' => $this->data, 'user_email' => $this->user_email, 'submitted_on' => date('Y-m-d H:i:s'), 'unique_token' => $this->unique_token);
     $data_specifiers = array('%d', '%s', '%s', '%s', '%s');
     $result = RM_DBManager::insert_row('SUBMISSIONS', $data, $data_specifiers);
     if (!$result) {
         return false;
     }
     $this->submission_id = $result;
     return $result;
 }
 public function insert_into_db($force = false)
 {
     if (!$this->initialized) {
         return false;
     }
     if (!$force && $this->sub_field_id) {
         return false;
     }
     $data = array('submission_id' => $this->submission_id, 'field_id' => $this->field_id, 'form_id' => $this->form_id, 'value' => $this->value);
     $data_specifiers = array('%d', '%d', '%d', '%s');
     $result = RM_DBManager::insert_row('SUBMISSION_FIELDS', $data, $data_specifiers);
     if (!$result) {
         return false;
     }
     $this->sub_field_id = $result;
     return $result;
 }
 public function insert_into_db()
 {
     if (!$this->initialized) {
         return false;
     }
     if ($this->note_id) {
         return false;
     }
     $data = array('submission_id' => $this->submission_id, 'notes' => $this->notes, 'status' => $this->status, 'publication_date' => RM_Utilities::get_current_time(), 'published_by' => get_current_user_id(), 'note_options' => maybe_serialize($this->note_options));
     $data_specifiers = array('%d', '%s', '%s', '%s', '%d', '%s');
     $result = RM_DBManager::insert_row('NOTES', $data, $data_specifiers);
     if (!$result) {
         return false;
     }
     $this->note_id = $result;
     return $this->note_id;
 }
 public function insert_into_db()
 {
     // echo (date('Y-m-d H:i:s'));die;
     if (!$this->initialized) {
         return false;
     }
     if ($this->form_id) {
         return false;
     }
     /*
      * If automatic role selection is enabled then disable manual options
      */
     if (count($this->form_options->form_should_user_pick) > 0) {
         $this->default_form_user_role = '';
     }
     $data = array('form_name' => $this->form_name, 'form_type' => $this->form_type, 'default_user_role' => $this->default_form_user_role, 'form_user_role' => $this->form_user_role, 'form_should_send_email' => $this->form_should_send_email, 'form_redirect' => $this->form_redirect, 'form_redirect_to_page' => $this->form_redirect_to_page, 'form_redirect_to_url' => $this->form_redirect_to_url, 'form_should_auto_expire' => $this->form_should_auto_expire, 'created_on' => date('Y-m-d H:i:s'), 'created_by' => get_current_user_id(), 'form_options' => maybe_serialize($this->form_options));
     $data_specifiers = array('%s', '%s', '%s', '%s', '%d', '%s', '%s', '%s', '%d', '%s', '%d', '%s');
     $result = RM_DBManager::insert_row('FORMS', $data, $data_specifiers);
     if (!$result) {
         return false;
     }
     $this->form_id = $result;
     return $this->form_id;
 }
 public function insert_into_db()
 {
     if (!$this->initialized) {
         return false;
     }
     if ($this->field_id) {
         return false;
     }
     $data = array('type' => $this->type, 'name' => $this->name, 'value' => $this->value, 'class' => $this->class, 'option_label' => $this->option_label, 'option_price' => $this->option_price, 'option_value' => $this->option_value, 'description' => $this->description, 'require' => $this->require, 'order' => $this->order, 'extra_options' => $this->extra_options);
     $data_specifiers = array('%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%d', '%s');
     $result = RM_DBManager::insert_row('PAYPAL_FIELDS', $data, $data_specifiers);
     if (!$result) {
         return false;
     }
     $this->field_id = $result;
     return $result;
 }
 public function process_payment($form_id, $reg_data, $service, $request)
 {
     //echo "<pre>"; var_dump($_GET); die;
     $payment_fields = array();
     foreach ($request->req as $field_name => $field_value) {
         if (substr($field_name, 0, 5) === 'Price') {
             $payment_fields[$field_name] = $field_value;
         }
     }
     //echo "<br>id= ".explode("_", $field_name)[2];
     //var_dump($payment_fields);
     //die;
     $sandbox = parent::get_setting('paypal_test_mode');
     $paypal_email = parent::get_setting('paypal_email');
     $currency = parent::get_setting('currency');
     $paypal_page_style = parent::get_setting('paypal_page_style');
     require_once plugin_dir_path(plugin_dir_path(__FILE__)) . 'external/PayPal/paypal.php';
     $p = new paypal_class();
     // paypal class
     if ($sandbox == 'yes') {
         $p->toggle_sandbox(true);
     } else {
         $p->toggle_sandbox(false);
     }
     $p->admin_mail = get_option('admin_email');
     // set notification email
     if (isset($request->req['rm_pproc'])) {
         switch ($request->req['rm_pproc']) {
             case 'success':
                 if (isset($request->req['rm_pproc_id'])) {
                     $log_id = $request->req['rm_pproc_id'];
                     $log = RM_DBManager::get_row('PAYPAL_LOGS', $log_id);
                     if ($log) {
                         if ($log->log) {
                             $paypal_log = maybe_unserialize($log->log);
                             $payment_status = $paypal_log['payment_status'];
                             if ($payment_status == 'Completed') {
                                 echo '<div id="rmform">';
                                 echo "<div class='rminfotextfront'>" . RM_UI_Strings::get("MSG_PAYMENT_SUCCESS") . "</br>";
                                 echo '</div></div>';
                                 return 'success';
                             } else {
                                 if ($payment_status == 'Denied' || $payment_status == 'Failed' || $payment_status == 'Refunded' || $payment_status == 'Reversed' || $payment_status == 'Voided') {
                                     echo '<div id="rmform">';
                                     echo "<div class='rminfotextfront'>" . RM_UI_Strings::get("MSG_PAYMENT_FAILED") . "</br>";
                                     echo '</div></div>';
                                     return 'failed';
                                 } else {
                                     if ($payment_status == 'In-Progress' || $payment_status == 'Pending' || $payment_status == 'Processed') {
                                         echo '<div id="rmform">';
                                         echo "<div class='rminfotextfront'>" . RM_UI_Strings::get("MSG_PAYMENT_PENDING") . "</br>";
                                         echo '</div></div>';
                                         return 'pending';
                                     } else {
                                         if ($payment_status == 'Canceled_Reversal') {
                                             return 'canceled_reversal';
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
                 return false;
             case 'cancel':
                 echo '<div id="rmform">';
                 echo "<div class='rminfotextfront'>" . RM_UI_Strings::get("MSG_PAYMENT_CANCEL") . "</br>";
                 echo '</div></div>';
                 return;
             case 'ipn':
                 $trasaction_id = $_POST["txn_id"];
                 $payment_status = $_POST["payment_status"];
                 $cstm = $_POST["custom"];
                 $abcd = explode("|", $cstm);
                 $user_id = (int) $abcd[1];
                 $acbd = explode("|", $cstm);
                 $log_entry_id = (int) $acbd[0];
                 //$_POST["custom"];
                 $log_array = maybe_serialize($_POST);
                 $curr_date = RM_Utilities::get_current_time();
                 // date_i18n(get_option('date_format'));
                 RM_DBManager::update_row('PAYPAL_LOGS', $log_entry_id, array('status' => $payment_status, 'txn_id' => $trasaction_id, 'posted_date' => $curr_date, 'log' => $log_array), array('%s', '%s', '%s', '%s'));
                 if ($p->validate_ipn()) {
                     //IPN is valid, check payment status and process logic
                     if ($payment_status == 'Completed') {
                         if ($user_id) {
                             $gopt = new RM_Options();
                             $this->user_service->activate_user_by_id($user_id);
                         }
                         return 'success';
                     } else {
                         if ($payment_status == 'Denied' || $payment_status == 'Failed' || $payment_status == 'Refunded' || $payment_status == 'Reversed' || $payment_status == 'Voided') {
                             return 'failed';
                         } else {
                             if ($payment_status == 'In-Progress' || $payment_status == 'Pending' || $payment_status == 'Processed') {
                                 return 'pending';
                             } else {
                                 if ($payment_status == 'Canceled_Reversal') {
                                     return 'canceled_reversal';
                                 }
                             }
                         }
                     }
                     //Send mail notifications about payment success.
                     /* $recipients = parent::get_setting('admin_email');
                     
                                               if ($recipients)
                                               {
                                               $recipients = explode(',', $recipients);
                     
                                               foreach ($recipients as $recipient)
                                               {
                                               $p->send_report($recipient);
                                               }
                                               } */
                     return 'unknown';
                 }
                 return 'invalid_ipn';
         }
         //return;
     }
     $paypal_field = new RM_PayPal_Fields();
     $prices = array();
     $item_names = array();
     foreach ($payment_fields as $pf_name => $pf_value) {
         $abe = explode("_", $pf_name);
         $paypal_field->load_from_db((int) $abe[2]);
         switch ($paypal_field->get_type()) {
             case "fixed":
                 $prices[] = $paypal_field->get_value();
                 $item_names[] = $paypal_field->get_name();
                 break;
             case "userdef":
                 if ($pf_value == "") {
                     break;
                 }
                 $prices[] = $pf_value;
                 $item_names[] = $paypal_field->get_name();
                 break;
             case "multisel":
                 $tmp_v = maybe_unserialize($paypal_field->get_option_price());
                 $tmp_l = maybe_unserialize($paypal_field->get_option_label());
                 foreach ($pf_value as $pf_single_val) {
                     $index = (int) substr($pf_single_val, 1);
                     if (!isset($tmp_v[$index])) {
                         continue;
                     }
                     $prices[] = $tmp_v[$index];
                     $item_names[] = $tmp_l[$index];
                 }
                 break;
             case "dropdown":
                 $tmp_v = maybe_unserialize($paypal_field->get_option_price());
                 $tmp_l = maybe_unserialize($paypal_field->get_option_label());
                 //Check whether dropdown was not submitted
                 if (!$pf_value) {
                     break;
                 }
                 $index = (int) substr($pf_value, 1);
                 if (!isset($tmp_v[$index])) {
                     break;
                 }
                 $prices[] = $tmp_v[$index];
                 $item_names[] = $tmp_l[$index];
                 break;
         }
     }
     /*
      echo "<br><br>========  names =============<br><br>";
      var_dump($item_names);
      echo "<br><br>========  prices =============<br><br>";
      var_dump($prices);
      die;
     */
     $this_script = get_permalink();
     $sign = strpos($this_script, '?') ? '&' : '?';
     $i = 1;
     foreach ($item_names as $item_name) {
         $p->add_field('item_name_' . $i, $item_name);
         $i++;
     }
     $i = 1;
     $total_amount = 0.0;
     foreach ($prices as $price) {
         $p->add_field('amount_' . $i, $price);
         $total_amount += floatval($price);
         $i++;
     }
     $invoice = (string) date("His") . rand(1234, 9632);
     $p->add_field('business', $paypal_email);
     // Call the facilitator eaccount
     $p->add_field('cmd', '_cart');
     // cmd should be _cart for cart checkout
     $p->add_field('upload', '1');
     $p->add_field('return', $this_script . $sign . 'rm_pproc=success&rm_pproc_id=');
     // return URL after the transaction got over
     $p->add_field('cancel_return', $this_script . $sign . 'rm_pproc=cancel');
     // cancel URL if the trasaction was cancelled during half of the transaction
     $p->add_field('notify_url', $this_script . $sign . 'rm_pproc=ipn');
     // Notify URL which received IPN (Instant Payment Notification)
     $p->add_field('currency_code', $currency);
     $p->add_field('invoice', $invoice);
     $p->add_field('page_style', $paypal_page_style);
     //Insert into PayPal log table
     $curr_date = RM_Utilities::get_current_time();
     //date_i18n(get_option('date_format'));
     if ($total_amount <= 0.0) {
         $log_entry_id = RM_DBManager::insert_row('PAYPAL_LOGS', array('submission_id' => $reg_data->submission_id, 'form_id' => $form_id, 'invoice' => $invoice, 'status' => 'Completed', 'total_amount' => $total_amount, 'currency' => $currency, 'posted_date' => $curr_date), array('%d', '%d', '%s', '%s', '%f', '%s', '%s'));
         return 'zero_amount';
     } else {
         $log_entry_id = RM_DBManager::insert_row('PAYPAL_LOGS', array('submission_id' => $reg_data->submission_id, 'form_id' => $form_id, 'invoice' => $invoice, 'status' => 'Pending', 'total_amount' => $total_amount, 'currency' => $currency, 'posted_date' => $curr_date), array('%d', '%d', '%s', '%s', '%f', '%s', '%s'));
     }
     $p->add_field('custom', $log_entry_id . "|" . $reg_data->user_id);
     $p->add_field('return', $this_script . $sign . 'rm_pproc=success&rm_pproc_id=' . $log_entry_id);
     // return URL after the transaction got over
     $p->add_field('cancel_return', $this_script . $sign . 'rm_pproc=cancel&rm_pproc_id=' . $log_entry_id);
     // cancel URL if the trasaction was cancelled during half of the transaction
     $p->add_field('notify_url', $this_script . $sign . 'rm_pproc=ipn');
     // Notify URL which received IPN (Instant Payment Notification)
     $p->submit_paypal_post();
     // POST it to paypal
     //$p->dump_fields();
 }
 public function create_stat_entry($params)
 {
     $form_id = (int) $params['form_id'];
     $visited_on = time();
     $user_ip = $this->get_user_ip();
     if ($user_ip == null) {
         die("Unauthorised request. Access denied.");
     }
     if (isset($_SERVER['HTTP_USER_AGENT'])) {
         $ua_string = $_SERVER['HTTP_USER_AGENT'];
     } else {
         $ua_string = "no_user_agent_found";
     }
     require_once plugin_dir_path(plugin_dir_path(__FILE__)) . 'external/Browser/Browser.php';
     $browser = new RM_Browser($ua_string);
     $browser_name = $browser->getBrowser();
     return RM_DBManager::insert_row('STATS', array('form_id' => $form_id, 'user_ip' => $user_ip, 'ua_string' => $ua_string, 'browser_name' => $browser_name, 'visited_on' => $visited_on), array('%d', '%s', '%s', '%s'));
 }