Permalink
Browse files

cancellation ipn notification are now processed, subscription is mark…

…ed as cancelled and user is no longer subscriber
  • Loading branch information...
Rija Ménagé
Rija Ménagé committed Feb 10, 2014
1 parent 9e2f7b1 commit aa4a3744aff717683c4b0319d6ee2cccdb0cb0f0
@@ -88,6 +88,23 @@ def create
rescue ActiveRecord::RecordNotUnique
Rails.logger.warn "Duplicate IPN message: #{request.raw_post}"
end
elsif request.params[:txn_type] == "subscr_cancel"
user = request.params[:custom]
user_instance = User.find(user)
amount = request.params[:mc_amount3]
plan = request.params[:item_number]
plan_id = get_plan_id(plan)
subscription = Subscription.find_by_user_id_and_plan_id_and_amount(user, plan_id, amount)
if subscription
subscription.status = Subscription::STATUSES["cancelled"]
Rails.logger.info "Updating subscription #{subscription.id} to status: #{Subscription::STATUSES["cancelled"]}"
subscription.save
user_instance.remove_role :subscriber
else
Rails.logger.error "No subscription found for #{user}, #{plan_id}, #{amount}"

end

else
notification.save
end
@@ -7,7 +7,8 @@ class Subscription < ActiveRecord::Base
"error" => 0,
"paid" => 1,
"expired" => 2,
"terminated" => 3
"terminated" => 3,
"cancelled" => 4
}

end
@@ -41,6 +41,11 @@
post("/paypal_notifications",@payment_message)
end

Given(/^paypal has sent a cancellation notification to our platform$/) do
@cancel_message="amount1=0.00&amount3=19.95&address_status=confirmed&subscr_date=00:56:37 Feb 06, 2014 PST&payer_id=4GHMU6FGZ24WU&address_street=456, White Lake&mc_amount1=0.00&mc_amount3=19.95&charset=Big5&address_zip=VX 345&first_name=Rija&reattempt=1&address_country_code=GB&address_name=Ted Blank&notify_version=3.7&subscr_id=I-YD2BBKUPYMFY&custom=1&payer_status=verified&business=seller@shop.com&address_country=United Kingdom&address_city=London&verify_sign=AqtJPMlUVfy3SOYR9I5hm9h9mES0AnbNSvAKiugbpLxLxLdLq2af6tnc&payer_email=torsk@bamboo.com&btn_id=74592484&last_name=Blank&address_state=London&receiver_email=seller@shop.com&recurring=1&txn_type=subscr_cancel&item_name=CCQ Solo - 1 project/3 team members - monthly&mc_currency=USD&item_number=1741&residence_country=GB&period1=10 D&period3=1 M&ipn_track_id=6c81849f6b8c9"
post("/paypal_notifications",@cancel_message)
end


When(/^our platform has validated the authenticity of the message$/) do
# 1. our platform makes a POST call to paypal endpoint with identical message
@@ -100,3 +105,14 @@
subscription = Subscription.find_by_user_id(1)
subscription.status.should eq(Subscription::STATUSES[status])
end

When(/^the user cancels her subscription$/) do
step 'paypal has sent a cancellation notification to our platform'
end

Then(/^the user is no longer a subscriber$/) do
user = User.find(1)
user.has_role?(:subcriber).should be_false
end


@@ -38,11 +38,18 @@ And the subscribtion status change to "trial"
Scenario: A member signed up for a plan make first payment
Given a member is signed in
And a subscription has been created
And the first instalment has been paid
When the first instalment has been paid
Then the subscribtion status change to "paid"


@ok @use-test-env
Scenario: A member signed up for a plan cancels her subscription
Given a member is signed in
And a subscription has been created
When the user cancels her subscription
Then the subscribtion status change to "cancelled"
And the user is no longer a subscriber


Scenario: A member signed up for a plan changes her subscription

@@ -4,10 +4,10 @@
# executed.
Warden.test_mode!
Rails.logger.debug "Starting scenario: #{scenario.title}"
if scenario.title =~ /paypal/ || scenario.title =~ /subscription notification/ || scenario.title =~ /payment notification/ || scenario.title =~ /first payment/
if scenario.title =~ /paypal/ || scenario.title =~ /subscription notification/ || scenario.title =~ /payment notification/ || scenario.title =~ /first payment/ || scenario.title =~ /cancels her subscription/
RestClient.post "http://localhost:4578/doubles", "fullpath=/cgi-bin/webscr%3Fcmd=_notify-validate&verb=POST&content=VERIFIED&status=200"
end
if scenario.title =~ /A member subscription is activated upon subscription notification/ || scenario.title =~ /A member signed up for a plan make first payment/
if scenario.title =~ /A member subscription is activated upon subscription notification/ || scenario.title =~ /A member signed up for a plan make first payment/ || scenario.title =~ /cancels her subscription/
Plan.create(name:'solo',paypal_dev_button: '1741')
end
end

0 comments on commit aa4a374

Please sign in to comment.