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 | square/helpers/FrmSquareLiteConnectHelper.php +169 -62 6.25 → trunk View file →
@@ -21,8 +21,11 @@
21 21 $settings = FrmSquareLiteAppHelper::get_settings();
22 22
23 23 self::register_settings_scripts();
24 24
25 + FrmSquareLiteAppHelper::fee_education( 'square-global-settings-tip' );
26 +
27 + // phpcs:disable Generic.WhiteSpace.ScopeIndent
25 28 ?>
26 29 <table class="form-table" style="width: 400px;">
27 30 <tr class="form-field">
28 31 <td>
@@ -41,8 +44,9 @@
41 44 <div class="frm_grid_container">
42 45 <?php
43 46
44 47 $modes = array( 'live', 'test' );
48 +
45 49 foreach ( $modes as $mode ) {
46 50 self::render_settings_for_mode( $mode );
47 51 }
48 52 ?>
@@ -55,18 +59,21 @@
55 59 </em>
56 60 </div>
57 61 <?php } ?>
58 62 <?php
63 + // phpcs:enable Generic.WhiteSpace.ScopeIndent
59 64 }
60 65
61 66 /**
62 67 * @param string $mode
68 + *
63 69 * @return void
64 70 */
65 71 private static function render_settings_for_mode( $mode ) {
72 + // phpcs:disable Generic.WhiteSpace.ScopeIndent
66 73 ?>
67 74 <div class="frm-card-item frm4">
68 - <div class="frm-flex-col">
75 + <div class="frm-flex-col" style="width: 100%;">
69 76 <div>
70 77 <span style="font-size: var(--text-lg); font-weight: 500; margin-right: 5px;">
71 78 <?php
72 79 echo $mode === 'test' ? esc_html__( 'Test', 'formidable' ) : esc_html__( 'Live', 'formidable' );
@@ -73,21 +80,15 @@
73 80 ?>
74 81 </span>
75 82 <?php
76 83
77 - $connected = (bool) self::get_merchant_id( $mode );
78 -
79 - $tag_classes = '';
80 - if ( $connected ) {
81 - $tag_classes = 'frm-lt-green-tag';
82 - } else {
83 - $tag_classes = 'frm-grey-tag';
84 - }
84 + $connected = (bool) self::get_merchant_id( $mode );
85 + $tag_classes = $connected ? 'frm-lt-green-tag' : 'frm-grey-tag';
85 86 ?>
86 87 <div class="frm-meta-tag <?php echo esc_attr( $tag_classes ); ?>" style="font-size: var(--text-sm); font-weight: 600;">
87 88 <?php
88 89 if ( $connected ) {
89 - FrmAppHelper::icon_by_class( 'frm_icon_font frm_checkmark_icon', array( 'style' => 'width: 10px; position: relative; top: 2px; margin-right: 5px;' ) );
90 + FrmAppHelper::icon_by_class( 'frmfont frm_checkmark_icon', array( 'style' => 'width: 10px; position: relative; top: 2px; margin-right: 5px;' ) );
90 91 echo 'Connected';
91 92 } else {
92 93 echo 'Not configured';
93 94 }
@@ -116,8 +117,9 @@
116 117 </div>
117 118 </div>
118 119 </div>
119 120 <?php
121 + // phpcs:enable Generic.WhiteSpace.ScopeIndent
120 122 }
121 123
122 124 /**
123 125 * @return void
@@ -122,17 +124,19 @@
122 124 /**
123 125 * @return void
124 126 */
125 127 private static function register_settings_scripts() {
126 - $script_url = FrmSquareLiteAppHelper::plugin_url() . '/js/settings.js';
127 - $dependencies = array( 'formidable_dom' );
128 - $plugin_version = FrmAppHelper::plugin_version();
129 - wp_register_script( 'formidable_square_settings', $script_url, $dependencies, $plugin_version, true );
128 + $script_url = FrmSquareLiteAppHelper::plugin_url() . '/js/settings.js';
129 + $dependencies = array( 'formidable_dom' );
130 + wp_register_script( 'formidable_square_settings', $script_url, $dependencies, FrmAppHelper::plugin_version(), true );
130 131 wp_enqueue_script( 'formidable_square_settings' );
131 132 }
132 133
134 + /**
135 + * @return false|string
136 + */
133 137 public static function get_oauth_redirect_url() {
134 - $mode = FrmAppHelper::get_post_param( 'mode', 'test', 'sanitize_text_field' );
138 + $mode = self::get_mode_value_from_post();
135 139
136 140 if ( self::get_merchant_id( $mode ) ) {
137 141 // Do not allow for initialize if there is already a configured account id.
138 142 return false;
@@ -152,9 +156,9 @@
152 156 return false;
153 157 }
154 158
155 159 if ( ! empty( $data->password ) ) {
156 - update_option( self::get_server_side_token_option_name( $mode ), $data->password, 'no' );
160 + update_option( self::get_server_side_token_option_name( $mode ), $data->password, false );
157 161 }
158 162
159 163 if ( ! is_object( $data ) || empty( $data->redirect_url ) ) {
160 164 return false;
@@ -165,8 +169,9 @@
165 169
166 170 /**
167 171 * @param string $action
168 172 * @param array $additional_body
173 + *
169 174 * @return object|string
170 175 */
171 176 private static function post_to_connect_server( $action, $additional_body = array() ) {
172 177 $body = array(
@@ -176,12 +181,8 @@
176 181 $body = array_merge( $body, $additional_body );
177 182 $url = self::get_url_to_connect_server();
178 183 $headers = self::build_headers_for_post();
179 184
180 - if ( ! $headers ) {
181 - return 'Unable to build headers for post. Is your pro license configured properly?';
182 - }
183 -
184 185 // (Seconds) default timeout is 5. we want a bit more time to work with.
185 186 $timeout = 45;
186 187
187 188 self::try_to_extend_server_timeout( $timeout );
@@ -193,18 +194,25 @@
193 194 return 'Response from server is invalid';
194 195 }
195 196
196 197 $body = self::pull_response_body( $response );
198 +
197 199 if ( empty( $body->success ) ) {
198 200 if ( ! empty( $body->data ) && is_string( $body->data ) ) {
199 201 return $body->data;
200 202 }
203 +
201 204 return 'Response from server was not successful';
202 205 }
203 206
204 - return isset( $body->data ) ? $body->data : array();
207 + return $body->data ?? array();
205 208 }
206 209
210 + /**
211 + * @param array $response
212 + *
213 + * @return mixed
214 + */
207 215 private static function pull_response_body( $response ) {
208 216 $http_response = $response['http_response'];
209 217 $response_object = $http_response->get_response_object();
210 218 return json_decode( $response_object->body );
@@ -211,8 +219,9 @@
211 219 }
212 220
213 221 /**
214 222 * @param mixed $response
223 + *
215 224 * @return bool
216 225 */
217 226 private static function validate_response( $response ) {
218 227 return ! is_wp_error( $response ) && is_array( $response ) && isset( $response['http_response'] );
@@ -229,8 +238,9 @@
229 238 * @return array
230 239 */
231 240 private static function build_headers_for_post() {
232 241 $password = self::maybe_get_pro_license();
242 +
233 243 if ( false === $password ) {
234 244 $password = 'lite_' . self::get_uuid();
235 245 }
236 246
@@ -259,15 +269,16 @@
259 269 }
260 270
261 271 /**
262 272 * WPML might add a language to the url. Don't send that to the server.
273 + *
274 + * @param string $url URL to strip language from.
275 + *
276 + * @return string
263 277 */
264 278 private static function strip_lang_from_url( $url ) {
265 279 $split_on_language = explode( '/?lang=', $url );
266 - if ( 2 === count( $split_on_language ) ) {
267 - $url = $split_on_language[0];
268 - }
269 - return $url;
280 + return 2 === count( $split_on_language ) ? $split_on_language[0] : $url;
270 281 }
271 282
272 283 /**
273 284 * WPML alters the output of home_url.
@@ -272,9 +283,10 @@
272 283 /**
273 284 * WPML alters the output of home_url.
274 285 * If it is active, use the WPML "absolute home" URL which is not modified.
275 286 *
276 - * @param string $url
287 + * @param string $url URL to maybe fix.
288 + *
277 289 * @return string
278 290 */
279 291 private static function maybe_fix_wpml_url( $url ) {
280 292 if ( defined( 'ICL_SITEPRESS_VERSION' ) && ! ICL_PLUGIN_INACTIVE && class_exists( 'SitePress' ) ) {
@@ -292,12 +304,14 @@
292 304 */
293 305 private static function maybe_get_pro_license() {
294 306 if ( FrmAppHelper::pro_is_installed() ) {
295 307 $pro_license = FrmAddonsController::get_pro_license();
308 +
296 309 if ( $pro_license ) {
297 310 $password = $pro_license;
298 311 }
299 312 }
313 +
300 314 return ! empty( $password ) ? $password : false;
301 315 }
302 316
303 317 /**
@@ -314,8 +328,9 @@
314 328 }
315 329
316 330 /**
317 331 * @param string $mode either 'auto', 'live', or 'test'.
332 + *
318 333 * @return string
319 334 */
320 335 private static function get_server_side_token_option_name( $mode = 'auto' ) {
321 336 return self::get_square_connect_option_name( 'server_password', $mode );
@@ -324,18 +339,20 @@
324 339 /**
325 340 * Generate a new client password for authenticating with Connect Service and save it locally as an option.
326 341 *
327 342 * @param string $mode 'live' or 'test'.
343 + *
328 344 * @return string the client password.
329 345 */
330 346 private static function generate_client_password( $mode ) {
331 347 $client_password = wp_generate_password();
332 - update_option( self::get_client_side_token_option_name( $mode ), $client_password, 'no' );
348 + update_option( self::get_client_side_token_option_name( $mode ), $client_password, false );
333 349 return $client_password;
334 350 }
335 351
336 352 /**
337 353 * @param string $mode either 'auto', 'live', or 'test'.
354 + *
338 355 * @return string
339 356 */
340 357 private static function get_client_side_token_option_name( $mode = 'auto' ) {
341 358 return self::get_square_connect_option_name( 'client_password', $mode );
@@ -350,8 +367,9 @@
350 367 }
351 368
352 369 /**
353 370 * @param string $mode either 'auto', 'live', or 'test'.
371 + *
354 372 * @return bool|string
355 373 */
356 374 public static function get_merchant_id( $mode = 'auto' ) {
357 375 if ( 'auto' === $mode ) {
@@ -361,8 +379,9 @@
361 379 }
362 380
363 381 /**
364 382 * @param string $mode either 'auto', 'live', or 'test'.
383 + *
365 384 * @return string
366 385 */
367 386 private static function get_merchant_id_option_name( $mode = 'auto' ) {
368 387 return self::get_square_connect_option_name( 'merchant_id', $mode );
@@ -368,8 +387,10 @@
368 387 return self::get_square_connect_option_name( 'merchant_id', $mode );
369 388 }
370 389
371 390 /**
391 + * @param string $mode either 'auto', 'live', or 'test'.
392 + *
372 393 * @return string
373 394 */
374 395 private static function get_location_id_option_name( $mode = 'auto' ) {
375 396 return self::get_square_connect_option_name( 'merchant_location_id', $mode );
@@ -376,8 +397,9 @@
376 397 }
377 398
378 399 /**
379 400 * @param string $mode either 'auto', 'live', or 'test'.
401 + *
380 402 * @return string
381 403 */
382 404 private static function get_merchant_currency_option_name( $mode = 'auto' ) {
383 405 return self::get_square_connect_option_name( 'merchant_currency', $mode );
@@ -383,10 +405,11 @@
383 405 return self::get_square_connect_option_name( 'merchant_currency', $mode );
384 406 }
385 407
386 408 /**
387 - * @param string $key 'merchant_id', 'client_password', 'server_password'.
409 + * @param string $key 'merchant_id', 'client_password', 'server_password'.
388 410 * @param string $mode either 'auto', 'live', or 'test'.
411 + *
389 412 * @return string
390 413 */
391 414 private static function get_square_connect_option_name( $key, $mode = 'auto' ) {
392 415 return 'frm_square_connect_' . $key . self::get_active_mode_option_name_suffix( $mode );
@@ -393,8 +416,9 @@
393 416 }
394 417
395 418 /**
396 419 * @param string $mode either 'auto', 'live', or 'test'.
420 + *
397 421 * @return string either _test or _live.
398 422 */
399 423 private static function get_active_mode_option_name_suffix( $mode = 'auto' ) {
400 424 if ( 'auto' !== $mode ) {
@@ -423,8 +447,9 @@
423 447 }
424 448
425 449 /**
426 450 * @param bool $connected
451 + *
427 452 * @return string
428 453 */
429 454 private static function get_url_for_square_settings( $connected ) {
430 455 return admin_url( 'admin.php?page=formidable-settings&t=square_settings&connected=' . intval( $connected ) );
@@ -448,19 +473,19 @@
448 473 );
449 474 $data = self::post_to_connect_server( 'oauth_merchant_status', $body );
450 475
451 476 if ( is_object( $data ) && ! empty( $data->merchant_id ) ) {
452 - update_option( self::get_merchant_id_option_name( $mode ), $data->merchant_id, 'no' );
477 + update_option( self::get_merchant_id_option_name( $mode ), $data->merchant_id, false );
453 478
454 479 $currency = self::get_merchant_currency( true, $mode );
455 480 $location_id = self::get_location_id( true, $mode );
456 481
457 482 if ( $currency ) {
458 - update_option( self::get_merchant_currency_option_name( $mode ), $currency, 'no' );
483 + update_option( self::get_merchant_currency_option_name( $mode ), $currency, false );
459 484 }
460 485
461 486 if ( $location_id ) {
462 - update_option( self::get_location_id_option_name( $mode ), $location_id, 'no' );
487 + update_option( self::get_location_id_option_name( $mode ), $location_id, false );
463 488 }
464 489
465 490 FrmTransLiteAppController::install();
466 491
@@ -469,8 +494,17 @@
469 494
470 495 return false;
471 496 }
472 497
498 + /**
499 + * @param string $amount
500 + * @param string $currency
501 + * @param string $square_token
502 + * @param string $verification_token
503 + * @param string $description
504 + *
505 + * @return false|object
506 + */
473 507 public static function create_payment( $amount, $currency, $square_token, $verification_token, $description ) {
474 508 return self::post_with_authenticated_body(
475 509 'create_payment',
476 510 array(
@@ -491,16 +525,19 @@
491 525 */
492 526 private static function post_with_authenticated_body( $action, $additional_body = array() ) {
493 527 $body = array_merge( self::get_standard_authenticated_body(), $additional_body );
494 528 $response = self::post_to_connect_server( $action, $body );
529 +
495 530 if ( is_object( $response ) ) {
496 531 return $response;
497 532 }
533 +
498 534 if ( is_array( $response ) ) {
499 - // reformat empty arrays as empty objects
500 - // if the response is an array, it's because it's empty. Everything with data is already an object.
535 + // Reformat empty arrays as empty objects
536 + // If the response is an array, it's because it's empty. Everything with data is already an object.
501 537 return new stdClass();
502 538 }
539 +
503 540 if ( is_string( $response ) ) {
504 541 self::$latest_error_from_square_api = $response;
505 542 FrmTransLiteLog::log_message( 'Square API Error', $response );
506 543 } else {
@@ -505,53 +542,95 @@
505 542 FrmTransLiteLog::log_message( 'Square API Error', $response );
506 543 } else {
507 544 self::$latest_error_from_square_api = '';
508 545 }
546 +
509 547 return false;
510 548 }
511 549
550 + /**
551 + * @return array
552 + */
512 553 private static function get_standard_authenticated_body() {
513 - $mode = self::get_mode_value_from_post();
514 - return array(
515 - 'merchant_id' => get_option( self::get_merchant_id_option_name( $mode ) ),
516 - 'server_password' => get_option( self::get_server_side_token_option_name( $mode ) ),
517 - 'client_password' => get_option( self::get_client_side_token_option_name( $mode ) ),
518 - );
554 + return self::get_body_for_mode( FrmSquareLiteAppHelper::active_mode() );
519 555 }
520 556
521 557 /**
522 - * Check $_POST for live or test mode value as it can be updated in real time from Stripe Settings and can be configured before the update is saved.
558 + * Check $_POST for live or test mode value as it can be updated in real time from Square Settings and can be configured before the update is saved.
559 + * The connect request sends a 'mode' string, and the disconnect request sends a 'testMode' flag, so check for both.
523 560 *
524 561 * @return string 'test' or 'live'
525 562 */
526 563 private static function get_mode_value_from_post() {
527 564 // phpcs:ignore WordPress.Security.NonceVerification.Missing
528 - if ( empty( $_POST ) || ! array_key_exists( 'testMode', $_POST ) ) {
529 - return FrmSquareLiteAppHelper::active_mode();
565 + if ( array_key_exists( 'mode', $_POST ) ) {
566 + $mode = FrmAppHelper::get_post_param( 'mode', '', 'sanitize_text_field' );
567 + return 'test' === $mode ? 'test' : 'live';
530 568 }
531 - $test_mode = FrmAppHelper::get_param( 'testMode', '', 'post', 'absint' );
532 - return $test_mode ? 'test' : 'live';
569 +
570 + // phpcs:ignore WordPress.Security.NonceVerification.Missing
571 + if ( array_key_exists( 'testMode', $_POST ) ) {
572 + $test_mode = FrmAppHelper::get_post_param( 'testMode', '', 'absint' );
573 + return $test_mode ? 'test' : 'live';
574 + }
575 +
576 + return FrmSquareLiteAppHelper::active_mode();
533 577 }
534 578
579 + /**
580 + * Get the standard body with account id, mode, and passwords to send to the connect server.
581 + *
582 + * @since 6.32.1
583 + *
584 + * @param string $mode 'live' or 'test'.
585 + *
586 + * @return array
587 + */
588 + private static function get_body_for_mode( $mode ) {
589 + return array(
590 + 'merchant_id' => get_option( self::get_merchant_id_option_name( $mode ) ),
591 + 'server_password' => get_option( self::get_server_side_token_option_name( $mode ) ),
592 + 'client_password' => get_option( self::get_client_side_token_option_name( $mode ) ),
593 + 'frm_square_api_mode' => $mode,
594 + );
595 + }
596 +
597 + /**
598 + * @return string|null
599 + */
535 600 public static function get_latest_error_from_square_api() {
536 601 return self::$latest_error_from_square_api;
537 602 }
538 603
604 + /**
605 + * @param string $receipt_id
606 + *
607 + * @return bool
608 + */
539 609 public static function refund_payment( $receipt_id ) {
540 - return self::post_with_authenticated_body( 'refund_payment', array( 'receipt_id' => $receipt_id ) );
610 + $data = self::post_with_authenticated_body( 'refund_payment', array( 'receipt_id' => $receipt_id ) );
611 + return is_object( $data );
541 612 }
542 613
614 + /**
615 + * @param array $info
616 + *
617 + * @return false|object
618 + */
543 619 public static function create_subscription( $info ) {
544 620 return self::post_with_authenticated_body( 'create_subscription', compact( 'info' ) );
545 621 }
546 622
547 623 /**
548 - * @param bool $force
624 + * @param bool $force Whether to force refreshing the location id.
625 + * @param string $mode Either 'auto', 'live', or 'test'.
626 + *
549 627 * @return false|string
550 628 */
551 629 public static function get_location_id( $force = false, $mode = 'auto' ) {
552 630 if ( ! $force ) {
553 631 $location_id = get_option( self::get_location_id_option_name( $mode ) );
632 +
554 633 if ( $location_id ) {
555 634 return $location_id;
556 635 }
557 636 }
@@ -556,16 +635,17 @@
556 635 }
557 636 }
558 637
559 638 $request_body = array();
639 +
560 640 if ( 'auto' !== $mode ) {
561 - $_POST['testMode'] = 'test' === $mode ? 1 : 0;
562 - $request_body['frm_square_api_mode'] = $mode;
641 + $request_body = self::get_body_for_mode( $mode );
563 642 }
564 643
565 644 $response = self::post_with_authenticated_body( 'get_location_id', $request_body );
645 +
566 646 if ( is_object( $response ) ) {
567 - update_option( self::get_location_id_option_name( $mode ), $response->id, 'no' );
647 + update_option( self::get_location_id_option_name( $mode ), $response->id, false );
568 648 return $response->id;
569 649 }
570 650
571 651 return false;
@@ -575,20 +655,24 @@
575 655 * @return array
576 656 */
577 657 public static function get_unprocessed_event_ids() {
578 658 $data = self::post_with_authenticated_body( 'get_unprocessed_event_ids' );
659 +
579 660 if ( false === $data || empty( $data->event_ids ) ) {
580 661 return array();
581 662 }
663 +
582 664 return $data->event_ids;
583 665 }
584 666
585 667 /**
586 668 * @param string $event_id
669 + *
587 670 * @return false|object
588 671 */
589 672 public static function get_event( $event_id ) {
590 673 $event = wp_cache_get( $event_id, 'frm_square' );
674 +
591 675 if ( is_object( $event ) ) {
592 676 return $event;
593 677 }
594 678
@@ -604,32 +688,46 @@
604 688 }
605 689
606 690 /**
607 691 * @param string $event_id
608 - * @return mixed
692 + *
693 + * @return false|object
609 694 */
610 695 public static function process_event( $event_id ) {
611 696 return self::post_with_authenticated_body( 'process_event', compact( 'event_id' ) );
612 697 }
613 698
699 + /**
700 + * @param string $payment_id
701 + *
702 + * @return false|object
703 + */
614 704 public static function get_payment( $payment_id ) {
615 705 return self::post_with_authenticated_body( 'get_payment', compact( 'payment_id' ) );
616 706 }
617 707
708 + /**
709 + * @param string $payment_id
710 + *
711 + * @return false|object
712 + */
618 713 public static function get_subscription_id_for_payment( $payment_id ) {
619 714 return self::post_with_authenticated_body( 'get_subscription_id_for_payment', compact( 'payment_id' ) );
620 715 }
621 716
717 + /**
718 + * @param string $subscription_id
719 + *
720 + * @return bool
721 + */
622 722 public static function cancel_subscription( $subscription_id ) {
623 - return self::post_with_authenticated_body( 'cancel_subscription', compact( 'subscription_id' ) );
723 + return false !== self::post_with_authenticated_body( 'cancel_subscription', compact( 'subscription_id' ) );
624 724 }
625 725
626 - /**
627 - * @return void
628 - */
629 726 public static function handle_disconnect() {
630 727 self::disconnect();
631 728 self::reset_square_api_integration();
729 + FrmTransLiteAppHelper::trigger_gateway_disconnected_hook( 'square', self::get_mode_value_from_post() );
632 730 wp_send_json_success();
633 731 }
634 732
635 733 /**
@@ -635,11 +733,10 @@
635 733 /**
636 734 * @return false|object
637 735 */
638 736 private static function disconnect() {
639 - $additional_body = array(
640 - 'frm_square_api_mode' => self::get_mode_value_from_post(),
641 - );
737 + $mode = self::get_mode_value_from_post();
738 + $additional_body = self::get_body_for_mode( $mode );
642 739 return self::post_with_authenticated_body( 'disconnect', $additional_body );
643 740 }
644 741
645 742 /**
@@ -658,13 +755,15 @@
658 755
659 756 /**
660 757 * @param bool $force
661 758 * @param string $mode
759 + *
662 760 * @return false|string
663 761 */
664 762 public static function get_merchant_currency( $force = false, $mode = 'auto' ) {
665 763 if ( ! $force ) {
666 764 $currency = get_option( self::get_merchant_currency_option_name( $mode ) );
765 +
667 766 if ( $currency ) {
668 767 return $currency;
669 768 }
670 769 }
@@ -669,16 +768,17 @@
669 768 }
670 769 }
671 770
672 771 $request_body = array();
772 +
673 773 if ( 'auto' !== $mode ) {
674 - $_POST['testMode'] = 'test' === $mode ? 1 : 0;
675 - $request_body['frm_square_api_mode'] = $mode;
774 + $request_body = self::get_body_for_mode( $mode );
676 775 }
677 776
678 777 $response = self::post_with_authenticated_body( 'get_merchant_currency', $request_body );
778 +
679 779 if ( is_object( $response ) && ! empty( $response->currency ) ) {
680 - update_option( self::get_merchant_currency_option_name( $mode ), $response->currency, 'no' );
780 + update_option( self::get_merchant_currency_option_name( $mode ), $response->currency, false );
681 781 return $response->currency;
682 782 }
683 783
684 784 return false;
@@ -705,22 +805,29 @@
705 805 }
706 806
707 807 $site_identifier = FrmAppHelper::get_post_param( 'site_identifier' );
708 808 $usage = new FrmUsage();
709 - $uuid = $usage->uuid();
710 809
711 810 update_option( $option_name, time() );
712 811
713 - if ( $site_identifier === $uuid ) {
812 + if ( $site_identifier === $usage->uuid() ) {
714 813 wp_send_json_success();
715 814 }
815 +
716 816 wp_send_json_error();
717 817 }
718 818
819 + /**
820 + * @param string $subscription_id
821 + *
822 + * @return false|object
823 + */
719 824 public static function get_subscription( $subscription_id ) {
720 825 $response = self::post_with_authenticated_body( 'get_subscription', array( 'subscription_id' => $subscription_id ) );
826 +
721 827 if ( is_object( $response ) && is_object( $response->subscription ) ) {
722 828 return $response->subscription;
723 829 }
830 +
724 831 return false;
725 832 }
726 833 }