使用即时付款通知取消paypal定期付款

时间:2013-05-16 17:42:18

标签: paypal paypal-ipn

从我收集的几个stackoverflow帖子中,当用户取消PayPal定期付款时,即时付款通知会发送到IPN设置中设置的指定网址。但我无法收集的是在查询字符串中将数据发送到此URL的内容。我发现了这个链接:

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

它提供了一个变量列表,我假设这些变量是作为使用IPN设置中指定的url发送的查询字符串的一部分发送的。如果这是真的,那么这意味着我知道此通知是取消通知,因为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。

1 个答案:

答案 0 :(得分: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] => chad@x.com
    [address_country] => United States
    [address_city] => San Jose
    [verify_sign] => AQ3T0Omh4bXNzomBbYUO2LL1dphyAiWU5Sa7wpw8spAU-Pb1YFnm-mig
    [payer_email] => mts_us_per@ccaples.com
    [last_name] => Testing
    [address_state] => CA
    [receiver_email] => chad@x.com
    [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
)
相关问题