$options = $field_data->field_value;
     }
 } else {
     $options = null;
 }
 if (isset($field_data->field_options)) {
     $field_data->field_options = maybe_unserialize($field_data->field_options);
 }
 //var_dump($data->form->form_options);die;
 if ($field_data->field_type === 'HTMLH' || $field_data->field_type === 'HTMLP') {
     $form->addElement(new $element_class($options));
 } elseif ($field_data->field_type == 'Price') {
     //$options = array("paypal_field_id"=>$options);
     $price_field_id = (int) $field_data->field_value;
     //////////// New APppPPPPPPpPPppPPPPpp
     $paypal_field = new RM_PayPal_Fields();
     $res = $paypal_field->load_from_db($price_field_id);
     if (!$res) {
         $options = null;
         continue;
     }
     $form->addElement(new Element_Hidden('rm_payment_form', $options));
     // echo "<pre>", var_dump($field_data->properties),"</pre>";
     $properties = array();
     if (isset($field_data->properties['required'])) {
         $properties['required'] = '1';
     }
     //echo '<pre>'; var_dump($field_data); die;
     switch ($paypal_field->get_type()) {
         case "fixed":
             if ($data->currency_pos == 'before') {
 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();
 }
         $options = $field_data->field_value;
     }
 } else {
     $options = null;
 }
 if (isset($field_data->field_options)) {
     $field_data->field_options = maybe_unserialize($field_data->field_options);
 }
 //var_dump($data->form->form_options);die;
 if ($field_data->field_type === 'HTMLH' || $field_data->field_type === 'HTMLP') {
     $form->addElement(new $element_class($options));
 } elseif ($field_data->field_type == 'Price') {
     //$options = array("paypal_field_id"=>$options);
     $price_field_id = (int) $field_data->field_value;
     //////////// New APppPPPPPPpPPppPPPPpp
     $paypal_field = new RM_PayPal_Fields();
     $res = $paypal_field->load_from_db($price_field_id);
     if (!$res) {
         $options = null;
         continue;
     }
     $form->addElement(new Element_Hidden('rm_payment_form', $options));
     // echo "<pre>", var_dump($field_data->properties),"</pre>";
     $properties = array();
     if (isset($field_data->properties['required'])) {
         $properties['required'] = '1';
     }
     //echo '<pre>'; var_dump($field_data); die;
     switch ($paypal_field->get_type()) {
         case "fixed":
             if ($data->currency_pos == 'before') {
 public function get_pricing_detail($request)
 {
     $paypal_field = new RM_PayPal_Fields();
     $res = $paypal_field->load_from_db($this->pp_field_id);
     if (!$res) {
         return null;
     }
     $total_price = 0.0;
     $billing = array();
     switch ($paypal_field->get_type()) {
         case "fixed":
             $total_price = floatval($paypal_field->get_value());
             $billing[] = (object) array('label' => $paypal_field->get_name(), 'price' => $total_price);
             break;
     }
     $value = (object) array('billing' => $billing, 'total_price' => $total_price);
     return $value;
 }