AuthorizeNet / sdk-dotnet

.Net SDK for Authorize.Net API
Other
149 stars 205 forks source link

Error response codes are not available with Subscription requests. #71

Closed gorgi closed 9 years ago

gorgi commented 9 years ago

Currently, if there is an error, an Invalid Operation Exception is being thrown, with message like: Error processing request: E00013 - Credit Card Number is invalid.

The error codes are not available in a strongly typed manner. The above message is not really user friendly and I would have to parse it to get the error code, which is error prone.

Can you add a strongly typed response for Subscription request instead of throwing an Exception? Our web site is multilanguage, so we need to translate the error codes.

Thanks!

Dthurman commented 9 years ago

I'm investigating your issue and have two questions.

1) Are you using the gateway model ( SubscriptionGateway) or the new controller model (ARBCreateSubscriptionController)?

2) Can you include the line of code where your are executing the request?

Thanks

gorgi commented 9 years ago

I am using the SubscriptionGateway. Here's my simple code:

subscription request The exception's Data field is empty, there is no way to get the error codes.

Dthurman commented 9 years ago

Thanks. I'm able to repro it now.

Dthurman commented 9 years ago

I have reproed the issue, and you are right, error handling is not ideal for the gateway model. We are looking at how to handle the issue.

Going forward, the best approach would be to use the new "Controller" model. Using the new model, your sample would look like this:

    [Test]
    public void TestSubscription_ExpiredCC()
    {
        Random rnd = new Random(DateTime.Now.Millisecond);
        ApiOperationBase<ANetApiRequest, ANetApiResponse>.MerchantAuthentication = CustomMerchantAuthenticationType;
        ApiOperationBase<ANetApiRequest, ANetApiResponse>.RunEnvironment = TestEnvironment;
        //create a subscription
        var subscriptionDef = new ARBSubscriptionType
        {

            paymentSchedule = new paymentScheduleType
            {
                interval = new paymentScheduleTypeInterval
                {
                    length = 7,
                    unit = ARBSubscriptionUnitEnum.days
                },
                startDate = DateTime.UtcNow,
                totalOccurrences = 2,
            },

            amount = 9.99M,
            billTo = new nameAndAddressType
            {
                address = "1234 Elm St NE",
                city = "Bellevue",
                state = "WA",
                zip = "98007",
                firstName = "First",
                lastName = "Last"
            },

            payment = new paymentType
            {
                Item = new creditCardType
                             {
                                 cardCode = "655",
                                 cardNumber = "4007000",
                                 expirationDate = "122013",
                             }
            },

            customer = new customerType { email = "somecustomer@test.org", id = "5", },

            order = new orderType { description = string.Format("member monthly {0}", rnd.Next(99999)) },
        };

        var arbRequest = new ARBCreateSubscriptionRequest { subscription = subscriptionDef };
        var arbController = new ARBCreateSubscriptionController(arbRequest);
        arbController.Execute();

        var arbCreateResponse = arbController.GetApiResponse();

        //If request responds with an error, walk the messages and get code and text for each message.
        if (arbController.GetResultCode() == messageTypeEnum.Error)
        {
            foreach(var msg in arbCreateResponse.messages.message)
            {
                Console.WriteLine("Error Num = {0}, Message = {1}", msg.code, msg.text);
            }
        }
    }
Dthurman commented 9 years ago

I have added a sample to the future branch, that walks through the error messages returned by a failed create subscription request.

Gorgi, does this resolve your issue?

gorgi commented 9 years ago

We switched to the new Controller model. Thanks!