give
/
src
/
PaymentGateways
/
Gateways
/
Stripe
/
StripePaymentElementGateway
/
Actions
/
UpdateStripeFormBuilderSettingsMeta.php
give
/
src
/
PaymentGateways
/
Gateways
/
Stripe
/
StripePaymentElementGateway
/
Actions
Last commit date
AddStripeAttributesToNewForms.php
2 years ago
EnqueueStripeFormBuilderScripts.php
2 years ago
UpdateStripeFormBuilderSettingsMeta.php
2 years ago
UpdateStripeInvoiceMetaData.php
1 year ago
UpdateStripeFormBuilderSettingsMeta.php
46 lines
| 1 | <?php |
| 2 | |
| 3 | namespace Give\PaymentGateways\Gateways\Stripe\StripePaymentElementGateway\Actions; |
| 4 | |
| 5 | use Give\DonationForms\Models\DonationForm; |
| 6 | |
| 7 | /** |
| 8 | * Update Stripe settings on backwards compatible form meta. |
| 9 | * |
| 10 | * @since 3.0.0 |
| 11 | */ |
| 12 | class UpdateStripeFormBuilderSettingsMeta |
| 13 | { |
| 14 | /** |
| 15 | * @since 3.0.0 |
| 16 | * @param DonationForm $form |
| 17 | */ |
| 18 | public function __invoke(DonationForm $form) |
| 19 | { |
| 20 | $paymentGatewaysBlock = $form->blocks->findByName('givewp/payment-gateways'); |
| 21 | if (!$paymentGatewaysBlock) { |
| 22 | return; |
| 23 | } |
| 24 | |
| 25 | [ |
| 26 | 'stripeUseGlobalDefault' => $stripeUseGlobalDefault, |
| 27 | 'stripeAccountId' => $stripeAccountId |
| 28 | ] = $paymentGatewaysBlock->getAttributes() + ['stripeUseGlobalDefault' => true, 'stripeAccountId' => '']; |
| 29 | |
| 30 | if (is_bool($stripeUseGlobalDefault)) { |
| 31 | give()->form_meta->update_meta( |
| 32 | $form->id, |
| 33 | "give_stripe_per_form_accounts", |
| 34 | $stripeUseGlobalDefault ? 'disabled' : 'enabled' |
| 35 | ); |
| 36 | |
| 37 | if ($stripeUseGlobalDefault === false && $stripeAccountId && strpos( |
| 38 | $stripeAccountId, |
| 39 | 'acct_' |
| 40 | ) !== false) { |
| 41 | give()->form_meta->update_meta($form->id, "_give_stripe_default_account", $stripeAccountId); |
| 42 | } |
| 43 | } |
| 44 | } |
| 45 | } |
| 46 |