cancel
Showing results for 
Search instead for 
Did you mean: 

I am unable to validate credit card from user

Hi,

Is there anyway that I can check credit card from new user who came to my website? It seems like I am forced to make profile and payment profile as well.
My intention is that, if I give wrong CC number or CCV it still creates my profile in payment gateway when I put wrong credit card.
Any help and API guide? How many steps will be involved in it? I am using CIM.

 

I submitted the data with wrong credit card and below is the response:

 

 

#<AuthorizeNet::CIM::Response:0x00000003bfbe10 @raw_response=#<Net::HTTPOK 200 OK readbody=true>, @transaction=#<AuthorizeNet::CIM::Transaction:0x00000003d70e80 @fields={:method=>"CC", :card_num=>"2334444444", :exp_date=>"01-2017", :validation_mode=>:none, :customer_profile_id=>""}, @api_login_id="47x3vKE6", @api_transaction_key="7b4aE92S6Jtfu4wr", @response=#<AuthorizeNet::CIM::Response:0x00000003bfbe10 ...>, @type="createCustomerPaymentProfileRequest", @verify_ssl=true, @reference_id=nil, @gateway="https://apitest.authorize.net/xml/v1/request.api", @delim_char=",", @encap_char=nil, @custom_fields={}, @xml="<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<createCustomerPaymentProfileRequest xmlns=\"AnetApi/xml/v1/schema/AnetApiSchema.xsd\">\n  <merchantAuthentication>\n    <name>47x3vKE6</name>\n    <transactionKey>7b4aE92S6Jtfu4wr</transactionKey>\n  </merchantAuthentication>\n  <customerProfileId/>\n  <paymentProfile>\n    <payment>\n      <creditCard>\n        <cardNumber>2334444444</cardNumber>\n        <expirationDate>2017-10</expirationDate>\n      </creditCard>\n    </payment>\n  </paymentProfile>\n  <validationMode>none</validationMode>\n</createCustomerPaymentProfileRequest>\n">, @root=#<Nokogiri::XML::Element:0x1dfdb70 name="ErrorResponse" namespace=#<Nokogiri::XML::Namespace:0x1dfd7ec href="AnetApi/xml/v1/schema/AnetApiSchema.xsd"> children=[#<Nokogiri::XML::Element:0x1da662c name="messages" namespace=#<Nokogiri::XML::Namespace:0x1dfd7ec href="AnetApi/xml/v1/schema/AnetApiSchema.xsd"> children=[#<Nokogiri::XML::Element:0x1df9dcc name="resultCode" namespace=#<Nokogiri::XML::Namespace:0x1dfd7ec href="AnetApi/xml/v1/schema/AnetApiSchema.xsd"> children=[#<Nokogiri::XML::Text:0x1d9c988 "Error">]>, #<Nokogiri::XML::Element:0x1d97c6c name="message" namespace=#<Nokogiri::XML::Namespace:0x1dfd7ec href="AnetApi/xml/v1/schema/AnetApiSchema.xsd"> children=[#<Nokogiri::XML::Element:0x1df38f0 name="code" namespace=#<Nokogiri::XML::Namespace:0x1dfd7ec href="AnetApi/xml/v1/schema/AnetApiSchema.xsd"> children=[#<Nokogiri::XML::Text:0x1d8f710 "E00003">]>, #<Nokogiri::XML::Element:0x1df0b8c name="text" namespace=#<Nokogiri::XML::Namespace:0x1dfd7ec href="AnetApi/xml/v1/schema/AnetApiSchema.xsd"> children=[#<Nokogiri::XML::Text:0x1d8e694 "The 'AnetApi/xml/v1/schema/AnetApiSchema.xsd:customerProfileId' element is invalid - The value &#39;&#39; is invalid according to its datatype 'AnetApi/xml/v1/schema/AnetApiSchema.xsd:numericString' - The Pattern constraint failed.">]>]>]>]>, @result_code="Error", @message_code="E00003", @message_text="The 'AnetApi/xml/v1/schema/AnetApiSchema.xsd:customerProfileId' element is invalid - The value &#39;&#39; is invalid according to its datatype 'AnetApi/xml/v1/schema/AnetApiSchema.xsd:numericString' - The Pattern constraint failed.", @reference_id=nil, @customer_profile_id=nil, @customer_payment_profile_id=nil, @customer_payment_profile_id_list=nil, @customer_shipping_address_id_list=nil, @customer_address_id=nil, @validation_direct_response_list=nil, @validation_direct_response=nil, @direct_response=nil, @customer_profile_id_list=nil, @address=nil, @payment_profile=nil, @profile=nil, @token=nil>

Also see here, it created the customer in the account - that is totally wrong.

 

 

 

Below is the case when I gave everything correct and it returned below response (shows success).
 
Its clear the account cretion is done on both success and failure credit card cases.

 

#<AuthorizeNet::CIM::Response:0x007f4976161298 @raw_response=#<Net::HTTPOK 200 OK readbody=true>, @transaction=#<AuthorizeNet::CIM::Transaction:0x007f49762feb28 @fields={:method=>"CC", :card_num=>"5555555555554444", :exp_date=>"01-2018", :validation_mode=>:none, :customer_profile_id=>"1502593898"}, @api_login_id="47x3vKE6", @api_transaction_key="7b4aE92S6Jtfu4wr", @response=#<AuthorizeNet::CIM::Response:0x007f4976161298 ...>, @type="createCustomerPaymentProfileRequest", @verify_ssl=true, @reference_id=nil, @gateway="https://apitest.authorize.net/xml/v1/request.api", @delim_char=",", @encap_char=nil, @custom_fields={}, @xml="<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<createCustomerPaymentProfileRequest xmlns=\"AnetApi/xml/v1/schema/AnetApiSchema.xsd\">\n  <merchantAuthentication>\n    <name>47x3vKE6</name>\n    <transactionKey>7b4aE92S6Jtfu4wr</transactionKey>\n  </merchantAuthentication>\n  <customerProfileId>1502593898</customerProfileId>\n  <paymentProfile>\n    <payment>\n      <creditCard>\n        <cardNumber>5555555555554444</cardNumber>\n        <expirationDate>2017-10</expirationDate>\n      </creditCard>\n    </payment>\n  </paymentProfile>\n  <validationMode>none</validationMode>\n</createCustomerPaymentProfileRequest>\n">, @root=#<Nokogiri::XML::Element:0x3fa4bb0b0794 name="createCustomerPaymentProfileResponse" namespace=#<Nokogiri::XML::Namespace:0x3fa4bb0b05c8 href="AnetApi/xml/v1/schema/AnetApiSchema.xsd"> children=[#<Nokogiri::XML::Element:0x35e2ad8 name="messages" namespace=#<Nokogiri::XML::Namespace:0x3fa4bb0b05c8 href="AnetApi/xml/v1/schema/AnetApiSchema.xsd"> children=[#<Nokogiri::XML::Element:0x3fa4bb09d518 name="resultCode" namespace=#<Nokogiri::XML::Namespace:0x3fa4bb0b05c8 href="AnetApi/xml/v1/schema/AnetApiSchema.xsd"> children=[#<Nokogiri::XML::Text:0x3fa4bb019894 "Ok">]>, #<Nokogiri::XML::Element:0x3fa4bb01913c name="message" namespace=#<Nokogiri::XML::Namespace:0x3fa4bb0b05c8 href="AnetApi/xml/v1/schema/AnetApiSchema.xsd"> children=[#<Nokogiri::XML::Element:0x3fa4bb09be20 name="code" namespace=#<Nokogiri::XML::Namespace:0x3fa4bb0b05c8 href="AnetApi/xml/v1/schema/AnetApiSchema.xsd"> children=[#<Nokogiri::XML::Text:0x3fa4bb01f71c "I00001">]>, #<Nokogiri::XML::Element:0x3fa4bb09a804 name="text" namespace=#<Nokogiri::XML::Namespace:0x3fa4bb0b05c8 href="AnetApi/xml/v1/schema/AnetApiSchema.xsd"> children=[#<Nokogiri::XML::Text:0x3fa4bb01e998 "Successful.">]>]>]>, #<Nokogiri::XML::Element:0x3fa4bb087808 name="customerProfileId" namespace=#<Nokogiri::XML::Namespace:0x3fa4bb0b05c8 href="AnetApi/xml/v1/schema/AnetApiSchema.xsd"> children=[#<Nokogiri::XML::Text:0x3fa4bb0314a8 "1502593898">]>, #<Nokogiri::XML::Element:0x3fa4bb08641c name="customerPaymentProfileId" namespace=#<Nokogiri::XML::Namespace:0x3fa4bb0b05c8 href="AnetApi/xml/v1/schema/AnetApiSchema.xsd"> children=[#<Nokogiri::XML::Text:0x3fa4bb0301c0 "1502127815">]>]>, @result_code="Ok", @message_code="I00001", @message_text="Successful.", @reference_id=nil, @customer_profile_id="1502593898", @customer_payment_profile_id="1502127815", @customer_payment_profile_id_list=nil, @customer_shipping_address_id_list=nil, @customer_address_id=nil, @validation_direct_response_list=nil, @validation_direct_response=nil, @direct_response=nil, @customer_profile_id_list=nil, @address=nil, @payment_profile=nil, @profile=nil, @token=nil>

 

The code I am trying is - Its Ruby code.

 

Could anyone please let me know what needs correction here?

 

def confirm

profile = AuthorizeNet::CIM::CustomerProfile.new(
    :email => "web@web.com",
    :id => "1221",
    :description => "Creating Customer Profile"
)
profile_response = make_connection_to_api.create_profile(profile)
profile_response.profile_id if profile_response.success?
# current_user.update_attribute(:profile_id,profile_response.profile_id)
payment_profile = AuthorizeNet::CIM::PaymentProfile.new(
    :payment_method => AuthorizeNet::CreditCard.new("#{params['credit_card']}", "#{params['month_num']}-#{params['year_num']}")
)
response = make_connection_to_api.create_payment_profile(payment_profile, "#{profile_response.profile_id}")
response.payment_profile_id if response.success?
# current_user.update_attribute(:payment_profile_id,response.payment_profile_id)
puts response.inspect

end

def make_connection_to_api
  AuthorizeNet::CIM::Transaction.new(API_LOGIN, API_KEY, :gateway => :sandbox)
end
webitdev2015
Member
3 REPLIES 3

Hi @webitdev2015,

 

Have a look through our Customer Profiles API examples, specifically the Ruby samples in the "Sample Code" tabs there. The code you're using is using an older deprecated API, and I can't guarantee that it behaves the same way as our current one.

Aaron
All Star

Hi,

 

Per your suggestions from other question I am trying the below code but it giving me very strange error.

 

 

def confirm
    request = AuthorizeNet::API::CreateCustomerProfileRequest.new(nil,nil,nil, validation_mode: 'liveMode')
    payment = AuthorizeNet::API::PaymentType.new(AuthorizeNet::API::CreditCardType.new('4111111111111111', '2020-05'))
    profile = AuthorizeNet::API::CustomerPaymentProfileType.new(nil, nil, payment, nil, nil)
    request.profile = AuthorizeNet::API::CustomerProfileType.new('jdoe'+rand(10000).to_s, 'John2 Doe', rand(10000).to_s + '@mail.com', [profile], nil)

    response = make_connection_to_api.create_customer_profile(request)

    if response.messages.resultCode == AuthorizeNet::API::MessageTypeEnum::Ok
      puts "Successfully created a customer profile with id:  #{response.customerProfileId}"
      puts "Customer Payment Profile Id List:"
      response.customerPaymentProfileIdList.numericString.each do |id|
        puts id
      end
      puts "Customer Shipping Address Id List:"
      response.customerShippingAddressIdList.numericString.each do |id|
        puts id
      end
    else
      puts response.messages.messages[0].text
      puts "Failed to create a new customer profile."
    end
    puts response.inspect
end

def make_connection_to_api
    AuthorizeNet::API::Transaction.new(API_LOGIN, API_KEY, :gateway => :sandbox)
  end

 

The error is:

 

The element 'paymentProfiles' in namespace 'AnetApi/xml/v1/schema/AnetApiSchema.xsd' cannot contain text. List of possible elements expected: 'customerType, billTo, payment, driversLicense, taxId, defaultPaymentProfile' in namespace 'AnetApi/xml/v1/schema/AnetApiSchema.xsd'.
Failed to create a new customer profile.

 

Could anyone please put me in right direction? I am not able to get through it. 

Hi @webitdev2015,

 

I'll take this up in the issue on GitHub: https://github.com/AuthorizeNet/sample-code-ruby/issues/49