How to Create Your Own Payment Gateway For Magento


Creating your own payment gateway for Magento always starts with the configuration file. Luckily the Module Creator has done the work for you.

In this tutorial, you will learn how to create your own payment gateway for Magento. Ensure that the app/code/local is in the right path. Also, you should replace the NewModule with your own module name.

You might want to take a look at the following related articles:

Dont forget to subscribe to our RSS-feed and follow us on Twitter – for recent updates.

Microsoft PowerPoint Presentation Templates

Overview

How to Create Your Own Payment Gateway For Magento

This module will make a module that is capable of accepting credit card information, and give it authorization when an order has been submitted. This model will also save the ID used in the transaction in the payment record. If you are going to use this code make the necessary changes to the file name.

In this example make sure the app/code/local is at the include_path.

Module Declaration

Make app/etc/modules/CompanyName_NewModule.xml:

<config>
<modules>
<!-- declare CompanyName_NewModule module -->
<CompanyName_NewModule>

<!-- this is an active module -->
<active>true</active>

<!-- this module will be located in app/code/local code pool -->
<codePool>local</codePool>

<!-- specify dependencies for correct module loading order -->
<depends>
<Mage_Payment />
</depends>

</CompanyName_NewModule>
</modules>
</config>

Now the application is aware of this module.

Configuration

Make the app/code/local/CompanyName/NewModule/etc/config.xml:

<?xml version="1.0"?>
<config>

<modules>
<CompanyName_NewModule>
<!-- declare module's version information for database updates -->
<version>0.1.0</version>
</CompanyName_NewModule>
</modules>

<global>
<!-- Note: if you use your own namespace (i.e. CompanyName) you also have to declare blocks group for new module. -->

<blocks>
<newmodule>
<class>CompanyName_NewModule_Block</class>
</newmodule>
</blocks>

<!-- declare model group for new module -->
<models>
<!-- model group alias to be used in Mage::getModel('newmodule/...') -->
<newmodule>
<!-- base class name for the model group -->
<class>CompanyName_NewModule_Model</class>
</newmodule>
</models>

<!-- declare resource setup for new module -->
<resources>

<!-- resource identifier -->
<newmodule_setup>

<!-- specify that this resource is a setup resource and used for upgrades -->
<setup>
<!-- which module to look for install/upgrade files in -->
<module>CompanyName_NewModule</module>
</setup>

<!-- specify database connection for this resource -->
<connection>

<!-- do not create new connection, use predefined core setup connection -->
<use>core_setup</use>
</connection>
</newmodule_setup>
<newmodule_write>
<connection>
<use>core_write</use>
</connection>
</newmodule_write>
<newmodule_read>
<connection>
<use>core_read</use>
</connection>
</newmodule_read>
</resources>
</global>

<!-- declare default configuration values for this module -->
<default>

<!-- 'payment' configuration section (tab) -->
<payment>

<!-- 'newmodule' configuration group (fieldset) -->
<newmodule>

<!-- by default this payment method is inactive -->
<active>0</active>

<!-- model to handle logic for this payment method -->
<model>newmodule/paymentMethod</model>

<!-- order status for new orders paid by this payment method -->
<order_status>pending</order_status>

<!-- default title for payment checkout page and order view page -->
<title>Credit Card (Authorize.net)</title>

<cctypes>AE,VI,MC,DI</cctypes>
<payment_action>authorize</payment_action>
<allowspecific>0</allowspecific>
</newmodule>
</payment>
</default>
</config>

The Adapter Model

It must be emphasized that Payment Method is arbitrary and it is up to you to define the method’s name. This is very important and neglecting it might cause the code to fail.

<?php
/**
* Our test CC module adapter
*/

class CompanyName_NewModule_Model_PaymentMethod extends Mage_Payment_Model_Method_Cc
{
/**
* unique internal payment method identifier
*
* @var string [a-z0-9_]
*/
protected $_code = 'newmodule';

/**
* Here are instances of flags that will determine functionality availability
* of this module to be used by frontend and backend.
*
* @see all flags and their defaults in Mage_Payment_Model_Method_Abstract
*
* It is possible to have a custom dynamic logic by overloading
* public function can* for each flag respectively
*/

/**
* Is this payment method a gateway (online auth/charge) ?
*/
protected $_isGateway = true;

/**
* Can authorize online?
*/

protected $_canAuthorize = true;

/**
* Can capture funds online?
*/

protected $_canCapture = true;

/**
* Can capture partial amounts online?
*/

protected $_canCapturePartial = false;

/**
* Can refund online?
*/

protected $_canRefund = false;

/**
* Can void transactions online?
*/

protected $_canVoid = true;

/**
* Can use this payment method in administration panel?
*/

protected $_canUseInternal = true;

/**
* Can show this payment method as an option on checkout payment page?
*/

protected $_canUseCheckout = true;

/**
* Is this payment method suitable for multi-shipping checkout?
*/

protected $_canUseForMultishipping = true;

/**
* Can save credit card information for future processing?
*/

protected $_canSaveCc = false;

/**
* Here you will need to implement authorize, capture and void public methods
*
* @see examples of transaction specific public methods such as
* authorize, capture and void in Mage_Paygate_Model_Authorizenet
*/

}

?>

This class will interact with your payment gateway.

Admin Panel Configuration Options

<?xml version="1.0"?>
<config>
<sections>
<!-- payment tab -->
<payment>
<groups>
<!-- newmodule fieldset -->
<newmodule translate="label" module="paygate">
<!-- will have title 'New Module' -->
<label>New Module</label>
<!-- position between other payment methods -->
<sort_order>670</sort_order>
<!-- do not show this configuration options in store scope -->
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>0</show_in_store>
<fields>

<!-- is this payment method active for the website? -->
<active translate="label">
<!-- label for the field -->
<label>Enabled</label>
<!-- input type for configuration value -->
<frontend_type>select</frontend_type>
<!-- model to take the option values from -->
<source_model>adminhtml/system_config_source_yesno</source_model>
<!-- field position -->
<sort_order>1</sort_order>
<!-- do not show this field in store scope -->
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>0</show_in_store>
</active>

<order_status translate="label">
<label>New order status</label>
<frontend_type>select</frontend_type>
<source_model>adminhtml/system_config_source_order_status_processing</source_model>
<sort_order>4</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>0</show_in_store>
</order_status>

<title translate="label">
<label>Title</label>
<frontend_type>text</frontend_type>
<sort_order>2</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>0</show_in_store>
</title>

</fields>
</newmodule>
</groups>
</payment>
</sections>
</config>

Updating the Database

Make the app/code/local/CompanyName/NewModule/sql/newmodule_setup/mysql4-install-0.1.0.php:

<?php

// here are the table creation for this module e.g.:
$this->startSetup();
$this->run("HERE YOUR SQL");
$this->endSetup();
<modules>
<CompanyName_NewModule>
<version>0.2.0</version>
</CompanyName_NewModule>
</modules>
<?php

// here are the table updates for this module e.g.:
$this->startSetup();
$this->run("HERE YOUR UPDATE SQL");
$this->endSetup();

<modules>
<CompanyName_NewModule>
<version>0.2.0</version>
</CompanyName_NewModule>
</modules>

<?php

// here are the table updates for this module e.g.:
$this->startSetup();
$this->run("HERE YOUR UPDATE SQL");
$this->endSetup();

How to Set up the WorldPay Gateway

Go to Magento Go’s Admin Panel and choose System > Configuration > Payment Methods. At the Sales > Configuration panel choose Payment Methods and go to WordlPay. Now you need to do the following:

  1. Choose “enable”.
  2. Leave the Title name as it is or modify it.
  3. For Payment Option choose either Authorize Only or Authorize and Capture.
  4. Provide the following info from your WorldPay account: XML Password, Merchant Code, installation ID and account type.
  5. Set the credit card verification to yes or no. Go to the credit card types and choose the ones that are acceptable with this payment gateway.

Now go to the field “Payment from Applicable Countries” and choose the countries where this payment option is acceptable. Next you should set the 3D Secure Card Validation to “yes”. The “Transaction ID prefix” is optional.

Click Save Config and you are done.

Set up PayPal PayFlow Gateway

Go to the Admin panel and choose System > Configuration and go to Sales Payment Methods and select the Merchant Location section. Now choose the Merchant Country where your business is situated. Now go to PayPal Payment Gateways and choose Configure.

Go to Required PayPal Settings and go to PayFlow Pro and Express Checkout.

  1. Type the email address linked with your PayPal account.
  2. Choose PayPal as “partner”.
  3. In the user field set the name needed to log in. Make “Vendor” the user name. Type the password as well.
  4. Click “Enable this Solution”.

If your store has several views, make sure Current Configuration Scope is set at the views where the configuration is applicable. Now you have to type a title for identifying PayPal PayFlow Pro at checkout.

It’s best to just have the default on. Now you just need to set Payment Action to Sale or Authorization. Next you should go to Allowed Credit Card Types and choose the credit cards that work with your payment method.

Now go to the Advanced Settings where you can make several modifications to the payment system.

  1. If you want customers to type the 3 digit code have the Require CVV Entry set to “yes”.
  2. Enable the “enable 3D Secure Card Validation” on Frontend and enable the following: Enable 3D Secure Card Validation in Admin, Severe 3D Secure Card Validation and Centinel API URL.
  3. Now go to Settlement Report Settings. If you are a part of the PayPal Secure FTP Server set the login and password.
  4. Set the Sandbox to yes.
  5. Set the right P-Address or Custom Endpoint Hostname (PayPal’s website is the default).
  6. Under Scheduled Fetching, choose the schedule for the system to generate reports.
  7. At the Frontend Experience Settings, you can customize the PayPal logo as well as the merchant pages. There are a lot of other settings here that you can modify and change. The ones that you need to change will depend on the kind of store you are running, so this will vary from case to case.

To complete the settings for your Express Checkout enable “Checkout with PayPal” at the Shopping Cart page. Click yes to PayPal Shortcut on Shopping Cart. Now follow these steps:

  1. Set shortcut on Product View to yes, as this will display the “Checkout with PayPal” button at the page for product details.
  2. Go to Advance Settings and choose either Specific Countries or All Allowed Countries.
  3. At the Transfer Cart Line Items set it to “yes”.

One Final Thought

As you can see, there are many ways to create a payment method in Magento. Regardless of which method you choose, make sure that you test it carefully before actually implementing it. If you encounter trouble when you create a payment method, go through the code again. Chances are you made a mistake. It will also help clean the cache as it may cause problems.

About the Author: James Larson has been using Magento for several years and his primary specialty is creating your own payment gateway for Magento & Magento Extension. Part of his work also includes helping companies set up popular payment methods with the application such as WorldPay and PayPal PayFlow.
A Collection of Christmas Resources and Inspirations
Authored by: Designrshub.com

This post is published by a Designrshub.com staff or a guest contributor. If you'd like to guest post for Designrshub check out our Write for Designrshub page for details about how YOU can share your tips with our community.