Closed hjeldin closed 1 year ago
Hi @hjeldin ,
That's definitely an interesting use case.
Why doesn't $billable->redeemCoupon(...)
fit your use case here, right after $subscription->swap(...)
?
Thanks, i just checked again in our testing environment. Calling $billable->redeemCoupon() after a swap doesn't insert the coupon in the order's items. Actually, it doesn't show up anywhere besides "redeemed_coupons" with a "times_left" = 1. My understanding is that it will be applied after the next renewal (in our case, a year from now). We'd like the discount to be applied immediately and the generated invoice should include it.
Hi @sandervanhooft, should i create a pull request with the additional call_user_func or should the combo redeemCoupon/swap be fixed? Did you manage to take a look?
Thanks!
Hi @hjeldin,
sorry for not getting back to you earlier.
In essence, you are absolutely correct in your observation that coupons are applied during the next renewal of the subscription cycle. However, this also holds true when a subscription swap occurs. To ensure proper functionality with subscription swaps, please follow these steps:
cashier_plans.defaults.order_item_preprocessors
configuration includes the ProcessCoupons
class (alias of CouponOrderItemPreprocessor
).Here's a brief overview of how the renewal process is calculated:
cashier_plans
configuration.Order
Model is created with this combined amount.Order
ModelFor coupons to function as intended, the ProcessCoupons
(alias of CouponOrderItemPreprocessor
) is essential. This preprocessor has the capability to modify, add, or remove order items from the collection used to create the order in step (2). In the case of a coupon, it adds another OrderItem
with a negative net amount equal to the coupon's value.
I wrote a test for your specific use case to make 100% sure that it’s working.
Kindly let me know if this explanation resolves your issue. If you have any further questions or concerns, please don't hesitate to ask.
Thanks @Naoray, apparently we specified the correct preprocessors in cashier.php, but we were overwriting them with an empty collection in our database-backed plans.
Hello, we would like to offer our users the ability to swap (immediately) to a more expensive plan and at the same time redeem a coupon. At the moment it doesn't seem possible:
We managed to work around these issues by passing a closure to both restartCycleWithoutModifications (whose name should be changed after this modification) and the swap method on Subscription. The closure uses a reference to the list of orderItems that are going to be processed.
The reasoning behind this change is allowing the developer to edit the orderItems before they get packed up in an order and the user is billed.
If we were to push a PR with this functionality would it be accepted? Does anyone have a better idea?