Skip to content

Commit

Permalink
Merge branch 'release/3.0.0' into feature/empty-section-starter
Browse files Browse the repository at this point in the history
  • Loading branch information
kjohnson authored Oct 9, 2023
2 parents 0d80169 + f6f2f4d commit cc02af3
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 4 deletions.
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);
}
}
42 changes: 42 additions & 0 deletions src/DonationForms/Listeners/UpdateDonationLevelId.php
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();
}
}
}
5 changes: 2 additions & 3 deletions src/FormMigration/Steps/FormTitle.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ class FormTitle extends FormMigrationStep
{
public function process()
{
$formTitle = sprintf('%s [form builder]', $this->formV2->title);
$this->formV3->title = $formTitle;
$this->formV3->settings->formTitle = $formTitle;
$this->formV3->title = $this->formV2->title;
$this->formV3->settings->formTitle = $this->formV2->title;
}
}

0 comments on commit cc02af3

Please sign in to comment.