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 | square/helpers/FrmSquareLiteConnectHelper.php +37 -19 6.31 → trunk View file →
@@ -134,9 +134,9 @@
134 134 /**
135 135 * @return false|string
136 136 */
137 137 public static function get_oauth_redirect_url() {
138 - $mode = FrmAppHelper::get_post_param( 'mode', 'test', 'sanitize_text_field' );
138 + $mode = self::get_mode_value_from_post();
139 139
140 140 if ( self::get_merchant_id( $mode ) ) {
141 141 // Do not allow for initialize if there is already a configured account id.
142 142 return false;
@@ -550,32 +550,52 @@
550 550 /**
551 551 * @return array
552 552 */
553 553 private static function get_standard_authenticated_body() {
554 - $mode = self::get_mode_value_from_post();
555 - return array(
556 - 'merchant_id' => get_option( self::get_merchant_id_option_name( $mode ) ),
557 - 'server_password' => get_option( self::get_server_side_token_option_name( $mode ) ),
558 - 'client_password' => get_option( self::get_client_side_token_option_name( $mode ) ),
559 - );
554 + return self::get_body_for_mode( FrmSquareLiteAppHelper::active_mode() );
560 555 }
561 556
562 557 /**
563 - * 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.
558 + * Check $_POST for live or test mode value as it can be updated in real time from Square Settings and can be configured before the update is saved.
559 + * The connect request sends a 'mode' string, and the disconnect request sends a 'testMode' flag, so check for both.
564 560 *
565 561 * @return string 'test' or 'live'
566 562 */
567 563 private static function get_mode_value_from_post() {
568 564 // phpcs:ignore WordPress.Security.NonceVerification.Missing
569 - if ( empty( $_POST ) || ! array_key_exists( 'testMode', $_POST ) ) {
570 - return FrmSquareLiteAppHelper::active_mode();
565 + if ( array_key_exists( 'mode', $_POST ) ) {
566 + $mode = FrmAppHelper::get_post_param( 'mode', '', 'sanitize_text_field' );
567 + return 'test' === $mode ? 'test' : 'live';
571 568 }
572 569
573 - $test_mode = FrmAppHelper::get_param( 'testMode', '', 'post', 'absint' );
574 - return $test_mode ? 'test' : 'live';
570 + // phpcs:ignore WordPress.Security.NonceVerification.Missing
571 + if ( array_key_exists( 'testMode', $_POST ) ) {
572 + $test_mode = FrmAppHelper::get_post_param( 'testMode', '', 'absint' );
573 + return $test_mode ? 'test' : 'live';
574 + }
575 +
576 + return FrmSquareLiteAppHelper::active_mode();
575 577 }
576 578
577 579 /**
580 + * Get the standard body with account id, mode, and passwords to send to the connect server.
581 + *
582 + * @since 6.32.1
583 + *
584 + * @param string $mode 'live' or 'test'.
585 + *
586 + * @return array
587 + */
588 + private static function get_body_for_mode( $mode ) {
589 + return array(
590 + 'merchant_id' => get_option( self::get_merchant_id_option_name( $mode ) ),
591 + 'server_password' => get_option( self::get_server_side_token_option_name( $mode ) ),
592 + 'client_password' => get_option( self::get_client_side_token_option_name( $mode ) ),
593 + 'frm_square_api_mode' => $mode,
594 + );
595 + }
596 +
597 + /**
578 598 * @return string|null
579 599 */
580 600 public static function get_latest_error_from_square_api() {
581 601 return self::$latest_error_from_square_api;
@@ -617,10 +637,9 @@
617 637
618 638 $request_body = array();
619 639
620 640 if ( 'auto' !== $mode ) {
621 - $_POST['testMode'] = 'test' === $mode ? 1 : 0;
622 - $request_body['frm_square_api_mode'] = $mode;
641 + $request_body = self::get_body_for_mode( $mode );
623 642 }
624 643
625 644 $response = self::post_with_authenticated_body( 'get_location_id', $request_body );
626 645
@@ -706,8 +725,9 @@
706 725
707 726 public static function handle_disconnect() {
708 727 self::disconnect();
709 728 self::reset_square_api_integration();
729 + FrmTransLiteAppHelper::trigger_gateway_disconnected_hook( 'square', self::get_mode_value_from_post() );
710 730 wp_send_json_success();
711 731 }
712 732
713 733 /**
@@ -713,11 +733,10 @@
713 733 /**
714 734 * @return false|object
715 735 */
716 736 private static function disconnect() {
717 - $additional_body = array(
718 - 'frm_square_api_mode' => self::get_mode_value_from_post(),
719 - );
737 + $mode = self::get_mode_value_from_post();
738 + $additional_body = self::get_body_for_mode( $mode );
720 739 return self::post_with_authenticated_body( 'disconnect', $additional_body );
721 740 }
722 741
723 742 /**
@@ -751,10 +770,9 @@
751 770
752 771 $request_body = array();
753 772
754 773 if ( 'auto' !== $mode ) {
755 - $_POST['testMode'] = 'test' === $mode ? 1 : 0;
756 - $request_body['frm_square_api_mode'] = $mode;
774 + $request_body = self::get_body_for_mode( $mode );
757 775 }
758 776
759 777 $response = self::post_with_authenticated_body( 'get_merchant_currency', $request_body );
760 778