I’m using Visual Studio with asp.net, vb.net, and javascript in order to implement an API. I am editing sample code from Authorize.Net.
I need to pass the values of dataValue and dataDescriptor
<input type="hidden" name="dataValue" id="dataValue" />
<input type="hidden" name="dataDescriptor" id="dataDescriptor" />
to the next page after the form POSTS
'This returns as EMPTY!!! right now
Dim infoValue = Request.Form("dataValue")
Dim infoDescriptor = Request.Form("dataDescriptor")
How can I pass these two hidden field values over to the next page?
FULL CODE
PaymentInfo.aspx
<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="PaymentInfo.aspx.vb" Inherits="AuthorizeAccept.PaymentInfo" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<!--
This file is a standalone HTML page demonstrating usage of the Authorize.net
Accept JavaScript library when integrated with your own payment form.
For complete documentation for the Accept JavaScript library, see
https://developer.authorize.net/api/reference/features/acceptjs.html
-->
<head runat="server">
<title>Sample form</title>
</head>
<body>
<script type="text/javascript"
src="https://jstest.authorize.net/v1/Accept.js"
charset="utf-8">
</script>
<form id="paymentForm" runat="server"
method="POST"
action="PaymentProcess.aspx" >
<input type="text" name="cardNumber" id="cardNumber" placeholder="cardNumber" value="4111111111111111"/> <br><br>
<input type="text" name="expMonth" id="expMonth" placeholder="expMonth" value="12"/> <br><br>
<input type="text" name="expYear" id="expYear" placeholder="expYear" value="2028"/> <br><br>
<input type="text" name="cardCode" id="cardCode" placeholder="cardCode" value="123"/> <br><br>
<input type="text" name="amount" id="amount" placeholder="cardCode" value="6.00"/> <br><br>
<input type="text" name="accountNumber" id="accountNumber" placeholder="accountNumber"/> <br><br>
<input type="text" name="routingNumber" id="routingNumber" placeholder="routingNumber"/> <br><br>
<input type="text" name="nameOnAccount" id="nameOnAccount" placeholder="nameOnAccount"/> <br><br>
<input type="text" name="accountType" id="accountType" placeholder="accountType"/> <br><br>
<input type="hidden" name="dataValue" id="dataValue" />
<input type="hidden" name="dataDescriptor" id="dataDescriptor" />
<button type="button" onclick="sendPaymentDataToAnet()">Pay</button>
</form>
<script type="text/javascript">
function sendPaymentDataToAnet() {
var authData = {};
authData.clientKey = "6bpMZ759ELh6K3dAWx7MVNqyYX88zsN5R3zj7FChrwnYjTQ3bQ93TS7h6YjcE64M";
authData.apiLoginID = "93cWyMh9Kd6G";
var cardData = {};
cardData.cardNumber = document.getElementById("cardNumber").value;
cardData.month = document.getElementById("expMonth").value;
cardData.year = document.getElementById("expYear").value;
cardData.cardCode = document.getElementById("cardCode").value;
// If using banking information instead of card information,
// build a bankData object instead of a cardData object.
//
// var bankData = {};
// bankData.accountNumber = document.getElementById('accountNumber').value;
// bankData.routingNumber = document.getElementById('routingNumber').value;
// bankData.nameOnAccount = document.getElementById('nameOnAccount').value;
// bankData.accountType = document.getElementById('accountType').value;
var secureData = {};
secureData.authData = authData;
secureData.cardData = cardData;
// If using banking information instead of card information,
// send the bankData object instead of the cardData object.
//
// secureData.bankData = bankData;
Accept.dispatchData(secureData, responseHandler);
function responseHandler(response) {
if (response.messages.resultCode === "Error") {
var i = 0;
while (i < response.messages.message.length) {
console.log(
response.messages.message[i].code + ": " +
response.messages.message[i].text
);
i = i + 1;
}
} else {
paymentFormUpdate(response.opaqueData);
}
}
}
function paymentFormUpdate(opaqueData) {
document.getElementById("dataDescriptor").value = opaqueData.dataDescriptor;
document.getElementById("dataValue").value = opaqueData.dataValue;
// If using your own form to collect the sensitive data from the customer,
// blank out the fields before submitting them to your server.
document.getElementById("cardNumber").value = "";
document.getElementById("expMonth").value = "";
document.getElementById("expYear").value = "";
document.getElementById("cardCode").value = "";
document.getElementById("accountNumber").value = "";
document.getElementById("routingNumber").value = "";
document.getElementById("nameOnAccount").value = "";
document.getElementById("accountType").value = "";
document.getElementById("paymentForm").submit();
}
</script>
</body>
</html>
PaymentProcess.aspx
Imports System
Imports System.Linq
Imports System.Text
Imports System.Threading.Tasks
Imports System.Collections.Generic
Imports AuthorizeNet.Api.Controllers
Imports AuthorizeNet.Api.Contracts.V1
Imports AuthorizeNet.Api.Controllers.Bases
Public Class PaymentProcess
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
'EMPTY!!!
Dim infoValue = Request.Form("dataValue")
Dim infoDescriptor = Request.Form("dataDescriptor")
Run()
End Sub
Private Sub Run()
' Public Shared Function Run(ByVal ApiLoginID As String, ByVal ApiTransactionKey As String, ByVal amount As Decimal) As ANetApiResponse
Console.WriteLine("Create an Accept Payment Transaction Sample")
ApiOperationBase(Of ANetApiRequest, ANetApiResponse).RunEnvironment = AuthorizeNet.Environment.SANDBOX
ApiOperationBase(Of ANetApiRequest, ANetApiResponse).MerchantAuthentication = New merchantAuthenticationType() With {
.name = ConfigurationManager.AppSettings("AUTHORIZE_NET_API_LOGIN"),
.ItemElementName = ItemChoiceType.transactionKey,
.Item = ConfigurationManager.AppSettings("AUTHORIZE_NET_TRANSACTION_KEY")
}
Dim opaqueData = New opaqueDataType With {
.dataDescriptor = "COMMON.ACCEPT.INAPP.PAYMENT",
.dataValue = "119eyJjb2RlIjoiNTBfMl8wNjAwMDUyN0JEODE4RjQxOUEyRjhGQkIxMkY0MzdGQjAxQUIwRTY2NjhFNEFCN0VENzE4NTUwMjlGRUU0M0JFMENERUIwQzM2M0ExOUEwMDAzNzlGRDNFMjBCODJEMDFCQjkyNEJDIiwidG9rZW4iOiI5NDkwMjMyMTAyOTQwOTk5NDA0NjAzIiwidiI6IjEuMSJ9"
}
Dim billingAddress = New customerAddressType With {
.firstName = "John",
.lastName = "Doe",
.address = "123 My St",
.city = "OurTown",
.zip = "98004"
}
Dim paymentType = New paymentType With {
.Item = opaqueData
}
Dim lineItems = New lineItemType(1) {}
lineItems(0) = New lineItemType With {
.itemId = "1",
.name = "t-shirt",
.quantity = 2,
.unitPrice = New Decimal(15.0)
}
lineItems(1) = New lineItemType With {
.itemId = "2",
.name = "snowboard",
.quantity = 1,
.unitPrice = New Decimal(450.0)
}
Dim transactionRequest = New transactionRequestType With {
.transactionType = transactionTypeEnum.authCaptureTransaction.ToString(),
.amount = "5.00",
.payment = paymentType,
.billTo = billingAddress,
.lineItems = lineItems
}
Dim request = New createTransactionRequest With {
.transactionRequest = transactionRequest
}
Dim controller = New createTransactionController(request)
controller.Execute()
Dim response = controller.GetApiResponse()
If response IsNot Nothing Then
If response.messages.resultCode = messageTypeEnum.Ok Then
If response.transactionResponse.messages IsNot Nothing Then
Console.WriteLine("Successfully created transaction with Transaction ID: " & response.transactionResponse.transId)
Console.WriteLine("Response Code: " & response.transactionResponse.responseCode)
Console.WriteLine("Message Code: " & response.transactionResponse.messages(0).code)
Console.WriteLine("Description: " & response.transactionResponse.messages(0).description)
Console.WriteLine("Success, Auth Code : " & response.transactionResponse.authCode)
Else
Console.WriteLine("Failed Transaction.")
If response.transactionResponse.errors IsNot Nothing Then
Console.WriteLine("Error Code: " & response.transactionResponse.errors(0).errorCode)
Console.WriteLine("Error message: " & response.transactionResponse.errors(0).errorText)
End If
End If
Else
Console.WriteLine("Failed Transaction.")
If response.transactionResponse IsNot Nothing AndAlso response.transactionResponse.errors IsNot Nothing Then
Console.WriteLine("Error Code: " & response.transactionResponse.errors(0).errorCode)
Console.WriteLine("Error message: " & response.transactionResponse.errors(0).errorText)
Else
Console.WriteLine("Error Code: " & response.messages.message(0).code)
Console.WriteLine("Error message: " & response.messages.message(0).text)
End If
End If
Else
Console.WriteLine("Null Response.")
End If
End Sub
' Return response
'End Function
End Class