Hopefully this is going to be the right place to get some help...
module AuthorizeTransactionManager
require 'authorizenet'
include AuthorizeNet::API
class ANProposedSolution
def initialize
@transaction = Transaction.new(
AUTHORIZE_API_LOGIN,
AUTHORIZE_API_KEY,
:gateway => AUTHORIZE_GATEWAY
)
end
def request_customer_payment_profile
request = GetCustomerPaymentProfileRequest.new
request.customerProfileId = 1507241273
request.customerPaymentProfileId = 1506634046
response = @transaction.get_customer_payment_profile(request)
if response.messages.resultCode == MessageTypeEnum::Ok
response.paymentProfile
else
puts response.messages.messages[0].text
puts "Failed to get payment profile information with ID #{request.customerPaymentProfileId}."
nil
end
end
def update_customer_payment_profile_option_a
current_payment_profile = request_customer_payment_profile
unless current_payment_profile.blank?
current_payment_profile.billTo.firstName = "New firstName"
current_payment_profile.billTo.lastName = "New lastName"
current_payment_profile.billTo.company = "New company"
request = UpdateCustomerPaymentProfileRequest.new(current_payment_profile)
response = @transaction.update_customer_payment_profile(request)
if response.messages.resultCode == MessageTypeEnum::Ok
puts "Successfully updated customer payment profile with ID #{request.paymentProfile.customerPaymentProfileId}."
else
puts response.messages.messages[0].text
# ERROR! => The element 'updateCustomerPaymentProfileRequest' in namespace 'AnetApi/xml/v1/schema/AnetApiSchema.xsd' has invalid child element 'merchantAuthentication' in namespace 'AnetApi/xml/v1/schema/AnetApiSchema.xsd'. List of possible elements expected: 'clientId, refId, customerProfileId' in namespace 'AnetApi/xml/v1/schema/AnetApiSchema.xsd'.
puts "Failed to update customer with customer payment profile ID #{request.paymentProfile.customerPaymentProfileId}."
# ERROR! => NoMethodError: undefined method `customerPaymentProfileId' for nil:NilClass
end
else
puts "Failed to get payment profile information"
end
end
def update_customer_payment_profile_option_b
current_payment_profile = request_customer_payment_profile
unless current_payment_profile.blank?
current_payment_profile.billTo.firstName = "New firstName"
current_payment_profile.billTo.lastName = "New lastName"
current_payment_profile.billTo.company = "New company"
request = UpdateCustomerPaymentProfileRequest.new
payment = PaymentType.new(current_payment_profile.payment)
profile = CustomerPaymentProfileExType.new(nil,current_payment_profile.billTo,payment,nil,nil)
request.paymentProfile = profile
request.customerProfileId = current_payment_profile.customerProfileId
profile.customerPaymentProfileId = current_payment_profile.customerPaymentProfileId
response = @transaction.update_customer_payment_profile(request)
if response.messages.resultCode == MessageTypeEnum::Ok
puts "Successfully updated customer payment profile with ID #{request.paymentProfile.customerPaymentProfileId}."
else
puts response.messages.messages[0].text
# ERROR! => The element 'creditCard' in namespace 'AnetApi/xml/v1/schema/AnetApiSchema.xsd' has invalid child element 'creditCard' in namespace 'AnetApi/xml/v1/schema/AnetApiSchema.xsd'. List of possible elements expected: 'cardNumber' in namespace 'AnetApi/xml/v1/schema/AnetApiSchema.xsd'.
puts "Failed to update customer with customer payment profile ID #{request.paymentProfile.customerPaymentProfileId}."
end
else
puts "Failed to get payment profile information"
end
end
end
end
I know is a long story... I just want to give you the whole picture...
Any help? Thanks!
Solved! Go to Solution.
04-26-2019 02:34 PM
Hi @asaavedra ,
In your post you are mentioning that you are getting an error -"The element 'creditCard' in namespace 'AnetApi/xml/v1/schema/AnetApiSchema.xsd' has invalid child element 'cardType' in namespace" when you pass the card information that comes back from GetCustomerPaymentProfileRequest. The GetCustomerPaymentProfileResponse will have payment information like below:
<payment> <creditCard> <cardNumber> XXXX1733 </cardNumber> <expirationDate> XXXX </expirationDate> <cardType> Visa </cardType> </creditCard> </payment>
But when you make the UpdateCustomerPaymentProfileRequest in the payment information only pass the cardNumber and expirationDate like this:
<payment> <creditCard> <cardNumber> XXXX1733 </cardNumber> <expirationDate> XXXX </expirationDate> </creditCard> </payment>
04-29-2019 10:20 PM
Hi @asaavedra,
Do not pass the cardType field in the UpdateCustomerPaymentProfileRequest. You can copy the billTo and payment from getCustomerPaymentProfileResponse to the UpdateCustomerPaymentProfileRequest. Make your changes in billTo and remove cardType from payment. This is a sample UpdateCustomerPaymentProfileRequest using the default test merchant credentials from https://developer.authorize.net/api/reference/index.html:
<updateCustomerPaymentProfileRequest xmlns="AnetApi/xml/v1/schema/AnetApiSchema.xsd"> <merchantAuthentication> <name>4vzCzTK46uB</name> <transactionKey>4eT533qH5xD4v62S</transactionKey> </merchantAuthentication> <customerProfileId>36227533</customerProfileId> <paymentProfile> <billTo> <firstName>fasfghjk</firstName> <lastName>gfsakjdhf</lastName> <address>kajshfg</address> <city>kfjasdfghk</city> <state>fjkshadf</state> <zip>566666</zip> <country>Jamaica</country> <phoneNumber>123141666</phoneNumber> </billTo> <payment> <creditCard> <cardNumber> XXXX1733 </cardNumber> <expirationDate> XXXX </expirationDate> </creditCard> </payment> <customerPaymentProfileId>1831340201</customerPaymentProfileId> </paymentProfile> </updateCustomerPaymentProfileRequest>
04-28-2019 11:38 PM
Hi @rahulr!
Thanks so much for your help!
Currently, I am developing in RoR and due to this I have followed the Sample Code > Ruby (this is the GitHub source) and I have examined the rubydoc about the AuthorizeNet gem and the method UpdateCustomerPaymentProfileRequest requires a CustomerPaymentProfileExType (=paymentProfile) object. If I do not send the PaymentType object I receive the following error "Failed to update payment profile ID XXXX. Payment information is required".
Or probably I am not understanding your comment about "cardType", I don't see that reference in my code neither in the sample UpdateCustomerPaymentProfileRequest.
Or are you recommending me not use the Gem and instead use XML requests?
Thanks so much for your time and answer!
04-29-2019 10:06 AM
Hi @asaavedra ,
In your post you are mentioning that you are getting an error -"The element 'creditCard' in namespace 'AnetApi/xml/v1/schema/AnetApiSchema.xsd' has invalid child element 'cardType' in namespace" when you pass the card information that comes back from GetCustomerPaymentProfileRequest. The GetCustomerPaymentProfileResponse will have payment information like below:
<payment> <creditCard> <cardNumber> XXXX1733 </cardNumber> <expirationDate> XXXX </expirationDate> <cardType> Visa </cardType> </creditCard> </payment>
But when you make the UpdateCustomerPaymentProfileRequest in the payment information only pass the cardNumber and expirationDate like this:
<payment> <creditCard> <cardNumber> XXXX1733 </cardNumber> <expirationDate> XXXX </expirationDate> </creditCard> </payment>
04-29-2019 10:20 PM
Hi @rahulr.
OMG! I am so sorry! I totally forgot my firsts attempts to solve this and I was just focused into the last class I posted (ANProposedSolution)... and... THANK YOU SO MUCH!!! Your solution works! I am almost sure that I tried what you proposed before posting my problem here but I can't remember what happened... but... THANK YOU SOOO MUCH!!!
The following is the method that I created (added to the ANProposedSolution class) using your solution and it works perfectly!
... def update_customer_payment_profile_solution current_payment_profile = request_customer_payment_profile cc_data = request_customer_payment_profile.payment.creditCard unless current_payment_profile.blank? current_payment_profile.billTo.firstName = "New firstName" current_payment_profile.billTo.lastName = "New lastName" current_payment_profile.billTo.company = "New company" request = UpdateCustomerPaymentProfileRequest.new payment = PaymentType.new(CreditCardType.new(cc_data.cardNumber, cc_data.expirationDate)) profile = CustomerPaymentProfileExType.new(nil,current_payment_profile.billTo,payment,nil,nil) request.paymentProfile = profile request.customerProfileId = current_payment_profile.customerProfileId profile.customerPaymentProfileId = current_payment_profile.customerPaymentProfileId response = @transaction.update_customer_payment_profile(request) if response.messages.resultCode == MessageTypeEnum::Ok puts "Successfully updated customer payment profile with ID #{request.paymentProfile.customerPaymentProfileId}." else puts response.messages.messages[0].text puts "Failed to update customer with customer payment profile ID #{request.paymentProfile.customerPaymentProfileId}." end else puts "Failed to get payment profile information" end end ...
05-06-2019 11:39 AM
@asaavedra I'd like to thank you for this very thourough post and also for documenting the solution with the code. It helped me a lot to succeed update a customer payment profile without requesting payment information again.
Cheers!
09-29-2021 08:55 AM
Thanks for sharing such a helpful instruction, really appreciate for your article.
10-01-2021 03:16 AM