1

我正在使用 ActiveMerchant 与 Authorize.net CIM 集成。我正在编写自动化测试,并且我已经开始实施 Webmock 调用,这样我的测试在每次运行时都不会真正访问 Authorize.net。

我已经根据原始请求数据的响应创建了 XML 文件,并且在大多数情况下,它运行良好。但是,当我模拟一个成功的响应时,ActiveMerchant 出于某种原因仍然告诉我 Response.success?不是真的。

我的功能

if self.cim_customer_profile_id.nil?
  ActiveMerchant::Billing::Base.mode = :test

  customer_profile_information = {
    :profile     => {
      :merchant_customer_id => self.customer.username.first(20),
      :email => self.customer.email
    }
  }

  gateway = ActiveMerchant::Billing::AuthorizeNetCimGateway.new(
    :login    => AUTHORIZE_NET_API_LOGIN_ID,
    :password => AUTHORIZE_NET_API_TRANSACTION_KEY
  )

  response = gateway.create_customer_profile(customer_profile_information)

  if response.success?
    self.cim_customer_profile_id = response.authorization
  else
    raise StandardError, response.message
  end
end

然后我的回复是:

HTTP/1.1 200 OK
Content-Type: text/xml; charset=utf-8

<?xml version="1.0" encoding="utf-8"?>
<createCustomerProfileResponse xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns='AnetApi/xml/v1/schema/AnetApiSchema.xsd'>
  <messages>
    <resultCode>
      Ok
    </resultCode>
    <message>
      <code>
        I00001
      </code>
      <text>
        Successful.
      </text>
    </message>
  </messages>
  <customerProfileId>10793616</customerProfileId>
  <customerPaymentProfileIdList/>
  <customerShippingAddressIdList/>
  <validationDirectResponseList/>
</createCustomerProfileResponse>

ActiveMerchant 是否有任何理由无法处理成功的存根请求?还是我错过了 ActiveMerchant 为了注册响应实际上成功而需要的东西?

4

1 回答 1

1

啊,我太笨了。为了便于阅读,我在所有 XML 标记之后添加了新行,但它们干扰了 ActiveMerchant 解析和评估响应的方式。

所以正确的 XML 响应模拟应该是:

HTTP/1.1 200 OK
Content-Type: text/xml; charset=utf-8
<?xml version="1.0" encoding="utf-8"?>
<createCustomerProfileResponse xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns='AnetApi/xml/v1/schema/AnetApiSchema.xsd'>
  <messages>
    <resultCode>Ok</resultCode>
    <message>
      <code>I00001</code>
      <text>Successful.</text>
    </message>
  </messages>
  <customerProfileId>10793616</customerProfileId>
  <customerPaymentProfileIdList/>
  <customerShippingAddressIdList/>
  <validationDirectResponseList/>
</createCustomerProfileResponse>
于 2012-11-27T08:06:41.523 回答