簡體   English   中英

Paypal反復出現問題ruby on rails

[英]Paypal recurring questions ruby on rails

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

我現在一切正常,除了我現在正在努力弄清楚我怎么能知道用戶是否取消了他們在paypal中的訂閱。

我做了什么

我已設法在paypal商家帳戶中設置IPN網址,每次有人訂閱它都會將數據從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

請注意 ,我不想立即更新users屬性,我想等到月份訂閱結束。

我目前正將他們的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

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 ,在PayPal IPN變量中查找有關txn_type列表的更多詳細信息)

  2. 將配置文件/訂閱與數據庫條目協調並執行操作

    將來自IPN消息的recurring_payment_id=I-30FKJ55UV1RW與預先存儲的數據庫條目paypal_recurring_profile_token ,並采取措施更新user_role_id字段。 (立即停止訂閱或根據您的業務模式更新/設置新的到期日期)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM