Saturday, December 08 2018

Paypal Express Checkout Integration in PHP

In this article we have explained about How to integrate PayPal express checkout in PHP. PayPal Express Checkout payment gateway is the easiest way to integrate in PHP.  There are two ways to integrate PayPal checkout payment gateway, Client side and server side integrations.


In server side integration means we have to use PayPal API to create and execute payment via API calls. In client side integration means PayPal provides javascript codes we have to update our credentials key, amount and product details. Once form submitted our data is processing to paypal server and returns the data to our success page.

See our demo video on Youtube

Create PayPal Sandbox Account

  • Log in using your PayPal account and If you don’t have any PayPal account then create an account.
  • Go to the PayPal Developer Portal and create an sandbox account for testing purpose.


  • Click Create Account button and fill up the required details.


Create REST API App

  • In the My Apps & Credentials page, scroll down to REST API apps section. Click the Create App to create an application to get REST API credentials


  • Give your app name and select account that related to your business
  • Client ID and secret ID will be generated. Copy these API credentials for use in the script.

Client Side Integration

Copy the below code and paste in your file as “checkout.php”

<div id="paypal-button"></div>
<script src=""></script>
    // Configure environment
    env: 'sandbox',
    client: {
      sandbox: 'demo_sandbox_client_id',
      production: 'demo_production_client_id'
    // Customize button (optional)
    locale: 'en_US',
    style: {
      size: 'small',
      color: 'gold',
      shape: 'pill',

    // Enable Pay Now checkout flow (optional)
    commit: true,

    // Set up a payment
    payment: function(data, actions) {
      return actions.payment.create({
        transactions: [{
          amount: {
            total: '0.01',
            currency: 'USD'
    // Execute the payment
    onAuthorize: function(data, actions) {
      return actions.payment.execute().then(function() {
        // Show a confirmation message to the buyer
        //alert('Thank you for your purchase!');
  }, '#paypal-button');


HTML code

<form name="sucess_form" id="sucess_form" method="POST" action="success.php">
<input type="hidden" name="hid_payment_id" id="hid_payment_id">
<input type="hidden" name="hid_token" id="hid_token">
<input type="hidden" name="hid_payer_id" id="hid_payer_id">

Once payment has been successfully done and response will sent to success.php file. In this file we have to store the payment id and transaction id in the transaction history table.

Thanks for reading this article. If you have any queries and comment in the below.

Share Your Thoughts

Inline Feedbacks
View all comments
Subscribe Our Channel

Email Subscription
Watch Tutorials
Copyright © 2015 - 2021 PHPEXPERTISE.COM