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/controllers/FrmTransLiteSubscriptionsController.php +56 -6 6.30 → trunk View file →
@@ -92,13 +92,14 @@
92 92 * Handle routing to cancel a subscription.
93 93 *
94 94 * @return void
95 95 */
96 - public static function cancel_subscription() {
96 + public static function cancel_subscription() { // phpcs:ignore SlevomatCodingStandard.Complexity.Cognitive.ComplexityTooHigh
97 97 check_ajax_referer( 'frm_trans_ajax', 'nonce' );
98 98 FrmAppHelper::permission_check( 'frm_edit_entries' );
99 99
100 - $sub_id = FrmAppHelper::get_param( 'sub', '', 'get', 'sanitize_text_field' );
100 + $canceled = false;
101 + $sub_id = FrmAppHelper::get_param( 'sub', '', 'get', 'sanitize_text_field' );
101 102
102 103 if ( $sub_id ) {
103 104 $frm_sub = new FrmTransLiteSubscription();
104 105 $sub = $frm_sub->get_one( $sub_id );
@@ -103,8 +104,11 @@
103 104 $frm_sub = new FrmTransLiteSubscription();
104 105 $sub = $frm_sub->get_one( $sub_id );
105 106
106 107 if ( $sub ) {
108 + $reason = '';
109 + $debug_id = '';
110 +
107 111 switch ( $sub->paysys ) {
108 112 case 'stripe':
109 113 $canceled = FrmStrpLiteAppHelper::call_stripe_helper_class( 'cancel_subscription', $sub->sub_id );
110 114 break;
@@ -110,12 +114,38 @@
110 114 break;
111 115 case 'square':
112 116 $canceled = FrmSquareLiteConnectHelper::cancel_subscription( $sub->sub_id );
113 117 break;
118 + case 'paypal':
119 + $response = FrmPayPalLiteConnectHelper::cancel_subscription( $sub->sub_id );
120 +
121 + // Check for structured error response with message and debug_id (array or object)
122 + $reason = '';
123 + $debug_id = '';
124 + $canceled = false !== $response;
125 +
126 + if ( is_array( $response ) || is_object( $response ) ) {
127 + // Extract error details without type checks to avoid Mago type narrowing
128 + $response_array = is_array( $response ) ? $response : (array) $response;
129 + $reason = $response_array['message'] ?? '';
130 + // PayPal API returns debug_id (snake_case) in some cases and debugId (camelCase) in others
131 + $debug_id = $response_array['debug_id'] ?? $response_array['debugId'] ?? '';
132 +
133 + // If there's an error message or debug_id, the cancellation failed
134 + if ( $reason || $debug_id ) {
135 + $canceled = false;
136 + }
137 + } elseif ( false === $response ) {
138 + // Response is false, get error from static properties
139 + $reason = FrmPayPalLiteConnectHelper::get_latest_error_from_paypal_api();
140 + $debug_id = FrmPayPalLiteConnectHelper::get_latest_debug_id_from_paypal_api();
141 + $canceled = false;
142 + }
143 + break;
114 144 default:
115 145 $canceled = false;
116 146 break;
117 - }
147 + }//end switch
118 148
119 149 if ( $canceled ) {
120 150 self::change_subscription_status(
121 151 array(
@@ -124,10 +154,25 @@
124 154 )
125 155 );
126 156
127 157 $message = __( 'Canceled', 'formidable' );
158 + // phpcs:ignore Universal.ControlStructures.DisallowLonelyIf.Found
128 159 } else {
129 - $message = __( 'Failed', 'formidable' );
160 + // If the reason is already a complete error message, use it directly
161 + // instead of wrapping it redundantly in "Failed (...)"
162 + if ( $reason && ! preg_match( '/^[A-Z_]+$/', $reason ) ) {
163 + $message = $reason;
164 + } else {
165 + $message = __( 'Failed', 'formidable' );
166 +
167 + if ( ! empty( $reason ) ) {
168 + $message .= ' (' . $reason . ')';
169 + }
170 + }
171 + }//end if
172 +
173 + if ( $debug_id ) {
174 + $message .= '<br><br>Debug ID: ' . esc_html( $debug_id );
130 175 }
131 176 } else {
132 177 $message = __( 'That subscription was not found', 'formidable' );
133 178 }//end if
@@ -134,10 +179,15 @@
134 179 } else {
135 180 $message = __( 'Oops! No subscription was selected for cancelation.', 'formidable' );
136 181 }//end if
137 182
138 - echo esc_html( $message );
139 - wp_die();
183 + wp_die(
184 + sprintf(
185 + '<div class="%1$s">%2$s</div>',
186 + $canceled ? 'frm_updated_message' : 'frm_error_style',
187 + wp_kses_post( $message )
188 + )
189 + );
140 190 }
141 191
142 192 /**
143 193 * @since 6.5, introduced in v1.12 of the Payments submodule.