Skip to content
This repository was archived by the owner on Dec 19, 2019. It is now read-only.

Ipn notifications #29

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion lib/paypal/recurring/notification.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,14 @@ def recurring_payment_profile?
type == "recurring_payment_profile_created"
end

def recurring_payment_suspended?
type == "recurring_payment_suspended"
end

def recurring_payment_profile_cancel?
type == "recurring_payment_profile_cancel"
end

def request
@request ||= PayPal::Recurring::Request.new.tap do |request|
request.uri = URI.parse("#{PayPal::Recurring.site_endpoint}?cmd=_notify-validate")
Expand All @@ -57,7 +65,15 @@ def response
end

def valid?
completed? && verified? && email == PayPal::Recurring.email && seller_id == PayPal::Recurring.seller_id
if payment_received?
completed? && verified? && email == PayPal::Recurring.email && seller_id == PayPal::Recurring.seller_id
else
verified? && email == PayPal::Recurring.email
end
end

def payment_received?
express_checkout? || recurring_payment?
end

def completed?
Expand Down
10 changes: 10 additions & 0 deletions spec/paypal/notification_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,16 @@
subject.should be_recurring_payment_profile
end

it "detects recurring payment suspended" do
subject.params[:txn_type] = "recurring_payment_suspended"
subject.should be_recurring_payment_suspended
end

it "detects recurring payment profile cancel" do
subject.params[:txn_type] = "recurring_payment_profile_cancel"
subject.should be_recurring_payment_profile_cancel
end

it "normalizes payment date" do
subject.params[:payment_date] = "20:37:06 Jul 04, 2011 PDT" # PDT = -0700
subject.paid_at.strftime("%Y-%m-%d %H:%M:%S").should == "2011-07-05 03:37:06"
Expand Down