2013-05-16 157 views
1

從我收集的幾個stackoverflow帖子,當用戶取消貝寶定期付款時,即時付款通知發送到IPN設置中設置的指定網址。但是我無法收集的是在查詢字符串中發送到這個URL的數據。我遇到了這個鏈接:取消貝寶定期付款通知付款

https://www.paypal.com/cgi-bin/webscr?cmd=p/acc/ipn-subscriptions-outside 

它提供的,我認爲是在IPN設置中指定的網址發送的查詢字符串的一部分被送到變量列表。如果這是真的,那麼這意味着我知道這個通知是一個取消通知,因爲txn_type的值將是「subscr_cancel」。

但是,我仍然需要知道什麼經常性計劃實際上被取消。因此,我需要知道重複配置文件標記以便將其作爲查詢字符串中的變量進行訪問。

只給你什麼,我想在這裏做一個想法,這裏是一些示例代碼:

def notify_url 
if params[:txn_type] == "subscr_cancel" 
    item_id = Order.where(paypal_recurring_profile_token: params[:recurring_profile_token]).unit_id_for_plan 
    agent_host = CONFIG["agent_#{Rails.env}"]["host"] 
    agent_port = CONFIG["agent_#{Rails.env}"]["port"] 

url = "http://#{agent_host}:#{agent_port}/home/deactivate?item_id=#{item_id}" 
begin 
    resp = Net::HTTP.get(URI.parse(url)) 
    resp = JSON.parse(resp) 
    puts "resp is: #{resp}" 
    true 
    rescue => error 
    raise "Error: #{error}" 
    end 

    if resp["status"] == "success" 
    true 
    end 

end  
end 

所有我需要知道的是,如果txn_type將等於subscr_cancel當發送的通知取消經常性結算? @PP_MTS_Chad已經確認包含recurring_payment_id。我只需要知道是否包含txn_type。

回答

2

當配置文件被取消時,在您的IPN POST中,您將收回變量recurring_payment_id,該變量將取消配置文件的配置文件。

Array 
(
    [amount3] => 69.95 
    [address_status] => confirmed 
    [recur_times] => 5 
    [subscr_date] => 07:31:10 May 17, 2013 PDT 
    [payer_id] => EW4KQ9CQX45F6 
    [address_street] => 1 Main St 
    [mc_amount3] => 69.95 
    [charset] => KOI8-R 
    [address_zip] => 95131 
    [first_name] => MTS 
    [reattempt] => 1 
    [address_country_code] => US 
    [address_name] => MTS Testing 
    [notify_version] => 3.7 
    [subscr_id] => I-628HEBW1V99M 
    [payer_status] => verified 
    [business] => [email protected] 
    [address_country] => United States 
    [address_city] => San Jose 
    [verify_sign] => AQ3T0Omh4bXNzomBbYUO2LL1dphyAiWU5Sa7wpw8spAU-Pb1YFnm-mig 
    [payer_email] => [email protected] 
    [last_name] => Testing 
    [address_state] => CA 
    [receiver_email] => [email protected] 
    [recurring] => 1 
    [txn_type] => subscr_cancel 
    [item_name] => Alice's Weekly Digest 
    [mc_currency] => USD 
    [item_number] => DIG Weekly 
    [residence_country] => US 
    [test_ipn] => 1 
    [period3] => 6 M 
    [ipn_track_id] => 54b49fde502a4 
) 
+0

是:txn_type的值「subscr_cancel」還發送回來了嗎? – JohnMerlino

+0

是的,你會回來的。我在原始答案中添加了IPN POST的示例,當配置文件被取消時我收到了。 –

+1

在該IPN POST中,我沒有看到recurring_payment_id。 – JohnMerlino