AuthorizeNet / sdk-dotnet

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

Sandbox Accept Hosted Payment Fails #253

Open grantgoodart opened 5 years ago

grantgoodart commented 5 years ago

Including the order property on the transactionRequestType causes payments to fail using the Accept Hosted Sandbox form. I created a new MVC Application in Visual Studio using .NET Framework 4.5.2. The code below works if I use nuget package version 1.9.6, but if I use 1.9.7 this same payment will fail until I remove the transactionRequestType order property.

Global.asax.cs

public class MvcApplication : System.Web.HttpApplication
    {
        protected void Application_Start()
        {
            ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls;
            AreaRegistration.RegisterAllAreas();
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);
        }
    }

HomeController.cs

public class HomeController : Controller
    {
        public ActionResult Index()
        {
            var invoiceId = "18448294934052571560";
            var custacct = "000000000010";
            var custom_data = string.Format("{0}-{1}", invoiceId, custacct);

            ApiOperationBase<ANetApiRequest, ANetApiResponse>.RunEnvironment = AuthorizeNet.Environment.SANDBOX;
            ApiOperationBase<ANetApiRequest, ANetApiResponse>.MerchantAuthentication = new merchantAuthenticationType
            {
                name = "<LoginID>>",
                Item = "<TransactionKey>",
                ItemElementName = ItemChoiceType.transactionKey
            };

            var controller = new getHostedPaymentPageController(new getHostedPaymentPageRequest
            {
                hostedPaymentSettings = new settingType[]
                {
                    new settingType
                    {
                       settingName = "hostedPaymentReturnOptions",
                       settingValue =  string.Format(@"{{""showReceipt"":false,""url"":""{0}""}}",
                       "<Ngrok Address for me>/AuthNetTest/Home/Receipt")
                    },
                    new settingType
                    {
                        settingName = "hostedPaymentButtonOptions",
                        settingValue = "{\"text\":\"Pay\"}"
                    },
                    new settingType
                    {
                        settingName = "hostedPaymentPaymentOptions",
                        settingValue = string.Format(@"{{""cardCodeRequired"": false, ""showCreditCard"": {0}, ""showBankAccount"": {1}}}",
                            "true",
                            "false")
                    },
                    new settingType
                    {
                        settingName = "hostedPaymentSecurityOptions",
                        settingValue = "{\"captcha\": false}"
                    },
                    new settingType
                    {
                        settingName = "hostedPaymentShippingAddressOptions",
                        settingValue = "{\"show\": false, \"required\": false}"
                    },
                    new settingType
                    {
                        settingName = "hostedPaymentBillingAddressOptions",
                        settingValue = "{\"show\": true, \"required\": false}"
                    },
                    new settingType
                    {
                        settingName = "hostedPaymentCustomerOptions",
                        settingValue = "{\"showEmail\": true, \"requiredEmail\": false, \"addPaymentProfile\": false}"
                    }
                },
                transactionRequest = new transactionRequestType
                {
                    amount = 10.00M,
                    transactionType = transactionTypeEnum.authCaptureTransaction.ToString(),
                    order = new orderType
                    {
                        invoiceNumber = invoiceId,
                        description = invoiceId,

                    },
                    userFields = new userField[]
                    {
                        new userField
                        {
                            name = nameof(custom_data),
                            value = custom_data
                        }
                    }

                },

            });

            var hostedPaymentResult =  controller.ExecuteWithApiResponse();
            ViewBag.Token = hostedPaymentResult.token;
            return View();
        }

        public ActionResult Receipt()
        {
            ViewBag.Message = "Payment Finished";

            return View();
        }

Index.cshtml

@{
    ViewBag.Title = "Home Page";
}

<form method="post" action="https://test.authorize.net/payment/payment" id="formAuthorizeNetTestPage" name="formAuthorizeNetTestPage">
    <input type="hidden" name="token" value="@(ViewBag.Token)" />
    Continue to Authorize.Net to Payment Page
    <button id="btnContinue">Continue to next page</button>
</form>
sstalder commented 5 years ago

Just wanted to say I also posted this issue on the samples repository - https://github.com/AuthorizeNet/sample-code-csharp/issues/99

nthomson-choicescreening commented 5 years ago

Running into the same issue with the 2.0.0 release.

I attempted to run the sandbox with the 1.9.7 SDK version. It through the same ambiguous error as described above.

When I backed it down to 1.9.6, it works again. So there is something blowing up in the purchase process for the hosted payment page and whatever that error might be is not being rendered.

gnongsie commented 5 years ago

Hi, Apologies for the inconvenience caused. There seems to be a bug in the way that DateTime values are handled in the C# SDK.

A fix has been sent and is pending release ( #257 ). A temporary workaround for this is to include a valid date for order.purchaseOrderDateUTC in the format "YYYY-mm-dd".

transactionRequest = new transactionRequestType {
        amount = "100.00",
        transactionType = transactionTypeEnum.authCaptureTransaction.ToString(),
        order = new orderType {
            invoiceNumber = invoiceId,
            description = invoiceId,
            purchaseOrderDateUTC = new DateTime(2018, 03, 23, 11, 00, 00, DateTimeKind.Utc)
        }
}
nthomson-choicescreening commented 5 years ago

Sadly, the above workaround does not solve my problem. I am attempting to use the 2.0.0 SDK and it still throws the generic error. Is there any way to find out what the error is that is being thrown?

Kishkumen32 commented 5 years ago

I have tried the above work around, and it has not fixed the issue for me either....

gnongsie commented 5 years ago

Hi, Apologies for the inconvenience. I initially thought that this would fix it.

In any case, I've escalated this to the relevant team and I will keep this thread updated with the progress.

NST77 commented 5 years ago

So sad. After three months, there are no fixes. We are not expecting this from Authorize.net. Only the 1.9.6 version is working fine.

DavideMeneghello commented 4 years ago

Still no fix? happens to me in Italy ( but not with my colleague in USA )

Daxton47 commented 4 years ago

Still no fix for this. Confirmed that rolling back to the 1.9.6 version works correctly. Honestly surprised that the pr (1 line change!) hasn't been merged yet?

ahawes-clarity commented 4 years ago

Any update on what the issue is and when it will get fixed. Can't test a new integration for a client.

sstalder commented 4 years ago

The only way I got around this for now is to exclude the "order" in transactionRequest.

ahawes-clarity commented 4 years ago

The only way I got around this for now is to exclude the "order" in transactionRequest.

Yes, that would work, except I actually need to send order information. I reverted back to 1.9.6 and things seem to be working. I tried 1.9.7 but it didn't work either.

kwhite5 commented 4 years ago

@gnongsie, is there any update on this? It seems there are many developers hoping for a solution.

NST77 commented 4 years ago

@gnongsie, is there any update on this? It seems there are many developers hoping for a solution.

No update... Waiting till May 13th, 2019

m-imran38 commented 3 years ago

It seems that the issue is still not fixed even in version 2.0.1. The only latest working version is 1.9.6