【发布时间】:2023-03-26 06:00:01
【问题描述】:
我一直在关注 Railscast 289 关于如何使用 Paypal 进行定期付款的教程。
我现在一切正常,除了我现在正在努力弄清楚我如何才能知道用户是否在贝宝中取消了他们的订阅。
我做了什么
我已经设法在 paypal 商家帐户中设置了 IPN url,每次有人订阅它都会将数据从 paypal 发送到我的 webhook。
现在我正在存储 paypal 发送给我的所有参数,但我无法确定我应该检查哪些参数,以便了解用户是否取消了订阅,或者是否没有足够的资金等。
至少我认为它是这样工作的。
我正在使用Paypal Recurring Gem
问题
当 paypal 向我发送他们的 IPN 到我的 webhook 时,我如何注意到用户取消了他们的订阅。
我的 webhook atm
def create
user_id = Subscription.find_by(paypal_customer_token: params[:payer_id]).user_id
PaymentNotification.create!(params: params, user_id: user_id, user_role_id: params[:item_number], status: params[:payment_status], transaction_id: params[:txn_id])
@user = User.find_by(id: user_id)
if PaymentNotification.last.params[:profile_status] == "Cancelled"
@user.update_attributes(user_role_id: 1)
end
render nothing: true
end
通知,我不想立即更新用户属性,我想等到他们的月订阅结束。
我目前将他们的 IPN 呼叫存储在 PaymentNotification 表中。
create_table "payment_notifications", force: :cascade do |t|
t.text "params"
t.integer "user_role_id"
t.string "status"
t.string "transaction_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.integer "user_id"
end
另外,检查这些参数以便对尚未付款或取消订阅的用户采取行动的最佳方法是什么?
我有另一个存储订阅的表
create_table "subscriptions", force: :cascade do |t|
t.integer "user_role_id"
t.integer "user_id"
t.string "paypal_customer_token"
t.string "paypal_recurring_profile_token"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
user_role 在这种情况下是他们订阅的plan。
【问题讨论】:
-
您是否考虑将订阅到期日期存储在您的订阅表中?当收到通知时,您会更新该值。您需要一个守护程序或 chronjob 来每天/每小时/等运行。
标签: ruby-on-rails paypal paypal-subscriptions recurring-billing