| @@ -71,9 +71,9 @@ | ||
| 71 | 71 | private static function render_settings_for_mode( $mode ) { |
| 72 | 72 | // phpcs:disable Generic.WhiteSpace.ScopeIndent |
| 73 | 73 | ?> |
| 74 | 74 | <div class="frm-card-item frm4"> |
| 75 | - <div class="frm-flex-col"> | |
| 75 | + <div class="frm-flex-col" style="width: 100%;"> | |
| 76 | 76 | <div> |
| 77 | 77 | <span style="font-size: var(--text-lg); font-weight: 500; margin-right: 5px;"> |
| 78 | 78 | <?php |
| 79 | 79 | echo $mode === 'test' ? esc_html__( 'Test', 'formidable' ) : esc_html__( 'Live', 'formidable' ); |
| @@ -124,12 +124,11 @@ | ||
| 124 | 124 | /** |
| 125 | 125 | * @return void |
| 126 | 126 | */ |
| 127 | 127 | private static function register_settings_scripts() { |
| 128 | - $script_url = FrmSquareLiteAppHelper::plugin_url() . '/js/settings.js'; | |
| 129 | - $dependencies = array( 'formidable_dom' ); | |
| 130 | - $plugin_version = FrmAppHelper::plugin_version(); | |
| 131 | - wp_register_script( 'formidable_square_settings', $script_url, $dependencies, $plugin_version, true ); | |
| 128 | + $script_url = FrmSquareLiteAppHelper::plugin_url() . '/js/settings.js'; | |
| 129 | + $dependencies = array( 'formidable_dom' ); | |
| 130 | + wp_register_script( 'formidable_square_settings', $script_url, $dependencies, FrmAppHelper::plugin_version(), true ); | |
| 132 | 131 | wp_enqueue_script( 'formidable_square_settings' ); |
| 133 | 132 | } |
| 134 | 133 | |
| 135 | 134 | /** |
| @@ -135,9 +134,9 @@ | ||
| 135 | 134 | /** |
| 136 | 135 | * @return false|string |
| 137 | 136 | */ |
| 138 | 137 | public static function get_oauth_redirect_url() { |
| 139 | - $mode = FrmAppHelper::get_post_param( 'mode', 'test', 'sanitize_text_field' ); | |
| 138 | + $mode = self::get_mode_value_from_post(); | |
| 140 | 139 | |
| 141 | 140 | if ( self::get_merchant_id( $mode ) ) { |
| 142 | 141 | // Do not allow for initialize if there is already a configured account id. |
| 143 | 142 | return false; |
| @@ -182,12 +181,8 @@ | ||
| 182 | 181 | $body = array_merge( $body, $additional_body ); |
| 183 | 182 | $url = self::get_url_to_connect_server(); |
| 184 | 183 | $headers = self::build_headers_for_post(); |
| 185 | 184 | |
| 186 | - if ( ! $headers ) { | |
| 187 | - return 'Unable to build headers for post. Is your pro license configured properly?'; | |
| 188 | - } | |
| 189 | - | |
| 190 | 185 | // (Seconds) default timeout is 5. we want a bit more time to work with. |
| 191 | 186 | $timeout = 45; |
| 192 | 187 | |
| 193 | 188 | self::try_to_extend_server_timeout( $timeout ); |
| @@ -555,32 +550,52 @@ | ||
| 555 | 550 | /** |
| 556 | 551 | * @return array |
| 557 | 552 | */ |
| 558 | 553 | private static function get_standard_authenticated_body() { |
| 559 | - $mode = self::get_mode_value_from_post(); | |
| 560 | - return array( | |
| 561 | - 'merchant_id' => get_option( self::get_merchant_id_option_name( $mode ) ), | |
| 562 | - 'server_password' => get_option( self::get_server_side_token_option_name( $mode ) ), | |
| 563 | - 'client_password' => get_option( self::get_client_side_token_option_name( $mode ) ), | |
| 564 | - ); | |
| 554 | + return self::get_body_for_mode( FrmSquareLiteAppHelper::active_mode() ); | |
| 565 | 555 | } |
| 566 | 556 | |
| 567 | 557 | /** |
| 568 | - * 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. | |
| 569 | 560 | * |
| 570 | 561 | * @return string 'test' or 'live' |
| 571 | 562 | */ |
| 572 | 563 | private static function get_mode_value_from_post() { |
| 573 | 564 | // phpcs:ignore WordPress.Security.NonceVerification.Missing |
| 574 | - if ( empty( $_POST ) || ! array_key_exists( 'testMode', $_POST ) ) { | |
| 575 | - 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'; | |
| 576 | 568 | } |
| 577 | 569 | |
| 578 | - $test_mode = FrmAppHelper::get_param( 'testMode', '', 'post', 'absint' ); | |
| 579 | - 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(); | |
| 580 | 577 | } |
| 581 | 578 | |
| 582 | 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 | + /** | |
| 583 | 598 | * @return string|null |
| 584 | 599 | */ |
| 585 | 600 | public static function get_latest_error_from_square_api() { |
| 586 | 601 | return self::$latest_error_from_square_api; |
| @@ -588,12 +603,13 @@ | ||
| 588 | 603 | |
| 589 | 604 | /** |
| 590 | 605 | * @param string $receipt_id |
| 591 | 606 | * |
| 592 | - * @return false|object | |
| 607 | + * @return bool | |
| 593 | 608 | */ |
| 594 | 609 | public static function refund_payment( $receipt_id ) { |
| 595 | - return self::post_with_authenticated_body( 'refund_payment', array( 'receipt_id' => $receipt_id ) ); | |
| 610 | + $data = self::post_with_authenticated_body( 'refund_payment', array( 'receipt_id' => $receipt_id ) ); | |
| 611 | + return is_object( $data ); | |
| 596 | 612 | } |
| 597 | 613 | |
| 598 | 614 | /** |
| 599 | 615 | * @param array $info |
| @@ -621,10 +637,9 @@ | ||
| 621 | 637 | |
| 622 | 638 | $request_body = array(); |
| 623 | 639 | |
| 624 | 640 | if ( 'auto' !== $mode ) { |
| 625 | - $_POST['testMode'] = 'test' === $mode ? 1 : 0; | |
| 626 | - $request_body['frm_square_api_mode'] = $mode; | |
| 641 | + $request_body = self::get_body_for_mode( $mode ); | |
| 627 | 642 | } |
| 628 | 643 | |
| 629 | 644 | $response = self::post_with_authenticated_body( 'get_location_id', $request_body ); |
| 630 | 645 | |
| @@ -701,17 +716,18 @@ | ||
| 701 | 716 | |
| 702 | 717 | /** |
| 703 | 718 | * @param string $subscription_id |
| 704 | 719 | * |
| 705 | - * @return false|object | |
| 720 | + * @return bool | |
| 706 | 721 | */ |
| 707 | 722 | public static function cancel_subscription( $subscription_id ) { |
| 708 | - return self::post_with_authenticated_body( 'cancel_subscription', compact( 'subscription_id' ) ); | |
| 723 | + return false !== self::post_with_authenticated_body( 'cancel_subscription', compact( 'subscription_id' ) ); | |
| 709 | 724 | } |
| 710 | 725 | |
| 711 | 726 | public static function handle_disconnect() { |
| 712 | 727 | self::disconnect(); |
| 713 | 728 | self::reset_square_api_integration(); |
| 729 | + FrmTransLiteAppHelper::trigger_gateway_disconnected_hook( 'square', self::get_mode_value_from_post() ); | |
| 714 | 730 | wp_send_json_success(); |
| 715 | 731 | } |
| 716 | 732 | |
| 717 | 733 | /** |
| @@ -717,11 +733,10 @@ | ||
| 717 | 733 | /** |
| 718 | 734 | * @return false|object |
| 719 | 735 | */ |
| 720 | 736 | private static function disconnect() { |
| 721 | - $additional_body = array( | |
| 722 | - 'frm_square_api_mode' => self::get_mode_value_from_post(), | |
| 723 | - ); | |
| 737 | + $mode = self::get_mode_value_from_post(); | |
| 738 | + $additional_body = self::get_body_for_mode( $mode ); | |
| 724 | 739 | return self::post_with_authenticated_body( 'disconnect', $additional_body ); |
| 725 | 740 | } |
| 726 | 741 | |
| 727 | 742 | /** |
| @@ -755,10 +770,9 @@ | ||
| 755 | 770 | |
| 756 | 771 | $request_body = array(); |
| 757 | 772 | |
| 758 | 773 | if ( 'auto' !== $mode ) { |
| 759 | - $_POST['testMode'] = 'test' === $mode ? 1 : 0; | |
| 760 | - $request_body['frm_square_api_mode'] = $mode; | |
| 774 | + $request_body = self::get_body_for_mode( $mode ); | |
| 761 | 775 | } |
| 762 | 776 | |
| 763 | 777 | $response = self::post_with_authenticated_body( 'get_merchant_currency', $request_body ); |
| 764 | 778 | |
| @@ -791,13 +805,12 @@ | ||
| 791 | 805 | } |
| 792 | 806 | |
| 793 | 807 | $site_identifier = FrmAppHelper::get_post_param( 'site_identifier' ); |
| 794 | 808 | $usage = new FrmUsage(); |
| 795 | - $uuid = $usage->uuid(); | |
| 796 | 809 | |
| 797 | 810 | update_option( $option_name, time() ); |
| 798 | 811 | |
| 799 | - if ( $site_identifier === $uuid ) { | |
| 812 | + if ( $site_identifier === $usage->uuid() ) { | |
| 800 | 813 | wp_send_json_success(); |
| 801 | 814 | } |
| 802 | 815 | |
| 803 | 816 | wp_send_json_error(); |