Implementing a new payment gateway in Media Mall

Here is how to implement a PayPal-like payment gateway.

The workflow for a payment gateway like this is:

  • an order is created
  • an html form is being displayed to the user so that it can be submitted to the gateway's site
  • a notification from the payment gateway is being returned and parsed

To implement your own payment gateway (let's call it NewGateway), create in folder [Joomla dir]/administrator/components/com_mediamallfactory/payment/gateways the following directories and files:

  • NewGateway (this is the folder that will house all of the gateways's files)
  • templates/default.php (the template that will contain the html form displayed to the user)
  • newgateway.php (the php file that will contain the gateways' logic)
  • newgateway.xml (settings file for the gateway)

In order to fully understand how to implement a new gateway, please check the code for the gateways that are already implemented.

The template

In the template file you can use the $this→getOrder('variable_name') to get information regarding the order like:

  • title
  • id
  • amount
  • currency
  • complete url
  • cancel url
  • notify url
  • any option that is made available using the settings file

This html form will be displayed to the user after selecting the membership he/she wants to purchase. After submitting this form, the user will be redirected to the payment's page to actually make the payment.

The settings file

Different options for the payment gateway can be configured using the settings file, which is an xml file.
The file should contain a regular and valid Joomla form.

The php file

It should contain only a class with the name format: FactoryPaymentGatewayNewGatewy and it should extend the FactoryPaymentGateway.

This class should contain a method named step1 that has one parameter that contains information about the membership the user wants to purchase.
Inside the method the order should be created using the $this→createOrder($data) call and then the template displayed using the $this→render() call.

To process the notification received from the payment gateway, the function processNotification() must be implemented.
This function should create a new payment notification using the $this→getNewPaymentNotification() and return it.

Depending if the payment was successful or not, you need to set the notification status and errors. If the payment has failed, the order will be marked as failed and no credits will be added to the user's account. If the payment is successful, then the credits will be added to the user's account.