gpt4 book ai didi

ruby-on-rails - Paypal 重复出现问题 ruby​​ on rails

转载 作者:太空宇宙 更新时间:2023-11-03 15:44:06 24 4
gpt4 key购买 nike

我一直在关注 Railscast 289有关如何使用 Paypal 进行定期付款的教程。

我现在一切正常,除了我现在正在努力弄清楚我如何才能知道用户是否取消了他们在 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 在这种情况下是他们订阅的计划

最佳答案

IPN 确保当您的交易发生任何变化时您会收到通知,从经常性付款的角度来看,当您的客户取消配置文件时,触发的 POST-Back 事件将发送到您的 IPN 监听器。

配置文件取消的示例原始 POST-Back 消息如下所示,

payment_cycle=Daily &txn_type=recurring_payment_profile_cancel &last_name=US &next_payme
nt_date=N/A &residence_country=US &initial_payment_amount=0.00 &currency_code=USD &t
ime_created=19:25:09 Sep 24, 2015 PDT &verify_sign=AgUGxKs4vGiEqeit6IyHkIjDJVpeAqCMRVC4wh9CZYotn
Jqrr-3oWsFe &period_type= Trial &payer_status=verified &test_ipn=1 &tax=0.00 &pa
yer_email=USP@email.com &first_name=Payer &receiver_email=USM@email.com &payer_id=8FMFQ2
KVYYHTY &product_type=1 &shipping=0.00 &amount_per_cycle=2.00 &profile_status=Cancel
led &charset=gb2312 &notify_version=3.8 &amount=2.00 &outstanding_balance=0.00 &recurring_payment_id=I-30FKJ55UV1RW &product_name=RP BA Test &ipn_track_id=65583f3a80f10
  1. 当取消发生时,您如何能够注意到?

    读取 IPN 消息中的参数 txn_type,并用它确定事件类型(在您的情况下,事件类型将是 recurring_payment_profile_cancel,在 上找到更多详细信息>txn_type 列表在 PayPal IPN Variables )

  2. 将配置文件/订阅与您的数据库条目核对并采取行动

    将 IPN 消息中的 recurring_payment_id=I-30FKJ55UV1RW 与您预先存储的数据库条目 paypal_recurring_profile_token 匹配,并采取措施更新 user_role_id 领域。 (立即停止订阅或根据您的业务模式更新/设置新的到期日期)

关于ruby-on-rails - Paypal 重复出现问题 ruby​​ on rails,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32661424/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com