← All changes
|
square/controllers/FrmSquareLiteActionsController.php
+13
-42
6.26.1
→
trunk
View file →
| @@ -21,9 +21,9 @@ | ||
| 21 | 21 | |
| 22 | 22 | $form_id = is_object( $field ) ? $field->form_id : $field['form_id']; |
| 23 | 23 | $actions = self::get_actions_before_submit( $form_id ); |
| 24 | 24 | |
| 25 | - if ( empty( $actions ) ) { | |
| 25 | + if ( ! $actions ) { | |
| 26 | 26 | return $callback; |
| 27 | 27 | } |
| 28 | 28 | |
| 29 | 29 | $field_id = is_object( $field ) ? $field->id : $field['id']; |
| @@ -85,8 +85,9 @@ | ||
| 85 | 85 | if ( ! $is_square || empty( $payment_action->post_content['amount'] ) ) { |
| 86 | 86 | unset( $payment_actions[ $k ] ); |
| 87 | 87 | } |
| 88 | 88 | } |
| 89 | + | |
| 89 | 90 | return $payment_actions; |
| 90 | 91 | } |
| 91 | 92 | |
| 92 | 93 | /** |
| @@ -105,18 +106,18 @@ | ||
| 105 | 106 | 'run_triggers' => false, |
| 106 | 107 | 'show_errors' => true, |
| 107 | 108 | ); |
| 108 | 109 | $atts = compact( 'action', 'entry', 'form' ); |
| 110 | + $amount = self::prepare_amount( $action->post_content['amount'], $atts ); | |
| 109 | 111 | |
| 110 | - $amount = self::prepare_amount( $action->post_content['amount'], $atts ); | |
| 111 | - | |
| 112 | - if ( empty( $amount ) || $amount == 000 ) { | |
| 112 | + // phpcs:ignore Universal.Operators.StrictComparisons | |
| 113 | + if ( ! $amount || $amount == 000 ) { | |
| 113 | 114 | $response['error'] = __( 'Please specify an amount for the payment', 'formidable' ); |
| 114 | 115 | return $response; |
| 115 | 116 | } |
| 116 | 117 | |
| 117 | 118 | if ( ! self::square_is_configured() ) { |
| 118 | - $response['error'] = __( 'There was a problem communicating with Square. Please try again.', 'formidable' ); | |
| 119 | + $response['error'] = __( 'Square still needs to be configured.', 'formidable' ); | |
| 119 | 120 | return $response; |
| 120 | 121 | } |
| 121 | 122 | |
| 122 | 123 | $payment_args = compact( 'form', 'entry', 'action', 'amount' ); |
| @@ -201,10 +202,9 @@ | ||
| 201 | 202 | 'test' => 'test' === FrmSquareLiteAppHelper::active_mode() ? 1 : 0, |
| 202 | 203 | ); |
| 203 | 204 | |
| 204 | 205 | $frm_payment = new FrmTransLitePayment(); |
| 205 | - $payment_id = $frm_payment->create( $new_values ); | |
| 206 | - return $payment_id; | |
| 206 | + return $frm_payment->create( $new_values ); | |
| 207 | 207 | } |
| 208 | 208 | |
| 209 | 209 | /** |
| 210 | 210 | * Create a new Square subscription and a subscription and payment for the payments tables. |
| @@ -325,11 +325,10 @@ | ||
| 325 | 325 | 'test' => 'test' === FrmSquareLiteAppHelper::active_mode() ? 1 : 0, |
| 326 | 326 | ); |
| 327 | 327 | |
| 328 | 328 | $frm_payment = new FrmTransLiteSubscription(); |
| 329 | - $payment_id = $frm_payment->create( $new_values ); | |
| 330 | 329 | |
| 331 | - return $payment_id; | |
| 330 | + return $frm_payment->create( $new_values ); | |
| 332 | 331 | } |
| 333 | 332 | |
| 334 | 333 | /** |
| 335 | 334 | * @param string $repeat_cadence |
| @@ -403,28 +402,8 @@ | ||
| 403 | 402 | return (bool) FrmSquareLiteConnectHelper::get_merchant_id(); |
| 404 | 403 | } |
| 405 | 404 | |
| 406 | 405 | /** |
| 407 | - * Replace an [email] shortcode with the current user email. | |
| 408 | - * | |
| 409 | - * @param string $email | |
| 410 | - * | |
| 411 | - * @return string | |
| 412 | - */ | |
| 413 | - private static function replace_email_shortcode( $email ) { | |
| 414 | - if ( false === strpos( $email, '[email]' ) ) { | |
| 415 | - return $email; | |
| 416 | - } | |
| 417 | - | |
| 418 | - global $current_user; | |
| 419 | - return str_replace( | |
| 420 | - '[email]', | |
| 421 | - ! empty( $current_user->user_email ) ? $current_user->user_email : '', | |
| 422 | ||
| 423 | - ); | |
| 424 | - } | |
| 425 | - | |
| 426 | - /** | |
| 427 | 406 | * Convert the amount from 10.00 to 1000. |
| 428 | 407 | * |
| 429 | 408 | * @param mixed $amount |
| 430 | 409 | * @param array $atts |
| @@ -444,8 +423,9 @@ | ||
| 444 | 423 | * |
| 445 | 424 | * @return void |
| 446 | 425 | */ |
| 447 | 426 | public static function maybe_load_scripts( $params ) { |
| 427 | + // phpcs:ignore Universal.Operators.StrictComparisons | |
| 448 | 428 | if ( $params['form_id'] == $params['posted_form_id'] ) { |
| 449 | 429 | // This form has already been posted, so we aren't on the first page. |
| 450 | 430 | return; |
| 451 | 431 | } |
| @@ -546,9 +526,9 @@ | ||
| 546 | 526 | FrmAppHelper::plugin_version(), |
| 547 | 527 | false |
| 548 | 528 | ); |
| 549 | 529 | |
| 550 | - $square_vars = array( | |
| 530 | + $square_vars = array( | |
| 551 | 531 | 'formId' => $form_id, |
| 552 | 532 | 'nonce' => wp_create_nonce( 'frm_square_ajax' ), |
| 553 | 533 | 'ajax' => esc_url_raw( FrmAppHelper::get_ajax_url() ), |
| 554 | 534 | 'settings' => $action_settings, |
| @@ -570,8 +550,9 @@ | ||
| 570 | 550 | |
| 571 | 551 | if ( 'live' === $mode ) { |
| 572 | 552 | return 'sq0idp-eR4XI1xgNduJAXcBvjemTg'; |
| 573 | 553 | } |
| 554 | + | |
| 574 | 555 | return 'sandbox-sq0idb-MXl8ilzmhAgsHWKV9c6ycQ'; |
| 575 | 556 | } |
| 576 | 557 | |
| 577 | 558 | /** |
| @@ -631,9 +612,9 @@ | ||
| 631 | 612 | * |
| 632 | 613 | * @return string |
| 633 | 614 | */ |
| 634 | 615 | private static function prepare_font_family_setting( $font ) { |
| 635 | - if ( false === strpos( $font, ',' ) ) { | |
| 616 | + if ( ! str_contains( $font, ',' ) ) { | |
| 636 | 617 | return $font; |
| 637 | 618 | } |
| 638 | 619 | |
| 639 | 620 | $fonts = explode( ',', $font ); |
| @@ -712,19 +693,9 @@ | ||
| 712 | 693 | if ( ! $has_processed ) { |
| 713 | 694 | return $errors; |
| 714 | 695 | } |
| 715 | 696 | |
| 716 | - $field_id = $field->temp_id ?? $field->id; | |
| 717 | - | |
| 718 | - if ( isset( $errors[ 'field' . $field_id . '-cc' ] ) ) { | |
| 719 | - unset( $errors[ 'field' . $field_id . '-cc' ] ); | |
| 720 | - } | |
| 721 | - | |
| 722 | - if ( isset( $errors[ 'field' . $field_id ] ) ) { | |
| 723 | - unset( $errors[ 'field' . $field_id ] ); | |
| 724 | - } | |
| 725 | - | |
| 726 | - return $errors; | |
| 697 | + return FrmTransLiteActionsController::remove_cc_errors( $errors, $field ); | |
| 727 | 698 | } |
| 728 | 699 | |
| 729 | 700 | /** |
| 730 | 701 | * @return void |