Skip to content

Commit 67ae86e

Browse files
committed
Option to redirect to new url on payment success
1 parent f8ec847 commit 67ae86e

File tree

3 files changed

+29
-13
lines changed

3 files changed

+29
-13
lines changed

admin/class-paystack-forms-admin.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,7 @@ function kkd_pff_paystack_editor_add_form_data() {
278278
$loggedin = get_post_meta($post->ID, '_loggedin', true);
279279
$currency = get_post_meta($post->ID, '_currency', true);
280280
$filelimit = get_post_meta($post->ID, '_filelimit', true);
281+
$redirect = get_post_meta($post->ID, '_redirect', true);
281282

282283
if ($amount == "") {$amount = 0;}
283284
if ($filelimit == "") {$filelimit = 2;}
@@ -305,8 +306,10 @@ function kkd_pff_paystack_editor_add_form_data() {
305306
</select>';
306307
echo '<p>Success Message after Payment</p>';
307308
echo '<textarea rows="3" name="_successmsg" class="widefat" >'.$successmsg.'</textarea>';
308-
echo '<p>File Upload Limit(MB):</p>';
309+
echo '<p>File Upload Limit(MB):</p>';
309310
echo '<input ttype="number" name="_filelimit" value="' . $filelimit . '" class="widefat pf-number" />';
311+
echo '<p>Redirect to page link after payment(keep blank to use normal success message):</p>';
312+
echo '<input ttype="text" name="_redirect" value="' . $redirect . '" class="widefat" />';
310313

311314
}
312315
function kkd_pff_paystack_editor_add_email_data() {
@@ -423,13 +426,14 @@ function kkd_pff_paystack_save_data($post_id, $post) {
423426
return $post->ID;
424427
}
425428

426-
$form_meta['_amount'] = $_POST['_amount'];
429+
$form_meta['_amount'] = $_POST['_amount'];
427430
$form_meta['_paybtn'] = $_POST['_paybtn'];
428431
$form_meta['_currency'] = $_POST['_currency'];
429432
$form_meta['_successmsg'] = $_POST['_successmsg'];
430433
$form_meta['_txncharge'] = $_POST['_txncharge'];
431434
$form_meta['_loggedin'] = $_POST['_loggedin'];
432435
$form_meta['_filelimit'] = $_POST['_filelimit'];
436+
$form_meta['_redirect'] = $_POST['_redirect'];
433437
///
434438
$form_meta['_subject'] = $_POST['_subject'];
435439
$form_meta['_heading'] = $_POST['_heading'];

public/class-paystack-forms-public.php

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -46,20 +46,20 @@ public function enqueue_scripts() {
4646
define('KKD_PFF_PAYSTACK_ADDITIONAL_CHARGE', 10000);
4747
define('KKD_PFF_PAYSTACK_LOCAL_CAP', 200000);
4848

49-
define('KKD_PFF_PAYSTACK_CHARGE_DIVIDER', floatval(1-PAYSTACK_PERCENTAGE));
50-
define('KKD_PFF_PAYSTACK_CROSSOVER_AMOUNT', intval((PAYSTACK_CROSSOVER_TOTAL*PAYSTACK_CHARGE_DIVIDER)-PAYSTACK_ADDITIONAL_CHARGE));
51-
define('KKD_PFF_PAYSTACK_FLATLINE_AMOUNT_PLUS_CHARGE', intval((PAYSTACK_LOCAL_CAP-PAYSTACK_ADDITIONAL_CHARGE)/PAYSTACK_PERCENTAGE));
52-
define('KKD_PFF_PAYSTACK_FLATLINE_AMOUNT', PAYSTACK_FLATLINE_AMOUNT_PLUS_CHARGE - PAYSTACK_LOCAL_CAP);
49+
define('KKD_PFF_PAYSTACK_CHARGE_DIVIDER', floatval(1-KKD_PFF_PAYSTACK_PERCENTAGE));
50+
define('KKD_PFF_PAYSTACK_CROSSOVER_AMOUNT', intval((KKD_PFF_PAYSTACK_CROSSOVER_TOTAL*KKD_PFF_PAYSTACK_CHARGE_DIVIDER)-KKD_PFF_PAYSTACK_ADDITIONAL_CHARGE));
51+
define('KKD_PFF_PAYSTACK_FLATLINE_AMOUNT_PLUS_CHARGE', intval((KKD_PFF_PAYSTACK_LOCAL_CAP-KKD_PFF_PAYSTACK_ADDITIONAL_CHARGE)/KKD_PFF_PAYSTACK_PERCENTAGE));
52+
define('KKD_PFF_PAYSTACK_FLATLINE_AMOUNT', KKD_PFF_PAYSTACK_FLATLINE_AMOUNT_PLUS_CHARGE - KKD_PFF_PAYSTACK_LOCAL_CAP);
5353

5454
function kkd_pff_paystack_add_paystack_charge($amount)
5555
{
5656
$amountinkobo = $amount * 100;
57-
if ($amountinkobo > PAYSTACK_FLATLINE_AMOUNT)
58-
return ($amountinkobo + PAYSTACK_LOCAL_CAP)/100;
59-
elseif ($amountinkobo > PAYSTACK_CROSSOVER_AMOUNT)
60-
return (intval(($amountinkobo + PAYSTACK_ADDITIONAL_CHARGE) / PAYSTACK_CHARGE_DIVIDER))/100;
57+
if ($amountinkobo > KKD_PFF_PAYSTACK_FLATLINE_AMOUNT)
58+
return ($amountinkobo + KKD_PFF_PAYSTACK_LOCAL_CAP)/100;
59+
elseif ($amountinkobo > KKD_PFF_PAYSTACK_CROSSOVER_AMOUNT)
60+
return (intval(($amountinkobo + KKD_PFF_PAYSTACK_ADDITIONAL_CHARGE) / KKD_PFF_PAYSTACK_CHARGE_DIVIDER))/100;
6161
else
62-
return (intval($amountinkobo / PAYSTACK_CHARGE_DIVIDER))/100;
62+
return (intval($amountinkobo / KKD_PFF_PAYSTACK_CHARGE_DIVIDER))/100;
6363
}
6464

6565
add_filter ("wp_mail_content_type", "kkd_pff_paystack_mail_content_type");
@@ -1131,6 +1131,7 @@ function kkd_pff_paystack_confirm_payment() {
11311131
$recur = get_post_meta($payment_array->post_id,'_recur',true);
11321132
$currency = get_post_meta($payment_array->post_id,'_currency',true);
11331133
$txncharge = get_post_meta($payment_array->post_id,'_txncharge',true);
1134+
$redirect = get_post_meta($payment_array->post_id,'_redirect',true);
11341135

11351136

11361137
$mode = esc_attr( get_option('mode') );
@@ -1215,11 +1216,16 @@ function kkd_pff_paystack_confirm_payment() {
12151216
}
12161217

12171218
}
1218-
1219-
$response = array(
1219+
$response = array(
12201220
'result' => $result,
12211221
'message' => $message,
12221222
);
1223+
if ($result == 'success' && $redirect != '') {
1224+
$response['result'] = 'success2';
1225+
$response['link'] = $redirect;
1226+
}
1227+
1228+
12231229
echo json_encode($response);
12241230

12251231
die();

public/js/paystack-forms-public.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,9 @@
163163
$.blockUI({ message: 'Please wait...' });
164164
$.post($form.attr('action'), {'action':'kkd_pff_paystack_confirm_payment','code':response.trxref,'quantity':quantity}, function(newdata) {
165165
data = JSON.parse(newdata);
166+
if (data.result == 'success2'){
167+
window.location.href = data.link;
168+
}
166169
if (data.result == 'success'){
167170
$('.paystack-form')[0].reset();
168171
$('html,body').animate({ scrollTop: $('.paystack-form').offset().top - 110 }, 500);
@@ -199,6 +202,9 @@
199202
$.blockUI({ message: 'Please wait...' });
200203
$.post($form.attr('action'), {'action':'kkd_pff_paystack_confirm_payment','code':response.trxref}, function(newdata) {
201204
data = JSON.parse(newdata);
205+
if (data.result == 'success2'){
206+
window.location.href = data.link;
207+
}
202208
if (data.result == 'success'){
203209
$('.paystack-form')[0].reset();
204210
$('html,body').animate({ scrollTop: $('.paystack-form').offset().top - 110 }, 500);

0 commit comments

Comments
 (0)