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 +69 -24 6.25.1 → trunk View file →
@@ -6,8 +6,9 @@
6 6 class FrmTransLiteSubscriptionsController extends FrmTransLiteCRUDController {
7 7
8 8 /**
9 9 * @param object $subscription
10 + *
10 11 * @return void
11 12 */
12 13 public static function load_sidebar_actions( $subscription ) {
13 14 $date_format = __( 'M j, Y @ G:i', 'formidable' );
@@ -23,12 +24,14 @@
23 24 /**
24 25 * @since 6.5
25 26 *
26 27 * @param object $subscription
28 + *
27 29 * @return void
28 30 */
29 31 public static function show_receipt_link( $subscription ) {
30 32 $link = esc_html( $subscription->sub_id );
33 +
31 34 if ( $subscription->sub_id !== 'None' ) {
32 35 /**
33 36 * Filter a receipt link for a specific gateway.
34 37 * For example, Stripe uses frm_sub_stripe_receipt.
@@ -45,8 +48,9 @@
45 48
46 49 /**
47 50 * @param object $sub
48 51 * @param array $atts
52 + *
49 53 * @return void
50 54 */
51 55 public static function show_cancel_link( $sub, $atts = array() ) {
52 56 if ( ! isset( $sub->user_id ) ) {
@@ -60,8 +64,9 @@
60 64
61 65 /**
62 66 * @param object $sub
63 67 * @param array $atts
68 + *
64 69 * @return string
65 70 */
66 71 public static function cancel_link( $sub, $atts = array() ) {
67 72 $defaults = array(
@@ -87,16 +92,23 @@
87 92 * Handle routing to cancel a subscription.
88 93 *
89 94 * @return void
90 95 */
91 - public static function cancel_subscription() {
96 + public static function cancel_subscription() { // phpcs:ignore SlevomatCodingStandard.Complexity.Cognitive.ComplexityTooHigh
92 97 check_ajax_referer( 'frm_trans_ajax', 'nonce' );
98 + FrmAppHelper::permission_check( 'frm_edit_entries' );
93 99
94 - $sub_id = FrmAppHelper::get_param( 'sub', '', 'get', 'sanitize_text_field' );
100 + $canceled = false;
101 + $sub_id = FrmAppHelper::get_param( 'sub', '', 'get', 'sanitize_text_field' );
102 +
95 103 if ( $sub_id ) {
96 104 $frm_sub = new FrmTransLiteSubscription();
97 105 $sub = $frm_sub->get_one( $sub_id );
106 +
98 107 if ( $sub ) {
108 + $reason = '';
109 + $debug_id = '';
110 +
99 111 switch ( $sub->paysys ) {
100 112 case 'stripe':
101 113 $canceled = FrmStrpLiteAppHelper::call_stripe_helper_class( 'cancel_subscription', $sub->sub_id );
102 114 break;
@@ -102,12 +114,38 @@
102 114 break;
103 115 case 'square':
104 116 $canceled = FrmSquareLiteConnectHelper::cancel_subscription( $sub->sub_id );
105 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;
106 144 default:
107 145 $canceled = false;
108 146 break;
109 - }
147 + }//end switch
110 148
111 149 if ( $canceled ) {
112 150 self::change_subscription_status(
113 151 array(
@@ -116,10 +154,25 @@
116 154 )
117 155 );
118 156
119 157 $message = __( 'Canceled', 'formidable' );
158 + // phpcs:ignore Universal.ControlStructures.DisallowLonelyIf.Found
120 159 } else {
121 - $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 );
122 175 }
123 176 } else {
124 177 $message = __( 'That subscription was not found', 'formidable' );
125 178 }//end if
@@ -126,10 +179,15 @@
126 179 } else {
127 180 $message = __( 'Oops! No subscription was selected for cancelation.', 'formidable' );
128 181 }//end if
129 182
130 - echo esc_html( $message );
131 - 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 + );
132 190 }
133 191
134 192 /**
135 193 * @since 6.5, introduced in v1.12 of the Payments submodule.
@@ -134,8 +192,9 @@
134 192 /**
135 193 * @since 6.5, introduced in v1.12 of the Payments submodule.
136 194 *
137 195 * @param array $atts
196 + *
138 197 * @return void
139 198 */
140 199 public static function change_subscription_status( $atts ) {
141 200 $frm_sub = new FrmTransLiteSubscription();
@@ -145,27 +204,13 @@
145 204 FrmTransLiteActionsController::trigger_subscription_status_change( $atts['sub'] );
146 205 }
147 206
148 207 /**
208 + * @deprecated 6.27
209 + *
149 210 * @return string|null
150 211 */
151 212 public static function list_subscriptions_shortcode() {
152 - if ( ! is_user_logged_in() ) {
153 - return;
154 - }
155 -
156 - $frm_sub = new FrmTransLiteSubscription();
157 - $subscriptions = $frm_sub->get_all_for_user( get_current_user_id() );
158 - if ( empty( $subscriptions ) ) {
159 - return;
160 - }
161 -
162 - FrmTransLiteActionsController::actions_js();
163 -
164 - ob_start();
165 - include FrmTransLiteAppHelper::plugin_path() . '/views/subscriptions/list_shortcode.php';
166 - $content = ob_get_contents();
167 - ob_end_clean();
168 -
169 - return $content;
213 + _deprecated_function( __METHOD__, '6.27' );
214 + return null;
170 215 }
171 216 }