私のアプリケーションには、ユーザーがいます。ユーザーが後で使用するためにクレジット カード情報を保存できるように、Balanced Payments を利用しようとしています。以下の 2 つのリンクをガイドとしてたどりましたが、現在、次のエラーが発生しています。
Routing Error
No route matches [POST] "/store_credit_card"
私はこのGISTとRailsフォーム送信ハンドラーが実行されていないことに従いました。
balanced_controller.rb
- 作成した_credit_card_form.html.haml
- 作成して下に置くapp>view>balanced
credit_card_submission.js
- 作成して下に置くapp>assets>javascript
:balanced_account_uri string
ユーザー モデルにフィールドを追加しました- Balanced マーケットプレイス uri の .js ファイルのプレースホルダー テキストを置き換えました。
- balanced_controller.rb のメソッド用に routes.rb を更新
誰かがなぜそれが機能していないのか知っていますか?
ルート.rb
resources :users do
resources :balanced do
member do
post :store_credit_card, :create_balanced_account
end
end
end
ビュー/ユーザー/edit.html.erb
<div class = "container">
<script type="text/javascript" src="https://js.balancedpayments.com/v1/balanced.js"></script>
<script type="text/javascript">
balanced.init('YOUR MARKETPLACE URI HERE');
</script>
<%= render 'balanced/credit_card_form' %>
</div>
ビュー/バランス/_credit_card_form.html.haml
= form_tag "/store_credit_card", :method => :post, :id => "credit-card-form", :class => "form-horizontal" do
.control-group
= label_tag "cc-number", "Card Number", :class => "control-label"
.controls
= text_field_tag "cc-number", nil, :placeholder => "Enter Credit Card Number", :class => "cc-number", :autocomplete => "off"
.control-group
= label_tag "cc-em", "Expiration", :class => "control-label"
.controls
= 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"
.control-group
= label_tag "cc-csc", "Security Code", :class => "control-label"
.controls
= text_field_tag "cc-csc", nil, :placeholder => "Security Code", :class => "cc-csc", :autocomplete => "off"
.control-group
.controls
= submit_tag "Submit", :class => "btn btn-primary btn-large"
assets/javascript/credit_card_submissions.js
var marketplaceUri = 'YOUR MARKETPLACE URI HERE';
var requestBinUrl = '/store_credit_card'
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();
break;
case 400:
console.log(response.error);
break;
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);
};
$(function(){
$('#credit-card-form').submit(tokenizeCreditCard);
});
Balanced_controller.rb
class BalancedController < ApplicationController
def create_balanced_account
current_user.balanced_account_uri = Balanced::Marketplace.my_marketplace.create_account(:email => current_user.email, :type => 'person').uri
current_user.save
# add a redirect to the desired path
redirect_to root_url
end
def store_credit_card
balanced_account = Balanced::Account.find(current_user.balanced_account_uri)
balanced_account.add_card(params[:balancedCreditCardURI])
# add a redirect to the desired path
redirect_to root_url
end
def store_bank_account
balanced_account = Balanced::Account.find(current_user.balanced_account_uri)
balanced_account.add_card(params[:balancedBankAccountURI])
# add a redirect to the desired path
redirect_to root_url
end
def process_payment
balanced_account = Balanced::Account.find(current_user.balanced_account_uri)
account.debit(
:amount => 1000, # or params[:amount]
:description => "Balanced Payments transaction",
:appears_on_statement_as => "Balanced Payments")
# add a redirect to the desired path
redirect_to root_url
end
end