 Welcome back to the channel. In our last video, we had actually developed a payment gateway that when you click add on your WooCamas shop, go to view, go to process the checkout, you actually have our jobs payment gateway showing up here. So today I'm going to take that an extra step and get us to actually use a payment API to complete this process. So let's jump in. But first, I'm going to activate a small plugin to reduce all this number of fields for me. I don't like scrolling all the way down. So I've written a custom plugin to help me slim out that process. You can see the video of how this was done in the description below or in the link that has actually showed up on the screen above. And that will help you to reduce to have maybe these few lines of code so that it's a very short checkout for us. Now I'll go to WooCamas, go inside the includes, go inside the gateways, and we have these particular gateways already showing up here. So if I go into WooCamas and go to settings, and then I go to payments, you'll see that we have all these different payment gateways here, the bank payments, the check, cash on delivery, PayPal and our own payment showing up here. So what I usually do is just give the cash on delivery or any other check or PayPal or BSE, but the cash on delivery is really, really short. I'm going to copy the cash on delivery, come back to our plugins, I'm going to paste it here, then I'll rename it giving it our, our name here that we had, which is no payment for commerce. I'll just eventually get rid of this. And then what I'm going to do is drag and drop this inside our editor. So this is the file that we also need to rename. We can leave it the way it is, but we'll rename it for now so that we are able to see what's going on. I'm going to start shipping out a couple of things inside this plugin, but it will help me work better and a lot faster in comparison to trying to build my own files as we did with the new payment. So that's why I actually start off with an existing file. Now let's go and delete a couple of things, rename this other plugin's name, and then we'll go ahead to use this particular plugin. So first things first is we need to add, we need to add our plugin starter. So I'll use my short code here to help me get this. So we'll call this no payments gateway. And then it will have an author link and plugin link. I'll just use the same. I'll add my blog, blog here. Then we'll have the plugin name, author, or do take it first. And then the description will be our local payments gateway for mobile. The version will be 0.1. I'll give this a gpl2. You can choose whatever license you want. And then once that is done, of course, now WooCommerce or WordPress will recognize this as our plugin. However, with WooCommerce, I like to add the tested to Woo version and then and so on. So that when we go back to our WooCommerce and then go into the status, we are able to actually see that the plugins were able to see that when we have our plugin here, it should be able to show that it is actually working for that particular version of WooCommerce. Or we need to check whether there are some changes happening or it's the one affecting our WooCommerce operation. We always add the few settings in there to say it is tested for WooCommerce too, maybe whatever version you're using. The next thing that we're going to do is we can change this. We're going to call this a paleo for now. And then the class name, we're going to change everything that has WCVGateway.cod. We're going to call it, we're going to change the cod to paleo. So there are only three instances. I'll change this to paleo for now. And then I'll just have this as paleo-woo for our text domain. We don't need to use the constants that are coming from Jetpack. So I'll remove this. We need the security bit here. I'll just join up these two. This works fine. It's a gateway. It will be a version of 0.1. And then you'll see our paleo extends the gateway. So I went through all of this, what all of this is doing in the earlier video. But we'll see that now they have a couple of things they've thrown out into different functions. So we have the setup properties here. And the setup properties is actually just having the icon ID. So it's having the plugin ID. It's having the filter. It's talking about the title and the method. So these are things that we can change in contrast to the original plugin that we had done. Then we have the init form fields that shows you whether the plugin should be enabled. It's a checkbox. They give you a title, description, instructions. They allow you to enable it for shipping methods. So you can set for particular shipping methods. And then you can show whether it is also allowed for virtual product or not. So that's the beauty of again using what is already existing. You don't need to reinvent the wheel. And then we have the init settings. It's already part of the extension of the gateway class. And then we just add the extra settings like title, descriptions, instructions. These are already being got from what we have set down here in the init form fields function. And then we have them here. We have the other actions like updating the payment get ways by adding this in this function, process admin options. We have a thank you and we have a payment order status complete, which will change the payment order status whenever we use this particular payment option. And then we also have this added into the customers emails where we are adding this gateway. So we have the payment gateway method added into our email instructions. So that's the beauty of actually just starting with this particular extension. So you have everything given to you on a silver plate. So I'm going to save this. The only thing that we need to change is this ID because we can't also have it as a COD. So I'll try to change this in the different places that we do have. So we have it in the ID, the icon, request. So we're just going to change COD and we're going to call it a DO for now. Let me pick a few things from our old plugin, which is this. I'll add it to our workspace. I'm going to pick the assets and then I'm just going to drag them in there into our new point. And then I'm going to just get a few things like the icon, link of this. Come here and just change this here for this paleo so that we have our function working well. So then I'll just add this to make sure that I'm feeling the code standards. I'm applying the same thing. And then we have the title description here. This is all that I need to do for now. So let me just make the other edits inside here. Then we'll see whether our function is working. So we'll have cash on delivery, which we also need to change. And we'll call this a paleo mobile payments. And then we'll change also this we're not paying or delivery. So you can say use your mobile payments to clear the bill. So we have that working very well. Nothing to change here. So we'll come enable disable, which is okay, title, payment method description. So this is what will change a bit. So paleo payments method description, that is okay, instructions, pay with mobile cash balance. I'll save that. So let's go back from our field of view. And then I'll come back to our plugin reload. So we'll go to our plugins, let's activate our new payment. But I'm going to change this so that it's not disorganized. So I'll rename that and reload this so that we have it as paleo payments gateway. So when I activate this, I made an error here. So the other thing that will borrow is actually our if statements that show whenever we are excluding particular things. So I'll just run those here to check if we have wakeovers installed, if it's active, then we'll load this payment. And if the class exists of gateway, then we shall extend it so that we don't have any errors showing up like the one we've just had. So I'll make sure I've appended this well. Yeah, it's on the right line, then I'll close this off. So shouldn't have any problems. If we check in our terminal, we don't have any problems, meaning our page is well wrapped. I'll just change the names here. I don't like seeing the knob. It's a bit confusing. So I'll call this paleo and set this here. So all done. So let's go and see what happens after correcting that error. Yeah, we are good to go. And this should be ready. Let me reload this. We don't have this here because we've not activated it inside our settings in the payments section. So we'll get the payments. And then we don't have it here. It's not yet queued up. The other thing that we need to do now is we need to get our code which adds the filter here. So I'll just run this at the bottom and say we need to add the filter whenever we have the payments gateway. We are going to add to the paleo payment gateway and it is actually wwc gateway underscore paleo. I'll just cross check to confirm. Yeah, and that's what we have here with the capital P compared to what we have here in lowercase p. So I'll test this and save. When I save that and reload, we'll see that we have our paleo mobile payments showing up here again. So I'll activate it. Save changes. Come to manage. We'll see we have all of this setup. We're not excluding it from any shipping methods. We allow it for virtual products. And if I reload here, we'll see that we have a bit of errors in line 209 accessing setting. And this has to do with local shipping 209. We have an error and the error is constant is true for rest. So this is supposed to pass in things for rest if we use the jetpack plugin. However, we don't need to do that. So what I'm going to do is I'm going to take this out. We can always solve it some other way if we want to pass that payment gateway into the rest API or WooCommerce. But once we do that, everything is okay. We see our payments mobile is here. And if we place the order for now, we'll have an invalid currency code. Now, the reason why that is happening is we actually don't have a currency code here. And we need to check whether our particular plugin is actually using a particular currency. And I just have a few videos that explain how you add our currency. And they also linked here and also in the description, you can see them. But I'm going to quickly add our currency. And then I'm also going to quickly add to make sure that we always have that currency set up. So I'll go to general, come to our currency, which is DRAMS. I don't need DRAMS. I'm going to use my Ugandan shielding. Save this. And then if we come back and reload here, we'll see we have UGX. And if I place the order, that will clear out very well. But I don't want to have that error coming up again. So I'm going to paste some code inside my plugin. And then that is going to allow me to add extra currencies, that particular currency to my plugin. So I have a couple of code that I'm just going to copy from the other plugin. Copy this. And then I'll drop it here in my file. And basically, it's just getting the currencies on the symbol. And it's just checking if I have this currency for UGX. UGX is actually the country. This is Ugandan shieldings. This should be Ugandan shieldings. For that, we are checking if we have the currency. If we don't have it, we just add it. So we'll just add that currency. Then we'll get this particular currency, which is UGX. And we'll add that symbol of UGX to it. So we're always sure that we have UGX at any one time that it's given. However, we can also just cross-check to see if this function is available. But in this particular case, they're not going to show up. I'll just add, I'll just change these few pieces. Just in case I'm running the other plugin. So I'll change this to take a press add UGX currencies. So when I come back, go to my shop, go to show. And each set up my shop, then I go add genes, go to view the cut. Can fill in all of that payment. Pay this again just to make sure everything is working well. The order is received. If I come to my orders, you will see that everything should be working out. It's processing because I've chosen for it to always go into processing. We paid via PayLeo, which is working out well. So we've managed to convert our actual payment gateway from the cash on delivery to our mobile payments. So now the task at hand actually comes in with using the API. I'm going to try to break down this particular plugin and make it into more reusable code because this is really starting to get out of hand. We have so much going on. So we can break this down and make it into a class system. So I'll just go to my file. I'm going to just rename this and call it PayLeo. Call this PayLeo payments so that it's very clear what I'm working with. I'll change this here. We're going to have a new file which is for includes. And inside there is where we'll add our class. So copy this, paste this here, move it here. Okay. Let me go back to my plugins and then edit that from the editor. So do this and remove this. Now what we're going to do in this particular place is we shall allow for this to happen. So I'm going to move this whole class and then I'll leave it. I'm going to just require the particular file to from coming from includes from here. So shall rename this and call it a class dash wc payments get away PayLeo. That will work fine. So we're going to, if we have this class existing, then we shall require plugins URL to add to this file, then we shall add this name. So we shall change this to includes slash that dot PHP and then save this. Of course we, our semicolon, we don't need to concatenate. So save this, come back, go to settings, make sure our payment get away still active. It's not active because our plugins, we changed the name. So I need to change the name to this. It's also really affecting me get this class on its own page, take everything else out, then just scoot this to the beginning. So we have our class there, we'll extend it. If this is any, if this exists, then we'll require and then extend so that we actually have something that is much cleaner and manageable in terms of our file system. So, so this works out well, just 55 lines here. So this is manageable, a few functions with this showing up. Okay, so and then our class. So let's go back, reload this. We didn't rename this. So rename that to PayLeo Payments, a proper spelling get away, come back, reload here, we'll have PayLeo activated. We have quite a number of things because of my server configuration. I'll change this to the plugin directory path and I'll append on our final file. Let's see how this works out. And we have everything working out well. This is activated. Let's come back to our settings. This is active. If we manage this right, this works out well. Let me just save this. If we come back to our page, go to the shop, order for some jeans via the cut, fill out that this is available. This is missing because it should be broken. Showing plugins, they include assets. Yeah, because in our file, we are doing this. So I just need to go one level up and then our icon will show up, place the order and our order actually shows up. So we're good to go. Now let's tackle the real meat of the problem. So in here, we have a function that checks whether a couple of things are available and make sure everything is okay. We check if the shipping is in. If we're on the checkout page, blah, blah, blah is the method checked for? Is it available? The settings, we get them, get the shipping methods, get the order item rate and all those other things going in there. And eventually we have the biggest function of them all, which is the payments process here. And all it does is that it gets the order through the order ID by getting an ID here. We'll see that here, if it's greater than zero, we place it on hold. If it's greater than, if it's less than zero, then we complete the order. So this is the place where we're going to add our own particular function. So let me just copy this. So here we shall add a new function where you say this, and we're going to call it Paleo processing, Paleo payment processing. That will be our function, of course, with those and a semicolon. Now with this at hand, we shall just directly put it here. It's going to be a private function because we only want it inside this particular class. So again, it'll be a private function. So the only thing that we'll do is shall get this and then use it at a later stage. So reduce the space here and then paste this here. So mark payment on hold, payments won't be taken until we're putting it on hold, but rather I would rather have my own kind of, let's say, an order status that will allow me to show that it's either pending payment, in case should this fail, then we send it to pending payment, but if it should pass, then we go and actually do the order payment complete as we have here. So this already does it very, very well for us. So we can always also just copy this and have it here. So as we are planning for this, we need to recognize that in WooCommerce itself, there are already a number of order statuses that are available. So for example, if we go to this order status here, you can always check there's a status for on hold, completed, cancelled, funding, we have failed. Now we can also introduce our own order statuses and there's a video that I created that will show you how to actually add your own order status in this particular place. So let me just copy some of that code and dump it in our plugin. So we're going to have a new file in the includes that I'll call order statuses.php, but I'll just add on the paleo to make it very unique. And then I'm going to require it here. So I'll do this paleo dash order statuses. Essentially what these functions are doing is that we're just a new order status by going to register post status, which is a default WordPress function. And we add a IDWC invoice and we add invoice as its name. It's public. It can be shown in admin lists. And then we add that into our available order statuses by using this filter. And then eventually we add it in the bulk pieces of information. Now we add it in the bulk so that we can be able to use it. For example, when we go to many orders here, we're able to let us select all of these and then mark it as invoice. So that's why we have it here as mark invoice. So I want to make sure it's the same as all the others. So I'll just change status to invoice. So I'll just do this and say change status to invoice. And then I'll change the text domain so that it's the same for all the others. So get this, paste it here, save. I'm also going to add this text domain in all these other places. We have been shining head from doing so. So I'll just get everything and then paste that in there, save and come to our main page. Of course, look for this change here. There are no other places to do the text domain and I'll save this so that you can always translate this into a million other languages. So we have our bulk action showing a change status to invoice and we can decide to change maybe two of these and say invoice. And then we'll come back here. We see status is invoiced. And by using these status, we can be able to query our server and say maybe it failed at the particular time of payment, but can we recheck using a cron job we can check to see if our server eventually applied the paid status to that particular payment. And then when we query that and bring it back here, we'll be able to see that actually either this order failed to get payment or we actually receive payment because our mobile payment is a bit tricky when we see them in most cases, they give you time to process a USS ID and sometimes you will not get a message by USS D. But as you go and check using a particular dialed USS D, then you're able to recognize I have a pending payment and when you pay it, then it's cleared on the server. So cron jobs would be perfect in helping us check whether that is actually paid or not paid. So we've introduced the invoice status and that's what we're going to do even here in our class for this case. So in our payment processing, if things fail, we're going to have two points. If cleared, then we shall run this case. If it is still pending payment, if it's pending payment, then we shall run this to change the status and we shall the status that we'll be looking for is WC invoice. Basically, it's saying we'll get the order status and say if the order is a downloadable item, then we shall do the WC invoice. Otherwise, we should say it is processing and then payments will be payments pending. So we'll change that message here. So we have the message payments pending for when this is actually pending. So what we're going to do for now is we're going to zone this out and then start doing a couple of things here to bring in our API. The video is a bit long so I'm going to have to stop here and then in the next step, I'll show you how you can actually add your own API into that system.