HEX
Server: Apache/2.4.52 (Ubuntu)
System: Linux WebLive 5.15.0-79-generic #86-Ubuntu SMP Mon Jul 10 16:07:21 UTC 2023 x86_64
User: ubuntu (1000)
PHP: 7.4.33
Disabled: pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
Upload Files
File: /var/www/html/wpmuhibbah_err/wp-content/plugins/give/src/FormMigration/Steps/DonationOptions.php
<?php

namespace Give\FormMigration\Steps;

use Give\FormMigration\Contracts\FormMigrationStep;
use Give\Framework\Blocks\BlockModel;

class DonationOptions extends FormMigrationStep
{
    public function process()
    {
        /** @var BlockModel $amountField */
        $amountField = $this->fieldBlocks->findByName('givewp/donation-amount');

        $priceOption = $this->getMetaV2('_give_price_option');
        $amountField->setAttribute('priceOption', $priceOption);

        if('set' === $priceOption) {
            $amountField->setAttribute('setPrice', $this->getMetaV2('_give_set_price'));
        }

        if('multi' === $priceOption) {
            // @note $formV2->levels only returns a single level
            $donationLevels = $this->getMetaV2('_give_donation_levels');

            $isDescriptionEnabled = false;
            $amountField->setAttribute('levels',
                array_map(function ($donationLevel) use (&$isDescriptionEnabled) {
                    $isDescriptionEnabled = $isDescriptionEnabled || ! empty($donationLevel['_give_text']);

                    return [
                        'value' => $this->roundAmount($donationLevel['_give_amount']),
                        'label' => $donationLevel['_give_text'],
                        'checked' => isset($donationLevel['_give_default']) && $donationLevel['_give_default'] === 'default',
                    ];
                }, $donationLevels)
            );
            $amountField->setAttribute('descriptionsEnabled', $isDescriptionEnabled);
        }

        $isCustomAmountEnabled = $this->formV2->isCustomAmountOptionEnabled();
        $amountField->setAttribute('customAmount', $isCustomAmountEnabled);

        if ($isCustomAmountEnabled) {
            $customAmountMin = $this->getMetaV2('_give_custom_amount_range_minimum');
            $customAmountMax = $this->getMetaV2('_give_custom_amount_range_maximum');

            if ($customAmountMin) {
                $amountField->setAttribute('customAmountMin', $this->roundAmount($customAmountMin));
            }

            if ($customAmountMax) {
                $amountField->setAttribute('customAmountMax', $this->roundAmount($customAmountMax));
            }
        }

        // @note No corresponding setting in v3 for "Custom Amount Text"
    }

    /**
     * @since 3.0.0
     */
    private function roundAmount($amount): float
    {
        return round((float)$amount, 2);
    }
}