Skip to content

Commit ebd69f0

Browse files
committed
Bug fixes to price calculation
1 parent a302c66 commit ebd69f0

File tree

4 files changed

+88
-4
lines changed

4 files changed

+88
-4
lines changed

admin/class-paystack-forms-admin.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ function kkd_pff_paystack_txncheck($name,$txncharge){
3232
function kkd_pff_paystack_setting_page() {
3333
?>
3434
<h1>Paystack Forms API KEYS Settings!</h1>
35+
<h3>Paystack</h3>
36+
37+
<h4>Optional: To avoid situations where bad network makes it impossible to verify transactions, set your webhook URL <a href="https://dashboard.paystack.co/#/settings/developer">here</a> to the URL below<strong style="color: red"><pre><code><?php echo get_site_url().'/kkd/wpffp/webhook/'; ?></code></pre></strong></
3538
<form method="post" action="options.php">
3639
<?php settings_fields( 'kkd-pff-paystack-settings-group' ); do_settings_sections( 'kkd-pff-paystack-settings-group' ); ?>
3740
<table class="form-table paystack_setting_page">

includes/class-paystack-forms.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ private function load_dependencies() {
144144
* side of the site.
145145
*/
146146
require_once plugin_dir_path( dirname( __FILE__ ) ) . 'public/class-paystack-forms-public.php';
147+
require_once plugin_dir_path( dirname( __FILE__ ) ) . 'public/class-paystack-forms-webhook.php';
147148

148149
$this->loader = new Kkd_Pff_Paystack_Loader();
149150

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
<?php
2+
3+
class Kkd_Pff_Paystack_webhook{
4+
5+
/**
6+
* @var string Pug Bomb Headquarters
7+
*/
8+
9+
10+
/** Hook WordPress
11+
* @return void
12+
*/
13+
public function __construct(){
14+
add_filter('query_vars', array($this, 'add_query_vars'), 0);
15+
add_action('parse_request', array($this, 'sniff_requests'), 0);
16+
add_action('init', array($this, 'add_endpoint'), 0);
17+
}
18+
19+
/** Add public query vars
20+
* @param array $vars List of current public query vars
21+
* @return array $vars
22+
*/
23+
public function add_query_vars($vars){
24+
$vars[] = '__api';
25+
$vars[] = 'pugs';
26+
return $vars;
27+
}
28+
29+
/** Add API Endpoint
30+
* This is where the magic happens - brush up on your regex skillz
31+
* @return void
32+
*/
33+
public function add_endpoint(){
34+
add_rewrite_rule('/ kkd/wpffp/webhook/','index.php?__api=1&pugs=$matches[1]','top');
35+
}
36+
/** Sniff Requests
37+
* This is where we hijack all API requests
38+
* If $_GET['__api'] is set, we kill WP and serve up pug bomb awesomeness
39+
* @return die if API request
40+
*/
41+
public function sniff_requests(){
42+
global $wp;
43+
if(isset($wp->query_vars['__api'])){
44+
$this->handle_request();
45+
exit;
46+
}
47+
}
48+
49+
/** Handle Requests
50+
* This is where we send off for an intense pug bomb package
51+
* @return void
52+
*/
53+
protected function handle_request(){
54+
global $wp;
55+
$pugs = $wp->query_vars['pugs'];
56+
if(!$pugs)
57+
$this->send_response('Please tell us how many pugs to send.');
58+
59+
$pugs = file_get_contents(get_site_url().'/kkd/wpffp/webhook/'.$pugs);
60+
if($pugs)
61+
$this->send_response('200 OK', json_decode($pugs));
62+
else
63+
$this->send_response('Something went wrong with the pug bomb factory');
64+
}
65+
66+
/** Response Handler
67+
* This sends a JSON response to the browser
68+
*/
69+
protected function send_response($msg, $pugs = ''){
70+
$response['message'] = $msg;
71+
if($pugs)
72+
$response['pugs'] = $pugs;
73+
header('content-type: application/json; charset=utf-8');
74+
echo json_encode($response)."\n";
75+
exit;
76+
}
77+
}
78+
new Kkd_Pff_Paystack_webhook();

public/js/paystack-forms-public.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,11 @@
5050
var fees = multiplier * transaction_amount;
5151
var extrafee = 0;
5252
if (fees > 2000) {
53-
var extrafee = 2000;
53+
var fees = 2000;
5454
}else{
55-
if (transaction_amount > 2500) {extrafee = 100};
55+
if (transaction_amount > 2500) {fees += 100};
5656
}
57-
var total = transaction_amount + fees + extrafee;
57+
var total = transaction_amount + fees;
5858
// console.log(transaction_amount);
5959
if (transaction_amount == '' || transaction_amount == 0 || transaction_amount.length == 0 || transaction_amount == null || isNaN (transaction_amount)) {
6060
var total = 0;
@@ -148,7 +148,7 @@
148148
var lastName = names[1] || "";
149149
var quantity =data.quantity;
150150
// console.log(firstName+ " - "+lastName);
151-
if (data.plan == 'none') {
151+
if (data.plan == 'none' || data.plan == '' || data.plan == 'no' ) {
152152
var handler = PaystackPop.setup({
153153
key: settings.key,
154154
email: data.email,
@@ -158,6 +158,7 @@
158158
subaccount:data.subaccount,
159159
bearer:data.txnbearer,
160160
ref: data.code,
161+
transaction_charge:'0',
161162
metadata: {'custom_fields': data.custom_fields},
162163
callback: function(response){
163164
$.blockUI({ message: 'Please wait...' });
@@ -198,6 +199,7 @@
198199
lastname: lastName,
199200
ref: data.code,
200201
subaccount:data.subaccount,
202+
transaction_charge:'0',
201203
bearer:data.txnbearer,
202204
metadata: {'custom_fields': data.custom_fields},
203205
callback: function(response){

0 commit comments

Comments
 (0)