99 */
1010
1111use Monei \Core \ContainerProvider ;
12+ use Monei \Services \ApiKeyService ;
1213use Monei \Services \BlockSupportService ;
14+ use Monei \Services \MoneiApplePayVerificationService ;
15+ use Monei \Services \payment \MoneiPaymentServices ;
16+ use Monei \Services \sdk \MoneiSdkClientFactory ;
1317use Monei \Settings \MoneiSettings ;
1418
1519if ( ! class_exists ( 'Woocommerce_Gateway_Monei ' ) ) :
@@ -63,7 +67,7 @@ public function initalize_plugin() {
6367 }
6468
6569 self ::$ _initialized = true ;
66-
70+
6771 // Declare block compatibility
6872 $ this ->block_compatiblity ();
6973
@@ -72,23 +76,27 @@ public function initalize_plugin() {
7276
7377 public function block_compatiblity () {
7478 // Load checkout block class
75- add_action ( 'woocommerce_blocks_loaded ' , function () {
76- if ( ! class_exists ( 'Automattic\WooCommerce\Blocks\Payments\Integrations\AbstractPaymentMethodType ' ) ) {
77- return ;
79+ add_action (
80+ 'woocommerce_blocks_loaded ' ,
81+ function () {
82+ if ( ! class_exists ( 'Automattic\WooCommerce\Blocks\Payments\Integrations\AbstractPaymentMethodType ' ) ) {
83+ return ;
84+ }
85+ $ container = ContainerProvider::getContainer ();
86+ $ blockSupportService = $ container ->get ( BlockSupportService::class );
87+ $ blockSupportClasses = $ blockSupportService ->getBlockSupportClasses ();
88+ add_action (
89+ 'woocommerce_blocks_payment_method_type_registration ' ,
90+ function ( Automattic \WooCommerce \Blocks \Payments \PaymentMethodRegistry $ payment_method_registry ) use ( $ blockSupportClasses , $ container ) {
91+ foreach ( $ blockSupportClasses as $ className ) {
92+ if ( $ container ->has ( $ className ) ) {
93+ $ payment_method_registry ->register ( $ container ->get ( $ className ) );
94+ }
95+ }
96+ }
97+ );
7898 }
79- $ container = ContainerProvider::getContainer ();
80- $ blockSupportService = $ container ->get (BlockSupportService::class);
81- $ blockSupportClasses = $ blockSupportService ->getBlockSupportClasses ();
82- add_action ( 'woocommerce_blocks_payment_method_type_registration ' ,
83- function ( Automattic \WooCommerce \Blocks \Payments \PaymentMethodRegistry $ payment_method_registry ) use ($ blockSupportClasses , $ container ){
84- foreach ($ blockSupportClasses as $ className ) {
85- if ($ container ->has ($ className )) {
86- $ payment_method_registry ->register ($ container ->get ($ className ));
87- }
88- }
89- } );
90-
91- } );
99+ );
92100 }
93101
94102 /**
@@ -128,21 +136,22 @@ private function define_constants() {
128136 * Include required core files used in admin and on the frontend.
129137 */
130138 private function includes () {
131- $ container = ContainerProvider::getContainer ();
139+ $ container = ContainerProvider::getContainer ();
132140 include_once 'includes/woocommerce-gateway-monei-core-functions.php ' ;
133141 include_once 'includes/class-wc-monei-ipn.php ' ;
134- include_once 'includes/class-wc-monei-api.php ' ;
135142 include_once 'includes/class-wc-monei-logger.php ' ;
136143 include_once 'includes/addons/trait-wc-monei-addons-helper.php ' ;
137144 include_once 'includes/addons/trait-wc-monei-subscriptions.php ' ;
138- include_once 'includes/addons/class-wc-monei-apple-pay-verification.php ' ;
139145
140146 if ( $ this ->is_request ( 'admin ' ) ) {
141147 include_once 'includes/class-wc-monei-pre-auth.php ' ;
142- add_filter ('woocommerce_get_settings_pages ' , function ($ settings ) use ($ container ) {
143- $ settings [] = new MoneiSettings ($ container );
144- return $ settings ;
145- });
148+ add_filter (
149+ 'woocommerce_get_settings_pages ' ,
150+ function ( $ settings ) use ( $ container ) {
151+ $ settings [] = new MoneiSettings ( $ container );
152+ return $ settings ;
153+ }
154+ );
146155 }
147156
148157 if ( $ this ->is_request ( 'frontend ' ) ) {
@@ -175,12 +184,12 @@ function admin_new_install_notice() {
175184 }
176185 return ;
177186 }
178- $ container = \Monei \Core \ContainerProvider::getContainer ();
179- $ templateManager = $ container ->get ('Monei\Templates\TemplateManager ' );
180- $ template = $ templateManager ->getTemplate ('notice-admin-new-install ' );
181- if ( $ template ) {
182- $ template ->render ([] );
183- }
187+ $ container = \Monei \Core \ContainerProvider::getContainer ();
188+ $ templateManager = $ container ->get ( 'Monei\Templates\TemplateManager ' );
189+ $ template = $ templateManager ->getTemplate ( 'notice-admin-new-install ' );
190+ if ( $ template ) {
191+ $ template ->render ( array () );
192+ }
184193 }
185194
186195 /**
@@ -189,12 +198,12 @@ function admin_new_install_notice() {
189198 * @return void
190199 */
191200 public function dependency_notice () {
192- $ container = \Monei \Core \ContainerProvider::getContainer ();
193- $ templateManager = $ container ->get ('Monei\Templates\TemplateManager ' );
194- $ template = $ templateManager ->getTemplate ('notice-admin-dependency ' );
195- if ( $ template ) {
196- $ template ->render ([] );
197- }
201+ $ container = \Monei \Core \ContainerProvider::getContainer ();
202+ $ templateManager = $ container ->get ( 'Monei\Templates\TemplateManager ' );
203+ $ template = $ templateManager ->getTemplate ( 'notice-admin-dependency ' );
204+ if ( $ template ) {
205+ $ template ->render ( array () );
206+ }
198207 }
199208
200209 /**
@@ -243,56 +252,40 @@ private function is_request( $type ) {
243252 public function init () {
244253 // Before init
245254 do_action ( 'before_woocommerce_gateway_monei_init ' );
255+ //TODO use the container
256+ $ apiKeyService = new ApiKeyService ();
257+ $ sdkClient = new MoneiSdkClientFactory ( $ apiKeyService );
258+ $ moneiPaymentServices = new MoneiPaymentServices ( $ sdkClient );
259+ new MoneiApplePayVerificationService ( $ moneiPaymentServices );
246260
247261 // todo: not translation yet.
248262 //$this->load_plugin_textdomain();
249263
250- add_filter ( 'option_woocommerce_monei_bizum_settings ' , array ( $ this , 'monei_settings_by_default ' ), 1 );
264+ add_filter ( 'option_woocommerce_monei_bizum_settings ' , array ( $ this , 'monei_settings_by_default ' ), 1 );
251265 add_filter ( 'option_woocommerce_monei_paypal_settings ' , array ( $ this , 'monei_settings_by_default ' ), 1 );
252- add_filter ( 'option_woocommerce_monei_multibanco_settings ' , array ( $ this , 'monei_settings_by_default ' ), 1 );
253- add_filter ( 'option_woocommerce_monei_mbway_settings ' , array ( $ this , 'monei_settings_by_default ' ), 1 );
254- add_filter ( 'option_woocommerce_monei_settings ' , array ( $ this , 'copyKeysToCentralSettings ' ), 1 );
266+ add_filter ( 'option_woocommerce_monei_multibanco_settings ' , array ( $ this , 'monei_settings_by_default ' ), 1 );
267+ add_filter ( 'option_woocommerce_monei_mbway_settings ' , array ( $ this , 'monei_settings_by_default ' ), 1 );
255268
256269 // Init action.
257270 do_action ( 'woocommerce_gateway_monei_init ' );
258- wp_register_style (
259- 'monei-icons ' ,
271+ wp_register_style (
272+ 'monei-icons ' ,
260273 $ this ->plugin_url () . '/public/css/monei-icons-classic.css ' ,
261- [],
274+ array (),
262275 filemtime ( $ this ->plugin_path () . '/public/css/monei-icons-classic.css ' ),
263- 'screen '
276+ 'screen '
264277 );
265278 wp_enqueue_style ( 'monei-icons ' );
266- wp_register_style (
267- 'monei-blocks-checkout-cc ' ,
268- WC_Monei ()->plugin_url (). '/public/css/monei-blocks-checkout.css ' ,
269- array (),
270- WC_Monei ()->version ,
271- 'all '
272- );
273- wp_enqueue_style ( 'monei-blocks-checkout-cc ' );
279+ wp_register_style (
280+ 'monei-blocks-checkout-cc ' ,
281+ WC_Monei ()->plugin_url () . '/public/css/monei-blocks-checkout.css ' ,
282+ array (),
283+ WC_Monei ()->version ,
284+ 'all '
285+ );
286+ wp_enqueue_style ( 'monei-blocks-checkout-cc ' );
274287 }
275288
276- public function copyKeysToCentralSettings ($ default_params )
277- {
278- $ centralApiKey = get_option ('monei_apikey ' );
279- $ centralAccountId = get_option ('monei_accountid ' );
280- $ ccApiKey = $ default_params ['apikey ' ] ?? false ;
281- $ ccAccountId = $ default_params ['accountid ' ] ?? false ;
282-
283- // Update API key if centralApiKey is empty
284- if ( empty ( $ centralApiKey ) && !empty ( $ ccApiKey ) ) {
285- update_option ( 'monei_apikey ' , $ ccApiKey );
286- }
287-
288- // Update Account ID if centralAccountId is empty
289- if ( empty ( $ centralAccountId ) && !empty ( $ ccAccountId ) ) {
290- update_option ( 'monei_accountid ' , $ ccAccountId );
291- }
292-
293- return $ default_params ;
294- }
295-
296289
297290 /**
298291 * We have more than a Monei payment provider, we will use by default the main monei set up in case they don't set them up.
@@ -301,32 +294,32 @@ public function copyKeysToCentralSettings($default_params)
301294 *
302295 * @return array
303296 */
304- public function monei_settings_by_default ( $ default_params ) {
305- $ default_params ['testmode ' ] = $ this ->get_setting_with_default ( 'testmode ' , $ default_params );
306- $ default_params ['apikey ' ] = $ this ->get_setting_with_default ( 'apikey ' , $ default_params );
307- $ default_params ['debug ' ] = $ this ->get_setting_with_default ( 'debug ' , $ default_params );
308- $ default_params ['orderdo ' ] = ( empty ( $ default_params ['orderdo ' ] ) ) ? monei_get_settings ( 'orderdo ' ) : $ default_params ['orderdo ' ];
297+ public function monei_settings_by_default ( $ default_params ) {
298+ $ default_params ['testmode ' ] = $ this ->get_setting_with_default ( 'testmode ' , $ default_params );
299+ $ default_params ['apikey ' ] = $ this ->get_setting_with_default ( 'apikey ' , $ default_params );
300+ $ default_params ['debug ' ] = $ this ->get_setting_with_default ( 'debug ' , $ default_params );
301+ $ default_params ['orderdo ' ] = ( empty ( $ default_params ['orderdo ' ] ) ) ? monei_get_settings ( 'orderdo ' ) : $ default_params ['orderdo ' ];
309302
310- return $ default_params ;
311- }
303+ return $ default_params ;
304+ }
312305
313- private function get_setting_with_default ( $ key , $ params ) {
314- if ( ! empty ( $ params [ $ key ] ) ) {
315- return $ params [ $ key ];
316- }
306+ private function get_setting_with_default ( $ key , $ params ) {
307+ if ( ! empty ( $ params [ $ key ] ) ) {
308+ return $ params [ $ key ];
309+ }
317310
318- $ option_value = get_option ( "monei_ $ key " );
319- if ( ! empty ( $ option_value ) ) {
320- return $ option_value ;
321- }
311+ $ option_value = get_option ( "monei_ $ key " );
312+ if ( ! empty ( $ option_value ) ) {
313+ return $ option_value ;
314+ }
322315
323- $ monei_setting_value = monei_get_settings ( $ key );
324- if ( ! empty ( $ monei_setting_value ) ) {
325- return $ monei_setting_value ;
326- }
316+ $ monei_setting_value = monei_get_settings ( $ key );
317+ if ( ! empty ( $ monei_setting_value ) ) {
318+ return $ monei_setting_value ;
319+ }
327320
328- return '' ;
329- }
321+ return '' ;
322+ }
330323
331324 /**
332325 * Hooks when plugin_loaded
@@ -343,17 +336,17 @@ public function plugins_loaded() {
343336 * @return array
344337 */
345338 public function add_gateways ( $ methods ) {
346- $ container = \Monei \Core \ContainerProvider::getContainer ();
347-
348- $ methods [] = $ container ->get ('Monei\Gateways\PaymentMethods\WCGatewayMoneiCC ' );
349- if (! is_admin ()) {
350- $ methods [] = $ container ->get ('Monei\Gateways\PaymentMethods\WCGatewayMoneiAppleGoogle ' );
351- }
352- $ methods [] = $ container ->get ('Monei\Gateways\PaymentMethods\WCGatewayMoneiCofidis ' );
353- $ methods [] = $ container ->get ('Monei\Gateways\PaymentMethods\WCGatewayMoneiBizum ' );
354- $ methods [] = $ container ->get ('Monei\Gateways\PaymentMethods\WCGatewayMoneiPaypal ' );
355- $ methods [] = $ container ->get ('Monei\Gateways\PaymentMethods\WCGatewayMoneiMultibanco ' );
356- $ methods [] = $ container ->get ('Monei\Gateways\PaymentMethods\WCGatewayMoneiMBWay ' );
339+ $ container = \Monei \Core \ContainerProvider::getContainer ();
340+
341+ $ methods [] = $ container ->get ( 'Monei\Gateways\PaymentMethods\WCGatewayMoneiCC ' );
342+ if ( ! is_admin () ) {
343+ $ methods [] = $ container ->get ( 'Monei\Gateways\PaymentMethods\WCGatewayMoneiAppleGoogle ' );
344+ }
345+ $ methods [] = $ container ->get ( 'Monei\Gateways\PaymentMethods\WCGatewayMoneiCofidis ' );
346+ $ methods [] = $ container ->get ( 'Monei\Gateways\PaymentMethods\WCGatewayMoneiBizum ' );
347+ $ methods [] = $ container ->get ( 'Monei\Gateways\PaymentMethods\WCGatewayMoneiPaypal ' );
348+ $ methods [] = $ container ->get ( 'Monei\Gateways\PaymentMethods\WCGatewayMoneiMultibanco ' );
349+ $ methods [] = $ container ->get ( 'Monei\Gateways\PaymentMethods\WCGatewayMoneiMBWay ' );
357350 return $ methods ;
358351 }
359352
@@ -424,4 +417,3 @@ public function ajax_url() {
424417 }
425418
426419endif ;
427-
0 commit comments