From 5239f4b32742b69207eee680e5961be47b1d17d2 Mon Sep 17 00:00:00 2001 From: Jatin Goyal Date: Sun, 6 Oct 2024 16:09:35 +0530 Subject: [PATCH] Allow proration mode argument for paddle_billing subscription plan or quantity change --- app/models/pay/paddle_billing/subscription.rb | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/app/models/pay/paddle_billing/subscription.rb b/app/models/pay/paddle_billing/subscription.rb index 4d79f524..6ac37aba 100644 --- a/app/models/pay/paddle_billing/subscription.rb +++ b/app/models/pay/paddle_billing/subscription.rb @@ -102,7 +102,9 @@ def change_quantity(quantity, **options) quantity: quantity }] - ::Paddle::Subscription.update(id: processor_id, items: items, proration_billing_mode: "prorated_immediately") + proration_billing_mode = options.delete(:proration_billing_mode) || "prorated_immediately" + + ::Paddle::Subscription.update(id: processor_id, items: items, proration_billing_mode: proration_billing_mode) update(quantity: quantity) rescue ::Paddle::Error => e raise Pay::PaddleBilling::Error, e @@ -148,12 +150,16 @@ def resume end def swap(plan, **options) + raise ArgumentError, "plan must be a string" unless plan.is_a?(String) + items = [{ price_id: plan, quantity: quantity || 1 }] - ::Paddle::Subscription.update(id: processor_id, items: items, proration_billing_mode: "prorated_immediately") + proration_billing_mode = options.delete(:proration_billing_mode) || "prorated_immediately" + + ::Paddle::Subscription.update(id: processor_id, items: items, proration_billing_mode: proration_billing_mode) update(processor_plan: plan, ends_at: nil, status: :active) end