-
Notifications
You must be signed in to change notification settings - Fork 193
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature: update backwards compatibility for donation level id (#7002)
Co-authored-by: Jon Waldstein <[email protected]>
- Loading branch information
1 parent
b78d910
commit f6f2f4d
Showing
2 changed files
with
47 additions
and
1 deletion.
There are no files selected for viewing
6 changes: 5 additions & 1 deletion
6
src/DonationForms/Actions/DispatchDonateControllerDonationCreatedListeners.php
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 |
---|---|---|
@@ -1,24 +1,28 @@ | ||
<?php | ||
|
||
namespace Give\DonationForms\Actions; | ||
|
||
use Give\DonationForms\DataTransferObjects\DonateControllerData; | ||
use Give\DonationForms\Listeners\AddRedirectUrlsToGatewayData; | ||
use Give\DonationForms\Listeners\StoreCustomFields; | ||
use Give\DonationForms\Listeners\TemporarilyReplaceLegacySuccessPageUri; | ||
use Give\DonationForms\Listeners\UpdateDonationLevelId; | ||
use Give\Donations\Models\Donation; | ||
use Give\Framework\Exceptions\Primitives\Exception; | ||
use Give\Framework\FieldsAPI\Exceptions\NameCollisionException; | ||
use Give\Subscriptions\Models\Subscription; | ||
|
||
class DispatchDonateControllerDonationCreatedListeners | ||
{ | ||
/** | ||
* @since 3.0.0 | ||
* @throws NameCollisionException | ||
* @throws NameCollisionException|Exception | ||
*/ | ||
public function __invoke(DonateControllerData $formData, Donation $donation, ?Subscription $subscription) | ||
{ | ||
(new StoreCustomFields())($formData->getDonationForm(), $donation, $subscription, $formData->getCustomFields()); | ||
(new TemporarilyReplaceLegacySuccessPageUri())($formData, $donation); | ||
(new AddRedirectUrlsToGatewayData())($formData, $donation); | ||
(new UpdateDonationLevelId())($formData->getDonationForm(), $donation); | ||
} | ||
} |
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,42 @@ | ||
<?php | ||
|
||
namespace Give\DonationForms\Listeners; | ||
|
||
use Give\DonationForms\Models\DonationForm; | ||
use Give\Donations\Models\Donation; | ||
use Give\Framework\Exceptions\Primitives\Exception; | ||
use Give\Framework\FieldsAPI\Amount; | ||
use Give\Framework\FieldsAPI\Exceptions\NameCollisionException; | ||
|
||
class UpdateDonationLevelId | ||
{ | ||
/** | ||
* if the intended donation amount matches a donation level from the amount block settings, | ||
* this will update the donation level ID meta with the level array key, | ||
* which is used in the donation details screen. | ||
* | ||
* @unreleased | ||
* | ||
* @throws NameCollisionException|Exception | ||
*/ | ||
public function __invoke(DonationForm $donationForm, Donation $donation) | ||
{ | ||
/** @var Amount $amountField */ | ||
$amountField = $donationForm->schema()->getNodeByName('amount'); | ||
|
||
if (!$amountField) { | ||
return; | ||
} | ||
|
||
$donationLevel = array_search( | ||
(float)$donation->intendedAmount()->formatToDecimal(), | ||
$amountField->getLevels(), | ||
true | ||
); | ||
|
||
if ($donationLevel !== false) { | ||
$donation->levelId = (string)$donationLevel; | ||
$donation->save(); | ||
} | ||
} | ||
} |