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

[13.x] Discount improvements #1354

Merged
merged 4 commits into from
May 2, 2022
Merged

[13.x] Discount improvements #1354

merged 4 commits into from
May 2, 2022

Conversation

driesvints
Copy link
Member

@driesvints driesvints commented Apr 28, 2022

This PR implements some improvements and new API's for discount handling.

First of all, a new PromotionCode class was added that wraps a Stripe\PromotionCode object. This object represents a promotion code applied to either a customer or subscription.

Further, the Discount class now also features a promotionCode method to easily retrieve the promotion code should one have been used to apply a discount. Besides that, the class got dedicated methods to transform the start and end timestamps of a discount into Carbon\Carbon objects.

Other than that it's now easy to retrieve a PromotionCode by its code:

// Find the promotion code with 25OFF...
$promotionCode = $billable->findPromotionCode('25OFF');

// Or find only active promotion codes...
$promotionCode = $billable->findActivePromotionCode('25OFF');

It's now also easy to retrieve the applied discount on a customer or subscription:

$discount = $billable->discount();

$discount = $subscription->discount();

And it's easy now to apply a new coupon or promotion code on either a customer or subscription. These need the ID of their respective object:

$billable->applyCoupon('coupon_id');
$billable->applyPromotionCode('promotion_code_id');

$subscription->applyCoupon('coupon_id');
$subscription->applyPromotionCode('promotion_code_id');

I was thinking to add also some validation rules like coupon, promotion_code or coupon_or_promotion_code but decided to not extend the scope of this PR any further.

Closes #852

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Better coupon support & promotion codes
2 participants