Skip to content

Commit

Permalink
Feature: add Per Form Gateways add-on to the form migration process (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
glaubersilva authored Jan 10, 2024
1 parent 0f9447d commit 39e5bfd
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/DonationForms/V2/DonationFormsAdminPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ public function getSupportedAddons(): array
// 'Double the Donation' => defined('GIVE_DTD_NAME'),
// 'Simple Social Shout' => class_exists('SIMPLE_SOCIAL_SHARE_4_GIVEWP'),
// 'Receipt Attachments' => defined('GIVERA_VERSION'),
// 'Per Form Gateways' => class_exists('Give_Per_Form_Gateways'),
'Per Form Gateways' => class_exists('Give_Per_Form_Gateways'),
// 'Per Form Confirmations' => class_exists('Per_Form_Confirmations_4_GIVEWP'),
// 'Form Countdown' => class_exists('Give_Form_Countdown'),
// 'ActiveCampaign' => class_exists('Give_ActiveCampaign'),
Expand Down
1 change: 1 addition & 0 deletions src/FormMigration/ServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public function register()
Steps\FormMeta::class,
Steps\PdfSettings::class,
Steps\FeeRecovery::class,
Steps\PerFormGateways::class,
Steps\Mailchimp::class,
Steps\FundsAndDesignations::class,
]);
Expand Down
37 changes: 37 additions & 0 deletions src/FormMigration/Steps/PerFormGateways.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

namespace Give\FormMigration\Steps;

use Give\FormMigration\Contracts\FormMigrationStep;

/**
* @unreleased
*/
class PerFormGateways extends FormMigrationStep
{
/**
* @unreleased
*/
public function process()
{
$paymentGatewaysBlock = $this->fieldBlocks->findByName('givewp/payment-gateways');

$perFormGateways = give()->form_meta->get_meta($this->formV2->id, '_give_per_form_gateways', true);
$compatibleGateways = array_keys(give_get_enabled_payment_gateways(0, 3));
$gateways = [];
if (is_array($perFormGateways) && count($perFormGateways) > 0) {
foreach ($perFormGateways as $key => $checked) {
if (in_array($key, $compatibleGateways)) {
$gateways[] = [
'key' => $key,
'label' => give_get_gateway_checkout_label($key),
'checked' => (bool)$checked,
];
}
}
}

$paymentGatewaysBlock->setAttribute('useDefaultGateways', count($gateways) === 0);
$paymentGatewaysBlock->setAttribute('perFormGateways', $gateways);
}
}

0 comments on commit 39e5bfd

Please sign in to comment.