From 5239f4b32742b69207eee680e5961be47b1d17d2 Mon Sep 17 00:00:00 2001 From: Jatin Goyal Date: Sun, 6 Oct 2024 16:09:35 +0530 Subject: [PATCH 1/3] 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 From 113aab93b4c5a6bf58d37668dd2a54b1ddecd6ef Mon Sep 17 00:00:00 2001 From: Chris Oliver Date: Mon, 7 Oct 2024 09:46:49 -0500 Subject: [PATCH 2/3] Refactor --- app/models/pay/paddle_billing/subscription.rb | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/app/models/pay/paddle_billing/subscription.rb b/app/models/pay/paddle_billing/subscription.rb index 6ac37aba..65f26d01 100644 --- a/app/models/pay/paddle_billing/subscription.rb +++ b/app/models/pay/paddle_billing/subscription.rb @@ -102,9 +102,11 @@ def change_quantity(quantity, **options) quantity: quantity }] - proration_billing_mode = options.delete(:proration_billing_mode) || "prorated_immediately" - - ::Paddle::Subscription.update(id: processor_id, items: items, proration_billing_mode: proration_billing_mode) + ::Paddle::Subscription.update( + id: processor_id, + items: items, + proration_billing_mode: options.delete(:proration_billing_mode) || "prorated_immediately" + ) update(quantity: quantity) rescue ::Paddle::Error => e raise Pay::PaddleBilling::Error, e @@ -157,9 +159,11 @@ def swap(plan, **options) quantity: quantity || 1 }] - proration_billing_mode = options.delete(:proration_billing_mode) || "prorated_immediately" - - ::Paddle::Subscription.update(id: processor_id, items: items, proration_billing_mode: proration_billing_mode) + ::Paddle::Subscription.update( + id: processor_id, + items: items, + proration_billing_mode: options.delete(:proration_billing_mode) || "prorated_immediately" + ) update(processor_plan: plan, ends_at: nil, status: :active) end From 8bfc9cf3b59344f05a6b81f8e4428473eae75c09 Mon Sep 17 00:00:00 2001 From: Chris Oliver Date: Mon, 7 Oct 2024 09:50:03 -0500 Subject: [PATCH 3/3] Fix whitespac --- app/models/pay/paddle_billing/subscription.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/models/pay/paddle_billing/subscription.rb b/app/models/pay/paddle_billing/subscription.rb index 65f26d01..58327069 100644 --- a/app/models/pay/paddle_billing/subscription.rb +++ b/app/models/pay/paddle_billing/subscription.rb @@ -160,8 +160,8 @@ def swap(plan, **options) }] ::Paddle::Subscription.update( - id: processor_id, - items: items, + id: processor_id, + items: items, proration_billing_mode: options.delete(:proration_billing_mode) || "prorated_immediately" ) update(processor_plan: plan, ends_at: nil, status: :active)