| @@ -153,12 +153,8 @@ | ||
| 153 | 153 | $body = array_merge( $body, $additional_body ); |
| 154 | 154 | $url = self::get_url_to_connect_server(); |
| 155 | 155 | $headers = self::build_headers_for_post(); |
| 156 | 156 | |
| 157 | - if ( ! $headers ) { | |
| 158 | - return 'Unable to build headers for post. Is your pro license configured properly?'; | |
| 159 | - } | |
| 160 | - | |
| 161 | 157 | // (Seconds) default timeout is 5. we want a bit more time to work with. |
| 162 | 158 | $timeout = 45; |
| 163 | 159 | |
| 164 | 160 | self::try_to_extend_server_timeout( $timeout ); |
| @@ -266,9 +262,9 @@ | ||
| 266 | 262 | */ |
| 267 | 263 | private static function handle_disconnect() { |
| 268 | 264 | self::disconnect(); |
| 269 | 265 | self::reset_stripe_connect_integration(); |
| 270 | - self::maybe_unschedule_crons(); | |
| 266 | + FrmTransLiteAppHelper::trigger_gateway_disconnected_hook( 'stripe', self::get_mode_value_from_post() ); | |
| 271 | 267 | wp_send_json_success(); |
| 272 | 268 | } |
| 273 | 269 | |
| 274 | 270 | /** |
| @@ -287,38 +283,16 @@ | ||
| 287 | 283 | /** |
| 288 | 284 | * @return false|object |
| 289 | 285 | */ |
| 290 | 286 | private static function disconnect() { |
| 291 | - $additional_body = array( | |
| 292 | - 'frm_strp_connect_mode' => self::get_mode_value_from_post(), | |
| 293 | - ); | |
| 287 | + $mode = self::get_mode_value_from_post(); | |
| 288 | + $additional_body = self::get_body_for_mode( $mode ); | |
| 294 | 289 | return self::post_with_authenticated_body( 'disconnect', $additional_body ); |
| 295 | 290 | } |
| 296 | 291 | |
| 297 | 292 | /** |
| 298 | - * Stop the payment cron once all Stripe connections have been disconnected. | |
| 299 | - * | |
| 300 | 293 | * @since 6.5 |
| 301 | 294 | * |
| 302 | - * @return void | |
| 303 | - */ | |
| 304 | - private static function maybe_unschedule_crons() { | |
| 305 | - if ( self::at_least_one_mode_is_setup() ) { | |
| 306 | - // Don't unschedule if a mode is still on. | |
| 307 | - return; | |
| 308 | - } | |
| 309 | - | |
| 310 | - $event = 'frm_payment_cron'; | |
| 311 | - $timestamp = wp_next_scheduled( $event ); | |
| 312 | - | |
| 313 | - if ( false !== $timestamp ) { | |
| 314 | - wp_unschedule_event( $timestamp, $event ); | |
| 315 | - } | |
| 316 | - } | |
| 317 | - | |
| 318 | - /** | |
| 319 | - * @since 6.5 | |
| 320 | - * | |
| 321 | 295 | * @return bool |
| 322 | 296 | */ |
| 323 | 297 | public static function at_least_one_mode_is_setup() { |
| 324 | 298 | return self::stripe_connect_is_setup( 'test' ) || self::stripe_connect_is_setup( 'live' ); |
| @@ -327,16 +301,15 @@ | ||
| 327 | 301 | /** |
| 328 | 302 | * @return void |
| 329 | 303 | */ |
| 330 | 304 | private static function handle_reauth() { |
| 331 | - $additional_body = array( | |
| 332 | - 'frm_strp_connect_mode' => self::get_mode_value_from_post(), | |
| 333 | - ); | |
| 305 | + $mode = self::get_mode_value_from_post(); | |
| 306 | + $additional_body = self::get_body_for_mode( $mode ); | |
| 334 | 307 | $data = self::post_with_authenticated_body( 'reauth', $additional_body ); |
| 335 | 308 | |
| 336 | 309 | if ( false === $data ) { |
| 337 | 310 | // Check account status. |
| 338 | - if ( self::check_server_for_connected_account_status() ) { | |
| 311 | + if ( self::check_server_for_connected_account_status( $mode ) ) { | |
| 339 | 312 | wp_send_json_success(); |
| 340 | 313 | } |
| 341 | 314 | |
| 342 | 315 | wp_send_json_error(); |
| @@ -351,13 +324,26 @@ | ||
| 351 | 324 | /** |
| 352 | 325 | * @return array |
| 353 | 326 | */ |
| 354 | 327 | private static function get_standard_authenticated_body() { |
| 355 | - $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 ) { | |
| 356 | 341 | return array( |
| 357 | - 'account_id' => get_option( self::get_account_id_option_name( $mode ) ), | |
| 358 | - 'server_password' => get_option( self::get_server_side_token_option_name( $mode ) ), | |
| 359 | - '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, | |
| 360 | 346 | ); |
| 361 | 347 | } |
| 362 | 348 | |
| 363 | 349 | private static function redirect() { |
| @@ -465,20 +451,26 @@ | ||
| 465 | 451 | return $data->redirect_url; |
| 466 | 452 | } |
| 467 | 453 | |
| 468 | 454 | /** |
| 455 | + * @param string $mode | |
| 456 | + * | |
| 469 | 457 | * @return bool true if our account is onboarded |
| 470 | 458 | */ |
| 471 | - public static function check_server_for_connected_account_status() { | |
| 472 | - $mode = FrmAppHelper::get_param( 'mode', '', 'get', 'sanitize_text_field' ); | |
| 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' ); | |
| 473 | 462 | |
| 474 | - if ( 'live' !== $mode ) { | |
| 475 | - $mode = 'test'; | |
| 463 | + if ( 'live' !== $mode ) { | |
| 464 | + $mode = 'test'; | |
| 465 | + } | |
| 476 | 466 | } |
| 477 | 467 | |
| 478 | - $additional_body = array( | |
| 479 | - 'frm_strp_connect_mode' => $mode, | |
| 480 | - ); | |
| 468 | + if ( self::stripe_connect_is_setup( $mode ) ) { | |
| 469 | + return false; | |
| 470 | + } | |
| 471 | + | |
| 472 | + $additional_body = self::get_body_for_mode( $mode ); | |
| 481 | 473 | $data = self::post_with_authenticated_body( 'account_status', $additional_body ); |
| 482 | 474 | $success = false !== $data && ! empty( $data->details_submitted ); |
| 483 | 475 | |
| 484 | 476 | if ( $success ) { |
| @@ -701,9 +693,9 @@ | ||
| 701 | 693 | $data = self::post_with_authenticated_body( 'get_customer', compact( 'options' ) ); |
| 702 | 694 | $success = false !== $data; |
| 703 | 695 | |
| 704 | 696 | if ( ! $success ) { |
| 705 | - 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; | |
| 706 | 698 | } |
| 707 | 699 | |
| 708 | 700 | return ! empty( $data->customer_id ) ? $data->customer_id : false; |
| 709 | 701 | } |
| @@ -813,11 +805,10 @@ | ||
| 813 | 805 | /** |
| 814 | 806 | * @return false|object |
| 815 | 807 | */ |
| 816 | 808 | public static function get_customer_subscriptions() { |
| 817 | - $user_id = get_current_user_id(); | |
| 818 | 809 | $meta_name = FrmStrpLiteAppHelper::get_customer_id_meta_name(); |
| 819 | - $customer_id = get_user_meta( $user_id, $meta_name, true ); | |
| 810 | + $customer_id = get_user_meta( get_current_user_id(), $meta_name, true ); | |
| 820 | 811 | $data = self::post_with_authenticated_body( 'get_customer_subscriptions', compact( 'customer_id' ) ); |
| 821 | 812 | |
| 822 | 813 | return false === $data ? false : $data->subscriptions; |
| 823 | 814 | } |
| @@ -951,13 +942,12 @@ | ||
| 951 | 942 | } |
| 952 | 943 | |
| 953 | 944 | $site_identifier = FrmAppHelper::get_post_param( 'site_identifier' ); |
| 954 | 945 | $usage = new FrmUsage(); |
| 955 | - $uuid = $usage->uuid(); | |
| 956 | 946 | |
| 957 | 947 | update_option( $option_name, time() ); |
| 958 | 948 | |
| 959 | - if ( $site_identifier === $uuid ) { | |
| 949 | + if ( $site_identifier === $usage->uuid() ) { | |
| 960 | 950 | wp_send_json_success(); |
| 961 | 951 | } |
| 962 | 952 | |
| 963 | 953 | wp_send_json_error(); |