laravel-cashier-mollie icon indicating copy to clipboard operation
laravel-cashier-mollie copied to clipboard

Applied coupons not subtracted from the reimbursable amount

Open sander3 opened this issue 1 year ago • 5 comments

Hi there,

I noticed the applied coupons were not subtracted from the reimbursable amount when swapping a subscription. The issue occurs when calling ->toArray() on the order item collection. total is a accessor on the OrderItem model and since the appends array on the model is empty the value won't be included when casting to an array.

Alternatively, you could either add a $appends array containing the total key or call $this->append('total'); in the OrderItemCollection@getTotal method (available since L9 according to the docs).

sander3 avatar Oct 02 '23 16:10 sander3

Hi @sander3,

could you add a test for this issue please?

Naoray avatar Oct 03 '23 12:10 Naoray

I hope to find some time later this week.

sander3 avatar Oct 04 '23 09:10 sander3

Btw, the handlePaymentFailed method on the AppliedCoupon model causes the coupon to not be subtracted from the reimbursableAmount as well. Having a failed payment before swapping plans is cheaper for the customer haha.

sander3 avatar Oct 05 '23 16:10 sander3

Btw, the handlePaymentFailed method on the AppliedCoupon model causes the coupon to not be subtracted from the reimbursableAmount as well. Having a failed payment before swapping plans is cheaper for the customer haha.

Hi @sander3,

can you explain this to me please?

Naoray avatar Nov 02 '23 09:11 Naoray

Btw, the handlePaymentFailed method on the AppliedCoupon model causes the coupon to not be subtracted from the reimbursableAmount as well. Having a failed payment before swapping plans is cheaper for the customer haha.

Hi @sander3,

can you explain this to me please?

If a subscription payment fails, the AppliedCoupon self-deletes in ->handlePaymentFailed() causing it to be unavailable in the subscription reimbursableAmount() on line 788:

$appliedCoupons = $this->appliedCoupons()->with('orderItems')->get();

Therefor, the applied coupon (which remains "applied" to the already existing order, aka the customer has received a discount) is not available in order to be reduced from the reimbursableAmount().

sander3 avatar Nov 02 '23 12:11 sander3