diff --git a/site/plugins/buy/src/Passthrough.php b/site/plugins/buy/src/Passthrough.php index 2884098db..dba9d8b64 100644 --- a/site/plugins/buy/src/Passthrough.php +++ b/site/plugins/buy/src/Passthrough.php @@ -8,6 +8,7 @@ class Passthrough { public function __construct( public string|null $license = null, + public string $discounts = '', public bool $gratitude = false, public int $multiplier = 1, public string|null $partner = null, @@ -54,6 +55,7 @@ public function toJson(): string { return json_encode([ 'license' => $this->license, + 'discounts' => $this->discounts, 'gratitude' => $this->gratitude, 'multiplier' => $this->multiplier, 'partner' => $this->partner, diff --git a/site/plugins/buy/src/Price.php b/site/plugins/buy/src/Price.php index 67721e348..e813f5e9b 100644 --- a/site/plugins/buy/src/Price.php +++ b/site/plugins/buy/src/Price.php @@ -73,6 +73,26 @@ public function customerDonation(): int return $this->convert(option('buy.donation.customerAmount')); } + /** + * Returns a summary of all applied discounts + */ + public function discounts(): string + { + $discounts = []; + + if ($this->rateAdjusted !== $this->rate) { + $pppPercentage = number_format(100 * (1 - $this->rateAdjusted / $this->rate), 2, '.'); + $discounts[] = 'PPP (' . $pppPercentage . '%)'; + } + + $sale = new Sale(); + if ($sale->isActive()) { + $discounts[] = 'Sale (' . $sale->discount() . '%)'; + } + + return implode(', ', $discounts); + } + /** * Gets the team donation amount * per license in the customer currency diff --git a/site/routes/buy.php b/site/routes/buy.php index 7fcdbed06..306c29fb8 100644 --- a/site/routes/buy.php +++ b/site/routes/buy.php @@ -68,6 +68,7 @@ $price = $product->price(); $message = $product->revenueLimit(); $passthrough = new Passthrough( + discounts: $price->discounts(), donationOrg: option('buy.donation.charity'), teamDonation: option('buy.donation.teamAmount') * $quantity ); @@ -122,6 +123,7 @@ $product = Product::from($productId); $price = $product->price(); $passthrough = new Passthrough( + discounts: $price->discounts(), donationOrg: option('buy.donation.charity'), teamDonation: option('buy.donation.teamAmount') ); @@ -152,6 +154,7 @@ $product = Product::from($productId); $price = $product->price(); $passthrough = new Passthrough( + discounts: $price->discounts(), donationOrg: option('buy.donation.charity'), teamDonation: option('buy.donation.teamAmount') * $quantity ); @@ -179,6 +182,7 @@ $product = Product::from($productId); $price = $product->price(); $passthrough = new Passthrough( + discounts: $price->discounts(), donationOrg: option('buy.donation.charity'), teamDonation: option('buy.donation.teamAmount') * $quantity );