Skip to content

Commit 58bb610

Browse files
committed
v1.0
1 parent 28fd225 commit 58bb610

File tree

2 files changed

+24
-12
lines changed

2 files changed

+24
-12
lines changed

admin/class-paystack-forms-admin.php

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,11 @@ function paystack_setting_page() {
5858
<tr valign="top">
5959
<th scope="row">Mode</th>
6060

61-
<td><select class="form-control" name="mode" id="parent_id">
62-
<option value="live" <?php echo txncheck('live',esc_attr( get_option('mode') )) ?>>Live Mode</option>
63-
<option value="test" <?php echo txncheck('test',esc_attr( get_option('mode') )) ?>>Test Mode</option>
64-
</select>
65-
<!-- <input type="text" name="mode" value="<?php echo esc_attr( get_option('mode') ); ?>" /></td> -->
61+
<td>
62+
<select class="form-control" name="mode" id="parent_id">
63+
<option value="live" <?php echo txncheck('live',esc_attr( get_option('mode') )) ?>>Live Mode</option>
64+
<option value="test" <?php echo txncheck('test',esc_attr( get_option('mode') )) ?>>Test Mode</option>
65+
</select>
6666
</tr>
6767
<tr valign="top">
6868
<th scope="row">Test Secret Key</th>
@@ -82,7 +82,7 @@ function paystack_setting_page() {
8282
</tr>
8383
<tr valign="top">
8484
<th scope="row">Live Public Key</th>
85-
<td><input type="text" name="lsk" value="<?php echo esc_attr( get_option('lpk') ); ?>" /></td>
85+
<td><input type="text" name="lpk" value="<?php echo esc_attr( get_option('lpk') ); ?>" /></td>
8686
</tr>
8787
</table>
8888

@@ -375,6 +375,7 @@ function wpt_form_data_meta($post_id, $post) {
375375

376376
$events_meta['_amount'] = $_POST['_amount'];
377377
$events_meta['_paybtn'] = $_POST['_paybtn'];
378+
$events_meta['_currency'] = $_POST['_currency'];
378379
$events_meta['_successmsg'] = $_POST['_successmsg'];
379380
$events_meta['_txncharge'] = $_POST['_txncharge'];
380381
$events_meta['_loggedin'] = $_POST['_loggedin'];
@@ -514,7 +515,7 @@ public function prepare_items(){
514515
$data[] = array(
515516
'id' => $newkey,
516517
'email' => $dbdata->email,
517-
'amount' => $currency.number_format($dbdata->amount),
518+
'amount' => $currency.'<b>'.number_format($dbdata->amount).'</b>',
518519
'txn_code' => $dbdata->txn_code,
519520
'metadata' => format_data($dbdata->metadata),
520521
'date' => $dbdata->created_at

public/class-paystack-forms-public.php

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,9 @@ function paystack_confirm_payment() {
379379
if (array_key_exists("0", $record)) {
380380

381381
$payment_array = $record[0];
382+
$amount = get_post_meta($payment_array->post_id,'_amount',true);
383+
$currency = get_post_meta($payment_array->post_id,'_currency',true);
384+
382385

383386
$mode = esc_attr( get_option('mode') );
384387
if ($mode == 'test') {
@@ -400,15 +403,23 @@ function paystack_confirm_payment() {
400403
if ( 'success' == $paystack_response->data->status ) {
401404
$amount_paid = $paystack_response->data->amount / 100;
402405
$paystack_ref = $paystack_response->data->reference;
403-
if( $payment_array->amount != $amount_paid ) {
404-
$message = "Invalid amount Paid";
405-
$result = "failed";
406-
//Invalid Amount
406+
407+
if ($amount == 0) {
408+
$wpdb->query($wpdb->prepare("UPDATE $table SET paid='1',amount='".$amount_paid."' WHERE txn_code='".$paystack_ref."'"));
409+
$thankyou = get_post_meta($payment_array->post_id,'_successmsg',true);
410+
$message = $thankyou;
411+
$result = "success";
407412
}else{
413+
if( $amount != $amount_paid ) {
414+
$message = "Invalid amount Paid. Amount required is ".$currency."<b>".number_format($amount)."</b>";
415+
$result = "failed";
416+
}else{
417+
408418
$wpdb->query($wpdb->prepare("UPDATE $table SET paid='1' WHERE txn_code='".$paystack_ref."'"));
409419
$thankyou = get_post_meta($payment_array->post_id,'_successmsg',true);
410-
$message = $thankyou;
420+
$message = $thankyou;
411421
$result = "success";
422+
}
412423
}
413424
}else {
414425
$message = "Transaction Failed/Invalid Code";

0 commit comments

Comments
 (0)