Integrating PayPal Gateway in Joomla

Posted on in University

PayPal is one of the most common payment gateways today and one of the major reasons why is because it can easily integrate with various Content Management Systems (CMS). Today, we will give you a guide on how you can integrate PayPal payment gateway with Joomla. The integration process itself will require you to have some working knowledge of PHP, but overall, this guide is made for programmers.


Step 1: Create Gateway Folder In Joomla

[Joomla dir]\administrator\components\com_website\payment\gateways\ folder
The folder should be in lowercase letters and should only contain letters. We will now create another folder for PayPal gateway:
[Joomla dir]\administrator\components\com_website\payment\gateways\paypal

Step 2: Create Language File

Once you have created a PayPal gateway folder, you will now have to make a language file and name it to the language abbreviation that it contains. For instance, if you want the PayPal Gateway to be in US English, simply name the folder en-US. Similarly, you can do the same for UK English by naming the folder en-GB. Here is how you can create a language file:
[Joomla dir]\administrator\components\com_ website \payment\language\en-US\en-US.paypal.ini

Step 3: Create Parameter, Payment Process, and Logo File

The PayPal gateway folder or any gateway folder in this regard, will contain a parameters file, payment process file and an option logo. Follow the same routine for the parameter file and payment process file as in step 1 and step 2. As for the logo, create a file in one of the following formats:
[Joomla dir]\administrator\components\com_ website \payment\gateways\paypal\paypal.jpg/ png/ gif

Step 4: Create Gateway Configuration Form

We will create a paypal.xml form for the online transactions. Depending on gateway, the options you add will defer accordingly. Here is an example of a Joomla XML form:

		Options Go Here

Step 5: Create Main File for Payment Processing

[Joomla dir]\administrator\components\com_ website \payment\gateways\paypal\paypal.php

class Paypal extends factoryPaymentPlugin

You have to make sure that the class name should be same on point 1, the only difference being that the class name can be in uppercase letters this time. All the payment plug-ins will be integrated with Step 1 function.

public function step1()
    // Create a new order
    if (!$this->createOrder()) {
      return false;
    // Show the confirmation form
    <p>get('order')->title); ?></p>
    <br /gt;
    <form action="getAction(); ?>" method="post">
      <input type="hidden" name="item_number"   value="get('order')->id; ?>" />
      <input type="hidden" name="os0"           value="get('order')->user_id; ?>" />
      <input type="hidden" name="amount"        value="get('order')->amount; ?>" />
      <input type="hidden" name="currency_code" value="get('order')->currency; ?>" />
      <input type="hidden" name="business"      value="getParam('email'); ?>" />
    	<input type="hidden" name="item_name"     value="get('order')->title; ?>" />
    	<input type="hidden" name="return"        value="get('url.complete'); ?>" />
    	<input type="hidden" name="cancel_return" value="get('url.cancel'); ?>" />
    	<input type="hidden" name="notify_url"    value="get('url.notification'); ?>" />
    	<input type="image" src="getButton(); ?>" name="submit" />
    return true;

We will now create an order to preview the PayPal form that will be sent to PayPal servers. We can now access:

  • the order using: $this→get(‘order’) (id, title, user_id, membership_id, price_id, amount, currency)
  • the configuration parameters using: $this→getParam(‘PARAMETER_NAME_HERE’)
  • the url Paypal uses when transactions are completed: $this→get(‘url.complete’)
  • the url Paypal uses when transactions are cancelled: $this→get(‘url.cancel’)
  • the url Paypal uses when sending IPN regarding transactions: $this→get(‘url.notification’)
  • We will now create a ‘processIpn’ function for processing IPN. The function will process the IPN while returning the payment status. There are various variable used for different payment gateways.

    public function processIpn()
        $ipn = new JRegistry(JRequest::get('POST'));
        // Preprocess ipn
        $ipn->set('user_id',   $ipn->get('option_selection1'));
        $ipn->set('amount',    $ipn->get('mc_gross'));
        $ipn->set('currency',  $ipn->get('mc_currency'));
        $ipn->set('order_id',  $ipn->get('item_number'));
        $ipn->set('refnumber', $ipn->get('txn_id'));
        // Create payment
        $payment = $this->createPayment($ipn);
        // Check for errors
        $errors = $this->validatePayment($ipn);
        switch ($ipn->get('payment_status')) {
          case 'Completed':
          case 'Processed':
            $payment->status = $errors ? 40 : 20; // 40 - Manual check; 20 - Completed
          case 'Failed':
          case 'Denied':
          case 'Canceled-Reversal':
          case 'Expired':
          case 'Voided':
          case 'Reversed':
          case 'Refunded':
            $payment->status = 30; // 30 - Failed
          case 'In-Progress':
          case 'Pending':
            $payment->status = 10; // 10 - Pending
        $errors[] = 'Received Payment Status: ' . $ipn->get('payment_status');
        $this->savePayment($payment, $errors);

    To sum it up, this function:

  • Create a $ipn variable from requests, provided that it is JRegistry
  • Creates new payment through $ipn
  • Verifies errors
  • Determines the status, for instance:
  •       10 – Pending
          20 – Completed
          30 – Failed
          40 – Manual Check

    Now that you know how to create a PayPal folder and $ipn, let’s try this on your Joomla website!

    You may also like to read