2019-01-21 16:27:59 +01:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
# Provides methods for Plan & PartnerPlan actions
|
|
|
|
class PlansService
|
|
|
|
class << self
|
|
|
|
def create(type, partner, params)
|
|
|
|
if params[:group_id] == 'all'
|
|
|
|
plans = type.constantize.create_for_all_groups(params)
|
|
|
|
return false unless plans
|
|
|
|
|
|
|
|
plans.each { |plan| partner.add_role :partner, plan } unless partner.nil?
|
|
|
|
{ plan_ids: plans.map(&:id) }
|
|
|
|
else
|
|
|
|
plan = type.constantize.new(params)
|
2022-11-15 09:47:28 +01:00
|
|
|
return { errors: plan.errors.full_messages } unless plan.save
|
|
|
|
|
|
|
|
partner&.add_role :partner, plan
|
2022-05-17 17:38:00 +02:00
|
|
|
{ plan_ids: [plan.id] }
|
2019-01-21 16:27:59 +01:00
|
|
|
end
|
2021-04-30 16:07:19 +02:00
|
|
|
rescue PaymentGatewayError => e
|
2019-01-21 16:27:59 +01:00
|
|
|
{ errors: e.message }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|