diff --git a/inc/functions.php b/inc/functions.php
index b737643..534881e 100755
--- a/inc/functions.php
+++ b/inc/functions.php
@@ -179,24 +179,24 @@ function wc_mpesa_post_id_by_meta_key_and_value($key, $value)
add_action('init', 'wc_mpesa_rewrite_add_rewrites');
function wc_mpesa_rewrite_add_rewrites()
{
- add_rewrite_rule('wcpesa/([^/]*)/?', 'index.php?wcpesa=$matches[1]', 'top');
+ add_rewrite_rule('lipwa/([^/]*)/?', 'index.php?lipwa=$matches[1]', 'top');
}
add_filter('query_vars', 'wc_mpesa_rewrite_add_var');
function wc_mpesa_rewrite_add_var($vars)
{
- $vars[] = 'wcpesa';
+ $vars[] = 'lipwa';
return $vars;
}
add_action('template_redirect', 'wc_mpesa_process_ipn');
function wc_mpesa_process_ipn()
{
- if (get_query_var('wcpesa')) {
+ if (get_query_var('lipwa')) {
header("Access-Control-Allow-Origin: *");
header("Content-Type: Application/json");
- $action = get_query_var('wcpesa', 'something_ominous');
+ $action = get_query_var('lipwa', 'something_ominous');
switch ($action) {
case "validate":
@@ -327,7 +327,6 @@ function wc_mpesa_process_ipn()
$resultCode = $response['Body']['stkCallback']['ResultCode'];
$resultDesc = $response['Body']['stkCallback']['ResultDesc'];
$merchantRequestID = $response['Body']['stkCallback']['MerchantRequestID'];
- $checkoutRequestID = $response['Body']['stkCallback']['CheckoutRequestID'];
$post = wc_mpesa_post_id_by_meta_key_and_value('_request_id', $merchantRequestID);
wp_update_post(['post_content' => file_get_contents('php://input'), 'ID' => $post]);
@@ -341,22 +340,16 @@ function wc_mpesa_process_ipn()
$first_name = $order->get_billing_first_name();
$last_name = $order->get_billing_last_name();
$customer = "{$first_name} {$last_name}";
- } else {
- $customer = "MPesa Customer";
- }
-
- if (isset($response['Body']['stkCallback']['CallbackMetadata'])) {
- $amount = $response['Body']['stkCallback']['CallbackMetadata']['Item'][0]['Value'];
- $mpesaReceiptNumber = $response['Body']['stkCallback']['CallbackMetadata']['Item'][1]['Value'];
- $balance = $response['Body']['stkCallback']['CallbackMetadata']['Item'][2]['Value'];
- $transactionDate = $response['Body']['stkCallback']['CallbackMetadata']['Item'][3]['Value'];
- $phone = $response['Body']['stkCallback']['CallbackMetadata']['Item'][4]['Value'];
- $after_ipn_paid = round($before_ipn_paid) + round($amount);
- $ipn_balance = $after_ipn_paid - $amount_due;
+ if (isset($response['Body']['stkCallback']['CallbackMetadata'])) {
+ $amount = $response['Body']['stkCallback']['CallbackMetadata']['Item'][0]['Value'];
+ $mpesaReceiptNumber = $response['Body']['stkCallback']['CallbackMetadata']['Item'][1]['Value'];
+ $balance = $response['Body']['stkCallback']['CallbackMetadata']['Item'][2]['Value'];
+ $transactionDate = $response['Body']['stkCallback']['CallbackMetadata']['Item'][3]['Value'];
+ $phone = $response['Body']['stkCallback']['CallbackMetadata']['Item'][4]['Value'];
- if (wc_get_order($order_id)) {
- $order = new WC_Order($order_id);
+ $after_ipn_paid = round($before_ipn_paid) + round($amount);
+ $ipn_balance = $after_ipn_paid - $amount_due;
if ($ipn_balance == 0) {
update_post_meta($post, '_order_status', 'complete');
@@ -375,24 +368,25 @@ function wc_mpesa_process_ipn()
$order->add_order_note(__("MPesa Payment from {$phone} Incomplete"));
update_post_meta($post, '_order_status', 'on-hold');
}
- }
- update_post_meta($post, '_paid', $after_ipn_paid);
- update_post_meta($post, '_amount', $amount_due);
- update_post_meta($post, '_balance', $ipn_balance);
- update_post_meta($post, '_phone', $phone);
- update_post_meta($post, '_customer', $customer);
- update_post_meta($post, '_order_id', $order_id);
- update_post_meta($post, '_receipt', $mpesaReceiptNumber);
- } else {
- if (wc_get_order($order_id)) {
- $order = new WC_Order($order_id);
- $order->update_status('on-hold');
+ update_post_meta($post, '_paid', $after_ipn_paid);
+ update_post_meta($post, '_amount', $amount_due);
+ update_post_meta($post, '_balance', $ipn_balance);
+ update_post_meta($post, '_phone', $phone);
+ update_post_meta($post, '_customer', $customer);
+ update_post_meta($post, '_order_id', $order_id);
+ update_post_meta($post, '_receipt', $mpesaReceiptNumber);
+ } else {
+ $order->update_status('cancelled');
$order->add_order_note(__("MPesa Error {$resultCode}: {$resultDesc}"));
}
- }
- exit(wp_send_json(Osen\Mpesa\STK::reconcile()));
+ exit(wp_send_json(Osen\Mpesa\STK::reconcile()));
+ } else {
+ exit(wp_send_json(Osen\Mpesa\STK::reconcile(function () {
+ return false;
+ })));
+ }
break;
case "status":
diff --git a/inc/wc_mpesa_gateway.php b/inc/wc_mpesa_gateway.php
index a4cfbbc..2c4e3aa 100755
--- a/inc/wc_mpesa_gateway.php
+++ b/inc/wc_mpesa_gateway.php
@@ -232,9 +232,9 @@ public function init_form_fields()
),
'enable_c2b' => array(
'title' => __('Manual Payments', 'woocommerce'),
- 'label' => __('Enable C2B API', 'woocommerce'),
+ 'label' => __('Enable C2B API(Offline Payments)', 'woocommerce'),
'type' => 'checkbox',
- 'description' => '' . (($this->get_option('idtype') == 4) ? 'This requires C2B Validation, which is an optional feature that needs to be activated on M-Pesa.
Request for activation by sending an email to apisupport@safaricom.co.ke, or through a chat on the developer portal.
Once enabled, ' : '') . 'Click here to register confirmation & validation URLs',
+ 'description' => '' . (($this->get_option('idtype') == 4) ? 'This requires C2B Validation, which is an optional feature that needs to be activated on M-Pesa.
Request for activation by sending an email to apisupport@safaricom.co.ke, or through a chat on the developer portal.
' : '') . 'Once enabled, click here to register confirmation & validation URLs
Kindly note that if this is disabled, the user can still resend an STK push if the first one fails.
', 'default' => 'no', ), // 'enable_b2c' => array( diff --git a/osen-wc-mpesa.php b/osen-wc-mpesa.php index 4a3934a..dc400dc 100755 --- a/osen-wc-mpesa.php +++ b/osen-wc-mpesa.php @@ -3,20 +3,20 @@ /** * @package Mpesa For WooCommerce * @author Osen Concepts < hi@osen.co.ke > - * @version 1.20.56 + * @version 1.20.57 * * Plugin Name: MPesa For WooCommerce * Plugin URI: https://wc-mpesa.osen.co.ke/ * Description: This plugin extends WordPress and WooCommerce functionality to integrate Mpesa for making and receiving online payments. * Author: Osen Concepts Kenya < hi@osen.co.ke > - * Version: 1.20.56 + * Version: 1.20.57 * Author URI: https://osen.co.ke/ * * Requires at least: 4.6 * Tested up to: 5.4 * * WC requires at least: 3.5.0 - * WC tested up to: 4.0 + * WC tested up to: 4.1 * * License: GPLv3 * License URI: http://www.gnu.org/licenses/gpl-3.0.html @@ -140,8 +140,8 @@ function mpesa_row_meta($links, $file) /** * Initialize all our custom post types */ -Osen\Post\Types\C2B::init(); //Osen\Post\Types\B2C::init(); +Osen\Post\Types\C2B::init(); /** * Initialize our admin menus @@ -221,6 +221,9 @@ function mpesa_row_meta($links, $file) require_once $filename; } +/** + * Auto-updates + */ require __DIR__ . '/updates/plugin-update-checker.php'; $myUpdateChecker = Puc_v4_Factory::buildUpdateChecker( 'https://raw.githubusercontent.com/osenco/osen-wc-mpesa/master/updates.json', diff --git a/updates.json b/updates.json index 33c5bd5..b565239 100644 --- a/updates.json +++ b/updates.json @@ -1,12 +1,12 @@ { "name": "Mpesa for Woocommerce", - "version": "1.20.56", - "download_url": "https://github.com/osenco/osen-wc-mpesa/archive/v1.20.56.zip", + "version": "1.20.57", + "download_url": "https://github.com/osenco/osen-wc-mpesa/archive/v1.20.57.zip", "homepage": "https://wc-mpesa.osen.co.ke/", "requires": "4.5", "tested": "5.4", - "last_updated": "2020-05-24 16:17:00", + "last_updated": "2020-05-27 14:17:00", "upgrade_notice": "Autoupdates from here on", "author": "Osen Concepts", @@ -15,7 +15,7 @@ "sections": { "description": "This plugin seeks to provide a simple plug-n-play implementation for integrating M-Pesa Payments into online stores built with WooCommerce and WordPress.
", "installation": "Download the latest release from Github, and extract the zip file in your plugins directory of your WordPress instalation", - "changelog": "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.
We have made a tutorial here 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.
" },