Skip to content

Commit 0bb36fa

Browse files
committed
feat(purchase_order_number): Subscriptions upgrade/downgrade
1 parent 9fb894b commit 0bb36fa

4 files changed

Lines changed: 58 additions & 0 deletions

File tree

app/services/subscriptions/plan_downgrade_service.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ def call
4242
ending_at: params.key?(:ending_at) ? params[:ending_at] : current_subscription.ending_at,
4343
progressive_billing_disabled: params[:progressive_billing_disabled] || false,
4444
consolidate_invoice: params.key?(:consolidate_invoice) ? params[:consolidate_invoice] : current_subscription.consolidate_invoice,
45+
purchase_order_number: params.key?(:purchase_order_number) ? params[:purchase_order_number] : current_subscription.purchase_order_number,
4546
billing_entity_id: current_subscription.billing_entity_id
4647
)
4748

app/services/subscriptions/plan_upgrade_service.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ def new_subscription_with_overrides
6262
billing_time: current_subscription.billing_time,
6363
ending_at: params.key?(:ending_at) ? params[:ending_at] : current_subscription.ending_at,
6464
consolidate_invoice: params.key?(:consolidate_invoice) ? params[:consolidate_invoice] : current_subscription.consolidate_invoice,
65+
purchase_order_number: params.key?(:purchase_order_number) ? params[:purchase_order_number] : current_subscription.purchase_order_number,
6566
billing_entity_id: resolved_entity&.id || current_subscription.billing_entity_id
6667
)
6768

spec/services/subscriptions/plan_downgrade_service_spec.rb

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,33 @@
132132
end
133133
end
134134

135+
context "when subscription has a purchase_order_number" do
136+
let(:subscription) do
137+
create(
138+
:subscription,
139+
customer:,
140+
plan: old_plan,
141+
subscription_at: Time.current,
142+
external_id: SecureRandom.uuid,
143+
purchase_order_number: "PO-OLD"
144+
)
145+
end
146+
147+
it "inherits the purchase_order_number on the new subscription" do
148+
expect(result).to be_success
149+
expect(result.subscription.next_subscription.purchase_order_number).to eq("PO-OLD")
150+
end
151+
152+
context "when params override purchase_order_number" do
153+
let(:params) { {name: subscription_name, purchase_order_number: "PO-NEW"} }
154+
155+
it "applies the override on the new subscription" do
156+
expect(result).to be_success
157+
expect(result.subscription.next_subscription.purchase_order_number).to eq("PO-NEW")
158+
end
159+
end
160+
end
161+
135162
context "with plan overrides", :premium do
136163
let(:params) do
137164
{

spec/services/subscriptions/plan_upgrade_service_spec.rb

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,35 @@
103103
end
104104
end
105105

106+
context "when subscription has a purchase_order_number" do
107+
let(:subscription) do
108+
create(
109+
:subscription,
110+
customer:,
111+
plan: old_plan,
112+
status: :active,
113+
subscription_at: Time.current,
114+
started_at: Time.current,
115+
external_id: SecureRandom.uuid,
116+
purchase_order_number: "PO-OLD"
117+
)
118+
end
119+
120+
it "inherits the purchase_order_number on the new subscription" do
121+
expect(result).to be_success
122+
expect(result.subscription.purchase_order_number).to eq("PO-OLD")
123+
end
124+
125+
context "when params override purchase_order_number" do
126+
let(:params) { {name: subscription_name, purchase_order_number: "PO-NEW"} }
127+
128+
it "applies the override on the new subscription" do
129+
expect(result).to be_success
130+
expect(result.subscription.purchase_order_number).to eq("PO-NEW")
131+
end
132+
end
133+
end
134+
106135
context "with payment method" do
107136
let(:payment_method) { create(:payment_method, organization: subscription.organization, customer: subscription.customer) }
108137
let(:params) do

0 commit comments

Comments
 (0)