 Welcome back to the channel. In the last video that we did in our payment gateway series, we were able to get our payment number and throw it inside admin area and also in the other items that we do get and that is basically just getting the number and adding it inside our admin area at the backend inside the orders. So today I'm going to jump into the meat and think of things. Now I need you to be very alert as we see this. What I'm going to share with you can be applied to different number of APIs. I have experimented with so many APIs and I have shared a number of videos with you on this very channel. The videos are linked in the description. You can see how to interact with different APIs. And I'll make another video that's just talking about how to convert particular information. Maybe you need it in a SOAP or an XML kind of API. But I'll share another video with that today. I just want to work with an API. It's basically going to receive information that's straight out from an object or information that can be sent as a JSON. So let's watch this in depth and just dig into the meat of things. So with me, I have this API that I found out that does mobile payments. However, you need to sign up, get different credentials and then you'll make what we call a widget and you will also get an API key. Now the API key and the widget key allow for your application to be authenticated. And the other information that this mobile gateway needs is that it needs your phone that's going to be charged because that's the default payment method. It needs the mobile money company ID. It also needs the reason and it needs the amount. The rest of the other things are just an option if you look at the documentation carefully. So the biggest issue that I've seen with APIs is the documentation. If the documentation is bad, then you will not be able to get all the information that you do need. So when you start from bottom to top, we realize we just need a couple of things from this particular API. Now, before I jump into plugging this into my payment API, I am going to do just a demo and dummy API querying of that endpoint to see whether my information is going. Then I'll get that information that is static and then make it dynamic all through. So this is what I've done in this particular plugin that I have opened up. Now, there's another video also that I've linked in the description below where I'm querying an API. So basically, I will be opening a custom page menu and that will look something like this. So let me activate this API plugin. So when I have to get this plugin, you'll see that I have something here that says API test. Now, behind this code, I've just opened an admin page and I've called it API test settings. You'll see API test right here in the admin menu. And you'll also see that it runs to its own page ID. It runs this function, this callback function that you'll see here that I'm going to explain. And I just add a dash icon and give it an 85 position so that it's at the bottom. So this little icon that you see here, the message icon is what's coming from the dash icon. You'll be able to see more of that in the particular video that I've linked. Now, in this plugin, remember when we're looking at the API here, we filtered out a number of things that are essential to getting this API to work. First of all, we need to post to this URL here. Then we pass in our API key, then we pass in our widget key. So that's what I've done. I've got this URL, I've planted it here, and I have chained on our API key, which is in PHP. Then I add on a slash by escaping the PHP and coming back. Then we add on the widget key. Now, if you look again at this API, you will see that there is a question mark which allows us to start adding different parameters. So there's an email which is optional. Then you have the amount which is amount. If you see here, it is required. We have the phone, which is also required, and it's required to be in this format. And it's 13 digits. Then we have the mobile company ID, which either has to be a one or two, one for MTN and two for Airtel Uganda. And then we also need to pass a reason that is stored at the back end for this payment. Now, we're just going to have some dummy data that we're going to put in and see whether this actually works out for us. So my API key is this. Don't worry, I've changed it so this won't work for you right now. But please get your API and see the needs that it requires and then just pocket it through that. I've put my API key. I've put my widget key here. I've put a phone number that's starting characters. This is the amount I'm going to be charging. I'm assuming this is coming straight off my WooCommerce. Then we have our network ID, which I will go for one because any number that starts with 7, 8, 2 is from MTN. So we shall see how we can filter that and make that a function that will allow us to always detect what network it is and automatically send it in the right network ID. Then I've just put a reason which is test. And so I'm chaining all of this through this URL. So I've put the API key. I've put the widget key. I've put the phone. I've put the amount with the mobile ID and I've put the reason. So all these things that usually change, I've put them in variables and then just change them to the URL. The next thing I use a WP remote post, which is a default WordPress function. I pass in our URL. Then I pass in one extra thing, which is the timeout that I need to have. Most times, API is slow in terms of when you send the data. And by default, this is usually five seconds. However, you'll find that an API sometimes requires 15 or 20 seconds or whatever it is. So I've thrown a timeout that is really huge to see what's going to happen. Then eventually when we get our response from this URL call, if it's an error, we throw it in an error and then we throw it at the backend. However, if it works out, then we get our response and then we shall dump it at our backend. So this is what this code is doing. It's just helping us demo that information. So let's go and check what it does. So our query API's plugin is activated here. Then all I need to do is to hit this particular admin menu item. Clicking it on our phone will get a message to pay. And we'll also receive an SMS message that is showing us that we need to make that payment. And if we make that payment, then that message will be stored and we'll be able to see what actually happens at the end of the day. So our API is working. All the variables that we need are actually showing off. So then we are ready to have this particular part of our API integrated inside our WooCommerce, our payment gateway.