I am able to get the hosted form to come up and can process payments as long as the form validation passed.
I am getting the following error whenever the user inputs an incorrect field. I get the error message for the problem, then when it is corrected and clicking pay invoice I get an error "fingerprint value is not valid". This is happening in the sandbox and production. This example is in production, I entered an invalid expiration date:
![paymentTransaction1.jpg paymentTransaction1.jpg]()
![paymentTransaction2.jpg paymentTransaction2.jpg]()
Now the user is stuck and has to cancel and come back in to process the payment. Also, I have the cancel event being captured via the iframe communicator and this does not work after this error so the iframe redirects to the cancelUrl passed in with the token request. I can't get the cancel event to trigger unless I provide a cancel url. Here is my javascript to handle the events:
$(document).ready(function () {
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) {
var params = parseQueryString(argument.qstr);
console.log(argument);
switch (params['action']) {
case "resizeWindow":
//alert('resizeWindow: width-' + params['width'] + ' height-' + params['height']);
var iFrame = document.getElementById('authNetIFrame');
iFrame.width = params['width'];
iFrame.height = params['height'];
break;
case "cancel":
if (_paymentDetail) {
_paymentDetail.hide();
location.reload(true);
}
break;
case "transactResponse":
var transResponse = JSON.parse(params['response']);
if (transResponse.responseCode == 1) {
var firstName = '';
var lastName = '';
var city = '';
var state = '';
var zip = '';
var address = '';
if (transResponse.billTo != 'undefined') {
firstName = transResponse.billTo.firstName;
lastName = transResponse.billTo.lastName;
city = transResponse.billTo.city;
state = transResponse.billTo.state;
zip = transResponse.billTo.zip;
address = transResponse.billTo.address;
}
ProcessPaymentReceipt(transResponse.transId, transResponse.accountType, transResponse.accountNumber, firstName, lastName, city, state, zip, address);
}
break;
}
}
});
Here is the C# code to build the request:
public getHostedPaymentPageResponse GetHostedResponse(String ApiLoginID, String ApiTransactionKey, decimal paymentAmount, bool testMode)
{
var borrGuid = "";
if (UserID == 0 && !string.IsNullOrEmpty(Borrower.AppraisalOrder.PaymentGuid))
borrGuid = Borrower.AppraisalOrder.PaymentGuid;
ApiOperationBase<ANetApiRequest, ANetApiResponse>.RunEnvironment = testMode ? AuthorizeNet.Environment.SANDBOX : AuthorizeNet.Environment.PRODUCTION;
ApiOperationBase<ANetApiRequest, ANetApiResponse>.MerchantAuthentication = new merchantAuthenticationType()
{
name = ApiLoginID,
ItemElementName = ItemChoiceType.transactionKey,
Item = ApiTransactionKey,
};
var transactionRequest = new transactionRequestType
{
transactionType = transactionTypeEnum.authCaptureTransaction.ToString(), // authorize capture only
amount = paymentAmount,
poNumber = borrGuid
};
settingType[] settings = new settingType[9];
settings[0] = new settingType();
settings[0].settingName = settingNameEnum.hostedPaymentReturnOptions.ToString();
settings[0].settingValue = "{\"showReceipt\": false, \"cancelUrl\": \"" + AdminModel.BaseUrl + "\", \"cancelUrlText\": \"Cancel\"}";
settings[1] = new settingType();
settings[1].settingName = settingNameEnum.hostedPaymentButtonOptions.ToString();
settings[1].settingValue = "{\"text\": \"Pay Invoice\"}";
settings[2] = new settingType();
settings[2].settingName = settingNameEnum.hostedPaymentPaymentOptions.ToString();
settings[2].settingValue = "{\"cardCodeRequired\": false, \"showCreditCard\": true, \"showBankAccount\": false}";
settings[3] = new settingType();
settings[3].settingName = settingNameEnum.hostedPaymentSecurityOptions.ToString();
settings[3].settingValue = "{\"captcha\": false}";
settings[4] = new settingType();
settings[4].settingName = settingNameEnum.hostedPaymentShippingAddressOptions.ToString();
settings[4].settingValue = "{\"show\": false, \"required\": false}";
settings[5] = new settingType();
settings[5].settingName = settingNameEnum.hostedPaymentBillingAddressOptions.ToString();
settings[5].settingValue = "{\"show\": false, \"required\": false}";
settings[6] = new settingType();
settings[6].settingName = settingNameEnum.hostedPaymentCustomerOptions.ToString();
settings[6].settingValue = "{\"showEmail\": false, \"requiredEmail\": false, \"addPaymentProfile\": false}";
settings[7] = new settingType();
settings[7].settingName = settingNameEnum.hostedPaymentOrderOptions.ToString();
settings[7].settingValue = "{\"show\": false, \"merchantName\": \"\"}";
settings[8] = new settingType();
settings[8].settingName = settingNameEnum.hostedPaymentIFrameCommunicatorUrl.ToString();
settings[8].settingValue = "{\"url\": \"" + AdminModel.BaseUrl + "InvoiceCommunicator.html\"}";
var request = new getHostedPaymentPageRequest();
request.transactionRequest = transactionRequest;
request.refId = UserID.ToString();
request.hostedPaymentSettings = settings;
// instantiate the contoller that will call the service
var controller = new getHostedPaymentPageController(request);
controller.Execute();
// get the response from the service (errors contained if any)
var response = controller.GetApiResponse();
return response;
}
public string GetHostedFormToken()
{
string token = "";
if (Test)
{
if (!string.IsNullOrEmpty(TestLogin))
{
Login = TestLogin;
TransactionKey = TestTransactionKey;
}
}
Decimal amt = 0;
Decimal.TryParse(PmtFormAmount, out amt);
var logger = NLog.LogManager.GetLogger("AuthorizeNet");
var resp = GetHostedResponse(Login,TransactionKey, amt, Test);
//validate
if (resp != null && resp.messages.resultCode == messageTypeEnum.Ok)
{
token = resp.token;
}
logger.Debug(() => String.Format("HostedFormToken: [{}{}{0}] : token ", Borrower.BorrowerID.ToString()) + token);
return token;
}
Thanks for your help.