Payola宝石与条纹 - 更新payola_subscription表

时间:2016-07-23 09:14:10

标签: ruby-on-rails stripe-payments payola

我刚刚开始关注payola宝石并遇到问题。 gem创建了一个名为payola_subscription的表,它应该记录订阅创建,取消等。到目前为止,当我创建一个新的订阅时,它被记录在这个表中,但当我取消订阅时,这个表没有得到更新。我的问题是:如果执行诸如cancel subscription之类的操作,或者我必须在我的cancel方法中手动实现这些操作,那么payola gem是否应该更新此表上的记录?奇怪的是(对我而言)Payola::UpdateCard.call方法中使用的card_update使用新的信用卡号更新数据库,但Payola::CancelSubscription.call不更新表。以下是取消订阅的控制器代码。我在忽视或做错了什么?

# subscriptions_controller.rb
class SubscriptionsController < ApplicationController
  include Payola::StatusBehavior

  def create
    owner = current_user # this is just an example for Devise
    # set your plan in the params hash
    params[:plan] = SubscriptionPlan.find_by(id: params[:plan_id])
    # call Payola::CreateSubscription
    subscription = Payola::CreateSubscription.call(params, owner)
    current_user.subscription_plan_id=params[:plan_id]
    current_user.save
    flash.notice = "Subscription successfully created"
    UserMailer.subscribe_email(current_user).deliver_now
    render_payola_status(subscription)
  end

  def cancel
    if params[:guid].present?
       @subscription = Payola::Subscription.find_by(:guid => params[:guid])
       Payola::CancelSubscription.call(@subscription) if !@subscription.nil?
       current_user.subscription_plan_id=nil
       current_user.save
       UserMailer.unsubscribe_email(current_user).deliver_now
       flash.notice = "Subscription successfully cancelled"
       redirect_to dashboard_path
    end
  end

  def card_update
      @subscription = Payola::Subscription.find_by!(guid: params[:guid])
      Payola::UpdateCard.call(@subscription, params[:stripeToken])
      flash.notice = "Your credit card successfully updated!"
      render_payola_status(@subscription)
  end

end

1 个答案:

答案 0 :(得分:0)

设置Stripe webhook以获取从Stripe同步到您的应用的取消和其他更改。有关https://github.com/peterkeen/payola#installation的webhook设置的详细信息。

(此答案的原始来源https://github.com/peterkeen/payola/issues/237#issuecomment-234737250