prefix . ONE1APP_1APPPF_1APP_TABLE; $charset_collate = $wpdb->get_charset_collate(); $sql = "CREATE TABLE IF NOT EXISTS `" . $table_name . "` ( id int(11) NOT NULL AUTO_INCREMENT, post_id int(11) NOT NULL, user_id int(11) NOT NULL, fullname varchar(255) DEFAULT '' NOT NULL, email varchar(255) DEFAULT '' NOT NULL, phone varchar(255) DEFAULT '' NOT NULL, metadata text, paid int(1) NOT NULL DEFAULT '0', plan varchar(255) DEFAULT '' NOT NULL, txn_code varchar(255) DEFAULT '' NOT NULL, txn_code_2 varchar(255) DEFAULT '' NOT NULL, amount varchar(255) DEFAULT '' NOT NULL, ip varchar(255) NOT NULL, deleted_at varchar(255) DEFAULT '' NULL, created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, paid_at timestamp, modified timestamp DEFAULT '0000-00-00 00:00:00' NOT NULL, UNIQUE KEY id (id),PRIMARY KEY (id) ) $charset_collate;"; include_once ABSPATH . 'wp-admin/includes/upgrade.php'; dbDelta($sql); } function one1app_disconnect1app() { } register_activation_hook( __FILE__, 'one1app_connect1app' ); register_deactivation_hook( __FILE__, 'one1app_disconnect1app' ); $plugin_name = plugin_basename(__FILE__); add_filter( 'plugin_action_links_'.$plugin_name, 'one1app_mainSettingsPage'); function one1app_mainSettingsPage($links) { $setting_link = "Settings"; array_push($links, $setting_link); return $links; } function one1app_oneapp_add_scripts_styles() { wp_enqueue_style( 'one1app-oneapp-pay-styles', plugins_url( 'css/style.css', __FILE__ ), '', rand() ); wp_enqueue_script('onee1app_oneapp_jscripts', plugins_url( 'js/script.js', __FILE__ ), array(), rand(), true); } add_action( 'admin_enqueue_scripts', 'one1app_oneapp_add_scripts_styles' ); function one1app_oneapp_publicc_add_scripts_styles() { wp_enqueue_style( 'one1app-oneapp-publicc-pay-styles', plugins_url( 'css/style.css', __FILE__ ), '', rand() ); wp_enqueue_script('onee1app_oneapp_publicc_jscripts', plugins_url( 'js/script.js', __FILE__ ), array(), rand(), true); } add_action( 'wp_enqueue_scripts', 'one1app_oneapp_publicc_add_scripts_styles' ); function one1app_settingsPage() { echo "
".esc_html('Connect to your 1app Business Account.')."
".esc_html("Get your Secret Key")." ".esc_html("here")."
"; if(isset($_POST['connect']) && !empty($_POST['secret']) && !empty($_POST['site_url'])) { $secret = sanitize_text_field($_POST['secret']); $site_path = site_url(); if(isset(explode('//', $site_path)[1])) { $site_url = explode('//', $site_path)[1]; } elseif(!isset(explode('//', $site_path)[1])) { $site_url = site_url(); } $args = array( 'headers' => array( 'Authorization' => 'Bearer ' .$secret ) ); $response = wp_remote_get( 'https://api.1app.online/v2/verifyapikey', $args ); $body = wp_remote_retrieve_body( $response ); $newRes = json_decode($body, true); if($newRes['status'] == true) { $business_id = $newRes['business_id']; $basecode = '1app'.uniqid(); $body = array( 'secretkey' => $secret, 'basecode' => $basecode, 'path' => $site_url, 'business_id' => $business_id, ); $args = array( 'body' => $body, 'timeout' => '5', 'redirection' => '5', 'httpversion' => '1.0', 'blocking' => true, 'headers' => array(), 'cookies' => array(), ); $resp = wp_remote_post( 'https://api.1app.online/v2/connectplugin', $args ); $bodyresp = wp_remote_retrieve_body( $response ); $newResp = json_decode($bodyresp, true); if($newResp['status'] == true) { echo ''.esc_html('Account connected successfully!').'
'.esc_html('Could not connect! Try again.').'
'.esc_html('Invalid secret key!').'
'.esc_html('Account successfully disconnected!').'
'.esc_html('Account could not be disconnected!').'
'.esc_html('Kindly go to').' '.esc_html('settings').' '.esc_html('to connect to your 1app business account or create a 1app business account').' '.esc_html('here').'
post_type == '1app_form') { $amount = get_post_meta($id, '_amount', true); $exampleListTable = new one1app_1apppf_1app_Payments_List_Table(); $data = $exampleListTable->prepare_items(); ?>
All payments made for this form:
'.esc_html('Amount (Leave as 0 if the customer is to input this):').'
'; echo ''; echo "".esc_html($desc)."
"; } if(isset($_GET['err']) && !empty($_GET['err']) && isset($_GET['id']) && !empty($_GET['id']) ) { if($id == $_GET['id']) { global $wp; $c_pg = home_url( $wp->request ); $n_pg = explode('?' ,$c_pg)[0]; echo '';
$untouchedmetadata = one1app_1apppf_1app_meta_as_custom_fields($metadata);
$fixedmetadata = [];
// print_r($fixedmetadata );
$currency = get_post_meta(sanitize_text_field($_POST["pf-id"]), '_currency', true);
$formamount = get_post_meta(sanitize_text_field($_POST["pf-id"]), '_amount', true); /// From form
$amount = (int) str_replace(' ', '', sanitize_text_field($_POST["pf-amount"]));
$originalamount = $amount;
// if (($recur == 'no') && ($formamount != 0)) {
// $amount = (int) str_replace(' ', '', $formamount);
// }
$fixedmetadata[] = array(
'display_name' => 'Unit Price',
'variable_name' => 'Unit_Price',
'type' => 'text',
'value' => $currency . number_format($amount)
);
//--------------------------------------
$fixedmetadata = json_decode(json_encode($fixedmetadata, JSON_NUMERIC_CHECK), true);
$fixedmetadata = array_merge($untouchedmetadata, $fixedmetadata);
$insert = array(
'post_id' => sanitize_text_field($_POST["pf-id"]),
'fullname' => sanitize_text_field($_POST["pf-fname"]).' '.sanitize_text_field($_POST["pf-lname"]),
'email' => sanitize_text_field($_POST["pf-pemail"]),
'phone' => sanitize_text_field($_POST["pf-pphone"]),
'amount' => sanitize_text_field($amount),
'ip' => one1app_1apppf_1app_get_the_user_ip(),
'txn_code' => $code,
//'metadata' => 'metadata'
'metadata' => json_encode($fixedmetadata)
);
$exist = $wpdb->get_results(
"SELECT * FROM $table WHERE (post_id = '" . $insert['post_id'] . "'
AND fullname = '" .$insert['fullname'] . "'
AND email = '" . $insert['email'] . "'
AND phone = '" . $insert['phone'] . "'
AND amount = '" . $insert['amount'] . "'
AND ip = '" . $insert['ip'] . "'
AND paid = '0'
AND metadata = '" . $insert['metadata'] . "')"
);
if (count($exist) > 0) {
// $insert['txn_code'] = $code;
// $insert['plan'] = $exist[0]->plan;
$wpdb->update($table, array('txn_code' => $code, 'modified' => date("Y-m-d h:i:s")), array('id' => $exist[0]->id));
}
else {
$wpdb->insert(
$table,
$insert
);
}
$amount = floatval($insert['amount']) * 100;
$response = array(
'result' => 'success',
'code' => $insert['txn_code'],
'email' => $insert['email'],
'name' => $fullname,
'total' => round($amount),
'currency' => $currency,
'custom_fields' => $fixedmetadata
);
//initiate payment
if($response['result'] == 'success') {
$site_path = site_url();
if(isset(explode('//', $site_path)[1])) {
$site_url = explode('//', $site_path)[1];
}
elseif(!isset(explode('//', $site_path)[1])) {
$site_url = site_url();
}
//get business ID
$responsecp = wp_remote_get( 'https://api.1app.online/v2/checkplugin-connect?path='.$site_url );
$bodycp = wp_remote_retrieve_body( $responsecp );
$res_check = json_decode($bodycp, true);
if($res_check['status'] == true) {
$c_bid = $res_check['businessid'];
$body = array(
'reference' => $code,
'amount' => $insert['amount'],
'customer_email' => $insert['email'],
'currency' => sanitize_text_field($_POST["pf-currency"]),
'site_url' => $site_url,
'business_id' => $c_bid,
'phn' => $insert['phone'],
'fname' => $fname,
'lname' => $lname,
'redirecturl' => sanitize_text_field($_POST['pf-page']).'?id='.sanitize_text_field($_POST["pf-id"]),
);
$args = array(
'body' => $body,
'timeout' => '5',
'redirection' => '5',
'httpversion' => '1.0',
'blocking' => true,
'headers' => array(),
'cookies' => array(),
);
$respip = wp_remote_post( 'https://api.1app.online/v2/initiatepay', $args );
$bodyip = wp_remote_retrieve_body( $respip );
$d_res = json_decode($bodyip, true);
if($d_res['status'] == true) {
$access_token = $d_res['access_token'];
$ref_1app_pay = $d_res['reference'];
header('location: '.$d_res['authorization_url']);
}
else {
wp_redirect(sanitize_text_field($_POST['pf-page']).'?initiatepay=false&id='.sanitize_text_field($_POST['pf-id']));
}
}
}
}
}
function one1app_1apppf_1app_meta_as_custom_fields($metadata)
{
$custom_fields = array();
foreach ($metadata as $key => $value) {
if (is_array($value)) {
$value = implode(', ', $value);
}
if ($key == 'pf-fname') {
$custom_fields[] = array(
'display_name' => 'Full Name',
'variable_name' => 'Full_Name',
'type' => 'text',
'value' => $value
);
}
else {
$custom_fields[] = array(
'display_name' => ucwords(str_replace("_", " ", $key)),
'variable_name' => $key,
'type' => 'text',
'value' => (string) $value
);
}
}
return $custom_fields;
}
// add_action('wp_ajax_kkd_1apppf_1app_confirm_payment', 'one1app_1apppf_1app_confirm_payment');
// add_action('wp_ajax_nopriv_kkd_1apppf_1app_confirm_payment', 'one1app_1apppf_1app_confirm_payment');
// function one1app_1apppf_1app_confirm_payment() {
// }
function format_data($data)
{
$new = json_decode($data);
$text = '';
if (array_key_exists("0", $new)) {
foreach ($new as $key => $item) {
if ($item->type == 'text') {
$text .= '' . $item->display_name . ": " . $item->value . "
";
} else {
$text .= '' . $item->display_name . ": link
";
}
}
} else {
$text = '';
if (count($new) > 0) {
foreach ($new as $key => $item) {
$text .= '' . $key . ": " . $item . "
";
}
}
}
//
return $text;
}
if (!class_exists('WP_List_Table')) {
include_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php';
}
class one1app_1apppf_1app_Payments_List_Table extends WP_List_Table
{
public function prepare_items()
{
$post_id = sanitize_text_field($_GET['form']);
$currency = get_post_meta($post_id, '_currency', true);
global $wpdb;
$table = $wpdb->prefix . ONE1APP_1APPPF_1APP_TABLE;
$data = array();
$alldbdata = $wpdb->get_results("SELECT * FROM $table WHERE (post_id = '" . $post_id . "' AND paid = '1')");
foreach ($alldbdata as $key => $dbdata) {
$newkey = $key + 1;
if ($dbdata->txn_code_2 != "") {
$txn_code = $dbdata->txn_code_2;
} else {
$txn_code = $dbdata->txn_code;
}
$data[] = array(
//'id' => $newkey,
'email' => '' . $dbdata->email . '',
'amount' => $currency . '' . number_format($dbdata->amount) . '',
'txn_code' => $txn_code,
//'metadata' => format_data($dbdata->metadata),
'date' => $dbdata->created_at
);
}
$columns = $this->get_columns();
$hidden = $this->get_hidden_columns();
$sortable = $this->get_sortable_columns();
usort($data, array(&$this, 'sort_data'));
$perPage = 20;
$currentPage = $this->get_pagenum();
$totalItems = count($data);
$this->set_pagination_args(
array(
'total_items' => $totalItems,
'per_page' => $perPage
)
);
$data = array_slice($data, (($currentPage - 1) * $perPage), $perPage);
$this->_column_headers = array($columns, $hidden, $sortable);
$this->items = $data;
$rows = count($alldbdata);
return $rows;
}
public function get_columns()
{
$columns = array(
//'id' => '#',
'email' => 'Email',
'amount' => 'Amount',
'txn_code' => 'Txn Code',
//'metadata' => 'Data',
'date' => 'Date'
);
return $columns;
}
/**
* Define which columns are hidden
*
* @return Array
*/
public function get_hidden_columns()
{
return array();
}
public function get_sortable_columns()
{
return array('email' => array('email', false), 'date' => array('date', false), 'amount' => array('amount', false));
}
/**
* Get the table data
*
* @return Array
*/
private function table_data($data)
{
return $data;
}
/**
* Define what data to show on each column of the table
*
* @param Array $item Data
* @param String $column_name - Current column name
*
* @return Mixed
*/
public function column_default($item, $column_name)
{
switch ($column_name) {
//case 'id':
case 'email':
case 'amount':
case 'txn_code':
//case 'metadata':
case 'date':
return $item[$column_name];
default:
return print_r($item, true);
}
}
/**
* Allows you to sort the data by the variables set in the $_GET
*
* @return Mixed
*/
private function sort_data($a, $b)
{
$orderby = 'date';
$order = 'desc';
if (!empty($_GET['orderby'])) {
$orderby = sanitize_text_field($_GET['orderby']);
}
if (!empty($_GET['order'])) {
$order = sanitize_text_field($_GET['order']);
}
$result = strcmp($a[$orderby], $b[$orderby]);
if ($order === 'asc') {
return $result;
}
return -$result;
}
}
class one1app_1apppf_1app_Transactions_List_Table extends WP_List_Table
{
public function prepare_items()
{
$site_path = site_url();
if(isset(explode('//', $site_path)[1])) {
$site_url = explode('//', $site_path)[1];
}
elseif(!isset(explode('//', $site_path)[1])) {
$site_url = site_url();
}
$responsecp = wp_remote_get( 'https://api.1app.online/v2/checkplugin-connect?path='.$site_url );
$bodycp = wp_remote_retrieve_body( $responsecp );
$check_res = json_decode($bodycp, true);
if($check_res['status'] == true) {
$w_b_id = $check_res['businessid'];
$w_skey = $check_res['secretkey'];
$body = array(
'business_id' => $w_b_id,
'secretkey' => $w_skey,
);
$args = array(
'body' => $body,
'timeout' => '5',
'redirection' => '5',
'httpversion' => '1.0',
'blocking' => true,
'headers' => array(),
'cookies' => array(),
);
$resptl = wp_remote_post( 'https://api.1app.online/v2/translist', $args );
$bodytl = wp_remote_retrieve_body( $resptl );
$alltrxlist = json_decode($bodytl, true);
if($alltrxlist['status'] == true) {
$alltrxdata = $alltrxlist['data'];
if(count($alltrxdata) > 0) {
$idd = 1;
foreach($alltrxdata as $dbdata) {
$data[] = array(
//'id' => $idd,
'amount' => $dbdata['currency'] . '' . number_format($dbdata['amount']) . '',
'transfee' => $dbdata['currency'] . '' . number_format($dbdata['transfee']) . '',
'reference' => $dbdata['reference'],
'name' => $dbdata['customer_name'],
'email' => $dbdata['customer_email'],
'phone' => $dbdata['customer_phone'],
'paid_through' => $dbdata['paid_through'],
'time' => $dbdata['payment_time']
//'metadata' => format_data($dbdata->metadata),
//'date' => $dbdata->created_at
);
$idd++;
}
}
else {
$data[] = array();
}
}
else {
$data[] = array();
}
$columns = $this->get_columns();
$hidden = $this->get_hidden_columns();
$sortable = $this->get_sortable_columns();
usort($data, array(&$this, 'sort_data'));
$perPage = 20;
$currentPage = $this->get_pagenum();
$totalItems = count($data);
$this->set_pagination_args(
array(
'total_items' => $totalItems,
'per_page' => $perPage
)
);
$data = array_slice($data, (($currentPage - 1) * $perPage), $perPage);
$this->_column_headers = array($columns, $hidden, $sortable);
$this->items = $data;
$rows = count($alltrxlist);
return $rows;
}
else {
echo ''.esc_html('Kindly go to').' '.esc_html('settings').' '.esc_html('to connect to your 1app business account.').'
';
}
}
public function get_columns()
{
$columns = array(
//'id' => '#',
'reference' => 'Reference',
'name' => 'Customer',
'amount' => 'Amount',
'email' => 'Email',
'phone' => 'Phone',
'transfee' => 'Fee',
//'metadata' => 'Data',
'paid_through' => 'Paid Through',
'time' => 'Date'
);
return $columns;
}
/**
* Define which columns are hidden
*
* @return Array
*/
public function get_hidden_columns()
{
return array();
}
public function get_sortable_columns()
{
return array('time' => array('time', false), 'amount' => array('amount', false));
}
/**
* Get the table data
*
* @return Array
*/
private function table_data($data)
{
return $data;
}
/**
* Define what data to show on each column of the table
*
* @param Array $item Data
* @param String $column_name - Current column name
*
* @return Mixed
*/
public function column_default($item, $column_name)
{
switch ($column_name) {
//case 'id':
case 'email':
case 'name':
case 'transfee':
case 'phone':
case 'paid_through':
case 'amount':
case 'reference':
//case 'metadata':
case 'time':
return $item[$column_name];
default:
return print_r($item, true);
}
}
/**
* Allows you to sort the data by the variables set in the $_GET
*
* @return Mixed
*/
private function sort_data($a, $b)
{
$orderby = 'time';
$order = 'desc';
if (!empty($_GET['orderby'])) {
$orderby = sanitize_key($_GET['orderby']);
}
if (!empty($_GET['order'])) {
$order = sanitize_key($_GET['order']);
}
$result = strcmp($a[$orderby], $b[$orderby]);
if ($order === 'asc') {
return $result;
}
return -$result;
}
}