<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Haroldkerry on Medium]]></title>
        <description><![CDATA[Stories by Haroldkerry on Medium]]></description>
        <link>https://medium.com/@haroldkerry?source=rss-d22dd8271c19------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*ulFZds1XHA6gkReP</url>
            <title>Stories by Haroldkerry on Medium</title>
            <link>https://medium.com/@haroldkerry?source=rss-d22dd8271c19------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 19 Nov 2026 12:19:36 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@haroldkerry/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Integrating SMS Functionality in Your System: A PHP Guide with advanta_africa/sms_api]]></title>
            <link>https://medium.com/@haroldkerry/integrating-sms-functionality-in-your-system-a-php-guide-with-advanta-africa-sms-api-8778ed520e9a?source=rss-d22dd8271c19------2</link>
            <guid isPermaLink="false">https://medium.com/p/8778ed520e9a</guid>
            <category><![CDATA[sms-service]]></category>
            <category><![CDATA[php]]></category>
            <category><![CDATA[otp-sms]]></category>
            <category><![CDATA[sms-api]]></category>
            <category><![CDATA[bulk-sms]]></category>
            <dc:creator><![CDATA[Haroldkerry]]></dc:creator>
            <pubDate>Tue, 15 Oct 2024 12:33:31 GMT</pubDate>
            <atom:updated>2024-10-15T12:46:36.376Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="Messaging Icons" src="https://cdn-images-1.medium.com/max/1024/1*aBVgS4W5j9xGKr9aw2GEhg.png" /></figure><h4>Introduction</h4><p>As a developer you’ve definitely encountered situations where you need to automatically send messages from your system to end users. These messages may include OTPs, transaction alerts, downtime alerts or general communication. While there are several options used to send these messages one of the most widely used methods is SMS.</p><p>I recently built a ticketing system for <a href="https://igizaarts.co.ke/"><strong>Igiza Arts</strong></a>, where end users purchase tickets online and the e-ticket is sent via SMS. Given my experience in the bulk SMS industry I immediately knew how to go about integrating the functionality into the system.</p><p>SMS is still a core communication tool for reaching users quickly and integrating it into your system is often a key requirement. Before diving into the code, there are a few steps you need to follow:</p><blockquote>1: <strong>Identify a Bulk SMS provider</strong>: In my case, I used Advanta Africa. You can choose one based on factors like SMS API availability, price, delivery rates and technical support.<br>2: <strong>Set up an account with the provider</strong>: Contact your chosen provider to get your SMS account up and running.<br>3: <strong>Review the API documentation</strong>: Familiarize yourself with the endpoints, parameters and methods.<br>4: Start coding!</blockquote><h4>Prerequisites</h4><p>Before you begin, make sure you have the following details from Advanta Africa after setting up your account:</p><blockquote>1: <strong>API Endpoints</strong>: URLs for the various SMS services.However, in my package, go through the readme file to get these<br>2: <strong>Partner ID:</strong> A unique identifier for your account.<br>3: <strong>Sender ID (Shortcode)</strong>: The alphanumeric Id that appears as the message sender.<br>4: <strong>API Key</strong>: A secret key for authentication.</blockquote><p><strong><em>Security Tip</em></strong><em>: Don’t be like me. Avoid hardcoding sensitive credentials like API keys in your files. Instead, use environment variables to keep them secure. Advanta Africa also provides IP whitelisting, allowing you to restrict access to the SMS API based on trusted IP addresses.</em></p><h3>Project Setup and package installation</h3><ol><li>Create your project directory: mkdir sms-integration-project</li><li>Navigate into the directory: cd sms-integration-project</li><li>Create your base php file: sudo touch index.php</li><li>Install the package : composer require advanta_africa/sms_api</li><li>Time to start coding!</li></ol><p>In your index.php file,</p><pre>&lt;?php<br><br>require &quot;vendor/autoload.php&quot;; // // Load the vendor autoload file<br><br>//import the classes<br><br>use AdvantaAfrica\SmsApi\GetBalance;<br>use AdvantaAfrica\SmsApi\GetDeliveryReport;<br>use AdvantaAfrica\SmsApi\SendSms;<br><br>// Initialize API credentials (replace with env variables for security)<br><br>$partnerId = &#39;xxxxxxx&#39;;<br>$senderId = &#39;xxxxxxx&#39;;<br>$apiKey = &#39;xxxxxxx&#39;;</pre><h4>Sending SMS with advanta_africa/sms_api</h4><p>Now let’s go through how to send different types of SMS using the package</p><p>1.<strong>Sending Single SMS</strong></p><p>You can send SMS to single or multiple recipients</p><pre>$sendSmsUrl = ‘xxxxxxxxxxxx’; <br><br>$mobile = ‘2547xxxxxxxxxx’; //For multiple mobile numbers use a comma separated string<br><br>$message = ‘Hello World’;<br><br>// Create an instance of the SendSms class<br><br>$sendSms = new SendSms($sendSmsUrl,$apiKey,$partnerId,$senderId);<br><br><br>// Send via GET<br>$sendSingleResponse = $sendSms-&gt;sendSingleSmsGet($mobile,$message,null);<br><br>// Send via POST<br>$sendSingleResponse = $sendSms-&gt;sendSingleSmsPost($mobile,$message,null);<br><br>// If you want to schedule a message, replace null with a Unix timestamp.</pre><p><strong>2.Sending OTP SMS</strong></p><p>The sendOtp method can handle both normal and Safaricom hashed numbers</p><pre>$sendOtpUrl = &#39;xxxxxxxxxxxx&#39;; <br><br>$mobile = &#39;xxxxxxxxxxxx&#39;; //For multiple mobile numbers use a comma separated string<br><br>$message = &#39;Your OTP code is 1637388&#39;;<br><br>$hashed = true; // Set to true for hashed numbers<br><br>$sendSms = new SendSms($sendOtpUrl,$apiKey,$partnerId,$senderId);<br><br>// Send via GET<br>$sendOtpResponse = $sendSms-&gt;sendSingleSmsGet($mobile,$message,null,$hashed);<br><br>// Send via POST<br>$sendOtpResponse = $sendSms-&gt;sendSingleSmsPost($mobile,$message,null,$hashed);</pre><p><strong>3. Sending bulk SMS</strong></p><p>For bulk messaging, pass an array of messages and recipients</p><pre>$sendBulkSmsUrl = &#39;xxxxxxxxxxxx&#39;; <br><br>$smsListArray =  [<br>    [&#39;mobile&#39; =&gt; &#39;2547xxxxxxxxx&#39;, &#39;message&#39; =&gt; &#39;Message 1&#39;],<br>    [&#39;mobile&#39; =&gt; &#39;2547xxxxxxxxx&#39;, &#39;message&#39; =&gt; &#39;Message 2&#39;],<br>    [&#39;mobile&#39; =&gt; &#39;2547xxxxxxxxx&#39;, &#39;message&#39; =&gt; &#39;Message 3&#39;]<br>];<br><br>$sendSms = new SendSms($sendBulkSmsUrl,$apiKey,$partnerId,$senderId);<br><br>//Send via POST<br><br>$sendBulkResponse = $sendSms-&gt;sendBulkSms($smsListArray);</pre><p><strong>4.Checking SMS Balance</strong></p><p>To check your SMS balance</p><pre>$getBalanceUrl = &#39;xxxxxxxxxxxx&#39;; <br><br>$balance = new GetBalance($getBalanceUrl,$apiKey,$partnerId);<br><br>//Fetch via GET<br>$getBalResponse = $balance-&gt;getBalanceGet();<br><br>//Fetch via POST<br>$getBalResponse = $balance-&gt;getBalancePost();</pre><p>5: Fetching Delivery Status<br>You can retrieve the delivery status of your sent messages</p><pre>$getDlrUrl = &#39;xxxxxxxxxxxx&#39;; <br><br>$messageId = &#39;xxxxxxxxxxxx&#39;; //This is returned in every send sms or send bulk request<br><br>$delivery = new GetDeliveryReport($getDlrUrl,$apiKey,$partnerId); <br><br>//Retrieve with GET<br>$deliveryResponse = $delivery-&gt;getDeliveryStatusGet($messageId);<br><br>//Retrieve with POST<br>$deliveryResponse = $delivery-&gt;getDeliveryStatusPost($messageId); </pre><p>While I’ve provided basic examples of how to send SMS, send OTPs and check balances, you should implement proper error handling. Capture the raw api responses I am returning in the package and handle the rest accordingly. Use try-catch blocks to manage exceptions.</p><p>By integrating Advanta Africa’s SMS API into your system, you can efficiently communicate with your users by sending automated SMS messages from your system.</p><p>If you find this package useful and would like to contribute and improve on it, feel free to check out the GitHub repository.</p><p><em>GitHub Repository: </em><a href="https://github.com/harrykerry/advanta_sms_api"><strong><em>https://github.com/harrykerry/advanta_sms_api</em></strong></a></p><p>Cheers fam!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8778ed520e9a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Integrating Safaricom’s M-PESA APIs with PHP (Laravel): A Simple Guide]]></title>
            <link>https://medium.com/@haroldkerry/integrating-safaricoms-m-pesa-with-php-laravel-a-simple-guide-3f5b68816d12?source=rss-d22dd8271c19------2</link>
            <guid isPermaLink="false">https://medium.com/p/3f5b68816d12</guid>
            <category><![CDATA[mobile-payments]]></category>
            <category><![CDATA[laravel]]></category>
            <category><![CDATA[safaricom]]></category>
            <category><![CDATA[php]]></category>
            <category><![CDATA[mpesa]]></category>
            <dc:creator><![CDATA[Haroldkerry]]></dc:creator>
            <pubDate>Fri, 23 Aug 2024 14:20:20 GMT</pubDate>
            <atom:updated>2024-08-27T07:21:09.343Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/512/1*q6VZ_q0WIism6TgZ9kBIWQ.png" /></figure><p>In today’s digital economy, mobile payment solutions are crucial for businesses aiming to offer seamless transactions. One of the leading mobile payment solutions in Kenya is Safaricom’s M-PESA. In this article, I’ll walk you through how I developed a Laravel application to integrate with M-PESA’s C2B (Customer-to-Business) services and STK push for payments.</p><h3>Overview</h3><p>My Laravel application, which you can explore on GitHub (<a href="https://github.com/harrykerry/laravel-mpesa-integration">https://github.com/harrykerry/laravel-mpesa-integration</a>), facilitates the management of Safaricom M-PESA transactions. It includes features such as handling C2B callback data, processing STK push requests and registering C2B URLs with M-PESA. The application also provides API endpoints for external systems to interact with the features.</p><h3>Key Features</h3><ol><li><strong>MPESA Callback Handling</strong>: Receives and processes MPESA C2B callback data.</li><li><strong>C2B URL Registration</strong>: Allows clients to register their confirmation and validation URLs with MPESA.</li><li><strong>Data Storage</strong>: Stores callback data in a MySQL database.</li><li><strong>Data Fetching Endpoint</strong>: Exposes an API endpoint for retrieving stored callback data.</li><li><strong>MPESA STK Service</strong>: Interacts with MPESA’s STK push feature to initiate payments.</li></ol><h3>Core Project Structure</h3><p>Controllers manage incoming requests and responses:</p><ul><li>MpesaDataFetchController: Fetches stored M-PESA callback data.</li><li>MpesaCallbackController: Handles M-PESA callbacks and URL registration.</li><li>MpesaStkController: Handles requests related to STK push initiation and callbacks.</li></ul><p>Services encapsulate business logic:</p><ul><li>MpesaAuthService: Handles M-PESA access token generation.</li><li>MpesaCallBackService: Processes and saves M-PESA C2B callback data.</li><li>MpesaCallbackRegistrationService: Manages M-PESA C2B URL registration.</li><li>MpesaStkService: Handles STK push initiation and callback data.</li></ul><p>Routes define API endpoints:</p><ul><li>POST /payments/validation/callback: Endpoint for M-PESA validation callback. <br>Note Safaricom restricts the use of the word Mpesa in the c2b callback URLs</li><li>POST /payments/confirmation/callback: Endpoint for M-PESA confirmation callback.</li><li>POST /mpesa/callback/register: Endpoint for URL registration.</li><li>GET /mpesa/payments/c2b: Fetches stored C2B payments from the database.</li><li>POST /mpesa/stk/initiate: Endpoint to initiate STK requests .</li><li>POST /mpesa/stk/callback: Endpoint to handle STK callback data.</li><li>GET /mpesa/payments/stk: Fetches stored STK payments from the database.</li></ul><h3>Setup Instructions</h3><ol><li><strong>Clone the Repository</strong>:<br> git clone <a href="https://github.com/harrykerry/laravel-mpesa-integration.git">https://github.com/harrykerry/laravel-mpesa-integration.git</a></li><li><strong>Navigate to the Project Directory</strong>:<br> cd laravel-mpesa-integration</li><li><strong>Install Dependencies</strong>:<br> composer install</li><li><strong>Set Up Your Environment File</strong>:<br> cp .env.example .env</li><li><strong>Generate the Application Key</strong>:<br> php artisan key:generate</li><li><strong>Run the Migrations</strong>:<br> php artisan migrate</li></ol><h3>MPESA Requirements and Setup</h3><p>To integrate with MPESA, you’ll need the following:</p><ol><li><strong>Create a Daraja Portal Account</strong>:<br> Sign up here <a href="https://developer.safaricom.co.ke/">https://developer.safaricom.co.ke</a> to access the Daraja API</li><li><strong>Obtain Mpesa Credentials</strong>:<br>You’ll need an Mpesa Portal account with API rights. To create a production app you will need to go live using a business shortcode, organization name,username with the necessary rights. After creating an application in the portal, you will receive an email with a passkey. The other credentials including the consumer key and secret are accessible in the daraja portal under apps.</li></ol><h3>Configure Your Application</h3><p>The Laravel application is designed to streamline your integration with MPESA by automatically managing token generation. To use the application effectively, you’ll need to provide specific parameters when interacting with the API endpoints. Here’s a guide on what parameters are required:</p><p><strong>Register C2B Callbacks</strong> — To register your confirmation and validation URLs with MPESA, make a POST request to the <strong>/mpesa/callback/register</strong> endpoint with the following parameters:</p><pre>confirmation_url: The URL where MPESA will send confirmation callbacks. <br>validation_url: The URL where MPESA will send validation callbacks. <br>consumer_key: Your MPESA API consumer key. <br>consumer_secret: Your MPESA API consumer secret. <br>shortcode: Your MPESA business shortcode.</pre><p><strong>Initiate STK Push Requests — </strong>To initiate an STK push payment, make a POST request to the <strong>/mpesa/stk/initiate</strong> endpoint with the following parameters:</p><pre>consumer_key: Your MPESA API consumer key. <br>consumer_secret: Your MPESA API consumer secret. <br>shortcode: Your MPESA business shortcode. <br>passkey: The passkey provided by MPESA for STK transactions. <br>amount: The amount to be charged in the transaction. <br>msisdn: The phone number initiating the payment. <br>account_reference: A reference for the transaction. <br>stk_callback: The URL to receive STK push callback data. <br>organization_code: Your organization code (either &#39;till&#39; or &#39;paybill&#39;).<br>transaction_type: The transaction type (e.g., &#39;CustomerBuyGoodsOnline&#39; for till and &#39;CustomerPayBillOnline&#39; for paybill)</pre><p><strong>Fetch Stored Data — </strong>To retrieve stored C2B or STK payment data, use the GET request to the<strong> /mpesa/payments/c2b</strong> or /<strong>mpesa/payments/stk</strong> endpoints. Include the following query parameter:</p><pre>shortcode: The shortcode to filter the results by.</pre><p>By providing these parameters, you’ll be able to register your callback URLs, initiate STK push payments and fetch stored data with ease. The application handles the underlying complexity, allowing you to focus on integrating MPESA’s payment services into your solution.</p><p>If you’re looking to add M-PESA payment solutions to your application, this Laravel setup is designed to make the process as smooth as possible.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3f5b68816d12" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>