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/FrmStrpLiteConnectApiAdapter.php +45 -9 6.5.3 → trunk View file →
@@ -17,8 +17,9 @@
17 17 }
18 18
19 19 /**
20 20 * @param string $sub_id
21 + *
21 22 * @return bool
22 23 */
23 24 public static function cancel_subscription( $sub_id ) {
24 25 if ( current_user_can( 'administrator' ) ) {
@@ -23,20 +24,38 @@
23 24 public static function cancel_subscription( $sub_id ) {
24 25 if ( current_user_can( 'administrator' ) ) {
25 26 $customer_id = false;
26 27 } else {
27 - $user_id = get_current_user_id();
28 - $customer = self::get_customer_by_id( $user_id );
28 + $customer = self::get_customer_by_id( get_current_user_id() );
29 +
29 30 if ( ! is_object( $customer ) ) {
30 31 return false;
31 32 }
33 +
32 34 $customer_id = $customer->id;
33 35 }
36 +
34 37 return FrmStrpLiteConnectHelper::cancel_subscription( $sub_id, $customer_id );
35 38 }
36 39
37 40 /**
41 + * Cancel a subscription without checking that it belongs to the current user.
42 + * Use this when there is no logged in user, like when a webhook event is processed.
43 + * The customer check in self::cancel_subscription would always fail there because the current user ID is 0.
44 + *
45 + * @since 6.35
46 + *
47 + * @param string $sub_id
48 + *
49 + * @return bool
50 + */
51 + public static function cancel_subscription_without_customer_check( $sub_id ) {
52 + return FrmStrpLiteConnectHelper::cancel_subscription( $sub_id );
53 + }
54 +
55 + /**
38 56 * @param string $payment_id
57 + *
39 58 * @return bool
40 59 */
41 60 public static function refund_payment( $payment_id ) {
42 61 return FrmStrpLiteConnectHelper::refund_payment( $payment_id );
@@ -45,8 +64,9 @@
45 64 /**
46 65 * Get the payment intent from Stripe
47 66 *
48 67 * @param string $payment_id
68 + *
49 69 * @return mixed
50 70 */
51 71 public static function get_intent( $payment_id ) {
52 72 return FrmStrpLiteConnectHelper::get_intent( $payment_id );
@@ -60,22 +80,27 @@
60 80 }
61 81
62 82 /**
63 83 * @param array $options
84 + *
64 85 * @return object|string
65 86 */
66 87 public static function get_customer( $options = array() ) {
67 - $user_id = ! empty( $options['user_id'] ) ? $options['user_id'] : get_current_user_id();
68 - $meta_name = FrmStrpLiteAppHelper::get_customer_id_meta_name();
88 + $user_id = ! empty( $options['user_id'] ) ? $options['user_id'] : get_current_user_id();
89 + $meta_name = FrmStrpLiteAppHelper::get_customer_id_meta_name();
90 + $customer_id_error_message = '';
69 91
70 92 if ( $user_id ) {
71 93 $customer_id = get_user_meta( $user_id, $meta_name, true );
94 +
72 95 if ( ! isset( $options['email'] ) ) {
73 96 $user_info = get_userdata( $user_id );
97 +
74 98 if ( ! empty( $user_info->user_email ) ) {
75 99 $options['email'] = $user_info->user_email;
76 100 }
77 101 }
102 +
78 103 if ( $customer_id ) {
79 104 $options['customer_id'] = $customer_id;
80 105 }
81 106 }
@@ -87,9 +112,10 @@
87 112 $a_customer_id_value_was_previously_set = ! empty( $customer_id );
88 113 $customer_id = FrmStrpLiteConnectHelper::get_customer_id( $options );
89 114
90 115 if ( $customer_id ) {
91 - $customer_id_is_actually_an_error_message = false === strpos( $customer_id, 'cus_' );
116 + $customer_id_is_actually_an_error_message = ! str_contains( $customer_id, 'cus_' );
117 +
92 118 if ( $customer_id_is_actually_an_error_message ) {
93 119 $customer_id_error_message = $customer_id;
94 120 $customer_id = false;
95 121 }
@@ -99,9 +125,9 @@
99 125 if ( $a_customer_id_value_was_previously_set ) {
100 126 delete_user_meta( $user_id, $meta_name );
101 127 }
102 128
103 - if ( ! empty( $customer_id_error_message ) ) {
129 + if ( $customer_id_error_message ) {
104 130 return $customer_id_error_message;
105 131 }
106 132
107 133 return __( 'Unable to retrieve customer through Stripe Connect.', 'formidable' );
@@ -115,8 +141,9 @@
115 141 }
116 142
117 143 /**
118 144 * @param string $customer_id
145 + *
119 146 * @return object
120 147 */
121 148 private static function create_decoy_customer( $customer_id ) {
122 149 $decoy_object = new stdClass();
@@ -126,8 +153,9 @@
126 153 }
127 154
128 155 /**
129 156 * @param int $user_id
157 + *
130 158 * @return mixed
131 159 */
132 160 public static function get_customer_by_id( $user_id ) {
133 161 $meta_name = FrmStrpLiteAppHelper::get_customer_id_meta_name();
@@ -146,8 +174,9 @@
146 174 }
147 175
148 176 /**
149 177 * @param string $event_id
178 + *
150 179 * @return mixed
151 180 */
152 181 public static function get_event( $event_id ) {
153 182 return FrmStrpLiteConnectHelper::get_event( $event_id );
@@ -154,8 +183,10 @@
154 183 }
155 184
156 185 /**
157 186 * @param array $plan
187 + *
188 + * @return mixed
158 189 */
159 190 public static function maybe_create_plan( $plan ) {
160 191 return FrmStrpLiteConnectHelper::maybe_create_plan( $plan );
161 192 }
@@ -161,9 +192,10 @@
161 192 }
162 193
163 194 /**
164 195 * @param array $new_charge
165 - * @return object|string|false
196 + *
197 + * @return false|object|string
166 198 */
167 199 public static function create_subscription( $new_charge ) {
168 200 return FrmStrpLiteConnectHelper::create_subscription( $new_charge );
169 201 }
@@ -169,8 +201,9 @@
169 201 }
170 202
171 203 /**
172 204 * @param array $new_charge
205 + *
173 206 * @return mixed
174 207 */
175 208 public static function create_intent( $new_charge ) {
176 209 return FrmStrpLiteConnectHelper::create_intent( $new_charge );
@@ -178,8 +211,9 @@
178 211
179 212 /**
180 213 * @param string $intent_id
181 214 * @param array $data
215 + *
182 216 * @return mixed
183 217 */
184 218 public static function update_intent( $intent_id, $data ) {
185 219 return FrmStrpLiteConnectHelper::update_intent( $intent_id, $data );
@@ -192,9 +226,10 @@
192 226 * @since 6.5, introduced in v3.0 of the Stripe add on.
193 227 *
194 228 * @param string $customer_id Customer ID beginning with cus_.
195 229 * @param array|false $payment_method_types If false the types will defaults to array( 'card', 'link' ).
196 - * @return object|string|false
230 + *
231 + * @return false|object|string
197 232 */
198 233 public static function create_setup_intent( $customer_id, $payment_method_types = false ) {
199 234 return FrmStrpLiteConnectHelper::create_setup_intent( $customer_id, $payment_method_types );
200 235 }
@@ -204,9 +239,10 @@
204 239 *
205 240 * @since 6.5, introduced in v3.0 of the Stripe add on.
206 241 *
207 242 * @param string $setup_id
208 - * @return object|string|false
243 + *
244 + * @return false|object|string
209 245 */
210 246 public static function get_setup_intent( $setup_id ) {
211 247 return FrmStrpLiteConnectHelper::get_setup_intent( $setup_id );
212 248 }