diff --git a/app/graphql/mutations/plans/create.rb b/app/graphql/mutations/plans/create.rb index baba41b70be..a31b97d6d97 100644 --- a/app/graphql/mutations/plans/create.rb +++ b/app/graphql/mutations/plans/create.rb @@ -12,7 +12,7 @@ class Create < BaseMutation argument :name, String, required: true argument :code, String, required: true argument :interval, Types::Plans::IntervalEnum, required: true - argument :billing_period, Types::Plans::BillingPeriodEnum, required: true + argument :frequency, Types::Plans::FrequencyEnum, required: true argument :pro_rata, Boolean, required: true argument :pay_in_advance, Boolean, required: true argument :amount_cents, Integer, required: true diff --git a/app/graphql/mutations/plans/update.rb b/app/graphql/mutations/plans/update.rb index 2cf633027cc..0b9f9dde16c 100644 --- a/app/graphql/mutations/plans/update.rb +++ b/app/graphql/mutations/plans/update.rb @@ -12,7 +12,7 @@ class Update < BaseMutation argument :name, String, required: true argument :code, String, required: true argument :interval, Types::Plans::IntervalEnum, required: true - argument :billing_period, Types::Plans::BillingPeriodEnum, required: true + argument :frequency, Types::Plans::FrequencyEnum, required: true argument :pro_rata, Boolean, required: true argument :pay_in_advance, Boolean, required: true argument :amount_cents, Integer, required: true diff --git a/app/graphql/types/plans/billing_period_enum.rb b/app/graphql/types/plans/frequency_enum.rb similarity index 54% rename from app/graphql/types/plans/billing_period_enum.rb rename to app/graphql/types/plans/frequency_enum.rb index ce7cb600535..f9693f168e1 100644 --- a/app/graphql/types/plans/billing_period_enum.rb +++ b/app/graphql/types/plans/frequency_enum.rb @@ -2,8 +2,8 @@ module Types module Plans - class BillingPeriodEnum < Types::BaseEnum - Plan::BILLING_PERIODS.each do |type| + class FrequencyEnum < Types::BaseEnum + Plan::FREQUENCIES.each do |type| value type end end diff --git a/app/graphql/types/plans/object.rb b/app/graphql/types/plans/object.rb index 288a03ef47a..ae49402dc34 100644 --- a/app/graphql/types/plans/object.rb +++ b/app/graphql/types/plans/object.rb @@ -11,7 +11,7 @@ class Object < Types::BaseObject field :name, String, null: false field :code, String, null: false field :interval, Types::Plans::IntervalEnum, null: false - field :billing_period, Types::Plans::BillingPeriodEnum, null: false + field :frequency, Types::Plans::FrequencyEnum, null: false field :pro_rata, Boolean, null: false field :pay_in_advance, Boolean, null: false field :amount_cents, Integer, null: false diff --git a/app/models/plan.rb b/app/models/plan.rb index df2d92605e9..a9b22f0d6f3 100644 --- a/app/models/plan.rb +++ b/app/models/plan.rb @@ -16,13 +16,13 @@ class Plan < ApplicationRecord yearly ].freeze - BILLING_PERIODS = %i[ + FREQUENCIES = %i[ beginning_of_period subscription_date ].freeze enum interval: INTERVALS - enum billing_period: BILLING_PERIODS + enum frequency: FREQUENCIES monetize :amount_cents diff --git a/app/services/plans_service.rb b/app/services/plans_service.rb index 736be8c7d26..ee16035e435 100644 --- a/app/services/plans_service.rb +++ b/app/services/plans_service.rb @@ -8,7 +8,7 @@ def create(**args) code: args[:code], description: args[:description], interval: args[:interval].to_sym, - billing_period: args[:billing_period].to_sym, + frequency: args[:frequency].to_sym, pro_rata: args[:pro_rata], pay_in_advance: args[:pay_in_advance], amount_cents: args[:amount_cents], @@ -43,7 +43,7 @@ def update(**args) plan.code = args[:code] plan.description = args[:description] plan.interval = args[:interval].to_sym - plan.billing_period = args[:billing_period].to_sym + plan.frequency = args[:frequency].to_sym plan.pro_rata = args[:pro_rata] plan.pay_in_advance = args[:pay_in_advance] plan.amount_cents = args[:amount_cents] diff --git a/db/migrate/20220406133642_rename_billing_period_on_plans.rb b/db/migrate/20220406133642_rename_billing_period_on_plans.rb new file mode 100644 index 00000000000..c88360fd34e --- /dev/null +++ b/db/migrate/20220406133642_rename_billing_period_on_plans.rb @@ -0,0 +1,5 @@ +class RenameBillingPeriodOnPlans < ActiveRecord::Migration[7.0] + def change + rename_column :plans, :billing_period, :frequency + end +end diff --git a/db/schema.rb b/db/schema.rb index bf8b41fd869..14a9e079276 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[7.0].define(version: 2022_04_06_130321) do +ActiveRecord::Schema[7.0].define(version: 2022_04_06_133642) do # These are extensions that must be enabled in order to support this database enable_extension "pgcrypto" enable_extension "plpgsql" @@ -119,7 +119,7 @@ t.string "code", null: false t.integer "interval", null: false t.string "description" - t.integer "billing_period", null: false + t.integer "frequency", null: false t.boolean "pro_rata", null: false t.bigint "amount_cents", null: false t.string "amount_currency", null: false diff --git a/schema.graphql b/schema.graphql index 79e64fb9220..9780b64703c 100644 --- a/schema.graphql +++ b/schema.graphql @@ -21,11 +21,6 @@ type BillableMetricCollection { metadata: CollectionMetadata! } -enum BillingPeriodEnum { - beginning_of_period - subscription_date -} - type Charge { amountCents: Int! amountCurrency: CurrencyEnum! @@ -98,7 +93,6 @@ Autogenerated input type of CreatePlan input CreatePlanInput { amountCents: Int! amountCurrency: CurrencyEnum! - billingPeriod: BillingPeriodEnum! charges: [ChargeInput!]! """ @@ -107,6 +101,7 @@ input CreatePlanInput { clientMutationId: String code: String! description: String + frequency: FrequencyEnum! interval: PlanInterval! name: String! payInAdvance: Boolean! @@ -185,6 +180,11 @@ type DestroyPlanPayload { id: ID } +enum FrequencyEnum { + beginning_of_period + subscription_date +} + """ An ISO 8601-encoded datetime """ @@ -319,7 +319,6 @@ type Organization { type Plan { amountCents: Int! amountCurrency: CurrencyEnum! - billingPeriod: BillingPeriodEnum! """ Number of charges attached to a plan @@ -334,6 +333,7 @@ type Plan { """ customerCount: Int! description: String + frequency: FrequencyEnum! id: ID! interval: PlanInterval! name: String! @@ -452,7 +452,6 @@ Autogenerated input type of UpdatePlan input UpdatePlanInput { amountCents: Int! amountCurrency: CurrencyEnum! - billingPeriod: BillingPeriodEnum! charges: [ChargeInput!]! """ @@ -461,6 +460,7 @@ input UpdatePlanInput { clientMutationId: String code: String! description: String + frequency: FrequencyEnum! id: String! interval: PlanInterval! name: String! diff --git a/schema.json b/schema.json index 729d2fba8ea..f8d201d0447 100644 --- a/schema.json +++ b/schema.json @@ -250,29 +250,6 @@ "inputFields": null, "enumValues": null }, - { - "kind": "ENUM", - "name": "BillingPeriodEnum", - "description": null, - "interfaces": null, - "possibleTypes": null, - "fields": null, - "inputFields": null, - "enumValues": [ - { - "name": "beginning_of_period", - "description": null, - "isDeprecated": false, - "deprecationReason": null - }, - { - "name": "subscription_date", - "description": null, - "isDeprecated": false, - "deprecationReason": null - } - ] - }, { "kind": "SCALAR", "name": "Boolean", @@ -927,14 +904,14 @@ "deprecationReason": null }, { - "name": "billingPeriod", + "name": "frequency", "description": null, "type": { "kind": "NON_NULL", "name": null, "ofType": { "kind": "ENUM", - "name": "BillingPeriodEnum", + "name": "FrequencyEnum", "ofType": null } }, @@ -1440,6 +1417,29 @@ "inputFields": null, "enumValues": null }, + { + "kind": "ENUM", + "name": "FrequencyEnum", + "description": null, + "interfaces": null, + "possibleTypes": null, + "fields": null, + "inputFields": null, + "enumValues": [ + { + "name": "beginning_of_period", + "description": null, + "isDeprecated": false, + "deprecationReason": null + }, + { + "name": "subscription_date", + "description": null, + "isDeprecated": false, + "deprecationReason": null + } + ] + }, { "kind": "SCALAR", "name": "ID", @@ -2113,24 +2113,6 @@ ] }, - { - "name": "billingPeriod", - "description": null, - "type": { - "kind": "NON_NULL", - "name": null, - "ofType": { - "kind": "ENUM", - "name": "BillingPeriodEnum", - "ofType": null - } - }, - "isDeprecated": false, - "deprecationReason": null, - "args": [ - - ] - }, { "name": "chargeCount", "description": "Number of charges attached to a plan", @@ -2239,6 +2221,24 @@ ] }, + { + "name": "frequency", + "description": null, + "type": { + "kind": "NON_NULL", + "name": null, + "ofType": { + "kind": "ENUM", + "name": "FrequencyEnum", + "ofType": null + } + }, + "isDeprecated": false, + "deprecationReason": null, + "args": [ + + ] + }, { "name": "id", "description": null, @@ -3223,14 +3223,14 @@ "deprecationReason": null }, { - "name": "billingPeriod", + "name": "frequency", "description": null, "type": { "kind": "NON_NULL", "name": null, "ofType": { "kind": "ENUM", - "name": "BillingPeriodEnum", + "name": "FrequencyEnum", "ofType": null } }, diff --git a/spec/factories/plan_factory.rb b/spec/factories/plan_factory.rb index 73d1c7144ad..1fb0451289e 100644 --- a/spec/factories/plan_factory.rb +++ b/spec/factories/plan_factory.rb @@ -6,7 +6,7 @@ name { Faker::TvShows::SiliconValley.app } code { Faker::Name.name.underscore } interval { 'monthly' } - billing_period { 'beginning_of_period' } + frequency { 'beginning_of_period' } pro_rata { false } pay_in_advance { false } amount_cents { 100 } diff --git a/spec/graphql/mutations/plans/create_spec.rb b/spec/graphql/mutations/plans/create_spec.rb index d285a47bbb1..cc51fee028e 100644 --- a/spec/graphql/mutations/plans/create_spec.rb +++ b/spec/graphql/mutations/plans/create_spec.rb @@ -13,7 +13,7 @@ name, code, interval, - billingPeriod, + frequency, proRata, payInAdvance, amountCents, @@ -38,7 +38,7 @@ name: 'New Plan', code: 'new_plan', interval: 'monthly', - billingPeriod: 'beginning_of_period', + frequency: 'beginning_of_period', proRata: false, payInAdvance: false, amountCents: 200, @@ -73,7 +73,7 @@ expect(result_data['name']).to eq('New Plan') expect(result_data['code']).to eq('new_plan') expect(result_data['interval']).to eq('monthly') - expect(result_data['billingPeriod']).to eq('beginning_of_period') + expect(result_data['frequency']).to eq('beginning_of_period') expect(result_data['proRata']).to eq(false) expect(result_data['payInAdvance']).to eq(false) expect(result_data['amountCents']).to eq(200) @@ -92,7 +92,7 @@ name: 'New Plan', code: 'new_plan', interval: 'monthly', - billingPeriod: 'beginning_of_period', + frequency: 'beginning_of_period', proRata: false, payInAdvance: false, amountCents: 200, @@ -116,7 +116,7 @@ name: 'New Plan', code: 'new_plan', interval: 'monthly', - billingPeriod: 'beginning_of_period', + frequency: 'beginning_of_period', proRata: false, payInAdvance: false, amountCents: 200, diff --git a/spec/graphql/mutations/plans/update_spec.rb b/spec/graphql/mutations/plans/update_spec.rb index fb48cd731b2..e2934bac4f6 100644 --- a/spec/graphql/mutations/plans/update_spec.rb +++ b/spec/graphql/mutations/plans/update_spec.rb @@ -14,7 +14,7 @@ name, code, interval, - billingPeriod, + frequency, proRata, payInAdvance, amountCents, @@ -39,7 +39,7 @@ name: 'Updated plan', code: 'new_plan', interval: 'monthly', - billingPeriod: 'beginning_of_period', + frequency: 'beginning_of_period', proRata: false, payInAdvance: false, amountCents: 200, @@ -74,7 +74,7 @@ expect(result_data['name']).to eq('Updated plan') expect(result_data['code']).to eq('new_plan') expect(result_data['interval']).to eq('monthly') - expect(result_data['billingPeriod']).to eq('beginning_of_period') + expect(result_data['frequency']).to eq('beginning_of_period') expect(result_data['proRata']).to eq(false) expect(result_data['payInAdvance']).to eq(false) expect(result_data['amountCents']).to eq(200) @@ -93,7 +93,7 @@ name: 'Updated plan', code: 'new_plan', interval: 'monthly', - billingPeriod: 'beginning_of_period', + frequency: 'beginning_of_period', proRata: false, payInAdvance: false, amountCents: 200, diff --git a/spec/services/billing_service_spec.rb b/spec/services/billing_service_spec.rb index 190fab17e12..80804f17f79 100644 --- a/spec/services/billing_service_spec.rb +++ b/spec/services/billing_service_spec.rb @@ -7,7 +7,7 @@ describe '.call' do context 'when billed monthly on subscription date' do - let(:plan) { create(:plan, interval: :monthly, billing_period: :subscription_date) } + let(:plan) { create(:plan, interval: :monthly, frequency: :subscription_date) } context 'when subscription date is any day below 28' do let(:start_date) { DateTime.parse('04 Jan 2022') } @@ -63,7 +63,7 @@ end context 'when billed yearly on subscription date' do - let(:plan) { create(:plan, interval: :yearly, billing_period: :subscription_date) } + let(:plan) { create(:plan, interval: :yearly, frequency: :subscription_date) } context 'when subscription date is any day' do let(:start_date) { DateTime.parse('04 Jan 2021') } @@ -153,7 +153,7 @@ end context 'when billed monthly on beginning of period' do - let(:plan) { create(:plan, interval: :monthly, billing_period: :beginning_of_period) } + let(:plan) { create(:plan, interval: :monthly, frequency: :beginning_of_period) } let(:start_date) { DateTime.parse('20 Feb 2021') } let(:subscription) { create(:subscription, plan: plan, started_at: start_date) } @@ -181,7 +181,7 @@ end context 'when billed yearly on beginning of period' do - let(:plan) { create(:plan, interval: :yearly, billing_period: :beginning_of_period) } + let(:plan) { create(:plan, interval: :yearly, frequency: :beginning_of_period) } let(:start_date) { DateTime.parse('20 Feb 2021') } let(:subscription) { create(:subscription, plan: plan, started_at: start_date) } diff --git a/spec/services/fees/subscription_service_spec.rb b/spec/services/fees/subscription_service_spec.rb index 98ec2c741cc..1350df7314a 100644 --- a/spec/services/fees/subscription_service_spec.rb +++ b/spec/services/fees/subscription_service_spec.rb @@ -9,7 +9,7 @@ let(:plan) do create( :plan, - billing_period: :beginning_of_period, + frequency: :beginning_of_period, amount_cents: 100, amount_currency: 'EUR', vat_rate: 20, @@ -236,7 +236,7 @@ let(:plan) do create( :plan, - billing_period: :subscription_date, + frequency: :subscription_date, amount_cents: 100, amount_currency: 'EUR', vat_rate: 20, @@ -279,7 +279,7 @@ let(:plan) do create( :plan, - billing_period: :subscription_date, + frequency: :subscription_date, amount_cents: 100, amount_currency: 'EUR', vat_rate: 20, diff --git a/spec/services/invoices_service_spec.rb b/spec/services/invoices_service_spec.rb index f5f7aeb8eb6..04b972be09d 100644 --- a/spec/services/invoices_service_spec.rb +++ b/spec/services/invoices_service_spec.rb @@ -12,7 +12,7 @@ let(:timestamp) { Time.zone.now.beginning_of_month } let(:plan) do - create(:plan, interval: 'monthly', billing_period: 'beginning_of_period') + create(:plan, interval: 'monthly', frequency: 'beginning_of_period') end it 'creates an invoice' do @@ -34,7 +34,7 @@ context 'when billed monthly on subscription anniversary' do let(:timestamp) { subscription.started_at + 2.years } let(:plan) do - create(:plan, interval: 'monthly', billing_period: 'subscription_date') + create(:plan, interval: 'monthly', frequency: 'subscription_date') end it 'creates an invoice' do @@ -60,7 +60,7 @@ let(:subscription) { create(:subscription, plan: plan, started_at: started_at) } let(:plan) do - create(:plan, interval: 'monthly', billing_period: 'beginning_of_period') + create(:plan, interval: 'monthly', frequency: 'beginning_of_period') end it 'creates an invoice' do @@ -83,7 +83,7 @@ let(:timestamp) { Time.zone.now.beginning_of_month } let(:plan) do - create(:plan, interval: 'yearly', billing_period: 'beginning_of_period') + create(:plan, interval: 'yearly', frequency: 'beginning_of_period') end it 'creates an invoice' do @@ -106,7 +106,7 @@ let(:timestamp) { subscription.started_at + 2.years } let(:plan) do - create(:plan, interval: 'yearly', billing_period: 'subscription_date') + create(:plan, interval: 'yearly', frequency: 'subscription_date') end it 'creates an invoice' do @@ -127,7 +127,7 @@ context 'when billed yearly on first year' do let(:plan) do - create(:plan, interval: 'yearly', billing_period: 'beginning_of_period') + create(:plan, interval: 'yearly', frequency: 'beginning_of_period') end let(:timestamp) { Time.zone.now.beginning_of_month } diff --git a/spec/services/plans_service_spec.rb b/spec/services/plans_service_spec.rb index f9adf415e3b..dcb688ef1e5 100644 --- a/spec/services/plans_service_spec.rb +++ b/spec/services/plans_service_spec.rb @@ -18,7 +18,7 @@ organization_id: organization.id, code: 'new_plan', interval: 'monthly', - billing_period: 'beginning_of_period', + frequency: 'beginning_of_period', pro_rata: false, pay_in_advance: false, amount_cents: 200, @@ -90,7 +90,7 @@ name: plan_name, code: 'new_plan', interval: 'monthly', - billing_period: 'beginning_of_period', + frequency: 'beginning_of_period', pro_rata: false, pay_in_advance: false, amount_cents: 200, @@ -169,7 +169,7 @@ name: plan_name, code: 'new_plan', interval: 'monthly', - billing_period: 'beginning_of_period', + frequency: 'beginning_of_period', pro_rata: false, pay_in_advance: false, amount_cents: 200, @@ -223,7 +223,7 @@ name: plan_name, code: 'new_plan', interval: 'monthly', - billing_period: 'beginning_of_period', + frequency: 'beginning_of_period', pro_rata: false, pay_in_advance: false, amount_cents: 200,