-
Notifications
You must be signed in to change notification settings - Fork 682
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] Multiple discounts on receipts #1147
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,144 @@ | ||
<?php | ||
|
||
namespace Laravel\Cashier; | ||
|
||
use Illuminate\Contracts\Support\Arrayable; | ||
use Illuminate\Contracts\Support\Jsonable; | ||
use JsonSerializable; | ||
use Stripe\Coupon as StripeCoupon; | ||
|
||
class Coupon implements Arrayable, Jsonable, JsonSerializable | ||
{ | ||
/** | ||
* The Stripe Coupon instance. | ||
* | ||
* @var \Stripe\Coupon | ||
*/ | ||
protected $coupon; | ||
|
||
/** | ||
* Create a new Coupon instance. | ||
* | ||
* @param \Stripe\Coupon $coupon | ||
* @return void | ||
*/ | ||
public function __construct(StripeCoupon $coupon) | ||
{ | ||
$this->coupon = $coupon; | ||
} | ||
|
||
/** | ||
* Get the readable name for the Coupon. | ||
* | ||
* @return string | ||
*/ | ||
public function name() | ||
{ | ||
return $this->coupon->name ?: $this->coupon->id; | ||
} | ||
|
||
/** | ||
* Determine if the coupon is a percentage. | ||
* | ||
* @return bool | ||
*/ | ||
public function isPercentage() | ||
{ | ||
return ! is_null($this->coupon->percent_off); | ||
} | ||
|
||
/** | ||
* Get the discount percentage for the invoice. | ||
* | ||
* @return float|null | ||
*/ | ||
public function percentOff() | ||
{ | ||
return $this->coupon->percent_off; | ||
} | ||
|
||
/** | ||
* Get the amount off for the coupon. | ||
* | ||
* @return string|null | ||
*/ | ||
public function amountOff() | ||
{ | ||
if (! is_null($this->coupon->amount_off)) { | ||
return $this->formatAmount($this->rawAmountOff()); | ||
} | ||
} | ||
|
||
/** | ||
* Get the raw amount off for the coupon. | ||
* | ||
* @return int|null | ||
*/ | ||
public function rawAmountOff() | ||
{ | ||
return $this->coupon->amount_off; | ||
} | ||
|
||
/** | ||
* Format the given amount into a displayable currency. | ||
* | ||
* @param int $amount | ||
* @return string | ||
*/ | ||
protected function formatAmount($amount) | ||
{ | ||
return Cashier::formatAmount($amount, $this->coupon->currency); | ||
} | ||
|
||
/** | ||
* Get the Stripe Coupon instance. | ||
* | ||
* @return \Stripe\Coupon | ||
*/ | ||
public function asStripeCoupon() | ||
{ | ||
return $this->coupon; | ||
} | ||
|
||
/** | ||
* Get the instance as an array. | ||
* | ||
* @return array | ||
*/ | ||
public function toArray() | ||
{ | ||
return $this->asStripeCoupon()->toArray(); | ||
} | ||
|
||
/** | ||
* Convert the object to its JSON representation. | ||
* | ||
* @param int $options | ||
* @return string | ||
*/ | ||
public function toJson($options = 0) | ||
{ | ||
return json_encode($this->jsonSerialize(), $options); | ||
} | ||
|
||
/** | ||
* Convert the object into something JSON serializable. | ||
* | ||
* @return array | ||
*/ | ||
public function jsonSerialize() | ||
{ | ||
return $this->toArray(); | ||
} | ||
|
||
/** | ||
* Dynamically get values from the Stripe object. | ||
* | ||
* @param string $key | ||
* @return mixed | ||
*/ | ||
public function __get($key) | ||
{ | ||
return $this->coupon->{$key}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
<?php | ||
|
||
namespace Laravel\Cashier; | ||
|
||
use Illuminate\Contracts\Support\Arrayable; | ||
use Illuminate\Contracts\Support\Jsonable; | ||
use JsonSerializable; | ||
use Stripe\Discount as StripeDiscount; | ||
|
||
class Discount implements Arrayable, Jsonable, JsonSerializable | ||
{ | ||
/** | ||
* The Stripe Discount instance. | ||
* | ||
* @var \Stripe\Discount | ||
*/ | ||
protected $discount; | ||
|
||
/** | ||
* Create a new Discount instance. | ||
* | ||
* @param \Stripe\Discount $discount | ||
* @return void | ||
*/ | ||
public function __construct(StripeDiscount $discount) | ||
{ | ||
$this->discount = $discount; | ||
} | ||
|
||
/** | ||
* Get the coupon applied to the discount. | ||
* | ||
* @return \Laravel\Cashier\Coupon | ||
*/ | ||
public function coupon() | ||
{ | ||
return new Coupon($this->discount->coupon); | ||
} | ||
|
||
/** | ||
* Get the Stripe Discount instance. | ||
* | ||
* @return \Stripe\Discount | ||
*/ | ||
public function asStripeDiscount() | ||
{ | ||
return $this->discount; | ||
} | ||
|
||
/** | ||
* Get the instance as an array. | ||
* | ||
* @return array | ||
*/ | ||
public function toArray() | ||
{ | ||
return $this->asStripeDiscount()->toArray(); | ||
} | ||
|
||
/** | ||
* Convert the object to its JSON representation. | ||
* | ||
* @param int $options | ||
* @return string | ||
*/ | ||
public function toJson($options = 0) | ||
{ | ||
return json_encode($this->jsonSerialize(), $options); | ||
} | ||
|
||
/** | ||
* Convert the object into something JSON serializable. | ||
* | ||
* @return array | ||
*/ | ||
public function jsonSerialize() | ||
{ | ||
return $this->toArray(); | ||
} | ||
|
||
/** | ||
* Dynamically get values from the Stripe object. | ||
* | ||
* @param string $key | ||
* @return mixed | ||
*/ | ||
public function __get($key) | ||
{ | ||
return $this->discount->{$key}; | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I decreased the line-height here slightly to account for the extra items on the invoice.