Skip to content

Commit

Permalink
Allow proration mode argument for paddle_billing subscription update (#…
Browse files Browse the repository at this point in the history
…1085)

---------

Co-authored-by: Chris Oliver <excid3@gmail.com>
  • Loading branch information
jjatinggoyal and excid3 authored Oct 7, 2024
1 parent 19afa98 commit e0f5a81
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 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,11 @@ def change_quantity(quantity, **options)
quantity: quantity
}]

::Paddle::Subscription.update(id: processor_id, items: items, proration_billing_mode: "prorated_immediately")
::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
Expand Down Expand Up @@ -148,12 +152,18 @@ 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")
::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

Expand Down

0 comments on commit e0f5a81

Please sign in to comment.