Reply
Member
sam_smith
Posts: 6
Registered: ‎11-21-2009

Validate the Credit Card Number,Cvv code and Expairy Date

HI All,

 

I have been using CIM authorization.They provide all the methods in the sample code except validate the customer credit card information.Could any one give the code in C# to validate the credit card number,cvv code and expiary date?

Trusted Contributor
itdevworks
Posts: 165
Registered: ‎09-09-2009

Re: Validate the Credit Card Number,Cvv code and Expairy Date

Are you using SOAP or XML?


Dave Parker
IT DevWorks, LLC
Makers of the I-Bill IT libraries for Authorize.net
Blog: http://www.itdaveworks.com
Twitter: http://twitter.com/rayrad
Site: http://www.itdevworks.com
Member
sam_smith
Posts: 6
Registered: ‎11-21-2009

Re: Validate the Credit Card Number,Cvv code and Expairy Date

Thanks David for Reply.

 

I am using the XML version of their sample code.I have  made a method for validate the customer profile followed the same instructions  in the CIM documents.Its just vaildate the credit card number.I need to validate the CVV code and expiary date also.

 

 

Regards,

 

Sam

Trusted Contributor
itdevworks
Posts: 165
Registered: ‎09-09-2009

Re: Validate the Credit Card Number,Cvv code and Expairy Date

[ Edited ]

validateCustomerPaymentProfileRequest takes up to five values (aside from the merchantAuthentication).  These are:

 

  • customerProfileId
  • customerPaymentProfileId
  • customerShippingAddressId (optional)
  • cardCode (optional)
  • validationMode

The cardCode parameter is the CCV/CVV, and the payment profile already contains the expiration date of the card, so it is possible to validate all three.  In fact, I don't believe you can even create a payment profile without the expiration date.  I grabbed the latest C# sample code[^], and added a new method to the Program class that utilizes the provided validateCustomerPaymentProfileRequest class in the same way that the other "request" classes are used.  Here is that method:

 

/// <summary>
/// Validate the payment profile
/// </summary>
/// <param name="profile_id">
///     The customer profile id we are doing this for</param>
/// <param name="PaymentProfileID">
///     The payment profile id that we are validating</param>
/// <param name="cardCode">
///     The card validation code (CCV) to validate with.  Optional.</param>
/// <returns>
///     <strong>True</strong> if the payment profile validates; Otherwise
///     <strong>False</strong>.
/// </returns>
public static bool ValidateCustomerPaymentProfile(long profile_id,
                                                  string PaymentProfileID,
                                                  string cardCode)
{
    bool out_bool = false;

    // Setup the request
    validateCustomerPaymentProfileRequest request =
        new validateCustomerPaymentProfileRequest();
    XmlAPIUtilities.PopulateMerchantAuthentication((ANetApiRequest)request);

    // Set the properties on the request
    request.customerProfileId = profile_id.ToString();
    request.customerPaymentProfileId = PaymentProfileID;
    request.cardCode = cardCode;
    request.validationMode = validationModeEnum.liveMode;

    // Send the request and get the response
    System.Xml.XmlDocument response_xml = null;
    bool bResult = XmlAPIUtilities.PostRequest(request, out response_xml);
    object response = null;
    validateCustomerPaymentProfileResponse api_response = null;

    // See what the response was
    if (bResult)
    {
        bResult = XmlAPIUtilities.ProcessXmlResponse(response_xml, out response);
    }
    if (!(response is validateCustomerPaymentProfileResponse))
    {
        ANetApiResponse ErrorResponse = (ANetApiResponse)response;
        Console.WriteLine(String.Format(
            "Validate Payment Profile\n	 code: {0}\n	  msg: {1}",
            ErrorResponse.messages.message[0].code,
            ErrorResponse.messages.message[0].text));
        return out_bool;
    }
    if (bResult) api_response = (validateCustomerPaymentProfileResponse)response;
    if (api_response != null)
    {
        out_bool = true;
        Console.WriteLine(String.Format(
            "Validate Payment Profile\n	 code: {0}\n	  msg: {1}",
            api_response.messages.message[0].code,
            api_response.messages.message[0].text));
    }

    return out_bool;
}

 

I was able to compile and run this without problems.  Let me know if you have any problem with this. 

 

IMPORTANT: Please note that on a live account when a validation is submitted with validationMode = "liveMode", then the merchant account associated with the Authorize.net account will be charged transaction fees.  I wrote a blog post[^] about this.  Also, very recently, Visa has imposed rules about validating credit cards.  By using CIM's validateCustomerPaymentProfileRequest feature, you should automatically be in compliance with the new Visa mandates, depending somewhat on the payment processor used by your merchant service provider.  You can read the full details of this in this forum announcement[^]. 


Dave Parker
IT DevWorks, LLC
Makers of the I-Bill IT libraries for Authorize.net
Blog: http://www.itdaveworks.com
Twitter: http://twitter.com/rayrad
Site: http://www.itdevworks.com
Member
sam_smith
Posts: 6
Registered: ‎11-21-2009

Re: Validate the Credit Card Number,Cvv code and Expairy Date

Thanks David 

 

I implemented the same code given by you.But i entered the wrong cvv code ,its show the message the successfull.

 

Here is some content of response that i got.

 

1,1,1,(TESTMODE) This transaction has been approved.,000000,P,0,none,Test transaction for ValidateCustomerPaymentProfile.,1.00,CC,auth_only,

 

My account in the test mode and i am testing visa card.Please tell if i need to do some other settings in the my account.

The code just test the credit card number is valid,or not valid,but not the  cvv code.

 

Regards

 

Sam 

Trusted Contributor
itdevworks
Posts: 165
Registered: ‎09-09-2009

Re: Validate the Credit Card Number,Cvv code and Expairy Date

If you test against the Test Server (using your test account), your account is in Test Mode, or you set the validationMode to "testMode", then Authorize.net will not actually submit the validation request to the payment processor so the full card is not actually validated.  Try validating a card using your Live Account, with Test Mode disabled, and the validationMode set to "liveMode".

 

I actually also have a blog post[^] on the various meanings of "live" vs. "test", in the context of Authorize.net, if any of my terminology here is not clear.


Dave Parker
IT DevWorks, LLC
Makers of the I-Bill IT libraries for Authorize.net
Blog: http://www.itdaveworks.com
Twitter: http://twitter.com/rayrad
Site: http://www.itdevworks.com
Member
aparikh
Posts: 2
Registered: ‎12-18-2011

Re: Validate the Credit Card Number,Cvv code and Expairy Date

Hi,

 

I am trying to call ValidateCustomerPaymentProfile to validate payment profile for my customer. I am using SOAP and not xml and calling webmethod directly. webmethod defination says that customershippingAddressID is long input.

 

But when i try to pass 0 as a parameter(considering it's optional) its giving me e00040 error.

 

And I cannot leave it blank as I am directly calling api's webmethod which is expecting long value in it. 

 

Is any other value i need to pass it for this webmethod to work?

 

Please help.

 

Thanks,

Aparikh

Expert
RaynorC1emen7
Posts: 3,103
Registered: ‎03-08-2010

Re: Validate the Credit Card Number,Cvv code and Expairy Date

[ Edited ]

It work for me based on the c# soap sample code. With 0 as the shippingaddressID. Did the response message text said is the shippingAddressID?