public function callback($payment_status, $rm_pproc_id) { switch ($payment_status) { case 'success': if ($rm_pproc_id) { $log_id = $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 ($this->paypal->validate_ipn()) { //IPN is valid, check payment status and process logic if ($payment_status == 'Completed') { if ($user_id) { $gopt = new RM_Options(); if ($gopt->get_value_of('user_auto_approval') == "yes") { $user_service = new RM_User_Services(); $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'; } } } } return 'unknown'; } return 'invalid_ipn'; } }
public function load_from_db($submission_id, $should_set_id = true) { $result = RM_DBManager::get_row('SUBMISSIONS', $submission_id); if (null !== $result) { if ($should_set_id) { $this->submission_id = $submission_id; } $this->form_id = $result->form_id; $this->data = $result->data; $this->user_email = $result->user_email; $this->submitted_on = $result->submitted_on; $this->unique_token = $result->unique_token; } else { return false; } return true; }
public function load_from_db($field_id, $should_set_id = true) { $result = RM_DBManager::get_row('FIELDS', $field_id); if (null !== $result) { if ($should_set_id) { $this->field_id = $field_id; } else { $this->field_id = null; } $this->form_id = $result->form_id; $this->field_label = $result->field_label; $this->field_type = $result->field_type; $this->field_value = $result->field_value; $this->field_order = $result->field_order; $this->is_field_primary = $result->is_field_primary; $this->field_show_on_user_page = $result->field_show_on_user_page; $this->set_field_options($result->field_options); } else { return false; } $this->initialized = true; return true; }
public function load_from_db($sub_field_id, $should_set_id = true) { $result = RM_DBManager::get_row('SUBMISSION_FIELDS', $sub_field_id); if (null !== $result) { if ($should_set_id) { $this->sub_field_id = $sub_field_id; } $this->submission_id = $result['submission_id']; $this->field_id = $result['field_id']; $this->value = $result['value']; $this->form_id = $result['form_id']; } else { return false; } return true; }
public function load_from_db($id, $should_set_id = true) { $result = RM_DBManager::get_row('FRONT_USERS', $field_id); if (null !== $result) { if ($should_set_id) { $this->id = $id; } else { $this->field_id = null; } $this->email = $result['email']; $this->otp_code = $result['otp_code']; $this->last_activity_time = $result['last_activity_time']; $this->created_date = $result['created_date']; } else { return false; } $this->initialized = true; return true; }
public function load_from_db($note_id, $should_set_id = true) { $result = RM_DBManager::get_row('NOTES', $note_id); if (null !== $result) { if ($should_set_id) { $this->note_id = $note_id; } else { $this->note_id = null; } $this->submission_id = $result->submission_id; $this->notes = $result->notes; // $this->type = $result->type; $this->status = $result->status; $this->publication_date = $result->publication_date; $this->published_by = $result->published_by; $this->last_edit_date = $result->last_edit_date; $this->last_edited_by = $result->last_edited_by; $this->note_options = maybe_unserialize($result->note_options); } else { return false; } $this->initialized = true; return true; }
public function load_from_db($form_id, $should_set_id = true) { $result = RM_DBManager::get_row('FORMS', $form_id); //var_dump($result); die; if (null !== $result) { if ($should_set_id) { $this->form_id = $form_id; } else { $this->form_id = null; } $this->form_name = $result->form_name; $this->form_type = $result->form_type; $this->default_form_user_role = $result->default_user_role; $this->form_user_role = $result->form_user_role; $this->form_should_send_email = $result->form_should_send_email; $this->form_redirect = $result->form_redirect; $this->form_redirect_to_page = $result->form_redirect_to_page; $this->form_redirect_to_url = $result->form_redirect_to_url; $this->form_should_auto_expire = $result->form_should_auto_expire; $this->created_on = $result->created_on; $this->created_by = $result->created_by; $this->modified_on = $result->modified_on; $this->modified_by = $result->modified_by; $this->set_form_options($result->form_options); } else { //die("in_form_model"); return false; } $this->initialized = true; return true; }
public function load_from_db($field_id, $should_set_id = true) { $result = RM_DBManager::get_row('PAYPAL_FIELDS', $field_id); //var_dump($result);die; if (null !== $result) { if ($should_set_id) { $this->field_id = $field_id; } else { $this->field_id = null; } $this->type = $result->type; $this->name = $result->name; $this->value = $result->value; $this->class = $result->class; $this->option_label = $result->option_label; $this->option_price = $result->option_price; $this->option_value = $result->option_value; $this->description = $result->description; $this->require = $result->require; $this->order = $result->order; $this->extra_options = $result->extra_options; } else { return false; } $this->initialized = true; return true; }
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 is_browser_reload_duplication($stat_id) { //Not browser reload related, but if stat_id is not set then form submission is not valid or // it is just form creation, hence prevent submission. if ($stat_id === null) { return true; } $stat_entry = RM_DBManager::get_row('STATS', $stat_id); if ($stat_entry) { if ($stat_entry->submitted_on == null) { return false; } else { return true; } } return true; //No entry found in db, prevent submission. }