| 1 |
<?php |
| 2 |
|
| 3 |
namespace Give\FormMigration\Steps; |
| 4 |
|
| 5 |
use Give\FormMigration\Contracts\FormMigrationStep; |
| 6 |
|
| 7 |
/** |
| 8 |
* @since 3.3.0 |
| 9 |
*/ |
| 10 |
class PerFormGateways extends FormMigrationStep |
| 11 |
{ |
| 12 |
/** |
| 13 |
* @since 3.3.0 |
| 14 |
*/ |
| 15 |
public function process() |
| 16 |
{ |
| 17 |
$paymentGatewaysBlock = $this->fieldBlocks->findByName('givewp/payment-gateways'); |
| 18 |
|
| 19 |
$perFormGateways = give()->form_meta->get_meta($this->formV2->id, '_give_per_form_gateways', true); |
| 20 |
$compatibleGateways = array_keys(give_get_enabled_payment_gateways(0, 3)); |
| 21 |
$gateways = []; |
| 22 |
if (is_array($perFormGateways) && count($perFormGateways) > 0) { |
| 23 |
foreach ($perFormGateways as $key => $checked) { |
| 24 |
if (in_array($key, $compatibleGateways)) { |
| 25 |
$gateways[] = [ |
| 26 |
'id' => $key, |
| 27 |
'label' => give_get_gateway_checkout_label($key), |
| 28 |
'value' => $key, |
| 29 |
'checked' => (bool)$checked, |
| 30 |
]; |
| 31 |
} |
| 32 |
} |
| 33 |
} |
| 34 |
|
| 35 |
$paymentGatewaysBlock->setAttribute('useDefaultGateways', count($gateways) === 0); |
| 36 |
$paymentGatewaysBlock->setAttribute('perFormGateways', $gateways); |
| 37 |
} |
| 38 |
} |
| 39 |
|