How to Integrate Custom Payment Method in Mofluid

Table of Contents

  1. Choose a Payment Method and Learn its Flow
  2. Important Facts and conventions
  3. Creating mysql setup file
  4. Admin Menu and ACL setup in module configuration
  5. Create a Custom Module
  1. Create Admin View for configuration settings
  2. Create Admin Controller to Save Configuration Settings
  3. Create Frontend View for Payment Processing
  4. Create Frontend controller to handle cancel, success or other actions
  1. Test the Flow
  2. Create Extension Which support Mofluid

Choose a Payment Method and Learn its Flow

Select a Payment Method which you want to implement for mofluid, If possible download the demo code for this payment gateway and see the flow how it works, you can also refer any document or blog to learn more about this payment method. you should also know about the requirement of the payment gateway like all the form fields, Account Id, API key, hash, Mode etc

It is highly recommended that you should clearly know about the flow to setup it, If you have any doubt you can create a support ticket on the support center of that payment gateway website.

Important Facts and conventions

Before Going to start you should know about these facts and follow the conventions:-

  1. Your selected payment gateway should support the currency In which you have generated the mofluid app.
  2. Magento extension for that payment gateway should also installed on your website but it is not necessary that you have to enable it. This is required because while creating the order through the Mofluid Apps It will use the same payment code and attach it on your order.
  3. You can create your custom payment method either in MofluidExtra or in MofluidCustom Package, you should not change anything in Mofluid, because It is a core if you do so you may face the problem at the time of upgrade.
  4. Your Module name should have “Payment” as prefix like if you want to implement “paypal express” then your Module name should be “Paymentpaypalexpress”
  5. While setup you payment method you need to set following name

Name / Description / Example
Package Name / It should be either MofluidExtra or MofluidCustom / like MofluidExtra or MofluidCustom
Module Name / It should be you module name which has Payment as prefix / like Paymentpaypalexpress, Paymentpaypal, Paymentcod etc
Payment Method ID / Unique Integer Value which should not exist in your mofluidpayment table / like 10001,10002 etc
Payment Method Code / This will be your module name excluding Payment keyword, like if your Module name is Paymentpaypalexpress then Method ID should be paypalexpress, this should be unique. / like paypalexpress, paypal_standard, cod etc
Payment Method Order Code / This should be the payment method code which will attach in order object / like for Paypal Standard It is paypal_standard, for cod it is cashondelivery, for paypalexpress it is paypalexpress_ideal etc.
Frontend Controller Name / This is a frontName defined in config.xml file for your frontend controller it should be same as your module name but in lowecase characters. / like : <frontName>paymentpaypalexpress</frontName>

Creating mysql setup file

Create a mysql setup file in your module which will insert an entry in mofluidpayment table, let suppose you are going to implement Paypal Express Checkout and value of other fields which you have set is as follow

Package Name / MofluidExtra
Module Name / Paymentpaypalexpress
Payment Method ID / 1001
Payment Method Code / paypalexpress
Payment Method Order Code / paypal_express

<?php

$installer = $this; //Getting Installer Class Object In A Variable

$installer->startSetup();

$installer->run("INSERT INTO {$this->getTable('mofluidextra_paymentpaypalexpress/payment')} (

`payment_method_id`,

`payment_method_title`,

`payment_method_code`,

`payment_method_order_code`,

`payment_method_status`,

`payment_method_mode`

)

VALUES (1001, 'Paypal Express Checkout', 'paypalexpress', 'paypal_express', 0, 0);

");

$installer->endSetup();

?>

Admin Menu and ACL setup in Module Configuration

Below is the format of Module configuration file where sort_order of mofluid should be 90 and for Payment Configuration it should be 10 but for your Payment Method it should be the integer unique id which you have set in payment method id, let see an example (app/code/local/MofluidExtra/Paymentpaypalexpress/etc/adminhtml.xml)

<?xml version="1.0"?>

<config>

<menu>

<mofluid translate="title" module="mofluidextra_paymentpaypalexpress">

<title>Mofluid</title>

<sort_order>90</sort_order>

<children>

<mofluid_payment translate="title" module="mofluidextra_paymentpaypalexpress">

<title>Payment Configuration</title>

<sort_order>10</sort_order>

<children>

<mofluidextra_payment_paypalexpress_menu translate="title" module="mofluidextra_paymentpaypalexpress">

<title>Paypal Express</title>

<sort_order>1001</sort_order>

<action>adminhtml/paymentpaypalexpress</action>

</mofluidextra_payment_paypalexpress_menu>

</children>

</mofluid_payment>

</children>

</mofluid>

</menu>

<!--Access Control Settings-->

<acl>

<resources>

<all>

<title>Allow Everything</title>

</all>

<admin>

<children>

<mofluid translate="title" module="mofluidextra_paymentpaypalexpress">

<title>Mofluid</title>

<sort_order>90</sort_order>

<children>

<mofluid_payment translate="title" module="mofluidextra_paymentpaypalexpress">

<title>Payment Configuration</title>

<sort_order>10</sort_order>

<children>

<mofluidextra_payment_paypalexpress_menu translate="title" module="mofluidextra_paymentpaypalexpress">

<title>Paypal Express</title>

<sort_order>1001</sort_order>

</mofluidextra_payment_paypalexpress_menu>

</children>

</mofluid_payment>

</children>

</mofluid>

</children>

</admin>

</resources>

</acl>

</config>

Create a Custom Module

  1. Create Admin View for configuration settings

Inside your Block/Adminhtml you should create the Block or View which will display your configuration settings

  1. Create Admin Controller to Save Configuration Settings

Inside your controllers/Adminhtml you should create controller which will save your configuration settings

  1. Create Frontend View for Payment Processing

Inside your controllers/IndexController.php you should create the dynamic view which will create the payment form for processing it should get the configuration settings from your model and other values will be recieved in GET parameter in paymentdata parameter this value is encoded value so you should have to decode it using base64_decode method, it will give you the json data after that you will need to use json_decode method which will give you the object which consist orderid, amount, first_name, last_name, siteurl and shopid. see the example how you will get other values

@$paymentdata = json_decode(base64_decode($_GET["paymentdata"]));

$_ORDER_ID = @$paymentdata->orderid;

after creating the form set form auto submit using javascript so when Mobile app open this controller the payment form has been created and form will submit to the payment gateway(i.e. third party) here user will provide his payment data once the payment has been done it will return to the same url (for that you need to set the return url in your form) here you will get the response and process the order as required.

  1. Create Frontend controller to handle cancel, success or other actions

Once your payment has been done you will be redirected to your frontend controller by setting the return url value in your payment processing form, so on the same controller identify the response and process your order (as you have the order id) after that just display the response.

Test the Flow

If the Module has been developed as per the above flow and conventions, just enable and configure the payment from admin panel after that open the app add product to your cart, select your payment method and go if everything has been setup correctly you will see the app open your frontend controller for payment processing once the payment has been done click on close/done button to close this window and you will come back to the app.

Create Extension Which support Mofluid

If Test has been done successfully you should now ready to create the extension. to learn how to create magento extension just follow the link