I'm trying to incorporate balanced payment processing into my site, however, their solution assumes a standard HTML form is in use and retrieves it with jQuery. Since I'm using knockout.js to power my forms, the inputs are referenced differently which means I had to modify my form. For this example, I manually set the value of the credit card data rather than take it from the $(#credit-card-form)
When I open up the network tab to check for errors it says "Uncaught TypeError: Property '0' of object # is not a function" which I'm thinking is in reference to the input attribute being appended to creditCardData
This fiddle is the example that Balanced gives to show how it works. In the javascript area, you must create a new request bin and copy that bin into the code. Then when you update the code and click "tokenize", visit that request bin URL and you'll see the request was submitted.
I created this fiddle which properly tokenizes the card, but I'm getting errors and can't quite pin it down to where they're coming from. Remember, you must create your own requestbin and copy/paste that URL into the code. Just a heads up, that "tokenize" button won't do anything. I just left the HTML there, it really doesn't do anything considering the function is called as soon as the fiddle opens.
The main difference between my version and Balanced's is in the initial call to balanced.js functions.
//paidForItems is a button set with knockout.js
self.paidForItems = function() {
//responseCallbackHandler here, see fiddle for details
var creditCardData = {
card_number: '4111111111111111',
expiration_month: '01',
expiration_year: '2020',
security_code: '123'
};
balanced.card.create(creditCardData, responseCallbackHandler);
}
Whereas balanced does it upon submitting a form
//responseCallbackHandler here, see fiddle for details
var tokenizeInstrument = function(e) {
e.preventDefault();
var $form = $('#credit-card-form');
var creditCardData = {
card_number: $form.find('.cc-number').val(),
expiration_month: $form.find('.cc-em').val(),
expiration_year: $form.find('.cc-ey').val(),
security_code: $form.find('cc-csc').val()
};
balanced.card.create(creditCardData, responseCallbackHandler);
};
$('#credit-card-form').submit(tokenizeInstrument);