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 5.2.0-beta.1 10.0.2 5.2.0-rc.1 10.0.3 5.2.0-rc.2 10.0.4 5.2.1 10.0.5 5.2.2 10.0.6 5.2.3 10.1.0 5.2.4 10.1.0-rc.1 5.2.5 10.1.0-rc.2 5.3.0 10.1.0-rc.3 5.3.0-beta.1 10.1.0-rc.4 5.3.0-rc.1 10.1.1 5.3.0-rc.2 10.1.2 5.3.1 10.1.3 5.3.2 10.1.4 5.3.3 10.2.0 5.4.0 10.2.0-beta.1 5.4.0-beta.1 10.2.0-beta.2 5.4.0-rc.1 10.2.0-rc.1 5.4.1 10.2.1 5.4.2 10.2.2 5.4.3 10.2.3 5.4.4 10.2.4 5.4.5 10.3.0 5.5.0 10.3.0-beta.1 5.5.0-beta.1 10.3.0-beta.2 5.5.0-rc.1 10.3.0-rc.1 5.5.0-rc.2 10.3.0-rc.2 5.5.1 10.3.1 5.5.2 10.3.2 5.5.3 10.3.3 5.5.4 10.3.4 5.5.5 10.3.5 5.6.0 10.3.6 5.6.0-beta.1 10.3.7 5.6.0-rc.1 10.3.8 5.6.0-rc.2 10.4.0 5.6.1 10.4.0-beta.1 5.6.2 10.4.0-beta.2 5.6.3 10.4.0-rc.1 5.7.0 10.4.1 5.7.0-beta.1 10.4.2 5.7.0-rc.1 10.4.3 5.7.1 10.4.4 5.7.2 10.5.0 5.7.3 10.5.0-beta.1 5.8.0 10.5.0-beta.2 5.8.0-beta.1 10.5.0-rc.1 5.8.0-beta.2 10.5.0-rc.2 5.8.0-rc.1 10.5.0-rc.3 5.8.1 10.5.1 5.8.2 10.5.2 5.9.0 10.5.3 5.9.0-beta.1 10.6.0 5.9.0-rc.1 10.6.0-beta.1 5.9.0-rc.2 10.6.0-beta.2 5.9.1 10.6.0-rc.1 5.9.2 10.6.1 6.0.0 10.6.2 6.0.0-beta.1 10.7.0 6.0.0-rc.1 10.7.0-beta.1 6.0.1 10.7.0-beta.2 6.0.2 10.7.0-rc.1 6.1.0 3.0.0 6.1.0-beta.1 3.0.1 6.1.0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7.1.0-rc.1 3.7.1 7.1.0-rc.2 3.7.2 7.1.1
woocommerce / src / Internal / Admin / Settings / PaymentsProviders / Mollie.php
woocommerce / src / Internal / Admin / Settings / PaymentsProviders Last commit date
WooPayments 1 month ago Affirm.php 1 year ago AfterpayClearpay.php 1 year ago Airwallex.php 1 year ago AmazonPay.php 1 year ago Antom.php 1 year ago Eway.php 11 months ago GoCardless.php 1 year ago HelioPay.php 1 year ago Klarna.php 1 year ago KlarnaCheckout.php 1 year ago MercadoPago.php 1 year ago Mollie.php 1 year ago Monei.php 1 year ago NexiCheckout.php 11 months ago PayPal.php 1 year ago PayUIndia.php 1 year ago Payfast.php 1 year ago PaymentGateway.php 5 months ago Paymob.php 1 year ago Payoneer.php 1 year ago Paystack.php 1 year ago Paytrail.php 1 year ago PseudoWCPaymentGateway.php 1 year ago Razorpay.php 1 year ago Stripe.php 1 year ago Tilopay.php 1 year ago Visa.php 11 months ago Vivacom.php 1 year ago WCCore.php 9 months ago WooPayments.php 9 months ago
Mollie.php
188 lines
1 <?php
2 declare( strict_types=1 );
3
4 namespace Automattic\WooCommerce\Internal\Admin\Settings\PaymentsProviders;
5
6 use Automattic\WooCommerce\Internal\Logging\SafeGlobalFunctionProxy;
7 use Throwable;
8 use WC_Payment_Gateway;
9
10 defined( 'ABSPATH' ) || exit;
11
12 /**
13 * Mollie payment gateway provider class.
14 *
15 * This class handles all the custom logic for the Mollie payment gateway provider.
16 */
17 class Mollie extends PaymentGateway {
18
19 /**
20 * Get the settings URL for a payment gateway.
21 *
22 * @param WC_Payment_Gateway $payment_gateway The payment gateway object.
23 *
24 * @return string The settings URL for the payment gateway.
25 */
26 public function get_settings_url( WC_Payment_Gateway $payment_gateway ): string {
27 // Don't target any section because there are none to target when Mollie is not connected.
28 if ( 'mollie_stand_in' === $payment_gateway->id ) {
29 return $this->get_custom_settings_url();
30 }
31
32 // Target the payment methods section when the gateway is connected.
33 return $this->get_custom_settings_url( 'mollie_payment_methods' );
34 }
35
36 /**
37 * Check if the payment gateway has a payments processor account connected.
38 *
39 * @param WC_Payment_Gateway $payment_gateway The payment gateway object.
40 *
41 * @return bool True if the payment gateway account is connected, false otherwise.
42 * If the payment gateway does not provide the information, it will return true.
43 */
44 public function is_account_connected( WC_Payment_Gateway $payment_gateway ): bool {
45 try {
46 $sandbox_mode = $this->is_mollie_in_sandbox_mode( $payment_gateway );
47 // Let null results bubble up to the parent class.
48 if ( true === $sandbox_mode ) {
49 // If Mollie is in sandbox mode, we consider the account connected if the test API key is set.
50 return ! empty( get_option( 'mollie-payments-for-woocommerce_test_api_key', '' ) );
51 } elseif ( false === $sandbox_mode ) {
52 // In production mode, we check the live API key.
53 return ! empty( get_option( 'mollie-payments-for-woocommerce_live_api_key', '' ) );
54 }
55 } catch ( Throwable $e ) {
56 // Do nothing but log so we can investigate.
57 SafeGlobalFunctionProxy::wc_get_logger()->debug(
58 'Failed to determine if gateway has an account connected: ' . $e->getMessage(),
59 array(
60 'gateway' => $payment_gateway->id,
61 'source' => 'settings-payments',
62 'exception' => $e,
63 )
64 );
65 }
66
67 return parent::is_account_connected( $payment_gateway );
68 }
69
70 /**
71 * Determine if the payment gateway is in test mode.
72 *
73 * @param WC_Payment_Gateway $payment_gateway The payment gateway object.
74 *
75 * @return bool True if the payment gateway is in test mode, false otherwise.
76 */
77 public function is_in_test_mode( WC_Payment_Gateway $payment_gateway ): bool {
78 return $this->is_mollie_in_sandbox_mode( $payment_gateway ) ?? parent::is_in_test_mode( $payment_gateway );
79 }
80
81 /**
82 * Try to determine if the payment gateway is in test mode onboarding (aka sandbox or test-drive).
83 *
84 * This is a best-effort attempt, as there is no standard way to determine this.
85 * Trust the true value, but don't consider a false value as definitive.
86 *
87 * @param WC_Payment_Gateway $payment_gateway The payment gateway object.
88 *
89 * @return bool True if the payment gateway is in test mode onboarding, false otherwise.
90 */
91 public function is_in_test_mode_onboarding( WC_Payment_Gateway $payment_gateway ): bool {
92 return $this->is_mollie_in_sandbox_mode( $payment_gateway ) ?? parent::is_in_test_mode_onboarding( $payment_gateway );
93 }
94
95 /**
96 * Determine if at least a Mollie gateway is registered.
97 *
98 * @param array $payment_gateways The payment gateways objects.
99 *
100 * @return bool True if at least a Mollie gateway is registered, false otherwise.
101 */
102 public function is_gateway_registered( array $payment_gateways ): bool {
103 $mollie_gateways = array_filter(
104 $payment_gateways,
105 function ( $gateway ) {
106 return str_starts_with( $gateway->id, 'mollie_wc_gateway_' );
107 }
108 );
109
110 return ! empty( $mollie_gateways );
111 }
112
113 /**
114 * Get the pseudo Mollie gateway object.
115 *
116 * @param array $suggestion The suggestion data.
117 *
118 * @return PseudoWCPaymentGateway The pseudo gateway object.
119 */
120 public function get_pseudo_gateway( array $suggestion ): PseudoWCPaymentGateway {
121 // We will generate a generic gateway to represent Mollie in the settings page.
122 // The generic gateway's state will be not enabled, not connected, and not onboarded.
123 // The presentational details will be minimal, letting the suggestion provide most of the information.
124 return new PseudoWCPaymentGateway(
125 'mollie_stand_in',
126 array(
127 'method_title' => $suggestion['title'],
128 'method_description' => $suggestion['description'],
129 'enabled' => false,
130 'needs_setup' => true,
131 'test_mode' => false,
132 'dev_mode' => false,
133 'account_connected' => false,
134 'onboarding_started' => false,
135 'onboarding_completed' => false,
136 'settings_url' => $this->get_custom_settings_url(),
137 'plugin_slug' => $suggestion['plugin']['slug'],
138 'plugin_file' => $suggestion['plugin']['file'],
139 ),
140 );
141 }
142
143 /**
144 * Get the URL to the custom settings page for Mollie.
145 *
146 * @param string $section Optional. The section to navigate to.
147 *
148 * @return string The URL to the custom settings page for Mollie.
149 */
150 private function get_custom_settings_url( string $section = '' ): string {
151 $settings_url = admin_url( 'admin.php?page=wc-settings&tab=mollie_settings' );
152
153 if ( ! empty( $section ) ) {
154 $settings_url = add_query_arg( 'section', $section, $settings_url );
155 }
156
157 return $settings_url;
158 }
159
160 /**
161 * Check if the Mollie payment gateway is in sandbox mode.
162 *
163 * @param WC_Payment_Gateway $payment_gateway The payment gateway object.
164 *
165 * @return ?bool True if the payment gateway is in sandbox mode, false otherwise.
166 * Null if the environment could not be determined.
167 */
168 private function is_mollie_in_sandbox_mode( WC_Payment_Gateway $payment_gateway ): ?bool {
169 try {
170 // Unfortunately, Mollie does not provide a standard way to determine if the gateway is in sandbox mode.
171 return filter_var( get_option( 'mollie-payments-for-woocommerce_test_mode_enabled', 'yes' ), FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE );
172 } catch ( \Throwable $e ) {
173 // Do nothing but log so we can investigate.
174 SafeGlobalFunctionProxy::wc_get_logger()->debug(
175 'Failed to determine if gateway is in sandbox mode: ' . $e->getMessage(),
176 array(
177 'gateway' => $payment_gateway->id,
178 'source' => 'settings-payments',
179 'exception' => $e,
180 )
181 );
182 }
183
184 // Let the caller know that we couldn't determine the environment.
185 return null;
186 }
187 }
188