`
yanggaojiao
  • 浏览: 82939 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

Create Payment Method Module

阅读更多

Javaeye的一些作者也有相同的文章(都是从官网直接贴过来的),不过我还打算自己也发布一下,方便读者不用到处找Magento的资料。

废话不说,要新增一个Magento支付模块的话,最好单独出来定义;当然也可以跟其他的module定义在同一个Module中如果有需要的话。
下面我们将新增一个带可以完成下面列表的功能的payment方法的module:

  • 读取信用卡的信息
  • 交易提交前进行验证
  • 在订单支付记录中记录该交易的ID

假设这个module叫做NewModule.,当然这个名字是任意的。

首先确保你的 app/code/local 在 include_path中(你不能确定的话,请看我前面的文章有相关的代码完成该功能).

如果你的system->cache Management 中的configuration cache是开着的话,把它Disable,或者在更新*.xml配置文件时reset/reflash一下。

 

 新建 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>

 

Magento在初始化配置的时候自动到etc/目录下读取相关的xml文件。分析完上面的代码知道你新增一个module

 

Create 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> 
<!-- IMPORTANT: if you use your own namespace (i.e. CompanyName) you also have to declare blocks group for new module. See topic: http://www.magentocommerce.com/boards/viewthread/22416/#t102732 -->
    <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>

 

上面的xml文档定义了一些配置选项,在Magento admin panel System > Configuration 你将会看到这些选项。

Create app/code/local/CompanyName/NewModule/etc/system.xml:

<?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>

 
打开 Admin / System / Configuration / Payment Methods, 看到"New Module” group.Enable之,然后检测一下新模块是否可以工作了. 在payment methods可以看到"New Module” payment method并且带有填写信用卡信息的表单.

 

Create 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> 

 

 

然后 create app/code/local/CompanyName/NewModule/sql/newmodule_setup/mysql4-upgrade-0.1.0-0.2.0.php:

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

 注意事项:

  • Dont put your module in /Mage. It belongs in app/code/community/ or app/code/local
  • Make sure your module’s first letter is capitalized. newmodule apparently will not work, it must start with a capital letter Newmodule.
  • Also make sure that the recipient folder of the module’s folder (CompanyName in the example) is capitalized as well. companyName doesn’t seem to work, either.
  • If your module is not showing in configuration>advanced then check your config.xml
  • If your module shows in the list of modules (configuration>advanced) but not in the Payment Methods, your problem is probably in system.xml
  • Make sure you clear the cache.
分享到:
评论

相关推荐

    NopCommerce (ASP.NET商城) v2.0 源码包.zip

    Select payment/shipping method radio button text was not clickable Hide prices for non-registered customers didn't work on tier prices Renamed PayPal PTI to PDT MS Excel importing issue fixed A ...

    NopCommerce (ASP.NET商城) v2.0.zip

    Select payment/shipping method radio button text was not clickable Hide prices for non-registered customers didn't work on tier prices Renamed PayPal PTI to PDT MS Excel importing issue fixed A ...

    paypal接口等说明 中文

    Module Module1 Sub Main() ' 获取POST请求中的参数 Dim request As HttpWebRequest = WebRequest.Create("https://your-ipn-url.com/ipn") request.Method = "POST" request.ContentType = "application/x-...

    基于CST软件的三维超材料能带计算及其应用

    内容概要:本文介绍了如何利用CST软件进行三维超材料的能带计算。首先概述了三维超材料的独特性质及其广泛应用前景,接着简要介绍了CST软件的功能特点。随后详细阐述了能带计算的具体步骤,包括模型建立、材料参数设置、网格划分与求解设置以及最终的计算与结果分析。最后给出了一段Python代码示例,展示了如何处理CST输出的数据并绘制能带图。文章强调了计算机模拟技术对于深入了解超材料电子结构和物理性质的重要性。 适合人群:从事材料科学研究的专业人士,尤其是对三维超材料和电磁场模拟感兴趣的科研工作者和技术人员。 使用场景及目标:适用于希望借助CST软件开展三维超材料能带计算的研究项目,旨在提高对超材料的理解,推动相关领域的技术创新和发展。 其他说明:文中提供的Python代码仅为示例,在实际操作时可根据具体情况进行调整优化。同时,掌握CST软件的基本操作和电磁理论基础知识有助于更好地理解和应用本文内容。

    基于FPGA的永磁同步伺服系统设计:电流环及矢量控制实现

    内容概要:本文详细介绍了基于FPGA的永磁同步伺服系统的矢量控制设计,涵盖了从电流环到速度环的关键模块实现。具体包括Clarke和Park变换、PI调节器、AD7606采样、正交编码器反馈以及SVPWM生成等部分。文中提供了详细的Verilog代码片段,展示了各个模块的具体实现方法和技术细节。特别强调了定点数处理、时序设计和跨时钟域处理等方面的技术挑战及其解决方案。 适合人群:具备一定FPGA开发经验和电机控制基础知识的研发人员。 使用场景及目标:适用于希望深入了解FPGA在电机控制应用中的具体实现方式,特别是矢量控制和电流环设计的专业人士。目标是掌握FPGA平台下高效、低延迟的电机控制系统设计方法。 阅读建议:由于涉及大量具体的Verilog代码和硬件设计细节,建议读者在阅读过程中结合实际项目进行实验和调试,以便更好地理解和掌握相关技术。

    飞机大战:从运动方程到战斗系统的全链路设计解析

    经典飞机大战游戏是理解实时交互系统设计的绝佳载体。本文将深入剖析现代空战游戏的核心模块,涵盖刚体运动学、弹道轨迹优化、碰撞检测算法等关键技术,揭示二维游戏背后复杂的三维数学建模过程。

    scratch少儿编程逻辑思维游戏源码-冰塔.zip

    scratch少儿编程逻辑思维游戏源码-冰塔.zip

    scratch少儿编程逻辑思维游戏源码-弹跳(4).zip

    scratch少儿编程逻辑思维游戏源码-弹跳(4).zip

    COMSOL焊接热源模型解析:双椭球、高斯旋转体与柱状体热源的应用与优化

    内容概要:本文详细介绍了COMSOL软件中三种常见的焊接热源模型——双椭球热源、高斯旋转体热源和柱状体热源。双椭球热源适用于模拟移动热源(如激光焊、电弧焊),通过调整轴向系数a1和a2来控制热流分布;高斯旋转体热源适合小范围焊接,采用三维高斯函数描述热流密度;柱状体热源则用于深熔焊场景,特点是计算速度快。文中还提供了每种模型的具体代码实现,并强调了调试时需要注意的关键点,如时间步长、网格加密等。此外,作者分享了一些实用技巧,如将热源参数设置为全局变量并利用参数扫描功能提高调试效率。 适合人群:从事焊接工艺仿真、材料加工领域的研究人员和技术人员,以及对COMSOL建模感兴趣的工程技术人员。 使用场景及目标:帮助用户选择合适的热源模型进行焊接模拟,确保模拟结果的准确性;提供具体的代码实现和调试方法,使用户能够快速掌握并应用于实际项目中。 其他说明:文中提到的热源模型不仅限于理论介绍,还包括实际操作中的注意事项和优化建议,有助于提升模拟效果和工作效率。

    基于RBF神经网络的PID控制器在PMSM转速环中的Simulink模型设计与性能分析

    内容概要:本文介绍了将基于RBF神经网络的PID控制器应用于永磁同步电机(PMSM)转速环控制的方法及其性能优势。传统的PID控制器在面对非线性和时变系统时存在参数整定困难的问题,而引入RBF神经网络可以实现实时在线调参,提高系统的灵活性和鲁棒性。文中详细描述了Simulink模型的设计,特别是Matlab s-function模块中RBF神经网络的具体实现,包括高斯函数激活和带惯性的权值更新机制。实验结果显示,在转速突变情况下,改进后的控制器能够迅速稳定系统,超调量控制在2%以内,调节时间较传统方法缩短约40%,并且在负载变化时表现出色,无需重新整定参数。 适合人群:从事电机控制系统研究和开发的技术人员,尤其是对PID控制器优化感兴趣的工程师。 使用场景及目标:适用于需要提升PMSM转速环控制精度和响应速度的应用场合,如工业自动化设备、机器人等领域。目标是通过引入智能算法解决传统PID控制器参数整定难题,提高系统性能。 阅读建议:关注RBF神经网络与PID控制器结合的具体实现细节,特别是在Matlab s-function模块中的编码技巧以及参数调整策略。同时,注意学习率的选择和动量项的作用,这对于实际应用至关重要。

    scratch少儿编程逻辑思维游戏源码-GTA 6.zip

    scratch少儿编程逻辑思维游戏源码-GTA 6.zip

    scratch少儿编程逻辑思维游戏源码-仓鼠跑酷.zip

    scratch少儿编程逻辑思维游戏源码-仓鼠跑酷.zip

    scratch少儿编程逻辑思维游戏源码-超级麦克世界.zip

    scratch少儿编程逻辑思维游戏源码-超级麦克世界.zip

    scratch少儿编程逻辑思维游戏源码-400年.zip

    scratch少儿编程逻辑思维游戏源码-400年.zip

    少儿编程scratch项目源代码文件案例素材-气球足球.zip

    少儿编程scratch项目源代码文件案例素材-气球足球.zip

    少儿编程scratch项目源代码文件案例素材-沙漠迷城.zip

    少儿编程scratch项目源代码文件案例素材-沙漠迷城.zip

    scratch少儿编程逻辑思维游戏源码-比谁高.zip

    scratch少儿编程逻辑思维游戏源码-比谁高.zip

    少儿编程scratch项目源代码文件案例素材-乾坤大挪移.zip

    少儿编程scratch项目源代码文件案例素材-乾坤大挪移.zip

    scratch少儿编程逻辑思维游戏源码-菜鸟跳跃.zip

    scratch少儿编程逻辑思维游戏源码-菜鸟跳跃.zip

    【C++编程语言】核心特性详解、学习笔记

    内容概要:本文档详细介绍了C++语言的基础知识、高级特性及其应用。首先,文档回顾了C++对C语言的扩展,包括面向对象编程的支持、增强的语法特性(如命名空间、引用、常量处理等)。接着,深入探讨了类和对象的使用,涵盖构造函数、析构函数、拷贝构造函数、深浅拷贝等重要概念。文档还讲解了单例模式的设计与实现、C++面向对象模型的核心要素(如this指针、静态成员、友元函数)、继承与派生的关系及其实现细节、多态性的原理与应用。此外,文档详细介绍了C++的模板机制、类型转换、异常处理机制、输入输出流操作、STL(标准模板库)的容器和算法等内容。每个部分都通过具体的代码示例和解释,帮助读者理解和掌握C++的关键特性和最佳实践。 适合人群:具备一定编程基础,尤其是熟悉C语言的开发者;希望深入了解C++语言特性和面向对象编程思想的程序员;从事C++开发工作的工程师和技术爱好者。 使用场景及目标:①掌握C++语言的核心概念和高级特性;②理解并能够应用面向对象编程的基本原则和模式;③学习如何使用STL容器和算法优化代码性能;④提升C++程序的健壮性和可维护性,特别是在处理复杂数据结构和算法时;⑤掌握异常处理和类型转换的最佳实践,确保程序的稳定性和安全性。 其他说明:本文档不仅提供了理论知识,还结合了大量实例代码,便于读者边学边练。对于每一个知识点,文档都力求做到详尽解释,确保读者能够透彻理解并灵活运用。文档内容全面覆盖了C++编程的各个方面,从基础语法到高级特性,适合不同层次的学习者逐步深入学习。

Global site tag (gtag.js) - Google Analytics