PluginProbe
GiveWP – Donation Plugin and Fundraising Platform / 4.16.9
GiveWP – Donation Plugin and Fundraising Platform v4.16.9
4.16.9 4.16.8.1 4.16.8 4.16.7.2 4.16.7.1 4.16.7 4.16.6.1 4.16.6 4.16.5.1 4.16.5 4.16.4 4.16.3 4.16.2 4.16.1 4.16.0 4.15.5 4.15.4 4.15.3 4.15.2 4.15.1 4.15.0 2.3.0 2.3.1 2.3.2 2.30.0 All 255 releases
give / src / PaymentGateways / Gateways / ServiceProvider.php

ServiceProvider.php in GiveWP – Donation Plugin and Fundraising Platform 4.16.9, at src/PaymentGateways/Gateways/ServiceProvider.php

182 lines 6.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Give\PaymentGateways\Gateways;
4
5 use Give\Framework\Exceptions\Primitives\Exception;
6 use Give\Framework\PaymentGateways\Exceptions\OverflowException;
7 use Give\Framework\PaymentGateways\PaymentGatewayRegister;
8 use Give\Framework\Support\Scripts\Concerns\HasScriptAssetFile;
9 use Give\Helpers\Hooks;
10 use Give\Log\Log;
11 use Give\PaymentGateways\Gateways\Offline\Actions\DisableGatewayWhenDisabledPerForm;
12 use Give\PaymentGateways\Gateways\Offline\Actions\EnqueueOfflineFormBuilderScripts;
13 use Give\PaymentGateways\Gateways\Offline\Actions\UpdateOfflineMetaFromFormBuilder;
14 use Give\PaymentGateways\Gateways\PayPalCommerce\PayPalCommerceGateway;
15 use Give\PaymentGateways\Gateways\Stripe\Actions\AddExtraMetadataToPaymentIntent;
16 use Give\PaymentGateways\Gateways\Stripe\LegacyStripeAdapter;
17 use Give\PaymentGateways\Gateways\Stripe\StripePaymentElementGateway\Actions\AddStripeAttributesToNewForms;
18 use Give\PaymentGateways\Gateways\Stripe\StripePaymentElementGateway\Actions\EnqueueStripeFormBuilderScripts;
19 use Give\PaymentGateways\Gateways\Stripe\StripePaymentElementGateway\Actions\UpdateStripeFormBuilderSettingsMeta;
20 use Give\PaymentGateways\Gateways\Stripe\StripePaymentElementGateway\StripePaymentElementGateway;
21 use Give\PaymentGateways\Gateways\Stripe\StripePaymentElementGateway\Webhooks\Listeners\ChargeRefunded;
22 use Give\PaymentGateways\Gateways\Stripe\StripePaymentElementGateway\Webhooks\Listeners\CustomerSubscriptionCreated;
23 use Give\PaymentGateways\Gateways\Stripe\StripePaymentElementGateway\Webhooks\Listeners\CustomerSubscriptionDeleted;
24 use Give\PaymentGateways\Gateways\Stripe\StripePaymentElementGateway\Webhooks\Listeners\CustomerSubscriptionResumed;
25 use Give\PaymentGateways\Gateways\Stripe\StripePaymentElementGateway\Webhooks\Listeners\CustomerSubscriptionUpdated;
26 use Give\PaymentGateways\Gateways\Stripe\StripePaymentElementGateway\Webhooks\Listeners\InvoicePaymentFailed;
27 use Give\PaymentGateways\Gateways\Stripe\StripePaymentElementGateway\Webhooks\Listeners\InvoicePaymentSucceeded;
28 use Give\PaymentGateways\Gateways\Stripe\StripePaymentElementGateway\Webhooks\Listeners\PaymentIntentPaymentFailed;
29 use Give\PaymentGateways\Gateways\Stripe\StripePaymentElementGateway\Webhooks\Listeners\PaymentIntentSucceeded;
30 use Give\PaymentGateways\Gateways\TestGateway\TestGateway;
31 use Give\PaymentGateways\Gateways\TestOffsiteGateway\TestOffsiteGateway;
32 use Give\ServiceProviders\ServiceProvider as ServiceProviderInterface;
33
34 class ServiceProvider implements ServiceProviderInterface
35 {
36 use HasScriptAssetFile;
37
38 /**
39 * @since 3.0.0
40 */
41 public function register()
42 {
43 //
44 }
45
46 /**
47 * @since 3.0.0
48 */
49 public function boot()
50 {
51 try {
52 $this->registerGateways();
53 } catch (Exception $e) {
54 Log::error('Error Registering Gateways', [
55 'message' => $e->getMessage()
56 ]);
57 }
58 }
59
60 /**
61 * @since 4.16.8 register TestOffsiteGateway when GIVEWP_ENABLE_TEST_OFFSITE_GATEWAY is set
62 * @since 3.0.0
63 *
64 * @throws Exception
65 * @throws OverflowException
66 */
67 private function registerGateways()
68 {
69 add_action('givewp_register_payment_gateway', static function (PaymentGatewayRegister $registrar) {
70 // Not for production: it completes donations without charging anyone. The e2e suite turns it
71 // on through .wp-env.json to walk an offsite redirect end to end.
72 if (defined('GIVEWP_ENABLE_TEST_OFFSITE_GATEWAY') && GIVEWP_ENABLE_TEST_OFFSITE_GATEWAY) {
73 $registrar->registerGateway(TestOffsiteGateway::class);
74 }
75
76 $registrar->registerGateway(StripePaymentElementGateway::class);
77
78 $registrar->registerGateway(PayPalCommerceGateway::class);
79 });
80
81 $this->addLegacyStripeAdapter();
82 $this->addStripeWebhookListeners();
83 $this->addStripeFormBuilderHooks();
84 $this->addStripeTransactionMetadata();
85 $this->bootOfflineDonations();
86 }
87
88 /**
89 * @since 4.16.7
90 */
91 private function addStripeTransactionMetadata()
92 {
93 Hooks::addFilter('give_stripe_prepare_metadata', AddExtraMetadataToPaymentIntent::class, '__invoke', 10, 2);
94 }
95
96 /**
97 * @since 3.0.0
98 */
99 private function addStripeWebhookListeners()
100 {
101 Hooks::addAction(
102 'give_stripe_processing_payment_intent_succeeded',
103 PaymentIntentSucceeded::class
104 );
105
106 Hooks::addAction(
107 'give_stripe_processing_payment_intent_failed',
108 PaymentIntentPaymentFailed::class
109 );
110
111 Hooks::addAction(
112 'give_stripe_processing_charge_refunded',
113 ChargeRefunded::class
114 );
115
116 Hooks::addAction(
117 'give_recurring_stripe_processing_invoice_payment_succeeded',
118 InvoicePaymentSucceeded::class
119 );
120
121 Hooks::addAction(
122 'give_recurring_stripe_processing_invoice_payment_failed',
123 InvoicePaymentFailed::class
124 );
125
126 Hooks::addAction(
127 'give_recurring_stripe_processing_customer_subscription_created',
128 CustomerSubscriptionCreated::class
129 );
130
131 Hooks::addAction(
132 'give_recurring_stripe_processing_customer_subscription_deleted',
133 CustomerSubscriptionDeleted::class
134 );
135
136 Hooks::addAction(
137 'give_recurring_stripe_processing_customer_subscription_updated',
138 CustomerSubscriptionUpdated::class
139 );
140
141 Hooks::addAction(
142 'give_recurring_stripe_processing_customer_subscription_resumed',
143 CustomerSubscriptionResumed::class
144 );
145 }
146
147 /**
148 * @since 3.0.0
149 */
150 private function addLegacyStripeAdapter()
151 {
152 /** @var LegacyStripeAdapter $legacyStripeAdapter */
153 $legacyStripeAdapter = give(LegacyStripeAdapter::class);
154
155 $legacyStripeAdapter->addDonationDetails();
156 $legacyStripeAdapter->loadLegacyStripeWebhooksAndFilters();
157 }
158
159 /**
160 * @since 3.0.0
161 */
162 private function addStripeFormBuilderHooks()
163 {
164 Hooks::addAction('givewp_form_builder_enqueue_scripts', EnqueueStripeFormBuilderScripts::class);
165 Hooks::addAction('givewp_form_builder_new_form', AddStripeAttributesToNewForms::class);
166 Hooks::addAction('givewp_form_builder_updated', UpdateStripeFormBuilderSettingsMeta::class);
167 }
168
169 private function bootOfflineDonations()
170 {
171 Hooks::addAction('givewp_form_builder_enqueue_scripts', EnqueueOfflineFormBuilderScripts::class);
172 Hooks::addAction('givewp_form_builder_updated', UpdateOfflineMetaFromFormBuilder::class);
173 Hooks::addFilter(
174 'givewp_donation_form_enabled_gateways',
175 DisableGatewayWhenDisabledPerForm::class,
176 '__invoke',
177 10,
178 2
179 );
180 }
181 }
182