- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在使用 Stripe 进行订阅,我已将其设置为当用户取消订阅(以关闭自动续订)时,它将保持订阅有效,直到 Stripe 的计费期结束。
该操作通过 Stripe 起作用,但我如何设置才能使数据库中的 cancelled
列产生相同的效果?目前,如果用户点击取消订阅链接,它将把他们的 cancelled
列标记为 1
。我希望它在计费期结束之前不标记为已取消,以便用户可以继续访问该网站,直到他们的最后一个计费日(我打开了 autorenwal)
我已经阅读了 txdavidtx 的建议。他的建议是将所有用户在计费期结束时标记为已取消。该方法不适合我要完成的任务。
我将订阅设置为自动续订。我需要创建一个 cancel
操作,该操作只会将 current_user
标记为在其计费周期结束时已取消。
例如:
用户 A 在 9 月 27 日注册了每月订阅。用户 A 在 12 月 15 日决定取消订阅。用户 A 的订阅还剩 12 天。用户 A 单击 cancel
链接。用户 A 在他们的 PayPal 或 Stripe 账户中取消了自动续订和订阅。在我的数据库中,它们的 cancelled
属性值在这 12 天结束(12 月 27 日)之前不会更改。
如果有人可以提供帮助,那就太好了。
订阅 Controller :
def new
plan = Plan.find(params[:plan_id])
@subscription = plan.subscriptions.build
render layout: 'new_application'
if params[:PayerID]
@subscription.paypal_customer_token = params[:PayerID]
@subscription.paypal_payment_token = params[:token]
@subscription.email = @subscription.paypal.checkout_details.email
end
end
def create
@subscription = Subscription.new(params[:subscription])
if @subscription.save_with_payment
redirect_to @subscription, :notice => "Thank you for subscribing!"
else
render :new
end
end
def show
@subscription = Subscription.find(params[:id])
render layout: 'new_application'
end
def paypal_checkout
plan = Plan.find(params[:plan_id])
subscription = plan.subscriptions.build
redirect_to subscription.paypal.checkout_url(
return_url: new_subscription_url(:plan_id => plan.id),
cancel_url: root_url
)
end
def updatesubscription
@user = current_user
@customer = Stripe::Customer.retrieve(@user.subscription.stripe_customer_token)
if @user.subscription.plan_id == 12
@customer.update_subscription(:plan => "1", :prorate => true)
current_user.subscription.update_attributes(:plan_id => 1)
flash.alert = 'Your subscription has been changed to monthly!'
redirect_to root_url
elsif @user.subscription.plan_id == 1
@customer.update_subscription(:plan => "12", :prorate => true)
current_user.subscription.update_attributes(:plan_id => 12)
current_user.save!
flash.alert = 'Your subscription has been changed to annually!'
redirect_to root_url
end
end
def cancelsubscription
@user = current_user
@customer = Stripe::Customer.retrieve(@user.subscription.stripe_customer_token)
@customer.cancel_subscription(:at_period_end => true)
current_user.subscription.update_attributes(:cancelled => 1)
current_user.save!
flash.alert = 'Your subscription has been cancelled successfully!'
redirect_to root_url
end
def showcard
@user = current_user
Stripe::Customer.retrieve(@user.subscription.stripe_customer_token).cards.all()
end
def suspend
@user = current_user
@user.subscription.suspend_paypal
current_user.subscription.update_attributes(:cancelled => 1)
flash.alert = 'Billing has been suspended!'
redirect_to root_url
end
def reactivate
@user = current_user
@user.subscription.reactivate_paypal
current_user.subscription.update_attributes(:cancelled => nil)
flash.alert = 'Billing has been activated!'
redirect_to root_url
end
def edit_card
@user = current_user
end
def update_card
@user = current_user
card_info = {
name: params[:name],
number: params[:number],
exp_month: params[:date][:month],
exp_year: params[:date][:year],
cvc: params[:cvc]
}
if @user.subscription.update_card(@subscriber, card_info)
flash.alert = 'Saved. Your card information has been updated.'
redirect_to root_url
else
flash.alert = 'Stripe reported an error while updating your card. Please try again.'
redirect_to root_url
end
end
end
最佳答案
我认为最简单的方法是使用 stripe webhooks ,一旦订阅结束,条纹就会用 customer.subscription.deleted ping 您的系统。事件,此时您应该取消用户订阅。
设置非常简单。
检测用户并使用 at_period_end 参数 true 取消他的订阅
customer = Stripe::Customer.retrieve("cus_3R1W8PG2DmsmM9")customer.subscriptions.retrieve("sub_3R3PlB2YlJe84a").delete(:at_period_end => true
A customer.subscription.updated event is immediately triggered if you cancel a subscription at the end of the billing period instead, reflecting the change in the subscription’s cancel_at_period_end value. When the subscription is actually canceled at the end of the period, a customer.subscription.deleted event will occur. Stripe Doc
4- Then Setup your callback controller and detect subscription deleted
<pre>
class StripeEventsController
skip_before_filter :verify_authenticity_token
def catch
object = params[:data][:object]
case params[:type]
when "customer.subscription.deleted"
customer = object[:id]
user = User.find_by_stripe_id(customer)
user.subscription.update_attributes(cancelled: "1")
end
end
结束
关于ruby-on-rails - 在结算期后显示用户订阅已取消,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24894841/
我有一个 MySQL 数据库,其中包含订单表和具有可用库存的零件号表。 例如 ==Orders Table== part_number order_date qty ==Stock Table== p
我正在使用 Libgdx + Android Studio 并尝试实现 Google Play Billing。我按照 here 中的说明进行操作.我修改了我的依赖项,如示例所示: dependenc
背景:我们有一个电视应用程序,它提供每月订阅作为其唯一的应用程序内项目。 我主要是在寻找我认为是真实的确认: 从 Google Play 计费库 2.0 版开始,就有一种称为待定购买的东西。主要的实际
我正在尝试集成 Google Play 结算。 这是我的 onCreate : private final static String TAG = "MainActivity" ; priva
我遵循了 Google 开发者文档中的所有最佳实践:https://developer.android.com/google/play/billing/billing_library_overview
我想知道文档是否将使用 ProGuard 的含义错误(相反)? 来源:https://developer.android.com/google/play/billing/billing_library
编辑:因为有些人仍在检查这个线程,我想提一下,这是非常过时的,因为它是关于应用程序购买中的 v2,现在已弃用。请查看latest (目前是 v3)文档,非常简单 关于这个问题有很多话题,我想我理解这个
在 2020 年 11 月之前,Google Play 上的 Android 应用必须管理“帐户保留”状态。 https://developer.android.com/distribute/play
我创建了一个带有应用内计费的测试应用。将其上传到 google play 并将其发送给 beta 测试人员。当他们尝试购买时,他们会收到 Error retrieving information fr
我是一名优秀的程序员,十分优秀!