Loading...

How to integrate a third party library into CodeIgniter (using Braintree Payments as an example)

BraintreeCodeIgniter is an open source rapid development web application framework, written in PHP. The project has recently been taken over by the British Columbia Institute of Technology.

There were questions in the past on how to integrate third party libraries into Codeigniter. The answer is to do the following (at least this is how I do it):
1. Create a library in the application/library folder
2. The most important thing to take note is to include the third party library in the first few lines of the application:

defined('BASEPATH') OR exit('No direct script access allowed');
include APPPATH.'third_party/[library].php';

class [library]_lib extends [original class name]{
… code extends here
}

3. Place your third party library in the third_party section in your application folder.

If you’re curious to what Braintree is, this is a payments gateway recently acquired by Paypal, and is one of the recommended payment gateways documented by Apple Pay.

A minimal running library wrapper example of this is found in Bitbucket

If you want to run this sample wrapper I made (I only made the create token wrapping function so let us use this as an example), you can simply include the folders into your application folder, then in your controller, run:

$this-load->library(“Braintree_lib”);
$token = $this->Braintree_lib->create_client_token();

 
 

4 comments
  1. clintcan

    Oops. Sorry guys, just noticed your comments (been so busy). I edited the post to include the code on how to make the wrapper to the third party library.

    If you want to run the library wrapper (I made this library skeleton, at github for example purposes), just copy the code (in src/application) to the applications folder in your codeigniter application.

    In your controller, run:
    $this->load->library(“Braintree_lib”);

    then you can run the sample function by calling:
    $this->Braintree_lib->create_client_token();

Leave a Reply

Your email address will not be published. Required fields are marked *