Skip to content

Commit

Permalink
Allow proration mode argument for paddle_billing subscription plan or…
Browse files Browse the repository at this point in the history
… quantity change
  • Loading branch information
jjatinggoyal committed Oct 6, 2024
1 parent 19afa98 commit 5239f4b
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions app/models/pay/paddle_billing/subscription.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down

0 comments on commit 5239f4b

Please sign in to comment.