我正在尝试通过braintree.js 以一种形式提交一个创建新用户(设计)和支付令牌的表单。我的 html 表单看起来像这样。
<div class="container">
<h2 class='registration'>Sign up</h2>
<%= form_for(resource, as: resource_name, url: registration_path(resource_name), html: {:class => 'col-sm-12'}) do |f| %>
<%= devise_error_messages! %>
<div class="form-horizontal">
<%= f.label :email, class: "col-sm-3 control-label" %>
<div class="col-sm-7">
<%= f.email_field :email, class: "form-control" %>
</div>
</div><br /><br />
<div class="form-horizontal">
<%= f.label :full_name, class: "col-sm-3 control-label" %>
<div class="col-sm-7">
<%= f.text_field :full_name, class: "form-control",autofocus: true %>
</div>
</div><br /><br />
<div class="form-horizontal">
<%= f.label :password, class: "col-sm-3 control-label" %>
<div class="col-sm-7">
<%= f.password_field :password, autocomplete: "off", class: "form-control" %>
</div>
</div><br /><br />
<div class="form-horizontal">
<%= f.label :password_confirmation, class: "col-sm-3 control-label" %>
<div class="col-sm-7">
<%= f.password_field :password_confirmation, autocomplete: "off", class: "form-control" %>
</div>
</div><br /><br />
<input data-braintree-name="number" value="4111111111111111">
<input data-braintree-name="cvv" value="100">
<input data-braintree-name="expiration_month" value="10">
<input data-braintree-name="expiration_year" value="2020">
<div id="braintree-container"></div>
<script src="https://js.braintreegateway.com/v2/braintree.js"></script>
<script>
braintree.setup("MY BRAINTREE TOKEN",
"custom",
{
container: "braintree-container",
paymentMethodNonceInputField: "payment-method-nonce"}
);
var client = new braintree.api.Client({clientToken: <%= @client_token %>});
client.tokenizeCard({number: "4111111111111111", expirationDate: "10/20"}, function (err, nonce) {
</script>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-6">
<%= f.submit "Sign up", class: "btn btn-primary form-registration", id: "user-form-submit" %>
</div>
</div><br /><br />
<% end %>
</div>
当我提交这个时,我认为应该发生的事情是。Rails 创建了一个新用户。然后 Braintree.js 使用 CC 信息向他们的服务发出请求,并返回一个带有值的 params[:payment method_nonce]。但是会发生什么是用户被创建,但我没有得到有关 payment_method_nonce 的信息。
你可能会问我为什么要从一页添加所有这些信息?一旦用户注册,我计划创建一个后台工作人员来创建订阅。
控制器(我的用户控制器)
class Users::RegistrationsController < Devise::RegistrationsController
def new
@client_token = Braintree::ClientToken.generate()
super
end
def create
super
end
def configure_sign_up_params
devise_parameter_sanitizer.for(:sign_up) << [:full_name, :credit_card, :cvc,
:expiration_month, :expiration_year, :token, :client_token]
end
我的架构看起来像这样
create_table "users", force: true do |t|
t.string "email", default: "", null: false
t.string "encrypted_password", default: "", null: false
t.datetime "created_at"
t.datetime "updated_at"
t.string "full_name", null: false
t.string "token"
end
附加信息
-Rails 4 -Ruby 2.0 - Braintree.js v2