From dc9d7cd114a796a1bc48489aa7f6146a117d69a2 Mon Sep 17 00:00:00 2001
From: Mauko Maunde Confirming receipt, please wait Kindly note that if this is disabled, the user can still resend an STK push if the first one fails. Mpesa request body %2$s %2$s Add here the MPesa confirmation code received and set the appropriate order status for Request ID: .
+
+
@@ -121,14 +136,6 @@ function wc_mpesa_process_order($order)
-
+
+
+
+
+
+
-
@@ -234,13 +241,13 @@ function wc_mpesa_process_ipn()
$first_name = $order->get_billing_first_name();
$last_name = $order->get_billing_last_name();
- $result = Osen\Woocommerce\Mpesa\STK::request($phone, $total, $order_id, get_bloginfo('name') . ' Purchase', 'WCMPesa');
+ $result = STK::request($phone, $total, $order_id, get_bloginfo('name') . ' Purchase', 'WCMPesa');
wp_send_json($result);
break;
case "validate":
exit(wp_send_json(
- Osen\Woocommerce\Mpesa\STK::validate()
+ STK::validate()
));
break;
@@ -309,7 +316,7 @@ function wc_mpesa_process_ipn()
update_post_meta($post, '_order_status', 'complete');
$headers = 'From: ' . get_bloginfo('name') . ' <' . get_bloginfo('admin_email') . '>' . "\r\n";
- wp_mail($order["billing_address"], 'Your Mpesa payment', 'We acknowledge receipt of your payment via MPesa of KSh. ' . $amount . ' on ' . $transactionDate . 'with receipt Number ' . $mpesaReceiptNumber . '.', $headers);
+ wp_mail($order->get_billing_email(), 'Your Mpesa payment', 'We acknowledge receipt of your payment via MPesa of KSh. ' . $amount . ' on ' . $transactionDate . 'with receipt Number ' . $mpesaReceiptNumber . '.', $headers);
} elseif ($ipn_balance < 0) {
$currency = get_woocommerce_currency();
$order->update_status((isset($mpesa['completion']) ? $mpesa['completion'] : 'completed'), __("{$phone} has overpayed by {$currency} {$ipn_balance}. Receipt Number {$mpesaReceiptNumber}"));
@@ -329,11 +336,11 @@ function wc_mpesa_process_ipn()
update_post_meta($post, '_order_id', $order_id);
update_post_meta($post, '_receipt', $mpesaReceiptNumber);
- exit(wp_send_json(Osen\Woocommerce\Mpesa\STK::confirm()));
+ exit(wp_send_json(STK::confirm()));
break;
case "register":
- Osen\Woocommerce\Mpesa\C2B::register(function ($response) {
+ C2B::register(function ($response) {
$status = isset($response['ResponseDescription']) ? 'success' : 'fail';
if ($status == 'fail') {
$message = isset($response['errorMessage']) ? $response['errorMessage'] : 'Could not register M-PESA URLs, try again later.';
@@ -396,7 +403,7 @@ function wc_mpesa_process_ipn()
$order->update_status((isset($mpesa['completion']) ? $mpesa['completion'] : 'completed'), __("Full MPesa Payment Received From {$phone}. Receipt Number {$mpesaReceiptNumber}"));
$headers[] = 'From: ' . get_bloginfo('name') . ' <' . get_bloginfo('admin_email') . '>' . "\r\n";
- wp_mail($order["billing_address"], 'Your Mpesa payment', 'We acknowledge receipt of your payment via MPesa of KSh. ' . $amount . ' on ' . $transactionDate . '. Receipt number ' . $mpesaReceiptNumber, $headers);
+ wp_mail($order->get_billing_email(), 'Your Mpesa payment', 'We acknowledge receipt of your payment via MPesa of KSh. ' . $amount . ' on ' . $transactionDate . '. Receipt number ' . $mpesaReceiptNumber, $headers);
} elseif ($ipn_balance < 0) {
$currency = get_woocommerce_currency();
$order->update_status((isset($mpesa['completion']) ? $mpesa['completion'] : 'completed'), __("{$phone} has overpayed by {$currency} {$ipn_balance}. Receipt Number {$mpesaReceiptNumber}"));
@@ -420,9 +427,9 @@ function wc_mpesa_process_ipn()
$order->add_order_note(__("MPesa Error {$resultCode}: {$resultDesc}"));
}
- exit(wp_send_json(Osen\Woocommerce\Mpesa\STK::reconcile()));
+ exit(wp_send_json(STK::reconcile()));
} else {
- exit(wp_send_json(Osen\Woocommerce\Mpesa\STK::reconcile(function () {
+ exit(wp_send_json(STK::reconcile(function () {
return false;
})));
}
@@ -430,7 +437,7 @@ function wc_mpesa_process_ipn()
case "status":
$transaction = $_POST['transaction'];
- exit(wp_send_json(Osen\Woocommerce\Mpesa\STK::status($transaction)));
+ exit(wp_send_json(STK::status($transaction)));
break;
case "result":
@@ -466,7 +473,7 @@ function wc_mpesa_process_ipn()
$ReferenceData = $result['ReferenceData'];
$ReferenceItem = $ReferenceData['ReferenceItem'];
$Occasion = $ReferenceItem[0]['Value'];
- exit(wp_send_json(Osen\Woocommerce\Mpesa\STK::validate()));
+ exit(wp_send_json(STK::validate()));
break;
case "timeout":
@@ -493,10 +500,10 @@ function wc_mpesa_process_ipn()
$order->add_order_note(__("MPesa Payment Timed Out", 'woocommerce'));
}
- exit(wp_send_json(Osen\Woocommerce\Mpesa\STK::timeout()));
+ exit(wp_send_json(STK::timeout()));
break;
default:
- exit(wp_send_json(Osen\Woocommerce\Mpesa\C2B::register()));
+ exit(wp_send_json(C2B::register()));
}
}
diff --git a/inc/wc_mpesa_gateway.php b/inc/wc_mpesa_gateway.php
index 77c9dd2..8089862 100755
--- a/inc/wc_mpesa_gateway.php
+++ b/inc/wc_mpesa_gateway.php
@@ -2,7 +2,7 @@
/**
* @package MPesa For WooCommerce
- * @subpackage WooCommerce Functions
+ * @subpackage WooCommerce Mpesa Gateway
* @author Osen Concepts < hi@osen.co.ke >
* @since 0.18.01
*/
@@ -47,26 +47,26 @@ class WC_MPESA_Gateway extends WC_Payment_Gateway
* Constructor for the gateway.
*/
public function __construct()
- {
+ {
$this->id = 'mpesa';
$this->icon = apply_filters('woocommerce_mpesa_icon', plugins_url('mpesa.png', __FILE__));
- $this->method_title = __('Lipa Na MPesa', 'woocommerce');
-
+ $this->method_title = __('Lipa Na MPesa', 'woocommerce');
+
// Load settings
$this->init_form_fields();
- $this->init_settings();
-
+ $this->init_settings();
+
$env = $this->get_option('env', 'sandbox');
$b2c_settings = ($this->get_option('enable_b2c', 'no') == 'yes')
- ? 'These settings are for Customer-2-Business payments. Click here to Setup Business-2-Customer.'
- : '';
+ ? 'These settings are for Customer-2-Business payments. Click here to Setup Business-2-Customer.'
+ : '';
$test_cred = ($env == 'sandbox')
- ? '
-
-
- IMPORTANT!
' . $b2c_settings . '
We offer the service at a fiat fee of KSh 4000. Call +254204404993 or email hi@osen.co.ke if you need help.IMPORTANT!
' . $b2c_settings . '
We offer the service at a fiat fee of KSh 4000. Call +254204404993 or email hi@osen.co.ke if you need help.
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
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(
@@ -260,10 +260,10 @@ public function init_form_fields()
// ),
'debug' => array(
'title' => __('Debug Mode', 'woocommerce'),
- 'label' => __('Check to enable debug mode and show request body', 'woocommerce').$this->get_option('debug'),
+ 'label' => __('Check to enable debug mode and show request body', 'woocommerce'),
'type' => 'checkbox',
'default' => 'no',
- 'description' => '' .__('Show Request Body(to send to Daraja on request)', 'woocommerce').''
+ 'description' => '' . __('Show Request Body(to send to Daraja team on request)', 'woocommerce') . ''
)
);
}
@@ -335,17 +335,18 @@ public function process_payment($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();
-
- $c2b = get_option('woocommerce_mpesa_settings');
+ $last_name = $order->get_billing_last_name();
+
+ $c2b = get_option('woocommerce_mpesa_settings');
if (($c2b['debug'] ?? 'no') == 'yes') {
$result = STK::request($phone, $total, $order_id, get_bloginfo('name') . ' Purchase', 'WCMPesa', true);
- WC()->session->set('mpesa_request', json_encode($result['requested']));
+ $message = json_encode($result['requested']);
+ WC()->session->set('mpesa_request', $message);
} else {
$result = STK::request($phone, $total, $order_id, get_bloginfo('name') . ' Purchase', 'WCMPesa');
- }
-
+ }
+
if ($result) {
$request_id = $result['MerchantRequestID'];
diff --git a/inc/woocommerce.php b/inc/woocommerce.php
index 5411eaa..2030141 100755
--- a/inc/woocommerce.php
+++ b/inc/woocommerce.php
@@ -16,7 +16,7 @@ function wcmpesa_new_order_column($columns)
/**
* Render custom column content within edit.php table on event post types.
- *
+ *
* @access public
* @param string $column The name of the column being acted upon
* @return void
@@ -30,11 +30,11 @@ function shop_order_payments_table_column_content($column_id, $post_id)
case 'mpesa':
$statuses = array(
"processing" => "This Order Is Processing",
- "on-hold" => "This Order Is On Hold",
- "complete" => "This Order Is Complete",
- "cancelled" => "This Order Is Cancelled",
- "refunded" => "This Order Is Refunded",
- "failed" => "This Order Failed"
+ "on-hold" => "This Order Is On Hold",
+ "complete" => "This Order Is Complete",
+ "cancelled" => "This Order Is Cancelled",
+ "refunded" => "This Order Is Refunded",
+ "failed" => "This Order Failed",
);
echo ($value = get_post_meta($post_id, '_order_status', true)) ? '' . esc_attr($statuses[$value]) . '') : 'Set Status';
@@ -78,7 +78,7 @@ function woocommerce_emails_attach_downloadables($attachments, $status, $order)
echo '
'.WC()->session->get('mpesa_request').'
+ ' . WC()->session->get('mpesa_request') . '
@@ -64,7 +66,8 @@ public static function mpesa_status($post)
';
@@ -82,15 +96,15 @@ public static function mpesa_status($post)
public static function customer_details($post)
{
- $customer = get_post_meta($post->ID, '_customer', true);
- $phone = get_post_meta($post->ID, '_phone', true);
+ $customer = get_post_meta($post->ID, '_customer', true);
+ $phone = get_post_meta($post->ID, '_phone', true);
if (isset($_GET['order'])) {
- $order = new \WC_Order($_GET['order']);
- $total = wc_format_decimal($order->get_total(), 2);
- $phone = $order->get_billing_phone();
+ $order = new \WC_Order($_GET['order']);
+ $total = wc_format_decimal($order->get_total(), 2);
+ $phone = $order->get_billing_phone();
$first_name = $order->get_billing_first_name();
- $last_name = $order->get_billing_last_name();
- $customer = "{$first_name} {$last_name}";
+ $last_name = $order->get_billing_last_name();
+ $customer = "{$first_name} {$last_name}";
}
// Remove the plus sign before the customer's phone number
@@ -117,19 +131,19 @@ public static function customer_details($post)
public static function order_details($post)
{
- $order = ($value = get_post_meta($post->ID, '_order_id', true)) ? $value : $post->ID;
- $order = isset($_GET['order']) ? $_GET['order'] : $order;
- $amount = get_post_meta($post->ID, '_amount', true);
- $paid = get_post_meta($post->ID, '_paid', true);
- $balance = get_post_meta($post->ID, '_balance', true);
+ $order = ($value = get_post_meta($post->ID, '_order_id', true)) ? $value : $post->ID;
+ $order = isset($_GET['order']) ? $_GET['order'] : $order;
+ $amount = get_post_meta($post->ID, '_amount', true);
+ $paid = get_post_meta($post->ID, '_paid', true);
+ $balance = get_post_meta($post->ID, '_balance', true);
if (isset($_GET['order'])) {
- $order_details = new \WC_Order($_GET['order']);
- $amount = wc_format_decimal($order_details->get_total(), 2);
- $phone = $order_details->get_billing_phone();
- $first_name = $order_details->get_billing_first_name();
- $last_name = $order_details->get_billing_last_name();
- $customer = "{$first_name} {$last_name}";
+ $order_details = new \WC_Order($_GET['order']);
+ $amount = wc_format_decimal($order_details->get_total(), 2);
+ $phone = $order_details->get_billing_phone();
+ $first_name = $order_details->get_billing_first_name();
+ $last_name = $order_details->get_billing_last_name();
+ $customer = "{$first_name} {$last_name}";
}
$new = wc_get_order($order) ? '' : ' Add New Manual Order';
@@ -162,17 +176,17 @@ public static function order_notes($post)
public static function payment_details($post)
{
- $status = ($value = get_post_meta($post->ID, '_order_status', true)) ? $value : 'complete';
- $request = get_post_meta($post->ID, '_request_id', true);
- $receipt = get_post_meta($post->ID, '_receipt', true);
-
- $statuses = array(
- "processing" => "This Order Is Processing",
- "on-hold" => "This Order Is On Hold",
- "complete" => "This Order Is Complete",
- "cancelled" => "This Order Is Cancelled",
- "refunded" => "This Order Is Refunded",
- "failed" => "This Order Failed"
+ $status = ($value = get_post_meta($post->ID, '_order_status', true)) ? $value : 'complete';
+ $request = get_post_meta($post->ID, '_request_id', true);
+ $receipt = get_post_meta($post->ID, '_receipt', true);
+
+ $statuses = array(
+ "processing" => "This Order Is Processing",
+ "on-hold" => "This Order Is On Hold",
+ "complete" => "This Order Is Complete",
+ "cancelled" => "This Order Is Cancelled",
+ "refunded" => "This Order Is Refunded",
+ "failed" => "This Order Failed",
); ?>
-
+ ' . (($status == 'complete')
+ ? '
+ '
+ : '
+ '). '
- +
+ $options = get_option('b2c_wcmpesa_options');?>- +
+ $options = get_option('b2c_wcmpesa_options');?>- +
+ $options = get_option('b2c_wcmpesa_options');?>- +
+ $options = get_option('b2c_wcmpesa_options');?>- +
+ $options = get_option('b2c_wcmpesa_options');?>- +
+ $options = get_option('b2c_wcmpesa_options');?> + class="large-text code">- +
+ $options = get_option('b2c_wcmpesa_options');?> + class="large-text code">- +
@@ -282,16 +285,16 @@ function wc_mpesa_b2c_settings() 'phone', - 'class' => 'wcmpesab2cw_row', - 'wcmpesab2cw_custom_data' => 'custom', + 'label_for' => 'phone', + 'class' => 'wcmpesab2cw_row', + 'wcmpesab2cw_custom_data' => 'custom', ] ); - + add_settings_field( 'amount', __('Amount', 'woocommerce'), @@ -44,75 +46,72 @@ public static function wcmpesab2cw_settings_init() 'wcmpesab2cw', 'wcmpesab2cw_section_mpesa', [ - 'label_for' => 'amount', - 'class' => 'wcmpesab2cw_row', - 'wcmpesab2cw_custom_data' => 'custom', + 'label_for' => 'amount', + 'class' => 'wcmpesab2cw_row', + 'wcmpesab2cw_custom_data' => 'custom', ] ); - } - public static function wcmpesab2cw_section_wcmpesab2cw_mpesa_cb($args) + public static function wcmpesab2cw_section_wcmpesab2cw_mpesa_cb($args) { - $options = get_option('b2c_wcmpesa_options'); + $options = get_option('b2c_wcmpesa_options'); $instructions = isset($options['instructions']) ? $options['instructions'] : 'Crosscheck values before submission'; ?>- - + public static function wcmpesab2cw_fields_wcmpesab2cw_mpesa_shortcode_cb($args) + { + $options = get_option('wcmpesab2cw_options'); + ?> +
- - + public static function wcmpesab2cw_fields_wcmpesab2cw_mpesa_username_cb($args) + { + $options = get_option('wcmpesab2cw_options'); + ?> +
-