CamPay payment API for MOMO Intergration
Greeting Steemit Family
It has been a busy week for me with some projects. One of the projects that took most of my time during the week required integrating MOMo payment into a project.
After doing research on which will be the best option for my client. It is a Cameroon-based organization, so most of its audiences are based here. Those are some of the things to put into consideration when looking at an API to use on a project.
While I came across a couple of Payment APIs, CamPay seems more interesting to me. I don't know much about it, but I told my client to give it a try and see if we can use it.
CamPay is a payment API offers integration to facilitate mobile payment in Cameroon. With the CamPay payment API, developers can make payments through the website with their MTN and Orange Mobile Money. I look at what I have been trying to do with the API to see if I can have a small library to use on the client website.
I started by creating an account on the CamPay platform to be able to have access to the API keys. My directive was from the documentation, which I will send the link to below. It is important to follow the platform documentation to have a better understanding of the API.
For Testing purposes, I will be making use of the Demo site. The demo is used for development and testing without actually going live. Again, I noticed that with the demo, you can test with a maximum of 100 FCFA. That way, with less than 100 FCFA. You can work on the demo before thinking of going live.
When you finally create your account, You can go ahead to register your application to have the API keys that you will be using. Note, that you have access to the API keys, which means we have the authentication to the API. Most important is the token, which is generated after you have registered the application from your account. The are a list of tokens generated, which will be used for different operations.
The documentation has the code needed for me to request payment from the front end. When the request is executed, the endpoint triggers a pop-up on the user's phone requesting to confirm payment by inserting their PIN.
When this is done, I need a return status to tell that the transaction was complete. Note, you will need to download a composer to be able to make use HTTP_Request2()
In my project, I created four PHP files.
index.php
Here, I have the form to collect the necessary data: amount, phone number, and description.
The amount stands for the amount that will be withdrawn from your mobile money account.
The number will be the number to receive the endpoint popup to confirm the transaction with a PIN.
The description can be anything, but it is purposely for a description of what the transaction is for.
payment_send.php
Here, I will place the requested payment code from the documentation. I start by checking if the form was submitted and has all the input needed. To check the input, I have added another input external_reference
. This can be used as a unique identifier for every transaction executed. With this external_reference
, it will be easy to find the reference
and the transaction status.
waiting.php
I created a page to give the user some time to put in the MOMO pin. That way I will be able to get the updated status of the transaction, which will be directed to a response page.
On the waiting page, we get the Get Transaction status code. We can have this from the documentation. The difference here is that we are requesting a METHOD_GET. Make use of the reference
from the request payment.
I'm not good with JavaScript, but I needed it here to hold the page and reload it to get the updated status.
respond.php.
Here, I just got the reference
and the status and display. It is working well, and I will share the code on GitHub. It is best for the African market. Making use of the MTN and Orange Mobile Money service. I will drop Github repository, so no need sharing the code on the post.
CamPay payment API
Anyone with a Cameroon Mobile number can fetch and try.
That is the final check on my dashboard.
Cheers
Thanks for dropping by
@fombae
Upvoted! Thank you for supporting witness @jswit.
hi @fombae pls correct the tag #techclub-s23w43 to #techclub-s23w3