cancel
Showing results for 
Search instead for 
Did you mean: 

Invalid or Missing Token

Hello,

I am having an issue with the "getHostedPaymentPageRequest" api call where I always receive either error code E00001 "An error occured duing processing. Please try again", "Missing or invalid token", or a 550() error. My implementation is using pick basic as the backend. Here is the relevant code:

json = '{'
json := '"getHostedPaymentPageRequest":{'
json := '"merchantAuthentication":{"name":"':api.loginid:'","transactionKey":"':transactionKey:'"},'
json := '"transactionRequest":{"transactionType":"authCaptureTransaction","amount":"20.00","profile":{"customerProfileId":"':customerProfileId:'"},"customer":{"email":"eibachonline@gmail.com"}},'
json := '"hostedPaymentSettings":{"setting":['

json := '{"settingName":"hostedPaymentReturnOptions","settingValue":"{\\\"showReceipt\\\": true, \\\"url\\\": \\\"https://mysite.com/receipt\\\", \\\"urlText\\\": \\\"Continue\\\", \\\"cancelUrl\\\": \\\"https://mysite.com/cancel\\\", \\\"cancelUrlText\\\": \\\"Cancel\\\"}"},'
json := '{"settingName":"hostedPaymentButtonOptions","settingValue":"{\\\"text\\\": \\\"Pay\\\"}"},'
json := '{"settingName":"hostedPaymentStyleOptions","settingValue":"{\\\"bgColor\\\": \\\"blue\\\"}"},'
json := '{"settingName":"hostedPaymentPaymentOptions","settingValue":"{\\\"cardCodeRequired\\\": false, \\\"showCreditCard\\\": true, \\\"showBankAccount\\\": true}"},'
json := '{"settingName":"hostedPaymentSecurityOptions","settingValue":"{\\\"captcha\\\": false}"},'
json := '{"settingName":"hostedPaymentShippingAddressOptions","settingValue":"{\\\"show\\\": false, \\\"required\\\": false}"},'
json := '{"settingName":"hostedPaymentBillingAddressOptions","settingValue":"{\\\"show\\\": true, \\\"required\\\": false}"},'
json := '{"settingName":"hostedPaymentCustomerOptions","settingValue":"{\\\"showEmail\\\": false, \\\"requiredEmail\\\": false, \\\"addPaymentProfile\\\": true}"},'
json := '{"settingName":"hostedPaymentOrderOptions","settingValue":"{\\\"show\\\": true, \\\"merchantName\\\": \\\"G and S Questions Inc.\\\"}"},'
json := '{"settingName":"hostedPaymentIFrameCommunicatorUrl","settingValue":"{\\\"url\\\": \\\"https://mysite.com/iFrameCommunicator.html\\\"}"}'

json := ']}}}'

Sending this json via:

cmd = '!curl -s -X POST https://apitest.authorize.net/xml/v1/request.api '
cmd := '-H "Content-Type: application/json" '
cmd := '-H "Accept: application/json" '
cmd := "-d '" : json : "'"

Here is the html:

<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=0">
<title>HostedPayment Test Page</title>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script src="/mfgdev/js/hostedPayment.js"></script>
</head>
<body>
<div>
Open Authorize.net in an iframe to complete transaction
<button id="btnOpenAuthorizeNetIFrame">Show Payment Form</button>
</div>

<div id="iframe_holder" class="center-block" style="width:90%;max-width: 1000px;">
<iframe
id="add_payment"
name="add_payment"
width="100%"
height="600"
style="border:1px solid black;">
</iframe>
</div>
<form
id="send_token"
action="https://test.authorize.net/payment/payment"
method="POST"
target="add_payment">
<input type="hidden" name="token" value='##TOKEN##' />
</form>
</body>
</html>

Here is the Javascript&colon; 

$(function () {
$("#btnOpenAuthorizeNetIFrame").click(function () {
$("#add_payment").show();
const token = $("#send_token input[name=token]").val();
console.log("Here is the token that should be sent", token);
if (!token || token.includes("##TOKEN##")) {
console.log("Token expected to be null at this point:", token);
}
console.log("submitting now");
$("#send_token").attr({
"action": "https://test.authorize.net/customer/hostedProfile",
"target": "add_payment"
}).submit();
$(window).scrollTop($('#add_payment').offset().top - 50);
});
});

if (!window.AuthorizeNetIFrame) window.AuthorizeNetIFrame = {};
AuthorizeNetIFrame.onReceiveCommunication = function (querystr) {
var params = parseQueryString(querystr);
switch (params["action"]) {
case "successfulSave":
break;
case "cancel":
break;
case "resizeWindow":
var w = parseInt(params["width"]);
var h = parseInt(params["height"]);
var ifrm = document.getElementById("add_payment");
ifrm.style.width = w.toString() + "px";
ifrm.style.height = h.toString() + "px";
break;
case "transactResponse":
var ifrm = document.getElementById("add_payment");
ifrm.style.display = 'none';
}
};

function parseQueryString(str) {
var vars = [];
var arr = str.split('&');
var pair;
for (var i = 0; i < arr.length; i++) {
pair = arr[i].split('=');
vars.push(pair[0]);
vars[pair[0]] = unescape(pair[1]);
}
return vars;
}

Any help would be much appreciated. Thank you

 

 

 

TylerKurth
Member
2 REPLIES 2

Update: I am receiving a token, so I know that the javascript is injecting correctly.

TylerKurth
Member
  • Generate the hostedPaymentPage token on the server (not placeholder)
  • Inject that actual token into the hidden field before the form loads
  • Ensure you're using correct API login and key in the request
malikjoius
Member