我在 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] => abc@aol.com
[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
当我尝试通过 mag admin 创建发票和捕获交易时,出现错误
网关错误:需要有效的引用交易 ID。
我想知道为什么会发生这种情况..有人可以帮助我>?有什么想法吗?
我的盘子形式是 Magento Enterpise (1.12.x),我正在尝试使用的扩展是 Elayers(我没有购买它,为某人工作)
最佳答案
当您在使用的 Magento 版本中加载模型时,TransctionID 会被隐藏。尝试在加载模型时使用 ->addFieldToSelect('transaction_id') 。这样做的原因是因为它是一个 protected 数据属性,永远不应该按照您在此处尝试的方式直接处理。
或者,您确实应该使用 Magento 从销售订单模型创建发票的能力。
$order = Mage::getModel('sales/order');
$service = Mage::getModel('sales/service_order' , $order);
$service->prepareInvoice();
prepareInvoice 采用 ('sku' => 'qty') 的可选数组
这使得管理每个订单的多张发票的可能性变得容易。
关于php - 捕获时的 Auth.net 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14328475/
作为我的Rails应用程序的一部分,我编写了一个小导入程序,它从我们的LDAP系统中吸取数据并将其塞入一个用户表中。不幸的是,与LDAP相关的代码在遍历我们的32K用户时泄漏了大量内存,我一直无法弄清楚如何解决这个问题。这个问题似乎在某种程度上与LDAP库有关,因为当我删除对LDAP内容的调用时,内存使用情况会很好地稳定下来。此外,不断增加的对象是Net::BER::BerIdentifiedString和Net::BER::BerIdentifiedArray,它们都是LDAP库的一部分。当我运行导入时,内存使用量最终达到超过1GB的峰值。如果问题存在,我需要找到一些方法来更正我的代
我想为Heroku构建一个Rails3应用程序。他们使用Postgres作为他们的数据库,所以我通过MacPorts安装了postgres9.0。现在我需要一个postgresgem并且共识是出于性能原因你想要pggem。但是我对我得到的错误感到非常困惑当我尝试在rvm下通过geminstall安装pg时。我已经非常明确地指定了所有postgres目录的位置可以找到但仍然无法完成安装:$envARCHFLAGS='-archx86_64'geminstallpg--\--with-pg-config=/opt/local/var/db/postgresql90/defaultdb/po
尝试通过RVM将RubyGems升级到版本1.8.10并出现此错误:$rvmrubygemslatestRemovingoldRubygemsfiles...Installingrubygems-1.8.10forruby-1.9.2-p180...ERROR:Errorrunning'GEM_PATH="/Users/foo/.rvm/gems/ruby-1.9.2-p180:/Users/foo/.rvm/gems/ruby-1.9.2-p180@global:/Users/foo/.rvm/gems/ruby-1.9.2-p180:/Users/foo/.rvm/gems/rub
是的,我知道最好使用webmock,但我想知道如何在RSpec中模拟此方法:defmethod_to_testurl=URI.parseurireq=Net::HTTP::Post.newurl.pathres=Net::HTTP.start(url.host,url.port)do|http|http.requestreq,foo:1endresend这是RSpec:let(:uri){'http://example.com'}specify'HTTPcall'dohttp=mock:httpNet::HTTP.stub!(:start).and_yieldhttphttp.shou
我的最终目标是安装当前版本的RubyonRails。我在OSXMountainLion上运行。到目前为止,这是我的过程:已安装的RVM$\curl-Lhttps://get.rvm.io|bash-sstable检查已知(我假设已批准)安装$rvmlistknown我看到当前的稳定版本可用[ruby-]2.0.0[-p247]输入命令安装$rvminstall2.0.0-p247注意:我也试过这些安装命令$rvminstallruby-2.0.0-p247$rvminstallruby=2.0.0-p247我很快就无处可去了。结果:$rvminstall2.0.0-p247Search
由于fast-stemmer的问题,我很难安装我想要的任何rubygem。我把我得到的错误放在下面。Buildingnativeextensions.Thiscouldtakeawhile...ERROR:Errorinstallingfast-stemmer:ERROR:Failedtobuildgemnativeextension./System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/bin/rubyextconf.rbcreatingMakefilemake"DESTDIR="cleanmake"DESTDIR=
当我尝试安装Ruby时遇到此错误。我试过查看this和this但无济于事➜~brewinstallrubyWarning:YouareusingOSX10.12.Wedonotprovidesupportforthispre-releaseversion.Youmayencounterbuildfailuresorotherbreakages.Pleasecreatepull-requestsinsteadoffilingissues.==>Installingdependenciesforruby:readline,libyaml,makedepend==>Installingrub
我正在尝试使用boilerpipe来自JRuby。我看过guide从JRuby调用Java,并成功地将它与另一个Java包一起使用,但无法弄清楚为什么同样的东西不能用于boilerpipe。我正在尝试基本上从JRuby中执行与此Java等效的操作:URLurl=newURL("http://www.example.com/some-location/index.html");Stringtext=ArticleExtractor.INSTANCE.getText(url);在JRuby中试过这个:require'java'url=java.net.URL.new("http://www
我意识到这可能是一个非常基本的问题,但我现在已经花了几天时间回过头来解决这个问题,但出于某种原因,Google就是没有帮助我。(我认为部分问题在于我是一个初学者,我不知道该问什么......)我也看过O'Reilly的RubyCookbook和RailsAPI,但我仍然停留在这个问题上.我找到了一些关于多态关系的信息,但它似乎不是我需要的(尽管如果我错了请告诉我)。我正在尝试调整MichaelHartl'stutorial创建一个包含用户、文章和评论的博客应用程序(不使用脚手架)。我希望评论既属于用户又属于文章。我的主要问题是:我不知道如何将当前文章的ID放入评论Controller。
我目前正在使用以下方法获取页面的源代码:Net::HTTP.get(URI.parse(page.url))我还想获取HTTP状态,而无需发出第二个请求。有没有办法用另一种方法做到这一点?我一直在查看文档,但似乎找不到我要找的东西。 最佳答案 在我看来,除非您需要一些真正的低级访问或控制,否则最好使用Ruby的内置Open::URI模块:require'open-uri'io=open('http://www.example.org/')#=>#body=io.read[0,50]#=>"["200","OK"]io.base_ur