Skip to content

Commit b0d84a5

Browse files
committed
Start plan after x number of days
1 parent 7c039a9 commit b0d84a5

File tree

4 files changed

+89
-7
lines changed

4 files changed

+89
-7
lines changed

README.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Donate link: https://paystack.com/demo
44
Tags: paystack, recurrent payments, nigeria, mastercard, visa, target,Naira,payments,verve,donation,church,NGO,form,contact form 7, form,
55
Requires at least: 3.1
66
Tested up to: 4.7
7-
Stable tag: 2.1.1
7+
Stable tag: 2.1.2
88
License: GPLv2 or later
99
License URI: http://www.gnu.org/licenses/gpl-2.0.html
1010

@@ -84,6 +84,9 @@ You can also follow us on Twitter! **[@paystack](http://twitter.com/paystack)**
8484

8585

8686
== Changelog ==
87+
= 2.1.2 =
88+
* Checkbox form Element.
89+
* Special feature: Custom Start date use case for subscriptions.
8790
= 2.1.1 =
8891
* Bug fixes for minimum amount.
8992
= 2.1.0 =

admin/class-paystack-forms-admin.php

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,7 @@ function kkd_pff_paystack_editor_add_extra_metaboxes() {
266266
add_meta_box('kkd_pff_paystack_editor_add_quantity_data', 'Quantity Payment', 'kkd_pff_paystack_editor_add_quantity_data', 'paystack_form', 'side', 'default');
267267
add_meta_box('kkd_pff_paystack_editor_add_agreement_data', 'Agreement checkbox', 'kkd_pff_paystack_editor_add_agreement_data', 'paystack_form', 'side', 'default');
268268
add_meta_box('kkd_pff_paystack_editor_add_subaccount_data', 'Sub Account', 'kkd_pff_paystack_editor_add_subaccount_data', 'paystack_form', 'side', 'default');
269+
add_meta_box('kkd_pff_paystack_editor_add_startdateplan_data', '*Special: Subscribe to plan after time', 'kkd_pff_paystack_editor_add_startdateplan_data', 'paystack_form', 'side', 'default');
269270

270271
}
271272

@@ -475,6 +476,33 @@ function kkd_pff_paystack_editor_add_subaccount_data() {
475476
echo '<input type="text" name="_merchantamount" value="' . $merchantamount . '" class="widefat" />';
476477

477478
}
479+
function kkd_pff_paystack_editor_add_startdateplan_data() {
480+
global $post;
481+
482+
// Noncename needed to verify where the data originated
483+
echo '<p>User subscribes to plan after number of days:</p>';
484+
echo '<input type="hidden" name="eventmeta_noncename" id="eventmeta_noncename" value="' .
485+
wp_create_nonce( plugin_basename(__FILE__) ) . '" />';
486+
487+
// Get the location data if its already been entered
488+
$days = get_post_meta($post->ID, '_startdate_days', true);
489+
$plan = get_post_meta($post->ID, '_startdate_plan_code', true);
490+
$enabled = get_post_meta($post->ID, '_startdate_enabled', true);
491+
492+
493+
if ($days == "") {$days = '';}
494+
if ($plan == "") {$plan = '';}
495+
if ($enabled == "") {$enabled = 0;}
496+
echo '<p>Number of days:</p>';
497+
echo '<input type="number" name="_startdate_days" value="' . $days . '" class="widefat pf-number" />';
498+
echo '<p>Plan:</p>';
499+
echo '<input type="text" name="_startdate_plan_code" value="' . $plan . '" class="widefat" />';
500+
if ($enabled == 1) {
501+
echo '<p><br><label><input name="_startdate_enabled" type="checkbox" value="1" checked> Enable </label></p>';
502+
}else{
503+
echo '<p><br><label><input name="_startdate_enabled" type="checkbox" value="1"> Enable </label></p>';
504+
}
505+
}
478506
function kkd_pff_paystack_save_data($post_id, $post) {
479507

480508
if ( !wp_verify_nonce( @$_POST['eventmeta_noncename'], plugin_basename(__FILE__) )) {
@@ -517,6 +545,11 @@ function kkd_pff_paystack_save_data($post_id, $post) {
517545
$form_meta['_merchantamount'] = $_POST['_merchantamount'];
518546
// Add values of $form_meta as custom fields
519547

548+
//Custom Plan with Start Date
549+
$form_meta['_startdate_days'] = $_POST['_startdate_days'];
550+
$form_meta['_startdate_plan_code'] = $_POST['_startdate_plan_code'];
551+
$form_meta['_startdate_enabled'] = $_POST['_startdate_enabled'];
552+
520553
foreach ($form_meta as $key => $value) { // Cycle through the $form_meta array!
521554
if( $post->post_type == 'revision' ) return; // Don't store custom data twice
522555
$value = implode(',', (array)$value); // If $value is an array, make it a CSV (unlikely)
@@ -820,7 +853,7 @@ public function column_default( $item, $column_name ){
820853
*/
821854
private function sort_data( $a, $b ){
822855
$orderby = 'date';
823-
$order = 'asc';
856+
$order = 'desc';
824857
if(!empty($_GET['orderby'])){
825858
$orderby = $_GET['orderby'];
826859
}

paystack-forms.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
Plugin Name: Payment forms for Paystack
44
Plugin URI: https://github.com/Kendysond/Wordpress-paystack-forms
55
Description: Payment forms for Paystack allows you create forms that will be used to bill clients for goods and services via Paystack.
6-
Version: 2.1.1
6+
Version: 2.1.2
77
Author: Douglas Kendyson
88
Author URI: http://kendyson.com
99
License: GPL-2.0+

public/class-paystack-forms-public.php

Lines changed: 50 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,9 @@ function kkd_pff_paystack_add_paystack_charge($amount)
6060
// $amountinkobo = $amount; // * 100;
6161
$amount = intval($amount);
6262
if ($amount <= 2500) {
63-
$amount = $amount + ($amount*KKD_PFF_PAYSTACK_PERCENTAGE);
63+
$amount = $amount + floatval($amount*KKD_PFF_PAYSTACK_PERCENTAGE);
6464
}else{
65-
$amount = $amount + ($amount*KKD_PFF_PAYSTACK_PERCENTAGE)+100;
65+
$amount = $amount + floatval($amount*KKD_PFF_PAYSTACK_PERCENTAGE)+100;
6666

6767
}
6868
return $amount;
@@ -1361,6 +1361,7 @@ function kkd_pff_paystack_submit_action() {
13611361
unset($metadata['pf-plancode']);
13621362
}
13631363
}
1364+
13641365
if($plancode != 'none'){
13651366
$fixedmetadata[] = array(
13661367
'display_name' => 'Plan',
@@ -1410,20 +1411,23 @@ function kkd_pff_paystack_submit_action() {
14101411
if ($transaction_charge == "" || $transaction_charge == 0 || $transaction_charge == NULL) {
14111412
$transaction_charge = NULL;
14121413
}
1414+
1415+
$amount = floatval($insert['amount'])*100;
14131416
$response = array(
14141417
'result' => 'success',
14151418
'code' => $insert['txn_code'],
14161419
'plan' => $insert['plan'],
14171420
'quantity' => $quantity,
14181421
'email' => $insert['email'],
14191422
'name' => $fullname,
1420-
'total' => $insert['amount']*100,
1423+
'total' => round($amount),
14211424
'custom_fields' => $fixedmetadata,
14221425
'subaccount' => $subaccount,
14231426
'txnbearer' => $txnbearer,
14241427
'transaction_charge' => $transaction_charge
14251428
);
1426-
echo json_encode($response);
1429+
// print_r($response);
1430+
echo json_encode($response,JSON_NUMERIC_CHECK);
14271431

14281432
die();
14291433
}
@@ -1534,6 +1538,7 @@ function kkd_pff_paystack_confirm_payment() {
15341538
if( ! is_wp_error( $request ) && 200 == wp_remote_retrieve_response_code( $request ) ) {
15351539
$paystack_response = json_decode( wp_remote_retrieve_body( $request ) );
15361540
if ( 'success' == $paystack_response->data->status ) {
1541+
$customer_code = $paystack_response->data->customer->customer_code;
15371542
$amount_paid = $paystack_response->data->amount / 100;
15381543
$paystack_ref = $paystack_response->data->reference;
15391544
if ($recur == 'optional' || $recur == 'plan') {
@@ -1601,6 +1606,47 @@ function kkd_pff_paystack_confirm_payment() {
16011606
}
16021607

16031608
if ($result == 'success') {
1609+
///
1610+
//Create Plan
1611+
$enabled_custom_plan = get_post_meta($payment_array->post_id, '_startdate_enabled', true);
1612+
if ($enabled_custom_plan == 1) {
1613+
$mode = esc_attr( get_option('mode') );
1614+
if ($mode == 'test') {
1615+
$key = esc_attr( get_option('tsk') );
1616+
}else{
1617+
$key = esc_attr( get_option('lsk') );
1618+
}
1619+
//Create Plan
1620+
$paystack_url = 'https://api.paystack.co/subscription';
1621+
$headers = array(
1622+
'Content-Type' => 'application/json',
1623+
'Authorization' => 'Bearer ' . $key
1624+
);
1625+
$custom_plan = get_post_meta($payment_array->post_id, '_startdate_plan_code', true);
1626+
$days = get_post_meta($payment_array->post_id, '_startdate_days', true);
1627+
1628+
$start_date = date("c", strtotime("+".$days." days"));
1629+
$body = array(
1630+
'start_date' => $start_date,
1631+
'plan' => $custom_plan,
1632+
'customer' => $customer_code
1633+
);
1634+
$args = array(
1635+
'body' => json_encode( $body ),
1636+
'headers' => $headers,
1637+
'timeout' => 60
1638+
);
1639+
1640+
$request = wp_remote_post( $paystack_url, $args );
1641+
if( ! is_wp_error( $request )) {
1642+
$paystack_response = json_decode(wp_remote_retrieve_body($request));
1643+
$plancode = $paystack_response->data->subscription_code;
1644+
// $message.= $message.'Subscribed<br>'.$plancode.'sssss';
1645+
1646+
1647+
}
1648+
}
1649+
16041650
$sendreceipt = get_post_meta($payment_array->post_id, '_sendreceipt', true);
16051651
if($sendreceipt == 'yes'){
16061652
$decoded = json_decode($payment_array->metadata);

0 commit comments

Comments
 (0)