Reply
Highlighted
Contributor
Posts: 21
Registered: ‎08-10-2017

Hosted Payment Form not displayed correctly when deployed on server

I have been working on this on and off for months and cannot get it to work.  I have code to display the hosted payment page and it is working fine on my development machine.  As soon as I put it on a server (my dev server or my production server) it does not work.   When I run it from my machine All the fields and dropdowns appear properly and everything is aligned properly.  But if I run from a server (either my development server or production server) there are no inputs displayed only things like: Description            {{orderDescription}}

        InvoiceNumber     {{orderInvoiceNumber}}

 

Some of these are in red.

 

I have created a small sample app that reproduces the same results and here is the code for it:

WebForm1.aspx

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    
        <asp:Button ID="Button1" runat="server" Text="Button" />
      
    
    </div>
    </form>
</body>
</html>

WebForm1.aspx.vb:

 

Imports AuthorizeNet.Api.Contracts.V1
imports AuthorizeNet.Api.Controllers.Bases
imports AuthorizeNet.Api.Controllers


Public Class WebForm1
    Inherits System.Web.UI.Page

  
    Private Function PostToURL(strToken As String) As String
        Response.Clear()
        Dim posturl As String = "https://test.authorize.net/payment/payment"
        Dim sb As New StringBuilder
        sb.Append("<html>")
        sb.AppendFormat("<body onload='document.forms[""form""].submit()'>")
        sb.AppendFormat("<form target='payframe' name='form' action='{0}' method='post'>", posturl)
        sb.AppendFormat("<input type='hidden' name'token' value='{0}'>", strToken)
        sb.Append("</form>")
        sb.Append("<iframe style='height: 700px;width:100%;border-style: none;'name='payframe' id='payframe' id='payframe'></iframe>")
        sb.Append("</body>")
        sb.Append("</html>")
        Response.Write(sb.ToString())
        Response.End()
        Return strToken
    End Function

    Private Function GetHostedPaymentPageResponse(ApiLoginID As [String], ApiTransactionKey As [String], amount As Decimal) As ANetApiResponse
        Dim currentURL As String = HttpContext.Current.Request.Url.AbsoluteUri
        Dim postURL As String

            ApiOperationBase(Of ANetApiRequest, ANetApiResponse).RunEnvironment = AuthorizeNet.Environment.SANDBOX
            postURL = "https://test.authorize.net/payment/payment"


        Dim merchantAuthenticationType As New merchantAuthenticationType()
        merchantAuthenticationType.name = ApiLoginID
        merchantAuthenticationType.ItemElementName = ItemChoiceType.transactionKey
        merchantAuthenticationType.Item = ApiTransactionKey
        ApiOperationBase(Of ANetApiRequest, ANetApiResponse).MerchantAuthentication = merchantAuthenticationType

        System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls12
        Dim settings As settingType() = New settingType(1) {}

        settings(0) = New settingType()
        settings(0).settingName = settingNameEnum.hostedPaymentButtonOptions.ToString()
        settings(0).settingValue = "{""text"": ""Pay Now""}"

        settings(1) = New settingType()
        settings(1).settingName = settingNameEnum.hostedPaymentOrderOptions.ToString()
        settings(1).settingValue = "{""show"": true, ""merchantName"":""My Company""}"

        Dim MylineItems(0) As AuthorizeNet.Api.Contracts.V1.lineItemType
        Dim thisLineItem As New AuthorizeNet.Api.Contracts.V1.lineItemType

        thisLineItem.itemId = "a100"
        thisLineItem.quantity = 1
        thisLineItem.name = "test"
        thisLineItem.description = "Software Training"
        thisLineItem.unitPrice = 3500.0
        MylineItems(0) = thisLineItem
        Dim thisCustomerType As New AuthorizeNet.Api.Contracts.V1.customerAddressType
        thisCustomerType.address = "123 main"
        thisCustomerType.city = "Santa Barbara"
        thisCustomerType.state = "CA"
        thisCustomerType.country = "USA"
        thisCustomerType.zip = "93111"
        Dim myorder As New AuthorizeNet.Api.Contracts.V1.orderType
        myorder.description = "Software Training"
        ' authorize capture only
        Dim transactionRequest = New transactionRequestType() With { _
             .transactionType = transactionTypeEnum.authCaptureTransaction.ToString(), _
             .amount = amount, _
             .lineItems = MylineItems.ToArray, _
        .order = myorder, _
             .billTo = thisCustomerType _
        }

        Dim request = New getHostedPaymentPageRequest()
        request.transactionRequest = transactionRequest
        request.hostedPaymentSettings = settings

        ' instantiate the contoller that will call the service
        Dim controller = New getHostedPaymentPageController(request)
        controller.Execute()

        ' get the response from the service (errors contained if any)
        Dim response1 = controller.GetApiResponse()
        Response.Clear()

        Dim sb As New StringBuilder
        sb.Append("<html>")

        sb.AppendFormat("<body onload='document.forms[""form""].submit()'>")
        sb.AppendFormat("<form target='payframe' name='form' action='{0}' method='post'>", postURL)
        sb.AppendFormat("<input type='hidden' name='token' value='{0}'>", response1.token)
        sb.Append("</form>")
        sb.Append("<iframe style='height: 700px;width:100%;border-style: none;'name='payframe' id='payframe' id='payframe'></iframe>")
        sb.Append("</body>")
        sb.Append("</html>")
        Response.Write(sb.ToString())
        Response.End()


        Return response1
    End Function

    Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Dim ThisApiResponse As ANetApiResponse
        Dim currentURL As String = HttpContext.Current.Request.Url.AbsoluteUri
        
        ThisApiResponse = GetHostedPaymentPageResponse("4YHwQEj988", "3Z36s3YrJce76L2v",3500)

    End Sub
End Class

 

So pretty simple code.  Not sure what is making it fail when put on a server.  I have tried it on both Windows Server 2008 and 2016.  Anything I should look at regarding IIS? 

 

 

Thanks for any help you can provide.