Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow proration mode argument for paddle_billing subscription update #1085

Merged
merged 3 commits into from
Oct 7, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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