PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / trunk
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More vtrunk
6.35 6.34 6.33.1 6.33 6.32.1 6.32 6.31 6.25 6.25.1 6.26 6.26.1 6.27 6.28 6.29 6.3 6.3.1 6.3.2 6.30 6.4 6.4.1 6.4.2 6.5 6.5.1 6.5.2 6.5.3 All 141 releases
← All changes | stripe/helpers/FrmStrpLiteConnectHelper.php +131 -88 6.25.1 → trunk View file →
@@ -33,13 +33,14 @@
33 33 private static function check_for_stripe_connect_ajax_actions() {
34 34 $action = FrmAppHelper::get_param( 'action', '', 'post', 'sanitize_text_field' );
35 35 $prefix = 'frm_stripe_connect_';
36 36
37 - if ( ! $action || 0 !== strpos( $action, $prefix ) ) {
37 + if ( ! $action || ! str_starts_with( $action, $prefix ) ) {
38 38 if ( 'frm_strp_connect_get_settings_button' === $action ) {
39 39 FrmAppHelper::permission_check( 'frm_change_settings' );
40 40 self::render_settings();
41 41 }
42 +
42 43 return;
43 44 }
44 45
45 46 FrmAppHelper::permission_check( 'frm_change_settings' );
@@ -114,13 +115,13 @@
114 115 return $data;
115 116 }
116 117
117 118 if ( ! empty( $data->password ) ) {
118 - update_option( self::get_server_side_token_option_name( $mode ), $data->password, 'no' );
119 + update_option( self::get_server_side_token_option_name( $mode ), $data->password, false );
119 120 }
120 121
121 122 if ( ! empty( $data->account_id ) ) {
122 - update_option( self::get_account_id_option_name( $mode ), $data->account_id, 'no' );
123 + update_option( self::get_account_id_option_name( $mode ), $data->account_id, false );
123 124 }
124 125
125 126 return $data;
126 127 }
@@ -128,13 +129,14 @@
128 129 /**
129 130 * Generate a new client password for authenticating with Connect Service and save it locally as an option.
130 131 *
131 132 * @param string $mode 'live' or 'test'.
133 + *
132 134 * @return string the client password.
133 135 */
134 136 private static function generate_client_password( $mode ) {
135 137 $client_password = wp_generate_password();
136 - update_option( self::get_client_side_token_option_name( $mode ), $client_password, 'no' );
138 + update_option( self::get_client_side_token_option_name( $mode ), $client_password, false );
137 139 return $client_password;
138 140 }
139 141
140 142 /**
@@ -139,8 +141,9 @@
139 141
140 142 /**
141 143 * @param string $action
142 144 * @param array $additional_body
145 + *
143 146 * @return object|string
144 147 */
145 148 private static function post_to_connect_server( $action, $additional_body = array() ) {
146 149 $body = array(
@@ -150,12 +153,8 @@
150 153 $body = array_merge( $body, $additional_body );
151 154 $url = self::get_url_to_connect_server();
152 155 $headers = self::build_headers_for_post();
153 156
154 - if ( ! $headers ) {
155 - return 'Unable to build headers for post. Is your pro license configured properly?';
156 - }
157 -
158 157 // (Seconds) default timeout is 5. we want a bit more time to work with.
159 158 $timeout = 45;
160 159
161 160 self::try_to_extend_server_timeout( $timeout );
@@ -167,12 +166,14 @@
167 166 return 'Response from server is invalid';
168 167 }
169 168
170 169 $body = self::pull_response_body( $response );
170 +
171 171 if ( empty( $body->success ) ) {
172 172 if ( ! empty( $body->data ) && is_string( $body->data ) ) {
173 173 return $body->data;
174 174 }
175 +
175 176 return 'Response from server was not successful';
176 177 }
177 178
178 179 return $body->data ?? array();
@@ -192,8 +193,9 @@
192 193 }
193 194
194 195 /**
195 196 * @param string $mode either 'auto', 'live', or 'test'.
197 + *
196 198 * @return string either _test or _live.
197 199 */
198 200 private static function get_active_mode_option_name_suffix( $mode = 'auto' ) {
199 201 if ( 'auto' !== $mode ) {
@@ -204,8 +206,9 @@
204 206
205 207 /**
206 208 * @param string $key 'account_id', 'client_password', 'server_password', 'details_submitted'.
207 209 * @param string $mode either 'auto', 'live', or 'test'.
210 + *
208 211 * @return string
209 212 */
210 213 private static function get_strp_connect_option_name( $key, $mode = 'auto' ) {
211 214 return 'frm_strp_connect_' . $key . self::get_active_mode_option_name_suffix( $mode );
@@ -212,8 +215,9 @@
212 215 }
213 216
214 217 /**
215 218 * @param string $mode either 'auto', 'live', or 'test'.
219 + *
216 220 * @return string
217 221 */
218 222 private static function get_account_id_option_name( $mode = 'auto' ) {
219 223 return self::get_strp_connect_option_name( 'account_id', $mode );
@@ -220,8 +224,9 @@
220 224 }
221 225
222 226 /**
223 227 * @param string $mode either 'auto', 'live', or 'test'.
228 + *
224 229 * @return string
225 230 */
226 231 private static function get_client_side_token_option_name( $mode = 'auto' ) {
227 232 return self::get_strp_connect_option_name( 'client_password', $mode );
@@ -228,8 +233,9 @@
228 233 }
229 234
230 235 /**
231 236 * @param string $mode either 'auto', 'live', or 'test'.
237 + *
232 238 * @return string
233 239 */
234 240 private static function get_server_side_token_option_name( $mode = 'auto' ) {
235 241 return self::get_strp_connect_option_name( 'server_password', $mode );
@@ -236,8 +242,9 @@
236 242 }
237 243
238 244 /**
239 245 * @param string $mode either 'auto', 'live', or 'test'.
246 + *
240 247 * @return string
241 248 */
242 249 private static function get_stripe_details_submitted_option_name( $mode = 'auto' ) {
243 250 return self::get_strp_connect_option_name( 'details_submitted', $mode );
@@ -255,9 +262,9 @@
255 262 */
256 263 private static function handle_disconnect() {
257 264 self::disconnect();
258 265 self::reset_stripe_connect_integration();
259 - self::maybe_unschedule_crons();
266 + FrmTransLiteAppHelper::trigger_gateway_disconnected_hook( 'stripe', self::get_mode_value_from_post() );
260 267 wp_send_json_success();
261 268 }
262 269
263 270 /**
@@ -276,37 +283,16 @@
276 283 /**
277 284 * @return false|object
278 285 */
279 286 private static function disconnect() {
280 - $additional_body = array(
281 - 'frm_strp_connect_mode' => self::get_mode_value_from_post(),
282 - );
287 + $mode = self::get_mode_value_from_post();
288 + $additional_body = self::get_body_for_mode( $mode );
283 289 return self::post_with_authenticated_body( 'disconnect', $additional_body );
284 290 }
285 291
286 292 /**
287 - * Stop the payment cron once all Stripe connections have been disconnected.
288 - *
289 293 * @since 6.5
290 294 *
291 - * @return void
292 - */
293 - private static function maybe_unschedule_crons() {
294 - if ( self::at_least_one_mode_is_setup() ) {
295 - // Don't unschedule if a mode is still on.
296 - return;
297 - }
298 -
299 - $event = 'frm_payment_cron';
300 - $timestamp = wp_next_scheduled( $event );
301 - if ( false !== $timestamp ) {
302 - wp_unschedule_event( $timestamp, $event );
303 - }
304 - }
305 -
306 - /**
307 - * @since 6.5
308 - *
309 295 * @return bool
310 296 */
311 297 public static function at_least_one_mode_is_setup() {
312 298 return self::stripe_connect_is_setup( 'test' ) || self::stripe_connect_is_setup( 'live' );
@@ -315,18 +301,18 @@
315 301 /**
316 302 * @return void
317 303 */
318 304 private static function handle_reauth() {
319 - $additional_body = array(
320 - 'frm_strp_connect_mode' => self::get_mode_value_from_post(),
321 - );
305 + $mode = self::get_mode_value_from_post();
306 + $additional_body = self::get_body_for_mode( $mode );
322 307 $data = self::post_with_authenticated_body( 'reauth', $additional_body );
323 308
324 309 if ( false === $data ) {
325 310 // Check account status.
326 - if ( self::check_server_for_connected_account_status() ) {
311 + if ( self::check_server_for_connected_account_status( $mode ) ) {
327 312 wp_send_json_success();
328 313 }
314 +
329 315 wp_send_json_error();
330 316 }
331 317
332 318 $response_data = array(
@@ -338,13 +324,26 @@
338 324 /**
339 325 * @return array
340 326 */
341 327 private static function get_standard_authenticated_body() {
342 - $mode = self::get_mode_value_from_post();
328 + return self::get_body_for_mode( FrmStrpLiteAppHelper::active_mode() );
329 + }
330 +
331 + /**
332 + * Get the standard body with account id, mode, and passwords to send to the connect server.
333 + *
334 + * @since 6.32.1
335 + *
336 + * @param string $mode 'live' or 'test'.
337 + *
338 + * @return array
339 + */
340 + private static function get_body_for_mode( $mode ) {
343 341 return array(
344 - 'account_id' => get_option( self::get_account_id_option_name( $mode ) ),
345 - 'server_password' => get_option( self::get_server_side_token_option_name( $mode ) ),
346 - 'client_password' => get_option( self::get_client_side_token_option_name( $mode ) ),
342 + 'account_id' => get_option( self::get_account_id_option_name( $mode ) ),
343 + 'server_password' => get_option( self::get_server_side_token_option_name( $mode ) ),
344 + 'client_password' => get_option( self::get_client_side_token_option_name( $mode ) ),
345 + 'frm_strp_connect_mode' => $mode,
347 346 );
348 347 }
349 348
350 349 private static function redirect() {
@@ -363,8 +362,9 @@
363 362 * @return bool
364 363 */
365 364 private static function check_server_for_oauth_account_id() {
366 365 $mode = FrmAppHelper::get_param( 'mode', '', 'get', 'sanitize_text_field' );
366 +
367 367 if ( 'live' !== $mode ) {
368 368 $mode = 'test';
369 369 }
370 370
@@ -380,9 +380,9 @@
380 380 );
381 381 $data = self::post_to_connect_server( 'oauth_account_status', $body );
382 382
383 383 if ( is_object( $data ) && ! empty( $data->account_id ) ) {
384 - update_option( self::get_account_id_option_name( $mode ), $data->account_id, 'no' );
384 + update_option( self::get_account_id_option_name( $mode ), $data->account_id, false );
385 385
386 386 if ( ! empty( $data->details_submitted ) ) {
387 387 self::set_stripe_details_as_submitted( $mode );
388 388 }
@@ -396,12 +396,13 @@
396 396 /**
397 397 * On a successful account status check, set details_submitted option.
398 398 *
399 399 * @param string $mode 'live' or 'test'.
400 + *
400 401 * @return void
401 402 */
402 403 private static function set_stripe_details_as_submitted( $mode ) {
403 - update_option( self::get_stripe_details_submitted_option_name( $mode ), true, 'no' );
404 + update_option( self::get_stripe_details_submitted_option_name( $mode ), true, false );
404 405 FrmTransLiteAppController::install();
405 406 }
406 407
407 408 /**
@@ -439,9 +440,9 @@
439 440 return false;
440 441 }
441 442
442 443 if ( ! empty( $data->password ) ) {
443 - update_option( self::get_server_side_token_option_name( $mode ), $data->password, 'no' );
444 + update_option( self::get_server_side_token_option_name( $mode ), $data->password, false );
444 445 }
445 446
446 447 if ( ! is_object( $data ) || empty( $data->redirect_url ) ) {
447 448 return false;
@@ -450,28 +451,39 @@
450 451 return $data->redirect_url;
451 452 }
452 453
453 454 /**
455 + * @param string $mode
456 + *
454 457 * @return bool true if our account is onboarded
455 458 */
456 - public static function check_server_for_connected_account_status() {
457 - $mode = FrmAppHelper::get_param( 'mode', '', 'get', 'sanitize_text_field' );
458 - if ( 'live' !== $mode ) {
459 - $mode = 'test';
459 + public static function check_server_for_connected_account_status( $mode = 'check_get' ) {
460 + if ( 'check_get' === $mode ) {
461 + $mode = FrmAppHelper::get_param( 'mode', '', 'get', 'sanitize_text_field' );
462 +
463 + if ( 'live' !== $mode ) {
464 + $mode = 'test';
465 + }
460 466 }
461 - $additional_body = array(
462 - 'frm_strp_connect_mode' => $mode,
463 - );
467 +
468 + if ( self::stripe_connect_is_setup( $mode ) ) {
469 + return false;
470 + }
471 +
472 + $additional_body = self::get_body_for_mode( $mode );
464 473 $data = self::post_with_authenticated_body( 'account_status', $additional_body );
465 474 $success = false !== $data && ! empty( $data->details_submitted );
475 +
466 476 if ( $success ) {
467 477 self::set_stripe_details_as_submitted( $mode );
468 478 }
479 +
469 480 return $success;
470 481 }
471 482
472 483 /**
473 484 * @param string $mode
485 + *
474 486 * @return bool
475 487 */
476 488 public static function stripe_connect_is_setup( $mode = 'auto' ) {
477 489 return get_option( self::get_stripe_details_submitted_option_name( $mode ) );
@@ -478,8 +490,9 @@
478 490 }
479 491
480 492 /**
481 493 * @param mixed $response
494 + *
482 495 * @return bool
483 496 */
484 497 private static function validate_response( $response ) {
485 498 return ! is_wp_error( $response ) && is_array( $response ) && isset( $response['http_response'] );
@@ -484,8 +497,13 @@
484 497 private static function validate_response( $response ) {
485 498 return ! is_wp_error( $response ) && is_array( $response ) && isset( $response['http_response'] );
486 499 }
487 500
501 + /**
502 + * @param array $response
503 + *
504 + * @return object|null
505 + */
488 506 private static function pull_response_body( $response ) {
489 507 $http_response = $response['http_response'];
490 508 $response_object = $http_response->get_response_object();
491 509 return json_decode( $response_object->body );
@@ -495,8 +513,9 @@
495 513 * @return array
496 514 */
497 515 private static function build_headers_for_post() {
498 516 $password = self::maybe_get_pro_license();
517 +
499 518 if ( false === $password ) {
500 519 $password = 'lite_' . self::get_uuid();
501 520 }
502 521
@@ -518,8 +537,9 @@
518 537 * WPML alters the output of home_url.
519 538 * If it is active, use the WPML "absolute home" URL which is not modified.
520 539 *
521 540 * @param string $url
541 + *
522 542 * @return string
523 543 */
524 544 private static function maybe_fix_wpml_url( $url ) {
525 545 if ( defined( 'ICL_SITEPRESS_VERSION' ) && ! ICL_PLUGIN_INACTIVE && class_exists( 'SitePress' ) ) {
@@ -530,15 +550,16 @@
530 550 }
531 551
532 552 /**
533 553 * WPML might add a language to the url. Don't send that to the server.
554 + *
555 + * @param string $url URL.
556 + *
557 + * @return string
534 558 */
535 559 private static function strip_lang_from_url( $url ) {
536 560 $split_on_language = explode( '/?lang=', $url );
537 - if ( 2 === count( $split_on_language ) ) {
538 - $url = $split_on_language[0];
539 - }
540 - return $url;
561 + return 2 === count( $split_on_language ) ? $split_on_language[0] : $url;
541 562 }
542 563
543 564 /**
544 565 * Get a Pro license when Pro is active.
@@ -548,12 +569,14 @@
548 569 */
549 570 private static function maybe_get_pro_license() {
550 571 if ( FrmAppHelper::pro_is_installed() ) {
551 572 $pro_license = FrmAddonsController::get_pro_license();
573 +
552 574 if ( $pro_license ) {
553 575 $password = $pro_license;
554 576 }
555 577 }
578 +
556 579 return ! empty( $password ) ? $password : false;
557 580 }
558 581
559 582 /**
@@ -567,8 +590,9 @@
567 590 }
568 591
569 592 /**
570 593 * @param bool $connected
594 + *
571 595 * @return string
572 596 */
573 597 private static function get_url_for_stripe_settings( $connected ) {
574 598 return admin_url( 'admin.php?page=formidable-settings&t=stripe_settings&connected=' . intval( $connected ) );
@@ -578,8 +602,9 @@
578 602 * @return void
579 603 */
580 604 public static function render_stripe_connect_settings_container() {
581 605 self::register_settings_scripts();
606 + // phpcs:disable Generic.WhiteSpace.ScopeIndent
582 607 ?>
583 608 <tr>
584 609 <td>
585 610 <?php esc_html_e( 'Connection Status', 'formidable' ); ?>
@@ -588,8 +613,9 @@
588 613 <div id="frm_strp_settings_container"></div>
589 614 </td>
590 615 </tr>
591 616 <?php
617 + // phpcs:enable Generic.WhiteSpace.ScopeIndent
592 618 }
593 619
594 620 /**
595 621 * @return void
@@ -596,8 +622,9 @@
596 622 */
597 623 private static function render_settings() {
598 624 $modes = array( 'test', 'live' );
599 625 $html = '';
626 +
600 627 foreach ( $modes as $mode ) {
601 628 $account_id = self::get_account_id( $mode );
602 629 $connected = self::stripe_connect_is_setup( $mode );
603 630 $test = 'test' === $mode;
@@ -604,10 +631,9 @@
604 631 $title = $test ? __( 'TEST', 'formidable' ) : __( 'LIVE', 'formidable' );
605 632
606 633 ob_start();
607 634 require FrmStrpLiteAppHelper::plugin_path() . '/views/settings/connect.php';
608 - $html .= ob_get_contents();
609 - ob_end_clean();
635 + $html .= ob_get_clean();
610 636 }
611 637
612 638 $response_data = array(
613 639 'html' => $html,
@@ -615,15 +641,16 @@
615 641 wp_send_json_success( $response_data );
616 642 }
617 643
618 644 /**
619 - * @todo I can probably remove this.
620 645 * @return void
621 646 */
622 647 public static function stripe_icon() {
648 + // phpcs:disable Generic.WhiteSpace.ScopeIndent
623 649 ?>
624 - <svg height="16" aria-hidden="true" style="vertical-align:text-bottom" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 384 512"><path fill="currentColor" d="M155.3 154.6c0-22.3 18.6-30.9 48.4-30.9a320 320 0 01141.9 36.7V26.1A376.2 376.2 0 00203.8 0C88.1 0 11 60.4 11 161.4c0 157.9 216.8 132.3 216.8 200.4 0 26.4-22.9 34.9-54.7 34.9-47.2 0-108.2-19.5-156.1-45.5v128.5a396 396 0 00156 32.4c118.6 0 200.3-51 200.3-153.6 0-170.2-218-139.7-218-203.9z"/></svg>
650 + <svg height="16" aria-hidden="true" style="vertical-align:text-bottom" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 384 512"><path fill="currentColor" d="M155.3 154.6c0-22.3 18.6-30.9 48.4-30.9a320 320 0 01141.9 36.7V26.1A376.2 376.2 0 00203.8 0C88.1 0 11 60.4 11 161.4c0 157.9 216.8 132.3 216.8 200.4 0 26.4-22.9 34.9-54.7 34.9-47.2 0-108.2-19.5-156.1-45.5v128.5a396 396 0 00156 32.4c118.6 0 200.3-51 200.3-153.6 0-170.2-218-139.7-218-203.9z"/></svg><?php // phpcs:ignore SlevomatCodingStandard.Files.LineLength.LineTooLong ?>
625 651 <?php
652 + // phpcs:enable Generic.WhiteSpace.ScopeIndent
626 653 }
627 654
628 655 /**
629 656 * Check $_POST for live or test mode value as it can be updated in real time from Stripe Settings and can be configured before the update is saved.
@@ -634,8 +661,9 @@
634 661 // phpcs:ignore WordPress.Security.NonceVerification.Missing
635 662 if ( empty( $_POST ) || ! array_key_exists( 'testMode', $_POST ) ) {
636 663 return FrmStrpLiteAppHelper::active_mode();
637 664 }
665 +
638 666 $test_mode = FrmAppHelper::get_param( 'testMode', '', 'post', 'absint' );
639 667 return $test_mode ? 'test' : 'live';
640 668 }
641 669
@@ -642,14 +670,15 @@
642 670 /**
643 671 * @return void
644 672 */
645 673 private static function register_settings_scripts() {
646 - wp_register_script( 'formidable_stripe_settings', FrmStrpLiteAppHelper::plugin_url() . '/js/connect_settings.js', array( 'formidable_dom' ), FrmAppHelper::plugin_version(), true );
674 + wp_register_script( 'formidable_stripe_settings', FrmStrpLiteAppHelper::plugin_url() . '/js/connect_settings.js', array( 'formidable_dom' ), FrmAppHelper::plugin_version(), true ); // phpcs:ignore SlevomatCodingStandard.Files.LineLength.LineTooLong
647 675 wp_enqueue_script( 'formidable_stripe_settings' );
648 676 }
649 677
650 678 /**
651 679 * @param string $mode
680 + *
652 681 * @return bool|string
653 682 */
654 683 public static function get_account_id( $mode = 'auto' ) {
655 684 return get_option( self::get_account_id_option_name( $mode ) );
@@ -656,24 +685,25 @@
656 685 }
657 686
658 687 /**
659 688 * @param array $options
689 + *
660 690 * @return false|string
661 691 */
662 692 public static function get_customer_id( $options ) {
663 693 $data = self::post_with_authenticated_body( 'get_customer', compact( 'options' ) );
664 694 $success = false !== $data;
695 +
665 696 if ( ! $success ) {
666 - return ! empty( self::$latest_error_from_stripe_connect ) ? self::$latest_error_from_stripe_connect : false;
697 + return self::$latest_error_from_stripe_connect ? self::$latest_error_from_stripe_connect : false;
667 698 }
668 - if ( empty( $data->customer_id ) ) {
669 - return false;
670 - }
671 - return $data->customer_id;
699 +
700 + return ! empty( $data->customer_id ) ? $data->customer_id : false;
672 701 }
673 702
674 703 /**
675 704 * @param string $customer_id
705 + *
676 706 * @return bool
677 707 */
678 708 public static function validate_customer( $customer_id ) {
679 709 $data = self::post_with_authenticated_body( 'validate_customer', compact( 'customer_id' ) );
@@ -688,16 +718,19 @@
688 718 */
689 719 private static function post_with_authenticated_body( $action, $additional_body = array() ) {
690 720 $body = array_merge( self::get_standard_authenticated_body(), $additional_body );
691 721 $response = self::post_to_connect_server( $action, $body );
722 +
692 723 if ( is_object( $response ) ) {
693 724 return $response;
694 725 }
726 +
695 727 if ( is_array( $response ) ) {
696 - // reformat empty arrays as empty objects
697 - // if the response is an array, it's because it's empty. Everything with data is already an object.
728 + // Reformat empty arrays as empty objects
729 + // If the response is an array, it's because it's empty. Everything with data is already an object.
698 730 return new stdClass();
699 731 }
732 +
700 733 if ( is_string( $response ) ) {
701 734 self::$latest_error_from_stripe_connect = $response;
702 735 FrmTransLiteLog::log_message( 'Stripe Connect Error', $response );
703 736 } else {
@@ -702,45 +735,47 @@
702 735 FrmTransLiteLog::log_message( 'Stripe Connect Error', $response );
703 736 } else {
704 737 self::$latest_error_from_stripe_connect = '';
705 738 }
739 +
706 740 return false;
707 741 }
708 742
709 743 /**
710 744 * @param array $new_charge
745 + *
711 746 * @return mixed
712 747 */
713 748 public static function create_intent( $new_charge ) {
714 749 $data = self::post_with_authenticated_body( 'create_intent', compact( 'new_charge' ) );
715 750 $success = false !== $data;
716 - if ( ! $success ) {
717 - return false;
718 - }
719 - return $data;
751 +
752 + return $success ? $data : false;
720 753 }
721 754
722 755 /**
723 756 * @param string $payment_id
757 + *
724 758 * @return bool
725 759 */
726 760 public static function refund_payment( $payment_id ) {
727 - $data = self::post_with_authenticated_body( 'refund_payment', compact( 'payment_id' ) );
728 - $refunded = is_object( $data );
729 - return $refunded;
761 + $data = self::post_with_authenticated_body( 'refund_payment', compact( 'payment_id' ) );
762 + return is_object( $data );
730 763 }
731 764
732 765 /**
733 766 * @param array $new_charge
767 + *
734 768 * @return mixed
735 769 */
736 770 public static function create_subscription( $new_charge ) {
737 771 $data = self::post_with_authenticated_body( 'create_subscription', compact( 'new_charge' ) );
772 +
738 773 if ( is_object( $data ) ) {
739 774 return $data;
740 775 }
741 776
742 - if ( isset( self::$latest_error_from_stripe_connect ) && 0 === strpos( self::$latest_error_from_stripe_connect, 'No such plan: ' ) ) {
777 + if ( isset( self::$latest_error_from_stripe_connect ) && str_starts_with( self::$latest_error_from_stripe_connect, 'No such plan: ' ) ) {
743 778 return self::$latest_error_from_stripe_connect;
744 779 }
745 780
746 781 return false;
@@ -748,19 +783,20 @@
748 783
749 784 /**
750 785 * @param string $sub_id
751 786 * @param false|string $customer_id if specified, this will enforce a customer id match (bypassed for users with administrator permission).
787 + *
752 788 * @return bool
753 789 */
754 790 public static function cancel_subscription( $sub_id, $customer_id = false ) {
755 791 $cancel_at_period_end = FrmStrpLiteSubscriptionHelper::should_cancel_at_period_end();
756 792 $data = self::post_with_authenticated_body( 'cancel_subscription', compact( 'sub_id', 'customer_id', 'cancel_at_period_end' ) );
757 - $canceled = false !== $data;
758 - return $canceled;
793 + return false !== $data;
759 794 }
760 795
761 796 /**
762 797 * @param string $payment_id
798 + *
763 799 * @return mixed
764 800 */
765 801 public static function get_intent( $payment_id ) {
766 802 return self::post_with_authenticated_body( 'get_intent', compact( 'payment_id' ) );
@@ -769,31 +805,29 @@
769 805 /**
770 806 * @return false|object
771 807 */
772 808 public static function get_customer_subscriptions() {
773 - $user_id = get_current_user_id();
774 809 $meta_name = FrmStrpLiteAppHelper::get_customer_id_meta_name();
775 - $customer_id = get_user_meta( $user_id, $meta_name, true );
810 + $customer_id = get_user_meta( get_current_user_id(), $meta_name, true );
776 811 $data = self::post_with_authenticated_body( 'get_customer_subscriptions', compact( 'customer_id' ) );
777 812
778 - if ( false === $data ) {
779 - return false;
780 - }
781 -
782 - return $data->subscriptions;
813 + return false === $data ? false : $data->subscriptions;
783 814 }
784 815
785 816 /**
786 817 * @param string $event_id
818 + *
787 819 * @return false|object
788 820 */
789 821 public static function get_event( $event_id ) {
790 822 $event = wp_cache_get( $event_id, 'frm_strp' );
823 +
791 824 if ( is_object( $event ) ) {
792 825 return $event;
793 826 }
794 827
795 828 $event = self::post_with_authenticated_body( 'get_event', compact( 'event_id' ) );
829 +
796 830 if ( false === $event || empty( $event->event ) ) {
797 831 return false;
798 832 }
799 833
@@ -802,8 +836,9 @@
802 836 }
803 837
804 838 /**
805 839 * @param string $event_id
840 + *
806 841 * @return mixed
807 842 */
808 843 public static function process_event( $event_id ) {
809 844 return self::post_with_authenticated_body( 'process_event', compact( 'event_id' ) );
@@ -810,20 +845,24 @@
810 845 }
811 846
812 847 /**
813 848 * @param array $plan
849 + *
814 850 * @return false|string
815 851 */
816 852 public static function maybe_create_plan( $plan ) {
817 853 $data = self::post_with_authenticated_body( 'maybe_create_plan', compact( 'plan' ) );
854 +
818 855 if ( false === $data || empty( $data->plan_id ) ) {
819 856 return false;
820 857 }
858 +
821 859 return $data->plan_id;
822 860 }
823 861
824 862 /**
825 863 * @param array $plan
864 + *
826 865 * @return mixed
827 866 */
828 867 public static function create_plan( $plan ) {
829 868 return self::post_with_authenticated_body( 'create_plan', compact( 'plan' ) );
@@ -831,14 +870,14 @@
831 870
832 871 /**
833 872 * @param string $intent_id
834 873 * @param array $data
874 + *
835 875 * @return bool
836 876 */
837 877 public static function update_intent( $intent_id, $data ) {
838 - $data = self::post_with_authenticated_body( 'update_intent', compact( 'intent_id', 'data' ) );
839 - $success = false !== $data;
840 - return $success;
878 + $data = self::post_with_authenticated_body( 'update_intent', compact( 'intent_id', 'data' ) );
879 + return false !== $data;
841 880 }
842 881
843 882 /**
844 883 * @return array
@@ -844,11 +883,13 @@
844 883 * @return array
845 884 */
846 885 public static function get_unprocessed_event_ids() {
847 886 $data = self::post_with_authenticated_body( 'get_unprocessed_event_ids' );
887 +
848 888 if ( false === $data || empty( $data->event_ids ) ) {
849 889 return array();
850 890 }
891 +
851 892 return $data->event_ids;
852 893 }
853 894
854 895 /**
@@ -858,8 +899,9 @@
858 899 * @since 6.5, introduced in v3.0 of the Stripe add on.
859 900 *
860 901 * @param string $customer_id
861 902 * @param array|false $payment_method_types
903 + *
862 904 * @return false|object|string
863 905 */
864 906 public static function create_setup_intent( $customer_id, $payment_method_types = false ) {
865 907 $charge_data = array( 'customer' => $customer_id );
@@ -880,8 +922,9 @@
880 922 *
881 923 * @since 6.5, introduced in v3.0 of the Stripe add on.
882 924 *
883 925 * @param string $setup_id
926 + *
884 927 * @return false|object|string
885 928 */
886 929 public static function get_setup_intent( $setup_id ) {
887 930 return self::post_with_authenticated_body( 'get_setup_intent', compact( 'setup_id' ) );
@@ -899,14 +942,14 @@
899 942 }
900 943
901 944 $site_identifier = FrmAppHelper::get_post_param( 'site_identifier' );
902 945 $usage = new FrmUsage();
903 - $uuid = $usage->uuid();
904 946
905 947 update_option( $option_name, time() );
906 948
907 - if ( $site_identifier === $uuid ) {
949 + if ( $site_identifier === $usage->uuid() ) {
908 950 wp_send_json_success();
909 951 }
952 +
910 953 wp_send_json_error();
911 954 }
912 955 }