Skip to content

Commit

Permalink
Added resend STK Push button on thank you page.
Browse files Browse the repository at this point in the history
  • Loading branch information
maukoese committed Jun 11, 2020
1 parent 1986838 commit e37df21
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 36 deletions.
39 changes: 34 additions & 5 deletions inc/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,6 @@ function wc_mpesa_post_id_by_meta_key_and_value($key, $value)
$reference = $order_id;
}

if ($order->get_payment_method() !== 'mpesa') {
return;
}

$type = ($idtype == 4) ? 'Pay Bill' : 'Buy Goods and Services'; ?>
<style>
@keyframes wave {
Expand Down Expand Up @@ -91,7 +87,7 @@ function wc_mpesa_post_id_by_meta_key_and_value($key, $value)
<thead>
<tr>
<th class="woocommerce-table__product-name product-name">
<?php _e("STK Push didn't work? Pay Manually Via M-PESA") ?>
<?php _e("STK Push didn't work? Pay Manually Via M-PESA"); ?>
</th>
</tr>
</thead>
Expand All @@ -113,6 +109,15 @@ function wc_mpesa_post_id_by_meta_key_and_value($key, $value)
<li>Confirm your details and press OK.</li>
<li>Wait for a confirmation message from M-PESA.</li>
</ol>

</td>
</tr>
<tr class="woocommerce-table__line-item order_item">
<td class="woocommerce-table__product-name product-name">
<form action="<?php echo home_url("lipwa/request"); ?>" mhod="POST" id="renitiate-form">
<input type="hidden" name="order" value="<?php echo $order_id; ?>">
<button id="renitiate-button" class="button alt" type="submit">Resend STK Push</button>
</form>
</td>
</tr>
</tbody>
Expand All @@ -123,6 +128,18 @@ function wc_mpesa_post_id_by_meta_key_and_value($key, $value)
echo <<<JS
<script id="pesaipn-checker">
jQuery(document).ready(function($) {
$('#renitiate-form').submit(function(e){
e.preventDefault();
var form = $(this);
$.post(form.attr('action'), form.serialize(), function(response){
$("#mpesa_receipt").html(
'STK Resent. Confirming payment <span>.</span><span>.</span><span>.</span><span>.</span><span>.</span><span>.</span>'
);
});
});
var checker = setInterval(() => {
if ($("#payment_method").length && $("#payment_method").val() !== 'mpesa') {
clearInterval(checker);
Expand Down Expand Up @@ -199,6 +216,18 @@ function wc_mpesa_process_ipn()
$action = get_query_var('lipwa', 'something_ominous');

switch ($action) {
case "request":
$order_id = $_POST['order'];
$order = new WC_Order($order_id);
$total = $order->get_total();
$phone = $order->get_billing_phone();
$first_name = $order->get_billing_first_name();
$last_name = $order->get_billing_last_name();

$result = Osen\Mpesa\STK::request($phone, $total, $order_id, get_bloginfo('name') . ' Purchase', 'WCMPesa');

wp_send_json($result);
break;
case "validate":
exit(wp_send_json(
Osen\Mpesa\STK::validate()
Expand Down
24 changes: 12 additions & 12 deletions inc/wc_mpesa_gateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ class WC_MPESA_Gateway extends WC_Payment_Gateway
public function __construct()
{

$env = get_option('woocommerce_mpesa_settings')["env"];
$b2c_settings = (isset(get_option('woocommerce_mpesa_settings')['enable_b2c']) && get_option('woocommerce_mpesa_settings')['enable_b2c'] == 'yes')
$env = $this->get_option('env', 'sandbox');
$b2c_settings = ($this->get_option('enable_b2c', 'no') == 'yes')
? '<strong>These settings are for Customer-2-Business payments. Click here to <a href="' . admin_url('edit.php?post_type=mpesaipn&page=wc_mpesa_b2c_preferences') . '">Setup Business-2-Customer</a>.</strong>'
: '';

Expand Down Expand Up @@ -180,13 +180,13 @@ public function init_form_fields()
You will receive a confirmation message shortly thereafter.', 'woocommerce'),
'desc_tip' => true,
),
// 'instructions' => array(
// 'title' => __('Instructions', 'woocommerce'),
// 'type' => 'textarea',
// 'description' => __('Instructions that will be added to the thank you page.', 'woocommerce'),
// 'default' => __('Thank you for buying from us. You will receive a confirmation message from MPesa shortly.', 'woocommerce'),
// 'desc_tip' => true,
// ),
'instructions' => array(
'title' => __('Instructions', 'woocommerce'),
'type' => 'textarea',
'description' => __('Instructions that will be added to the thank you page.', 'woocommerce'),
'default' => __('Thank you for buying from us. Your order will be processed once we confirm your payment.', 'woocommerce'),
'desc_tip' => true,
),
// 'account' => array(
// 'title' => __('Account Name', 'woocommerce'),
// 'type' => 'text',
Expand Down Expand Up @@ -392,9 +392,9 @@ public function process_payment($order_id)
*/
public function thankyou_page()
{
// if ($this->instructions) {
// echo wpautop(wptexturize($this->instructions));
// }
if ($this->instructions) {
echo wpautop(wptexturize($this->instructions));
}
}

/**
Expand Down
22 changes: 9 additions & 13 deletions osen-wc-mpesa.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
/**
* @package Mpesa For WooCommerce
* @author Osen Concepts < [email protected] >
* @version 1.20.64
* @version 1.20.65
*
* Plugin Name: MPesa For WooCommerce
* Plugin URI: https://wc-mpesa.osen.co.ke/
* Description: This plugin extends WordPress and WooCommerce functionality to integrate <cite>Mpesa</cite> for making and receiving online payments.
* Author: Osen Concepts Kenya < [email protected] >
* Version: 1.20.64
* Version: 1.20.65
* Author URI: https://osen.co.ke/
*
* Requires at least: 4.6
Expand Down Expand Up @@ -47,26 +47,22 @@
define('WCM_PLUGIN_FILE', __FILE__);
}

add_action('wp', function () {
if (!in_array('woocommerce/woocommerce.php', apply_filters('active_plugins', get_option('active_plugins')))) {
deactivate_plugins(plugin_basename(__FILE__));
}
});

register_activation_hook(__FILE__, 'wc_mpesa_activation_check');
function wc_mpesa_activation_check()
{
if (!get_option('wc_mpesa_flush_rewrite_rules_flag')) {
add_option('wc_mpesa_flush_rewrite_rules_flag', true);
}

if (!in_array('woocommerce/woocommerce.php', apply_filters('active_plugins', get_option('active_plugins')))) {
deactivate_plugins(plugin_basename(__FILE__));
exit('Please Install/Activate WooCommerce for the MPesa extension to work');
}

if (!is_plugin_active('woocommerce/woocommerce.php')) {
deactivate_plugins(plugin_basename(__FILE__));

add_action('admin_notices', function () {
$class = 'notice notice-error is-dismissible';
$message = __('Please Install/Activate WooCommerce for this extension to work..', 'woocommerce');

printf('<div class="%1$s"><p>%2$s</p></div>', esc_attr($class), esc_html($message));
});
}
}

Expand Down
12 changes: 6 additions & 6 deletions updates.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
"name": "Mpesa for Woocommerce",
"version": "1.20.64",
"download_url": "https://github.com/osenco/osen-wc-mpesa/archive/v1.20.64.zip",
"version": "1.20.65",
"download_url": "https://github.com/osenco/osen-wc-mpesa/archive/v1.20.65.zip",

"homepage": "https://wc-mpesa.osen.co.ke/",
"requires": "4.5",
"tested": "5.4",
"last_updated": "2020-06-04 14:17:00",
"last_updated": "2020-06-11 15:00:00",
"upgrade_notice": "Autoupdates from here on",

"author": "Osen Concepts",
Expand All @@ -15,7 +15,7 @@
"sections": {
"description": "<p>This plugin seeks to provide a simple plug-n-play implementation for integrating M-Pesa Payments into online stores built with WooCommerce and WordPress.</p>",
"installation": "Download the latest release from Github, and extract the zip file in your plugins directory of your WordPress instalation",
"changelog": "<ul><li>Changed paths from /wcpesa to /lipwa to avoid blacklisted names</li><li>Auto updates enabled</li><li>Reorder account number and paybill in C2B instructions</li><li>Mark order as cancelled if STK push times out or is cancelled</li></ul>",
"changelog": "<ul><li>Added resend STK Push button on thank you page.</li><li>Changed paths from /wcpesa to /lipwa to avoid blacklisted names</li><li>Auto updates enabled</li><li>Reorder account number and paybill in C2B instructions</li><li>Mark order as cancelled if STK push times out or is cancelled</li></ul>",
"going_live": "<p>While we have made all efforts to ensure this plugin works out of the box - with minimum configuration required - the service provider requires that the user go through a certain ardous process to migrate from sandbox(test) environment to production.</p><p>We have made a <a href='https://wc-mpesa.osen.co.ke/going-live'>tutorial here</a> to walk you through the process. We however have a team ready on call to assist you in this are, at a fiat fee of KSh 4000 one-off, should you find it difficult.</p>"
},

Expand All @@ -30,8 +30,8 @@
},

"rating": 90,
"num_ratings": 560,
"num_ratings": 1070,

"downloaded": 859,
"downloaded": 929,
"active_installs": 845
}

0 comments on commit e37df21

Please sign in to comment.