Hi all,
I'm receiving the following error when using AcceptUI (hosted mode):
Uncaught TypeError: window[s] is not a function at _sendRespondBackToMerchant (AcceptUI.js:1) at U (AcceptUI.js:1)
When you prettify the minified JS source (https://jstest.authorize.net/v3/AcceptUI.js), you'll see that the code tries to find out if the responseHandler is a function or not:
"function"==typeof s?s.call(null,t):window[s](t)
Unfortunately, the responseHandler is set as a data-attribute (data-responseHandler) on the initiating button.
Example:
<form id="paymentForm" method="POST" action="https://YourServer/PathToExistingPaymentProcessingScript"> <input type="hidden" name="dataValue" id="dataValue" /> <input type="hidden" name="dataDescriptor" id="dataDescriptor" /> <button type="button" class="AcceptUI" data-billingAddressOptions='{"show":true, "required":false}' data-apiLoginID="YOUR API LOGIN ID" data-clientKey="YOUR PUBLIC CLIENT KEY" data-acceptUIFormBtnTxt="Submit" data-acceptUIFormHeaderTxt="Card Information" data-responseHandler="responseHandler">Pay </button> </form>
When set using the example, the code breaks when the AcceptUI library tries to determine if it's a function or not. It always turns out as a string. FYI: The responseHandler value (regardless if set inline or by JavaScript) returns as a string no matter what in my testing:
element.setAttribute("data-responseHandler", function() { console.log('Hello World'); });
Will still return as "string" when using typeof.
Is this a bug in the AcceptUI code or is there a workaround?
07-01-2018 09:25 AM - edited 07-01-2018 09:28 AM
Hi;
I just ran into this. Did you get it figured out?
07-18-2018 09:59 AM
Here's what I found.
My callback is called:
myNameSpace.myResponseHandler.
In my button definition I had:
07-18-2018 11:17 AM
The leehinde explanation helped a lot.
In my case, I'm using Vue w/ Nuxt and ran accross the same issue.
template.vue:
mounted: function() { let accept = document.createElement("script"); accept.setAttribute("src", "https://jstest.authorize.net/v3/AcceptUI.js"); document.body.appendChild(accept); if (process.client) { window.checkout = this.checkout; } ...<snip>... methods:{ checkout() { console.log('hello world'); }
11-02-2018 10:28 AM
I'm having the same problem.
button code:
<form id="paymentForm"
method="POST"
action="https://YourServer/PathToExistingPaymentProcessingScript">
<input type="hidden" name="dataValue" id="dataValue" />
<input type="hidden" name="dataDescriptor" id="dataDescriptor" />
<button type="button"
class="AcceptUI btn btn-primary"
data-billingAddressOptions='{"show":true, "required":true}'
data-apiLoginID="6jWN5Num7s"
data-clientKey="45WcsGtuZutcLj2Kfu5qx5dRk5Bb55vVcZ9GB9kzqjsqQBn3y99VA5jKX8TUKd2q"
data-acceptUIFormBtnTxt="Submit"
data-acceptUIFormHeaderTxt="Card Information"
data-responseHandler= "responseHandler">
Submit For Payment
</button>
</form>
Javascript code:
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);
}
}
Also, what is this:https://YourServer/PathToExistingPaymentProcessingScript? No documentation on Authorize.net.
The error I'm getting is: window[I] is not a function.. AcceptUI.js:1
04-16-2020 12:16 PM
I am also facing this issue in React.js version 16.13.1
Did anybody found any solution?
09-22-2020 06:25 AM - edited 09-22-2020 06:38 AM
Hi,
I used this solution for React, according to solutions above and it's working for me:
useEffect(() => {
window.responseHandler = responseHandler;
});
Hope it helps!
10-12-2020 06:44 AM