Reply
Member
Posts: 2
Registered: ‎08-02-2021
Accepted Solution

Error when integrating Authorize.Net C# SDK into Unity in Builds

TLDR: Sample credit card charging code does not work in builds of a mobile app made in Unity due to function call in precompiled dll of Authorize.Net C# SDK. Please help!

 

Description of Situation:

I needed to implement payment processing myself into our mobile application because the various app stores do not allow using the various existing services for in-app purchasing to sell physical goods (which is the primary goal of the app). This led me to Authorize.Net which seemed to have a fairly comprehensive set of c# based payment handling services as well as a github with sample code. I created a sandbox account, and plan to switch to the full account before launching our beta. I installed the sdk from here: https://github.com/AuthorizeNet/sdk-dotnet and used a modified version of this: https://github.com/AuthorizeNet/sample-code-csharp/blob/master/PaymentTransactions/ChargeCreditCard.... sample code for testing, which worked when running the app in the Unity Editor just fine. When I build the app to a mobile device (tested on both android and ios) and attempt the same credit card transaction as worked in the editor, I get an error saying that there is an unsupported function call to System.Configuration.ConfigurationManager::get_AppSettings() within the Authorize.Net sdk .dll file (full error message below). The installed SDK is in the form of a precompiled .dll file, so I'm not really sure how to look through the code inside to diagnose and fix the problem. My first thought was that this might be some sort of .NET version compatability issue, but as I am working in Unity, I have a very limited ability to affect the .NET version being used by my app. Can anyone please help me with this? I did contact developer support with this and their response was basically "your problem is outside the scope of the support we offer, go ask the forums".


Full Error Message:

Autoconnected Player NotSupportedException:
System.Configuration.ConfigurationManager::get_AppSettings
  at System.Configuration.ConfigurationManager.get_AppSettings () [0x00000]
in <00000000000000000000000000000000>:0
  at AuthorizeNet.Environment.GetProperty (System.String propertyName)
[0x00000] in <00000000000000000000000000000000>:0
  at AuthorizeNet.Environment.getBooleanProperty (System.String
propertyName) [0x00000] in <00000000000000000000000000000000>:0
  at AuthorizeNet.Util.HttpUtility..cctor () [0x00000] in
<00000000000000000000000000000000>:0
  at AuthorizeNet.Api.Controllers.Bases.ApiOperationBase`2[TQ,TS].Execute
(AuthorizeNet.Environment environment) [0x00000] in
<00000000000000000000000000000000>:0
  at JPurchasePlugin.AuthNetFunctions_Credit.ValidateAndCapture
(System.Decimal amount, System.String cardNumber, System.String
cardExpirationDate) [0x00000] in <00000000000000000000000000000000>:0
  at JPurchasePlugin.AsyncTransaction_Credit.OnInformationValid ()
[0x00000] in <00000000000000000000000000000000>:0
  at JPurchasePlugin.AsyncTransaction.OnInformationSubmitted
(JPurchasePlugin.PurchaseInformation information,
JPurchasePlugin.TransactionResultCallback callback) [0x00000] in
<00000000000000000000000000000000>:0
  at PurchaseWindowController.TrySubmitPaymentInformation
(JPurchasePlugin.PurchaseInformation information) [0x00000] in
<00000000000000000000000000000000>:0
  at JPurchasePlugin.InformationInput.Submit () [0x00000] in
<00000000000000000000000000000000>:0
  at UnityEngine.Events.InvokableCall.Invoke () [0x00000] in
<00000000000000000000000000000000>:0
  at UnityEngine.Events.UnityEvent.Invoke () [0x00000] in
<00000000000000000000000000000000>:0
  at UnityEngine.UI.Button.Press () [0x00000] in
<00000000000000000000000000000000>:0
  at UnityEngine.UI.Button.OnPointerClick
(UnityEngine.EventSystems.PointerEventData eventData) [0x00000] in
<00000000000000000000000000000000>:0
  at UnityEngine.EventSystems.ExecuteEvents.Execute
(UnityEngine.EventSystems.IPointerClickHandler handler,
UnityEngine.EventSystems.BaseEventData eventData) [0x00000] in
<00000000000000000000000000000000>:0
  at UnityEngine.EventSystems.ExecuteEvents.Execute[T]
(UnityEngine.GameObject target, UnityEngine.EventSystems.BaseEventData
eventData, UnityEngine.EventSystems.ExecuteEvents+EventFunction`1[T1]
functor) [0x00000] in <00000000000000000000000000000000>:0
  at UnityEngine.EventSystems.StandaloneInputModule.ProcessTouchPress
(UnityEngine.EventSystems.PointerEventData pointerEvent, System.Boolean
pressed, System.Boolean released) [0x00000] in
<00000000000000000000000000000000>:0
  at UnityEngine.EventSystems.StandaloneInputModule.ProcessTouchEvents ()
[0x00000] in <00000000000000000000000000000000>:0
  at UnityEngine.EventSystems.StandaloneInputModule.Process () [0x00000] in
<00000000000000000000000000000000>:0
  at UnityEngine.EventSystems.EventSystem.Update () [0x00000] in
<00000000000000000000000000000000>:0
Rethrow as TypeInitializationException: The type initializer for
'AuthorizeNet.Util.HttpUtility' threw an exception.
  at AuthorizeNet.Api.Controllers.Bases.ApiOperationBase`2[TQ,TS].Execute
(AuthorizeNet.Environment environment) [0x00000] in
<00000000000000000000000000000000>:0
  at JPurchasePlugin.AuthNetFunctions_Credit.ValidateAndCapture
(System.Decimal amount, System.String cardNumber, System.String
cardExpirationDate) [0x00000] in <00000000000000000000000000000000>:0
  at JPurchasePlugin.AsyncTransaction_Credit.OnInformationValid ()
[0x00000] in <00000000000000000000000000000000>:0
  at JPurchasePlugin.AsyncTransaction.OnInformationSubmitted
(JPurchasePlugin.PurchaseInformation information,
JPurchasePlugin.TransactionResultCallback callback) [0x00000] in
<00000000000000000000000000000000>:0
  at PurchaseWindowController.TrySubmitPaymentInformation
(JPurchasePlugin.PurchaseInformation information) [0x00000] in
<00000000000000000000000000000000>:0
  at JPurchasePlugin.InformationInput.Submit () [0x00000] in
<00000000000000000000000000000000>:0
  at UnityEngine.Events.InvokableCall.Invoke () [0x00000] in
<00000000000000000000000000000000>:0
  at UnityEngine.Events.UnityEvent.Invoke () [0x00000] in
<00000000000000000000000000000000>:0
  at UnityEngine.UI.Button.Press () [0x00000] in
<00000000000000000000000000000000>:0
  at UnityEngine.UI.Button.OnPointerClick
(UnityEngine.EventSystems.PointerEventData eventData) [0x00000] in
<00000000000000000000000000000000>:0
  at UnityEngine.EventSystems.ExecuteEvents.Execute
(UnityEngine.EventSystems.IPointerClickHandler handler,
UnityEngine.EventSystems.BaseEventData eventData) [0x00000] in
<00000000000000000000000000000000>:0
  at UnityEngine.EventSystems.ExecuteEvents.Execute[T]
(UnityEngine.GameObject target, UnityEngine.EventSystems.BaseEventData
eventData, UnityEngine.EventSystems.ExecuteEvents+EventFunction`1[T1]
functor) [0x00000] in <00000000000000000000000000000000>:0
  at UnityEngine.EventSystems.StandaloneInputModule.ProcessTouchPress
(UnityEngine.EventSystems.PointerEventData pointerEvent, System.Boolean
pressed, System.Boolean released) [0x00000] in
<00000000000000000000000000000000>:0
  at UnityEngine.EventSystems.StandaloneInputModule.ProcessTouchEvents ()
[0x00000] in <00000000000000000000000000000000>:0
  at UnityEngine.EventSystems.StandaloneInputModule.Process () [0x00000] in
<00000000000000000000000000000000>:0
  at UnityEngine.EventSystems.EventSystem.Update () [0x00000] in
<00000000000000000000000000000000>:0
UnityEngine.DebugLogHandler:LogException(Exception, Object)
UnityEngine.Logger:LogException(Exception, Object)
UnityEngine.Debug:LogException(Exception)
UnityEngine.EventSystems.ExecuteEvents:Execute(GameObject, BaseEventData,
EventFunction`1)
UnityEngine.EventSystems.StandaloneInputModule:ProcessTouchPress(PointerEventData,
Boolean, Boolean)
UnityEngine.EventSystems.StandaloneInputModule:ProcessTouchEvents()
UnityEngine.EventSystems.StandaloneInputModule:Process()
UnityEngine.EventSystems.EventSystem:Update()
ref:_00DF07nRI._5004Q2JF9Z3:ref


Accepted Solutions
Highlighted
Solution
Accepted by topic author H0MMUSVAMP1RE
‎08-04-2021 06:51 AM
Member
Posts: 2
Registered: ‎08-02-2021

Re: Error when integrating Authorize.Net C# SDK into Unity in Builds

I did figure out this problem. I had to pull the full sdk code from the github, make a few tweaks and build it on my end but it seems to be working now. In case anyone has this exact issue in the future, the problem fortunately occurred in a function with a built in alternative to the function call that was not implemented. In Environment.cs, the method Environment.GetProperty() there is an attempt to access ConfigurationManager.AppSettings which for some unknown reason is not supported in Unity. Wrapping the if statement that reads AppSettings and assigns to propValue in a try/catch block fixed the issue since this means that if ConfigurationManager.AppSettings is not defined, then the relevant property will be retrieved from System.Environment.GetEnvironmentVariable() instead (already set up).

View solution in original post


All Replies
Highlighted
Solution
Accepted by topic author H0MMUSVAMP1RE
‎08-04-2021 06:51 AM
Member
Posts: 2
Registered: ‎08-02-2021

Re: Error when integrating Authorize.Net C# SDK into Unity in Builds

I did figure out this problem. I had to pull the full sdk code from the github, make a few tweaks and build it on my end but it seems to be working now. In case anyone has this exact issue in the future, the problem fortunately occurred in a function with a built in alternative to the function call that was not implemented. In Environment.cs, the method Environment.GetProperty() there is an attempt to access ConfigurationManager.AppSettings which for some unknown reason is not supported in Unity. Wrapping the if statement that reads AppSettings and assigns to propValue in a try/catch block fixed the issue since this means that if ConfigurationManager.AppSettings is not defined, then the relevant property will be retrieved from System.Environment.GetEnvironmentVariable() instead (already set up).

Member
Posts: 3
Registered: ‎08-20-2021

Re: Error when integrating Authorize.Net C# SDK into Unity in Builds

Thank you for sharing. i am sharing this on pc with my friends.