PluginProbe
WooCommerce / 11.0.1
WooCommerce v11.0.1
11.1.0 11.1.0-rc.2 11.1.0-rc.1 11.1.0-beta.2 11.1.0-beta.1 11.0.1 11.0.0 11.0.0-rc.3 11.0.0-rc.2 11.0.0-rc.1 11.0.0-beta.2 11.0.0-beta.1 10.9.4 10.9.3 10.9.2 10.9.1 10.9.0 10.9.0-rc.1 10.9.0-beta.2 10.9.0-beta.1 10.8.1 10.8.0 10.8.0-rc.1 10.8.0-beta.2 10.8.0-beta.1 All 648 releases
woocommerce / src / Internal / Admin / Settings / PaymentsProviders / NexiCheckout.php
NexiCheckout.php
114 lines 4.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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 * Nexi Checkout payment gateway provider class.
14 *
15 * This class handles all the custom logic for the Nexi Checkout payment gateway provider.
16 */
17 class NexiCheckout extends PaymentGateway {
18
19 /**
20 * Check if the payment gateway has a payments processor account connected.
21 *
22 * @param WC_Payment_Gateway $payment_gateway The payment gateway object.
23 *
24 * @return bool True if the payment gateway account is connected, false otherwise.
25 * If the payment gateway does not provide the information, it will return true.
26 */
27 public function is_account_connected( WC_Payment_Gateway $payment_gateway ): bool {
28 try {
29 $sandbox = $this->is_nexi_in_sandbox_mode( $payment_gateway );
30 if ( null === $sandbox ) {
31 return parent::is_account_connected( $payment_gateway );
32 }
33
34 return $sandbox
35 ? ( ! empty( $payment_gateway->get_option( 'dibs_test_key' ) ) && ! empty( $payment_gateway->get_option( 'dibs_test_checkout_key' ) ) )
36 : ( ! empty( $payment_gateway->get_option( 'dibs_live_key' ) ) && ! empty( $payment_gateway->get_option( 'dibs_checkout_key' ) ) );
37 } catch ( Throwable $e ) {
38 // Do nothing but log so we can investigate.
39 SafeGlobalFunctionProxy::wc_get_logger()->debug(
40 'Failed to determine if gateway has an account connected: ' . $e->getMessage(),
41 array(
42 'gateway' => $payment_gateway->id,
43 'source' => 'settings-payments',
44 'exception' => $e,
45 )
46 );
47 }
48
49 return parent::is_account_connected( $payment_gateway );
50 }
51
52 /**
53 * Try to determine if the payment gateway is in test mode.
54 *
55 * @param WC_Payment_Gateway $payment_gateway The payment gateway object.
56 *
57 * @return bool True if the payment gateway is in test mode, false otherwise.
58 */
59 public function is_in_test_mode( WC_Payment_Gateway $payment_gateway ): bool {
60 return $this->is_nexi_in_sandbox_mode( $payment_gateway ) ?? parent::is_in_test_mode( $payment_gateway );
61 }
62
63 /**
64 * Try to determine if the payment gateway is in dev mode.
65 *
66 * @param WC_Payment_Gateway $payment_gateway The payment gateway object.
67 *
68 * @return bool True if the payment gateway is in dev mode, false otherwise.
69 */
70 public function is_in_dev_mode( WC_Payment_Gateway $payment_gateway ): bool {
71 return $this->is_nexi_in_sandbox_mode( $payment_gateway ) ?? parent::is_in_dev_mode( $payment_gateway );
72 }
73
74 /**
75 * Try to determine if the payment gateway is in test mode onboarding (aka sandbox or test-drive).
76 *
77 * @param WC_Payment_Gateway $payment_gateway The payment gateway object.
78 *
79 * @return bool True if the payment gateway is in test mode onboarding, false otherwise.
80 */
81 public function is_in_test_mode_onboarding( WC_Payment_Gateway $payment_gateway ): bool {
82 return $this->is_nexi_in_sandbox_mode( $payment_gateway ) ?? parent::is_in_test_mode_onboarding( $payment_gateway );
83 }
84
85 /**
86 * Check if the Nexi Checkout payment gateway is in test/sandbox mode.
87 *
88 * There are two different environments: test/sandbox and production.
89 *
90 * @param WC_Payment_Gateway $payment_gateway The payment gateway object.
91 *
92 * @return ?bool True if the payment gateway is in sandbox mode, false otherwise.
93 * Null if the environment could not be determined.
94 */
95 private function is_nexi_in_sandbox_mode( WC_Payment_Gateway $payment_gateway ): ?bool {
96 try {
97 return \wc_string_to_bool( $payment_gateway->get_option( 'test_mode' ) );
98 } catch ( Throwable $e ) {
99 // Do nothing but log so we can investigate.
100 SafeGlobalFunctionProxy::wc_get_logger()->debug(
101 'Failed to determine if gateway is in sandbox mode: ' . $e->getMessage(),
102 array(
103 'gateway' => $payment_gateway->id,
104 'source' => 'settings-payments',
105 'exception' => $e,
106 )
107 );
108 }
109
110 // Let the caller know that we couldn't determine the environment.
111 return null;
112 }
113 }
114