Skip to content

Commit

Permalink
Bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Kendysond committed Sep 17, 2016
1 parent 99344e3 commit cc1ca14
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 34 deletions.
4 changes: 2 additions & 2 deletions includes/class-paystack-forms-activator.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
<?php

class Kkd_Pff_Paystack_Activator {

public static function activate() {
global $wpdb;
$table_name = $wpdb->prefix . 'paystack_forms_payments';

$sql = "CREATE TABLE IF NOT EXISTS `".$table_name."` (
$sql = "CREATE TABLE `".$table_name."` (
id int(11) NOT NULL AUTO_INCREMENT,
post_id int(11) NOT NULL,
user_id int(11) NOT NULL,
Expand All @@ -24,6 +23,7 @@ public static function activate() {
);";
require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
dbDelta($sql);

}


Expand Down
5 changes: 4 additions & 1 deletion paystack-forms.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
}
define( 'KKD_PFF_PAYSTACK_PLUGIN_PATH', plugins_url( __FILE__ ) );
define( 'KKD_PFF_PAYSTACK_MAIN_FILE', __FILE__ );
define( 'KKD_PFF_PAYSTACK_VERSION', '1.0.4' );


// fix some badly enqueued scripts with no sense of HTTPS
add_action('wp_print_scripts', 'kkd_pff_paystack_enqueueScriptsFix', 100);
add_action('wp_print_styles', 'kkd_pff_paystack_enqueueStylesFix', 100);
Expand Down Expand Up @@ -53,7 +56,7 @@ function kkd_pff_paystack_enqueueStylesFix() {

function kkd_pff_paystack_activate_paystack_forms() {
require_once plugin_dir_path( __FILE__ ) . 'includes/class-paystack-forms-activator.php';
Paystack_Forms_Activator::activate();
Kkd_Pff_Paystack_Activator::activate();
}

register_activation_hook( __FILE__, 'kkd_pff_paystack_activate_paystack_forms' );
Expand Down
72 changes: 41 additions & 31 deletions public/class-paystack-forms-public.php
Original file line number Diff line number Diff line change
Expand Up @@ -614,6 +614,8 @@ function kkd_pff_paystack_form_shortcode($atts) {
<div class="input">';
if ($recur == 'plan') {
echo '<input type="text" name="pf-amount" value="'.$planamount.'" id="pf-amount" readonly required/>';
}elseif($recur == 'optional'){
echo '<input type="text" name="pf-amount" class="pf-number" id="pf-amount" required/>';
}else{
if ($amount == 0) {
echo '<input type="text" name="pf-amount" class="pf-number" id="pf-amount" required/>';
Expand All @@ -627,30 +629,29 @@ function kkd_pff_paystack_form_shortcode($atts) {
echo '</div>
</div>';

if ($recur != 'no') {
if ($recur == 'optional') {
echo '<div class="span12 unit">
<label class="label">Recuring Payment</label>
<div class="select">
<select class="form-control" name="pf-interval" >
<option value="no">None</option>
<option value="hourly">Hourly</option>
<option value="daily">Daily</option>
<option value="weekly">Weekly</option>
<option value="monthly">Monthly</option>
<option value="annually">Annually</option>
</select>
<i></i>
</div>
</div>';
}else{
echo '<input type="hidden" name="pf-plancode" value="' . $recurplan. '" />';
echo '<div class="span12 unit">
<label class="label" style="font-size:18px;font-weight:600;line-height: 20px;">'.$plan->data->name.' '.$plan->data->interval. ' recuring payment - '.$plan->data->currency.' '.number_format($planamount).'</label>
</div>';
}
if ($recur == 'optional') {
echo '<div class="span12 unit">
<label class="label">Recuring Payment</label>
<div class="select">
<select class="form-control" name="pf-interval" >
<option value="no">None</option>
<option value="hourly">Hourly</option>
<option value="daily">Daily</option>
<option value="weekly">Weekly</option>
<option value="monthly">Monthly</option>
<option value="annually">Annually</option>
</select>
<i></i>
</div>
</div>';
}elseif($recur == 'plan'){
echo '<input type="hidden" name="pf-plancode" value="' . $recurplan. '" />';
echo '<div class="span12 unit">
<label class="label" style="font-size:18px;font-weight:600;line-height: 20px;">'.$plan->data->name.' '.$plan->data->interval. ' recuring payment - '.$plan->data->currency.' '.number_format($planamount).'</label>
</div>';
}


}
echo(do_shortcode($obj->post_content));

// echo '<br /><p>Transaction charge:'.$currency.'<b class="txn_charge">13,000</b></p>';
Expand Down Expand Up @@ -1021,6 +1022,7 @@ function kkd_pff_paystack_confirm_payment() {

$payment_array = $record[0];
$amount = get_post_meta($payment_array->post_id,'_amount',true);
$recur = get_post_meta($payment_array->post_id,'_recur',true);
$currency = get_post_meta($payment_array->post_id,'_currency',true);


Expand All @@ -1044,25 +1046,33 @@ function kkd_pff_paystack_confirm_payment() {
if ( 'success' == $paystack_response->data->status ) {
$amount_paid = $paystack_response->data->amount / 100;
$paystack_ref = $paystack_response->data->reference;

if ($amount == 0) {
if ($recur == 'optional' || $recur == 'plan') {
$wpdb->update( $table, array( 'paid' => 1,'amount' =>$amount_paid),array('txn_code'=>$paystack_ref));
$thankyou = get_post_meta($payment_array->post_id,'_successmsg',true);
$message = $thankyou;
$result = "success";
// kkd_pff_paystack_send_receipt($currency,$amount,$name,$payment_array->email,$code,$metadata)
}else{
if( $amount != $amount_paid ) {
$message = "Invalid amount Paid. Amount required is ".$currency."<b>".number_format($amount)."</b>";
$result = "failed";
}else{

$wpdb->update( $table, array( 'paid' => 1),array('txn_code'=>$paystack_ref));
if ($amount == 0) {
$wpdb->update( $table, array( 'paid' => 1,'amount' =>$amount_paid),array('txn_code'=>$paystack_ref));
$thankyou = get_post_meta($payment_array->post_id,'_successmsg',true);
$message = $thankyou;
$result = "success";
// kkd_pff_paystack_send_receipt($currency,$amount,$name,$payment_array->email,$code,$metadata)
}else{
if( $amount != $amount_paid ) {
$message = "Invalid amount Paid. Amount required is ".$currency."<b>".number_format($amount)."</b>";
$result = "failed";
}else{

$wpdb->update( $table, array( 'paid' => 1),array('txn_code'=>$paystack_ref));
$thankyou = get_post_meta($payment_array->post_id,'_successmsg',true);
$message = $thankyou;
$result = "success";
}
}
}

}else {
$message = "Transaction Failed/Invalid Code";
$result = "failed";
Expand Down

0 comments on commit cc1ca14

Please sign in to comment.