Permalink
Browse files

sync canceled profiles from paypal

  • Loading branch information...
1 parent 141fc32 commit dcbe924315d16b657b50d8a92bfddd1716b922eb @mreinsch mreinsch committed Jul 1, 2011
View
@@ -22,6 +22,10 @@ Then install the required files:
rails g subscription_fu:install
+## Updating
+
+See UPDATING.md
+
## Configuration
1. Edit config/initializers/subscription\_fu.rb (generated by the install generator)
View
@@ -0,0 +1,19 @@
+# Updating Subscriptions for Rails
+
+## From 0.2.x to 0.3.0
+
+Add the new table subscription_system_initiators using a migration:
+
+ class SubscriptionFuUpdateToZeroThree < ActiveRecord::Migration
+ def self.up
+ create_table "subscription_system_initiators" do |t|
+ t.string "name"
+ t.string "description"
+ end
+ end
+ def self.down
+ drop_table "subscription_system_initiators"
+ end
+ end
+
+
@@ -1,7 +1,7 @@
class SubscriptionFu::Subscription < ActiveRecord::Base
set_table_name :subscriptions
- AVAILABLE_CANCEL_REASONS = %w( update cancel timeout admin )
+ AVAILABLE_CANCEL_REASONS = %w( update cancel gwcancel timeout admin )
default_scope order("created_at ASC", "id ASC")
@@ -108,6 +108,15 @@ def initiate_cancellation(initiator, activation_transaction)
transactions.create_cancellation(initiator, activation_transaction, self)
end
+ def sync_from_gateway!
+ if paypal?
+ if paypal_recurring_details[:status] == SubscriptionFu::Paypal::CANCELED_STATE
+ t = initiate_cancellation(SubscriptionFu::SystemInitiator.paypal_sync_initiator, nil)
+ t.complete(:effective => end_date_when_canceled, :reason => :gwcancel)
+ end
+ end
+ end
+
private
def paypal?
@@ -0,0 +1,7 @@
+class SubscriptionFu::SystemInitiator < ActiveRecord::Base
+ set_table_name :subscription_system_initiators
+
+ def self.paypal_sync_initiator
+ find_or_create_by_name("paypal sync", :description => "Updates subscription status based on status returned by Paypal")
+ end
+end
@@ -29,10 +29,16 @@ def self.up
add_index "subscription_transactions", ["identifier"]
add_index "subscription_transactions", ["subscription_id"]
+
+ create_table "subscription_system_initiators" do |t|
+ t.string "name"
+ t.string "description"
+ end
end
def self.down
drop_table "subscriptions"
drop_table "subscription_transactions"
+ drop_table "subscription_system_initiators"
end
end
@@ -1,3 +1,3 @@
module SubscriptionFu
- VERSION = "0.2.1"
+ VERSION = "0.3.0"
end
@@ -0,0 +1,12 @@
+class SubscriptionFuUpdateToZeroThree < ActiveRecord::Migration
+ def self.up
+ create_table "subscription_system_initiators" do |t|
+ t.string "name"
+ t.string "description"
+ end
+ end
+
+ def self.down
+ drop_table "subscription_system_initiators"
+ end
+end
View
@@ -10,7 +10,7 @@
#
# It's strongly recommended to check this file into your version control system.
-ActiveRecord::Schema.define(:version => 20110516070948) do
+ActiveRecord::Schema.define(:version => 20110701061927) do
create_table "initiators", :force => true do |t|
t.string "desc"
@@ -25,6 +25,11 @@
t.datetime "updated_at"
end
+ create_table "subscription_system_initiators", :force => true do |t|
+ t.string "name"
+ t.string "description"
+ end
+
create_table "subscription_transactions", :force => true do |t|
t.integer "subscription_id", :null => false
t.integer "initiator_id", :null => false
@@ -234,6 +234,16 @@ def should_have_paid_activation_flow(sub_instance, first_sub, prev_sub_is_free =
before { at_time(@now) { @succ = @sub.subject.build_next_subscription('free'); @succ.save! } }
should_build_valid_successor("free", :next_billing, :next_billing)
end
+ context "sync" do
+ before { mock_paypal_delete_profile_with_error("fgsga564aa") }
+ before { at_time(@now) { @sub.sync_from_gateway! } }
+ it "should mark subscription as cancelled" do
+ @sub.reload.should be_canceled
+ @sub.canceled_at.should == Time.parse("2010-02-10 00:00 UTC")
+ @sub.cacnel_reason.should == "gwcacnel"
+ @sub.transactions.last.status.should == "complete"
+ end
+ end
end
context "canceled on paypal, no payments made" do

0 comments on commit dcbe924

Please sign in to comment.