バランスの取れた支払いを統合して、ユーザーが後で使用するためにクレジットカード情報を保存できるようにしようとしています。関連するビューコードとjavascriptファイルは次のとおりですが、javascriptファイルで定義されている送信ハンドラーに問題があります。
balance_card.js
var marketplaceUri = '{MY MARKETPLACE URI}';
var requestBinUrl = '{FORM SUBMISSION PATH}'
var debug = function(tag, content) {
$('<' + tag + '>' + content + '</' + tag + '>').appendTo('#result');
};
try {
balanced.init(marketplaceUri);
} catch (e) {
debug('code', 'balanced.init error!');
}
function balancedCallback(response) {
var tag = (response.status < 300) ? 'pre' : 'code';
debug(tag, JSON.stringify(response));
switch(response.status) {
case 201:
console.log(response.data);
var $form = $("#credit-card-form");
var card_token_uri = response.data['uri'];
$('<input>').attr({
type: 'hidden',
value: card_token_uri,
name: 'balancedCreditCardURI'
}).appendTo($form);
$form.attr({action: requestBinUrl});
$form.get(0).submit();
case 400:
console.log(response.error);
case 404:
console.log(response.error);
break;
}
}
var tokenizeCreditCard = 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, balancedCallback);
};
$('#credit-card-form').submit(tokenizeCreditCard);
credit_card.html.haml
= javascript_include_tag 'https://js.balancedpayments.com/v1/balanced.js'
= javascript_include_tag 'balanced_card'
= render :partial => 'crdtcard'
_crdtcard.html.haml
%h3 Credit Card
= form_tag '#', :method => :post, :id => "credit-card-form" do
= label_tag "Card Number"
= text_field_tag "cc-number", nil, :placeholder => "Enter Credit Card Number", :class => "cc-number", :autocomplete => "off"
= label_tag "Expiration"
= text_field_tag "cc-em", nil, :placeholder => "Expiration Month", :class => "cc-em", :autocomplete => "off"
= text_field_tag "cc-em", nil, :placeholder => "Expiration Year", :class => "cc-ey", :autocomplete => "off"
= label_tag "Security Code"
= text_field_tag "cc-csc", nil, :placeholder => "Security Code", :class => "cc-csc", :autocomplete => "off"
= submit_tag "Submit", :name => "submit"
Firebugでデバッグすると、tokenizeCreditCardが呼び出されないようです。