Sha256: 91c15129dc4fe7cf6a52cca6d5f1832031386903b49755138be6d8f0b4749d34

Contents?: true

Size: 736 Bytes

Versions: 11

Compression:

Stored size: 736 Bytes

Contents

module StripeLocal
  module SyncPlans
    extend ActiveSupport::Concern

    included do
      after_create  :synchronize_create

      private :synchronize_create, :synchronize_destroy
    end

    module ClassMethods

      def delete id, destroy_remote = true
        if super( id )
          synchronize_destroy( id ) if destroy_remote == true
        end
      end
    end

    def synchronize_create
      hash = self.attributes
      unless !!hash.delete( :synced )
        Stripe::Plan.create hash #TODO: handle asynchronously
      end
    end

    def synchronize_destroy id
      begin
        Stripe::Plan.delete id
      rescue Stripe::Error
      end
    end

    def api_destroy plan
      Plan.destroy
    end

  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
stripe_local-0.2.5 app/mixins/stripe_local/sync_plans.rb
stripe_local-0.2.4 app/mixins/stripe_local/sync_plans.rb
stripe_local-0.2.3 app/mixins/stripe_local/sync_plans.rb
stripe_local-0.2.2 app/mixins/stripe_local/sync_plans.rb
stripe_local-0.2.1 app/mixins/stripe_local/sync_plans.rb
stripe_local-0.2.0 app/mixins/stripe_local/sync_plans.rb
stripe_local-0.1.3 app/mixins/stripe_local/sync_plans.rb
stripe_local-0.1.2 app/mixins/stripe_local/sync_plans.rb
stripe_local-0.1.1 app/mixins/stripe_local/sync_plans.rb
stripe_local-0.1.0 app/mixins/stripe_local/sync_plans.rb
stripe_local-0.0.2 app/mixins/stripe_local/sync_plans.rb