Hello!
I am using CIM from a Ruby on Rails app (Rails 3.1, ruby 1.9.2). I am currently using the sample code to call CreateProfile and GetCustomerProfile. I am working with the test api, and am successfully creating user profiles, sending them to you guys to enter their credit card, and receiving the user back when they complete that process.
I am having trouble parsing the customerPaymentProfileId out of the XML response for GetCustomerProfile. My code for this, which is a shamless edit of the sample code:
def GetCustomerProfile(profileId) # returns paymentProfileId
paymentProfileId = ''
Rails.logger.debug
Rails.logger.debug '---------------------'
Rails.logger.debug 'Getting Customer Profile ...'
xml = SetApiAuthentication($xmlGetCustomerProfile)
xml = xml.sub('@profileId@', profileId)
doc = SendXml(xml)
success = IsSuccess(doc)
if !success
PrintErrors(doc)
else
Rails.logger.debug doc.root
paymentProfileId = REXML::XPath.first(doc.root, '/*/customerPaymentProfileId').text
Rails.logger.debug
Rails.logger.debug 'New customerPaymentProfileId = ' + paymentProfileId
end
return paymentProfileId
end
Watching the logs, I see the response arrive intact. The response passes muster in the IsSuccess() function. I can see the customerPaymentProfileId in there:
<?xml version="1.0" encoding="utf-8"?> <getCustomerProfileResponse 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> <profile> <merchantCustomerId>3333</merchantCustomerId> <description>some description</description> <email>m33333n@gmail.com</email> <customerProfileId>5332967</customerProfileId> <paymentProfiles> <customerPaymentProfileId>4720154</customerPaymentProfileId> <payment> <creditCard> <cardNumber>XXXX0002</cardNumber> <expirationDate>XXXX</expirationDate> </creditCard> </payment> </paymentProfiles> </profile> </getCustomerProfileResponse>
This is returning nil:
REXML::XPath.first(doc.root, '/*/customerPaymentProfileId')
Yet that exact sytax succeeds earlier when processing CreateProfile, in the provided sample code:
def CreateProfile(email) # returns profileId
profileId = ''
Rails.logger.debug
Rails.logger.debug '---------------------'
Rails.logger.debug 'Creating Customer Profile with email = ' + email + ' ...'
xml = SetApiAuthentication($xmlCreateProfile)
xml = xml.sub('@email@', email)
doc = SendXml(xml)
success = IsSuccess(doc)
if !success
PrintErrors(doc)
else
profileId = REXML::XPath.first(doc.root, '/*/customerProfileId').text
Rails.logger.debug
Rails.logger.debug 'New customerProfileId = ' + profileId
end
return profileId
end
Lovely, eh? Any suggestions, fine peoples?
thx!
Mike
10-26-2011 02:36 PM - edited 10-26-2011 02:38 PM
Fixed!
I did not understand how to navigate the XML correctly. Nesting matters, of course. The correct syntax is:
REXML::XPath.first(doc.root, '/*/profile/paymentProfiles/customerPaymentProfileId')
Please move along.
10-26-2011 03:45 PM