Completed
Branch master (65e7e7)
by
unknown
16:24 queued 12:09
created
espresso.php 1 patch
Indentation   +107 added lines, -107 removed lines patch added patch discarded remove patch
@@ -37,138 +37,138 @@
 block discarded – undo
37 37
  * @since           4.0
38 38
  */
39 39
 if (function_exists('espresso_version')) {
40
-    if (! function_exists('espresso_duplicate_plugin_error')) {
41
-        /**
42
-         *    espresso_duplicate_plugin_error
43
-         *    displays if more than one version of EE is activated at the same time.
44
-         */
45
-        function espresso_duplicate_plugin_error()
46
-        {
47
-            ?>
40
+	if (! function_exists('espresso_duplicate_plugin_error')) {
41
+		/**
42
+		 *    espresso_duplicate_plugin_error
43
+		 *    displays if more than one version of EE is activated at the same time.
44
+		 */
45
+		function espresso_duplicate_plugin_error()
46
+		{
47
+			?>
48 48
 <div class="error">
49 49
 	<p>
50 50
 		<?php
51
-                    echo esc_html__(
52
-                        'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.',
53
-                        'event_espresso'
54
-                    ); ?>
51
+					echo esc_html__(
52
+						'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.',
53
+						'event_espresso'
54
+					); ?>
55 55
 	</p>
56 56
 </div>
57 57
 <?php
58
-            espresso_deactivate_plugin(plugin_basename(__FILE__));
59
-        }
60
-    }
61
-    add_action('admin_notices', 'espresso_duplicate_plugin_error', 1);
58
+			espresso_deactivate_plugin(plugin_basename(__FILE__));
59
+		}
60
+	}
61
+	add_action('admin_notices', 'espresso_duplicate_plugin_error', 1);
62 62
 } else {
63
-    define('EE_MIN_PHP_VER_REQUIRED', '7.4.0');
64
-    if (! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) {
65
-        /**
66
-         * espresso_minimum_php_version_error
67
-         *
68
-         * @return void
69
-         */
70
-        function espresso_minimum_php_version_error()
71
-        {
72
-            ?>
63
+	define('EE_MIN_PHP_VER_REQUIRED', '7.4.0');
64
+	if (! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) {
65
+		/**
66
+		 * espresso_minimum_php_version_error
67
+		 *
68
+		 * @return void
69
+		 */
70
+		function espresso_minimum_php_version_error()
71
+		{
72
+			?>
73 73
 <div class="error">
74 74
 	<p>
75 75
 		<?php
76
-                    printf(
77
-                        esc_html__(
78
-                            'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.',
79
-                            'event_espresso'
80
-                        ),
81
-                        EE_MIN_PHP_VER_REQUIRED,
82
-                        PHP_VERSION,
83
-                        '<br/>',
84
-                        '<a href="https://www.php.net/downloads.php">https://php.net/downloads.php</a>'
85
-                    );
86
-                    ?>
76
+					printf(
77
+						esc_html__(
78
+							'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.',
79
+							'event_espresso'
80
+						),
81
+						EE_MIN_PHP_VER_REQUIRED,
82
+						PHP_VERSION,
83
+						'<br/>',
84
+						'<a href="https://www.php.net/downloads.php">https://php.net/downloads.php</a>'
85
+					);
86
+					?>
87 87
 	</p>
88 88
 </div>
89 89
 <?php
90
-            espresso_deactivate_plugin(plugin_basename(__FILE__));
91
-        }
90
+			espresso_deactivate_plugin(plugin_basename(__FILE__));
91
+		}
92 92
 
93
-        add_action('admin_notices', 'espresso_minimum_php_version_error', 1);
94
-    } else {
95
-        define('EVENT_ESPRESSO_MAIN_FILE', __FILE__);
93
+		add_action('admin_notices', 'espresso_minimum_php_version_error', 1);
94
+	} else {
95
+		define('EVENT_ESPRESSO_MAIN_FILE', __FILE__);
96 96
 
97
-        require_once __DIR__ . '/vendor/autoload.php';
97
+		require_once __DIR__ . '/vendor/autoload.php';
98 98
 
99
-        /**
100
-         * espresso_version
101
-         * Returns the plugin version
102
-         *
103
-         * @return string
104
-         */
105
-        function espresso_version(): string
106
-        {
107
-            return apply_filters('FHEE__espresso__espresso_version', '5.0.17.rc.000');
108
-        }
99
+		/**
100
+		 * espresso_version
101
+		 * Returns the plugin version
102
+		 *
103
+		 * @return string
104
+		 */
105
+		function espresso_version(): string
106
+		{
107
+			return apply_filters('FHEE__espresso__espresso_version', '5.0.17.rc.000');
108
+		}
109 109
 
110
-        /**
111
-         * espresso_plugin_activation
112
-         * adds a wp-option to indicate that EE has been activated via the WP admin plugins page
113
-         */
114
-        function espresso_plugin_activation()
115
-        {
116
-            update_option('ee_espresso_activation', true);
117
-            update_option('event-espresso-core_allow_tracking', 'no');
118
-            update_option('event-espresso-core_tracking_notice', 'hide');
119
-            // Run WP GraphQL activation callback
120
-            espressoLoadWpGraphQL();
121
-            graphql_activation_callback();
122
-        }
110
+		/**
111
+		 * espresso_plugin_activation
112
+		 * adds a wp-option to indicate that EE has been activated via the WP admin plugins page
113
+		 */
114
+		function espresso_plugin_activation()
115
+		{
116
+			update_option('ee_espresso_activation', true);
117
+			update_option('event-espresso-core_allow_tracking', 'no');
118
+			update_option('event-espresso-core_tracking_notice', 'hide');
119
+			// Run WP GraphQL activation callback
120
+			espressoLoadWpGraphQL();
121
+			graphql_activation_callback();
122
+		}
123 123
 
124
-        register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation');
124
+		register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation');
125 125
 
126
-        /**
127
-         * espresso_plugin_deactivation
128
-         */
129
-        function espresso_plugin_deactivation()
130
-        {
131
-            // Run WP GraphQL deactivation callback
132
-            espressoLoadWpGraphQL();
133
-            graphql_deactivation_callback();
134
-            delete_option('event-espresso-core_allow_tracking');
135
-            delete_option('event-espresso-core_tracking_notice');
136
-        }
137
-        register_deactivation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_deactivation');
126
+		/**
127
+		 * espresso_plugin_deactivation
128
+		 */
129
+		function espresso_plugin_deactivation()
130
+		{
131
+			// Run WP GraphQL deactivation callback
132
+			espressoLoadWpGraphQL();
133
+			graphql_deactivation_callback();
134
+			delete_option('event-espresso-core_allow_tracking');
135
+			delete_option('event-espresso-core_tracking_notice');
136
+		}
137
+		register_deactivation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_deactivation');
138 138
 
139
-        require_once __DIR__ . '/core/bootstrap_espresso.php';
140
-        bootstrap_espresso();
141
-    }
139
+		require_once __DIR__ . '/core/bootstrap_espresso.php';
140
+		bootstrap_espresso();
141
+	}
142 142
 }
143 143
 
144 144
 if (! function_exists('espresso_deactivate_plugin')) {
145
-    /**
146
-     *    deactivate_plugin
147
-     * usage:  espresso_deactivate_plugin( plugin_basename( __FILE__ ));
148
-     *
149
-     * @access public
150
-     * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file
151
-     * @return    void
152
-     */
153
-    function espresso_deactivate_plugin(string $plugin_basename = '')
154
-    {
155
-        if (! function_exists('deactivate_plugins')) {
156
-            require_once ABSPATH . 'wp-admin/includes/plugin.php';
157
-        }
158
-        unset($_GET['activate'], $_REQUEST['activate']);
159
-        deactivate_plugins($plugin_basename);
160
-    }
145
+	/**
146
+	 *    deactivate_plugin
147
+	 * usage:  espresso_deactivate_plugin( plugin_basename( __FILE__ ));
148
+	 *
149
+	 * @access public
150
+	 * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file
151
+	 * @return    void
152
+	 */
153
+	function espresso_deactivate_plugin(string $plugin_basename = '')
154
+	{
155
+		if (! function_exists('deactivate_plugins')) {
156
+			require_once ABSPATH . 'wp-admin/includes/plugin.php';
157
+		}
158
+		unset($_GET['activate'], $_REQUEST['activate']);
159
+		deactivate_plugins($plugin_basename);
160
+	}
161 161
 }
162 162
 
163 163
 
164 164
 if (! function_exists('espressoLoadWpGraphQL')) {
165
-    function espressoLoadWpGraphQL()
166
-    {
167
-        if (
168
-            ! class_exists('WPGraphQL')
169
-            && is_readable(__DIR__ . '/vendor/wp-graphql/wp-graphql/wp-graphql.php')
170
-        ) {
171
-            require_once __DIR__ . '/vendor/wp-graphql/wp-graphql/wp-graphql.php';
172
-        }
173
-    }
165
+	function espressoLoadWpGraphQL()
166
+	{
167
+		if (
168
+			! class_exists('WPGraphQL')
169
+			&& is_readable(__DIR__ . '/vendor/wp-graphql/wp-graphql/wp-graphql.php')
170
+		) {
171
+			require_once __DIR__ . '/vendor/wp-graphql/wp-graphql/wp-graphql.php';
172
+		}
173
+	}
174 174
 }
Please login to merge, or discard this patch.
PaymentMethods/PayPalCommerce/domain/Domain.php 1 patch
Indentation   +165 added lines, -165 removed lines patch added patch discarded remove patch
@@ -15,169 +15,169 @@
 block discarded – undo
15 15
  */
16 16
 class Domain
17 17
 {
18
-    /**
19
-     * Name of the extra meta key that stores this PM options as one meta.
20
-     */
21
-    public const META_KEY_PAYPAL_DATA = 'paypal_data';
22
-    /**
23
-     * Name of the extra meta key that stores this PM options as one meta.
24
-     */
25
-    public const META_KEY_PAYPAL_DATA_SANDBOX = 'paypal_data_sandbox';
26
-
27
-    /**
28
-     * Name of the extra meta that stores whether the credentials were for the sandbox or live mode.
29
-     */
30
-    public const META_KEY_SANDBOX_MODE = 'sandbox_mode';
31
-
32
-    /**
33
-     * Name of the extra meta that stores the PayPal Access Token that is used get onboarding URL.
34
-     */
35
-    public const META_KEY_ACCESS_TOKEN = 'access_token';
36
-
37
-    /**
38
-     * Name of the extra meta that stores the last request tracking ID.
39
-     */
40
-    public const META_KEY_TRACKING_ID = 'tracking_id';
41
-
42
-    /**
43
-     * Name of the extra meta that stores the Event Espresso PayPal Account's merchant id.
44
-     */
45
-    public const META_KEY_APP_ID = 'app_id';
46
-
47
-    /**
48
-     * Name of the extra meta that holds the seller client ID.
49
-     */
50
-    public const META_KEY_CLIENT_ID = 'client_id';
51
-
52
-    /**
53
-     * Name of the extra meta that holds the seller secret.
54
-     */
55
-    public const META_KEY_CLIENT_SECRET = 'client_secret';
56
-
57
-    /**
58
-     * Name of the extra meta that stores the expiration date of the client ID.
59
-     */
60
-    public const META_KEY_EXPIRES_IN = 'expires_in';
61
-
62
-    /**
63
-     * Name of the extra meta that holds the partner client ID.
64
-     */
65
-    public const META_KEY_PARTNER_CLIENT_ID = 'partner_client_id';
66
-
67
-    /**
68
-     * Name of the extra meta that holds the partner merchant ID.
69
-     */
70
-    public const META_KEY_PARTNER_MERCHANT_ID = 'partner_merchant_id';
71
-
72
-    /**
73
-     * Name of the extra meta that holds the seller merchant ID.
74
-     */
75
-    public const META_KEY_SELLER_MERCHANT_ID = 'merchantIdInPayPal';
76
-
77
-    /**
78
-     * Name of the extra meta that holds the onboarding URL.
79
-     */
80
-    public const META_KEY_ONBOARDING_URL = 'onboarding_url';
81
-
82
-    /**
83
-     * Name of the extra meta that holds the BN / request tracking code.
84
-     */
85
-    public const META_KEY_BN_CODE = 'bn_code';
86
-
87
-    /**
88
-     * Name of the extra meta that holds the last order details.
89
-     */
90
-    public const META_KEY_LAST_ORDER = 'last_order_details';
91
-
92
-    /**
93
-     * Name of the extra meta that stores the allowed PP checkout type selected by merchant while onboarding.
94
-     */
95
-    public const META_KEY_ALLOWED_CHECKOUT_TYPE = 'allowed_checkout_type';
96
-
97
-    /**
98
-     * Name of the extra meta that stores the PP checkout type selected by merchant after onboarding.
99
-     */
100
-    public const META_KEY_CHECKOUT_TYPE = 'checkout_type';
101
-
102
-    /**
103
-     * Name of the PayPal API parameter that holds the auth code.
104
-     */
105
-    public const API_KEY_AUTH_CODE = 'authCode';
106
-
107
-    /**
108
-     * Name of the PayPal API parameter that holds the client token.
109
-     */
110
-    public const API_KEY_CLIENT_TOKEN = 'client_token';
111
-
112
-     /**
113
-     * Name of the extra meta that holds the seller payer ID.
114
-     */
115
-    public const META_KEY_PAYER_ID = 'payer_id';
116
-
117
-    /**
118
-     * Name of the PayPal API parameter that holds the client token expiration time.
119
-     */
120
-    public const API_KEY_EXPIRES_IN = 'expires_in';
121
-
122
-    /**
123
-     * Name of the PayPal API parameter that holds the list of oAuth integrations related to the merchant.
124
-     */
125
-    public const API_PARAM_OAUTH_INTEGRATIONS = 'oauth_integrations';
126
-
127
-    /**
128
-     * Name of the PayPal API parameter that holds the list of third party permissions that were granted.
129
-     */
130
-    public const API_PARAM_PERMISSIONS_GRANTED = 'oauth_third_party';
131
-
132
-    /**
133
-     * Name of the PayPal API parameter that holds the bool of if the primary email was confirmed.
134
-     */
135
-    public const API_PARAM_PRIM_EMAIL_CONFIRMED = 'primary_email_confirmed';
136
-
137
-    /**
138
-     * Name of the PayPal API parameter that holds the bool of if email was confirmed.
139
-     */
140
-    public const API_PARAM_EMAIL_CONFIRMED = 'isEmailConfirmed';
141
-
142
-    /**
143
-     * Name of the PayPal API parameter that holds the partner ID.
144
-     */
145
-    public const API_PARAM_PARTNER_ID = 'merchantId';
146
-
147
-    /**
148
-     * Name of the PayPal API parameter that holds the merchant ID in the Track seller onboarding status request.
149
-     */
150
-    public const API_PARAM_TRACK_MERCHANT_ID = 'merchant_id';
151
-
152
-    /**
153
-     * Name of the PayPal API parameter that holds the payments_receivable status.
154
-     */
155
-    public const API_PARAM_PAYMENTS_RECEIVABLE = 'payments_receivable';
156
-
157
-    /**
158
-     * Name of the nonce used in the capture order request.
159
-     */
160
-    public const CAPTURE_ORDER_NONCE_NAME = 'eea_pp_commerce_capture_order_payment';
161
-
162
-    /**
163
-     * Name of the nonce used in the onboarding process.
164
-     */
165
-    public const NONCE_NAME_ONBOARDING_RETURN = 'eea_pp_commerce_onboarding_return';
166
-
167
-    /**
168
-     * Holds this payment method slug.
169
-     */
170
-    public const PM_SLUG = 'paypalcheckout';
171
-
172
-
173
-    /**
174
-     * Returns the base PayPal API URL.
175
-     *
176
-     * @param EE_Payment_Method $payment_method
177
-     * @return string
178
-     */
179
-    public static function getPayPalApiUrl(EE_Payment_Method $payment_method): string
180
-    {
181
-        return $payment_method->debug_mode() ? 'https://api-m.sandbox.paypal.com' : 'https://api-m.paypal.com';
182
-    }
18
+	/**
19
+	 * Name of the extra meta key that stores this PM options as one meta.
20
+	 */
21
+	public const META_KEY_PAYPAL_DATA = 'paypal_data';
22
+	/**
23
+	 * Name of the extra meta key that stores this PM options as one meta.
24
+	 */
25
+	public const META_KEY_PAYPAL_DATA_SANDBOX = 'paypal_data_sandbox';
26
+
27
+	/**
28
+	 * Name of the extra meta that stores whether the credentials were for the sandbox or live mode.
29
+	 */
30
+	public const META_KEY_SANDBOX_MODE = 'sandbox_mode';
31
+
32
+	/**
33
+	 * Name of the extra meta that stores the PayPal Access Token that is used get onboarding URL.
34
+	 */
35
+	public const META_KEY_ACCESS_TOKEN = 'access_token';
36
+
37
+	/**
38
+	 * Name of the extra meta that stores the last request tracking ID.
39
+	 */
40
+	public const META_KEY_TRACKING_ID = 'tracking_id';
41
+
42
+	/**
43
+	 * Name of the extra meta that stores the Event Espresso PayPal Account's merchant id.
44
+	 */
45
+	public const META_KEY_APP_ID = 'app_id';
46
+
47
+	/**
48
+	 * Name of the extra meta that holds the seller client ID.
49
+	 */
50
+	public const META_KEY_CLIENT_ID = 'client_id';
51
+
52
+	/**
53
+	 * Name of the extra meta that holds the seller secret.
54
+	 */
55
+	public const META_KEY_CLIENT_SECRET = 'client_secret';
56
+
57
+	/**
58
+	 * Name of the extra meta that stores the expiration date of the client ID.
59
+	 */
60
+	public const META_KEY_EXPIRES_IN = 'expires_in';
61
+
62
+	/**
63
+	 * Name of the extra meta that holds the partner client ID.
64
+	 */
65
+	public const META_KEY_PARTNER_CLIENT_ID = 'partner_client_id';
66
+
67
+	/**
68
+	 * Name of the extra meta that holds the partner merchant ID.
69
+	 */
70
+	public const META_KEY_PARTNER_MERCHANT_ID = 'partner_merchant_id';
71
+
72
+	/**
73
+	 * Name of the extra meta that holds the seller merchant ID.
74
+	 */
75
+	public const META_KEY_SELLER_MERCHANT_ID = 'merchantIdInPayPal';
76
+
77
+	/**
78
+	 * Name of the extra meta that holds the onboarding URL.
79
+	 */
80
+	public const META_KEY_ONBOARDING_URL = 'onboarding_url';
81
+
82
+	/**
83
+	 * Name of the extra meta that holds the BN / request tracking code.
84
+	 */
85
+	public const META_KEY_BN_CODE = 'bn_code';
86
+
87
+	/**
88
+	 * Name of the extra meta that holds the last order details.
89
+	 */
90
+	public const META_KEY_LAST_ORDER = 'last_order_details';
91
+
92
+	/**
93
+	 * Name of the extra meta that stores the allowed PP checkout type selected by merchant while onboarding.
94
+	 */
95
+	public const META_KEY_ALLOWED_CHECKOUT_TYPE = 'allowed_checkout_type';
96
+
97
+	/**
98
+	 * Name of the extra meta that stores the PP checkout type selected by merchant after onboarding.
99
+	 */
100
+	public const META_KEY_CHECKOUT_TYPE = 'checkout_type';
101
+
102
+	/**
103
+	 * Name of the PayPal API parameter that holds the auth code.
104
+	 */
105
+	public const API_KEY_AUTH_CODE = 'authCode';
106
+
107
+	/**
108
+	 * Name of the PayPal API parameter that holds the client token.
109
+	 */
110
+	public const API_KEY_CLIENT_TOKEN = 'client_token';
111
+
112
+	 /**
113
+	  * Name of the extra meta that holds the seller payer ID.
114
+	  */
115
+	public const META_KEY_PAYER_ID = 'payer_id';
116
+
117
+	/**
118
+	 * Name of the PayPal API parameter that holds the client token expiration time.
119
+	 */
120
+	public const API_KEY_EXPIRES_IN = 'expires_in';
121
+
122
+	/**
123
+	 * Name of the PayPal API parameter that holds the list of oAuth integrations related to the merchant.
124
+	 */
125
+	public const API_PARAM_OAUTH_INTEGRATIONS = 'oauth_integrations';
126
+
127
+	/**
128
+	 * Name of the PayPal API parameter that holds the list of third party permissions that were granted.
129
+	 */
130
+	public const API_PARAM_PERMISSIONS_GRANTED = 'oauth_third_party';
131
+
132
+	/**
133
+	 * Name of the PayPal API parameter that holds the bool of if the primary email was confirmed.
134
+	 */
135
+	public const API_PARAM_PRIM_EMAIL_CONFIRMED = 'primary_email_confirmed';
136
+
137
+	/**
138
+	 * Name of the PayPal API parameter that holds the bool of if email was confirmed.
139
+	 */
140
+	public const API_PARAM_EMAIL_CONFIRMED = 'isEmailConfirmed';
141
+
142
+	/**
143
+	 * Name of the PayPal API parameter that holds the partner ID.
144
+	 */
145
+	public const API_PARAM_PARTNER_ID = 'merchantId';
146
+
147
+	/**
148
+	 * Name of the PayPal API parameter that holds the merchant ID in the Track seller onboarding status request.
149
+	 */
150
+	public const API_PARAM_TRACK_MERCHANT_ID = 'merchant_id';
151
+
152
+	/**
153
+	 * Name of the PayPal API parameter that holds the payments_receivable status.
154
+	 */
155
+	public const API_PARAM_PAYMENTS_RECEIVABLE = 'payments_receivable';
156
+
157
+	/**
158
+	 * Name of the nonce used in the capture order request.
159
+	 */
160
+	public const CAPTURE_ORDER_NONCE_NAME = 'eea_pp_commerce_capture_order_payment';
161
+
162
+	/**
163
+	 * Name of the nonce used in the onboarding process.
164
+	 */
165
+	public const NONCE_NAME_ONBOARDING_RETURN = 'eea_pp_commerce_onboarding_return';
166
+
167
+	/**
168
+	 * Holds this payment method slug.
169
+	 */
170
+	public const PM_SLUG = 'paypalcheckout';
171
+
172
+
173
+	/**
174
+	 * Returns the base PayPal API URL.
175
+	 *
176
+	 * @param EE_Payment_Method $payment_method
177
+	 * @return string
178
+	 */
179
+	public static function getPayPalApiUrl(EE_Payment_Method $payment_method): string
180
+	{
181
+		return $payment_method->debug_mode() ? 'https://api-m.sandbox.paypal.com' : 'https://api-m.paypal.com';
182
+	}
183 183
 }
Please login to merge, or discard this patch.
PaymentMethods/PayPalCommerce/api/partners/TrackSellerOnboarding.php 2 patches
Indentation   +104 added lines, -104 removed lines patch added patch discarded remove patch
@@ -17,115 +17,115 @@
 block discarded – undo
17 17
  */
18 18
 class TrackSellerOnboarding extends PartnersApi
19 19
 {
20
-    /**
21
-     * Partner ID.
22
-     *
23
-     * @var string
24
-     */
25
-    protected string $partner_id;
20
+	/**
21
+	 * Partner ID.
22
+	 *
23
+	 * @var string
24
+	 */
25
+	protected string $partner_id;
26 26
 
27
-    /**
28
-     * Seller ID.
29
-     *
30
-     * @var string
31
-     */
32
-    protected string $seller_id;
27
+	/**
28
+	 * Seller ID.
29
+	 *
30
+	 * @var string
31
+	 */
32
+	protected string $seller_id;
33 33
 
34 34
 
35
-    /**
36
-     * TrackSellerOnboarding constructor.
37
-     *
38
-     * @param PayPalApi $api
39
-     * @param string    $partner_id
40
-     * @param string    $seller_id
41
-     * @param bool      $sandbox_mode
42
-     */
43
-    public function __construct(
44
-        PayPalApi $api,
45
-        string $partner_id,
46
-        string $seller_id,
47
-        bool $sandbox_mode
48
-    ) {
49
-        parent::__construct($api, $sandbox_mode);
50
-        $this->partner_id  = $partner_id;
51
-        $this->seller_id   = $seller_id;
52
-        $this->request_url = $this->request_url . "/{$partner_id}/merchant-integrations/{$seller_id}";
53
-    }
35
+	/**
36
+	 * TrackSellerOnboarding constructor.
37
+	 *
38
+	 * @param PayPalApi $api
39
+	 * @param string    $partner_id
40
+	 * @param string    $seller_id
41
+	 * @param bool      $sandbox_mode
42
+	 */
43
+	public function __construct(
44
+		PayPalApi $api,
45
+		string $partner_id,
46
+		string $seller_id,
47
+		bool $sandbox_mode
48
+	) {
49
+		parent::__construct($api, $sandbox_mode);
50
+		$this->partner_id  = $partner_id;
51
+		$this->seller_id   = $seller_id;
52
+		$this->request_url = $this->request_url . "/{$partner_id}/merchant-integrations/{$seller_id}";
53
+	}
54 54
 
55 55
 
56
-    /**
57
-     * Get the onboarding status and validate it.
58
-     *
59
-     * @return array
60
-     */
61
-    public function isValid(): array
62
-    {
63
-        // Send GET request.
64
-        $response = $this->api->sendRequest([], $this->request_url, 'GET');
65
-        return $this->validateStatus($response);
66
-    }
56
+	/**
57
+	 * Get the onboarding status and validate it.
58
+	 *
59
+	 * @return array
60
+	 */
61
+	public function isValid(): array
62
+	{
63
+		// Send GET request.
64
+		$response = $this->api->sendRequest([], $this->request_url, 'GET');
65
+		return $this->validateStatus($response);
66
+	}
67 67
 
68 68
 
69
-    /**
70
-     * Makes sure that we have received proper parameters and the status is valid.
71
-     *
72
-     * @param array $response
73
-     * @return array
74
-     */
75
-    public function validateStatus(array $response): array
76
-    {
77
-        if (! empty($response['error'])) {
78
-            return $response;
79
-        }
80
-        if (! empty($response['name']) && ! empty($response['message'])) {
81
-            return ['error' => $response['name'], 'message' => $response['message']];
82
-        }
83
-        // Check the data we received.
84
-        if (
85
-            empty($response[ Domain::API_PARAM_TRACK_MERCHANT_ID ])
86
-            || ! isset($response[ Domain::API_PARAM_PAYMENTS_RECEIVABLE ])
87
-            || ! isset($response[ Domain::API_PARAM_PRIM_EMAIL_CONFIRMED ])
88
-            || ! isset($response[ Domain::API_PARAM_OAUTH_INTEGRATIONS ])
89
-        ) {
90
-            $err_msg = esc_html__('Missing required data for validating the onboarding status.', 'event_espresso');
91
-            PayPalLogger::errorLog($err_msg, $response);
92
-            return ['error' => 'ONBOARDING_MISSING_REQUIRED_DATA', 'message' => $err_msg];
93
-        }
94
-        // Now validate the onboarding status.
95
-        if (! $response[ Domain::API_PARAM_PAYMENTS_RECEIVABLE ]) {
96
-            $err_msg = esc_html__(
97
-                'Your Account has been limited by PayPal. Please check your PayPal account inbox for an email from PayPal to determine the next steps for this.',
98
-                'event_espresso'
99
-            );
100
-            PayPalLogger::errorLog($err_msg, $response);
101
-            return ['error' => 'ONBOARDING_LIMITED_BY_PAYPAL', 'message' => $err_msg];
102
-        }
103
-        if (! $response[ Domain::API_PARAM_PRIM_EMAIL_CONFIRMED ]) {
104
-            $err_msg = esc_html__('Email address not confirmed. Please confirm your email address.', 'event_espresso');
105
-            PayPalLogger::errorLog($err_msg, $response);
106
-            return ['error' => 'ONBOARDING_CONFIRM_EMAIL', 'message' => $err_msg];
107
-        }
108
-        if (empty($response[ Domain::API_PARAM_OAUTH_INTEGRATIONS ])) {
109
-            $permissions_valid = false;
110
-            // Look for the granted permissions.
111
-            foreach ($response[ Domain::API_PARAM_OAUTH_INTEGRATIONS ] as $integration_type) {
112
-                if (! empty($integration_type[ Domain::API_PARAM_PERMISSIONS_GRANTED ])) {
113
-                    $permissions_valid = true;
114
-                }
115
-            }
116
-            // Did we find any ? If no - oauth not valid.
117
-            if (! $permissions_valid) {
118
-                $err_msg = esc_html__(
119
-                    'Not all required permissions were granted. Please allow all permissions while onboarding.',
120
-                    'event_espresso'
121
-                );
122
-                PayPalLogger::errorLog($err_msg, $response);
123
-                return ['error' => 'ONBOARDING_PERMISSIONS_NOT_GRANTED', 'message' => $err_msg];
124
-            }
125
-        }
126
-        return [
127
-            'valid'    => true,
128
-            'response' => $response,
129
-        ];
130
-    }
69
+	/**
70
+	 * Makes sure that we have received proper parameters and the status is valid.
71
+	 *
72
+	 * @param array $response
73
+	 * @return array
74
+	 */
75
+	public function validateStatus(array $response): array
76
+	{
77
+		if (! empty($response['error'])) {
78
+			return $response;
79
+		}
80
+		if (! empty($response['name']) && ! empty($response['message'])) {
81
+			return ['error' => $response['name'], 'message' => $response['message']];
82
+		}
83
+		// Check the data we received.
84
+		if (
85
+			empty($response[ Domain::API_PARAM_TRACK_MERCHANT_ID ])
86
+			|| ! isset($response[ Domain::API_PARAM_PAYMENTS_RECEIVABLE ])
87
+			|| ! isset($response[ Domain::API_PARAM_PRIM_EMAIL_CONFIRMED ])
88
+			|| ! isset($response[ Domain::API_PARAM_OAUTH_INTEGRATIONS ])
89
+		) {
90
+			$err_msg = esc_html__('Missing required data for validating the onboarding status.', 'event_espresso');
91
+			PayPalLogger::errorLog($err_msg, $response);
92
+			return ['error' => 'ONBOARDING_MISSING_REQUIRED_DATA', 'message' => $err_msg];
93
+		}
94
+		// Now validate the onboarding status.
95
+		if (! $response[ Domain::API_PARAM_PAYMENTS_RECEIVABLE ]) {
96
+			$err_msg = esc_html__(
97
+				'Your Account has been limited by PayPal. Please check your PayPal account inbox for an email from PayPal to determine the next steps for this.',
98
+				'event_espresso'
99
+			);
100
+			PayPalLogger::errorLog($err_msg, $response);
101
+			return ['error' => 'ONBOARDING_LIMITED_BY_PAYPAL', 'message' => $err_msg];
102
+		}
103
+		if (! $response[ Domain::API_PARAM_PRIM_EMAIL_CONFIRMED ]) {
104
+			$err_msg = esc_html__('Email address not confirmed. Please confirm your email address.', 'event_espresso');
105
+			PayPalLogger::errorLog($err_msg, $response);
106
+			return ['error' => 'ONBOARDING_CONFIRM_EMAIL', 'message' => $err_msg];
107
+		}
108
+		if (empty($response[ Domain::API_PARAM_OAUTH_INTEGRATIONS ])) {
109
+			$permissions_valid = false;
110
+			// Look for the granted permissions.
111
+			foreach ($response[ Domain::API_PARAM_OAUTH_INTEGRATIONS ] as $integration_type) {
112
+				if (! empty($integration_type[ Domain::API_PARAM_PERMISSIONS_GRANTED ])) {
113
+					$permissions_valid = true;
114
+				}
115
+			}
116
+			// Did we find any ? If no - oauth not valid.
117
+			if (! $permissions_valid) {
118
+				$err_msg = esc_html__(
119
+					'Not all required permissions were granted. Please allow all permissions while onboarding.',
120
+					'event_espresso'
121
+				);
122
+				PayPalLogger::errorLog($err_msg, $response);
123
+				return ['error' => 'ONBOARDING_PERMISSIONS_NOT_GRANTED', 'message' => $err_msg];
124
+			}
125
+		}
126
+		return [
127
+			'valid'    => true,
128
+			'response' => $response,
129
+		];
130
+	}
131 131
 }
Please login to merge, or discard this patch.
Spacing   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -49,7 +49,7 @@  discard block
 block discarded – undo
49 49
         parent::__construct($api, $sandbox_mode);
50 50
         $this->partner_id  = $partner_id;
51 51
         $this->seller_id   = $seller_id;
52
-        $this->request_url = $this->request_url . "/{$partner_id}/merchant-integrations/{$seller_id}";
52
+        $this->request_url = $this->request_url."/{$partner_id}/merchant-integrations/{$seller_id}";
53 53
     }
54 54
 
55 55
 
@@ -74,25 +74,25 @@  discard block
 block discarded – undo
74 74
      */
75 75
     public function validateStatus(array $response): array
76 76
     {
77
-        if (! empty($response['error'])) {
77
+        if ( ! empty($response['error'])) {
78 78
             return $response;
79 79
         }
80
-        if (! empty($response['name']) && ! empty($response['message'])) {
80
+        if ( ! empty($response['name']) && ! empty($response['message'])) {
81 81
             return ['error' => $response['name'], 'message' => $response['message']];
82 82
         }
83 83
         // Check the data we received.
84 84
         if (
85
-            empty($response[ Domain::API_PARAM_TRACK_MERCHANT_ID ])
86
-            || ! isset($response[ Domain::API_PARAM_PAYMENTS_RECEIVABLE ])
87
-            || ! isset($response[ Domain::API_PARAM_PRIM_EMAIL_CONFIRMED ])
88
-            || ! isset($response[ Domain::API_PARAM_OAUTH_INTEGRATIONS ])
85
+            empty($response[Domain::API_PARAM_TRACK_MERCHANT_ID])
86
+            || ! isset($response[Domain::API_PARAM_PAYMENTS_RECEIVABLE])
87
+            || ! isset($response[Domain::API_PARAM_PRIM_EMAIL_CONFIRMED])
88
+            || ! isset($response[Domain::API_PARAM_OAUTH_INTEGRATIONS])
89 89
         ) {
90 90
             $err_msg = esc_html__('Missing required data for validating the onboarding status.', 'event_espresso');
91 91
             PayPalLogger::errorLog($err_msg, $response);
92 92
             return ['error' => 'ONBOARDING_MISSING_REQUIRED_DATA', 'message' => $err_msg];
93 93
         }
94 94
         // Now validate the onboarding status.
95
-        if (! $response[ Domain::API_PARAM_PAYMENTS_RECEIVABLE ]) {
95
+        if ( ! $response[Domain::API_PARAM_PAYMENTS_RECEIVABLE]) {
96 96
             $err_msg = esc_html__(
97 97
                 'Your Account has been limited by PayPal. Please check your PayPal account inbox for an email from PayPal to determine the next steps for this.',
98 98
                 'event_espresso'
@@ -100,21 +100,21 @@  discard block
 block discarded – undo
100 100
             PayPalLogger::errorLog($err_msg, $response);
101 101
             return ['error' => 'ONBOARDING_LIMITED_BY_PAYPAL', 'message' => $err_msg];
102 102
         }
103
-        if (! $response[ Domain::API_PARAM_PRIM_EMAIL_CONFIRMED ]) {
103
+        if ( ! $response[Domain::API_PARAM_PRIM_EMAIL_CONFIRMED]) {
104 104
             $err_msg = esc_html__('Email address not confirmed. Please confirm your email address.', 'event_espresso');
105 105
             PayPalLogger::errorLog($err_msg, $response);
106 106
             return ['error' => 'ONBOARDING_CONFIRM_EMAIL', 'message' => $err_msg];
107 107
         }
108
-        if (empty($response[ Domain::API_PARAM_OAUTH_INTEGRATIONS ])) {
108
+        if (empty($response[Domain::API_PARAM_OAUTH_INTEGRATIONS])) {
109 109
             $permissions_valid = false;
110 110
             // Look for the granted permissions.
111
-            foreach ($response[ Domain::API_PARAM_OAUTH_INTEGRATIONS ] as $integration_type) {
112
-                if (! empty($integration_type[ Domain::API_PARAM_PERMISSIONS_GRANTED ])) {
111
+            foreach ($response[Domain::API_PARAM_OAUTH_INTEGRATIONS] as $integration_type) {
112
+                if ( ! empty($integration_type[Domain::API_PARAM_PERMISSIONS_GRANTED])) {
113 113
                     $permissions_valid = true;
114 114
                 }
115 115
             }
116 116
             // Did we find any ? If no - oauth not valid.
117
-            if (! $permissions_valid) {
117
+            if ( ! $permissions_valid) {
118 118
                 $err_msg = esc_html__(
119 119
                     'Not all required permissions were granted. Please allow all permissions while onboarding.',
120 120
                     'event_espresso'
Please login to merge, or discard this patch.
PaymentMethods/PayPalCommerce/modules/EED_PayPalOnboard.module.php 2 patches
Indentation   +658 added lines, -658 removed lines patch added patch discarded remove patch
@@ -20,662 +20,662 @@
 block discarded – undo
20 20
  */
21 21
 class EED_PayPalOnboard extends EED_Module
22 22
 {
23
-    /**
24
-     * @return EED_Module
25
-     * @throws EE_Error
26
-     * @throws ReflectionException
27
-     */
28
-    public static function instance(): EED_Module
29
-    {
30
-        return parent::get_instance(__CLASS__);
31
-    }
32
-
33
-
34
-    /**
35
-     * Run - initial module setup.
36
-     *
37
-     * @param WP $WP
38
-     * @return void
39
-     */
40
-    public function run($WP)
41
-    {
42
-    }
43
-
44
-
45
-    /**
46
-     * For hooking into EE Admin Core and other modules.
47
-     *
48
-     * @return void
49
-     */
50
-    public static function set_hooks_admin(): void
51
-    {
52
-        if (DbStatus::isOnline()) {
53
-            // Get onboarding URL.
54
-            add_action('wp_ajax_eeaPpGetOnboardingUrl', [__CLASS__, 'getOnboardingUrl']);
55
-            // Catch the return/redirect from PayPal onboarding page.
56
-            add_action('init', [__CLASS__, 'updateOnboardingStatus'], 10);
57
-            // Return the connection/onboard status.
58
-            add_action('wp_ajax_eeaPpGetOnboardStatus', [__CLASS__, 'getOnboardStatus']);
59
-            // Revoke access.
60
-            add_action('wp_ajax_eeaPpOffboard', [__CLASS__, 'offboard']);
61
-            // Admin notice.
62
-            add_action('admin_init', [__CLASS__, 'adminNotice']);
63
-        }
64
-    }
65
-
66
-
67
-    /**
68
-     * Get the onboarding URL.
69
-     * (AJAX)
70
-     *
71
-     * @return void
72
-     */
73
-    public static function getOnboardingUrl(): void
74
-    {
75
-        $signup_link = '';
76
-        try {
77
-            $paypal_pm = EED_PayPalCommerce::getPaymentMethod();
78
-            if (! $paypal_pm instanceof EE_Payment_Method) {
79
-                PayPalLogger::errorLogAndExit(
80
-                    esc_html__('No payment method.', 'event_espresso'),
81
-                    EED_Module::getRequest()->postParams(),
82
-                    $paypal_pm
83
-                );
84
-            }
85
-            PayPalExtraMetaManager::updateDebugMode($paypal_pm, EED_Module::getRequest()->postParams());
86
-            // $signup_link   = PayPalExtraMetaManager::getPmOption($paypal_pm, Domain::META_KEY_ONBOARDING_URL);
87
-            // $token_expired = EED_PayPalOnboard::partnerAccessTokenExpired($paypal_pm);
88
-            // if (! $signup_link || $token_expired) {
89
-            $signup_link = EED_PayPalOnboard::requestOnboardingUrl($paypal_pm);
90
-            // }
91
-            if (! $signup_link) {
92
-                $err_msg = esc_html__('Error! Could not generate a sign-up link.', 'event_espresso');
93
-                PayPalLogger::errorLogAndExit($err_msg, ['signup_link' => $signup_link], $paypal_pm);
94
-            }
95
-            PayPalExtraMetaManager::savePmOption($paypal_pm, Domain::META_KEY_ONBOARDING_URL, $signup_link);
96
-        } catch (Exception $exception) {
97
-            PayPalLogger::errorLogAndExit($exception->getMessage());
98
-        }
99
-        // Is it empty (can happen if we didn't get the URL through the API).
100
-        $signup_link = $signup_link ? $signup_link . '?&displayMode=minibrowser' : '#';
101
-        wp_send_json(
102
-            [
103
-                'signup_link' => $signup_link,
104
-            ]
105
-        );
106
-    }
107
-
108
-
109
-    /**
110
-     * Request the sign-up link from PayPal.
111
-     *
112
-     * @param EE_Payment_Method $paypal_pm
113
-     * @param bool              $one_time_request
114
-     * @return string
115
-     * @throws EE_Error
116
-     * @throws Exception
117
-     */
118
-    public static function requestOnboardingUrl(EE_Payment_Method $paypal_pm, bool $one_time_request = false): string
119
-    {
120
-        $signup_link = '';
121
-        // Get the access token.
122
-        $access_token = EED_PayPalOnboard::getPartnerAccessToken($paypal_pm);
123
-        if (! $access_token) {
124
-            $err_msg = esc_html__('Error! No access token.', 'event_espresso');
125
-            PayPalLogger::errorLog($err_msg, ['access_token' => $access_token], $paypal_pm);
126
-            return '';
127
-        }
128
-        // Request the access token.
129
-        $body_params = EED_PayPalOnboard::signupLinkRequestBody($paypal_pm);
130
-        $bn_code     = PayPalExtraMetaManager::getPmOption($paypal_pm, Domain::META_KEY_BN_CODE);
131
-        $post_params = [
132
-            'method'  => 'POST',
133
-            'headers' => [
134
-                'User-Agent'                    => sanitize_text_field($_SERVER['HTTP_USER_AGENT']),
135
-                'Content-Type'                  => 'application/json',
136
-                'Authorization'                 => 'Bearer ' . $access_token,
137
-                'PayPal-Partner-Attribution-Id' => $bn_code,
138
-            ],
139
-            'body'    => $body_params,
140
-        ];
141
-        $request_url = Domain::getPayPalApiUrl($paypal_pm) . '/v2/customer/partner-referrals';
142
-        $response    = EED_PayPalOnboard::sendRequest($paypal_pm, $request_url, $post_params);
143
-        // Check the data we received.
144
-        if (isset($response['error']) || empty($response['links'])) {
145
-            // Did the original access token get replaced by any chance ?
146
-            if (! $one_time_request
147
-                && ! empty($response['message'])
148
-                && $response['message'] === 'Access Token not found in cache'
149
-            ) {
150
-                // Clear all PM metadata and try getting the access token One more time.
151
-                PayPalExtraMetaManager::deleteAllData($paypal_pm);
152
-                return EED_PayPalOnboard::requestOnboardingUrl($paypal_pm, true);
153
-            }
154
-            $err_msg = esc_html__('Incoming sign-up link parameter validation failed.', 'event_espresso');
155
-            PayPalLogger::errorLog($err_msg, $response, $paypal_pm);
156
-            return '';
157
-        }
158
-        // Now retrieve that sign-up link.
159
-        foreach ($response['links'] as $link) {
160
-            if ($link['rel'] === 'action_url') {
161
-                $signup_link = $link['href'] ?? '';
162
-            }
163
-        }
164
-        return $signup_link;
165
-    }
166
-
167
-
168
-    /**
169
-     * Get the return URL.
170
-     *
171
-     * @param EE_Payment_Method $paypal_pm
172
-     * @return string
173
-     * @throws Exception
174
-     */
175
-    public static function signupLinkRequestBody(EE_Payment_Method $paypal_pm): string
176
-    {
177
-        $identifier_string = new OneTimeString($paypal_pm->debug_mode());
178
-        $tracking_id       = $identifier_string->value();
179
-        $request           = LoaderFactory::getLoader()->getShared(RequestInterface::class);
180
-        $checkout_type     = $request->getRequestParam('checkout_type', 'EXPRESS_CHECKOUT', DataType::STRING);
181
-        // Save the identifier for future use.
182
-        PayPalExtraMetaManager::savePmOption($paypal_pm, Domain::META_KEY_TRACKING_ID, $tracking_id);
183
-        // Assemble the return URL.
184
-        $return_url = EED_PayPalOnboard::getReturnUrl($paypal_pm);
185
-        return json_encode([
186
-            'tracking_id'             => $tracking_id,
187
-            'operations'              => [
188
-                [
189
-                    'operation'                  => 'API_INTEGRATION',
190
-                    'api_integration_preference' => [
191
-                        'rest_api_integration' => [
192
-                            'integration_method'  => 'PAYPAL',
193
-                            'integration_type'    => 'THIRD_PARTY',
194
-                            'third_party_details' => [
195
-                                'features' => ['PAYMENT', 'REFUND'],
196
-                            ],
197
-                        ],
198
-                    ],
199
-                ],
200
-            ],
201
-            'products'                => [$checkout_type],
202
-            'legal_consents'          => [
203
-                [
204
-                    'type'    => 'SHARE_DATA_CONSENT',
205
-                    'granted' => true,
206
-                ],
207
-            ],
208
-            'partner_config_override' => [
209
-                'return_url' => $return_url,
210
-            ],
211
-        ]);
212
-    }
213
-
214
-
215
-    /**
216
-     * Get the return URL.
217
-     *
218
-     * @param EE_Payment_Method $paypal_pm
219
-     * @return string
220
-     * @throws EE_Error
221
-     * @throws ReflectionException
222
-     */
223
-    public static function getReturnUrl(EE_Payment_Method $paypal_pm): string
224
-    {
225
-        $wp_nonce = EED_Module::getRequest()->getRequestParam('wp_nonce');
226
-        $nonce    = wp_create_nonce(Domain::NONCE_NAME_ONBOARDING_RETURN);
227
-        return add_query_arg(
228
-            [
229
-                'page'                        => 'espresso_payment_settings',
230
-                'webhook_action'              => 'eepPpcMerchantOnboard',
231
-                'payment_method'              => $paypal_pm->slug(),
232
-                '_wpnonce'                    => $wp_nonce,
233
-                'nonce'                       => $nonce,
234
-                Domain::META_KEY_SANDBOX_MODE => $paypal_pm->debug_mode() ? '1' : '0',
235
-            ],
236
-            admin_url('admin.php')
237
-        );
238
-    }
239
-
240
-
241
-    /**
242
-     * Redirect to the payment method (PP) settings home page.
243
-     *
244
-     * @return void
245
-     */
246
-    public static function redirectToPmSettingsHome(): void
247
-    {
248
-        $get_params = EED_Module::getRequest()->getParams();
249
-        if (empty($get_params['payment_method'])) {
250
-            // Simply do not redirect.
251
-            return;
252
-        }
253
-        $args_to_add = [
254
-            'page'           => 'espresso_payment_settings',
255
-            'payment_method' => $get_params['payment_method'],
256
-        ];
257
-        if (isset($get_params['sandbox_mode'])) {
258
-            $args_to_add[ Domain::META_KEY_SANDBOX_MODE ] = $get_params['sandbox_mode'];
259
-        }
260
-        $home_url = add_query_arg($args_to_add, admin_url('admin.php'));
261
-        wp_redirect($home_url);
262
-        exit;
263
-    }
264
-
265
-
266
-    /**
267
-     * Check user’s onboarding status.
268
-     * This will handle the user return from the auth page and also check the status via the API.
269
-     *
270
-     * @return void
271
-     * @throws EE_Error
272
-     * @throws ReflectionException
273
-     */
274
-    public static function updateOnboardingStatus(): void
275
-    {
276
-        // Check if this is the webhook from PayPal.
277
-        if (! isset($_GET['webhook_action'], $_GET['nonce'])
278
-            || $_GET['webhook_action'] !== 'eepPpcMerchantOnboard'
279
-        ) {
280
-            return;  // Ignore.
281
-        }
282
-        $get_params = EED_Module::getRequest()->getParams();
283
-        // Get the payment method.
284
-        $paypal_pm = EED_PayPalCommerce::getPaymentMethod();
285
-        // Check the response (GET) parameters.
286
-        if (! EED_PayPalOnboard::onboardingStatusResponseValid($get_params, $paypal_pm)) {
287
-            // Missing parameters. Can't proceed.
288
-            PayPalLogger::errorLog(
289
-                esc_html__('Missing required onboarding parameters.', 'event_espresso'),
290
-                $get_params,
291
-                $paypal_pm
292
-            );
293
-            EED_PayPalOnboard::redirectToPmSettingsHome();
294
-            return;
295
-        }
296
-        // Check on the onboarding status (recommended by PP).
297
-        $onboarding_status = EED_PayPalOnboard::trackSellerOnboarding(
298
-            $paypal_pm,
299
-            $get_params[ Domain::META_KEY_SELLER_MERCHANT_ID ]
300
-        );
301
-        if (! isset($onboarding_status['valid']) || ! $onboarding_status['valid']) {
302
-            PayPalLogger::errorLog(
303
-                $onboarding_status['message'],
304
-                array_merge($get_params, $onboarding_status),
305
-                $paypal_pm
306
-            );
307
-            EED_PayPalOnboard::redirectToPmSettingsHome();
308
-            return;
309
-        }
310
-        // Start saving the setup and info.
311
-        PayPalExtraMetaManager::parseAndSaveOptions($paypal_pm, $onboarding_status);
312
-        // Save the credentials.
313
-        PayPalExtraMetaManager::saveSellerApiCredentials($paypal_pm, $get_params);
314
-        // If onboarded successfully, remove the onboarding URL.
315
-        PayPalExtraMetaManager::deletePmOption($paypal_pm, Domain::META_KEY_ONBOARDING_URL);
316
-        // Also clen GET params by redirecting, because PP auto redirects to the return_url on closing the onboarding window.
317
-        EED_PayPalOnboard::redirectToPmSettingsHome();
318
-    }
319
-
320
-
321
-    /**
322
-     * Check if all required parameters for the onboarding status check are present.
323
-     *
324
-     * @param array $data
325
-     * @param mixed $paypal_pm
326
-     * @return bool
327
-     */
328
-    public static function onboardingStatusResponseValid(array $data, $paypal_pm): bool
329
-    {
330
-        // Check that we have all the required parameters and the nonce is ok.
331
-        if ($paypal_pm instanceof EE_Payment_Method
332
-            && wp_verify_nonce($data['nonce'], Domain::NONCE_NAME_ONBOARDING_RETURN)
333
-            && ! empty($data[ Domain::API_PARAM_PARTNER_ID ])
334
-            && ! empty($data[ Domain::META_KEY_SELLER_MERCHANT_ID ])
335
-            && isset($data[ Domain::API_PARAM_EMAIL_CONFIRMED ])
336
-        ) {
337
-            return true;
338
-        }
339
-        return false;
340
-    }
341
-
342
-
343
-    /**
344
-     * Get partner access token.
345
-     *
346
-     * @param EE_Payment_Method $paypal_pm
347
-     * @return string
348
-     * @throws EE_Error
349
-     * @throws ReflectionException
350
-     */
351
-    public static function getPartnerAccessToken(EE_Payment_Method $paypal_pm): string
352
-    {
353
-        // Do we have it saved ?
354
-        $access_token = PayPalExtraMetaManager::getPmOption($paypal_pm, Domain::META_KEY_ACCESS_TOKEN);
355
-        $expired      = EED_PayPalOnboard::partnerAccessTokenExpired($paypal_pm);
356
-        // If we don't have it, request/update it.
357
-        if (! $access_token || $expired) {
358
-            return EED_PayPalOnboard::requestPartnerAccessToken($paypal_pm);
359
-        }
360
-        // Access token is saved as encrypted, so return decrypted.
361
-        return $access_token;
362
-    }
363
-
364
-
365
-    /**
366
-     * Get partner access token.
367
-     *
368
-     * @param EE_Payment_Method $paypal_pm
369
-     * @return bool
370
-     */
371
-    public static function partnerAccessTokenExpired(EE_Payment_Method $paypal_pm): bool
372
-    {
373
-        $expires_at = (int) PayPalExtraMetaManager::getPmOption($paypal_pm, Domain::META_KEY_EXPIRES_IN);
374
-        if (! $expires_at) {
375
-            return true;
376
-        }
377
-        // Validate the token expiration date.
378
-        $now          = time();
379
-        $minutes_left = round(($expires_at - $now) / 60);
380
-        // Count as expired if less than 60 minutes till expiration left.
381
-        if ($minutes_left <= 60) {
382
-            return true;
383
-        }
384
-        return false;
385
-    }
386
-
387
-
388
-    /**
389
-     * Request the partner access token from PayPal and save/update it.
390
-     *
391
-     * @param EE_Payment_Method $paypal_pm
392
-     * @return string
393
-     * @throws EE_Error
394
-     * @throws ReflectionException
395
-     */
396
-    public static function requestPartnerAccessToken(EE_Payment_Method $paypal_pm): string
397
-    {
398
-        $nonce = wp_create_nonce('eea_pp_commerce_get_access_token');
399
-        // Request the access token.
400
-        $post_args = [
401
-            'method' => 'POST',
402
-            'body'   => [
403
-                'nonce'                       => $nonce,
404
-                'api_version'                 => 'v1',
405
-                Domain::META_KEY_SANDBOX_MODE => $paypal_pm->debug_mode() ? '1' : '0',
406
-            ],
407
-        ];
408
-        if (defined('LOCAL_MIDDLEMAN_SERVER')) {
409
-            $post_args['sslverify'] = false;
410
-        }
411
-        $post_url = EED_PayPalOnboard::getMiddlemanBaseUrl($paypal_pm) . 'get_token';
412
-        $response = EED_PayPalOnboard::sendRequest($paypal_pm, $post_url, $post_args);
413
-        if (isset($response['error'])) {
414
-            return '';
415
-        }
416
-        // Check the data we received.
417
-        if (! EED_PayPalOnboard::partnerTokenResponseValid($response, $paypal_pm)) {
418
-            return '';
419
-        }
420
-        // If we are here all seems to be ok. Save the token and it's data.
421
-        $saved = PayPalExtraMetaManager::savePartnerAccessToken($paypal_pm, $response);
422
-        if (! $saved) {
423
-            return '';
424
-        }
425
-        return $response['access_token'];
426
-    }
427
-
428
-
429
-    /**
430
-     * Request seller onboarding status from PayPal.
431
-     *
432
-     * @param EE_Payment_Method $paypal_pm
433
-     * @param string            $merchant_id
434
-     * @return array
435
-     */
436
-    public static function trackSellerOnboarding(EE_Payment_Method $paypal_pm, string $merchant_id): array
437
-    {
438
-        $track_onboarding = EED_PayPalOnboard::getTrackOnboardingApi($paypal_pm, $merchant_id);
439
-        if (! $track_onboarding instanceof TrackSellerOnboarding) {
440
-            $err_msg = esc_html__('Failed to track seller onboarding.', 'event_espresso');
441
-            return ['error' => 'TRACK_ONBOARDING_FAILED', 'message' => $err_msg];
442
-        }
443
-        return $track_onboarding->isValid();
444
-    }
445
-
446
-
447
-    /**
448
-     * Returns the Track Seller Onboarding API.
449
-     *
450
-     * @param EE_Payment_Method $paypal_pm
451
-     * @param string            $merchant_id
452
-     * @return TrackSellerOnboarding|null
453
-     * @throws EE_Error
454
-     * @throws ReflectionException
455
-     */
456
-    public static function getTrackOnboardingApi(
457
-        EE_Payment_Method $paypal_pm,
458
-        string            $merchant_id
459
-    ): ?TrackSellerOnboarding {
460
-        $partner_id = PayPalExtraMetaManager::getPmOption($paypal_pm, Domain::META_KEY_PARTNER_MERCHANT_ID);
461
-        $paypal_api = EED_PayPalCommerce::getPayPalApi($paypal_pm);
462
-        if (! $paypal_api instanceof PayPalApi || ! $partner_id) {
463
-            return null;
464
-        }
465
-        return new TrackSellerOnboarding($paypal_api, $partner_id, $merchant_id, $paypal_pm->debug_mode());
466
-    }
467
-
468
-
469
-    /**
470
-     * Check the onboard status and return the result.
471
-     * (AJAX)
472
-     *
473
-     * @return void
474
-     */
475
-    public static function getOnboardStatus(): void
476
-    {
477
-        $paypal_pm = EED_PayPalCommerce::getPaymentMethod();
478
-        if (! $paypal_pm instanceof EE_Payment_Method) {
479
-            $err_msg = esc_html__('Could not specify the payment method.', 'event_espresso');
480
-            PayPalLogger::errorLog($err_msg, EED_Module::getRequest()->postParams(), $paypal_pm);
481
-            wp_send_json(['on_board' => false]);
482
-        }
483
-        try {
484
-            $seller_id = PayPalExtraMetaManager::getPmOption($paypal_pm, Domain::META_KEY_SELLER_MERCHANT_ID) ?? '--';
485
-        } catch (Exception $e) {
486
-            $seller_id = '--';
487
-        }
488
-        wp_send_json(
489
-            [
490
-                'on_board'  => EED_PayPalOnboard::isOnboard($paypal_pm),
491
-                'seller_id' => $seller_id,
492
-            ]
493
-        );
494
-    }
495
-
496
-
497
-    /**
498
-     * De-authorize the seller. Remove all API credentials.
499
-     * (AJAX)
500
-     *
501
-     * @return void
502
-     */
503
-    public static function offboard(): void
504
-    {
505
-        $paypal_pm = EED_PayPalCommerce::getPaymentMethod();
506
-        if (! $paypal_pm instanceof EE_Payment_Method) {
507
-            wp_send_json([
508
-                'error'   => 'INVALID_PM',
509
-                'message' => esc_html__(
510
-                    'Invalid payment method. Please refresh the page and try again.',
511
-                    'event_espresso'
512
-                ),
513
-            ]);
514
-        }
515
-        PayPalExtraMetaManager::deleteAllData($paypal_pm);
516
-        wp_send_json(['success' => true]);
517
-    }
518
-
519
-
520
-    /**
521
-     * Checks if already onboard.
522
-     *
523
-     * @param EE_Payment_Method $payment_method
524
-     * @return boolean
525
-     */
526
-    public static function isOnboard(EE_Payment_Method $payment_method): bool
527
-    {
528
-        $pp_meta_data = PayPalExtraMetaManager::getAllData($payment_method);
529
-        return
530
-            // onborded with a third party integration ?
531
-            (! empty($pp_meta_data[ Domain::META_KEY_SELLER_MERCHANT_ID ])
532
-                && ! empty($pp_meta_data[ Domain::META_KEY_ACCESS_TOKEN ])
533
-            )
534
-            // or with the first party integration ?
535
-            || (! empty($pp_meta_data[ Domain::META_KEY_CLIENT_ID ])
536
-                && ! empty($pp_meta_data[ Domain::META_KEY_CLIENT_SECRET ])
537
-                && ! empty($pp_meta_data[ Domain::META_KEY_PAYER_ID ])
538
-            );
539
-    }
540
-
541
-
542
-    /**
543
-     * Send a request and return a decoded response body.
544
-     *
545
-     * @param EE_Payment_Method $paypal_pm
546
-     * @param string            $request_url
547
-     * @param array             $request_args
548
-     * @return array
549
-     */
550
-    public static function sendRequest(EE_Payment_Method $paypal_pm, string $request_url, array $request_args): array
551
-    {
552
-        $error_return = ['error' => true];
553
-        $response     = wp_remote_request($request_url, $request_args);
554
-        if (is_wp_error($response)) {
555
-            $message = $response->get_error_message();
556
-            PayPalLogger::errorLog($message, [$request_url, $request_args, $response], $paypal_pm);
557
-            $error_return['message'] = $message;
558
-            return $error_return;
559
-        }
560
-        $response_body = (isset($response['body']) && $response['body']) ? json_decode($response['body'], true) : [];
561
-        if (empty($response_body) || isset($response_body['error'])) {
562
-            $message = $response_body['error_description']
563
-                       ?? sprintf(
564
-                           esc_html__('Unknown response received while sending a request to: %1$s', 'event_espresso'),
565
-                           $request_url
566
-                       );
567
-            PayPalLogger::errorLog($message, [$request_url, $request_args, $response], $paypal_pm);
568
-            $error_return['message'] = $message;
569
-            return $error_return;
570
-        }
571
-        return $response_body;
572
-    }
573
-
574
-
575
-    /**
576
-     * Check the response for a partner token request.
577
-     *
578
-     * @param                   $response
579
-     * @param EE_Payment_Method $paypal_pm
580
-     * @return bool
581
-     */
582
-    public static function partnerTokenResponseValid($response, EE_Payment_Method $paypal_pm): bool
583
-    {
584
-        // Check the data we received.
585
-        if (
586
-            empty($response['nonce'])
587
-            || ! wp_verify_nonce($response['nonce'], 'eea_pp_commerce_get_access_token')
588
-            || empty($response['access_token'])
589
-            || empty($response['app_id'])
590
-            || empty($response['expires_in'])
591
-            || empty($response['partner_client_id'])
592
-            || empty($response['partner_merchant_id'])
593
-        ) {
594
-            // This is an error.
595
-            $err_msg = esc_html__('Incoming parameter validation failed.', 'event_espresso');
596
-            PayPalLogger::errorLog($err_msg, (array) $response, $paypal_pm);
597
-            return false;
598
-        }
599
-        return true;
600
-    }
601
-
602
-
603
-    /**
604
-     * Returns the base URL to the middleman server.
605
-     * If LOCAL_MIDDLEMAN_SERVER is defined, requests will be sent to connect.eventespresso.test
606
-     *
607
-     * @param EE_Payment_Method $payment_method
608
-     * @return string
609
-     * @throws EE_Error
610
-     * @throws ReflectionException
611
-     */
612
-    public static function getMiddlemanBaseUrl(EE_Payment_Method $payment_method): string
613
-    {
614
-        $target = defined('LOCAL_MIDDLEMAN_SERVER') ? 'test' : 'com';
615
-        // If this PM is used under different provider accounts, you might need an account indicator.
616
-        $account = defined('EE_PAYPAL_COMMERCE_ACCOUNT_INDICATOR') ? EE_PAYPAL_COMMERCE_ACCOUNT_INDICATOR : '';
617
-        $postfix = $payment_method->debug_mode() ? '_sandbox' : '';
618
-        $path    = 'paypal_commerce' . $account . $postfix;
619
-        return 'https://connect.eventespresso.' . $target . '/' . $path . '/';
620
-    }
621
-
622
-
623
-    /**
624
-     * This Payment Method admin notices.
625
-     *
626
-     * @return void
627
-     * @throws EE_Error
628
-     * @throws ReflectionException
629
-     */
630
-    public static function adminNotice()
631
-    {
632
-        // A notice to re-connect if still connected through the first party integration.
633
-        $pp_commerce = EEM_Payment_Method::instance()->get_one_by_slug('paypalcheckout');
634
-        // Show the notice only if PayPal Commerce is active.
635
-        if (! $pp_commerce instanceof EE_Payment_Method
636
-            || ! EED_PayPalOnboard::isOnboard($pp_commerce)
637
-            || EED_PayPalCommerce::isThirdParty($pp_commerce)
638
-        ) {
639
-            return;
640
-        }
641
-        add_action('admin_notices', [__CLASS__, 'reConnectNotice']);
642
-    }
643
-
644
-
645
-    /**
646
-     * Re-connect notice contents.
647
-     *
648
-     * @return void
649
-     * @throws EE_Error
650
-     * @throws ReflectionException
651
-     */
652
-    public static function reConnectNotice()
653
-    {
654
-        $open_anchor = $close_anchor = '';
655
-        $pp_commerce = EEM_Payment_Method::instance()->get_one_by_slug('paypalcheckout');
656
-        if ($pp_commerce instanceof EE_Payment_Method) {
657
-            $pm_page = add_query_arg(
658
-                [
659
-                    'page'           => 'espresso_payment_settings',
660
-                    'webhook_action' => 'eepPpcMerchantOnboard',
661
-                    'payment_method' => $pp_commerce->slug(),
662
-                ],
663
-                admin_url('admin.php')
664
-            );
665
-            $open_anchor  = "<a href='$pm_page'>";
666
-            $close_anchor = "</a>";
667
-        }
668
-        echo '<div class="error"><p>'
669
-        . sprintf(
670
-            esc_html__(
671
-                '%1$sPayPal Commerce%2$s has updated the API integration type to allow more flexibility with payments. Please disconnect and re-Connect on the %3$sPayment Methods admin%4$s page to update the credentials and allow advanced payment type options.',
672
-                'event_espresso'
673
-            ),
674
-            '<strong>',
675
-            '</strong>',
676
-            $open_anchor,
677
-            $close_anchor
678
-         )
679
-         . '</p></div>';
680
-    }
23
+	/**
24
+	 * @return EED_Module
25
+	 * @throws EE_Error
26
+	 * @throws ReflectionException
27
+	 */
28
+	public static function instance(): EED_Module
29
+	{
30
+		return parent::get_instance(__CLASS__);
31
+	}
32
+
33
+
34
+	/**
35
+	 * Run - initial module setup.
36
+	 *
37
+	 * @param WP $WP
38
+	 * @return void
39
+	 */
40
+	public function run($WP)
41
+	{
42
+	}
43
+
44
+
45
+	/**
46
+	 * For hooking into EE Admin Core and other modules.
47
+	 *
48
+	 * @return void
49
+	 */
50
+	public static function set_hooks_admin(): void
51
+	{
52
+		if (DbStatus::isOnline()) {
53
+			// Get onboarding URL.
54
+			add_action('wp_ajax_eeaPpGetOnboardingUrl', [__CLASS__, 'getOnboardingUrl']);
55
+			// Catch the return/redirect from PayPal onboarding page.
56
+			add_action('init', [__CLASS__, 'updateOnboardingStatus'], 10);
57
+			// Return the connection/onboard status.
58
+			add_action('wp_ajax_eeaPpGetOnboardStatus', [__CLASS__, 'getOnboardStatus']);
59
+			// Revoke access.
60
+			add_action('wp_ajax_eeaPpOffboard', [__CLASS__, 'offboard']);
61
+			// Admin notice.
62
+			add_action('admin_init', [__CLASS__, 'adminNotice']);
63
+		}
64
+	}
65
+
66
+
67
+	/**
68
+	 * Get the onboarding URL.
69
+	 * (AJAX)
70
+	 *
71
+	 * @return void
72
+	 */
73
+	public static function getOnboardingUrl(): void
74
+	{
75
+		$signup_link = '';
76
+		try {
77
+			$paypal_pm = EED_PayPalCommerce::getPaymentMethod();
78
+			if (! $paypal_pm instanceof EE_Payment_Method) {
79
+				PayPalLogger::errorLogAndExit(
80
+					esc_html__('No payment method.', 'event_espresso'),
81
+					EED_Module::getRequest()->postParams(),
82
+					$paypal_pm
83
+				);
84
+			}
85
+			PayPalExtraMetaManager::updateDebugMode($paypal_pm, EED_Module::getRequest()->postParams());
86
+			// $signup_link   = PayPalExtraMetaManager::getPmOption($paypal_pm, Domain::META_KEY_ONBOARDING_URL);
87
+			// $token_expired = EED_PayPalOnboard::partnerAccessTokenExpired($paypal_pm);
88
+			// if (! $signup_link || $token_expired) {
89
+			$signup_link = EED_PayPalOnboard::requestOnboardingUrl($paypal_pm);
90
+			// }
91
+			if (! $signup_link) {
92
+				$err_msg = esc_html__('Error! Could not generate a sign-up link.', 'event_espresso');
93
+				PayPalLogger::errorLogAndExit($err_msg, ['signup_link' => $signup_link], $paypal_pm);
94
+			}
95
+			PayPalExtraMetaManager::savePmOption($paypal_pm, Domain::META_KEY_ONBOARDING_URL, $signup_link);
96
+		} catch (Exception $exception) {
97
+			PayPalLogger::errorLogAndExit($exception->getMessage());
98
+		}
99
+		// Is it empty (can happen if we didn't get the URL through the API).
100
+		$signup_link = $signup_link ? $signup_link . '?&displayMode=minibrowser' : '#';
101
+		wp_send_json(
102
+			[
103
+				'signup_link' => $signup_link,
104
+			]
105
+		);
106
+	}
107
+
108
+
109
+	/**
110
+	 * Request the sign-up link from PayPal.
111
+	 *
112
+	 * @param EE_Payment_Method $paypal_pm
113
+	 * @param bool              $one_time_request
114
+	 * @return string
115
+	 * @throws EE_Error
116
+	 * @throws Exception
117
+	 */
118
+	public static function requestOnboardingUrl(EE_Payment_Method $paypal_pm, bool $one_time_request = false): string
119
+	{
120
+		$signup_link = '';
121
+		// Get the access token.
122
+		$access_token = EED_PayPalOnboard::getPartnerAccessToken($paypal_pm);
123
+		if (! $access_token) {
124
+			$err_msg = esc_html__('Error! No access token.', 'event_espresso');
125
+			PayPalLogger::errorLog($err_msg, ['access_token' => $access_token], $paypal_pm);
126
+			return '';
127
+		}
128
+		// Request the access token.
129
+		$body_params = EED_PayPalOnboard::signupLinkRequestBody($paypal_pm);
130
+		$bn_code     = PayPalExtraMetaManager::getPmOption($paypal_pm, Domain::META_KEY_BN_CODE);
131
+		$post_params = [
132
+			'method'  => 'POST',
133
+			'headers' => [
134
+				'User-Agent'                    => sanitize_text_field($_SERVER['HTTP_USER_AGENT']),
135
+				'Content-Type'                  => 'application/json',
136
+				'Authorization'                 => 'Bearer ' . $access_token,
137
+				'PayPal-Partner-Attribution-Id' => $bn_code,
138
+			],
139
+			'body'    => $body_params,
140
+		];
141
+		$request_url = Domain::getPayPalApiUrl($paypal_pm) . '/v2/customer/partner-referrals';
142
+		$response    = EED_PayPalOnboard::sendRequest($paypal_pm, $request_url, $post_params);
143
+		// Check the data we received.
144
+		if (isset($response['error']) || empty($response['links'])) {
145
+			// Did the original access token get replaced by any chance ?
146
+			if (! $one_time_request
147
+				&& ! empty($response['message'])
148
+				&& $response['message'] === 'Access Token not found in cache'
149
+			) {
150
+				// Clear all PM metadata and try getting the access token One more time.
151
+				PayPalExtraMetaManager::deleteAllData($paypal_pm);
152
+				return EED_PayPalOnboard::requestOnboardingUrl($paypal_pm, true);
153
+			}
154
+			$err_msg = esc_html__('Incoming sign-up link parameter validation failed.', 'event_espresso');
155
+			PayPalLogger::errorLog($err_msg, $response, $paypal_pm);
156
+			return '';
157
+		}
158
+		// Now retrieve that sign-up link.
159
+		foreach ($response['links'] as $link) {
160
+			if ($link['rel'] === 'action_url') {
161
+				$signup_link = $link['href'] ?? '';
162
+			}
163
+		}
164
+		return $signup_link;
165
+	}
166
+
167
+
168
+	/**
169
+	 * Get the return URL.
170
+	 *
171
+	 * @param EE_Payment_Method $paypal_pm
172
+	 * @return string
173
+	 * @throws Exception
174
+	 */
175
+	public static function signupLinkRequestBody(EE_Payment_Method $paypal_pm): string
176
+	{
177
+		$identifier_string = new OneTimeString($paypal_pm->debug_mode());
178
+		$tracking_id       = $identifier_string->value();
179
+		$request           = LoaderFactory::getLoader()->getShared(RequestInterface::class);
180
+		$checkout_type     = $request->getRequestParam('checkout_type', 'EXPRESS_CHECKOUT', DataType::STRING);
181
+		// Save the identifier for future use.
182
+		PayPalExtraMetaManager::savePmOption($paypal_pm, Domain::META_KEY_TRACKING_ID, $tracking_id);
183
+		// Assemble the return URL.
184
+		$return_url = EED_PayPalOnboard::getReturnUrl($paypal_pm);
185
+		return json_encode([
186
+			'tracking_id'             => $tracking_id,
187
+			'operations'              => [
188
+				[
189
+					'operation'                  => 'API_INTEGRATION',
190
+					'api_integration_preference' => [
191
+						'rest_api_integration' => [
192
+							'integration_method'  => 'PAYPAL',
193
+							'integration_type'    => 'THIRD_PARTY',
194
+							'third_party_details' => [
195
+								'features' => ['PAYMENT', 'REFUND'],
196
+							],
197
+						],
198
+					],
199
+				],
200
+			],
201
+			'products'                => [$checkout_type],
202
+			'legal_consents'          => [
203
+				[
204
+					'type'    => 'SHARE_DATA_CONSENT',
205
+					'granted' => true,
206
+				],
207
+			],
208
+			'partner_config_override' => [
209
+				'return_url' => $return_url,
210
+			],
211
+		]);
212
+	}
213
+
214
+
215
+	/**
216
+	 * Get the return URL.
217
+	 *
218
+	 * @param EE_Payment_Method $paypal_pm
219
+	 * @return string
220
+	 * @throws EE_Error
221
+	 * @throws ReflectionException
222
+	 */
223
+	public static function getReturnUrl(EE_Payment_Method $paypal_pm): string
224
+	{
225
+		$wp_nonce = EED_Module::getRequest()->getRequestParam('wp_nonce');
226
+		$nonce    = wp_create_nonce(Domain::NONCE_NAME_ONBOARDING_RETURN);
227
+		return add_query_arg(
228
+			[
229
+				'page'                        => 'espresso_payment_settings',
230
+				'webhook_action'              => 'eepPpcMerchantOnboard',
231
+				'payment_method'              => $paypal_pm->slug(),
232
+				'_wpnonce'                    => $wp_nonce,
233
+				'nonce'                       => $nonce,
234
+				Domain::META_KEY_SANDBOX_MODE => $paypal_pm->debug_mode() ? '1' : '0',
235
+			],
236
+			admin_url('admin.php')
237
+		);
238
+	}
239
+
240
+
241
+	/**
242
+	 * Redirect to the payment method (PP) settings home page.
243
+	 *
244
+	 * @return void
245
+	 */
246
+	public static function redirectToPmSettingsHome(): void
247
+	{
248
+		$get_params = EED_Module::getRequest()->getParams();
249
+		if (empty($get_params['payment_method'])) {
250
+			// Simply do not redirect.
251
+			return;
252
+		}
253
+		$args_to_add = [
254
+			'page'           => 'espresso_payment_settings',
255
+			'payment_method' => $get_params['payment_method'],
256
+		];
257
+		if (isset($get_params['sandbox_mode'])) {
258
+			$args_to_add[ Domain::META_KEY_SANDBOX_MODE ] = $get_params['sandbox_mode'];
259
+		}
260
+		$home_url = add_query_arg($args_to_add, admin_url('admin.php'));
261
+		wp_redirect($home_url);
262
+		exit;
263
+	}
264
+
265
+
266
+	/**
267
+	 * Check user’s onboarding status.
268
+	 * This will handle the user return from the auth page and also check the status via the API.
269
+	 *
270
+	 * @return void
271
+	 * @throws EE_Error
272
+	 * @throws ReflectionException
273
+	 */
274
+	public static function updateOnboardingStatus(): void
275
+	{
276
+		// Check if this is the webhook from PayPal.
277
+		if (! isset($_GET['webhook_action'], $_GET['nonce'])
278
+			|| $_GET['webhook_action'] !== 'eepPpcMerchantOnboard'
279
+		) {
280
+			return;  // Ignore.
281
+		}
282
+		$get_params = EED_Module::getRequest()->getParams();
283
+		// Get the payment method.
284
+		$paypal_pm = EED_PayPalCommerce::getPaymentMethod();
285
+		// Check the response (GET) parameters.
286
+		if (! EED_PayPalOnboard::onboardingStatusResponseValid($get_params, $paypal_pm)) {
287
+			// Missing parameters. Can't proceed.
288
+			PayPalLogger::errorLog(
289
+				esc_html__('Missing required onboarding parameters.', 'event_espresso'),
290
+				$get_params,
291
+				$paypal_pm
292
+			);
293
+			EED_PayPalOnboard::redirectToPmSettingsHome();
294
+			return;
295
+		}
296
+		// Check on the onboarding status (recommended by PP).
297
+		$onboarding_status = EED_PayPalOnboard::trackSellerOnboarding(
298
+			$paypal_pm,
299
+			$get_params[ Domain::META_KEY_SELLER_MERCHANT_ID ]
300
+		);
301
+		if (! isset($onboarding_status['valid']) || ! $onboarding_status['valid']) {
302
+			PayPalLogger::errorLog(
303
+				$onboarding_status['message'],
304
+				array_merge($get_params, $onboarding_status),
305
+				$paypal_pm
306
+			);
307
+			EED_PayPalOnboard::redirectToPmSettingsHome();
308
+			return;
309
+		}
310
+		// Start saving the setup and info.
311
+		PayPalExtraMetaManager::parseAndSaveOptions($paypal_pm, $onboarding_status);
312
+		// Save the credentials.
313
+		PayPalExtraMetaManager::saveSellerApiCredentials($paypal_pm, $get_params);
314
+		// If onboarded successfully, remove the onboarding URL.
315
+		PayPalExtraMetaManager::deletePmOption($paypal_pm, Domain::META_KEY_ONBOARDING_URL);
316
+		// Also clen GET params by redirecting, because PP auto redirects to the return_url on closing the onboarding window.
317
+		EED_PayPalOnboard::redirectToPmSettingsHome();
318
+	}
319
+
320
+
321
+	/**
322
+	 * Check if all required parameters for the onboarding status check are present.
323
+	 *
324
+	 * @param array $data
325
+	 * @param mixed $paypal_pm
326
+	 * @return bool
327
+	 */
328
+	public static function onboardingStatusResponseValid(array $data, $paypal_pm): bool
329
+	{
330
+		// Check that we have all the required parameters and the nonce is ok.
331
+		if ($paypal_pm instanceof EE_Payment_Method
332
+			&& wp_verify_nonce($data['nonce'], Domain::NONCE_NAME_ONBOARDING_RETURN)
333
+			&& ! empty($data[ Domain::API_PARAM_PARTNER_ID ])
334
+			&& ! empty($data[ Domain::META_KEY_SELLER_MERCHANT_ID ])
335
+			&& isset($data[ Domain::API_PARAM_EMAIL_CONFIRMED ])
336
+		) {
337
+			return true;
338
+		}
339
+		return false;
340
+	}
341
+
342
+
343
+	/**
344
+	 * Get partner access token.
345
+	 *
346
+	 * @param EE_Payment_Method $paypal_pm
347
+	 * @return string
348
+	 * @throws EE_Error
349
+	 * @throws ReflectionException
350
+	 */
351
+	public static function getPartnerAccessToken(EE_Payment_Method $paypal_pm): string
352
+	{
353
+		// Do we have it saved ?
354
+		$access_token = PayPalExtraMetaManager::getPmOption($paypal_pm, Domain::META_KEY_ACCESS_TOKEN);
355
+		$expired      = EED_PayPalOnboard::partnerAccessTokenExpired($paypal_pm);
356
+		// If we don't have it, request/update it.
357
+		if (! $access_token || $expired) {
358
+			return EED_PayPalOnboard::requestPartnerAccessToken($paypal_pm);
359
+		}
360
+		// Access token is saved as encrypted, so return decrypted.
361
+		return $access_token;
362
+	}
363
+
364
+
365
+	/**
366
+	 * Get partner access token.
367
+	 *
368
+	 * @param EE_Payment_Method $paypal_pm
369
+	 * @return bool
370
+	 */
371
+	public static function partnerAccessTokenExpired(EE_Payment_Method $paypal_pm): bool
372
+	{
373
+		$expires_at = (int) PayPalExtraMetaManager::getPmOption($paypal_pm, Domain::META_KEY_EXPIRES_IN);
374
+		if (! $expires_at) {
375
+			return true;
376
+		}
377
+		// Validate the token expiration date.
378
+		$now          = time();
379
+		$minutes_left = round(($expires_at - $now) / 60);
380
+		// Count as expired if less than 60 minutes till expiration left.
381
+		if ($minutes_left <= 60) {
382
+			return true;
383
+		}
384
+		return false;
385
+	}
386
+
387
+
388
+	/**
389
+	 * Request the partner access token from PayPal and save/update it.
390
+	 *
391
+	 * @param EE_Payment_Method $paypal_pm
392
+	 * @return string
393
+	 * @throws EE_Error
394
+	 * @throws ReflectionException
395
+	 */
396
+	public static function requestPartnerAccessToken(EE_Payment_Method $paypal_pm): string
397
+	{
398
+		$nonce = wp_create_nonce('eea_pp_commerce_get_access_token');
399
+		// Request the access token.
400
+		$post_args = [
401
+			'method' => 'POST',
402
+			'body'   => [
403
+				'nonce'                       => $nonce,
404
+				'api_version'                 => 'v1',
405
+				Domain::META_KEY_SANDBOX_MODE => $paypal_pm->debug_mode() ? '1' : '0',
406
+			],
407
+		];
408
+		if (defined('LOCAL_MIDDLEMAN_SERVER')) {
409
+			$post_args['sslverify'] = false;
410
+		}
411
+		$post_url = EED_PayPalOnboard::getMiddlemanBaseUrl($paypal_pm) . 'get_token';
412
+		$response = EED_PayPalOnboard::sendRequest($paypal_pm, $post_url, $post_args);
413
+		if (isset($response['error'])) {
414
+			return '';
415
+		}
416
+		// Check the data we received.
417
+		if (! EED_PayPalOnboard::partnerTokenResponseValid($response, $paypal_pm)) {
418
+			return '';
419
+		}
420
+		// If we are here all seems to be ok. Save the token and it's data.
421
+		$saved = PayPalExtraMetaManager::savePartnerAccessToken($paypal_pm, $response);
422
+		if (! $saved) {
423
+			return '';
424
+		}
425
+		return $response['access_token'];
426
+	}
427
+
428
+
429
+	/**
430
+	 * Request seller onboarding status from PayPal.
431
+	 *
432
+	 * @param EE_Payment_Method $paypal_pm
433
+	 * @param string            $merchant_id
434
+	 * @return array
435
+	 */
436
+	public static function trackSellerOnboarding(EE_Payment_Method $paypal_pm, string $merchant_id): array
437
+	{
438
+		$track_onboarding = EED_PayPalOnboard::getTrackOnboardingApi($paypal_pm, $merchant_id);
439
+		if (! $track_onboarding instanceof TrackSellerOnboarding) {
440
+			$err_msg = esc_html__('Failed to track seller onboarding.', 'event_espresso');
441
+			return ['error' => 'TRACK_ONBOARDING_FAILED', 'message' => $err_msg];
442
+		}
443
+		return $track_onboarding->isValid();
444
+	}
445
+
446
+
447
+	/**
448
+	 * Returns the Track Seller Onboarding API.
449
+	 *
450
+	 * @param EE_Payment_Method $paypal_pm
451
+	 * @param string            $merchant_id
452
+	 * @return TrackSellerOnboarding|null
453
+	 * @throws EE_Error
454
+	 * @throws ReflectionException
455
+	 */
456
+	public static function getTrackOnboardingApi(
457
+		EE_Payment_Method $paypal_pm,
458
+		string            $merchant_id
459
+	): ?TrackSellerOnboarding {
460
+		$partner_id = PayPalExtraMetaManager::getPmOption($paypal_pm, Domain::META_KEY_PARTNER_MERCHANT_ID);
461
+		$paypal_api = EED_PayPalCommerce::getPayPalApi($paypal_pm);
462
+		if (! $paypal_api instanceof PayPalApi || ! $partner_id) {
463
+			return null;
464
+		}
465
+		return new TrackSellerOnboarding($paypal_api, $partner_id, $merchant_id, $paypal_pm->debug_mode());
466
+	}
467
+
468
+
469
+	/**
470
+	 * Check the onboard status and return the result.
471
+	 * (AJAX)
472
+	 *
473
+	 * @return void
474
+	 */
475
+	public static function getOnboardStatus(): void
476
+	{
477
+		$paypal_pm = EED_PayPalCommerce::getPaymentMethod();
478
+		if (! $paypal_pm instanceof EE_Payment_Method) {
479
+			$err_msg = esc_html__('Could not specify the payment method.', 'event_espresso');
480
+			PayPalLogger::errorLog($err_msg, EED_Module::getRequest()->postParams(), $paypal_pm);
481
+			wp_send_json(['on_board' => false]);
482
+		}
483
+		try {
484
+			$seller_id = PayPalExtraMetaManager::getPmOption($paypal_pm, Domain::META_KEY_SELLER_MERCHANT_ID) ?? '--';
485
+		} catch (Exception $e) {
486
+			$seller_id = '--';
487
+		}
488
+		wp_send_json(
489
+			[
490
+				'on_board'  => EED_PayPalOnboard::isOnboard($paypal_pm),
491
+				'seller_id' => $seller_id,
492
+			]
493
+		);
494
+	}
495
+
496
+
497
+	/**
498
+	 * De-authorize the seller. Remove all API credentials.
499
+	 * (AJAX)
500
+	 *
501
+	 * @return void
502
+	 */
503
+	public static function offboard(): void
504
+	{
505
+		$paypal_pm = EED_PayPalCommerce::getPaymentMethod();
506
+		if (! $paypal_pm instanceof EE_Payment_Method) {
507
+			wp_send_json([
508
+				'error'   => 'INVALID_PM',
509
+				'message' => esc_html__(
510
+					'Invalid payment method. Please refresh the page and try again.',
511
+					'event_espresso'
512
+				),
513
+			]);
514
+		}
515
+		PayPalExtraMetaManager::deleteAllData($paypal_pm);
516
+		wp_send_json(['success' => true]);
517
+	}
518
+
519
+
520
+	/**
521
+	 * Checks if already onboard.
522
+	 *
523
+	 * @param EE_Payment_Method $payment_method
524
+	 * @return boolean
525
+	 */
526
+	public static function isOnboard(EE_Payment_Method $payment_method): bool
527
+	{
528
+		$pp_meta_data = PayPalExtraMetaManager::getAllData($payment_method);
529
+		return
530
+			// onborded with a third party integration ?
531
+			(! empty($pp_meta_data[ Domain::META_KEY_SELLER_MERCHANT_ID ])
532
+				&& ! empty($pp_meta_data[ Domain::META_KEY_ACCESS_TOKEN ])
533
+			)
534
+			// or with the first party integration ?
535
+			|| (! empty($pp_meta_data[ Domain::META_KEY_CLIENT_ID ])
536
+				&& ! empty($pp_meta_data[ Domain::META_KEY_CLIENT_SECRET ])
537
+				&& ! empty($pp_meta_data[ Domain::META_KEY_PAYER_ID ])
538
+			);
539
+	}
540
+
541
+
542
+	/**
543
+	 * Send a request and return a decoded response body.
544
+	 *
545
+	 * @param EE_Payment_Method $paypal_pm
546
+	 * @param string            $request_url
547
+	 * @param array             $request_args
548
+	 * @return array
549
+	 */
550
+	public static function sendRequest(EE_Payment_Method $paypal_pm, string $request_url, array $request_args): array
551
+	{
552
+		$error_return = ['error' => true];
553
+		$response     = wp_remote_request($request_url, $request_args);
554
+		if (is_wp_error($response)) {
555
+			$message = $response->get_error_message();
556
+			PayPalLogger::errorLog($message, [$request_url, $request_args, $response], $paypal_pm);
557
+			$error_return['message'] = $message;
558
+			return $error_return;
559
+		}
560
+		$response_body = (isset($response['body']) && $response['body']) ? json_decode($response['body'], true) : [];
561
+		if (empty($response_body) || isset($response_body['error'])) {
562
+			$message = $response_body['error_description']
563
+					   ?? sprintf(
564
+						   esc_html__('Unknown response received while sending a request to: %1$s', 'event_espresso'),
565
+						   $request_url
566
+					   );
567
+			PayPalLogger::errorLog($message, [$request_url, $request_args, $response], $paypal_pm);
568
+			$error_return['message'] = $message;
569
+			return $error_return;
570
+		}
571
+		return $response_body;
572
+	}
573
+
574
+
575
+	/**
576
+	 * Check the response for a partner token request.
577
+	 *
578
+	 * @param                   $response
579
+	 * @param EE_Payment_Method $paypal_pm
580
+	 * @return bool
581
+	 */
582
+	public static function partnerTokenResponseValid($response, EE_Payment_Method $paypal_pm): bool
583
+	{
584
+		// Check the data we received.
585
+		if (
586
+			empty($response['nonce'])
587
+			|| ! wp_verify_nonce($response['nonce'], 'eea_pp_commerce_get_access_token')
588
+			|| empty($response['access_token'])
589
+			|| empty($response['app_id'])
590
+			|| empty($response['expires_in'])
591
+			|| empty($response['partner_client_id'])
592
+			|| empty($response['partner_merchant_id'])
593
+		) {
594
+			// This is an error.
595
+			$err_msg = esc_html__('Incoming parameter validation failed.', 'event_espresso');
596
+			PayPalLogger::errorLog($err_msg, (array) $response, $paypal_pm);
597
+			return false;
598
+		}
599
+		return true;
600
+	}
601
+
602
+
603
+	/**
604
+	 * Returns the base URL to the middleman server.
605
+	 * If LOCAL_MIDDLEMAN_SERVER is defined, requests will be sent to connect.eventespresso.test
606
+	 *
607
+	 * @param EE_Payment_Method $payment_method
608
+	 * @return string
609
+	 * @throws EE_Error
610
+	 * @throws ReflectionException
611
+	 */
612
+	public static function getMiddlemanBaseUrl(EE_Payment_Method $payment_method): string
613
+	{
614
+		$target = defined('LOCAL_MIDDLEMAN_SERVER') ? 'test' : 'com';
615
+		// If this PM is used under different provider accounts, you might need an account indicator.
616
+		$account = defined('EE_PAYPAL_COMMERCE_ACCOUNT_INDICATOR') ? EE_PAYPAL_COMMERCE_ACCOUNT_INDICATOR : '';
617
+		$postfix = $payment_method->debug_mode() ? '_sandbox' : '';
618
+		$path    = 'paypal_commerce' . $account . $postfix;
619
+		return 'https://connect.eventespresso.' . $target . '/' . $path . '/';
620
+	}
621
+
622
+
623
+	/**
624
+	 * This Payment Method admin notices.
625
+	 *
626
+	 * @return void
627
+	 * @throws EE_Error
628
+	 * @throws ReflectionException
629
+	 */
630
+	public static function adminNotice()
631
+	{
632
+		// A notice to re-connect if still connected through the first party integration.
633
+		$pp_commerce = EEM_Payment_Method::instance()->get_one_by_slug('paypalcheckout');
634
+		// Show the notice only if PayPal Commerce is active.
635
+		if (! $pp_commerce instanceof EE_Payment_Method
636
+			|| ! EED_PayPalOnboard::isOnboard($pp_commerce)
637
+			|| EED_PayPalCommerce::isThirdParty($pp_commerce)
638
+		) {
639
+			return;
640
+		}
641
+		add_action('admin_notices', [__CLASS__, 'reConnectNotice']);
642
+	}
643
+
644
+
645
+	/**
646
+	 * Re-connect notice contents.
647
+	 *
648
+	 * @return void
649
+	 * @throws EE_Error
650
+	 * @throws ReflectionException
651
+	 */
652
+	public static function reConnectNotice()
653
+	{
654
+		$open_anchor = $close_anchor = '';
655
+		$pp_commerce = EEM_Payment_Method::instance()->get_one_by_slug('paypalcheckout');
656
+		if ($pp_commerce instanceof EE_Payment_Method) {
657
+			$pm_page = add_query_arg(
658
+				[
659
+					'page'           => 'espresso_payment_settings',
660
+					'webhook_action' => 'eepPpcMerchantOnboard',
661
+					'payment_method' => $pp_commerce->slug(),
662
+				],
663
+				admin_url('admin.php')
664
+			);
665
+			$open_anchor  = "<a href='$pm_page'>";
666
+			$close_anchor = "</a>";
667
+		}
668
+		echo '<div class="error"><p>'
669
+		. sprintf(
670
+			esc_html__(
671
+				'%1$sPayPal Commerce%2$s has updated the API integration type to allow more flexibility with payments. Please disconnect and re-Connect on the %3$sPayment Methods admin%4$s page to update the credentials and allow advanced payment type options.',
672
+				'event_espresso'
673
+			),
674
+			'<strong>',
675
+			'</strong>',
676
+			$open_anchor,
677
+			$close_anchor
678
+		 )
679
+		 . '</p></div>';
680
+	}
681 681
 }
Please login to merge, or discard this patch.
Spacing   +33 added lines, -33 removed lines patch added patch discarded remove patch
@@ -75,7 +75,7 @@  discard block
 block discarded – undo
75 75
         $signup_link = '';
76 76
         try {
77 77
             $paypal_pm = EED_PayPalCommerce::getPaymentMethod();
78
-            if (! $paypal_pm instanceof EE_Payment_Method) {
78
+            if ( ! $paypal_pm instanceof EE_Payment_Method) {
79 79
                 PayPalLogger::errorLogAndExit(
80 80
                     esc_html__('No payment method.', 'event_espresso'),
81 81
                     EED_Module::getRequest()->postParams(),
@@ -88,7 +88,7 @@  discard block
 block discarded – undo
88 88
             // if (! $signup_link || $token_expired) {
89 89
             $signup_link = EED_PayPalOnboard::requestOnboardingUrl($paypal_pm);
90 90
             // }
91
-            if (! $signup_link) {
91
+            if ( ! $signup_link) {
92 92
                 $err_msg = esc_html__('Error! Could not generate a sign-up link.', 'event_espresso');
93 93
                 PayPalLogger::errorLogAndExit($err_msg, ['signup_link' => $signup_link], $paypal_pm);
94 94
             }
@@ -97,7 +97,7 @@  discard block
 block discarded – undo
97 97
             PayPalLogger::errorLogAndExit($exception->getMessage());
98 98
         }
99 99
         // Is it empty (can happen if we didn't get the URL through the API).
100
-        $signup_link = $signup_link ? $signup_link . '?&displayMode=minibrowser' : '#';
100
+        $signup_link = $signup_link ? $signup_link.'?&displayMode=minibrowser' : '#';
101 101
         wp_send_json(
102 102
             [
103 103
                 'signup_link' => $signup_link,
@@ -120,7 +120,7 @@  discard block
 block discarded – undo
120 120
         $signup_link = '';
121 121
         // Get the access token.
122 122
         $access_token = EED_PayPalOnboard::getPartnerAccessToken($paypal_pm);
123
-        if (! $access_token) {
123
+        if ( ! $access_token) {
124 124
             $err_msg = esc_html__('Error! No access token.', 'event_espresso');
125 125
             PayPalLogger::errorLog($err_msg, ['access_token' => $access_token], $paypal_pm);
126 126
             return '';
@@ -133,17 +133,17 @@  discard block
 block discarded – undo
133 133
             'headers' => [
134 134
                 'User-Agent'                    => sanitize_text_field($_SERVER['HTTP_USER_AGENT']),
135 135
                 'Content-Type'                  => 'application/json',
136
-                'Authorization'                 => 'Bearer ' . $access_token,
136
+                'Authorization'                 => 'Bearer '.$access_token,
137 137
                 'PayPal-Partner-Attribution-Id' => $bn_code,
138 138
             ],
139 139
             'body'    => $body_params,
140 140
         ];
141
-        $request_url = Domain::getPayPalApiUrl($paypal_pm) . '/v2/customer/partner-referrals';
141
+        $request_url = Domain::getPayPalApiUrl($paypal_pm).'/v2/customer/partner-referrals';
142 142
         $response    = EED_PayPalOnboard::sendRequest($paypal_pm, $request_url, $post_params);
143 143
         // Check the data we received.
144 144
         if (isset($response['error']) || empty($response['links'])) {
145 145
             // Did the original access token get replaced by any chance ?
146
-            if (! $one_time_request
146
+            if ( ! $one_time_request
147 147
                 && ! empty($response['message'])
148 148
                 && $response['message'] === 'Access Token not found in cache'
149 149
             ) {
@@ -255,7 +255,7 @@  discard block
 block discarded – undo
255 255
             'payment_method' => $get_params['payment_method'],
256 256
         ];
257 257
         if (isset($get_params['sandbox_mode'])) {
258
-            $args_to_add[ Domain::META_KEY_SANDBOX_MODE ] = $get_params['sandbox_mode'];
258
+            $args_to_add[Domain::META_KEY_SANDBOX_MODE] = $get_params['sandbox_mode'];
259 259
         }
260 260
         $home_url = add_query_arg($args_to_add, admin_url('admin.php'));
261 261
         wp_redirect($home_url);
@@ -274,16 +274,16 @@  discard block
 block discarded – undo
274 274
     public static function updateOnboardingStatus(): void
275 275
     {
276 276
         // Check if this is the webhook from PayPal.
277
-        if (! isset($_GET['webhook_action'], $_GET['nonce'])
277
+        if ( ! isset($_GET['webhook_action'], $_GET['nonce'])
278 278
             || $_GET['webhook_action'] !== 'eepPpcMerchantOnboard'
279 279
         ) {
280
-            return;  // Ignore.
280
+            return; // Ignore.
281 281
         }
282 282
         $get_params = EED_Module::getRequest()->getParams();
283 283
         // Get the payment method.
284 284
         $paypal_pm = EED_PayPalCommerce::getPaymentMethod();
285 285
         // Check the response (GET) parameters.
286
-        if (! EED_PayPalOnboard::onboardingStatusResponseValid($get_params, $paypal_pm)) {
286
+        if ( ! EED_PayPalOnboard::onboardingStatusResponseValid($get_params, $paypal_pm)) {
287 287
             // Missing parameters. Can't proceed.
288 288
             PayPalLogger::errorLog(
289 289
                 esc_html__('Missing required onboarding parameters.', 'event_espresso'),
@@ -296,9 +296,9 @@  discard block
 block discarded – undo
296 296
         // Check on the onboarding status (recommended by PP).
297 297
         $onboarding_status = EED_PayPalOnboard::trackSellerOnboarding(
298 298
             $paypal_pm,
299
-            $get_params[ Domain::META_KEY_SELLER_MERCHANT_ID ]
299
+            $get_params[Domain::META_KEY_SELLER_MERCHANT_ID]
300 300
         );
301
-        if (! isset($onboarding_status['valid']) || ! $onboarding_status['valid']) {
301
+        if ( ! isset($onboarding_status['valid']) || ! $onboarding_status['valid']) {
302 302
             PayPalLogger::errorLog(
303 303
                 $onboarding_status['message'],
304 304
                 array_merge($get_params, $onboarding_status),
@@ -330,9 +330,9 @@  discard block
 block discarded – undo
330 330
         // Check that we have all the required parameters and the nonce is ok.
331 331
         if ($paypal_pm instanceof EE_Payment_Method
332 332
             && wp_verify_nonce($data['nonce'], Domain::NONCE_NAME_ONBOARDING_RETURN)
333
-            && ! empty($data[ Domain::API_PARAM_PARTNER_ID ])
334
-            && ! empty($data[ Domain::META_KEY_SELLER_MERCHANT_ID ])
335
-            && isset($data[ Domain::API_PARAM_EMAIL_CONFIRMED ])
333
+            && ! empty($data[Domain::API_PARAM_PARTNER_ID])
334
+            && ! empty($data[Domain::META_KEY_SELLER_MERCHANT_ID])
335
+            && isset($data[Domain::API_PARAM_EMAIL_CONFIRMED])
336 336
         ) {
337 337
             return true;
338 338
         }
@@ -354,7 +354,7 @@  discard block
 block discarded – undo
354 354
         $access_token = PayPalExtraMetaManager::getPmOption($paypal_pm, Domain::META_KEY_ACCESS_TOKEN);
355 355
         $expired      = EED_PayPalOnboard::partnerAccessTokenExpired($paypal_pm);
356 356
         // If we don't have it, request/update it.
357
-        if (! $access_token || $expired) {
357
+        if ( ! $access_token || $expired) {
358 358
             return EED_PayPalOnboard::requestPartnerAccessToken($paypal_pm);
359 359
         }
360 360
         // Access token is saved as encrypted, so return decrypted.
@@ -371,7 +371,7 @@  discard block
 block discarded – undo
371 371
     public static function partnerAccessTokenExpired(EE_Payment_Method $paypal_pm): bool
372 372
     {
373 373
         $expires_at = (int) PayPalExtraMetaManager::getPmOption($paypal_pm, Domain::META_KEY_EXPIRES_IN);
374
-        if (! $expires_at) {
374
+        if ( ! $expires_at) {
375 375
             return true;
376 376
         }
377 377
         // Validate the token expiration date.
@@ -408,18 +408,18 @@  discard block
 block discarded – undo
408 408
         if (defined('LOCAL_MIDDLEMAN_SERVER')) {
409 409
             $post_args['sslverify'] = false;
410 410
         }
411
-        $post_url = EED_PayPalOnboard::getMiddlemanBaseUrl($paypal_pm) . 'get_token';
411
+        $post_url = EED_PayPalOnboard::getMiddlemanBaseUrl($paypal_pm).'get_token';
412 412
         $response = EED_PayPalOnboard::sendRequest($paypal_pm, $post_url, $post_args);
413 413
         if (isset($response['error'])) {
414 414
             return '';
415 415
         }
416 416
         // Check the data we received.
417
-        if (! EED_PayPalOnboard::partnerTokenResponseValid($response, $paypal_pm)) {
417
+        if ( ! EED_PayPalOnboard::partnerTokenResponseValid($response, $paypal_pm)) {
418 418
             return '';
419 419
         }
420 420
         // If we are here all seems to be ok. Save the token and it's data.
421 421
         $saved = PayPalExtraMetaManager::savePartnerAccessToken($paypal_pm, $response);
422
-        if (! $saved) {
422
+        if ( ! $saved) {
423 423
             return '';
424 424
         }
425 425
         return $response['access_token'];
@@ -436,7 +436,7 @@  discard block
 block discarded – undo
436 436
     public static function trackSellerOnboarding(EE_Payment_Method $paypal_pm, string $merchant_id): array
437 437
     {
438 438
         $track_onboarding = EED_PayPalOnboard::getTrackOnboardingApi($paypal_pm, $merchant_id);
439
-        if (! $track_onboarding instanceof TrackSellerOnboarding) {
439
+        if ( ! $track_onboarding instanceof TrackSellerOnboarding) {
440 440
             $err_msg = esc_html__('Failed to track seller onboarding.', 'event_espresso');
441 441
             return ['error' => 'TRACK_ONBOARDING_FAILED', 'message' => $err_msg];
442 442
         }
@@ -459,7 +459,7 @@  discard block
 block discarded – undo
459 459
     ): ?TrackSellerOnboarding {
460 460
         $partner_id = PayPalExtraMetaManager::getPmOption($paypal_pm, Domain::META_KEY_PARTNER_MERCHANT_ID);
461 461
         $paypal_api = EED_PayPalCommerce::getPayPalApi($paypal_pm);
462
-        if (! $paypal_api instanceof PayPalApi || ! $partner_id) {
462
+        if ( ! $paypal_api instanceof PayPalApi || ! $partner_id) {
463 463
             return null;
464 464
         }
465 465
         return new TrackSellerOnboarding($paypal_api, $partner_id, $merchant_id, $paypal_pm->debug_mode());
@@ -475,7 +475,7 @@  discard block
 block discarded – undo
475 475
     public static function getOnboardStatus(): void
476 476
     {
477 477
         $paypal_pm = EED_PayPalCommerce::getPaymentMethod();
478
-        if (! $paypal_pm instanceof EE_Payment_Method) {
478
+        if ( ! $paypal_pm instanceof EE_Payment_Method) {
479 479
             $err_msg = esc_html__('Could not specify the payment method.', 'event_espresso');
480 480
             PayPalLogger::errorLog($err_msg, EED_Module::getRequest()->postParams(), $paypal_pm);
481 481
             wp_send_json(['on_board' => false]);
@@ -503,7 +503,7 @@  discard block
 block discarded – undo
503 503
     public static function offboard(): void
504 504
     {
505 505
         $paypal_pm = EED_PayPalCommerce::getPaymentMethod();
506
-        if (! $paypal_pm instanceof EE_Payment_Method) {
506
+        if ( ! $paypal_pm instanceof EE_Payment_Method) {
507 507
             wp_send_json([
508 508
                 'error'   => 'INVALID_PM',
509 509
                 'message' => esc_html__(
@@ -528,13 +528,13 @@  discard block
 block discarded – undo
528 528
         $pp_meta_data = PayPalExtraMetaManager::getAllData($payment_method);
529 529
         return
530 530
             // onborded with a third party integration ?
531
-            (! empty($pp_meta_data[ Domain::META_KEY_SELLER_MERCHANT_ID ])
532
-                && ! empty($pp_meta_data[ Domain::META_KEY_ACCESS_TOKEN ])
531
+            ( ! empty($pp_meta_data[Domain::META_KEY_SELLER_MERCHANT_ID])
532
+                && ! empty($pp_meta_data[Domain::META_KEY_ACCESS_TOKEN])
533 533
             )
534 534
             // or with the first party integration ?
535
-            || (! empty($pp_meta_data[ Domain::META_KEY_CLIENT_ID ])
536
-                && ! empty($pp_meta_data[ Domain::META_KEY_CLIENT_SECRET ])
537
-                && ! empty($pp_meta_data[ Domain::META_KEY_PAYER_ID ])
535
+            || ( ! empty($pp_meta_data[Domain::META_KEY_CLIENT_ID])
536
+                && ! empty($pp_meta_data[Domain::META_KEY_CLIENT_SECRET])
537
+                && ! empty($pp_meta_data[Domain::META_KEY_PAYER_ID])
538 538
             );
539 539
     }
540 540
 
@@ -615,8 +615,8 @@  discard block
 block discarded – undo
615 615
         // If this PM is used under different provider accounts, you might need an account indicator.
616 616
         $account = defined('EE_PAYPAL_COMMERCE_ACCOUNT_INDICATOR') ? EE_PAYPAL_COMMERCE_ACCOUNT_INDICATOR : '';
617 617
         $postfix = $payment_method->debug_mode() ? '_sandbox' : '';
618
-        $path    = 'paypal_commerce' . $account . $postfix;
619
-        return 'https://connect.eventespresso.' . $target . '/' . $path . '/';
618
+        $path    = 'paypal_commerce'.$account.$postfix;
619
+        return 'https://connect.eventespresso.'.$target.'/'.$path.'/';
620 620
     }
621 621
 
622 622
 
@@ -632,7 +632,7 @@  discard block
 block discarded – undo
632 632
         // A notice to re-connect if still connected through the first party integration.
633 633
         $pp_commerce = EEM_Payment_Method::instance()->get_one_by_slug('paypalcheckout');
634 634
         // Show the notice only if PayPal Commerce is active.
635
-        if (! $pp_commerce instanceof EE_Payment_Method
635
+        if ( ! $pp_commerce instanceof EE_Payment_Method
636 636
             || ! EED_PayPalOnboard::isOnboard($pp_commerce)
637 637
             || EED_PayPalCommerce::isThirdParty($pp_commerce)
638 638
         ) {
Please login to merge, or discard this patch.