jquery - Javascript balanced function is defined according to console but undefined according to function call. What's the scope feature I'm bungling? -
i trying create user credit card via balanced.js.
in javascript console, when type "balanced.card.create" balanced.card.create function.
but when balanced.card.create(payload, handlecreditcardresponse) undefined.
code:
in html header have:
<script type="text/javascript" src="https://js.balancedpayments.com/1.1/balanced.js"></script> <script type="text/javascript" src="localbalancedcode.js"></script>
in localbalancedcode.js form submit event have:
$(document).ready(function () { $('#create-credit-card-submit').click(function (e) { e.preventdefault(); var payload = { name: $('#id_name').val(), address: $('#id_address').val(), city: $('#id_city').val(), line1: $('#id_line1').val(), line2: $('#id_line2').val(), state: $('#id_state').val(), postal_code: $('#id_postal_code').val(), number: $('#id_number').val(), expiration_month: $('#id_expiration_month').val(), expiration_year: $('#id_expiration_year').val(), cvv: $('#id_cvv').val() }; // create credit card balanced.card.create(payload, handlecreditcardresponse); }); });
and have callback function:
function handlecreditcardresponse(response) { if (response.status_code === 201) { debugger var fundinginstrument = response.cards[0]; // call backend jquery.post("user/payment/card/add/$", { uri: fundinginstrument.href }, function (r) { // check backend response if (r.status === 201) { // successful logic here backend ruby } else { // failure logic here backend ruby } }); } else { // failed tokenize, error logic here } }
Comments
Post a Comment