Skip to content

Commit a64c946

Browse files
committed
Try again feature from email.
1 parent 67ae86e commit a64c946

File tree

5 files changed

+554
-228
lines changed

5 files changed

+554
-228
lines changed

admin/class-paystack-forms-admin.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -570,11 +570,16 @@ public function prepare_items(){
570570

571571
foreach ($alldbdata as $key => $dbdata) {
572572
$newkey = $key+1;
573+
if ($dbdata->txn_code_2 != "") {
574+
$txn_code = $dbdata->txn_code_2;
575+
}else{
576+
$txn_code = $dbdata->txn_code;
577+
}
573578
$data[] = array(
574579
'id' => $newkey,
575580
'email' => '<a href="mailto:'.$dbdata->email.'">'.$dbdata->email.'</a>',
576581
'amount' => $currency.'<b>'.number_format($dbdata->amount).'</b>',
577-
'txn_code' => $dbdata->txn_code,
582+
'txn_code' => $txn_code,
578583
'metadata' => format_data($dbdata->metadata),
579584
'date' => $dbdata->created_at
580585
);

includes/paystack-invoice.php

Lines changed: 70 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -2,83 +2,106 @@
22
require_once('../../../../wp-load.php');
33

44
$code = @$_GET['code'];
5+
function kkd_format_metadata($data){
6+
$new = json_decode($data);
7+
$text = '';
8+
if (array_key_exists("0", $new)) {
9+
foreach ($new as $key => $item) {
10+
if ($item->type == 'text') {
11+
$text.= '<div class="span12 unit">
12+
<label class="label inline">'.$item->display_name.':</label>
13+
<strong>'.$item->value.'</strong>
14+
</div>';
15+
}else{
16+
$text.= '<div class="span12 unit">
17+
<label class="label inline">'.$item->display_name.':</label>
18+
<strong> <a target="_blank" href="'.$item->value.'">link</a></strong>
19+
</div>';
20+
}
521

6-
$mode = esc_attr( get_option('mode') );
7-
if ($mode == 'test') {
8-
$key = esc_attr( get_option('tpk') );
9-
}else{
10-
$key = esc_attr( get_option('lpk') );
22+
}
23+
}else{
24+
$text = '';
25+
if (count($new) > 0) {
26+
foreach ($new as $key => $item) {
27+
$text.= '<div class="span12 unit">
28+
<label class="label inline">'.$key.':</label>
29+
<strong>'.$item.'</strong>
30+
</div>';
31+
}
32+
}
33+
}
34+
//
35+
return $text;
1136
}
12-
?>
1337

14-
<?php
15-
/**
16-
* Template Name: Alphabetical Posts
17-
*/
18-
19-
get_header(); ?>
38+
global $wpdb;
39+
$table = $wpdb->prefix.KKD_PFF_PAYSTACK_TABLE;
40+
$record = $wpdb->get_results("SELECT * FROM $table WHERE (txn_code = '".$code."')");
41+
42+
if (array_key_exists("0", $record)) {
43+
get_header();
44+
$dbdata = $record[0];
45+
$currency = get_post_meta($dbdata->post_id,'_currency',true);
46+
47+
48+
49+
50+
?>
2051
<div class="content-area main-content" id="primary">
2152
<main role="main" class="site-main" id="main">
2253
<div class="blog_post">
2354
<article class="post-4 page type-page status-publish hentry" id="post-4">
24-
<form action="" method="" class="j-forms" id="pf-form" novalidate="">
55+
<form action="<?php echo admin_url('admin-ajax.php'); ?>" method="post" enctype="multipart/form-data" class="j-forms retry-form" id="pf-form" novalidate="">
56+
<input type="hidden" name="action" value="kkd_pff_paystack_retry_action">
57+
<input type="hidden" name="code" value="<?php echo $code; ?>" />
2558
<div class="content">
2659

2760
<div class="divider-text gap-top-20 gap-bottom-45">
28-
<span>Input</span>
61+
<span>Payment Invoice</span>
2962
</div>
3063

3164
<div class="j-row">
3265
<div class="span12 unit">
33-
<label class="label">Text input without icon <span>*</span></label>
34-
<div class="input">
35-
<input type="text" placeholder="placeholder text...">
36-
</div>
66+
<label class="label inline">Email:</label>
67+
<strong><a href="mailto:<?php echo $dbdata->email; ?>"><?php echo $dbdata->email; ?></a></strong>
3768
</div>
3869
<div class="span12 unit">
39-
<label class="label">Text input without icon</label>
40-
<label class="select">
41-
<select autocomplete="off">
42-
<option value="none">Select fruit</option>
43-
<option value="0">Apple</option>
44-
<option value="1">Banana</option>
45-
<option value="2">Coconut</option>
46-
<option value="3">Mango</option>
47-
<option value="4">Melon</option>
48-
<option value="5">Orange</option>
49-
<option value="6">Pear</option>
50-
<option value="7">Watermelon</option>
51-
</select>
52-
<i></i>
53-
</label>
70+
<label class="label inline">Amount:</label>
71+
<strong><?php echo $currency.number_format($dbdata->amount); ?></strong>
5472
</div>
73+
<?php echo kkd_format_metadata($dbdata->metadata); ?>
74+
5575
<div class="span12 unit">
56-
<label class="input append-small-btn">
57-
<div class="file-button">
58-
Browse
59-
<input type="file" onchange="document.getElementById('append-small-btn').value = this.value;">
60-
</div>
61-
<input type="text" id="append-small-btn" readonly="" placeholder="no file selected">
62-
</label>
76+
<label class="label inline">Date:</label>
77+
<strong><?php echo $currency.number_format($dbdata->amount); ?></strong>
6378
</div>
79+
<?php if($dbdata->paid == 1) {?>
6480
<div class="span12 unit">
65-
<label class="label">Textarea</label>
66-
<div class="input">
67-
<textarea placeholder="your message..." spellcheck="false" id="textarea"></textarea>
68-
</div>
81+
<label class="label inline">Payment Status:</label>
82+
<strong> Successful</strong>
6983
</div>
84+
<?php } ?>
85+
86+
7087
</div>
7188
</div>
7289

7390
<div class="footer">
7491
<small><span style="color: red;">*</span> are compulsory</small><br>
75-
<img class="paystack-cardlogos size-full wp-image-1096" alt="cardlogos" src="http://localhost/wordpress/wp-content/plugins/paystack-forms/public/../images/[email protected]">
76-
<button type="submit" class="primary-btn">Submit</button>
92+
<img class="paystack-cardlogos size-full wp-image-1096" alt="cardlogos" src="<?php echo plugins_url( '../images/[email protected]' , __FILE__ ) ;?>">
93+
<?php if($dbdata->paid == 0) {?>
94+
<button type="submit" class="primary-btn" id='submitbtn'>Retry Payment</button>
95+
<?php } ?>
96+
7797
</div>
7898
</form>
7999
</article>
80100
</div>
81101
</main>
82102
</div>
83103
<?php
84-
get_footer();
104+
get_footer();
105+
}else{
106+
die('Invoice code invalid');
107+
}

public/class-paystack-forms-public.php

Lines changed: 180 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -187,13 +187,13 @@ function kkd_pff_paystack_send_invoice($currency,$amount,$name,$email,$code){
187187
<table class="primary_btn" align="center" border="0" cellspacing="0" cellpadding="0" style="border-spacing:0;mso-table-lspace:0;mso-table-rspace:0;clear:both;margin:0 auto">
188188
<tbody>
189189
<tr>
190-
<!-- <p style="font-family:Helvetica,Arial,sans-serif;font-size:15px;line-height:23px;margin-top:16px;margin-bottom:24px"><small class="text-muted" style="font-size:86%;font-weight:normal;color:#b3b3b5">Use this link below to try again, if you encountered <br />any issue while trying to make the payment.</small><br>
190+
<p style="font-family:Helvetica,Arial,sans-serif;font-size:15px;line-height:23px;margin-top:16px;margin-bottom:24px"><small class="text-muted" style="font-size:86%;font-weight:normal;color:#b3b3b5">Use this link below to try again, if you encountered <br />any issue while trying to make the payment.</small><br>
191191
</p>
192192
<td class="font_default" style="padding:12px 24px;font-family:Helvetica,Arial,sans-serif;font-size:16px;mso-line-height-rule:exactly;text-align:center;vertical-align:middle;-webkit-border-radius:4px;border-radius:4px;background-color:#666">
193-
<a href="<?php echo $code; ?>" style="display:block;text-decoration:none;font-family:Helvetica,Arial,sans-serif;color:#fff;font-weight:bold;text-align:center">
193+
<a href="<?php echo get_site_url().'/paystackinvoice/?code='.$code; ?>" style="display:block;text-decoration:none;font-family:Helvetica,Arial,sans-serif;color:#fff;font-weight:bold;text-align:center">
194194
<span style="text-decoration:none;color:#fff;text-align:center;display:block">Try Again</span>
195195
</a>
196-
</td> -->
196+
</td>
197197
</tr>
198198
</tbody>
199199
</table>
@@ -527,6 +527,7 @@ function kkd_pff_paystack_form_shortcode($atts) {
527527
if ((($user_id != 0) && ($loggedin == 'yes')) || $loggedin == 'no') {
528528

529529
echo "<h1 id='pf-form".$id."'>".$obj->post_title."</h1>";
530+
// echo get_site_url().'/paystackinvoice/?code=ddddddd';
530531
echo '<form enctype="multipart/form-data" action="' . admin_url('admin-ajax.php') . '" url="' . admin_url() . '" method="post" class="paystack-form j-forms" novalidate>
531532
<div class="j-row">';
532533
echo '<input type="hidden" name="action" value="kkd_pff_paystack_submit_action">';
@@ -1120,7 +1121,7 @@ function kkd_pff_paystack_confirm_payment() {
11201121

11211122
exit(json_encode($response));
11221123
}
1123-
global $wpdb;
1124+
global $wpdb;
11241125
$table = $wpdb->prefix.KKD_PFF_PAYSTACK_TABLE;
11251126
$code = $_POST['code'];
11261127
$record = $wpdb->get_results("SELECT * FROM $table WHERE (txn_code = '".$code."')");
@@ -1230,3 +1231,178 @@ function kkd_pff_paystack_confirm_payment() {
12301231

12311232
die();
12321233
}
1234+
1235+
1236+
add_action( 'wp_ajax_kkd_pff_paystack_retry_action', 'kkd_pff_paystack_retry_action' );
1237+
add_action( 'wp_ajax_nopriv_kkd_pff_paystack_retry_action', 'kkd_pff_paystack_retry_action' );
1238+
function kkd_pff_paystack_retry_action() {
1239+
if (trim($_POST['code']) == '') {
1240+
$response['result'] = 'failed';
1241+
$response['message'] = 'Cde is required';
1242+
1243+
// Exit here, for not processing further because of the error
1244+
exit(json_encode($response));
1245+
}
1246+
do_action( 'kkd_pff_paystack_before_save' );
1247+
1248+
global $wpdb;
1249+
$code = $_POST['code'];
1250+
$newcode = kkd_pff_paystack_generate_code();
1251+
$newcode = $newcode.'_2';
1252+
$insert = [];
1253+
$table = $wpdb->prefix.KKD_PFF_PAYSTACK_TABLE;
1254+
$record = $wpdb->get_results("SELECT * FROM $table WHERE (txn_code = '".$code."')");
1255+
if (array_key_exists("0", $record)) {
1256+
$dbdata = $record[0];
1257+
$plan = $dbdata->plan;
1258+
$quantity = 1;
1259+
$wpdb->update( $table, array( 'txn_code_2' => $newcode),array('txn_code' => $code));
1260+
1261+
$currency = get_post_meta($dbdata->post_id,'_currency',true);
1262+
$fixedmetadata = kkd_pff_paystack_meta_as_custom_fields($dbdata->metadata);
1263+
$nmeta = json_decode($dbdata->metadata);
1264+
foreach ($nmeta as $nkey => $nvalue) {
1265+
if ($nvalue->variable_name == 'Quantity') {
1266+
$quantity = $nvalue->value;
1267+
}
1268+
if ($nvalue->variable_name == 'Full_Name') {
1269+
$fullname = $nvalue->value;
1270+
}
1271+
}
1272+
1273+
}
1274+
1275+
$response = array(
1276+
'result' => 'success',
1277+
'code' => $newcode,
1278+
'plan' => $plan,
1279+
'quantity' => $quantity,
1280+
'email' => $dbdata->email,
1281+
'name' => $fullname,
1282+
'total' => $dbdata->amount*100,
1283+
'custom_fields' => $fixedmetadata
1284+
);
1285+
echo json_encode($response);
1286+
1287+
die();
1288+
}
1289+
add_action( 'wp_ajax_kkd_pff_paystack_rconfirm_payment', 'kkd_pff_paystack_rconfirm_payment' );
1290+
add_action( 'wp_ajax_nopriv_kkd_pff_paystack_rconfirm_payment', 'kkd_pff_paystack_rconfirm_payment' );
1291+
1292+
function kkd_pff_paystack_rconfirm_payment() {
1293+
if (trim($_POST['code']) == '') {
1294+
$response['error'] = true;
1295+
$response['error_message'] = "Did you make a payment?";
1296+
1297+
exit(json_encode($response));
1298+
}
1299+
global $wpdb;
1300+
$table = $wpdb->prefix.KKD_PFF_PAYSTACK_TABLE;
1301+
$code = $_POST['code'];
1302+
$record = $wpdb->get_results("SELECT * FROM $table WHERE (txn_code_2 = '".$code."')");
1303+
if (array_key_exists("0", $record)) {
1304+
1305+
$payment_array = $record[0];
1306+
$amount = get_post_meta($payment_array->post_id,'_amount',true);
1307+
$recur = get_post_meta($payment_array->post_id,'_recur',true);
1308+
$currency = get_post_meta($payment_array->post_id,'_currency',true);
1309+
$txncharge = get_post_meta($payment_array->post_id,'_txncharge',true);
1310+
$redirect = get_post_meta($payment_array->post_id,'_redirect',true);
1311+
1312+
1313+
$mode = esc_attr( get_option('mode') );
1314+
if ($mode == 'test') {
1315+
$key = esc_attr( get_option('tsk') );
1316+
}else{
1317+
$key = esc_attr( get_option('lsk') );
1318+
}
1319+
$paystack_url = 'https://api.paystack.co/transaction/verify/' . $code;
1320+
$headers = array(
1321+
'Authorization' => 'Bearer ' . $key
1322+
);
1323+
$args = array(
1324+
'headers' => $headers,
1325+
'timeout' => 60
1326+
);
1327+
$request = wp_remote_get( $paystack_url, $args );
1328+
if( ! is_wp_error( $request ) && 200 == wp_remote_retrieve_response_code( $request ) ) {
1329+
$paystack_response = json_decode( wp_remote_retrieve_body( $request ) );
1330+
if ( 'success' == $paystack_response->data->status ) {
1331+
$amount_paid = $paystack_response->data->amount / 100;
1332+
$paystack_ref = $paystack_response->data->reference;
1333+
if ($recur == 'optional' || $recur == 'plan') {
1334+
$wpdb->update( $table, array( 'paid' => 1,'amount' =>$amount_paid),array('txn_code_2'=>$paystack_ref));
1335+
$thankyou = get_post_meta($payment_array->post_id,'_successmsg',true);
1336+
$message = $thankyou;
1337+
$result = "success";
1338+
}else{
1339+
1340+
if ($amount == 0) {
1341+
$wpdb->update( $table, array( 'paid' => 1,'amount' =>$amount_paid),array('txn_code_2'=>$paystack_ref));
1342+
$thankyou = get_post_meta($payment_array->post_id,'_successmsg',true);
1343+
$message = $thankyou;
1344+
$result = "success";
1345+
// kkd_pff_paystack_send_receipt($currency,$amount,$name,$payment_array->email,$code,$metadata)
1346+
}else{
1347+
$usequantity = get_post_meta($payment_array->post_id,'_usequantity',true);
1348+
if ($usequantity == 'no') {
1349+
$amount = (int)str_replace(' ', '', $amount);
1350+
}else{
1351+
$quantity = $_POST["quantity"];
1352+
$unitamount = (int)str_replace(' ', '', $amount);
1353+
$amount = $quantity*$unitamount;
1354+
}
1355+
1356+
1357+
if ($txncharge == 'customer') {
1358+
$amount = kkd_pff_paystack_add_paystack_charge($amount);
1359+
}
1360+
if( $amount != $amount_paid ) {
1361+
$message = "Invalid amount Paid. Amount required is ".$currency."<b>".number_format($amount)."</b>";
1362+
$result = "failed";
1363+
}else{
1364+
1365+
$wpdb->update( $table, array( 'paid' => 1),array('txn_code_2'=>$paystack_ref));
1366+
$thankyou = get_post_meta($payment_array->post_id,'_successmsg',true);
1367+
$message = $thankyou;
1368+
$result = "success";
1369+
}
1370+
}
1371+
}
1372+
1373+
}else {
1374+
$message = "Transaction Failed/Invalid Code";
1375+
$result = "failed";
1376+
}
1377+
1378+
}
1379+
}else{
1380+
$message = "Payment Verification Failed.";
1381+
$result = "failed";
1382+
1383+
}
1384+
1385+
if ($result == 'success') {
1386+
$sendreceipt = get_post_meta($payment_array->post_id, '_sendreceipt', true);
1387+
if($sendreceipt == 'yes'){
1388+
$decoded = json_decode($payment_array->metadata);
1389+
$fullname = $decoded[0]->value;
1390+
kkd_pff_paystack_send_receipt($payment_array->post_id,$currency,$amount_paid,$fullname,$payment_array->email,$paystack_ref,$payment_array->metadata);
1391+
1392+
}
1393+
1394+
}
1395+
$response = array(
1396+
'result' => $result,
1397+
'message' => $message,
1398+
);
1399+
if ($result == 'success' && $redirect != '') {
1400+
$response['result'] = 'success2';
1401+
$response['link'] = $redirect;
1402+
}
1403+
1404+
1405+
echo json_encode($response);
1406+
1407+
die();
1408+
}

0 commit comments

Comments
 (0)