-
Notifications
You must be signed in to change notification settings - Fork 109
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Expose billing periods in invoice serializer (#3064)
## Context This PR is related to the rollback of the zero amount removal (See #3059) It appears that some customers are relying on the fees on some invoice webhooks to retrieve the billing period info. ## Description This PR makes sure that the billing period info are always sent in webhooks / exposed in the API when, to ensure that users can rely on it even if no fees have been created
- Loading branch information
1 parent
d7e2a27
commit b784d73
Showing
10 changed files
with
83 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# frozen_string_literal: true | ||
|
||
module V1 | ||
module Invoices | ||
class BillingPeriodSerializer < ModelSerializer | ||
def serialize | ||
{ | ||
lago_subscription_id: model.subscription_id, | ||
external_subscription_id: model.subscription&.external_id, | ||
lago_plan_id: model.subscription&.plan_id, | ||
subscription_from_datetime: model.from_datetime.iso8601, | ||
subscription_to_datetime: model.to_datetime.iso8601, | ||
charges_from_datetime: model.charges_from_datetime.iso8601, | ||
charges_to_datetime: model.charges_to_datetime.iso8601, | ||
invoicing_reason: model.invoicing_reason | ||
} | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
spec/serializers/v1/invoices/billing_period_serializer_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'rails_helper' | ||
|
||
RSpec.describe ::V1::Invoices::BillingPeriodSerializer do | ||
subject(:serializer) { described_class.new(invoice_subscription, root_name: 'billing_period') } | ||
|
||
let(:invoice_subscription) { build(:invoice_subscription, :boundaries) } | ||
|
||
it 'serializes the object' do | ||
result = JSON.parse(serializer.to_json) | ||
|
||
aggregate_failures do | ||
expect(result['billing_period']['lago_subscription_id']).to eq(invoice_subscription.subscription_id) | ||
expect(result['billing_period']['external_subscription_id']).to eq(invoice_subscription.subscription.external_id) | ||
expect(result['billing_period']['lago_plan_id']).to eq(invoice_subscription.subscription.plan_id) | ||
expect(result['billing_period']['subscription_from_datetime']).to eq(invoice_subscription.from_datetime.iso8601) | ||
expect(result['billing_period']['subscription_to_datetime']).to eq(invoice_subscription.to_datetime.iso8601) | ||
expect(result['billing_period']['charges_from_datetime']).to eq(invoice_subscription.charges_from_datetime.iso8601) | ||
expect(result['billing_period']['charges_to_datetime']).to eq(invoice_subscription.charges_to_datetime.iso8601) | ||
expect(result['billing_period']['invoicing_reason']).to eq(invoice_subscription.invoicing_reason) | ||
end | ||
end | ||
end |