سؤال

I'm using ActiveMerchant to integrate with Authorize.net CIM. I'm in the middle of writing up automated tests, and I've begun putting into place Webmock calls so that my tests aren't actually hitting Authorize.net each time that they run.

I've created XML files from the responses of raw request data, and for the most part, it's working well. However, when I mock up a successful response, ActiveMerchant for some reason still tells me that Response.success? is not true.

My function

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

And then my stubbed response is:

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>

Is there any reason why ActiveMerchant won't function with a successful, stubbed, request? Or am I missing something that ActiveMerchant requires in order to register that the response is actually successful?

هل كانت مفيدة؟

المحلول

Ah, I'm so dumb. I added new lines after all of my XML tags for readability, but they're interfering with how ActiveMerchant parses and evaluates the response.

So the correct XML response mock would be:

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>
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top