订阅不是在自定义条带表单上创建,而是在Stripe上创建订阅
目前我的代码没有在数据库中创建实际的订阅项,但它正在Stripe上创建订阅。
我已经检查了日志,在订阅表单完成时我看不到任何创建的项目。 我玩了一下并将stripe代码从before_create更改为after_create,这似乎有效,但这没有意义,因为我们只能在用户通过Stripe订阅时给予用户订阅。
有任何想法吗? 谢谢!
subscriptions_controller.rb
class SubscriptionsController "Thank you for subscribing!" else render :new end end def show @subscription = Subscription.find(params[:id]) end def subscription_params params.require(:subscription).permit(:stripe_card_token) end end
subscription.rb
class Subscription stripe_card_token, :description => "name", :plan => 121, :email => "email") self.stripe_customer_id = customer.id self.plan = 121 end end
subscriptions.js.coffee
# Place all the behaviors and hooks related to the matching controller here. # All this logic will automatically be available in application.js. jQuery -> Stripe.setPublishableKey($('meta[name="stripe-key"]').attr('content')) subscription.setupForm() subscription = setupForm: -> $('#new_subscription').submit (e) -> $('input[type=submit]').attr('disabled', true) subscription.processCard() return false processCard: -> card = number: $('#card_number').val() cvc: $('#card_code').val() expMonth: $('#card_month').val() expYear: $('#card_year').val() Stripe.createToken(card, subscription.handleStripeResponse) handleStripeResponse: (status, response) -> if status == 200 $('#subscription_stripe_card_token').val(response.id) $('#new_subscription')[0].submit() else $('#stripe_error').text(response.error.message) $('input[type=submit]').attr('disabled', false) false
new.html.erb
Subscribe
{:class => 'main-form'} do |f| %> Nothing is billed to your card for 7 days. Guaranteed.
If you choose to continue after 7 days, only then will you be billed. 'Credit Card Number' %> 'Security Code on Card (CVC)' %>
我能够通过删除以下内容来解决此问题:
before_create :save_with_payment