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/helpers/FrmStrpLiteSubscriptionHelper.php +15 -20 6.26 → trunk View file →
@@ -14,11 +14,8 @@
14 14 * Prepare a charge object for a Stripe subscription.
15 15 *
16 16 * @since 6.5, introduced in v3.0 of the Stripe add on.
17 17 *
18 - * @todo I removed the $charge_object->paid = false; line from here is it isn't required for Stripe link.
19 - * Make sure that if/when we re-use this in Stripe that we still include that.
20 - *
21 18 * @param object $subscription A Stripe Subscription object.
22 19 * @param string $amount
23 20 *
24 21 * @return stdClass
@@ -39,9 +36,9 @@
39 36 * @since 6.5
40 37 *
41 38 * @param array $atts
42 39 *
43 - * @return int|string $sub_id
40 + * @return int|string Sub ID.
44 41 */
45 42 public static function create_new_subscription( $atts ) {
46 43 $atts['charge'] = (object) $atts['charge'];
47 44
@@ -70,10 +67,9 @@
70 67 }
71 68 }
72 69
73 70 $frm_sub = new FrmTransLiteSubscription();
74 - $sub_id = $frm_sub->create( $new_values );
75 - return $sub_id;
71 + return $frm_sub->create( $new_values );
76 72 }
77 73
78 74 /**
79 75 * Get a plan for Stripe subscription.
@@ -86,9 +82,9 @@
86 82 * @type WP_Post $action
87 83 * @type string $amount
88 84 * }
89 85 *
90 - * @return string Plan id.
86 + * @return false|string Plan id.
91 87 */
92 88 public static function get_plan_from_atts( $atts ) {
93 89 $action = $atts['action'];
94 90 $action->post_content['amount'] = $atts['amount'];
@@ -104,16 +100,17 @@
104 100 */
105 101 private static function get_plan_for_action( $action ) {
106 102 $plan_id = $action->post_content['plan_id'];
107 103
108 - if ( ! $plan_id ) {
109 - // The amount has already been formatted, so add the decimal back in.
110 - $amount = $action->post_content['amount'];
111 - $action->post_content['amount'] = number_format( $amount / 100, 2, '.', '' );
112 - $plan_opts = self::prepare_plan_options( $action->post_content );
113 - $plan_id = self::maybe_create_plan( $plan_opts );
104 + if ( $plan_id ) {
105 + return $plan_id;
114 106 }
115 - return $plan_id;
107 +
108 + // The amount has already been formatted, so add the decimal back in.
109 + $amount = $action->post_content['amount'];
110 + $action->post_content['amount'] = number_format( $amount / 100, 2, '.', '' );
111 + $plan_opts = self::prepare_plan_options( $action->post_content );
112 + return self::maybe_create_plan( $plan_opts );
116 113 }
117 114
118 115 /**
119 116 * @since 6.5
@@ -129,9 +126,9 @@
129 126 'amount' => $amount,
130 127 'interval' => $settings['interval'],
131 128 'interval_count' => $settings['interval_count'],
132 129 'currency' => $settings['currency'],
133 - 'name' => empty( $settings['description'] ) ? $default_description : $settings['description'],
130 + 'name' => ! empty( $settings['description'] ) ? $settings['description'] : $default_description,
134 131 );
135 132
136 133 if ( ! empty( $settings['trial_interval_count'] ) ) {
137 134 $plan_opts['trial_period_days'] = self::get_trial_with_default( $settings['trial_interval_count'] );
@@ -149,9 +146,8 @@
149 146 *
150 147 * @return mixed
151 148 */
152 149 public static function maybe_create_plan( $plan ) {
153 - FrmStrpLiteAppHelper::call_stripe_helper_class( 'initialize_api' );
154 150 return FrmStrpLiteAppHelper::call_stripe_helper_class( 'maybe_create_plan', $plan );
155 151 }
156 152
157 153 /**
@@ -185,9 +181,9 @@
185 181 *
186 182 * @return false|object|string
187 183 */
188 184 public static function maybe_create_missing_plan_and_create_subscription( $subscription, $charge_data, $action, $amount ) {
189 - if ( ! is_string( $subscription ) || 0 !== strpos( $subscription, 'No such plan: ' ) ) {
185 + if ( ! is_string( $subscription ) || ! str_starts_with( $subscription, 'No such plan: ' ) ) {
190 186 // Only retry when there is a No such plan string error.
191 187 return $subscription;
192 188 }
193 189
@@ -193,10 +189,9 @@
193 189
194 190 // The full error message looks like "No such plan: '_399_1month_usd".
195 191 $action->post_content['plan_id'] = '';
196 192 $charge_data['plan'] = self::get_plan_from_atts( compact( 'action', 'amount' ) );
197 - $subscription = FrmStrpLiteAppHelper::call_stripe_helper_class( 'create_subscription', $charge_data );
198 - return $subscription;
193 + return FrmStrpLiteAppHelper::call_stripe_helper_class( 'create_subscription', $charge_data );
199 194 }
200 195
201 196 /**
202 197 * When this is filtered and returns false, the subscription will be canceled immediately instead.
@@ -227,9 +222,9 @@
227 222 if ( is_numeric( $payment_limit ) ) {
228 223 return (int) $payment_limit;
229 224 }
230 225
231 - if ( false === strpos( $payment_limit, '[' ) ) {
226 + if ( ! str_contains( $payment_limit, '[' ) ) {
232 227 return self::get_invalid_payment_limit_error( $payment_limit );
233 228 }
234 229
235 230 $payment_limit = FrmTransLiteAppHelper::process_shortcodes(