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 +41 -7 6.25.1 → 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,24 +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();
69 -
88 + $user_id = ! empty( $options['user_id'] ) ? $options['user_id'] : get_current_user_id();
89 + $meta_name = FrmStrpLiteAppHelper::get_customer_id_meta_name();
70 90 $customer_id_error_message = '';
71 91
72 92 if ( $user_id ) {
73 93 $customer_id = get_user_meta( $user_id, $meta_name, true );
94 +
74 95 if ( ! isset( $options['email'] ) ) {
75 96 $user_info = get_userdata( $user_id );
97 +
76 98 if ( ! empty( $user_info->user_email ) ) {
77 99 $options['email'] = $user_info->user_email;
78 100 }
79 101 }
102 +
80 103 if ( $customer_id ) {
81 104 $options['customer_id'] = $customer_id;
82 105 }
83 106 }
@@ -89,9 +112,10 @@
89 112 $a_customer_id_value_was_previously_set = ! empty( $customer_id );
90 113 $customer_id = FrmStrpLiteConnectHelper::get_customer_id( $options );
91 114
92 115 if ( $customer_id ) {
93 - $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 +
94 118 if ( $customer_id_is_actually_an_error_message ) {
95 119 $customer_id_error_message = $customer_id;
96 120 $customer_id = false;
97 121 }
@@ -101,9 +125,9 @@
101 125 if ( $a_customer_id_value_was_previously_set ) {
102 126 delete_user_meta( $user_id, $meta_name );
103 127 }
104 128
105 - if ( ! empty( $customer_id_error_message ) ) {
129 + if ( $customer_id_error_message ) {
106 130 return $customer_id_error_message;
107 131 }
108 132
109 133 return __( 'Unable to retrieve customer through Stripe Connect.', 'formidable' );
@@ -117,8 +141,9 @@
117 141 }
118 142
119 143 /**
120 144 * @param string $customer_id
145 + *
121 146 * @return object
122 147 */
123 148 private static function create_decoy_customer( $customer_id ) {
124 149 $decoy_object = new stdClass();
@@ -128,8 +153,9 @@
128 153 }
129 154
130 155 /**
131 156 * @param int $user_id
157 + *
132 158 * @return mixed
133 159 */
134 160 public static function get_customer_by_id( $user_id ) {
135 161 $meta_name = FrmStrpLiteAppHelper::get_customer_id_meta_name();
@@ -148,8 +174,9 @@
148 174 }
149 175
150 176 /**
151 177 * @param string $event_id
178 + *
152 179 * @return mixed
153 180 */
154 181 public static function get_event( $event_id ) {
155 182 return FrmStrpLiteConnectHelper::get_event( $event_id );
@@ -156,8 +183,10 @@
156 183 }
157 184
158 185 /**
159 186 * @param array $plan
187 + *
188 + * @return mixed
160 189 */
161 190 public static function maybe_create_plan( $plan ) {
162 191 return FrmStrpLiteConnectHelper::maybe_create_plan( $plan );
163 192 }
@@ -163,8 +192,9 @@
163 192 }
164 193
165 194 /**
166 195 * @param array $new_charge
196 + *
167 197 * @return false|object|string
168 198 */
169 199 public static function create_subscription( $new_charge ) {
170 200 return FrmStrpLiteConnectHelper::create_subscription( $new_charge );
@@ -171,8 +201,9 @@
171 201 }
172 202
173 203 /**
174 204 * @param array $new_charge
205 + *
175 206 * @return mixed
176 207 */
177 208 public static function create_intent( $new_charge ) {
178 209 return FrmStrpLiteConnectHelper::create_intent( $new_charge );
@@ -180,8 +211,9 @@
180 211
181 212 /**
182 213 * @param string $intent_id
183 214 * @param array $data
215 + *
184 216 * @return mixed
185 217 */
186 218 public static function update_intent( $intent_id, $data ) {
187 219 return FrmStrpLiteConnectHelper::update_intent( $intent_id, $data );
@@ -194,8 +226,9 @@
194 226 * @since 6.5, introduced in v3.0 of the Stripe add on.
195 227 *
196 228 * @param string $customer_id Customer ID beginning with cus_.
197 229 * @param array|false $payment_method_types If false the types will defaults to array( 'card', 'link' ).
230 + *
198 231 * @return false|object|string
199 232 */
200 233 public static function create_setup_intent( $customer_id, $payment_method_types = false ) {
201 234 return FrmStrpLiteConnectHelper::create_setup_intent( $customer_id, $payment_method_types );
@@ -206,8 +239,9 @@
206 239 *
207 240 * @since 6.5, introduced in v3.0 of the Stripe add on.
208 241 *
209 242 * @param string $setup_id
243 + *
210 244 * @return false|object|string
211 245 */
212 246 public static function get_setup_intent( $setup_id ) {
213 247 return FrmStrpLiteConnectHelper::get_setup_intent( $setup_id );