PayPal Express Checkout Payment Gateway Integration with Codeigniter

In this tutorial, We have share how to integrate PayPal Express Checkout payment gateway in Codeigniter. The tutorial covered in easy steps with live example.PayPal is a widely used payment gateway that allows you to accept payment online in the web application.Express Checkout is a fast and very easy way for buyer to pay for the product they are buying.PayPal Express Checkout payment gateway is very useful when you want to provide a user-friendly user interface to the user for the online payment.


Step 1: Create PayPal Account
First we need to create sandbox account on Sandbox account to run this demo example.

Step 2: Update PayPal Config Details
Here in this example, we will use Test App to integrate PayPal Express gateway. So we will update constants.php with KeyID and Secret Key from PayPal.

Step 3: Open file constants
Open "application/config/constants.php" file and add code like as bellow:

// TEST Paypal Express credential
define('PRO_PAYPAL', 0);
define("PAYPAL_CLIENTID", "XXXXXXXXXX");
define("PAYPAL_SECRET", "XXXXXXXXXX");
define("PAYPAL_BASE_URL", "https://api.sandbox.paypal.com/v1/");
define("PAYPAL_ENV", "sandbox");
define('CURRENCY', 'USD');
?>


Step 4: Create a Controller file PayPal Express
Create a controller file named "Paypal.php" inside "application/controllers" folder.


/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/

/**
* @package PayPal Express : CodeIgniter PayPal Express Gateway
*
* @author TechArise Team
*
* @email info@techarise.com
*
* Description of PayPal Express Controller
*/
if (!defined('BASEPATH'))
exit('No direct script access allowed');

class Paypal extends CI_Controller {
// construct
public function __construct() {
parent::__construct();
$this->load->model('Site', 'site');
}
// index page
public function index() {
$data['title'] = 'Paypal | TechArise';
$data['productInfo'] = $this->site->getProduct();
$this->load->view('paypal/index', $data);
}

// checkout page
public function checkout($id) {
$data['title'] = 'Checkout payment | TechArise';
$this->site->setProductID($id);
$data['itemInfo'] = $this->site->getProductDetails();
$data['return_url'] = site_url().'paypal/callback';
$data['surl'] = site_url().'paypal/success';;
$data['furl'] = site_url().'paypal/failed';;
$data['currency_code'] = 'INR';
$this->load->view('paypal/checkout', $data);
}

// success method
public function callback() {
$data['title'] = 'Paypal Success | TechArise';
$paymentID = $this->input->post('paymentID');
$payerID = $this->input->post('payerID');
$token = $this->input->post('token');
$pid = $this->input->post('pid');
if(!empty($paymentID) && !empty($payerID) && !empty($token) && !empty($pid) ){
$data['paymentID'] = $paymentID;
$data['payerID'] = $payerID;
$data['token'] = $token;
$data['pid'] = $pid;
$this->load->view('paypal/success', $data);

} else {
$this->load->view('paypal/failed', $data);
}
}

}
?>

Step 5: Create a view file index
Create a view file named "index.php" inside "application/views/paypal" folder


$this->load->view('templates/header');
?>


Paypal Express Checkout Integration with Codeigniter





$element) { ?>



$this->load->view('templates/footer');
?>


Step 6: Create a view file checkout
Create a view file named "checkout.php" inside "application/views/paypal" folder


$this->load->view('templates/header');
?>


Paypal Express Checkout Integration with Codeigniter




$amount = $itemInfo['price'];
$merchant_order_id = $itemInfo['product_id'];
$return_url = site_url().'paypal/callback';

?>


session->flashdata('msg'))){ ?>

session->flashdata('msg'); ?>





















































$this->load->view('templates/footer');
?>



Step 7: Open file constants
Open "application/config/routes.php" file and add code like as bellow:


// routes
$route['default_controller'] = 'paypal/index';
$route['checkout/(:any)'] = "paypal/checkout/$1";
?>


Demo  [sociallocker] Download[/sociallocker]

Komentar

Postingan Populer