Magento 支付流程

本文介绍了Magento 支付流程的处理方法,对大家解决问题具有一定的参考价值

问题描述

我正在为 Magento 实现一个新的支付模块,并想了解这个逻辑背后的核心概念.我知道我必须从 Mage_Payment_Model_Method_Abstract 或其任何子类扩展,但我的问题是何时使用以及如何在我的模型中使用捕获和授权方法.例如,如果我将整个过程分成以下步骤:

I am working on implementing a new payment module for Magento and want to understand the core concept behind this logic. I know I have to extend from Mage_Payment_Model_Method_Abstract or any of its children classes, but my problem is when to use and how to use capture and authorize methods in my model. For example if I split the whole process in steps like this:

  1. 用户来到购物车并选择了一些付款方式,即网关.
  2. 系统拦截请求,收集所有提交的数据并将用户发送到网关网址.
  3. 用户在网关站点下订单(或取消),网关站点将相关信息发送到我的商店.
  4. 我的商店使用收到的数据对订单进行了更多修改,并保存状态为已完成或已取消的订单.

在这些步骤中,我必须在哪里使用授权和捕获方法?如果有人能向我解释授权和捕获的含义,我将不胜感激?

Where in these steps will I have to use authorize and capture methods ? I would appreciate if someone could explain to me what authorize and capture means?

推荐答案

以下是我一直以来理解这些概念的方式,以及在 Magento 中实现支付模块所需的知识.下面以粗体显示了对您具体的这在何处发生"的回答,尽管它并不像您希望的那么简单.

Here's the way I've always understood the concepts, and what you'll need to know to implement a payment module in Magento. Answers to your specific "where does this happen" are bolded below, although it's not quite as simple as you're hoping for.

互联网出现之前,实体信用卡交易是一个两个阶段的过程.

Pre-internet, brick and mortar credit card transactions were a two stage process.

在销售时,当商家拿着消费者的信用卡进行购买时,他们会将其滑过一个销售点设备,该设备会呼叫信用卡的中央办公室并询问这张卡是否已授权用于此目的?网络,以及这个特定消费者的可用信用额度是否足够大以允许购买".

At the time of a sale, when the merchant took a consumer's credit card for a purchase they'd slide it through a point of sale device which would call into the credit card's central office and ask "is this card authorized for this network, and is this particular consumer's line of available credit large enough to allow this purchase".

如果购买被接受(而不是被拒绝),则该费用被视为授权.消费者会拿走他们的产品,销售点系统/收银机会注意到交易已获授权.然后,在一天结束或一周结束时,按照其他预定的定期时间表,或者当所有者决定停止饮酒时,商家会查看所有授权收据并发送另一个strong> 请求中央办公室获取来自授权交易的资金.获取资金是将资金存入商家账户的原因.

If the purchase was accepted (as opposed to declined), the charge was said to be authorized. The consumer would take their product, and the point of sale system/cash-register would note that the transaction was authorized. Then, at the end of a the day, or the end of the week, at some other predetermined regular schedule, or when the owner decided to stop drinking, the merchant would go though all their authorized receipts and send another request to the central office to capture the funds from the authorized transaction. Capturing the funds is what puts money in the merchant's account.

这仍然是大多数网关使用的模型,也是 Magento Inc. 选择为其支付模块实现的域模型.

This is still the model in use by most gateways, and is the domain model that Magento Inc. chose to implement for their payment modules.

事情应该运行的方式是,当消费者到达像 Magento 这样的系统中的最终结帐步骤时,Magento 会向网关的 API 发出授权请求.如果交易成功,系统接受订单,并存储来自授权请求的唯一 ID.接下来,当消费者的商品发货时,店主使用 Magento 管理员创建发票.此发票的创建会发出一个捕获请求(使用从授权请求返回的商店 ID).这是在 Magento 中发出这些方法调用的地方.

The way things are supposed to run is, when a consumer reaches the final checkout steps in a system like Magento, Magento issues an authorization request to the gateway's API. If the transaction is successful, the order is accepted into the system, and a unique ID from the authorization request is stored. Next, when the consumer's goods ship, a store owner uses the Magento admin to create an invoice. The creation of this invoice issues a capture request (using a store id returned from the authorization request). This is where these method calls are issued in Magento.

然而,事情变得棘手,因为每个支付网关对这些概念的解释都略有不同,每个商家对他们在发货前不要捕获"的责任的解释也不同.除了上述场景之外,支付模块还有一个系统配置值,称为支付操作.这可以设置为Authorize Only,这将实现上述流程.它也可以设置为Authorize and Capture,这将在下订单时授权和获取付款.它甚至更多令人困惑,因为虽然该方法称为授权和捕获,但当前版本的 Magento 只会在设置为这种模式时发出捕获请求(至少对于 Authorize.net)和 Authorize.net将在内部使捕获请求在一天中的大部分时间处于已授权但未捕获的状态.Magento 处理订单、付款和发票的方式是代码库的一个领域,它因版本而异.

However, things get tricky because every payment gateway interprets these concepts a little differently, and every merchant interprets their "don't capture until we've shipped" responsibilities differently. In addition to the scenario described above, payment modules have a system configuration value known as a Payment Action. This can be set to Authorize Only, which will implement the flow described above. It can also be set to Authorize and Capture, which will both authorize and capture a payment when the order is placed. It gets even more confusing because although the method is called Authorize and Capture, current versions of Magento will only issue the capture request when set in this mode (at least for Authorize.net), and Authorize.net will, internally, leave capture requests in an authorized but not captured state for most of the day. How Magento handles orders and payments and invoices is one area of the codebase that changes a lot from version to version.

因此,Magento 支付模块系统背后的想法是保护您免受集群 F 的影响——即编程支付网关逻辑.在您的 authorize 方法中,您实现对支付网关的授权 API 的调用(或执行您希望在此时发生的任何检查和逻辑).这个方法被传递一个支付对象和一个金额.如果你让你请求/执行你的逻辑并确定它因任何原因无效,你会抛出一个异常

So, the idea behind the Magento payment module system is to shield you from the Cluster F--- that is programming payment Gateway logic. In your authorize method you implement a call to your payment gateway's authorize API (or perform whatever checks and logic you want to happen at this point). This method is passed a payment object and an amount. If you make you request/perform-your-logic and determine it's invalid for whatever reason, you throw an Exception with

Mage::throwException('...');

这告诉 Magento 授权失败,它将采取相应的行动(显示错误消息等).否则,您在 Payment 对象上设置数据成员并发出

This tells Magento the authorization failed, and it will act accordingly (show an error message, etc.). Otherwise, you set data members on the Payment object and issue a

return $this;

数据成员是您稍后在获取付款时需要的东西.这将我们带到您的 Payment 模块的 capture 方法.此方法还会发送一个付款对象和一个金额.在此方法中,您发出捕获请求.付款对象将具有 cc_trans_id 数据成员

The data members are things you'll need later, when capturing the payment. Which brings us to the capture method of your Payment module. This method is also sent a payment object and an amount. In this method you issue your capture request. The payment object will have cc_trans_id data member

$payment->getCcTransId()

这将允许您针对您的网关发出捕获.这是您负责保存在 authorize 中的数据成员之一.同样,如果您的代码确定捕获失败,则会抛出异常.否则,您返回 $this.

which will allow you to issue a capture against your gateway. This is one of the data members you're responsible for saving up in authorize. Again, if your code determines the capture has failed, you throw an exception. Otherwise, you return $this.

authorize.net 支付模块有很好的例子说明如何做到这一点.

The authorize.net payment module has good examples of how this is done.

app/code/core/Mage/Paygate/Model/Authorizenet.php

例如,考虑capture方法的这一部分

For example, consider this part of the capture method

public function capture(Varien_Object $payment, $amount)
{
    if ($payment->getCcTransId()) {
        $payment->setAnetTransType(self::REQUEST_TYPE_PRIOR_AUTH_CAPTURE);
    } else {
        $payment->setAnetTransType(self::REQUEST_TYPE_AUTH_CAPTURE);
    }   

    $payment->setAmount($amount);
    $request= $this->_buildRequest($payment);
    $result = $this->_postRequest($request);
    //...

这里的捕获方法是检查付款是否具有 cc_trans_id.根据结果​​,它将 anet_trans_type 设置为:

Here the capture method is checking if the payment has a cc_trans_id. Depending on the result, it sets anet_trans_type to either:

self::REQUEST_TYPE_PRIOR_AUTH_CAPTURE
self::REQUEST_TYPE_AUTH_CAPTURE

API 请求对象随后使用该值来发送 API 调用

This value is then used by the API request object to send an API call for either

  1. 捕获预授权交易
  2. 立即捕获

希望能帮到你,祝你好运!

Hope that helps, and good luck!

这篇关于Magento 支付流程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,WP2

admin_action_{$_REQUEST[‘action’]}

do_action( "admin_action_{$_REQUEST[‘action’]}" )动作钩子::在发送“Action”请求变量时激发。Action Hook: Fires when an ‘action’ request variable is sent.目录锚点:#说明#源码说明(Description)钩子名称的动态部分$_REQUEST['action']引用从GET或POST请求派生的操作。源码(Source)更新版本源码位置使用被使用2.6.0 wp-admin/admin.php:...

日期:2020-09-02 17:44:16 浏览:1127

admin_footer-{$GLOBALS[‘hook_suffix’]}

do_action( "admin_footer-{$GLOBALS[‘hook_suffix’]}", string $hook_suffix )操作挂钩:在默认页脚脚本之后打印脚本或数据。Action Hook: Print scripts or data after the default footer scripts.目录锚点:#说明#参数#源码说明(Description)钩子名的动态部分,$GLOBALS['hook_suffix']引用当前页的全局钩子后缀。参数(Parameters)参数类...

日期:2020-09-02 17:44:20 浏览:1033

customize_save_{$this->id_data[‘base’]}

do_action( "customize_save_{$this->id_data[‘base’]}", WP_Customize_Setting $this )动作钩子::在调用WP_Customize_Setting::save()方法时激发。Action Hook: Fires when the WP_Customize_Setting::save() method is called.目录锚点:#说明#参数#源码说明(Description)钩子名称的动态部分,$this->id_data...

日期:2020-08-15 15:47:24 浏览:775

customize_value_{$this->id_data[‘base’]}

apply_filters( "customize_value_{$this->id_data[‘base’]}", mixed $default )过滤器::过滤未作为主题模式或选项处理的自定义设置值。Filter Hook: Filter a Customize setting value not handled as a theme_mod or option.目录锚点:#说明#参数#源码说明(Description)钩子名称的动态部分,$this->id_date['base'],指的是设置...

日期:2020-08-15 15:47:24 浏览:866

get_comment_author_url

过滤钩子:过滤评论作者的URL。Filter Hook: Filters the comment author’s URL.目录锚点:#源码源码(Source)更新版本源码位置使用被使用 wp-includes/comment-template.php:32610...

日期:2020-08-10 23:06:14 浏览:904

network_admin_edit_{$_GET[‘action’]}

do_action( "network_admin_edit_{$_GET[‘action’]}" )操作挂钩:启动请求的处理程序操作。Action Hook: Fires the requested handler action.目录锚点:#说明#源码说明(Description)钩子名称的动态部分$u GET['action']引用请求的操作的名称。源码(Source)更新版本源码位置使用被使用3.1.0 wp-admin/network/edit.php:3600...

日期:2020-08-02 09:56:09 浏览:848

network_sites_updated_message_{$_GET[‘updated’]}

apply_filters( "network_sites_updated_message_{$_GET[‘updated’]}", string $msg )筛选器挂钩:在网络管理中筛选特定的非默认站点更新消息。Filter Hook: Filters a specific, non-default site-updated message in the Network admin.目录锚点:#说明#参数#源码说明(Description)钩子名称的动态部分$_GET['updated']引用了非默认的...

日期:2020-08-02 09:56:03 浏览:834

pre_wp_is_site_initialized

过滤器::过滤在访问数据库之前是否初始化站点的检查。Filter Hook: Filters the check for whether a site is initialized before the database is accessed.目录锚点:#源码源码(Source)更新版本源码位置使用被使用 wp-includes/ms-site.php:93910...

日期:2020-07-29 10:15:38 浏览:809

WordPress 的SEO 教学:如何在网站中加入关键字(Meta Keywords)与Meta 描述(Meta Description)?

你想在WordPress 中添加关键字和meta 描述吗?关键字和meta 描述使你能够提高网站的SEO。在本文中,我们将向你展示如何在WordPress 中正确添加关键字和meta 描述。为什么要在WordPress 中添加关键字和Meta 描述?关键字和说明让搜寻引擎更了解您的帖子和页面的内容。关键词是人们寻找您发布的内容时,可能会搜索的重要词语或片语。而Meta Description则是对你的页面和文章的简要描述。如果你想要了解更多关于中继标签的资讯,可以参考Google的说明。Meta 关键字和描...

日期:2020-10-03 21:18:25 浏览:1622

谷歌的SEO是什么

SEO (Search Engine Optimization)中文是搜寻引擎最佳化,意思近于「关键字自然排序」、「网站排名优化」。简言之,SEO是以搜索引擎(如Google、Bing)为曝光媒体的行销手法。例如搜寻「wordpress教学」,会看到本站的「WordPress教学:12个课程…」排行Google第一:关键字:wordpress教学、wordpress课程…若搜寻「网站架设」,则会看到另一个网页排名第1:关键字:网站架设、架站…以上两个网页,每月从搜寻引擎导入自然流量,达2万4千:每月「有机搜...

日期:2020-10-30 17:23:57 浏览:1264