← All changes
|
stripe/controllers/FrmTransLiteActionsController.php
+61
-7
6.28
→
trunk
View file →
| @@ -410,8 +410,9 @@ | ||
| 410 | 410 | $settings_for_action = array( |
| 411 | 411 | 'id' => $payment_action->ID, |
| 412 | 412 | 'first_name' => $payment_action->post_content['billing_first_name'], |
| 413 | 413 | 'last_name' => $payment_action->post_content['billing_last_name'], |
| 414 | + 'address' => $payment_action->post_content['billing_address'] ?? '', | |
| 414 | 415 | 'gateways' => $payment_action->post_content['gateway'], |
| 415 | 416 | 'fields' => self::get_fields_for_price( $payment_action ), |
| 416 | 417 | 'one' => $payment_action->post_content['type'], |
| 417 | 418 | 'email' => $payment_action->post_content['email'], |
| @@ -456,13 +457,9 @@ | ||
| 456 | 457 | 'post_status' => 'publish', |
| 457 | 458 | ); |
| 458 | 459 | $payment_actions = FrmFormAction::get_action_for_form( $form_id, 'payment', $action_status ); |
| 459 | 460 | |
| 460 | - if ( ! $payment_actions ) { | |
| 461 | - return array(); | |
| 462 | - } | |
| 463 | - | |
| 464 | - return $payment_actions; | |
| 461 | + return $payment_actions ? $payment_actions : array(); | |
| 465 | 462 | } |
| 466 | 463 | |
| 467 | 464 | /** |
| 468 | 465 | * Make sure a gateway field is hidden on the front end. |
| @@ -476,8 +473,14 @@ | ||
| 476 | 473 | if ( $field->type !== 'gateway' ) { |
| 477 | 474 | return $values; |
| 478 | 475 | } |
| 479 | 476 | |
| 477 | + if ( FrmAppHelper::is_form_builder_page() ) { | |
| 478 | + // The hooks this uses can get called in the form builder and settings pages. | |
| 479 | + // But we do not need the script in this case. | |
| 480 | + return $values; | |
| 481 | + } | |
| 482 | + | |
| 480 | 483 | // This is also called from the frm_enqueue_form_scripts hook. |
| 481 | 484 | // With this here, the value of frm_stripe_vars.settings[0].fields is -1 |
| 482 | 485 | // This is because the amount value is processed and a shortcode is not found in '000'. |
| 483 | 486 | FrmStrpLiteActionsController::load_scripts( (int) $field->form_id ); |
| @@ -592,8 +595,14 @@ | ||
| 592 | 595 | $settings['credit_card'] = $credit_card_field_id; |
| 593 | 596 | } |
| 594 | 597 | } |
| 595 | 598 | |
| 599 | + if ( ! in_array( 'stripe', $settings['gateway'], true ) ) { | |
| 600 | + // We only need a gateway field for Stripe add-on compatibility, | |
| 601 | + // so unless Stripe is selected, we can return early. | |
| 602 | + return $settings; | |
| 603 | + } | |
| 604 | + | |
| 596 | 605 | $gateway_field_id = FrmDb::get_var( |
| 597 | 606 | 'frm_fields', |
| 598 | 607 | array( |
| 599 | 608 | 'type' => 'gateway', |
| @@ -638,9 +647,54 @@ | ||
| 638 | 647 | * |
| 639 | 648 | * @return false|int |
| 640 | 649 | */ |
| 641 | 650 | protected static function add_a_field( $form_id, $field_type, $field_name ) { |
| 642 | - $new_values = FrmFieldsHelper::setup_new_vars( $field_type, $form_id ); | |
| 643 | - $new_values['name'] = $field_name; | |
| 651 | + $new_values = FrmFieldsHelper::setup_new_vars( $field_type, $form_id ); | |
| 652 | + $new_values['name'] = $field_name; | |
| 653 | + $new_values['field_order'] = self::get_field_order_before_submit( $form_id, $new_values['field_order'] ); | |
| 644 | 654 | return FrmField::create( $new_values ); |
| 655 | + } | |
| 656 | + | |
| 657 | + /** | |
| 658 | + * When auto-injecting a field, ensure it is placed before the submit button. | |
| 659 | + * | |
| 660 | + * @since 6.29 | |
| 661 | + * | |
| 662 | + * @param int $form_id | |
| 663 | + * @param int $field_order | |
| 664 | + * | |
| 665 | + * @return int | |
| 666 | + */ | |
| 667 | + private static function get_field_order_before_submit( $form_id, $field_order ) { | |
| 668 | + $submit_field = FrmSubmitHelper::get_submit_field( $form_id ); | |
| 669 | + | |
| 670 | + if ( ! $submit_field || $field_order < (int) $submit_field->field_order ) { | |
| 671 | + return $field_order; | |
| 672 | + } | |
| 673 | + | |
| 674 | + $submit_order = (int) $submit_field->field_order; | |
| 675 | + FrmField::update( $submit_field->id, array( 'field_order' => $submit_order + 1 ) ); | |
| 676 | + return $submit_order; | |
| 677 | + } | |
| 678 | + | |
| 679 | + /** | |
| 680 | + * Remove credit card validation errors. | |
| 681 | + * | |
| 682 | + * @param array $errors | |
| 683 | + * @param stdClass $field | |
| 684 | + * | |
| 685 | + * @return array | |
| 686 | + */ | |
| 687 | + public static function remove_cc_errors( $errors, $field ) { | |
| 688 | + $field_id = $field->temp_id ?? $field->id; | |
| 689 | + | |
| 690 | + if ( isset( $errors[ 'field' . $field_id . '-cc' ] ) ) { | |
| 691 | + unset( $errors[ 'field' . $field_id . '-cc' ] ); | |
| 692 | + } | |
| 693 | + | |
| 694 | + if ( isset( $errors[ 'field' . $field_id ] ) ) { | |
| 695 | + unset( $errors[ 'field' . $field_id ] ); | |
| 696 | + } | |
| 697 | + | |
| 698 | + return $errors; | |
| 645 | 699 | } |
| 646 | 700 | } |