<?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 Conrad Suuna on Medium]]></title>
        <description><![CDATA[Stories by Conrad Suuna on Medium]]></description>
        <link>https://medium.com/@conradsuuna.cs?source=rss-d6cb192153a7------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/2*A4Z3_PQwx5Fns08VMBbJXA.jpeg</url>
            <title>Stories by Conrad Suuna on Medium</title>
            <link>https://medium.com/@conradsuuna.cs?source=rss-d6cb192153a7------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 14:18:32 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@conradsuuna.cs/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[MOMO API integration with python(3).]]></title>
            <link>https://medium.com/@conradsuuna.cs/momo-api-integration-with-python-3-14038851f224?source=rss-d6cb192153a7------2</link>
            <guid isPermaLink="false">https://medium.com/p/14038851f224</guid>
            <category><![CDATA[momo]]></category>
            <category><![CDATA[python3]]></category>
            <category><![CDATA[api-integration]]></category>
            <category><![CDATA[mobile-money]]></category>
            <category><![CDATA[mtn-uganda]]></category>
            <dc:creator><![CDATA[Conrad Suuna]]></dc:creator>
            <pubDate>Fri, 19 Jun 2020 16:18:52 GMT</pubDate>
            <atom:updated>2020-06-19T16:18:52.437Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zFMGzDEdLaGJHTE3JyM0MA.png" /></figure><p>A couple of years ago from date, MTN released an open API to it’s Mobile Money. Many of the organisations that were sick and tired of using third party aggregators were jubilant to such news because they were going to save a lump sum that was going to the aggregators.</p><p>The API offers integration capabilities with a multitude of programming languages but for the purposes of this article, I will be focusing on python3 and I will focus on integrating collections.</p><p>One can use the <a href="https://momodeveloper.mtn.com/">developer portal</a> to test the API and should follow the steps below;</p><ol><li>Sign up for an account</li><li>Get a product subscription key</li><li>Create an API user (UUID4)</li><li>Create an API key</li><li>Generate a JWT token</li><li>Make authenticated API requests</li></ol><h4>Sign up for an account.</h4><p>The first step is to register for an account <a href="https://momodeveloper.mtn.com/signup">here</a>.</p><h4>Get a product subscription key.</h4><p>Before you get the subscription key, you need to subscribe to a product, for our case, Collections. Go to Productions, Select collections and click subscribe. Then go to your <a href="https://momodeveloper.mtn.com/developer">profile</a> and select any key (either primary or secondary) as your subscription key.</p><h4>Create an API user.</h4><p>Next step is to create an API user, this is supposed to be a UUID4 series of character.</p><pre>import uuid<br>reference_id = str(uuid.uuid4())</pre><p>The generated UUID has to be registered <a href="https://momodeveloper.mtn.com/docs/services/sandbox-provisioning-api/operations/post-v1_0-apiuser/console">here</a> to become an API user. You don’t necessarily need to write a function for this in your code, you can use the developer portal.</p><h4>Create an API key.</h4><p>Use the reference ID (reference_id) generated above when creating your API user to generate the API key. You shall need to make a POST request to /v1_0/apiuser/&lt;put-your-reference-id-here&gt;/apikey to generate your API key. Still, you don’t necessarily have to write code for this. You can just use the developer portal.</p><p>The response will be a JSON object with an API key.</p><pre>201<br>Created<br>{&quot;apiKey&quot;:&quot;&lt;api key string here&gt;&quot;}</pre><h4>Generate a JWT token.</h4><p>For this, you need the apiKey, subscription_key from step 2 and the reference_id already generated. These may never change for as long as the API is in production and thus need to be kept secret i.e. in a .env file.</p><p>With those in place, it’s time to write our function to generate the authentication key.</p><pre>def get_auth_token():</pre><pre>data=momo_user_uuid+&quot;:&quot;+momo_user_api_key</pre><pre>data_b64 = base64.b64encode(data.encode()).decode()</pre><pre>headers = {</pre><pre># Request headers<br>#mind the space between Basic and the preceeding quotation.</pre><pre>&#39;Authorization&#39;: &quot;Basic &quot;+data_b64,</pre><pre>&#39;Ocp-Apim-Subscription-Key&#39;:subscription_key,</pre><pre>&#39;Content-Type&#39;: &#39;application/json&#39;,</pre><pre>}</pre><pre>params = urllib.parse.urlencode({</pre><pre>})</pre><pre>conn = http.client.HTTPSConnection(momo_dev_url)</pre><pre>try:</pre><pre>conn.request(&quot;POST&quot;, &quot;/collection/token/?%s&quot; % params, &quot;{}&quot;, headers)</pre><pre>response = conn.getresponse()</pre><pre>data = response.read()</pre><pre>return data</pre><pre>except:</pre><pre>return None</pre><pre>finally:</pre><pre>conn.close()</pre><blockquote>Forgive me for unindented code. There are many frustrating issues with medium and I didn’t have the time to hustle with it. So take my code as is. Article below explains how to deal with this kind of frustration to <strong>some</strong> degree.</blockquote><blockquote><a href="https://medium.com/@egonelbre/dealing-with-code-on-medium-c40016e8b1f3">https://medium.com/@egonelbre/dealing-with-code-on-medium-c40016e8b1f3</a></blockquote><pre>import http.client, urllib.request, urllib.parse, urllib.error, base64</pre><p>Import the above modules before your implementation.</p><p>The response will contain your secure token that can be used to interact with other parts of the API. It will look something like this</p><pre>200<br>OK<br>{&quot;access_token&quot;:&quot;eyJ0eXAiOiJKV1QiLCJhbGciOiJSMjU2In0.eyJjbGllbnRJZCI6IjQ2MmU1MzNmLTZkYjYtNDk4Ci04OTljLTBhNmRkY2E2ZDE5NSIsImV4cGlyZXMiOiIyMDE4LTExLTE2VDEzOjA1OjByLjExNyIsInNlc3Npb25JZCI6IjAxZGZlZDdlLTI5OGUtNDA5YS05NmI0LWJmODA0OWVkMzA5NCJ9.CureJ3-LnPCUpUAlB9oknqukQalqO1milbh4kBT3L6QTC7EJLApB46sEFszQ53hazvz_HvPIbAO20SxMQtrHN-VVGl8tZN92cAzO-nNdqts8s0LCdGY_Cjjk81ZL3v2cqv9bPxrzB8dp1i-YE6UePRSEqzROmzaywqazEntVYvQ66--uraaV1kdVp-1Gjo658ATu1uJtkWx6tvDD0j227a24gu5_3OoluAErcni3ziKtbKtk5Evu-WAPjcr6FyZrvfmMbkCYvN8NCem2VUe8RV5zL5K-1EKrSsHhsinsYZrS3kTblxPz8Z5t9OHgwH2HRZO_ITCYeiyVFwYMVFJktg&quot;,&quot;token_type&quot;:&quot;access_token&quot;,&quot;expires_in&quot;:3600}</pre><h3><strong>Make authenticated API requests.</strong></h3><p>This is your last and final step in the integration, or not. After generating the authentication key, you can now peacefully request other API endpoints as MTN shall know from whom the requests are coming.</p><h4>Making a request to pay.</h4><p>This is the process of generating a USSD prompt to enable a user or client to make payments to you say for using your service, et cetera.</p><pre>def make_request_to_pay(request):</pre><pre>#this can be any number so I chose to use random numbers<br>externalId=str(random())[2:]</pre><pre>#this is a unique reference id required when making a request to pay. it&#39;s unique for every request.</pre><pre>X_Reference_Id=str(uuid.uuid4())</pre><pre>#this is the token generated from our previous step</pre><pre>token_instance = get_auth_token()</pre><pre>token = json.loads(token_instance.decode())[&#39;access_token&#39;]</pre><pre>print(token)</pre><pre>#this is the phone number of the user making the request. he supplies it say through a form</pre><pre>party_id = request.POST.get(&#39;party_id_value&#39;)</pre><pre>#amount payable for the product/service</pre><pre>amount = request.POST.get(&#39;amount&#39;)</pre><pre>headers = {</pre><pre># Request headers</pre><pre>&#39;Authorization&#39;: &#39;Bearer &#39;+token,</pre><pre>&#39;X-Reference-Id&#39;: X_Reference_Id,</pre><pre>#&quot;sandbox&quot; for testing, &quot;mtnuganda&quot; for production</pre><pre>&#39;X-Target-Environment&#39;: &quot;sandbox&quot;,</pre><pre>&#39;Content-Type&#39;: &#39;application/json&#39;,</pre><pre>&#39;Ocp-Apim-Subscription-Key&#39;: Ocp_Apim_Subscription_Key,</pre><pre>}</pre><pre>params = urllib.parse.urlencode({</pre><pre>})</pre><pre>body = json.dumps({</pre><pre>&quot;amount&quot;: amount,</pre><pre>#use EUR when working in sandbox</pre><pre>&quot;currency&quot;: &quot;UGX&quot;,</pre><pre>&quot;externalId&quot;: externalId,</pre><pre>&quot;payer&quot;: {</pre><pre>&quot;partyIdType&quot;: &quot;MSISDN&quot;,</pre><pre>&quot;partyId&quot;: party_id</pre><pre>},</pre><pre>&quot;payerMessage&quot;: &quot;You have made payment to me, thank you.&quot;,</pre><pre>&quot;payeeNote&quot;: &quot;Payment received thank you.&quot;</pre><pre>})</pre><pre>conn = http.client.HTTPSConnection(momo_dev_url)</pre><pre>try:</pre><pre>conn.request(&quot;POST&quot;, &quot;/collection/v1_0/requesttopay?%s&quot; % params, body, headers)</pre><pre>response = conn.getresponse()</pre><pre># data = response.read()</pre><pre>print(response.status)</pre><pre># print(response.reason)</pre><pre># print(data)</pre><pre>except:</pre><pre>print(&quot;something went wrong&quot;)</pre><pre>finally:</pre><pre>conn.close()</pre><pre>print( &quot;transaction in process&quot;)</pre><pre>return</pre><blockquote>Edit/customise the code in accordance with your needs.</blockquote><p>import these modules before the above function;</p><pre>from random import random</pre><pre>import json</pre><pre>import uuid</pre><h4>Conclusion.</h4><p>The next endpoints e.g /collection/v1_0/accountholder/msisdn/ will be easy to implement after understanding the above.</p><p>One might incur certain difference between the sandbox and the live version( some bits of code work well in the sandbox but crush in production) for example;</p><p>In addition to that, an organisation called sparkplug developed a PyPI module that you can use. I personally haven’t tested it but I will adamantly believe that it works as desired.</p><p><strong>Note:</strong> When testing, one should know the account balance on their MOMO as the insufficient balance will cause the USSD popup not to pop. In addition, requests with money below 500UGX will also not allow the popup to pop.</p><h4>References.</h4><p><a href="https://momodeveloper.mtn.com/api-documentation">https://momodeveloper.mtn.com/api-documentation</a></p><p><a href="https://pypi.org/project/mtnmomo/">mtnmomo</a></p><p><a href="https://medium.com/@malendefahad/getting-started-mtn-mobile-money-api-with-python-7486148d650e">https://medium.com/@malendefahad/getting-started-mtn-mobile-money-api-with-python-7486148d650e</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=14038851f224" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Calculating the distance between two geocoordinate points with python.]]></title>
            <link>https://medium.com/@conradsuuna.cs/calculating-the-distance-between-two-geocoordinate-points-with-python-7eda1dc14889?source=rss-d6cb192153a7------2</link>
            <guid isPermaLink="false">https://medium.com/p/7eda1dc14889</guid>
            <category><![CDATA[haversine]]></category>
            <category><![CDATA[haversinedistance]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[geocoding]]></category>
            <category><![CDATA[python3]]></category>
            <dc:creator><![CDATA[Conrad Suuna]]></dc:creator>
            <pubDate>Fri, 19 Jun 2020 11:30:51 GMT</pubDate>
            <atom:updated>2020-06-19T11:30:51.375Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*X-G__yCUsEMQ68_YPr310w.jpeg" /></figure><p>Many mobile applications use this kind of technology for various reasons for example Tinder (for finding the distance between suiters). In my country, we have an Uber version called SafeBoda that uses the same technology to triangulate and pair different rider-passenger pairs for a means of quick transport and this is all achieved by knowing the distance between both parties.</p><p>Enough with the chit-chat. I got encountered with the task of developing an algorithm for doing the task at hand (calculating the distance between two geocoordinate points). The obvious steps to follow are;</p><ol><li>Generate the coordinates:- Here, you can use the Google Maps API to generate the respective coordinate points</li><li>Calculate the distance (Reason for this writing).</li></ol><h4>Tool Used.</h4><p>For this purpose, I used the <a href="https://en.wikipedia.org/wiki/Haversine_formula#:~:text=The%20haversine%20formula%20determines%20the,and%20angles%20of%20spherical%20triangles.">Haversine distance</a> formula and lucky enough, there’s a package in python that can help you avoid the headache.</p><p><a href="https://pypi.org/project/haversine/">haversine</a></p><h4>Conclusion.</h4><p>Much of Haverines’ simplicity comes from the underlying assumption that Earth is a perfect sphere (which it isn’t…). Because of this, it can lead to errors of up to 0.5%. More accurate methods exist but at the expense of computational complexity. [1]</p><p>There are other tools that can be used to calculate the distance. Read about them in the following;</p><ol><li>Lambert’s formula</li><li><a href="https://en.wikipedia.org/wiki/Great-circle_distance">Great-circle distance</a></li><li><a href="https://nathanrooy.github.io/posts/2016-12-18/vincenty-formula-with-python/">Vicenty’s formulae</a></li></ol><h4>References.</h4><p>[1] <a href="https://nathanrooy.github.io/posts/2016-09-07/haversine-with-python/">https://nathanrooy.github.io/posts/2016-09-07/haversine-with-python/</a></p><p>[2] <a href="https://janakiev.com/blog/gps-points-distance-python/">https://janakiev.com/blog/gps-points-distance-python/</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7eda1dc14889" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[QUICK COMPOSER INSTALL ON MAC.]]></title>
            <link>https://medium.com/@conradsuuna.cs/quick-composer-install-on-mac-cb2994011cdc?source=rss-d6cb192153a7------2</link>
            <guid isPermaLink="false">https://medium.com/p/cb2994011cdc</guid>
            <category><![CDATA[laravel]]></category>
            <category><![CDATA[composer]]></category>
            <dc:creator><![CDATA[Conrad Suuna]]></dc:creator>
            <pubDate>Mon, 09 Sep 2019 08:52:54 GMT</pubDate>
            <atom:updated>2024-05-17T08:07:32.310Z</atom:updated>
            <content:encoded><![CDATA[<p>Hello everyone, I recently moved from a Windows machine to a mac and needed to work with my Laravel projects again. To install Laravel, I needed to first install Composer, which is the purpose of this write-up.</p><p>Install PHP first if the Mac doesn’t already have PHP. To install PHP, you can choose to use homebrew.</p><pre>brew install php@&lt;version-number&gt;</pre><p>After successfully installing PHP, you have to link it and then finally test the installation.</p><pre>brew link php@&lt;version-number&gt;<br><br>php -v</pre><h3>Composer Install</h3><p>Download Composer using curl, which will create a Phar (PHP Archive) file called composer.phar in your current working directory. From your terminal, run the following command:</p><pre>curl -sS <a href="https://getcomposer.org/installer">https://getcomposer.org/installer</a> | php</pre><p>For need to access composer globally, one needs to run the following command:</p><pre>sudo mv composer.phar /usr/local/bin/</pre><p>To access composer globally by just typing “composer”, one needs to create a composer alias by running the following command:</p><pre>alias composer=&quot;php /usr/local/bin/composer.phar&quot;</pre><p>So by simply running the command “composer”, one has to see something like this;</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*N2_-nOqyKBom3d8pibTT0g.png" /></figure><p>DISCLAIMER: No errors were observed when running all the above commands.</p><p>Thank You for the read and your time, claps are awesome, and comments are welcome.</p><blockquote><strong>Note:</strong> I landed in a small bump where after updating my mac OS I would no longer have access to the composer, this stack overflow answer helped me out; <a href="https://stackoverflow.com/a/25022888/9532902">https://stackoverflow.com/a/25022888/9532902</a></blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cb2994011cdc" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[MySQL database connection(IBM Watson Studio).]]></title>
            <link>https://medium.com/@conradsuuna.cs/mysql-database-connection-ibm-watson-studio-719f64a114e6?source=rss-d6cb192153a7------2</link>
            <guid isPermaLink="false">https://medium.com/p/719f64a114e6</guid>
            <category><![CDATA[ibm-watson-studio]]></category>
            <category><![CDATA[mysql]]></category>
            <dc:creator><![CDATA[Conrad Suuna]]></dc:creator>
            <pubDate>Thu, 29 Aug 2019 07:31:20 GMT</pubDate>
            <atom:updated>2019-08-29T07:31:20.170Z</atom:updated>
            <content:encoded><![CDATA[<p>Hello everyone here, I have recently been drifting into use of IBM cloud services due to my enthusiasm with AI and machine learning. I started off by creating simple machine learning models in IBM studio and also creating simple chatbots and I can only promise you how much your work load can be highly reduced by these graphical tools provided by IBM Watson.</p><p>So a few days ago I started working on a credit scoring machine learning model for a company project am working on and i faced a bizarre issue while trying to connect my IBM Watson studio project to a MySQL database hosted on a linux server (cpanel). While trying to create the connection, I got about three kinds of errors, “failed to authenticate”, “invalid credentials provided”, “connection timeout”.</p><p>CONNECTION TIMEOUT, I mainly faced this problem when trying to test if the port i was using was the problem that led to the error, “invalid credentials..”. This is because i tried to change the port number from 3306 to a different 4 digit number which wasn’t a TCP port number. So the server would load until a request timeout error would occur.</p><p>INVALID CREDENTIALS AND FAILED AUTHENTICATION.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*acxHPCZhDF2O0vvZG5dGQg.png" /></figure><p>The above image depicts the one of the errors faced. This may seem an obvious case to some but with all the resources available, there was absolutely no help.</p><p>SOLUTION, enabling host access for remote database access on the database server. I first tried using the client’s Ip address, then I tried using the client’s hostname as the host but weirdly both of these didn’t do the trick and I haven’t realised as why this didn’t work. For any ideas of how to go about this, all help is welcome. So what I did was using a wildcard(%) as the host. The problem with this fix is that it opens up your database to any client that has access to the database username and the password, meaning that these now have to kept so secret until I find a fix to this temporary solution.</p><p>IBM Connection details; So just to make some things clear that might confuse a few people, by ‘User name’, IBM is asking for the username of the database not the username of the server. “password” is the password of the database as well. These two are sometimes normally confused with server credentials.</p><p>CONCLUSION, all corpus written herein are personal opinions that i think would help someone out there. A few claps are highly welcome.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=719f64a114e6" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>