laravel / cashier-paddle

Cashier Paddle provides an expressive, fluent interface to Paddle's subscription billing services.
https://laravel.com/docs/cashier-paddle
MIT License
238 stars 57 forks source link

Add ability to update Subscription Items with different proration modes for addition and removal. #246

Closed HelgeSverre closed 6 months ago

HelgeSverre commented 6 months ago

Summary

This PR introduces a new method updateItemsWithDifferentProration to the Subscription model.

It allows the consumer of the package to specify the proration mode to be used for adding new items or incrementing the quantity of existing items already on the subscription, with a separate proration mode than removing items or decrementing the quantity of existing items.

Why

In non-trivial subscription scenarios, it is sometimes desirable to apply different proration behaviors for addition and removal of a item on a subscription,

A Specific example of this is the following scenario:

In this scenario, the following is expected:

Usage

$subscription->updateItemsWithDifferentProration(
    items: [
        ['price_id' => '123', 'quantity' => 2],
        ['price_id' => '456', 'quantity' => 1],
    ],
    additionProrationBehaviour: 'prorated_immediately',
    removalProrationBehaviour: 'full_next_billing_period'
);

Etc

The logic could probably be simplified a bit, but i have provided tests for various scenarios so we can refactor it if needed.

Fully understand if this use-case is too niche to put in "core", but it's fairly common practice for B2B SaaS, and is a PITA to implement with Paddle.

(Package does not have pint, so my editor messed with the formatting, assuming this will be auto-fixed by GitHub actions)

github-actions[bot] commented 6 months ago

Thanks for submitting a PR!

Note that draft PR's are not reviewed. If you would like a review, please mark your pull request as ready for review in the GitHub user interface.

Pull requests that are abandoned in draft may be closed due to inactivity.

taylorotwell commented 6 months ago

Too many other formatting changes here.

HelgeSverre commented 6 months ago

Shall reformat and resubmit later, is this repo using the default pint with Laravel preset?