通过API发送帖子请求

时间:2013-08-01 22:31:55

标签: ruby-on-rails balanced-payments

我开始使用付款API,我正在关注their jsfiddle example。他们在小提琴中发布到网站requestbin。但是,如何将其发布到我的服务器呢?我使用平衡付款,铁路和HAML。

在代码的第一行var THEPOSTTOLINK = 'http://requestb.in/1hkphb71';示例显示了发布到哪里,但我如何在Rails中执行此操作?我不能只写localhost:3000或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);

银行帐户表单

%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

1 个答案:

答案 0 :(得分:1)

正如我们在IRC上的#balanced中所讨论的,这是一个关于如何完成你正在寻找的东西的一个粗略的例子。 https://gist.github.com/remear/7f6d7e6f24aa7e63fd2b