Post by Qphoria » Tue Apr 19, 2011 4:02 am

Payment extensions can be created by cloning an existing one that does something similar to what you want.

There are generally 2 types of payment extension methods:
  1. Gateway Hosted (aka: Redirect, offsite, SIM, Simple). This means the customer is redirected to the secure payment gateway site to enter their payment details, then returned back to your store's success page.
    Examples of payments that use this method: Paypal, PayPoint, FirstData Connect, Moneybookers
  2. Merchant Hosted (aka: API, XML, onsite, AIM, Advanced). This means you collect credit card details directly on your site and the customer never leaves your site. This requires you to have your own SSL certificate.
    Examples of payments that use this method: Authorize.net AIM, Paypal Pro, SagePay Direct
The method you choose must be supported by the gateway you are integrating with.

After deciding what method you want, choose one of the example payment extensions listed above as your basis. For this example I will use the Paypal Pro files as my basis for a new extension called "My Pay". Regardless of the fact that Paypal Pro uses the "Merchant Hosted" method, the process of getting the files ready is the same. Only the internal code of the catalog controller file really changes for the method.

1. Clone the Files
Payment extensions in their MVC layout have a minimum of 7 files:

Code: Select all

catalog/controller/payment/pp_pro.php
catalog/model/payment/pp_pro.php
catalog/language/english/payment/pp_pro.php
catalog/view/theme/default/template/payment/pp_pro.tpl
admin/controller/payment/pp_pro.php
admin/language/english/payment/pp_pro.php
admin/view/template/payment/pp_pro.tpl
Copy all the pp_pro files and name the new ones "my_pay".
Be sure to use the correct extension (php or tpl) where appropriate.
Also, be sure you have follow the same folder structure.
** ALWAYS USE "default" THEME FOR PAYMENT TPL FILES **

2. Global Replaces:
In most cases, you can usually use a good editor like notepad++ to do a "Replace in Files" and simply run that twice for lower and uppercase wording separately:
- replace the word "pp_pro" with "my_pay"
- replace the word "PPPro" with "MyPay"
The upper case only applies to the main class extends (e.g. ControllerPaymentPPPro). In some cases where there are underscores in the main name, like "pp_pro", note that the uppercase version will NOT likely have the underscore. e.g. replace "pp_pro" with "my_pay" but replace "PPPro" with "MyPay"

3. Setup the Admin side
I always start on the admin side first...
- Setup the username/password/secret keys etc fields that the extension will need to access the API
- Setup any special settings for things like transaction type, test/production mode, etc
The admin/controller/payment/my_pay.php file handles all the form and variable control.
The admin/language/english/payment/my_pay.php file shows the text values for the different fields. You can clone and translate this file for any language.
The admin/view/template/payment/my_pay.tpl file is the html file that shows the actual form for configuring the extension settings. These all work together to form the page. You should be able to follow the existing pp_pro code and modify only parts of it to make it work for my_pay

4. Setup the Catalog side
After the admin is setup and working, it is easier to test as you code on the catalog side.
The catalog/language/english/payment/my_pay.php file will have the special error scenarios and the title of the
shipping extension as you want to show it in which ever languages you support.
The catalog/model/payment/my_pay.php file will have checks for geozone and any other special cases you want to add like subtotal must be a certain amount or the store must have a certain currency installed. Usually this is almost never changed and using the existing clone with just the replacing of the name is all that is needed in this file.
The catalog/controller/payment/my_pay.php file is for all the code logic. Use your payment gateway's API document to set up what you need for the extension here. It will of course require you know some advanced php at this point.

That's it. Step 4 is where most of the work gets done, but with the first 3 steps done, it makes it easier to test as you go.

If you have other advice to make this tutorial clearer and easier to understand, or if you think I missed a step, please PM me with tips.

Image
Donate!|OpenCart Basics|GeoZones
Image


User avatar
Administrator

Posts

Joined
Tue Jul 22, 2008 3:02 am

Post by alexmath » Sat Oct 28, 2017 6:20 am

Thanks for the tutorial. I have been trying to follow this for a while but not successful so far hence a few questions:
1. I am not sure for what version this was intended but currently OC 3x, there are some significant changes in the file structure. Anyway, will putting the files in their corresponding places suffice or do i need to create extra files?
2. Assuming I want to create an extension to handle just credit/debit cards and only deal with the banks involved; is that possible? What's the minimum amount of data/requirements I need for that. To which of the two gateway types you have mentioned above does this belong? Thank you.

New member

Posts

Joined
Sat Sep 23, 2017 7:35 am

Post by IP_CAM » Sun Oct 29, 2017 1:09 am

It would probably be much simpler, to just download some
free extensions on this, and check on how they are made to work:
https://www.opencart.com/index.php?rout ... load_id=55
Just an idea! ;)
Ernie

For Sale: Top URL's, including OpenCart V-Pro installed, like seen here:
http://www.bigmax.ch - http://www.ipcam.li - http://www.opencart.li
For Information + URL's offered, please contact me at: jti@jacob.ch
I am NOT available for Custom Support in existing OC Installations!
My Github Repositories: https://github.com/IP-CAM
Image


User avatar
Guru Member

Posts

Joined
Tue Mar 04, 2014 1:37 am
Location - Switzerland
Who is online

Users browsing this forum: No registered users and 2 guests