{"id":4679,"date":"2017-10-26T04:39:24","date_gmt":"2017-10-26T04:39:24","guid":{"rendered":"http:\/\/a1webdesignteam.com\/blog\/?p=4679"},"modified":"2017-10-26T04:39:24","modified_gmt":"2017-10-26T04:39:24","slug":"paypal-express-checkout-with-php-and-mysql","status":"publish","type":"post","link":"https:\/\/a1webdesignteam.com\/blog\/paypal-express-checkout-with-php-and-mysql\/","title":{"rendered":"PayPal Express Checkout with PHP and MySQL"},"content":{"rendered":"<div class=\"bigInt\">Most of the people prefer to shop online which made eCommerce to grow rapidly. But, what makes an excellent eCommerce site for the customers? The answer is &#8211; an excellent checkout process. There are several different payment options available in the market today. Out of all, Paypal is the most popular and convenient way to get paid. Making it as easy as possible for your customers to pay is essential for increasing conversions and sales. This is why your checkout page is critical. I have already discussed 2 checkout options in my previous articles\u00a0<a href=\"https:\/\/www.9lessons.info\/2015\/10\/payment-system-with-braintree-paypal.html\" target=\"_blank\" rel=\"noopener\">BrainTree PayPal using PHP<\/a>\u00a0and\u00a0<a href=\"https:\/\/www.9lessons.info\/2011\/03\/payment-system-with-paypal.html\" target=\"_blank\" rel=\"noopener\">Payment System<\/a>\u00a0which were in most trend till day. Now, a new checkout option has been introduced by Paypal which is Paypal Express Checkout option.<\/div>\n<p>&nbsp;<\/p>\n<div class=\"cen\"><img class=\"sri650\" src=\"https:\/\/github.com\/srinivastamada\/9lessonsImages\/blob\/master\/other\/paypal\/paypal.png?raw=true\" alt=\"PayPal Express Checkout with PHP and MySQL \" \/><\/div>\n<p><a name=\"more\"><\/a><br \/>\n<a href=\"http:\/\/demos.9lessons.info\/PHP-PayPal-ExpressCheckout\/index.php\" target=\"_blank\" rel=\"noopener\"><img src=\"https:\/\/lh6.ggpht.com\/_N9kpbq3FL74\/Sd31o5XF8hI\/AAAAAAAABg0\/104nWJR7wro\/live.png\" alt=\"\" align=\"absmiddle\" border=\"0\" \/>\u00a0Live Demo<\/a><\/p>\n<div class=\"github_div\"><a href=\"https:\/\/github.com\/srinivastamada\/PHP-PayPal-ExpressCheckout.git\" target=\"_blank\" rel=\"nofollow noopener\"><b>PayPal Express Checkout with PHP and MySQL<\/b>Download this project on Github<\/a><\/div>\n<p><b>Database Design<\/b><br \/>\nTo build the user order system, you have to create three tables such as Users, Products, and Orders.<\/p>\n<div class=\"cen\"><img class=\"sri650\" src=\"https:\/\/github.com\/srinivastamada\/9lessonsImages\/blob\/master\/other\/paypal\/design.png?raw=true\" alt=\"PayPal Express Checkout with PHP Design\" \/><\/div>\n<p><b>Users<\/b><br \/>\nUser table contains all the users registration details.<\/p>\n<div class=\"code\">CREATE TABLE\u00a0users(<br \/>\nuid\u00a0int\u00a0AUTO_INCREMENT\u00a0PRIMARY KEY,<br \/>\nusername\u00a0varchar(50),<br \/>\npassword\u00a0varchar(300),<br \/>\nname\u00a0varchar(200),<br \/>\nemail\u00a0varchar(300));<\/div>\n<p><b>Products<\/b><br \/>\nThis table contains product details.<\/p>\n<div class=\"code\">CREATE TABLE\u00a0products(<br \/>\npid\u00a0int\u00a0PRIMARY KEY\u00a0AUTO_INCREMENT,<br \/>\nproduct\u00a0varchar(300),<br \/>\nproduct_img\u00a0varchar(300),<br \/>\nprice\u00a0int,<br \/>\ncurrency\u00a0varchar(10)<br \/>\n);<\/div>\n<p><b>Orders<\/b><br \/>\nThis table contains user order details.<\/p>\n<div class=\"code\">CREATE TABLE\u00a0orders(<br \/>\noid\u00a0int\u00a0PRIMARY KEY\u00a0AUTO_INCREMENT,<br \/>\nuid_fk\u00a0int,<br \/>\npid_fk\u00a0int,<br \/>\npayerID\u00a0varchar(300),<br \/>\npaymentID\u00a0varchar(300),<br \/>\ntoken\u00a0varchar(300),<br \/>\ncreated\u00a0int<br \/>\n);<\/div>\n<p><b class=\"big\">Video Tutorial<\/b><br \/>\nPayPal Express Checkout with PHP and MySQL<br \/>\n<iframe loading=\"lazy\" src=\"https:\/\/www.youtube.com\/embed\/y72wxGsBZuU\" width=\"100%\" height=\"370\" frameborder=\"0\" allowfullscreen=\"allowfullscreen\" data-mce-fragment=\"1\"><\/iframe><\/p>\n<p><b class=\"big\">Getting started with PayPal Express Checkout<\/b><\/p>\n<p><b>Create Sandbox Account<\/b><br \/>\nGo to\u00a0<a href=\"https:\/\/developer.paypal.com\/\" target=\"_blank\" rel=\"nofollow noopener\">PayPal Developer<\/a>\u00a0and create a sandbox account for development.<\/p>\n<div class=\"cen\"><img class=\"sri650\" src=\"https:\/\/github.com\/srinivastamada\/9lessonsImages\/blob\/master\/other\/paypal\/createsandbox.png?raw=true\" alt=\"Getting started with PayPal Express Checkout\" \/><\/div>\n<p>Make sure choose account type as bussiness and give some PayPal balanace number.<\/p>\n<div class=\"cen\"><img class=\"sri650\" src=\"https:\/\/github.com\/srinivastamada\/9lessonsImages\/blob\/master\/other\/paypal\/payment.png?raw=true\" alt=\"Getting started with PayPal Express Checkout\" \/><\/div>\n<p><b>Create REST API Application<\/b><br \/>\nNow go to\u00a0<a href=\"https:\/\/developer.paypal.com\/developer\/applications\/\" target=\"_blank\" rel=\"nofollow noopener\">PayPal dashboard<\/a>\u00a0and scroll down, you will find a REST API apps and click on create app button.<\/p>\n<div class=\"cen\"><img class=\"sri650\" src=\"https:\/\/github.com\/srinivastamada\/9lessonsImages\/blob\/master\/other\/paypal\/startapp.png?raw=true\" alt=\"Getting started with PayPal Express Checkout\" \/><\/div>\n<p>Give your application name and choose your sandbox account. This only works with\u00a0<i>PayPal business accounts<\/i>.<\/p>\n<div class=\"cen\"><img class=\"sri650\" src=\"https:\/\/github.com\/srinivastamada\/9lessonsImages\/blob\/master\/other\/paypal\/createApp.png?raw=true\" alt=\"Getting started with PayPal Express Checkout\" \/><\/div>\n<p><b>Application Credentials<\/b><br \/>\nHere you will find both Sandbox and Live Client ID and Secret values.<\/p>\n<div class=\"cen\"><img class=\"sri650\" src=\"https:\/\/github.com\/srinivastamada\/9lessonsImages\/blob\/master\/other\/paypal\/appID.png?raw=true\" alt=\"Getting started with PayPal Express Checkout\" \/><\/div>\n<p><b class=\"big\">PHP Development<\/b><br \/>\nProject structure.<\/p>\n<div class=\"cen\"><img class=\"sri650\" src=\"https:\/\/github.com\/srinivastamada\/9lessonsImages\/blob\/master\/other\/paypal\/files.png?raw=true\" alt=\"Getting started with PayPal Express Checkout\" \/><\/div>\n<p><b>config.php<\/b><br \/>\nDatabase and PayPal checkout API configuration file. Here you have to modify PayPal credentials for Sandbox and Live. Function\u00a0<i>getDB()<\/i>\u00a0help you to create a PDO connection with MySQL database.<\/p>\n<div class=\"code\"><b>&lt;?php<\/b><br \/>\n\/\/ob_start();<br \/>\nerror_reporting(0);<br \/>\nsession_start();<\/p>\n<p>\/* DATABASE CONFIGURATION *\/<br \/>\ndefine(&#8216;DB_SERVER&#8217;, &#8216;localhost&#8217;);<br \/>\ndefine(&#8216;DB_USERNAME&#8217;, &#8216;username&#8217;);<br \/>\ndefine(&#8216;DB_DATABASE&#8217;, &#8216;database_name&#8217;);<br \/>\ndefine(&#8216;DB_PASSWORD&#8217;, &#8216;password&#8217;);<br \/>\ndefine(&#8220;BASE_URL&#8221;, &#8220;http:\/\/localhost\/PHP-PayPal-ExpressCheckout\/&#8221;);<br \/>\ndefine(&#8216;PRO_PayPal&#8217;, 0);\u00a0\/\/ PayPal live change 0 to 1<\/p>\n<p>if(PRO_PayPal){<br \/>\ndefine(&#8220;PayPal_CLIENT_ID&#8221;, &#8220;##Your Production\/Live Client ID##&#8221;);<br \/>\ndefine(&#8220;PayPal_SECRET&#8221;, &#8220;##Your Production\/Live Secret\u00a0ID##&#8221;);<br \/>\ndefine(&#8220;PayPal_BASE_URL&#8221;, &#8220;https:\/\/api.paypal.com\/v1\/&#8221;);<br \/>\n}<br \/>\nelse{<br \/>\ndefine(&#8220;PayPal_CLIENT_ID&#8221;, &#8220;##Your Sandbox Client ID##&#8221;);<br \/>\ndefine(&#8220;PayPal_SECRET&#8221;, &#8220;##Your Sandbox Secret ID##&#8221;);<br \/>\ndefine(&#8220;PayPal_BASE_URL&#8221;, &#8220;https:\/\/api.sandbox.paypal.com\/v1\/&#8221;);<br \/>\n}<\/p>\n<p><b>function<\/b>\u00a0getDB()<br \/>\n{<br \/>\n$dbhost=DB_SERVER;<br \/>\n$dbuser=DB_USERNAME;<br \/>\n$dbpass=DB_PASSWORD;<br \/>\n$dbname=DB_DATABASE;<br \/>\n$dbConnection = new\u00a0PDO(&#8220;mysql:host=$dbhost;dbname=$dbname&#8221;, $dbuser, $dbpass);<br \/>\n$dbConnection-&gt;exec(&#8220;set names utf8&#8221;);<br \/>\n$dbConnection-&gt;setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);<br \/>\nreturn\u00a0$dbConnection;<br \/>\n}<br \/>\n?&gt;<\/div>\n<p><b>paypalExpress.php<\/b><br \/>\nPHP class for all the project operations like user login, getting product details, PayPal backend check etc.<\/p>\n<div class=\"code\"><b>&lt;?php<\/b><br \/>\nclass\u00a0paypalExpress<br \/>\n{<br \/>\npublic\u00a0<b>function<\/b>\u00a0userLogin($username,$password)<br \/>\n{<\/p>\n<p>$db =\u00a0getDB();<br \/>\n$hash_password= hash(&#8216;sha256&#8217;, $password);<br \/>\n$stmt = $db-&gt;prepare(&#8220;SELECT uid FROM users WHERE \u00a0username=:username and password=:hash_password&#8221;);<br \/>\n$stmt-&gt;bindParam(&#8220;username&#8221;, $username,\u00a0PDO::PARAM_STR) ;<br \/>\n$stmt-&gt;bindParam(&#8220;hash_password&#8221;, $hash_password,\u00a0PDO::PARAM_STR) ;<br \/>\n$stmt-&gt;execute();<br \/>\n$db = null;<\/p>\n<p>if($stmt-&gt;rowCount()==1)<br \/>\n{<br \/>\n$data = $stmt-&gt;fetch(PDO::FETCH_OBJ);<br \/>\n$_SESSION[&#8216;session_uid&#8217;] = $data-&gt;uid;<br \/>\nreturn\u00a0$data-&gt;uid;<br \/>\n}<br \/>\nelse<br \/>\n{<br \/>\nreturn\u00a0false;<br \/>\n}<br \/>\n}<\/p>\n<p>\/\/ Other functions<br \/>\n}<br \/>\n?&gt;<\/p><\/div>\n<p><b>index.php<\/b><br \/>\nHere index is a user login page. Using $paypalExpress-&gt;userLogin() function, verifing the user login details.<\/p>\n<div class=\"code\"><b>&lt;?php<\/b><br \/>\nrequire\u00a0&#8216;config.php&#8217;;<br \/>\nrequire\u00a0&#8216;class\/paypalExpress.php&#8217;;<\/p>\n<p>$errorMsgLogin =&#8221;;<br \/>\nif (!empty($_POST[&#8216;loginSubmit&#8217;]))<br \/>\n{<br \/>\n$usernameEmail=$_POST[&#8216;username&#8217;];<br \/>\n$password=$_POST[&#8216;password&#8217;];<br \/>\nif(strlen(trim($usernameEmail))&gt;1\u00a0&amp;&amp;\u00a0strlen(trim($password))&gt;1 )<br \/>\n{<br \/>\n$paypalExpress =\u00a0new\u00a0paypalExpress();<br \/>\n$uid=$paypalExpress-&gt;userLogin($usernameEmail,$password);<br \/>\nif($uid)<br \/>\n{<br \/>\nheader(&#8220;Location:home.php&#8221;);\u00a0\/\/ Page redirecting to home.php<br \/>\n}<br \/>\nelse<br \/>\n{<br \/>\n$errorMsgLogin=&#8221;Please check login details.&#8221;;<br \/>\n}<br \/>\n}<br \/>\n}<br \/>\n?&gt;<br \/>\n&lt;form action=&#8221;&#8221; method=&#8221;post&#8221;&gt;<br \/>\n&lt;label&gt;Username&lt;\/label&gt;<br \/>\n&lt;input type=&#8221;text&#8221; value=&#8221;&#8221; name=&#8221;username&#8221; class=&#8221;input&#8221; \/&gt;<br \/>\n&lt;label&gt;Password&lt;\/label&gt;<br \/>\n&lt;input type=&#8221;password&#8221; value=&#8221;&#8221; name=&#8221;password&#8221; \u00a0class=&#8221;input&#8221; \/&gt;<br \/>\n&lt;div&gt;<br \/>\n&lt;input type=&#8221;submit&#8221; value=&#8221; Log In&#8221; name=&#8221;loginSubmit&#8221; \/&gt;<br \/>\n&lt;\/div&gt;<br \/>\n&lt;div&gt;\u00a0&lt;?php\u00a0echo\u00a0$errorMsgLogin\u00a0?&gt;&lt;\/div&gt;<br \/>\n&lt;\/form&gt;<\/p><\/div>\n<p><b>home.php<\/b><br \/>\nDisplaying all of the product details. Clicking on order button this will redirect to checkout page for actual payment process.<\/p>\n<div class=\"code\"><b>&lt;?php<\/b><br \/>\nrequire\u00a0&#8216;config.php&#8217;;<br \/>\nrequire\u00a0&#8216;session.php&#8217;;<br \/>\nrequire\u00a0&#8216;class\/paypalExpress.php&#8217;;<br \/>\n$paypalExpress =\u00a0new\u00a0paypalExpress();<br \/>\n$getAllProducts = $paypalExpress-&gt;getAllProducts();<br \/>\n<b>?&gt;<\/b><br \/>\n\/\/Logout link<br \/>\n&lt;a href=&#8221;logout.php&#8221; class=&#8221;logout&#8221;&gt;Logout&lt;\/a&gt;<br \/>\n&lt;table&gt;<br \/>\n<b>&lt;?php<\/b>\u00a0foreach($getAllProducts as $product){\u00a0<b>?&gt;<\/b><br \/>\n&lt;tr&gt;<br \/>\n&lt;td &gt;<br \/>\n&lt;img src=&#8221;img\/<b>&lt;?php<\/b>\u00a0echo\u00a0$product-&gt;product_img;\u00a0<b>?&gt;<\/b>&#8221; \/&gt;<br \/>\n&lt;\/td&gt;<br \/>\n&lt;td&gt;$<b>&lt;?php<\/b>\u00a0echo\u00a0$product-&gt;price;\u00a0<b>?&gt;<\/b>&lt;\/td&gt;<br \/>\n&lt;td &gt;<br \/>\n&lt;a href=&#8221;<b>&lt;?php<\/b>\u00a0echo\u00a0BASE_URL.&#8217;checkout.php?pid=&#8217;.$product-&gt;pid; ?&gt;&#8221; class=&#8221;wallButton&#8221;&gt;Order&lt;\/a&gt;&lt;\/td&gt;<br \/>\n&lt;\/tr&gt;<br \/>\n<b>\u00a0&lt;?php<\/b>\u00a0}\u00a0<b>?&gt;<\/b><br \/>\n&lt;\/table&gt;<\/div>\n<p><b>getProducts\u00a0<\/b><br \/>\nGetting all of the products.<\/p>\n<div class=\"code\">public\u00a0function\u00a0getAllProducts()<br \/>\n{<br \/>\n$db =\u00a0getDB();<br \/>\n$stmt = $db-&gt;prepare(&#8220;SELECT * FROM products&#8221;);<br \/>\n$stmt-&gt;bindParam(&#8220;pid&#8221;, $pid, PDO::PARAM_INT) ;<br \/>\n$stmt-&gt;execute();<br \/>\n$data = $stmt-&gt;fetchAll(PDO::FETCH_OBJ);<br \/>\n$db=null;<br \/>\nreturn\u00a0$data;<br \/>\n}<\/div>\n<p><b>checkout.php<\/b><br \/>\nProduct information displaying here based on the product id. Here\u00a0<i>paypalButton.php<\/i>file contains PayPal express API JavaScript client code.<\/p>\n<div class=\"code\"><b>&lt;?php<\/b><br \/>\nrequire\u00a0&#8216;config.php&#8217;;<br \/>\nrequire\u00a0&#8216;session.php&#8217;;<br \/>\nrequire\u00a0&#8216;class\/paypalExpress.php&#8217;;<br \/>\nif(!empty($_GET[&#8216;pid&#8217;]) &amp;&amp;\u00a0$_GET[&#8216;pid&#8217;]&gt;0){<br \/>\n$paypalExpress =\u00a0new\u00a0paypalExpress();<br \/>\n$product = $paypalExpress-&gt;getProduct($_GET[&#8216;pid&#8217;]);<br \/>\n}<br \/>\nelse{<br \/>\nheader(&#8220;Location:home.php&#8221;);<br \/>\n}<br \/>\n?&gt;<br \/>\n&lt;table&gt;<br \/>\n&lt;tr&gt;<br \/>\n&lt;td &gt;<br \/>\n&lt;img src=&#8221;img\/<b>&lt;?php<\/b>\u00a0echo\u00a0$product-&gt;product_img; ?&gt;&#8221; \/&gt;<br \/>\n&lt;\/td&gt;<br \/>\n&lt;td &gt;$<b>&lt;?php<\/b>\u00a0echo\u00a0$product-&gt;price; ?&gt; &lt;\/td&gt;<br \/>\n&lt;td width=&#8221;20%&#8221;&gt;<br \/>\n<b>&lt;?php<\/b>\u00a0require\u00a0&#8216;paypalButton.php&#8217;; ?&gt;<br \/>\n&lt;\/td&gt;<br \/>\n&lt;\/tr&gt;<br \/>\n&lt;\/table&gt;<\/div>\n<p><b>paypalButton.php<\/b><br \/>\nDynamicly changing the product price details with PHP defined configuration values. You can control this file from config.php, like to swithing between Sandbox and Live. Once payment is successful, this will send payment information to the process.php file for cross checking.<\/p>\n<div class=\"code\">&lt;div id=&#8221;paypal-button-container&#8221;&gt;&lt;\/div&gt;<br \/>\n&lt;script src=&#8221;https:\/\/www.paypalobjects.com\/api\/checkout.js&#8221;&gt;&lt;\/script&gt;<br \/>\n&lt;script&gt;<br \/>\npaypal.Button.render({<br \/>\n<b>&lt;?php<\/b>\u00a0if(PRO_PayPal) { ?&gt;<br \/>\nenv: &#8216;production&#8217;,<br \/>\n<b>&lt;?php<\/b>\u00a0} else {?&gt;<br \/>\nenv: &#8216;sandbox&#8217;,<br \/>\n<b>&lt;?php<\/b>\u00a0} ?&gt;<\/p>\n<p>client: {<br \/>\nsandbox: \u00a0 \u00a0&#8216;<b>&lt;?php<\/b>\u00a0echo\u00a0PayPal_CLIENT_ID;\u00a0<b>?&gt;<\/b>&#8216;,<br \/>\nproduction: &#8216;<b>&lt;?php<\/b>\u00a0echo\u00a0PayPal_CLIENT_ID;\u00a0<b>?&gt;<\/b>&#8216;<br \/>\n},<\/p>\n<p>\/\/ Show the buyer a &#8216;Pay Now&#8217; button in the checkout flow<br \/>\ncommit: true,<\/p>\n<p>\/\/ payment() is called when the button is clicked<br \/>\npayment: function(data, actions) {<\/p>\n<p>\/\/ Make a call to the REST api to create the payment<br \/>\nreturn actions.payment.create({<br \/>\npayment: {<br \/>\ntransactions: [<br \/>\n{<br \/>\namount: {<br \/>\ntotal: &#8216;<b>&lt;?php<\/b>\u00a0echo\u00a0$product-&gt;price\u00a0<b>?&gt;<\/b>&#8216;,<br \/>\ncurrency: &#8216;<b>&lt;?php<\/b>\u00a0echo\u00a0$product-&gt;currency\u00a0?&gt;&#8217;<br \/>\n}<br \/>\n} ]<br \/>\n}<br \/>\n});<br \/>\n},<\/p>\n<p>\/\/ onAuthorize() is called when the buyer approves the payment<br \/>\nonAuthorize:\u00a0<b>function<\/b>(data, actions) {<br \/>\n\/\/ Make a call to the REST api to execute the payment<br \/>\nreturn actions.payment.execute().then(function() {<br \/>\nconsole.log(&#8216;Payment Complete!&#8217;);<\/p>\n<p>window.location = &#8220;<b>&lt;?php<\/b>\u00a0echo BASE_URL ?&gt;process.php?paymentID=&#8221;+data.paymentID+&#8221;&amp;payerID=&#8221;+data.payerID+&#8221;&amp;token=&#8221;+data.paymentToken+&#8221;&amp;pid=<b>&lt;?php<\/b>\u00a0echo $product-&gt;pid \u00a0?&gt;&#8221;;<\/p>\n<p>});<br \/>\n}<br \/>\n}, &#8216;#paypal-button-container&#8217;);<br \/>\n&lt;\/script&gt;<\/p><\/div>\n<p><b>process.php<\/b><br \/>\nHere is the most important process happen to create an user order.<\/p>\n<div class=\"code\"><b>&lt;?php<\/b><br \/>\nrequire\u00a0&#8216;config.php&#8217;;<br \/>\nrequire\u00a0&#8216;session.php&#8217;;<br \/>\nrequire\u00a0&#8216;class\/paypalExpress.php&#8217;;<br \/>\nif(!empty($_GET[&#8216;paymentID&#8217;])\u00a0&amp;&amp;!empty($_GET[&#8216;payerID&#8217;])\u00a0&amp;&amp;\u00a0!empty($_GET[&#8216;token&#8217;])\u00a0&amp;&amp;\u00a0!empty($_GET[&#8216;pid&#8217;]) ){<br \/>\n$paypalExpress =\u00a0new\u00a0paypalExpress();<br \/>\n$paymentID =\u00a0$_GET[&#8216;paymentID&#8217;];<br \/>\n$payerID =\u00a0$_GET[&#8216;payerID&#8217;];<br \/>\n$token =\u00a0$_GET[&#8216;token&#8217;];<br \/>\n$pid =\u00a0$_GET[&#8216;pid&#8217;];<\/p>\n<p>$paypalCheck=$paypalExpress-&gt;paypalCheck($paymentID, $pid, $payerID, $token);<br \/>\nif($paypalCheck){<br \/>\nheader(&#8216;Location:orders.php&#8217;);\u00a0\/\/ Success redirect to orders<br \/>\n}<br \/>\n}<br \/>\nelse{<br \/>\nheader(&#8216;Location:home.php&#8217;);\u00a0\/\/ Fail<br \/>\n}<br \/>\n?&gt;<\/p><\/div>\n<p><b>paypalCheck function<\/b><br \/>\nThis contains a PHP curl functionality and in backend this will communicate with PayPal API for order cofirmation. Here it again cross verifies with package price and currency to avoid any bad payments.<\/p>\n<div class=\"code\"><b>&lt;?php<\/b><br \/>\npublic\u00a0<b>function<\/b>\u00a0paypalCheck($paymentID, $pid, $payerID, $paymentToken){<\/p>\n<p>$ch =\u00a0curl_init();<br \/>\n$clientId = PayPal_CLIENT_ID;<br \/>\n$secret = PayPal_SECRET;<br \/>\ncurl_setopt($ch,\u00a0CURLOPT_URL, PayPal_BASE_URL.&#8217;oauth2\/token&#8217;);<br \/>\ncurl_setopt($ch,\u00a0CURLOPT_HEADER, false);<br \/>\ncurl_setopt($ch,\u00a0CURLOPT_SSL_VERIFYPEER, false);<br \/>\ncurl_setopt($ch,\u00a0CURLOPT_POST, true);<br \/>\ncurl_setopt($ch,\u00a0CURLOPT_RETURNTRANSFER, true);<br \/>\ncurl_setopt($ch,\u00a0CURLOPT_USERPWD, $clientId . &#8220;:&#8221; . $secret);<br \/>\ncurl_setopt($ch,\u00a0CURLOPT_POSTFIELDS, &#8220;grant_type=client_credentials&#8221;);<br \/>\n$result =\u00a0curl_exec($ch);<br \/>\n$accessToken = null;<\/p>\n<p>if (empty($result)){<br \/>\nreturn\u00a0false;<br \/>\n}<\/p>\n<p>else {<br \/>\n$json =\u00a0json_decode($result);<br \/>\n$accessToken = $json-&gt;access_token;<br \/>\n$curl =\u00a0curl_init(PayPal_BASE_URL.&#8217;payments\/payment\/&#8217; . $paymentID);<br \/>\ncurl_setopt($curl,\u00a0CURLOPT_POST, false);<br \/>\ncurl_setopt($curl,\u00a0CURLOPT_SSL_VERIFYPEER, false);<br \/>\ncurl_setopt($curl,\u00a0CURLOPT_HEADER, false);<br \/>\ncurl_setopt($curl,\u00a0CURLOPT_RETURNTRANSFER, true);<br \/>\ncurl_setopt($curl,\u00a0CURLOPT_HTTPHEADER, array(<br \/>\n&#8216;Authorization: Bearer\u00a0&#8216; . $accessToken,<br \/>\n&#8216;Accept: application\/json&#8217;,<br \/>\n&#8216;Content-Type: application\/xml&#8217;<br \/>\n));<br \/>\n$response =\u00a0curl_exec($curl);<br \/>\n$result =\u00a0json_decode($response);<\/p>\n<p>$state = $result-&gt;state;<br \/>\n$total = $result-&gt;transactions[0]-&gt;amount-&gt;total;<br \/>\n$currency = $result-&gt;transactions[0]-&gt;amount-&gt;currency;<br \/>\n$subtotal = $result-&gt;transactions[0]-&gt;amount-&gt;details-&gt;subtotal;<br \/>\n$recipient_name = $result-&gt;transactions[0]-&gt;item_list-&gt;shipping_address-&gt;recipient_name;<br \/>\ncurl_close($ch);<br \/>\ncurl_close($curl);<\/p>\n<p>$product = $this-&gt;getProduct($pid);<\/p>\n<p>if($state == &#8216;approved&#8217;\u00a0&amp;&amp;\u00a0$currency == $product-&gt;currency\u00a0&amp;&amp;\u00a0$product-&gt;price == \u00a0$subtotal){<br \/>\n$this-&gt;updateOrder($pid, $payerID, $paymentID, $paymentToken);<br \/>\nreturn\u00a0true;<\/p>\n<p>}<br \/>\nelse{<\/p>\n<p>return\u00a0false;<br \/>\n}<\/p>\n<p>}<\/p>\n<p>}<br \/>\n<b>?&gt;<\/b><\/div>\n<p><b>orders.php<\/b><br \/>\nDisplaying all of the orders based on user session id.<\/p>\n<div class=\"code\"><b>&lt;?php<\/b><br \/>\nrequire\u00a0&#8216;config.php&#8217;;<br \/>\nrequire\u00a0&#8216;session.php&#8217;;<br \/>\nrequire\u00a0&#8216;class\/paypalExpress.php&#8217;;<br \/>\n$paypalExpress =\u00a0new\u00a0paypalExpress();<br \/>\n$orders = $paypalExpress-&gt;orders();<br \/>\n?&gt;<br \/>\n<b>&lt;?php<\/b>\u00a0if($orders) { ?&gt;<br \/>\n&lt;table&gt;<br \/>\n<b>&lt;?php<\/b>\u00a0foreach($orders\u00a0as\u00a0$order){ \u00a0?&gt;<br \/>\n&lt;tr&gt;<br \/>\n&lt;td&gt;ORDER &#8211;\u00a0&lt;?php\u00a0echo\u00a0$order-&gt;oid;\u00a0?&gt;&lt;\/td&gt;<br \/>\n&lt;td&gt;&lt;?php\u00a0echo\u00a0$order-&gt;product;\u00a0?&gt;&lt;\/td&gt;<br \/>\n&lt;td&gt;&lt;?php\u00a0echo\u00a0$order-&gt;price.&#8217; &#8216;.$order-&gt;currency;\u00a0?&gt;&lt;\/td&gt;<br \/>\n&lt;td&gt;&lt;?php\u00a0echo\u00a0$paypalExpress-&gt;timeFormat($order-&gt;created);\u00a0?&gt;&lt;\/td&gt;<br \/>\n&lt;\/tr&gt;<br \/>\n<b>&lt;?php<\/b>\u00a0}\u00a0<b>?&gt;<\/b><br \/>\n&lt;\/table&gt;<br \/>\n<b>&lt;?php<\/b>\u00a0} \u00a0else {\u00a0<b>?&gt;<\/b><br \/>\n&lt;div&gt; No Orders&lt;\/div&gt;<br \/>\n<b>&lt;?php<\/b>\u00a0}\u00a0<b>?&gt;<\/b><\/div>\n<p><b>logout.php<\/b><br \/>\nClearing user session.<\/p>\n<div class=\"code\"><b>&lt;?php<\/b><br \/>\n$_SESSION[&#8216;session_uid&#8217;] = &#8221;;<br \/>\n$sesson_uid = &#8221;;<br \/>\nsession_destroy();<br \/>\nif(empty($_SESSION[&#8216;session_uid&#8217;]) &amp;&amp; \u00a0empty($sesson_uid)){<br \/>\nheader(&#8216;Location:index.php&#8217;);<br \/>\n}<br \/>\n?&gt;<\/div>\n<p><b>sessions.php<\/b><br \/>\nCommon session code, you have to include this in all of the pages. If the user session is not found, this will redirect to index\/login page.<\/p>\n<div class=\"code\"><b>&lt;?php<\/b><br \/>\n$sesson_uid = &#8221;;<br \/>\nif(!empty($_SESSION[&#8216;session_uid&#8217;]\u00a0)){<br \/>\n$sesson_uid =\u00a0$_SESSION[&#8216;session_uid&#8217;]\u00a0;<br \/>\n}<br \/>\nelse{<br \/>\nheader(&#8216;Location:index.php&#8217;);<br \/>\n}<br \/>\n?&gt;<\/div>\n<p>Express Checkout gives your buyers a simplified checkout experience that keeps them local to your website or mobile app throughout the payment authorization process and lets them use their PayPal balance, bank account or credit card to pay without sharing or entering any sensitive information on your site. An order is stored immediately after payment is completed and this happens while the customer is actively engaged on your website. When payment is complete, the customer is redirected to your website, but your website is immediately informed by PayPal whether the transaction was successful or not. The Express Checkout flow keeps the buyer on your web page or mobile app throughout the entire checkout flow. All this process makes the buyer details more secured and also the process is fast. Hope you all like to integrate this PayPal Express Checkout process in your website and provide a good feel for the buyers to buy on the website.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Most of the people prefer to shop online which made eCommerce to grow rapidly. But, what makes an excellent eCommerce site for the customers? The answer is &#8211; an excellent checkout process. There are several different payment options available in the market today. Out of all, Paypal is the most popular and convenient way to [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":4680,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_bbp_topic_count":0,"_bbp_reply_count":0,"_bbp_total_topic_count":0,"_bbp_total_reply_count":0,"_bbp_voice_count":0,"_bbp_anonymous_reply_count":0,"_bbp_topic_count_hidden":0,"_bbp_reply_count_hidden":0,"_bbp_forum_subforum_count":0},"categories":[30],"tags":[51],"_links":{"self":[{"href":"https:\/\/a1webdesignteam.com\/blog\/wp-json\/wp\/v2\/posts\/4679"}],"collection":[{"href":"https:\/\/a1webdesignteam.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/a1webdesignteam.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/a1webdesignteam.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/a1webdesignteam.com\/blog\/wp-json\/wp\/v2\/comments?post=4679"}],"version-history":[{"count":0,"href":"https:\/\/a1webdesignteam.com\/blog\/wp-json\/wp\/v2\/posts\/4679\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/a1webdesignteam.com\/blog\/wp-json\/wp\/v2\/media\/4680"}],"wp:attachment":[{"href":"https:\/\/a1webdesignteam.com\/blog\/wp-json\/wp\/v2\/media?parent=4679"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/a1webdesignteam.com\/blog\/wp-json\/wp\/v2\/categories?post=4679"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/a1webdesignteam.com\/blog\/wp-json\/wp\/v2\/tags?post=4679"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}