 Lucky niục na himishizu ninyu na hini hisha kuwa npati kwa mwen curry hisha kwa hikivu na maqa maqa waz na usewe na mwaz na kwa hiki na leley na na naji mwaz na maqa maqa maqa maqa maqa maqa maqa mwaz nshivu nsi kwa mwaz niya wazha so amiaitwa nini ya y woman mwaz jajene wa ni hwiai dhiza ni usu ni sdarko man ni jamia ki juya kumukama na kufunbara. Kusunbara m왔u wakama, habi ki chilu kajalijne kama ni hwiai kufunbara wako ya umao uko ya wako ya umao waka jajene wako jajene kufunbara katilufunbara fain our payments process our process payment function and we know that we're going to apply to the payments processing here so whenever our value is actually greater than zero then we run this function but from this api i've realized that you actually need to have a value that is above 1000 shilling but for now we'll leave it at zero then allow this to actually run so i'm going to paste everything here and then from that point on we shall be able to make it dynamic based on the information that is coming from our wukamas order so let's save this here and then we are going to start off to make this all dynamic so i'll just click to reduce all these functions so that it's a very short distance going back and forth here so we realize that there are a couple of things that we're going to need to add in our payment settings for example we don't always change our api key and our widget key so we're going to have to make some forms for them here i'm going to duplicate this let me just duplicate the description which is going to be easy so description i'll call this a api key so we'll have that and then i'll duplicate also the api key so that we can have our widget id as paste this out to make it even so we have that working we don't have a problem with that so i'm also going to set these same pieces down here i'll copy these paste them down here and then for our api key i'm just going to add a message let's say this is our api key so i'll copy this add it here and say add api key and then i'll do the same thing here and then i'll say add widget key add widget id so we have this incorporated the next thing that we need to do is actually add them here so i'll duplicate this twice and then we'll have this as api key and then this will be widget id so we need to backspace this so that we keep everything nice and neat when we need to see it and then in here of course we will change this and say add widget id so we'll call this widget id that's the title we'll call this api key then we just need to change all this information add your widget key of course here we'll just say api key then we'll take out the defaults because we don't have any default keys that will be applied at that point so i'll save this and then come back to our payment gateway of course we now need to go to the settings and see how that looks like and if we go to payments you don't have any errors that's the good thing here it shows that we've done everything properly and then we now have the new field for the api key if we click we see it tells us what to do and then we have also the widget id already here so what i'm going to do instead of having this uh looking at me at the bottom let me close this off uh i'll just save this so instead of having this uh just thrown here i'm just going to copy this and then save them in our database so that we can always just pick them from there copy this also as well and test them here and save changes when i save that you can see that they are stored i can change them and save settings again so that's covered so what we're going to do is actually just come and take this away this so instead of having this generated here i'm going to do this dash greater than symbol and then put api key that will automatically fetch it i'm going to get that and then also paste here instead of api key this time it will be a widget key so we have this information that will be dynamically needed to be added here um the next thing that we need to do is get our phone number we've been we had the phone number already sorted for us inside our payment when you look at the payment checkout we already have this post payment number as this so i just need to get the same thing here copy it and then come back here and change it to that so that we'll have dynamic information always coming in from our form so the only thing that i need to do is because i'm sending this to our api we need to cleanse it we need to sanitize it so i'll use a escape attribute a ttr i usually read as attribute but it escapes this and makes it clean for our api to receive but we can do more sanitization and validation to make sure that this is as it's supposed to be and then for this particular part we're going to need the order amount so i'm going to check our function here which we have here we already have the order id here uh we just need to get this order total and when we get this order total i'm going to pass it inside this argument here and then after passing this here we need to also receive it here so i'll just call it total when we receive it here we shall just call it total so i'll copy this and then i'll say amount is equal to total so instead of saving it as a variable here i'll just quickly go in this piece that we set up here and i'll just change it to total there so we no longer need that amount and again there so for now we can also change the api key and do the writing so api key change it here and then our widget key will copy it and also paste it here so that we don't need these pieces we are reducing our code and making it a little cleaner so the phone number we can also just get it from here but since we are sanitizing it and running it let's just leave it here so what we are going to do at this point is let's just try to run our function see what it says and then at the end of this we are going to actually just kill whatever it is or just print out whatever response that we do get we'll also be looking out to see what comes on our mobile so i'm going to go back to our order our order is just 300 shillings it won't work for us so i'll go back to our shop i'll add a couple of items and then after that i'll go to view we'll come in we'll fill in our form you can even use this phone number if you want to since we have our tutu here i'm going to choose a paleo mobile payments i'll put in my number then we'll take this out and just validate this number to make sure everything is working out well and when i click place order our order says it has been carried out but we seem to be having an error at this particular point so i'm going to just place die here so that after we've ordered everything actually just sticks and then we don't go any further than that point first things first let's first comment this out and then let's first vadamp what we have here which is our url so get this url to make sure that everything is actually working out well uh so we'll vadamp it let's just go and try to make our order so we'll place a couple of things here go to our view cut then we have our order one six to put in our number five six blah blah blah and make sure that it's all right so i'll just open my audit of this and i'm ready place the order we have called our Ajax here we are seeing what we have and i know it breaks because we have a vadamp in there but if we look at our url we have this coming out well we have of course our api key working out well we don't have our widget so we know that's not going to work but we have our phone number coming out well we have our amount is missing we don't have a the company mobile is okay the reason is actually okay so we need to get two things we need to get the widget id to work we also need to get our amount to show up here so first things first is a widget key does not exist because what we have here is actually widget id so i need to come back down here and make that correct and then the other thing that we didn't have was the amount the amount we're going to get the order here so for my reason i am just going to get the order id and say payment for order id so we'll just change this here and say our reason is order id we're going to just chain on one thing in brackets chain that on so payment for order that and then we'll chain on our id that will be our reason so we need to also get the payment uh total so in here we shall pass in the order that we get and then we shall filter to get the order total from this point order here let's see if we get the order total so total will equal to the order and then we shall get our total on that gauge total do that so we can also decide to add up this see what happens copy this that let's see what happens so we'll go back to our order reload this come back down feeding our value because it will break everything look at our console place our order look at our hctp request we now have our api key we have our widget key we have our form we have our amount which is really good however it has two dots on it uh i probably don't want the two dots on it so i could sanitize it to be different but we can also see here that we have verdant it as zero zero here so for my case i am going to actually make this an integer so it will have to remove all the other pieces uh on it so make this int val and then i'll have this as int val but since it's working out well i'm just going to allow it to actually go to our api for the first time and let's see what we actually get so i'm going to go back reload this we have our order which is our order which is over 1600 it's better than what we required the api place the order look at our ajax going we have our request on our phone to pay and our sms has come to pay and then the api is just waiting to get a signal from our site to see if we have made a payment so if i make my payment and it is approved i have a payment of 160 on my phone you can see that and then of course we have an error showing up on this side but we now know that we in our api if you look at this this payment has been successful we'll see that we get back a response a message which is saying thank you this was successful we have all this in our our contents i'm going to copy this and then we'll filter it to make it possible to say if this response that we get was successful then this is what we should do maybe we should change our order status to payments have been made if it fails then we say the order status should be payments are pending so i'm just going to dump all of this here the reason why it failed to complete to have this is because we left die inside our function so i'm going to take this out and then i'm going to add our code that we get here it's not the best thing to do probably we just want to get the message that we get here we also need to know the response which is a 200 the code is 200 and then that will be all we need to have so i'll just undo this and just have this inside a notepad to make it easy for us to follow along so i'll just press all this information here and then we're going to get a couple of things so first and foremost we have to get the response code and see if it's 200 then we go if it's not 200 then we fail the whole process we just say you know what the payment has actually failed so we're going to use a couple of things that come by default one press and that is things like the response we're going to use the the wp remote get remote retrieve body that is one then we're also going to get the remote retrieve code and we shall get it from here so everything else will work out if it's an error we do that and then we return if that's the error otherwise let's go the step below and what we are going to say if 200 which means that it is okay we'll first start off if it's not 200 if our remote response code is not 200 then that means we have a problem so we need to return and say we have an error so we return and that will automatically show our payment gateway that there is actually an issue so we can even decide to echo what the problem is and then just throw it off so I'll just copy this and then serve this because we need to close this properly that's why we're having that error so that's the first fail if everything works out actually if it's not 200 this is how it should be not like this if it's not 200 then we should fail please note that this is just an exclamation mark and two equal signs but because I'm using font link it adds them all together to actually give us that piece so I'll take this out so if it's not 200 then we have an issue let's return we can even return this message right here and save some space not much it's negligible but that is it so we'll copy this and just do the something save here then if it is successful I'll just make it really typed to show that it is the issue but we don't to have that so I'll copy this if it's 200 and it is right so we just need to add three equal signs that if that is the case for us then what we are going to do is we are going to get the remote retrieve to also make sure that everything worked out well so we can also come in here and say if the remote retrieve body is saying blah blah blah then that it was okay so the body is going to have the message it can also return the metadata if you look at the metadata here it can return it because our API told us if you want to have any other information coming back you should write metadata so we can always pass that along if we want it but for my case probably not so if this field of body if our body has this message so we are going to chain on this message here so if we remote retrieve body and we are going to get we're going to chain on the message that's what we need to get if the message this message that we're getting here is actually equal to it's a string so we can even equate it to that and say if it is equal to thank you blah blah blah successful uh we'll do this yoda style to make it work out so if it is that then that means three equal signs if that is that so let's first escape let's first get this and say this is our response body so response body equal to this part and then we're going to say we're going to look for one part there we're getting body if this is what we are looking for so if if this is what we are looking for then what we are going to do is actually come here and say it was cleared so the order is complete so order payment is complete uh if it's like all the other cases up there then we are going to instead of just returning we shall just say pending payment so we shall use what we had here so we just say the order is actually pending payment it's invoice pending payment and then we shall also do the same thing here is an error so we can sort of record if we want we can record the order or we can just decide to fail it complete so in this case I will uh just say it's pending payment and then here I will pass it and then we'll clean out all these parts so for this point I'll save this and then we're just going to try one more order pay it first of all we shall fail it we shall refuse to pay see whether it goes in pending payment and then after all we shall also order to see if it actually passes so let's just do that and see what happens so we're going to go back come back let's make some new orders uh I'll just vardamp this I am not so sure of what we're going to be having here I'll just vardamp it so that we can see what goes on in there and then we can work according to it accordingly so I'll vardamp that uh let's see what happens so go back to our shop or go to our shop uh make some orders to pieces this is 1000 go to the view cart everything is working out where we fill out our order this is 26 means so much items let me just I need to go to the cart edit my cart uh remove a few things that take out that uh make these two update cart and then proceed to pay out our order details are filled in we have that I'll put 26 fill that in place our order let's see what Ajax gives us what our response is we have that showing up we are failing it for the first time let's see the response that we get we have failed it just waiting for it to time out come back tell us just waiting for a few seconds 45 to be exact so we got a response back uh clear the order that is a problem in our code here we need to check uh why it clears the order is received let's go to the back end and see how that appears so it goes to paying payments which is really good and clears the order it's paying payment but now we need to check uh when we actually pay for the commodities so let's go back and then see uh what happens when you actually pay for the commodities so shop let's go to the shop uh get our 500 another go to pay go to review that our mobile payments 25 blah blah blah this time around we are actually going to pay the order so let's go wait what comes we'll wait to see our response so waiting for api comes we get the message we are now paying and then replying fill payments are done we've approved the payments and then we get our order back we see our response gives us it's cleaned out this is doing so well let's go in the back end look at the orders and it's paying payment so we just need to see if we have an error in terms of what the way we receive this object it's supposed to we're not supposed to chain it but rather we're supposed to get the message like this so we'll paste our message like that same thing for this so i'll just copy this then paste it here to see what kind of message we get save this uh let's try it again um don't get ahead of losing some money that's why we have sandboxes to help us fix all of this so i'll pay this to the shop go pay for a few items i'll go to the cuts preview it and then i'll make my payments 256 blah blah blah come to place the order and now we are waiting for the order see what comes back in our response we're going to pay put in our code messages come reply positively the key is working out well our order is received let's go let's come back to our orders in the back end so when we come back to our orders we actually see that this is processing so our payments actually going through and this is working out well so try it out on your api see how you handle your data let me know if your processing is working out well try it out don't fail when you get some errors keep trying over and over again depending on the response that you get on your api so our api is actually processing it is in good shape and we are having what needs to be done so thank you for watching the video if you enjoyed it please give it a thumbs up share it with your friends and of course don't forget to subscribe because we have more interesting things coming up for you