PayPal Payments Integration Tutorial Using PHP & IPN & PHPMailer

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
in this video you will learn how to accept PayPal payments on your website and then with the help of instant payment notification how to automatically send everything to the customer so let's do it hey what's up guys Senaid here from codingpassiveincome.com the place where I help others to become a web developer much easier and fast and then they will do it on they own so if that's something that interests you consider subscribing so before we actually start writing any code I want to explain you the basics that you need to understand for this tutorial so that you have a visual representation of what is going to happen so we are going to create a one simple website let's say like this and then here we will like to sell something let's say a wordpress plugin or something and then we will have some futures of our plugin here and we will add here a PayPal button so now once the person press this button we will resurrect him to the PayPal website and here he will be able to purchase our product so now if he decide to press a cancel button we will resurrect him back to this page but if he successfully purchase this product we will resurrect him to some thank-you page like this and they will say he thank you okay but now what will happen in the background the PayPal let's say here it's paper the PayPal will send an instant payment notification to our server so let's say we will have here one file let's say callback file and then once the PayPal send an instant payment notification we will inside this file accept all those information we will verify if he really purchased this product because in most cases there will be a people that will try to scam him and then if everything is okay we will send to this person an email that contains all the details and about their purchase and also the voter flag in the debugged so I hope so that this is very simple process and I will show you that the code is much simpler than this explanation so let me now show you how to write the code so now I'm here at my PHPstorm I have created a new project in that project I have one folder attachment and there's some zip archive that I will send to the customers and then I have an empty index.php and listener.php or we can name it callback dot PHP whatever you like so now first let's quickly design some basic pricing page I will say here pricing page and now I'm going to include the booster so I'll say getbootstrap.com and I'll go to download ok and down below I will just get CDN link for the CSS and I will include it just before closing head tag so in here I will have one class container and in that container of course you are going to have one row and then inside this row I will have just one column so let's say col-md-6 and I will set offset to the tree so that from the boat side we have same padding and on that way we have everything in the center ok cool so now inside this column I'm going just to create something that is the latest in the booster for and it is card so we will say their class card and then we will have card-header and here we will have card-block which is basically the body of our card so maybe in this book I will say we will have card title and then I would say it is WordPress plugin and then I will just specify some like pewters so let's say this is a list group and then I will have different list group items so maybe let's say future one let's say you have multiple of those ok and maybe up here I will say okay I want <h3> and this will be let's say does the price so let's say 67$ okay so I have just saved this and let's see what I got so just upload everything because for us in order to test the PayPal gateway IPN we will need to have it on the live server and we are not able to test it on the local host anyway so it is okay and here is the basic design that they have so maybe we can write some CSS here at the head so I would say style text/css let's say our container will be margin-top let's say whole pixels and let's see here we'll have or maybe in the row I will say line to the center or maybe to be better received just fine content to the center and then let's say for the please group item I will say that I will have padding of five pixels and maybe let's remove I think we have the border yep so let's remove this border shall see for the ratio pixels and let's see what will happened okay so maybe we can for God here say text center and then maybe I'll go to say it like span I'll define some class currency and <h3> will be class price so now let's write let's say that the price font size I will set set to pixels I want something big okay and then for the currency I want font size are very small let's say 25 pixels I mean small in comparison with the price then I will set the position to the relative and maybe lets its top like -30 is this okay cool so this is looking good maybe we should just put here everything in here the center and then maybe on I will set card to the let's see 300 pixels and then card horror let's say transition okay transform I will set scale to the 1.05 and then maybe let's set transition to the let's see this should be the time and then he is in out will be how we are going to do it and I would delete this okay so let's say see what we have now okay so now it is looking good and if we do okay this creates a really nice effect here and that's it so now the next thing that we need to do for this pricing page is we really need to add Buy Now button from the Pay Pal and now in order to do that we will need to log in to our PayPal account and then once you are logged in you just need to go to the tools and then to the all tools and you should get a similar design like I have I think that it will depend on the type of the account that you have on the paper but something similar will be there and then you will just need to find PayPal buttons click there and then I will go to the create new button and now here we have a different types of the button for this one I will choose by now okay here for the item name I will say water spoiling and then for the item ID I will say again what this plugin so I will just use this to identify that it is this one product because maybe on this pricing page you will have a lot of different products that you want to sell so the price for this one will be 67 I don't need anything else then here I will remove this option and then here in the Advanced section I don't want to add customer to change all the quantities sorry I don't want any special instruction shipping enters we don't need and then here are the things that I have been talking about so for the cancel if I will press cancel I want to resurrect them again to the sales page to the pricing page okay and now when they finish checkout we will reject them to the some thank-you page we don't have it at the moment and then here is an important thing as you can see if we want that paypal send an instant payment notification to our website we will need to add advanced variables and then we need to say notify URL okay equal and then to specify the link to the file where it will send all the details so I will just say Western I think that is the name of the file that we used second yes this so little dot PHP okay and that's it it does go to create but so now here you will get the code that is ready to be just pasted in your website and here's the design as you can see this one is encrypted and you can use that one or if you click remove code protection you will get something that is much readable and you will if anytime you want you will be able to quickly modify this code but probably I will always suggest to you to just use protected version because that way it is much harder to try to scam it also there is an option to use an email and all you need to do is just to get this link here and then just create a normal link in your HTML document but I will just use this protected version I will just copy and then I'm going to paste here under this list so let's say I will put new twin brake lines and have just pasted everything in I will save it now let's see what will happen on our sales page so if we refresh the pinenut by now but that is there and be quick we will be redirected to purchase this okay and if I now decide to cancel I will be redirected to the pricing page again so now this is all that we need to setup in the part what the customer or the Vista to our website will see but now the problem is to set up instant payment notification and what will happen once the customer purchase your product so in order to do that we will need to go to the developer dot paypal calm and you have to notice that their vision s after the developer so it's not developers its developer and then I will go to load into dashboard and here again you can just use your normal login details from the paper okay we are loaded in and now what is important for us here to use all I want is IP and simulator basically with this I beam simulator we are able to just to send to simulate the purchase and on that way could make a code on our back-end and verify that everything will work just as we want so first thing is ID Panhandle URL so that one I will copy here and then how does sale here Lister the problem is that you are not able to just test it if you don't have this file so just make sure that you have one uploaded and that's it and the problem is that most of the time if you only have the file this IP and handle your out will always work so you just keep that in mind so transaction type let's say that we will have a asset okay and then here are the payment information that you can set up so that you can make a test so let's say first times will be instant payment date okay payment status let's say completed a trash fire status first name last name for email or ID address name address country country code those are all the things basic before the customer and earlier I never change any of those because it's not important now here for the business and receiver email and ID I usually write here something like let's say calling as income and then here I want to use an email that will actually receive all the payments so I want to test that okay and then for the item name you just need to make sure that this is the one that you have been using on the PayPal and we created by now button and then item number sorry guys this should here and then item a miss board press ok and quantity shipping tax we really don't need any of those we can just delete if you want to and then currency fee that's not that much report and gross let's say this is our price that we want to have you can delete this one Sumter section ID not 5 version etc etcetera we really don't need any of those things okay cool and now if we hit send ipn the word thing is that you will always need to scroll up and here's what the IP Anderson and the handshake was verified it is okay but the problem is that we don't have set up any listener so far so let's create one so I will just open PHP thanks doesn't mean a little bit and now the first thing that I want to track if a server request method equally put post or maybe different than post I want just to redirect person to them index.php so all I'm doing here is basically if someone has found that we have less than a dot PHP file we just want to verify that there is some post executing on this page and if it there isn't that we want just to redirect that person to the our pricing page okay so now here probably we will receive the details from the paper just here is I've been simulator and if we open here you can read a lot more about this IPIN simulator and all the things that we will need to know okay so basically we need to verify all the information that we have received in this speed derive directly on the paper and if there isn't a verification from the paypal that means that probably someone is trying to scam us so for that reason I'm just going to write here I will use cool so I'll say call handler equal called init okay and now here I will say sorry cool set up sequel opt and then URL in the URL on which we are going to execute this code is here so I will just copy and paste here now the next thing that you need to set up is we'll return transfer I will set to the one then let me just duplicate this then the next thing is s somewhere if I host I will set the 0 then we have verify here how does set the zero again then I will say just because implicit so I'll stay here pull off let's say post I will set it to the one and now post files ok and here I'm going to say command e go notify and voila day so this is something that is required by the paper so we need to include this command that we want to notify and validate this information that we have received here and then I will obtained here hurting from the post okay and after that I think that we have set everything and I am going just to execute this ball handler and of course I am going to close it okay so basically what I have done here I have set up some URL for the call I have decided that I want to return transfer from the paypal husband in it I don't to verify anything related to them SSL and then I have decided to we are going to make a post request and then here are the informations that we are making through this post and of course here we need to execute so let's say just I want to with everything to them let's say test 50 and then response I want to see what will be returned by PayPal once we try to verify okay and I will just upload listener okay and now let's try again this simulator I will say sent IP n okay it's done and let's try here now test the Eckstein and here is what is returned by paper so I'm not sure what this says that there is no transactions that's weird so let's check our code the code is looking good but it was that I have forgot here include a person okay so let's see and try again so I'll hit Send IPN again okay crash okay and now it says that the data has been verified and basically this is always what you are looking for when you are verifying is actually the payment happened on the PayPal side so if this response equal verified that means that the purchase is surely there and everything is looking good so for that reason I'll just say here if response Iko Iko verified okay and usually what I love to check here is basically who is the receiver of this transaction because someone can try to purchase to his own email so here at the top we have receiver email and basically that is what you are looking for so I'll say if response equal verified and post receiver email = email that you have specified here okay I did and on this way we are actually sure that there isn't any problem with this email so we are actually the one who received the payment and now we can say here else we can maybe write some error to the error log or maybe we can send an email to ourself and basically to save everything from this post does to know what is happening behind but I'm not to do this inside this tutorial because we just want to make sure that the payment has happened it's verified we are the ones that received an email and also now we are going to check the price of our product so the price we will get so maybe let me show you first what what are all the information that we have got inside in this IPN so I will just say like for each let's say handle equal open and then I will use just again same file I will use more the bright and then here I will say foreach post as key value I will write it to them this handle and let's say to be key value and then on your Y and here I will just close it this handle okay like this so let me now just quickly upload and show you what are the information that we are going to get down I will hit Send IP n okay and let's not take a look so here we go so basically we have keys payment type payment date payment status address that aspire status first name last name fire email address name and all other informations business receiver email this is one important item number and item name quantity we have MC gross which is basically how much money someone paid of course also information like currency fee etc etc but now for us basically to verify this and be able to send to this customer an email I will just get a first name last name fire email and of course you will need to get price and item maybe number so let's do it so I will see customer name is basically the first name and then separate by so I will say last name okay now price we said is in the MC cross I guess we can always make sure that yeah it's a super us okay we want also to check the currency it is not the same if someone is paying in something else see currency okay and then we have item so let's say boss item number okay we will also need customer email customer email is it's fired so that you can send an email the plugin that he bought and I guess this is all that you need to have so far yeah I think it is maybe we can track the penis that's so payment that's his boss cool so now we want to make sure let's say I will dust no like this so those are the things later the purchase and those two are to the customer so here I want to see if item equal WordPress plugin and currency equal USD and I think it is USD let's put picture yeah capital letters okay and if payment status equal confirmed and of course the last English price and price equally both 67 we will execute this part of the code here which means that basically we are just going to send an email to this customer so what else we can do is to use those information and if you are selling membership access or anything else to create a new account in the database and then send a login details to that person but for the purpose of this tutorial that is not that much important so let me just now quickly save file put contents okay now let's see-oh verify so this is just to make sure that we did everything correctly because we do not have any any other way on how to test this okay I'll try to send ipn again okay cool - and we didn't get anything so there has to be some mistake so maybe let's say else with condensed dude and then he I'll see the top and I want just make sure the date that equal then I will just say price okay and then currency and then item I want to make sure that we can identify what is the problem so let's see okay I will send idea again okay so I think the problem is with the status I said here confirmed and basically it is completed okay so let's try to test again so that is why this IP and simulator is so important because there are hundreds of places where you can make small mistake and your IP n won't work so now it says all verified okay it's amazing I can now just delete this okay and now inside here if everything is verified I would love just to send to our customer an email that will contain attachment that he booked which is basically what was plugging and for that purpose I'm going to us to use PHP mailer of course shall go to the Google and say it be mail at don't go here then I'll go to the phone or download and I'll just put it down okay I'm going to save it to our folder and let me just fine here so extract everything here I will delete this archive maybe I should rename this okay and then I will just delete everything except source then I would the source get everything move here and then delete this I mean this is just the way that I love to organize the files okay cool so now first thing that we need to do is basically here at the top will need to use PHP mailer namespace so see use PHP mailer so this is usually the namespace of the PHP mailer and you can find that in the documentation github okay and then I'm just going to include so yeah I would say PHP mailer and then I will use PHP mailer for us and I'm going to get exceptions okay I don't I think that we don't need any of the others for the purpose of this video tutorial so here I'm just going to create a new object so seen u8p mailer okay and here for this object we need to set so same mail and then I will say set from so this is who is sending an email so does a sales@codingpassiveincome.com comment and then the name I'll say CPI's feels okay then I want to set okay we can add attachment which is the path is attachment so just quickly attachment and then the name is WordPress plugin so I'll say here WordPress plug-in that's it tako then you can specify the name for it I will just say WordPress plugin okay now mail is add address which is where we are sending an email so that person is theirs customer email and then the name is we have it okay cool so now I will say mail is HTML I'll say true so I am going a little bit faster over those settings for the PHP mailer and for those of you that really don't understand this part you can find a lot of different tutorials on my channel related to creating content food and sending an email using PHP mailer and then I will set subject so I'll say thank you maybe your purchase details okay and then body okay yes shall say maybe hi - no one's thank you for purchase and attachment you will find my amazing wordpress - my regards maybe whatever I mean this is not that much important and then here I would say mail send and that's it so let's verify it once again we have said who is sending you said an attachment who is and where we are sending we said that it is HTML subject body and pretty much that's it so now let's quickly just upload everything fresh and let's make a test but first I want here to change who is the buyer so I'll set by email to one of mine shall see hello and let's see any calm calm and then I will just say send IPN so let's now see and I get any email maybe we have made some mistake so yep here is the latest one it says your purchase details CPI sales and if I click here it says hi thank you for purchase blah blah and in the attachment there is water spot and yeah that's it now it is everything working just as it should so guys I hope that you have enjoyed this video if you do please like it and share your friends and of course if you have any questions feel free to ask in the comments below take care
Info
Channel: Coding Passive Income
Views: 83,522
Rating: undefined out of 5
Keywords: php paypal integration tutorial, paypal, php, paypal payments, payment, paypal account, payment gateway, paypal php, gateway, paypal integration, ipn, payment processing, tutorial, tutorials, pay pal, paypal ipn, payments, howto, how to, paypal integration in php, paypal integration in php step by step, paypal express checkout in php, integration, php tutorial, php tutorial for beginners
Id: dHUD5L5loVU
Channel Id: undefined
Length: 42min 12sec (2532 seconds)
Published: Mon Nov 27 2017
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.