Auth.net 捕获问题

2024-03-07

我在 auth.net 上捕获交易的函数是

public function capture(Varien_Object $payment, $amount){

    if(!$this->isEnabled()){
        return parent::capture($payment, $amount);
    }else{

        $captureCase = $_POST['invoice']['capture_case'];
        if(isset($captureCase) && $captureCase == "online"){
            if($capOrderid = $payment->getOrder()->getIncrementId()){

                $capOrder = $payment->getOrder();
                $capPayment = $payment;
                $capAmount = $amount;

                $capTransID = $capPayment->getLastTransId();

                $ccProfile = $this->getProfileForOrder($capOrderid);
                if(isset($ccProfile['used_this_profile']) && $ccProfile['used_this_profile'] == 1){


                    $pID = $ccProfile['cust_profile_id'];
                    $ppID = $ccProfile['cust_paymentprofile_id'];
                    $nick = $ccProfile['nickname'];

                    $lastOrderId = $capOrder->getIncrementId();


                    $cvv = $payment->getCcCid();
                    $directResponseFields = $this->createTransaction($pID,$ppID,$capAmount,$lastOrderId,"profileTransPriorAuthCapture",$cvv,$capTransID);
                    $responseCode = $directResponseFields[0]; // 1 = Approved 2 = Declined 3 = Error
                    $responseReasonCode = $directResponseFields[2]; // See http://www.authorize.net/support/AIM_guide.pdf
                    $responseReasonText = $directResponseFields[3];
                    $approvalCode = $directResponseFields[4]; // Authorization code
                    $transId = $directResponseFields[6];

                    switch ($responseCode) {
                        case "1":
                            $capPayment->setStatus(self::STATUS_APPROVED);
                            $capPayment->setCcTransId($transId);
                            $capPayment->setLastTransId($transId);
                            if (!$capPayment->getParentTransactionId() || $transId != $capPayment->getParentTransactionId()) {
                                $capPayment->setTransactionId($transId);
                            }
                            return true;
                            break;
                        case "2":
                            Mage::throwException(__('Payment authorization transaction has been declined.'));
                            break;
                        default:
                            Mage::throwException(__('Payment authorization error.'));
                            break;
                    }

                }

            }

        }elseif(!isset($captureCase)){
            $oldorderid = Mage::getModel('adminhtml/sales_order_create')->getSession()->getOrder()->getIncrementId();

            if(isset($oldorderid) && ($oldorderid != $payment->getOrder()->getIncrementId())){ // if order is created from admin and has an order to refund first.
                $oldOrder = Mage::getModel('sales/order')->loadByIncrementId($oldorderid);
                $oldPayment = $oldOrder->getPayment();
                $oldAmount = $oldPayment->getAmountOrdered();


                $transID = $oldPayment->getLastTransId();

                $ccProfile = $this->getProfileForOrder($oldorderid);
                if(isset($ccProfile['used_this_profile']) && $ccProfile['used_this_profile'] == 1){


                    $pID = $ccProfile['cust_profile_id'];
                    $ppID = $ccProfile['cust_paymentprofile_id'];

                    if($directResponseFields = $this->refundCIM($pID,$ppID,$transID,$oldorderid,$oldAmount)){

                        $responseCode = $directResponseFields[0]; // 1 = Approved 2 = Declined 3 = Error
                        $responseReasonCode = $directResponseFields[2]; // See http://www.authorize.net/support/AIM_guide.pdf
                        $responseReasonText = $directResponseFields[3];
                        $approvalCode = $directResponseFields[4]; // Authorization code
                        $transId = $directResponseFields[6];
                        switch ($responseCode) {
                            case "1":

                                //$oldPayment->setStatus(self::STATUS_SUCCESS);
                                $oldOrder->cancel()->save();

                                //$oldPayment->setIsTransactionClosed(1);
                                $oldOrder->setState(Mage_Sales_Model_Order::STATE_CANCELED, true)->save();
                                //$oldOrder->setState(Mage_Sales_Model_Order::STATE_CLOSED, true)->save();


                                //Mage::throwException(__("a".$responseCode));
                                //return $this;
                                break;
                            case "4":
                                Mage::throwException(__('Error Code 4. You cannot refund an unsettled transaction.'));
                                break;
                            default:
                                if(isset($responseReasonText) && !empty($responseReasonText)){
                                    Mage::throwException(__("Code: ".$responseReasonCode." - ".$responseReasonText));
                                }else{
                                    Mage::throwException(__('Error in refunding the payment. This can happen if the customer has deleted their profile from CIM.'));
                                }
                                break;
                        }
                    }

                }else if(isset($transID) && $oldAmount > 0) {

                    $oldPayment->setAnetTransType(self::REQUEST_TYPE_CREDIT);
                    $oldRequest = $this->_buildRequest($oldPayment);

                    $oldRequest->setXTransId($transID);

                    $oldPayment->setXAmount($oldAmount,2);  
                    $oldRequest->setXCurrencyCode($oldOrder->getBaseCurrencyCode());
                    $oldRequest->setXCardNum($oldPayment->getCcLast4());

                    $oldResult = $this->_postRequest($oldRequest);

                    if ($oldResult->getResponseCode()==self::RESPONSE_CODE_APPROVED) {
                        $oldPayment->setStatus(self::STATUS_SUCCESS);
                        $oldOrder->cancel()->save();
                    }else{
                        Mage::throwException($this->_wrapGatewayError($oldResult->getResponseReasonText())); //////////error here/////////

                    }
                }else{
                    Mage::throwException(Mage::helper('authnet')->__('Error in refunding the payment.'));
                }
            }
        }


        $quote = Mage::getSingleton('customer/session');
        $nickname = $quote->getAuthorizenetNickname();
        $profile = $quote->getProfile();
        $postedNickname = $quote->getNickname();

        if(!isset($nickname) || $nickname == "" || $nickname == "nnnew"){

            if ($amount <= 0) {
                Mage::throwException(Mage::helper('authnet')->__('Invalid amount for authorization.'));
            }

            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);

            if ($result->getResponseCode() == self::RESPONSE_CODE_APPROVED) {
                $payment->setStatus(self::STATUS_APPROVED);
                $payment->setCcTransId($result->getTransactionId());
                $payment->setLastTransId($result->getTransactionId());
                if (!$payment->getParentTransactionId() || $result->getTransactionId() != $payment->getParentTransactionId()) {
                    $payment->setTransactionId($result->getTransactionId());
                }
                if(isset($profile) && $profile == "save"){
                    $order = $payment->getOrder();
                    $billing = $order->getBillingAddress();

                    $ccno = $payment->getCcNumber();
                    $exp = sprintf('%04d-%02d', $payment->getCcExpYear(), $payment->getCcExpMonth());
                    $cvv = $payment->getCcCid();
                    $email = $order->getCustomerEmail();
                    $orderId = $order->getIncrementId();

                    if($profiles = $this->getCustId($email)){
                        foreach ($profiles as $_nickname => $cust_profile_id){
                            if($_nickname == $postedNickname){
                                Mage::throwException(__('Nickname already in use.')); 
                            }
                        }
                        $profileId = $cust_profile_id;
                    }else{
                        $profileId = $this->createProfile($payment,true);
                    }
                    if($profileId && $profileId != 1){
                        $ppId = $this->createPaymentProfile($billing,$profileId,$ccno,$exp,$postedNickname,$email,$cvv,true);
                        $this->assignNicknameToOrder($orderId,$profileId,$ppId,$postedNickname,0);
                    }
                }   

                return $this;
            }

            if ($result->getResponseReasonText()) {
                Mage::throwException($this->_wrapGatewayError($result->getResponseReasonText()));
            }
                Mage::throwException(Mage::helper('paygate')->__('Error in capturing the payment.'));

        }else if($nickname != "" && $nickname != "nnnew"){

            $selectedNickname = $nickname;

            $conn_selected = $this->conn();
            $results_selected = $conn_selected->query("SELECT * FROM ".$this->getTable()." WHERE cust_paymentprofile_id = '".$selectedNickname."'");
            while ($row = $results_selected->fetch() ) {
                $pID = $row['cust_profile_id'];
                $nick = $row['nickname'];
            }
            $ppID = $selectedNickname;
            $order = $payment->getOrder();
            $lastOrderId = $order->getIncrementId();


            $cvv = $payment->getCcCid();
            $directResponseFields = $this->createTransaction($pID,$ppID,$amount,$lastOrderId,"profileTransAuthCapture",$cvv);
            $responseCode = $directResponseFields[0]; // 1 = Approved 2 = Declined 3 = Error
            $responseReasonCode = $directResponseFields[2]; // See http://www.authorize.net/support/AIM_guide.pdf
            $responseReasonText = $directResponseFields[3];
            $approvalCode = $directResponseFields[4]; // Authorization code
            $transId = $directResponseFields[6];

            switch ($responseCode) {
                case "1":
                    $payment->setStatus(self::STATUS_APPROVED);
                    //$payment->setCcTransId($result->getTransactionId());
                    $payment->setLastTransId($transId);
                    if (!$payment->getParentTransactionId() || $transId != $payment->getParentTransactionId()) {
                        $payment->setTransactionId($transId);
                    }
                    $this->assignNicknameToOrder($lastOrderId,$pID,$ppID,$nick,1);
                    return true;
                    break;
                case "2":
                    Mage::throwException(__('Payment authorization transaction has been declined.'));
                    break;
                default:
                    Mage::throwException(__('Payment authorization error.'));
                    break;
            }
        }
        Mage::throwException(Mage::helper('paygate')->__('Error in capturing the payment.'));
    }
}

当我尝试捕获已授权的金额时,问题是随机出现的。我的交易请求的转储是

[request] => Array
        (
            [x_version] => 3.1
            [x_delim_data] => True
            [x_relay_response] => False
            [x_test_request] => FALSE
            [x_login] => ****
            [x_tran_key] => ****
            [x_type] => PRIOR_AUTH_CAPTURE
            [x_method] => CC
            [x_invoice_num] => dummy
            [x_amount] => 127.48
            [x_currency_code] => USD
            [x_trans_id] => 
            [x_first_name] => dummy
            [x_last_name] => dummyl
            [x_company] => 
            [x_address] => dummy Apt 67
            [x_city] => dummy
            [x_state] => California
            [x_zip] => dummy
            [x_country] => US
            [x_phone] => dummy
            [x_fax] => 
            [x_cust_id] => 
            [x_customer_ip] => 68.183xxxxx8
            [x_customer_tax_id] => 
            [x_email] => [email protected] /cdn-cgi/l/email-protection
            [x_email_customer] => 0
            [x_merchant_email] => 
            [x_ship_to_first_name] =>dummy
            [x_ship_to_last_name] => dummy
            [x_ship_to_company] => 
            [x_ship_to_address] => dummy Blvd.
            [x_ship_to_city] => dummy
            [x_ship_to_state] => dummy
            [x_ship_to_zip] => dummy
            [x_ship_to_country] => US
            [x_po_num] => 
            [x_tax] => 0.0000
            [x_freight] => 0.0000
        )

响应是

[result] => Array
        (
            [response_code] => 3
            [response_subcode] => 2
            [response_reason_code] => 33
            [response_reason_text] => A valid referenced transaction ID is required.
            [approval_code] => 
            [avs_result_code] => P
            [transaction_id] => 0
            [invoice_number] => 100dddd38
            [description] => 
            [amount] => 127.48
            [method] => CC
            [transaction_type] => prior_auth_capture
            [customer_id] => 
            [md5_hash] => dummy
            [card_code_response_code] => 
            [c_av_vresponse_code] => 
            [split_tender_id] => 
            [acc_number] => 
            [card_type] => 
            [requested_amount] => 
            [balance_on_card] => 
        )

我注意到Transaction ID在我的请求中,Auth.net 开发者网站也有同样的说法。有时订单会被捕获,但大多数时候,它们不会。我还注意到,无论是成功捕获还是不成功捕获,交易 ID 都存在于 Magento 中(我可以在管理面板中查看它,请参阅this http://awesomescreenshot.com/0e0sz0wba

当我尝试通过 mag admin 创建发票并捕获交易时,出现错误

网关错误:需要有效的引用交易 ID。

我想知道为什么会发生这种情况..有人可以帮助我>吗?任何想法?

我的板形式是 Magento Enterprise (1.12.x),我尝试使用的扩展是 Elayers(我没有购买它,为某人工作)


当您在正在使用的 Magento 版本中加载模型时,TransctionID 会被隐藏。尝试在加载模型时使用 ->addFieldToSelect('transaction_id') 。这样做的原因是因为它是受保护的数据属性,永远不应该像您在此处尝试的方式直接处理。

或者,您确实应该使用 Magento 的功能从销售订单模型创建发票。

$order = Mage::getModel('sales/order');
$service = Mage::getModel('sales/service_order' , $order);
$service->prepareInvoice();

prepareInvoice 采用可选数组 ( 'sku' => 'qty' )

这样可以轻松管理每个订单的多张发票的潜力。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Auth.net 捕获问题 的相关文章

  • Doctrine2:入门教程“没有要处理的元数据类”

    我已经将本教程的第一部分运行了三遍 到目前为止 在这里或其他地方进行的大量搜索都无法帮助我使其发挥作用 我收到 没有要处理的元数据类 当我尝试时 php vendor bin doctrine orm schema tool update
  • shell_exec 的输出被截断为 100 个字符

    当在 shell 中运行以下命令时 curl F file filename http 192 168 0 1 产生以下输出 Accuracy 0 0 1 classification Accuracy 0 0 1 classificati
  • 是否可以使用流上下文在 PHP 下使用 FTPS?

    我了解到使用ftpsPHP for Windows 下的 ftp ssl connect 很困难 您被要求进入构建自己的二进制文件以包括 Open SSL 的漫长旅程 我找到了以下建议phpseclib http phpseclib sou
  • 合并 csv 文件 [关闭]

    Closed 这个问题不符合堆栈溢出指南 help closed questions 目前不接受答案 如何在 PHP 或 joomla 中将多个 CSV 文件合并为一个 csv 文件 将文件夹中 csv 文件中的所有数据合并到文本文件中 通
  • 如何处理 PHP 中浮点数的奇怪舍入

    众所周知 浮点运算并不总是完全准确 但是如何处理它的不一致之处呢 As an example in PHP 5 2 9 this doesn t happen in 5 3 echo round 14 99225 4 14 9923 ech
  • PHP:STR 替换为链接

    我有这个 PHP 聊天框 如果我在聊天框中键入链接 它不会将其显示为链接 我如何使用 STR 替换来执行此操作 它应该响应诸如 http http com nl www www 之类的内容 我的其他 STR 替换行如下所示 bericht
  • PHP服务器端IAB验证openssl_verify总是返回0

    我使用以下函数 服务器端 php 来验证 IAB v3 事务 我从 Android 应用程序传递过来 Override protected void onActivityResult int requestCode int resultCo
  • Symfony 学说错误“DoctrineMigrationsBundle 需要启用 DoctrineBundle。”

    我创建了一个新的 Symfony 项目 并且不断收到此消息 DoctrineMigrationsBundle 需要启用 DoctrineBundle 错误并且无法摆脱它 显然我是这个星球上唯一一个收到此错误的人 因为谷歌并没有太大帮助 在
  • 如何将 .env 添加到 codeigniter?

    我尝试按照以下步骤使 php 连接到 Outlookhttps learn microsoft com en us outlook rest php tutorial https learn microsoft com en us outl
  • Laravel 5.6 - 注册表无法正常工作并且不显示任何错误

    在我最近的一个项目中 定制登记表不管用 当我单击注册按钮时 它会重新加载注册表单 不会打印任何错误 并且不会将数据插入数据库中 这是注册表的外观 这里是移民文件代码 public function up Schema create user
  • 在 Laravel 中按数据透视表 create_at 排序

    在我的数据库中 我有以下表格 courses id 名称 创建时间 更新时间 students id 名称 创建时间 更新时间 课程 学生 id course id student id created at updated at 我正在尝
  • 获取目录中最后修改的文件

    有没有办法只选择目录中的最后一个文件 扩展名jpg png gif 或者我是否必须解析整个目录并使用进行检查filemtime 是的 你必须通读它们 但由于目录访问已被缓存 因此您不必真正担心它 files array merge glob
  • MySQL:“您的 SQL 语法错误...靠近键...”? [关闭]

    Closed 这个问题是无法重现或由拼写错误引起 help closed questions 目前不接受答案 我发现了一个非常酷的用于丢失密码的脚本 但是这一行给我带来了问题 r mysql query INSERT INTO keys u
  • Mandrill 验证错误

    很高兴能在 StackOverflow 上提出我的第一个问题 多年来我一直依靠它自学了很多东西 我的问题是这样的 尝试通过 Mandrill 的 API 发送邮件时出现以下错误 status error code 1 name Valida
  • 将单独的月、日和年值转换为时间戳

    我有月份值 1 12 日期值 1 31 和年份值 2010 2011 2012 我还有一个小时值和一个分钟值 我怎样才能把这个给strtotime 它可以以某种方式将其转换为时间戳吗 当您已经知道年月和日期时 为什么将字符串转换为日期 us
  • PHP URL 验证

    我知道有无数的线程问这个问题 但我一直无法找到一个可以帮助我解决这个问题的线程 我基本上试图解析大约 10 000 000 个 URL 的列表 确保它们根据以下标准有效 然后获取根域 URL 此列表包含您能想象到的几乎所有内容 包括类似的内
  • 使用 Flot、html、PHP 和 MySql 查询绘制多个图表

    我正在尝试使用 Flot html PHP 和 MySql 查询绘制多个图表 但我陷入了困境 因为我找不到在同一个 html 页面中绘制多个 flot 的方法 为简单起见 在数据库 test db3 映像中包含以下字段 表1 用户名 发送邮
  • 由于未定义符号,PECL solr 未加载:curl_easy_getinfo

    我正在尝试加载 PECL solr 扩展 我尝试使用 pecl install solr 并下载并使用 phpize configure make 来安装它 在这两种情况下 扩展安装时都没有错误 但在 apache 重新启动后 或在命令行上
  • __callStatic():从静态上下文实例化对象?

    我对 PHP 中的 静态 和 动态 函数和对象如何协同工作感到困惑 特别是在 callStatic 方面 callStatic 的工作原理 您可以有一个普通的班级 MyClass 在班级内您可以 放置一个名为 callStatic 的静态函
  • MYSQL 的 Google OAuth 2.0 用户 ID 数据类型

    我正在实施 Google OAuth 2 0 并注意到 Google OAuth 返回的唯一用户 ID 是21位数字长的 我想大整数 20 足以满足这种需求 但我现在看到 Google OAuth 返回的用户 ID 的长度感到困惑 关于我应

随机推荐

  • 如何让 VS 2008 停止强制命名空间缩进?

    我从来都不太喜欢大多数编辑器处理名称空间的方式 他们总是强迫你添加额外的东西无意义压痕级别 例如 我在一个页面中有很多代码 我更喜欢将其格式化为 namespace mycode class myclass void function fo
  • golang:在 Windows 上运行 pdf 文件的默认应用程序

    我想使用默认应用程序在文件系统中打开 PDF 文件 我怎样才能做到这一点 在命令行中 我只需编写 pdf 文件的文件名 应用程序就会打开 包含请求的文件 当我尝试使用时exec Command 我收到一个错误 毫不奇怪 exec foo p
  • v-model 不支持输入类型=“文件”

    我不能使用v model对于文件输入 Vue 说我必须使用v on change 好的 我可以使用v on change 但是如何将输入文件的 内容 绑定到data财产 假设我想将它绑定到一个组件中this file export defa
  • 片段中的片段不刷新

    这是我的应用程序 带有片段 左侧有一个ListView 您可以在其中进行选择 如果您选择了右侧之一 则加载一个片段并将选项卡添加到 ActionBar 有这样的代码 import java util ArrayList import and
  • 实现多个用户角色

    我使用 state machine 取得了巨大的成功 并且喜欢它通过几行代码动态创建的类方法 但是 我不确定如何继续我正在创建的系统 我目前正在开发一个用户具有多种角色的系统 所以这并不像拥有一个状态来自的用户那么简单未证实 to 确认的然
  • php cURL 脚本在打印返回字符串时运行两次

    我有以下脚本 在远程 php 脚本中 一条记录被添加到数据库表中 当我在这个脚本中留下最后一行 print html 时 添加了 2 条记录 当我省略该行时 仅添加一条记录 但显然我没有任何输出 如果我将输出写入文件 则仅添加一条记录 输出
  • 无法加载类型“MediatR.ServiceFactory”

    我正在创建一个 Api 并且也在使用 mediatR 我已经创建了命令 查询 处理程序 但是当我尝试启动我的 Api 时 我在程序类中收到此错误消息 Could not load type MediatR ServiceFactory fr
  • Keras:一维输入的卷积层

    我无法为一维输入向量构建 CNN 输入值示例 df x iloc 300 Out 33 0 0 571429 1 1 000000 2 0 971429 3 0 800000 4 1 000000 5 0 142857 6 0 657143
  • 如何在 Cypress.io 中等待 WebSocket STOMP 消息

    在我的一项测试中 我想等待 WebSocket STOMP 消息 Cypress io 可以做到这一点吗 如果您要访问的 websocket 是由您的应用程序建立的 您可以遵循以下基本过程 获取参考WebSocket来自测试内部的实例 将事
  • jQuery插件回调函数参数

    我正在寻找一种更好的方法来访问 管理插件回调函数内的数据 我想做与 jQuery UI 相同的事情 用户界面示例 我想如何做到这一点 http api jqueryui com sortable http api jqueryui com
  • Perl 单行代码匹配所有出现的正则表达式

    对于类似这样的多行文本 views panes gw hero small site placement panel pane 1 1 a 0 a 10 s 14 override title i 1 s 19 override title
  • 使用“is”来命名布尔变量是不好的做法吗?

    现在命名以 is 开头的布尔值是不好的做法吗 我的经理认为 isAnything 已经过时且糟糕的做法 这是真的 myManager isLame correct incorrect 它在很多语言中都经常使用 但我不知道是否可以肯定地说它是
  • 团队中审批应用程序的 API - 是否有任何其他 API 可用于团队中新的审批应用程序?

    是否有任何 REST API 可用于团队中的新审批应用程序 在 Microsoft Teams 中发送 接收 管理和共享批准 您创建 管理和共享的所有系统的审批中心 能够在 Microsoft Teams 中直接查看并采取行动 快速完成工作
  • Python Matplotlib 动画帧重叠

    I am working on my orbit program and I have currently only animated the moon with a downward y velocity of 1023 The anim
  • 实体框架 - 对象上下文的关闭

    在使用 EFProfiler 顺便说一句 绝对是很棒的工具 对我们的一些实体框架应用程序进行分析后 似乎在大多数情况下 所有对象上下文都没有关闭 例如 在本地运行后 EF Profiler 告诉我有326对象上下文已打开 但只有 1 个被关
  • Keras 自定义损失函数不打印张量值

    我正在编写一个简单的损失函数 其中我必须将张量转换为 numpy 数组 这是必需的 我只是想打印张量的值 但收到此错误 张量 loss activation 4 loss Print 0 shape 224 224 2 数据类型 float
  • 如何通过 Mercurial 命令行获取所有关闭的分支?

    在命令行中 我可以通过以下方式获取没有闭合分支的所有头 hg heads 我还可以通过以下方式获取所有具有闭合分支的头 hg heads closed 但是 我如何通过命令行知道所有关闭的分支 RTM hg help revsets hg
  • Node.js:客户端模板与服务器端模板

    我已经尝试学习 Node js 几天了 但有一件事情我很困惑 JQuery 模板等客户端模板解决方案与 Jade for Node js 等服务器端解决方案之间有什么区别 各有什么用途 它们用在哪里 它们可以一起使用吗 如果有的话 有没有两
  • 使用“IN”命令将数组作为参数传递给 SQL 查询

    大家下午好 我有一个关于 SQL 查询的问题 是否可以使用数组作为使用 IN 命令的查询的参数 例如 int x 2 3 4 5 UPDATE table name set field 数据 WHERE field ID IN x 我问这个
  • Auth.net 捕获问题

    我在 auth net 上捕获交易的函数是 public function capture Varien Object payment amount if this gt isEnabled return parent capture pa