Stripe Payment Gateway Integration in Laravel 11 - Part 2

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
now I am going to show you how to integrate the strip payment Gateway with laravel 11 so first I am going to install a fresh laravel application in my computer so I am going to this location for example uh into my main root that means triple W there is a laravel 11 folder and here I will install the flesh laravel application so I am going to open the terminal in this location and here into the laravel 11 here I am going to uh run the command to install the larel 11 so in to install the latest laral I will have to call the composer command so this is composer then create project then laravel SL laravel and then I am going to give a name here for the application for example payment stripe so just wait for some time you'll see that the laravel new application is going to be installed in my computer and it is done okay so you see the payment STP this is a fresh L 11 and so I am going to run it first so in order to run it uh you see in order to run it here I am going to enter into the folder that is payment stripe so I am now into the payment folder I am going to clear the terminal okay so I am into this location now and now I am going to run phsp artian migrate so nothing sorry uh so I will have to run PSP artion serve so a development server uh is going to run here so I am going to paste it here so you see this is the front end of the newly install laravel 11 and you see in the bottom it is showing laravel 11. 6.0 and the PSP version I am going to be used here that is PSP 8.3.1 okay so this task is done now I wrote something in order to in to integrate the stripe on my computer I put all the steps here okay so I will just show you how to do that very easy just first I am going to uh here in my editor and I am going to open the payment step folder with my editor here you will see there is a file and in thatb file I will make here you see by default that database connection name is SQ but I am going to use here MySQL okay so I will use my SQL here but before going there I am going to show you something that is in the resources views that is welcome so I am going to remove this and just going to put something that is testing so this is the main default BL file that is going to run here so I'm going to refresh you see testing is showing here so this is the file that is showing in front of me and another important thing is Route and here web. PSP this is the default route welcome BL file it is going to call that means this is the main out and when you are going to hit into the main URL then it is going to be open this view file that is welcome view so in the welcome I write just testing and that is showing here very easy so now I am not going to put this I am going to put something special here that is I am now going to open this stripe _ 11. txt file this is my help file I am going to login into this using this email into my stpe account you see this is the stpe account that I have logged in and here if I go to the profile you will see this is my email address and this is the email that I write here and here the publishable key is here into the developer and API Keys you'll see this is the publishable keys and this key I put here and another one was actually the secret key and this one and I put this one here and there are some step test cards that I will use to check the step payment uh using any of these cards I will show you that later so what is my steps uh my step now that is I will install a stripe package in my computer from here that is GitHub package so if you search in Google and search by GitHub package you will get that GitHub type you if you search Google you will get that and this is the GitHub page and stripe PHP if you go here in the bottom you'll see that it gives you the command to install the stripe this one right so I put that here into my doc file uh to make my task easy so I just copy it and from the terminal of the browser I can easily run this so uh payment stripe uh it is showing sorry I am not going to use this actually the composer command I will have to run so install package is here but uh the command will be this one I copy this from here command will be this one okay so this one I will have to run so I am going to the terminal paste it composer require okay Enter you will see that the step package is going to be installed in my application so it for sometimes yes the application um is done installation is done if you go to the vendor you will see now a stripe this one okay so it is installed perfectly now my task is uh I will have to call something into my en file so I am going to open my en file now here and in the bottom I'm going to paste it so this is uh a variable that is a stripe it is environmental variable you can put any variable name here I give here a stripe test PK uh publishable key I give the short name PK you can give any name in this variable and another one is a step test uh secret key okay you can give any name here so I just put my publishable key and secet key here into the EnV file and into the config I will create a file I will create a config file here that will be for example stri do phsp okay and here what code I will have to write I already have given here the instruction into the config folder you will have to create this file and then copy this content and paste it here this is the content here uh return here it is showing what is syntax zor okay so here it will be a stripe PK here single quote missing like like this okay so it will be actually single cat missing here this one okay so here um this environmental variable it is loading from here that means the information that is saved in this variable that means my publishable key it will come actually here and the main variable is St PK and here it is type SK I will return this value that means I will have this in my hand because I put this into the config file okay so I can call this by the config anytime so after this step I will have to I am going to the view so I am going to replace the welcome blade. PHP here I paste the code here but before going there I put a nice HTML format then paste it here like this I can use a good format here like um this one H2 and here I can put H3 okay so like this and pay with stpe is okay and another input value that is hidden that is input type hidden name price value 20 for example the price of the mobile phone for example $10 not 20 I give here $10 okay mobile phone no problem the route is a stpe i for now I am going to remove this because I did not create any route yet just load the P how it looks like you see product is this price is this if I click here it will take me to the stripe so I will use that way so now I um give here the config file that is Route stripe so as I give route here if I want to run it you'll see there is a error because I did not def any Define any route into the web. phsp so into the web. phsp I will create I will have to create route here you see there total three routes I will have to create I am going to copy and P T it here but there is no controller here I call the St type controller I did not create it yet so I will have to create it first so in the terminal um write PHP artian make controller and I will create desk type controller so enter you will see into the app HTTP controllers folder um there is a step controller this one okay so this is my main controller and I will have to write the functions here so here if you go come you will see that this controller is called into the web.php into the top and then I create total three routes one is post route for a stripe and for success and cancel I use the get route okay so type controller St type success and cancel total three methods all the methods are given here don't worry I am I will work with migration but after sometimes I am going uh here in the top I will have to create a model actually there is no model um but not now I will do that later for now I will do some other steps that is po as St stpe is a post route because what will happen when you will um click here pay with a stripe then it will take you to the checkout page of a stripe then there I will uh receive some request so that will be a post out so because you see in the welcome I um submit the information using the form so it will actually go to the stripe and that will be a post you see this is a post as this is a post route so here I will have to call function public function stripe and here request of request I will have to write this because this is a post route right I am going to copy this one and this is a step documentation and in the step document you will see that in the documentation you can search by quantity check out or something like that you can check by anything for now here a step check out and here under the checkout option you will see there is a code that is in the bottom I'm going to SCE line make line items quantity adjustable go here and you will uh see some code here this is C code I am going to select my programming language I am going to use the pp actually so the PSP language format is this you will have to use this code so uh this code already has given here I am going to copy all the codes from this function and paste it into here I will explain don't worry here you'll see that this is a STP client this function is given by stripe they tell me to use in this way right so what I do I just copy the code that they give me and paste it here and you will see here there is a config stpe stripe. SK why I write this if you go here you'll see that here that straight put the uh secret key you can also do that but in order to make it um standard so I put that into the EM file then from here I uh copy that here and as this is into the config folder so in order to run anything into the config folder I will have to use the config function so into the config function I give this as a parameter uh this as a parameter to get the secret key so that is given here that into the config this config function means I am pulling something from the config folder and the folder uh the file name is stripe so I call stripe dot this is the variable name that is stripe so I get the secret key in this way and this is the stripe and here you see in the price data I give the product data name this name actually come from where here you see request product name request price and there is request quantity also so here I can do one thing product is this here more hidden Fields I am going to write one is um one is you see product name right so here I call product name for example the product name is mobile phone so this this one I put here another one is quantity now for example one piece I will buy and the one piece price is $10 so in this way so this is the price and then there is quantity so all this data will be sent using the hidden form Fields here okay and then I will use the parameter in this way because these are Dynamic parameters one important thing to mention here that in in the case of a stripe you must have to convert the unit amount into cents so it comes into USD when I will multiply it with 100 then it will come into cents and that will be actually the unit amount so you'll must have to uh do this action here mode equal to payment success URL equal to Route success and the session ID equal to this one checkout session ID this is by default remember it so you can use that here here you see success URL there is no parameter but in my case it will come because when you will submit the you will go to the checkout page then in the top you will see a URL like this for example if I go here if I click pay on stripe just look at the URL okay so here is uh some URL here you will see and in this URL checkout. s.com but here in the success URL when it will be succeeded if I pay something if I uh pay give email card information ETA it will take me to a page you will understand I am going to do one thing that is I am going to pull the response here okay what will be the success URL I am going to show you so let's do that how I can how I got that uh checkout session ID you will understand this is default that you will have to use the checkout session ID but how I call the parameter um let's do that the sample type card is this one a 42 42 23 4 okay sorry it is not this it is email uh email you can give any email here here this is the card and here this is the CBB number name is my name click on pay the processing is going to be done and when it is succeeded you see that there is error that is okay but you in the top you'll see that success question session ID equal to this one you do not know what will be this because this will be a variable so check out session ID and this session ID equal to this actually exactly what is given here success question session ID equal to this so up to success this is actually a success URL then question session ID equal to this so in this way I write this one because when it will be succeeded I will get that data into another place for example if this is successful then I will check if there is any response ID okay if there is any ID in the response here is response ID because I actually get the data right so in this case what will happen actually there is no success so I am not going to get anything and some error is showing I am going to do one thing that is success but not request okay and there is cancel uh cancel not view success it will be um return success and here I call return this is cancel so like this so if so you see this is success okay so if you want you can if I want to show the response here Refresh on no response not coming here okay the link is actually expired so uh you can not call this two times I am going to again there now you see when I call here there are some response here so how I get that because DD response I get all the data here right here you see when I click here all the ID this is actually the main ID here you must have to get the response ID all these things are into my response variable because you see response equal to all these things so in the response variable I have all the data that you are seeing here so this is the ID so I am going to check if there is actually any ID so if there is any response ID then and it is not equal to null then only you will proceed to the next step and here you see there is a return redirect that is uh response URL right so where you will redirect this is response URL it will take you there so where you will get the response URL here there is a response URL you see when there is any success this one give me the success URL you see success question session equal to this so stpe is giving me this right and um URL is this you see response of URL what is the URL in the last you will see there is URL so it will take you to this URL so if your key is wrong uh if your secret key is wrong you will not be able to see the step checkout P that means from your application it will give you an error and you will be taken to the cancel P you will not be able to see the check out P that sometimes ago you already saw so I stop I will stop him here right and if everything is okay if I get this stopped I do not need to see the response I will just redirect it to the external URL right that means it will take the user to this URL now now try again I am going back click here you see it is taking me to the URL I hope you got uh you understood okay so when it is taking me to the URL then something will be happened when something will be happened that means if uh you get the response what you will receive that because when you will pay here you give your email you give your card information if if you give your EMA name Etc then pay if uh the payment is done or not how you will understand so there is another step so after the response URL you will get some data here in the success so there must be another request from here using the success so here you will have to use a parameter that is request of request then I will check if the session ID there must have a session ID uh so I am going to check the session ID if the session ID is okay then this will be happening so I'm going to copy this and in my function here I going to paste it this is not need I'm going to remove okay what is actually done here if this is successful that means if there is any payment done then what will happen then you will get another response here so I do one thing so that you can understand DD response what is coming here I will show you so you see this page is okay you are allowed so you come here now I pay here for example like this sample card information I'm going to give here like this like this if I click on Pay What will happen now when every success is done you see another response this is whose response this response success response so if successful that means you see there is a session ID right so if the request has a session ID in the success uh so what will happen you see there is the ID uh so uh if this success response that means if there is anything in the success that means it is not null actually right so what will happen you will have to save the data into the database because you know the real payment is done so you can easily save the stype data into your uh database now so I will uh do that next step task now so as there is a session and you have data the session and each set session is okay then the type is this and this one and now I will uh call the model I do not have any model and I do not have any table uh so I will have to now enter the data into the database table I do not have any table yet so I will do the steps now so first I am going to create a migration PHP partition make migration and then create uh payments table okay so you can create the payments table now the migration file is created if I go to the database and here you see into the migrations this is the migration file now what I will do I will create my migration CES here that I already have written here in the top um this one so I am going to copy this codes and here I am going to paste it that means when I will run the migration uh command after this um then this Fields will be created into the payments table but there is no database yet uh if I want I can go to EnV file and here I will change that DB connection to mySQL now MySQL okay and then I am going to unblock this because I will need this for my SQL my database connection uh is established and my database name is for example you can give any name here payment stripe you can give this name database username is root and in my case password is this but in your case it can be different okay so this should work and if there is notable by this name then it will there is no database by this name it will create a database by this name no no problem and what information from the user I will save here that is the payment ID the product name the product quantity amount currency uh PR name email status payment method EXT information I will save for example so in the terminal I'm going to run PHP artian migrate you see it is asking me because there is no database in my table so here I call uh this is my PSP I PSP my admin but there is no database here by this name so it is asking me if I want to create that database by this name payment stripe so I am going to press enter okay so two things happen that is database is created and migration is done so refresh you see this one is created payment stripe and here after the migration as migrate is run so you will uh see all the tables are created here cash table cash locks fail jobs jobs Etc my main custom table that I created and that I added the fields for wh that is payments all others are by default made by larav I did not create anything for those I only created this one so I only created this one that is the payments if I go here you will see all the fields are created but there is no information here this is the structure payment ID product name Etc given here in the browse there is no information so now let's uh do this task that means in the stpe controller this one and in the top I will have to call the model but I do not have any model now as I will use the eloquent system in order to save the data into the database I am going to create ppti make model then model name will be the singular name of the migration files that is singular name of the database table so this is payment because my table name is payments so model name will be singular form so payment enter so model is created if you go here app models and here you'll see payment. PSP that means the payment model is created I am not going to modify anything here uh so now I will just put the use app models payment in the top then this payment function will work because this is a eloquent system you know so here payment equal to I create a new object of this payment function so payment equal to new payment this is the model name and payment uh ID equal to response of ID which is response of ID uh you see in my case here there is ID so I have this ID in my hand so I will have to save that into that database table you can save it or not but I'm going to save it the product name is session the session is very important when before going to the success section in the stripe when I first time check if um the um secret key is okay or not if the payment is possible or not when I going to check when I um go into the checkout page before going to that page I I saved the user information into here some important information that will be lost because the product name quantity price if I put into a session variable that will be convenient for me to use those letter because when I am going to step checkout P that means I am already out from my application so when a step throw me to my success space how I will get the information that means how I will get the quantity price and name that is a problem so in order to solve that problem before sending the user to the check out of this type I just put I just save all these import important information into session variables and here in this case when I save the data into the database I have that session variable into my hand so into the product name table field I am going to use that information that means session G of product name and in the similar way session get quantity as a quantity and session get price as a uh amount and the currencies are response of currency you see the whole response that comes here is actually as an object so I will have to use the currency right so you see the currency equal to USD in this case so response of currency in this way I will have to pull the information and similar way customer name where I will get the customer name customer email you see response customer detail name where that is I am into the response then customer detail you see customer details if I click here you see all the customer data here that is address email name phone Etc so I have email and name and address from here so in this way I get the customer name and email and payment status you know the status uh you can State um hard code here you can guite here manually that completed or if you want you will get the status as completed from this line This is complete right and another one is payment method step you know you are going to implement the step pment so you can straight right here the stripe so the data will be saved into the database and then payment is successful this message will be shown and then all the session data you will have to remove because those are not needed so for the security purpose you will have to unset all the sessions I am going to comment the DD now my task is uh almost done now I will have to just check everything if it works so this is my application but before going to check I am going to the payment sections all payments and okay these two are checked because I checked those payments now $10 now I am going to check with $20 okay so I'm going to close this one and here into the welcome I increase the price 20 and here 20 okay so now let's check it if 20 comes here as a payment and also that will be saved there currently it is empty so uh sorry I am going to put PSP my admin okay so here uh this is the database this is the table okay this is currently empty now I am going to pay so pay with a stripe it takes me here uh here I give test gmail.com this is thepe card for example if you give a wrong card for example like this uh you see this is the wrong card sorry this is a wrong card your card number is invalid so you must have to give a valid card otherwise step will not take the card so here like this like this and here is uh like this I give my full name here and click on pay button the payment is going to be processed and after the payment is processed it takes me on sorry customer name it is not going to get uh the customer name actually here my name is pairer name not customer name so there is a mistake I am going to check this is uh payment I mes this this information again with my database table what I did so payment ID product name quantity amount payment ID product name quantity amount currency customer name currency here pair name pair email okay paer name pirer email and uh payment status payment method okay payment Estus payment method okay again I am going to do the same thing actually payment is done everything is okay but the problem is for the database saving if you come into the step you see the payment is done probably I'm going to check yes payment is done but the problem is here right the problem is here okay so let's do uh that again I am going to refresh it pay with a stripe $20 okay test rfn of gmail.com so here I'm going to click on pay you see payment is successful if I go to the payments table you see this is the payment ID product name coming quantity amount is 20 USD pair name uh paer email and payment stus complete payment methods stpe so it is working and if you go to the stpe now um here if I go to the transactions you see that $20 comes here now in this transaction tfin of gmail.com what I did right now so in both the cases it is working that means the payment is done in the stend and also in the database after the successful transaction the information is going to be saved here so I hope you have understood how to integrate the step payment Gateway with larav 11
Info
Channel: CodeWithArefin
Views: 440
Rating: undefined out of 5
Keywords: php, mysql, editor, vs code, phpmyadmin, database, web development, programming, website, html, css, coding, javascript, php8, php tutorial, php full course, php tutorial for beginners, php video tutorial, advanced php tutorial, basic php tutorial, full php tutorial, php tutorial for web development, laravel, eloquent ORM, database relationship, one to one, one to many, many to many, authentication, laravel fundamentsl, laravel 10
Id: eEySu0RBnhU
Channel Id: undefined
Length: 35min 27sec (2127 seconds)
Published: Sun May 05 2024
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.