illing form with details * provided by Google Pay. */ if (is_checkout()) { $button->enqueue(); } if (has_block('woocommerce/checkout') || has_block('woocommerce/cart')) { /** * Should add this to the ButtonInterface. * * @psalm-suppress UndefinedInterfaceMethod */ $button->enqueue_styles(); } }); // Enqueue backend scripts. add_action('admin_enqueue_scripts', static function () use ($c, $button) { if (!is_admin() || !$c->get('wcgateway.is-ppcp-settings-payment-methods-page')) { return; } /** * Should add this to the ButtonInterface. * * @psalm-suppress UndefinedInterfaceMethod */ $button->enqueue_admin(); }); // Registers buttons on blocks pages. add_action('woocommerce_blocks_payment_method_type_registration', function (PaymentMethodRegistry $payment_method_registry) use ($c, $button): void { if (SettingsModule::should_use_the_old_ui() && !$button->is_enabled()) { return; } $payment_method_registry->register($c->get('googlepay.blocks-payment-method')); }); // Adds GooglePay component to the backend button preview settings. add_action('woocommerce_paypal_payments_admin_gateway_settings', function (array $settings) use ($c): array { if (is_array($settings['components'])) { $settings['components'][] = 'googlepay'; } return $settings; }); // Initialize AJAX endpoints. add_action('wc_ajax_' . UpdatePaymentDataEndpoint::ENDPOINT, static function () use ($c) { $endpoint = $c->get('googlepay.endpoint.update-payment-data'); assert($endpoint instanceof UpdatePaymentDataEndpoint); $endpoint->handle_request(); }); }, 1); add_filter( 'woocommerce_payment_gateways', /** * Param types removed to avoid third-party issues. * * @psalm-suppress MissingClosureParamType */ static function ($methods) use ($c): array { if (!is_array($methods)) { return $methods; } $settings = $c->get('wcgateway.settings'); assert($settings instanceof Settings); if ($settings->has('googlepay_button_enabled') && $settings->get('googlepay_button_enabled')) { $googlepay_gateway = $c->get('googlepay.wc-gateway'); assert($googlepay_gateway instanceof WC_Payment_Gateway); $methods[] = $googlepay_gateway; } return $methods; } ); add_action('woocommerce_review_order_after_submit', function () { echo '
'; }); add_action('woocommerce_pay_order_after_submit', function () { echo '
'; }); add_filter('woocommerce_paypal_payments_selected_button_locations', function (array $locations, string $setting_name): array { $gateway = WC()->payment_gateways()->payment_gateways()[\WooCommerce\PayPalCommerce\Googlepay\GooglePayGateway::ID] ?? ''; if ($gateway && $gateway->enabled === 'yes' && $setting_name === 'smart_button_locations') { $locations[] = 'checkout'; } return $locations; }, 10, 2); add_filter('woocommerce_paypal_payments_rest_common_merchant_features', function (array $features) use ($c): array { $product_status = $c->get('googlepay.helpers.apm-product-status'); assert($product_status instanceof ApmProductStatus); $google_pay_enabled = $product_status->is_active(); $features[FeaturesDefinition::FEATURE_GOOGLE_PAY] = array('enabled' => $google_pay_enabled); return $features; }); add_filter('ppcp_create_order_request_body_data', static function (array $data, string $payment_method, array $request) use ($c): array { $funding_source = $request['funding_source'] ?? ''; if ($payment_method !== \WooCommerce\PayPalCommerce\Googlepay\GooglePayGateway::ID && $funding_source !== 'googlepay') { return $data; } $settings = $c->get('wcgateway.settings'); assert($settings instanceof Settings); $experience_context_builder = $c->get('wcgateway.builder.experience-context'); assert($experience_context_builder instanceof ExperienceContextBuilder); $payment_source_data = array('experience_context' => $experience_context_builder->with_endpoint_return_urls()->build()->to_array()); $three_d_secure_contingency = $settings->has('3d_secure_contingency') ? apply_filters('woocommerce_paypal_payments_three_d_secure_contingency', $settings->get('3d_secure_contingency')) : ''; if ($three_d_secure_contingency === 'SCA_ALWAYS' || $three_d_secure_contingency === 'SCA_WHEN_REQUIRED') { $payment_source_data['attributes'] = array('verification' => array('method' => $three_d_secure_contingency)); } $data['payment_source'] = array('google_pay' => $payment_source_data); return $data; }, 10, 3); return \true; } }