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("paymentForm").submit(); }