| 1 |
<?php |
| 2 |
|
| 3 |
namespace Give\PaymentGateways\Gateways\Offline\Actions; |
| 4 |
|
| 5 |
use Give\DonationForms\Models\DonationForm; |
| 6 |
|
| 7 |
/** |
| 8 |
* Updates the Offline gateway meta based on the form builder settings. This is done in order to use the legacy |
| 9 |
* instructions function. |
| 10 |
* |
| 11 |
* @since 3.0.0 |
| 12 |
* |
| 13 |
* @see give_get_offline_payment_instruction() |
| 14 |
*/ |
| 15 |
class UpdateOfflineMetaFromFormBuilder |
| 16 |
{ |
| 17 |
public function __invoke(DonationForm $form) |
| 18 |
{ |
| 19 |
$paymentGatewaysBlock = $form->blocks->findByName('givewp/payment-gateways'); |
| 20 |
if (!$paymentGatewaysBlock) { |
| 21 |
return; |
| 22 |
} |
| 23 |
|
| 24 |
[ |
| 25 |
'offlineEnabled' => $enabled, |
| 26 |
'offlineUseGlobalInstructions' => $useGlobalInstructions, |
| 27 |
'offlineDonationInstructions' => $donationInstructions, |
| 28 |
] = $paymentGatewaysBlock->getAttributes() + [ |
| 29 |
'offlineEnabled' => true, |
| 30 |
'offlineUseGlobalInstructions' => true, |
| 31 |
'offlineDonationInstructions' => '', |
| 32 |
]; |
| 33 |
|
| 34 |
if (!$enabled) { |
| 35 |
$modeMeta = 'disabled'; |
| 36 |
} elseif ($useGlobalInstructions) { |
| 37 |
$modeMeta = 'global'; |
| 38 |
} else { |
| 39 |
$modeMeta = 'enabled'; |
| 40 |
} |
| 41 |
|
| 42 |
give()->form_meta->update_meta( |
| 43 |
$form->id, |
| 44 |
'_give_customize_offline_donations', |
| 45 |
$modeMeta |
| 46 |
); |
| 47 |
|
| 48 |
give()->form_meta->update_meta( |
| 49 |
$form->id, |
| 50 |
'_give_offline_checkout_notes', |
| 51 |
$donationInstructions |
| 52 |
); |
| 53 |
} |
| 54 |
} |
| 55 |
|