I am starting to use a Payment API and I'm following their jsfiddle example. They are posting to the website requestbin in the fiddle. However, how do I make it post to my server instead? I am using balanced payments, rails and HAML.
In the first line of code var THEPOSTTOLINK = 'http://requestb.in/1hkphb71';
The example shows where to post to but how do I do that in Rails? I can't just write localhost:3000 or www.mysite.user/account.
Javascript
var THEPOSTTOLINK = 'http://requestb.in/1hkphb71';
var marketplaceUri = '/v1/marketplaces/TEST-MPg9bCIQUZMBoiPMnvWkQJW';
balanced.init(marketplaceUri);
function responseCallbackHandler(response) {
switch (response.status) {
case 400:
console.log(response.error);
break;
case 404:
console.log(response.error);
break;
case 201:
var $form = $("#bank-account-form");
var bank_account_uri = response.data['uri'];
$('<input>').attr({
type: 'hidden',
value: bank_account_uri,
name: 'balancedBankAccountURI'
}).appendTo($form);
$form.attr({action: THEPOSTTOLINK});
$form.get(0).submit();
}
}
var tokenizeInstrument = function(e) {
e.preventDefault();
var $form = $('#bank-account-form');
var bankAccountData = {
name: $form.find('.ba-name').val(),
account_number: $form.find('.ba-an').val(),
bank_code: $form.find('.ba-rn').val(),
type: $form.find('select').val()
};
balanced.bankAccount.create(bankAccountData, responseCallbackHandler);
};
$('#bank-account-form').submit(tokenizeInstrument);
Bank account form
%form#bank-account-form{:action => "#", :method => "POST"}
= label_tag :bank_name, "Account Holder's Name"
= text_field_tag :bank_name, nil, name: nil, :value => "John Q. TaxPayer", class: "ba-name"
%p
= label_tag :route_num, "Routing Number"
= text_field_tag :route_num, nil, name: nil, :value => "121000358", class: "ba-rn"
%p
= label_tag :acct_num, "Account Number"
= text_field_tag :acct_num, nil, name: nil, :value => "9900000001", class: "ba-an"
%p
%button.btn{:type => "submit"}
tokenize
As we discussed in #balanced on IRC, here's a rough example on how to accomplish what you're looking for. https://gist.github.com/remear/7f6d7e6f24aa7e63fd2b