Or, embed this snippet using GenerateWP WordPress Plugin.

Download

Clone

MM payment

for making online payments

<?php
/**
 * Plugin Name: Mobile Money Payments
 * Plugin URI: https://yourwebsite.com/
 * Description: A plugin to enable mobile money payments via Airtel, MTN, and Zamtel.
 * Version: 1.0
 * Author: Adrian Fumpa (Naird Logistics & Supplies)
 * Author URI: https://naird.tech/
 * License: GPL2
 */

// Exit if accessed directly.
if (!defined('ABSPATH')) {
    exit;
}

// Include necessary files.
require_once plugin_dir_path(__FILE__) . 'includes/class-mobile-money-gateway.php';

// Initialize the plugin.
function mmp_init() {
    Mobile_Money_Gateway::init();
}
add_action('plugins_loaded', 'mmp_init');
<?php

class Mobile_Money_Gateway {

    public static function init() {
        add_action('woocommerce_payment_gateways', [__CLASS__, 'add_gateway']);
    }

    public static function add_gateway($gateways) {
        $gateways[] = 'WC_Mobile_Money_Gateway';
        return $gateways;
    }
}

class WC_Mobile_Money_Gateway extends WC_Payment_Gateway {

    public function __construct() {
        $this->id = 'mobile_money';
        $this->method_title = __('Mobile Money', 'woocommerce');
        $this->method_description = __('Accept payments via Mobile Money.', 'woocommerce');
        
        $this->init_form_fields();
        $this->init_settings();

        // Save settings.
        add_action('woocommerce_update_options_payment_gateways_' . $this->id, [$this, 'process_admin_options']);
    }

    public function init_form_fields() {
        $this->form_fields = [
            'enabled' => [
                'title'   => __('Enable/Disable', 'woocommerce'),
                'type'    => 'checkbox',
                'label'   => __('Enable Mobile Money Payments', 'woocommerce'),
                'default' => 'yes',
            ],
            'title' => [
                'title'       => __('Title', 'woocommerce'),
                'type'        => 'text',
                'description' => __('Payment method title seen during checkout.', 'woocommerce'),
                'default'     => __('Mobile Money', 'woocommerce'),
                'desc_tip'    => true,
            ],
            'api_key' => [
                'title'       => __('API Key', 'woocommerce'),
                'type'        => 'text',
                'description' => __('API key for mobile money gateway.', 'woocommerce'),
                'desc_tip'    => true,
            ],
        ];
    }

    public function process_payment($order_id) {
        $order = wc_get_order($order_id);

        // Add API logic to process mobile money payment.
        // For now, we mark as "on-hold" until verified.
        $order->update_status('on-hold', __('Awaiting mobile money payment', 'woocommerce'));

        // Reduce stock levels.
        wc_reduce_stock_levels($order_id);

        // Return thank you page redirect.
        return [
            'result'   => 'success',
            'redirect' => $this->get_return_url($order),
        ];
    }
}
/* Add custom styles here. */
// Add custom JavaScript logic here.
function mmp_enqueue_assets() {
    wp_enqueue_style('mmp-styles', plugin_dir_url(__FILE__) . 'assets/css/style.css');
    wp_enqueue_script('mmp-scripts', plugin_dir_url(__FILE__) . 'assets/js/script.js', ['jquery'], '1.0', true);
}
add_action('wp_enqueue_scripts', 'mmp_enqueue_assets');