Sha256: 192dfb7908302853b6618004be27200d37a2ab93eef749b518119c1d3014430e

Contents?: true

Size: 1.34 KB

Versions: 5

Compression:

Stored size: 1.34 KB

Contents

module Spree
  class Recurring < Spree::Base
    class StripeRecurring < Spree::Recurring
      module ApiHandler 
        module PlanApiHandler
          def create_plan(plan)
            raise_invalid_object_error(plan, Spree::Plan)
            Stripe::Plan.create(
              amount: stripe_amount(plan.amount),
              interval: plan.interval,
              interval_count: plan.interval_count,
              name: plan.name,
              currency: plan.currency,
              id: plan.api_plan_id,
              trial_period_days: plan.trial_period_days
            )
          end

          def delete_plan(plan)
            raise_invalid_object_error(plan, Spree::Plan)
            stripe_plan = retrieve_api_plan(plan)
            stripe_plan.delete
          end

          def update_plan(plan)
            raise_invalid_object_error(plan, Spree::Plan)
            stripe_plan = retrieve_api_plan(plan)
            stripe_plan.name = plan.name
            stripe_plan.save
          end

          def set_api_plan_id(plan)
            plan.api_plan_id = "KS-Plan-#{Time.current.to_i}"
          end

          private

          def retrieve_api_plan(plan)
            Stripe::Plan.retrieve(plan.api_plan_id)
          end

          def stripe_amount(amount)
            (amount * 100).to_i
          end
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
spree_account_recurring-2.0.0 app/models/concerns/spree/recurring/stripe_recurring/api_handler/plan_api_handler.rb
spree_account_recurring-1.3.1 app/models/concerns/spree/recurring/stripe_recurring/api_handler/plan_api_handler.rb
spree_account_recurring-1.2.1 app/models/concerns/spree/recurring/stripe_recurring/api_handler/plan_api_handler.rb
spree_account_recurring-1.3.0 app/models/concerns/spree/recurring/stripe_recurring/api_handler/plan_api_handler.rb
spree_account_recurring-1.2.0 app/models/concerns/spree/recurring/stripe_recurring/api_handler/plan_api_handler.rb