Powered By

Create a New ZenCart Payment Module with Sample Module Source Code


1. Introduction:

There are several payment modules in zen cart. You can find them under Admin > Modules > Payment in the admin panel. Many of them are for payment gateways where the customer's credit card is authorized automatically while they are online, and payment is deposited to your merchant bank account (which you set up with your bank) automatically.

Zen Cart as gateways built-in for:

1. Authorize.net AIM (SIM also supported, but AIM is recommended for its security benefits)

2. PayPal Website Payments Standard (IPN)

3. PayPal Express Checkout

4. PayPal Website Payments Pro

5. LinkPoint API

6. YourPay API

as well as:

C.O.D. - Cash On Delivery.
Check/MoneyOrder

2. File Structure:

Payment modules must contain two compulsory files.

1. The payment class is stored in

includes/modules/payment/.php

2. while all text is stored in the appropriate language file

includes/languages//modules/payment/.php

3. The response from the payment server is handled by the files

_response_handler.php


You can download the source of the sample Zen-Cart Payment Module


3. Anatomy of a Payment Module:

The payment class must override some of the following pre defined functions in zencart payment module. So a payment class must contain definitions for the following classes.

Constructor Method

In the Constructor method, the modules initialization must be done. Set the class code, title, description, sort order and status of the module.

update_status Method

This method will be called whenever the status of the module in the admin panel is changed. Here the currency type and zone of the shop can be checked each time of update.

javascript_validation Method

Validate the user input submitted on checkout_payment.php with javascript (client-side). Example: validate credit card number, make sure required fields are filled in

selection Method

This method can be overridden to retrieve required information from the form before submit. Example: ask for extra fields (credit card number), display extra information

pre_confirmation_check Method

This method will be called before processing the checkout confirmation page (i.e, on calling the checkout_process.php). Here check if credit card information is right before sending the info to the payment server

confirmation Method

In this method check for the products details and payment information and execute before displaying the checkout confirmation page

process_button Method

This is the main function, which sends the needed informations to the payment server on submitting the payment form. Examples: add extra hidden fields to the form that are required by the server as POST to perform the transaction.

before_process Method

This method will be executed before processing the order. Check all the parameters before forwarding to checkout confirm page. Examples: retrieve result from online payment services

after_process Method

After processing, the confirmation of checkout this method will be called.

after_order_create Method

This is the last step in processing the check out. Here the orders are taken and the items in the cart are removed to customer purchase table and the products table is updated and successful shopping mail is send to the customer and the store owner.

get_error Method

If an error occurs with the process, output error messages here

check Method

This method is called every time this module is accessed, to check whether the module is in active state.

install Method

If the ‘check method’ returns, status of the module as removed or uninstalled. A install button will be displayed in the admin panel. On clicking on the install() button this install method will be called. The zen cart configuration table will be updated with the information such as module code, title, description and other required parameters of the module.

remove Method

After installing the module, remove button will be displayed on top of the module in admin panel. On clicking on that remove button the rows related to this modules in the zen-cart configuration table will be removed.

Related Posts by Categories