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0-beta.1 3.2.2 6.3.0-rc.1 3.2.3 6.3.0-rc.2 3.2.4 6.3.1 3.2.5 6.3.2 3.2.6 6.4.0 3.3.0 6.4.0-beta.1 3.3.1 6.4.0-rc.1 3.3.2 6.4.1 3.3.2-rc.1 6.4.2 3.3.3 6.5.0 3.3.4 6.5.0-beta.1 3.3.5 6.5.0-rc.1 3.3.6 6.5.0-rc.2 3.4.0 6.5.1 3.4.0-beta.1 6.5.2 3.4.0-rc.2 6.6.0 3.4.1 6.6.0-beta.1 3.4.2 6.6.0-rc.1 3.4.3 6.6.0-rc.2 3.4.4 6.6.1 3.4.5 6.6.2 3.4.6 6.7.0 3.4.7 6.7.0-beta.1 3.4.8 6.7.0-beta.2 3.5.0 6.7.0-rc.1 3.5.0-beta.1 6.7.1 3.5.0-rc.1 6.8.0 3.5.0-rc.2 6.8.0-beta.1 3.5.1 6.8.0-beta.2 3.5.10 6.8.0-rc.1 3.5.2 6.8.1 3.5.3 6.8.2 3.5.4 6.8.3 3.5.5 6.9.0 3.5.6 6.9.0-beta.1 3.5.7 6.9.0-beta.2 3.5.8 6.9.0-rc.1 3.5.9 6.9.1 3.6.0 6.9.2 3.6.0-beta.1 6.9.3 3.6.0-rc.1 6.9.4 3.6.0-rc.2 6.9.5 3.6.0-rc.3 7.0.0 3.6.1 7.0.0-beta.1 3.6.2 7.0.0-beta.2 3.6.3 7.0.0-beta.3 3.6.4 7.0.0-rc.1 3.6.5 7.0.0-rc.2 3.6.6 7.0.1 3.6.7 7.0.2 3.7.0 7.1.0 3.7.0-beta.1 7.1.0-beta.1 3.7.0-rc.1 7.1.0-beta.2 3.7.0-rc.2 7.1.0-rc.1 3.7.1 7.1.0-rc.2 3.7.2 7.1.1
woocommerce / src / Gateways / PayPal / TransactAccountManager.php
woocommerce / src / Gateways / PayPal Last commit date
AddressRequirements.php 7 months ago Buttons.php 4 months ago Constants.php 2 months ago Helper.php 2 months ago Notices.php 4 months ago Request.php 1 month ago TransactAccountManager.php 4 months ago WebhookHandler.php 2 months ago
TransactAccountManager.php
421 lines
1 <?php
2
3 declare(strict_types=1);
4
5 namespace Automattic\WooCommerce\Gateways\PayPal;
6
7 use Automattic\Jetpack\Connection\Client as Jetpack_Connection_Client;
8 use Automattic\WooCommerce\Gateways\PayPal\Constants as PayPalConstants;
9
10 if ( ! defined( 'ABSPATH' ) ) {
11 exit;
12 }
13
14 /**
15 * PayPal TransactAccountManager Class
16 *
17 * Handles Transact account management.
18 *
19 * @since 10.5.0
20 */
21 final class TransactAccountManager {
22 /**
23 * The API version for the proxy endpoint.
24 *
25 * @var int
26 *
27 * @since 10.5.0
28 */
29 private const WPCOM_PROXY_ENDPOINT_API_VERSION = 2;
30
31 /**
32 * Transact provider type, for provider onboarding.
33 *
34 * @var string
35 *
36 * @since 10.5.0
37 */
38 private const TRANSACT_PROVIDER_TYPE = 'paypal_standard';
39
40 /**
41 * Cache key for the merchant account in live mode.
42 *
43 * @var string
44 *
45 * @since 10.5.0
46 */
47 private const TRANSACT_MERCHANT_ACCOUNT_CACHE_KEY_LIVE = 'woocommerce_paypal_transact_merchant_account_live';
48
49 /**
50 * Cache key for the merchant account in test mode.
51 *
52 * @var string
53 *
54 * @since 10.5.0
55 */
56 private const TRANSACT_MERCHANT_ACCOUNT_CACHE_KEY_TEST = 'woocommerce_paypal_transact_merchant_account_test';
57
58 /**
59 * Cache key for the provider account in live mode.
60 *
61 * @var string
62 *
63 * @since 10.5.0
64 */
65 private const TRANSACT_PROVIDER_ACCOUNT_CACHE_KEY_LIVE = 'woocommerce_paypal_transact_provider_account_live';
66
67 /**
68 * Cache key for the provider account in test mode.
69 *
70 * @var string
71 *
72 * @since 10.5.0
73 */
74 private const TRANSACT_PROVIDER_ACCOUNT_CACHE_KEY_TEST = 'woocommerce_paypal_transact_provider_account_test';
75
76 /**
77 * The expiry time for the Transact account cache.
78 *
79 * @var int
80 *
81 * @since 10.5.0
82 */
83 private const TRANSACT_ACCOUNT_CACHE_EXPIRY = 60 * 60 * 24; // 24 hours.
84
85 /**
86 * Paypal gateway object.
87 *
88 * @var \WC_Gateway_Paypal
89 */
90 private \WC_Gateway_Paypal $gateway;
91
92 /**
93 * Constructor.
94 *
95 * @param \WC_Gateway_Paypal $gateway Paypal gateway object.
96 */
97 public function __construct( \WC_Gateway_Paypal $gateway ) {
98 $this->gateway = $gateway;
99 }
100
101 /**
102 * Onboard the merchant with the Transact platform.
103 *
104 * @return void
105 *
106 * @since 10.5.0
107 */
108 public function do_onboarding(): void {
109 // Check that we have a PayPal email. This is required for processing payments --
110 // used as the payee email. Only begin onboarding if this minimum requirement is met.
111 if ( empty( $this->gateway->email ) ) {
112 return;
113 }
114
115 // Register with Jetpack if not already connected.
116 $jetpack_connection_manager = $this->gateway->get_jetpack_connection_manager();
117 if ( ! $jetpack_connection_manager ) {
118 \WC_Gateway_Paypal::log( 'Jetpack connection manager not found.', 'error' );
119 return;
120 }
121
122 if ( ! $jetpack_connection_manager->is_connected() ) {
123 $result = $jetpack_connection_manager->try_registration();
124 if ( is_wp_error( $result ) ) {
125 \WC_Gateway_Paypal::log( 'Jetpack registration failed: ' . $result->get_error_message(), 'error' );
126 return;
127 }
128 }
129
130 // Fetch (cached) or create the Transact merchant and provider accounts.
131 $merchant_account_data = $this->get_transact_account_data( 'merchant' );
132 if ( empty( $merchant_account_data ) ) {
133 $merchant_account = $this->create_merchant_account();
134 if ( empty( $merchant_account ) ) {
135 \WC_Gateway_Paypal::log( 'Transact merchant onboarding failed.', 'error' );
136 return;
137 }
138
139 // Cache the merchant account data.
140 $this->update_transact_account_cache(
141 $this->get_cache_key( 'merchant' ),
142 $merchant_account
143 );
144 }
145
146 $provider_account_data = $this->get_transact_account_data( 'provider' );
147 if ( empty( $provider_account_data ) ) {
148 $provider_account = $this->create_provider_account();
149 if ( ! $provider_account ) {
150 \WC_Gateway_Paypal::log( 'Transact provider onboarding failed.', 'error' );
151 return;
152 }
153
154 // Cache the provider account data.
155 $this->update_transact_account_cache(
156 $this->get_cache_key( 'provider' ),
157 $provider_account
158 );
159 }
160
161 // Set an extra flag to indicate that we've completed onboarding,
162 // so we can do inexpensive early returns for checkers like
163 // WC_Gateway_Paypal::should_use_orders_v2().
164 $this->gateway->set_transact_onboarding_complete();
165 }
166
167 /**
168 * Get the Transact account (merchant or provider) data. Performs a fetch if the account
169 * is not in cache or expired.
170 *
171 * @since 10.5.0
172 *
173 * @param string $account_type The type of account to get (merchant or provider).
174 * @return mixed Returns null if the transact account cannot be retrieved.
175 */
176 public function get_transact_account_data( string $account_type ) {
177 $cache_key = $this->get_cache_key( $account_type );
178
179 // Get transact account from cache. If not found, fetch/create it.
180 $transact_account = $this->get_transact_account_from_cache( $cache_key );
181 if ( empty( $transact_account ) ) {
182 $transact_account = 'merchant' === $account_type ? $this->fetch_merchant_account() : $this->fetch_provider_account();
183
184 // Fetch failed.
185 if ( empty( $transact_account ) ) {
186 return null;
187 }
188
189 // Update cache.
190 $this->update_transact_account_cache( $cache_key, $transact_account );
191 }
192
193 return $transact_account;
194 }
195
196 /**
197 * Get the cache key for the transact account.
198 *
199 * @since 10.5.0
200 *
201 * @param string $account_type The type of account to get (merchant or provider).
202 * @return string|null The cache key, or null if the account type is invalid.
203 */
204 private function get_cache_key( string $account_type ): ?string {
205 if ( 'merchant' === $account_type ) {
206 return $this->gateway->testmode ? self::TRANSACT_MERCHANT_ACCOUNT_CACHE_KEY_TEST : self::TRANSACT_MERCHANT_ACCOUNT_CACHE_KEY_LIVE;
207 }
208
209 if ( 'provider' === $account_type ) {
210 return $this->gateway->testmode ? self::TRANSACT_PROVIDER_ACCOUNT_CACHE_KEY_TEST : self::TRANSACT_PROVIDER_ACCOUNT_CACHE_KEY_LIVE;
211 }
212
213 return null;
214 }
215
216 /**
217 * Fetch the merchant account from the Transact platform.
218 *
219 * @since 10.5.0
220 *
221 * @return array|null The API response body, or null if the request fails.
222 */
223 private function fetch_merchant_account(): ?array {
224 $site_id = \Jetpack_Options::get_option( 'id' );
225 if ( ! $site_id ) {
226 return null;
227 }
228
229 $request_body = array(
230 'test_mode' => $this->gateway->testmode,
231 );
232
233 $response = $this->send_transact_api_request(
234 'GET',
235 sprintf( '/sites/%d/transact/account', $site_id ),
236 $request_body
237 );
238
239 if ( is_wp_error( $response ) || 200 !== wp_remote_retrieve_response_code( $response ) ) {
240 return null;
241 }
242
243 $response_data = json_decode( wp_remote_retrieve_body( $response ), true );
244 if ( empty( $response_data['public_id'] ) ) {
245 return null;
246 }
247
248 return array( 'public_id' => $response_data['public_id'] );
249 }
250
251 /**
252 * Fetch the provider account from the Transact platform.
253 *
254 * @since 10.5.0
255 *
256 * @return bool True if the provider account exists, false otherwise.
257 */
258 private function fetch_provider_account(): bool {
259 $site_id = \Jetpack_Options::get_option( 'id' );
260 if ( ! $site_id ) {
261 return false;
262 }
263
264 $request_body = array(
265 'test_mode' => $this->gateway->testmode,
266 'provider_type' => self::TRANSACT_PROVIDER_TYPE,
267 );
268
269 $response = $this->send_transact_api_request(
270 'GET',
271 sprintf( '/sites/%d/transact/account/%s', $site_id, self::TRANSACT_PROVIDER_TYPE ),
272 $request_body
273 );
274
275 if ( is_wp_error( $response ) || 200 !== wp_remote_retrieve_response_code( $response ) ) {
276 return false;
277 }
278
279 // Provider account response only returns an empty onboarding link,
280 // which we do not need.
281 return true;
282 }
283
284 /**
285 * Create the merchant account with the Transact platform.
286 *
287 * @since 10.5.0
288 *
289 * @return array|null The API response body, or null if the request fails.
290 */
291 private function create_merchant_account(): ?array {
292 $site_id = \Jetpack_Options::get_option( 'id' );
293 if ( ! $site_id ) {
294 return null;
295 }
296
297 $request_body = array( 'test_mode' => $this->gateway->testmode );
298
299 $response = $this->send_transact_api_request(
300 'POST',
301 sprintf( '/sites/%d/transact/account', $site_id ),
302 $request_body
303 );
304
305 if ( is_wp_error( $response ) || 200 !== wp_remote_retrieve_response_code( $response ) ) {
306 return null;
307 }
308
309 $response_data = json_decode( wp_remote_retrieve_body( $response ), true );
310 if ( empty( $response_data['public_id'] ) ) {
311 \WC_Gateway_Paypal::log( 'Transact merchant account creation failed. Response body: ' . wc_print_r( $response_data, true ) );
312 return null;
313 }
314
315 return array( 'public_id' => $response_data['public_id'] );
316 }
317
318 /**
319 * Create the provider account with the Transact platform.
320 *
321 * @since 10.5.0
322 *
323 * @return bool True if the provider account creation was successful, false otherwise.
324 */
325 private function create_provider_account(): bool {
326 $site_id = \Jetpack_Options::get_option( 'id' );
327 if ( ! $site_id ) {
328 return false;
329 }
330
331 $request_body = array(
332 'test_mode' => $this->gateway->testmode,
333 'provider_type' => self::TRANSACT_PROVIDER_TYPE,
334 );
335 $response = $this->send_transact_api_request(
336 'POST',
337 sprintf( '/sites/%d/transact/account/%s/onboard', $site_id, self::TRANSACT_PROVIDER_TYPE ),
338 $request_body
339 );
340
341 if ( is_wp_error( $response ) || 200 !== wp_remote_retrieve_response_code( $response ) ) {
342 return false;
343 }
344
345 // Provider account response only returns an empty onboarding link,
346 // which we do not need.
347 return true;
348 }
349
350 /**
351 * Update the transact account (merchant or provider) cache.
352 *
353 * @since 10.5.0
354 *
355 * @param string|null $cache_key The cache key to update.
356 * @param array|bool $account_data The transact account data.
357 *
358 * @return void
359 */
360 private function update_transact_account_cache( string $cache_key, $account_data ): void {
361 $expires = time() + self::TRANSACT_ACCOUNT_CACHE_EXPIRY;
362 update_option(
363 $cache_key,
364 array(
365 'account' => $account_data,
366 'expiry' => $expires,
367 )
368 );
369 }
370
371 /**
372 * Get the transact account (merchant or provider) from the database cache.
373 *
374 * @since 10.5.0
375 *
376 * @param string $cache_key The cache key to get the account.
377 * @return mixed The transact account data, or null if the cache is
378 * empty or expired.
379 */
380 private function get_transact_account_from_cache( string $cache_key ) {
381 $transact_account = get_option( $cache_key, null );
382
383 if ( empty( $transact_account ) || ( isset( $transact_account['expiry'] ) && $transact_account['expiry'] < time() ) ) {
384 return null;
385 }
386
387 return $transact_account['account'] ?? null;
388 }
389
390 /**
391 * Send a request to the Transact platform.
392 *
393 * @since 10.5.0
394 *
395 * @param string $method The HTTP method to use.
396 * @param string $endpoint The endpoint to request.
397 * @param array $request_body The request body.
398 *
399 * @return array|\WP_Error The API response body, or null if the request fails.
400 */
401 private function send_transact_api_request( string $method, string $endpoint, array $request_body ) {
402 if ( 'GET' === $method ) {
403 $endpoint .= '?' . http_build_query( $request_body );
404 }
405
406 $response = Jetpack_Connection_Client::wpcom_json_api_request_as_blog(
407 $endpoint,
408 (string) self::WPCOM_PROXY_ENDPOINT_API_VERSION,
409 array(
410 'headers' => array( 'Content-Type' => 'application/json' ),
411 'method' => $method,
412 'timeout' => PayPalConstants::WPCOM_PROXY_REQUEST_TIMEOUT,
413 ),
414 'GET' === $method ? null : wp_json_encode( $request_body ),
415 'wpcom'
416 );
417
418 return $response;
419 }
420 }
421