1

バランスド ペイメント APIを使用しています。ユーザーの銀行口座情報を取得しようとしているので、例の jsfiddleをガイドとして使用しています。したがって、銀行口座の URI をユーザー モデルに保存する必要があることはわかっています。問題は、Rails でそれをどのようにやってのけるかということです。

これはjsfiddleの私の Rails バージョンです。

%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


%script{:charset => "utf-8", :type => "text/javascript"}
  \// FOR DEMONSTRATION PURPOSES ONLY - if you already have a server you can POST to, replace
  \//                                   the URL with the URL to post to.
  \// go to http://requestb.in/
  \// click create new request bin and COPY that URL without the ?inspect at the end
  var requestBinURL = 'http://requestb.in/1jwwlla1';  // make sure it doesn't end in ?inspect

  var marketplaceUri = '/v1/marketplaces/TEST-MPg9bCIQUZMBoiPMnvWkQJW';
  balanced.init(marketplaceUri);

  function responseCallbackHandler(response) {
  switch (response.status) {
  case 400:
  \// missing or invalid field - check response.error for details
  console.log(response.error);
  break;
  case 404:
  \// your marketplace URI is incorrect
  console.log(response.error);
  break;
  case 201:
  \// WOO HOO! MONEY!
  \// response.data.uri == URI of the bank account resource you
  \// should store this bank account URI to later credit it
  console.log(response.data);
  var $form = $("#bank-account-form");
  \// the uri is an opaque token referencing the tokenized bank account
  var bank_account_uri = response.data['uri'];
  \// append the token as a hidden field to submit to the server
  $('
  %input>/
  ').attr({
  type: 'hidden',
  value: bank_account_uri,
  name: 'balancedBankAccountURI'
  }).appendTo($form);
  $form.attr({action: requestBinURL});
  $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);
4

1 に答える 1