FormFields
2 years ago
FormTemplate
2 years ago
DonationGoal.php
2 years ago
DonationOptions.php
2 years ago
EmailSettings.php
2 years ago
FeeRecovery.php
2 years ago
FormFeaturedImage.php
2 years ago
FormFieldManager.php
2 years ago
FormFields.php
2 years ago
FormGrid.php
2 years ago
FormMeta.php
2 years ago
FormTitle.php
2 years ago
FundsAndDesignations.php
2 years ago
GiftAid.php
2 years ago
Mailchimp.php
2 years ago
MigrateMeta.php
2 years ago
OfflineDonations.php
2 years ago
PaymentGateways.php
2 years ago
PdfSettings.php
2 years ago
PerFormGateways.php
2 years ago
RecurringDonationOptions.php
2 years ago
TermsAndConditions.php
2 years ago
FeeRecovery.php
67 lines
| 1 | <?php |
| 2 | |
| 3 | namespace Give\FormMigration\Steps; |
| 4 | |
| 5 | use Give\FormMigration\Contracts\FormMigrationStep; |
| 6 | use Give\Framework\Blocks\BlockModel; |
| 7 | |
| 8 | class FeeRecovery extends FormMigrationStep |
| 9 | { |
| 10 | |
| 11 | /** |
| 12 | * @since 3.0.0 |
| 13 | */ |
| 14 | public function process() |
| 15 | { |
| 16 | $feeRecoverySettings = $this->formV2->getFeeRecoverySettings(); |
| 17 | |
| 18 | if (empty($feeRecoverySettings) || ( |
| 19 | $feeRecoverySettings['useGlobalSettings'] === true && |
| 20 | !give_is_setting_enabled(give_get_option('give_fee_recovery', 'disabled')) |
| 21 | )) { |
| 22 | return; |
| 23 | } |
| 24 | |
| 25 | if ($feeRecoverySettings['useGlobalSettings']) { |
| 26 | $feeRecoverySettings = $this->getGlobalSettings(); |
| 27 | } |
| 28 | |
| 29 | $feeRecoveryBlock = BlockModel::make([ |
| 30 | 'name' => 'givewp-fee-recovery/fee-recovery', |
| 31 | 'attributes' => $feeRecoverySettings, |
| 32 | ]); |
| 33 | $this->fieldBlocks->insertAfter('givewp/donation-amount', $feeRecoveryBlock); |
| 34 | } |
| 35 | |
| 36 | /** |
| 37 | * @since 3.0.0 |
| 38 | */ |
| 39 | private function getGlobalSettings(): array |
| 40 | { |
| 41 | return [ |
| 42 | 'useGlobalSettings' => true, |
| 43 | 'feeSupportForAllGateways' => give_get_option('give_fee_configuration', 'all_gateways') === 'all_gateways', |
| 44 | 'perGatewaySettings' => [], |
| 45 | 'feePercentage' => (float)give_get_option('give_fee_percentage', 2.9), |
| 46 | 'feeBaseAmount' => (float)give_get_option('give_fee_base_amount', 0.30), |
| 47 | 'maxFeeAmount' => (float)give_get_option( |
| 48 | 'give_fee_maximum_fee_amount', |
| 49 | give_format_decimal(['amount' => '0.00']) |
| 50 | ), |
| 51 | 'includeInDonationSummary' => give_get_option('give_fee_breakdown', 'enabled') === 'enabled', |
| 52 | 'donorOptIn' => give_get_option('give_fee_mode', 'donor_opt_in') === 'donor_opt_in', |
| 53 | 'feeCheckboxLabel' => give_get_option( |
| 54 | 'give_fee_checkbox_label', |
| 55 | __( |
| 56 | 'I\'d like to help cover the transaction fees of {fee_amount} for my donation.', |
| 57 | 'give-fee-recovery' |
| 58 | ) |
| 59 | ), |
| 60 | 'feeMessage' => give_get_option( |
| 61 | 'give_fee_explanation', |
| 62 | __('Plus an additional {fee_amount} to cover gateway fees.', 'give-fee-recovery') |
| 63 | ), |
| 64 | ]; |
| 65 | } |
| 66 | } |
| 67 |