Reply
Member
Posts: 5
Registered: ‎07-07-2017

Hosted Form Implementation | User Defined Response Capture

Hi All

 

      Am implementing Hosted Form Payment Gateway in my .Net application. 

Following are the clarifications that I need;

 

- Unable to capture the transaction ID in my custom page. Kindly suggest a soltn.

-  How to disable the default receipt page.

-  For bulk transaction processing would I be able to use the same mechanism, or is there a walk-around?

Any help would really be appreciated. Waiting for a warm and quick response

Highlighted
Posts: 138
Topics: 0
Kudos: 27
Blog Posts: 0
Ideas: 0
Solutions: 9
Registered: ‎04-28-2017

Re: Hosted Form Implementation | User Defined Response Capture

[ Edited ]

Hi,

 

One way to capture the transactionId in your parent page is:

<script>
    window.CommunicationHandler = {};
    function parseQueryString(str) {
        var vars = [];
        var arr = str.split('&');
        var pair;
        for (var i = 0; i < arr.length; i++) {
            pair = arr[i].split('=');
            vars[pair[0]] = unescape(pair[1]);
        }
        return vars;
    }
    window.CommunicationHandler.onReceiveCommunication = function (argument) {
        params = parseQueryString(argument.qstr)
        parentFrame = argument.parent.split('/')[4];
          switch (params['action']) {
            case "transactResponse":
                var transResponse = JSON.parse(params['response']);
                $('#demo').html(transResponse.transId); // Transaction Id is here
               
        }

    }

</script>

<div id="demo"></div>

To disable the default receipt page, in your getHostedPaymentPageRequest, include the setting block below with your own parameters: 

<setting>
<settingName>hostedPaymentReturnOptions</settingName>
<settingValue>{'showReceipt' : false, 'url':'https://yourwebsite.com/continue','urlText':'Continue','cancelUrl':'https://yourwebsites.com/cancel','cancelUrlText':'Cancel'}</settingValue>
</setting>

 

Powered by NexWebSites.com -
Certified Authorize.net developers
Member
Posts: 5
Registered: ‎07-17-2017

Re: Hosted Form Implementation | User Defined Response Capture

Hi @devashis1993

Can you please share the .net code you did since I'm looking for some good .net example.

 

Also how did you generate the token? 

 

Thanks

Member
Posts: 5
Registered: ‎07-07-2017

Re: Hosted Form Implementation | User Defined Response Capture

Hi Team

      Thank you for the warm response. I've tried implenenting the same but it seems to fail. The debugger itself is not going in after  window.CommunicationHandler.onReceiveCommunication = function (argument) and exits the script. 

As instructed in the mentioned documents I've strictly followed the steps for iCommunicator implementation. PFB the code;

 

Kindly help! Awaiting  a quick response. Thank you!

 

<script>

       debugger
       window.CommunicationHandler = {};
       function parseQueryString(str) {
           var vars = [];
           var arr = str.split('&');
           var pair;
           for (var i = 0; i < arr.length; i++) {
               pair = arr[i].split('=');
               vars[pair[0]] = unescape(pair[1]);
           }
           return vars;
       }
       debugger
       window.CommunicationHandler.onReceiveCommunication = function (argument) {
           params = parseQueryString(argument.qstr)
           parentFrame = argument.parent.split('/')[4];
           switch (params['action']) {
               case "transactResponse":
                   var transResponse = JSON.parse(params['response']);
                   $('#demo').html(transResponse.transId); // Transaction Id is here

           }

       }
   </script>

// The form where I am doing the call;

    <form id="send_hptoken" runat="server" method="post" action="https://accept.authorize.net/payment/payment" target="load_payment">
        
        <asp:Button ID="Button1" runat="server" Text="Button" />
        <input type="hidden" id="token" runat="server"/>
        
        </form>
    <iframe id="load_payment" class="embed-responsive-item" name="load_payment" width="900" height="700">
    </iframe>  

 

Member
Posts: 5
Registered: ‎07-07-2017

Re: Hosted Form Implementation | User Defined Response Capture

Hi @arnaudov

  Am using a dictionary object to bind the data objects in json and then sending it with the API call.

 

PFB the code

        Dim merchantAuthentication As New JsonDictionaryDTO(Of String, Object)
        Dim inner As New JsonDictionaryDTO(Of String, Object)
        inner.Add("name", APILOGINID)
        inner.Add("transactionKey", TRANSACTIONKEY)
        merchantAuthentication.Add("merchantAuthentication", inner)
        Dim getHostedPaymentPageRequest As New JsonDictionaryDTO(Of String, Object)
        Dim hostedPaymentSettings As New JsonDictionaryDTO(Of String, Object)
        Dim innerMain As New JsonDictionaryDTO(Of String, Object)
        Dim transactionRequest As New JsonDictionaryDTO(Of String, Object)
        Dim customer As New JsonDictionaryDTO(Of String, Object)
        Dim billTo As New JsonDictionaryDTO(Of String, Object)
        Dim setting As New JsonDictionaryDTO(Of String, Object)()
        Dim settingList As New ArrayList()

        billTo.Add("firstName", "Ellen")
        billTo.Add("lastName", "Johnson")
        billTo.Add("company", "Souveniropolis")
        billTo.Add("address", "14 Main Street")
        billTo.Add("city", "Pecan Springs")
        billTo.Add("state", "TX")
        billTo.Add("zip", "44628")
        billTo.Add("country", "USA")

        customer.Add("email", "bmcmanus@mail.com")

        transactionRequest.Add("transactionType", "authCaptureTransaction")
        transactionRequest.Add("amount", "20.00")
        transactionRequest.Add("customer", customer)
        transactionRequest.Add("billTo", billTo)

        Dim innersettings1 As New JsonDictionaryDTO(Of String, Object)
        innersettings1.Add("settingName", "hostedPaymentPaymentOptions)")
        innersettings1.Add("settingValue", "{""cardCodeRequired"":true}")

        Dim innersettings2 As New JsonDictionaryDTO(Of String, Object)
        innersettings2.Add("settingName", "hostedPaymentCustomerOptions")
        innersettings2.Add("settingValue", "{""showEmail"":true,""requiredEmail"":true}")

        Dim innersettings3 As New JsonDictionaryDTO(Of String, Object)
        innersettings3.Add("settingName", "hostedPaymentReturnOptions")
        innersettings3.Add("settingValue", "{""showReceipt"" : false ,""url"":""http://localhost:54440/Members/AR/TestPaymentGateway.aspx"",""urlText"":""Continue""}")

        Dim innersettings4 As New JsonDictionaryDTO(Of String, Object)
        innersettings4.Add("settingName", "hostedPaymentStyleOptions")
        innersettings4.Add("settingValue", "{""bgColor"": ""EE00EE""}")

        Dim innersettings5 As New JsonDictionaryDTO(Of String, Object)
        innersettings5.Add("settingName", "hostedPaymentIFrameCommunicatorUrl")
        innersettings5.Add("settingValue", "{""url"":""https://localhost:54440/Members/AR/iCommunicator.html""}")


        'settingList.Add(innersettings1)
        settingList.Add(innersettings2)
        settingList.Add(innersettings3)
        settingList.Add(innersettings4)

        setting.Add("setting", settingList)
        innerMain.Add("merchantAuthentication", inner)
        innerMain.Add("transactionRequest", transactionRequest)
        innerMain.Add("hostedPaymentSettings", setting)
        getHostedPaymentPageRequest.Add("getHostedPaymentPageRequest", innerMain)
        str = Newtonsoft.Json.JsonConvert.SerializeObject(getHostedPaymentPageRequest)


        Dim IsPaymentTokenCreated As String = String.Empty
        RESTClientResponse = RESTClient.POSTRequest(apiuri, str)
        If (RESTClientResponse.IsError = False) Then
            Dim response = RESTClientResponse.ResponseString
            Dim responseCode = Newtonsoft.Json.JsonConvert.DeserializeObject(response)
            sToken = responseCode("token")
            token.Value = sToken
            IsPaymentTokenCreated = responseCode("messages")("resultCode")

        End If



JSON Ddictionary Class;

<Serializable>
Public Class JsonDictionaryDTO(Of Key, Val)
    Implements ISerializable
    Private dict As New Dictionary(Of Key, Val)()
    Public Sub New()
    End Sub
    Public Sub Add(key As Key, value As Val)
        dict.Add(key, value)
    End Sub
    Private Sub ISerializable_GetObjectData(info As SerializationInfo, context As StreamingContext) Implements ISerializable.GetObjectData
        For Each key As Key In dict.Keys
            info.AddValue(key.ToString(), dict(key))
        Next
    End Sub
End Class
Member
Posts: 5
Registered: ‎07-07-2017

Re: Hosted Form Implementation | User Defined Response Capture

Hi @arnaudov

     If by any chance you find the solution to capture the transaction details in the merchant page. Kindly let me know. Any kind of help would be really appreciated as am stuck with this issue since a week.

Posts: 138
Topics: 0
Kudos: 27
Blog Posts: 0
Ideas: 0
Solutions: 9
Registered: ‎04-28-2017

Re: Hosted Form Implementation | User Defined Response Capture

At https://nexwebsites.com/authorizenet/ is a very basic working example of Accept Hosted in C#, using the exact Javascript above. Not only does it return the transaction Id, but said is placed into the form to enable the creation of a Customer Profile from the transaction.

Powered by NexWebSites.com -
Certified Authorize.net developers
Member
Posts: 5
Registered: ‎07-07-2017

Re: Hosted Form Implementation | User Defined Response Capture

Hi @NexusSoftware

    Thank you for the quick response. It seems I'll have to run my local-host as Https. Then only I'll be able to achieve the proper functionality.

My approach;

    - Have created a new communicator.html page.

    - Passing the same in JSON.

    - Have embedded the above mentioned javascript in the head section of my source page.

    - On click of continue button on the receipt page, am redirecting to my main page where the javascript code to receive the tran-Id is writen

Kindly point out if I've missed anything. And regarding enabling Https in localhost kindly suggest some pointers. 

 

Waiting for a quick response