| @@ -6,15 +6,16 @@ | ||
| 6 | 6 | class FrmTransLiteAction extends FrmFormAction { |
| 7 | 7 | |
| 8 | 8 | public function __construct() { |
| 9 | 9 | $action_ops = array( |
| 10 | - 'classes' => 'frm_stripe_icon frm_credit_card_alt_icon frm_icon_font', | |
| 10 | + 'classes' => 'frm_stripe_icon frm_credit_card_alt_icon frmfont', | |
| 11 | 11 | // This is 99 in the Payments submodule but Stripe Lite only supports a single action. |
| 12 | 12 | 'limit' => 1, |
| 13 | 13 | 'active' => true, |
| 14 | - 'priority' => 45, // After user registration. | |
| 14 | + // After user registration. | |
| 15 | + 'priority' => 45, | |
| 15 | 16 | 'event' => array( 'create' ), |
| 16 | - 'color' => 'var(--green)', | |
| 17 | + 'color' => '#3fac25', | |
| 17 | 18 | ); |
| 18 | 19 | |
| 19 | 20 | $this->FrmFormAction( 'payment', __( 'Collect a Payment', 'formidable' ), $action_ops ); |
| 20 | 21 | } |
| @@ -32,11 +33,15 @@ | ||
| 32 | 33 | $action_control = $this; |
| 33 | 34 | $options = $form_action->post_content; |
| 34 | 35 | $form_fields = $this->get_field_options( $args['form']->id ); |
| 35 | 36 | $field_dropdown_atts = compact( 'form_fields', 'form_action' ); |
| 36 | - $currencies = FrmCurrencyHelper::get_currencies(); | |
| 37 | 37 | $repeat_times = FrmTransLiteAppHelper::get_repeat_times(); |
| 38 | + $gateways = FrmTransLiteAppHelper::get_gateways(); | |
| 38 | 39 | |
| 40 | + if ( ! isset( $form_action->post_content['payment_limit'] ) ) { | |
| 41 | + $form_action->post_content['payment_limit'] = ''; | |
| 42 | + } | |
| 43 | + | |
| 39 | 44 | include FrmTransLiteAppHelper::plugin_path() . '/views/action-settings/payments-options.php'; |
| 40 | 45 | } |
| 41 | 46 | |
| 42 | 47 | /** |
| @@ -45,14 +50,17 @@ | ||
| 45 | 50 | * When it is clicked, it should prompt to install Stripe. |
| 46 | 51 | * |
| 47 | 52 | * @since 6.5 |
| 48 | 53 | * |
| 54 | + * @param string $selected_gateway The selected gateway for the given payment action. | |
| 55 | + * | |
| 49 | 56 | * @return void |
| 50 | 57 | */ |
| 51 | - public function echo_capture_payment_upsell() { | |
| 58 | + public function echo_capture_payment_upsell( $selected_gateway = 'stripe' ) { | |
| 52 | 59 | // Add an upsell placeholder for the capture payment setting. |
| 53 | 60 | $upgrading = FrmAddonsController::install_link( 'stripe' ); |
| 54 | 61 | $upgrade_params = array(); |
| 62 | + | |
| 55 | 63 | if ( isset( $upgrading['url'] ) ) { |
| 56 | 64 | $upgrade_params['data-oneclick'] = json_encode( $upgrading ); |
| 57 | 65 | } else { |
| 58 | 66 | $upgrade_params['data-requires'] = FrmAddonsController::get_addon_required_plan( 28136428 ); |
| @@ -78,8 +86,14 @@ | ||
| 78 | 86 | 'gateway' => array(), |
| 79 | 87 | 'credit_card' => '', |
| 80 | 88 | 'billing_first_name' => '', |
| 81 | 89 | 'billing_last_name' => '', |
| 90 | + 'billing_address' => '', | |
| 91 | + 'shipping_email' => '', | |
| 92 | + 'shipping_first_name' => '', | |
| 93 | + 'shipping_last_name' => '', | |
| 94 | + 'shipping_address' => '', | |
| 95 | + 'entry_data_sync' => 'overwrite', | |
| 82 | 96 | ); |
| 83 | 97 | return (array) apply_filters( 'frm_pay_action_defaults', $defaults ); |
| 84 | 98 | } |
| 85 | 99 | |
| @@ -90,8 +104,9 @@ | ||
| 90 | 104 | */ |
| 91 | 105 | private function default_currency() { |
| 92 | 106 | $frm_settings = FrmAppHelper::get_settings(); |
| 93 | 107 | $currency = trim( $frm_settings->currency ); |
| 108 | + | |
| 94 | 109 | if ( ! $currency ) { |
| 95 | 110 | $currency = 'USD'; |
| 96 | 111 | } |
| 97 | 112 | |
| @@ -99,19 +114,32 @@ | ||
| 99 | 114 | } |
| 100 | 115 | |
| 101 | 116 | /** |
| 102 | 117 | * @param mixed $form_id |
| 118 | + * | |
| 103 | 119 | * @return array |
| 104 | 120 | */ |
| 105 | 121 | public function get_field_options( $form_id ) { |
| 106 | - $form_fields = FrmField::getAll( | |
| 122 | + $form_id = absint( $form_id ); | |
| 123 | + $form_ids = $form_id; | |
| 124 | + | |
| 125 | + /** | |
| 126 | + * Allows updating form ids used to query fields for displaying options with in the Payment action. | |
| 127 | + * | |
| 128 | + * @since 6.8 | |
| 129 | + * | |
| 130 | + * @param int|int[] $form_ids | |
| 131 | + * @param int $form_id | |
| 132 | + */ | |
| 133 | + $form_ids = apply_filters( 'frm_trans_action_get_field_options_form_id', $form_ids, $form_id ); | |
| 134 | + | |
| 135 | + return FrmField::getAll( | |
| 107 | 136 | array( |
| 108 | - 'fi.form_id' => absint( $form_id ), | |
| 137 | + 'fi.form_id' => $form_ids, | |
| 109 | 138 | 'fi.type not' => array( 'divider', 'end_divider', 'html', 'break', 'captcha', 'rte', 'form' ), |
| 110 | 139 | ), |
| 111 | 140 | 'field_order' |
| 112 | 141 | ); |
| 113 | - return $form_fields; | |
| 114 | 142 | } |
| 115 | 143 | |
| 116 | 144 | /** |
| 117 | 145 | * Get the ID of the credit card field. |
| @@ -118,8 +146,9 @@ | ||
| 118 | 146 | * We assume there is only a single credit card field in Stripe Lite. |
| 119 | 147 | * This is saved as part of the Stripe payment action. |
| 120 | 148 | * |
| 121 | 149 | * @param array $form_atts |
| 150 | + * | |
| 122 | 151 | * @return int |
| 123 | 152 | */ |
| 124 | 153 | public function get_credit_card_field_id( $form_atts ) { |
| 125 | 154 | $field_id = 0; |
| @@ -137,10 +166,13 @@ | ||
| 137 | 166 | /** |
| 138 | 167 | * Show the dropdown fields for custom form fields. |
| 139 | 168 | * This is used for first and last name fields. |
| 140 | 169 | * |
| 170 | + * @since 6.18 The `$field_atts` might contain `skipped_fields`. By default, the submit field is skipped. | |
| 171 | + * | |
| 141 | 172 | * @param array $form_atts |
| 142 | 173 | * @param array $field_atts |
| 174 | + * | |
| 143 | 175 | * @return void |
| 144 | 176 | */ |
| 145 | 177 | public function show_fields_dropdown( $form_atts, $field_atts ) { |
| 146 | 178 | if ( ! isset( $field_atts['allowed_fields'] ) ) { |
| @@ -145,14 +177,25 @@ | ||
| 145 | 177 | public function show_fields_dropdown( $form_atts, $field_atts ) { |
| 146 | 178 | if ( ! isset( $field_atts['allowed_fields'] ) ) { |
| 147 | 179 | $field_atts['allowed_fields'] = array(); |
| 148 | 180 | } |
| 181 | + | |
| 182 | + if ( ! isset( $field_atts['skipped_fields'] ) ) { | |
| 183 | + $field_atts['skipped_fields'] = array( FrmSubmitHelper::FIELD_TYPE ); | |
| 184 | + } | |
| 185 | + | |
| 149 | 186 | $has_field = false; |
| 187 | + // phpcs:disable Generic.WhiteSpace.ScopeIndent | |
| 150 | 188 | ?> |
| 189 | + <?php // phpcs:ignore SlevomatCodingStandard.Files.LineLength.LineTooLong ?> | |
| 151 | 190 | <select class="frm_with_left_label" name="<?php echo esc_attr( $this->get_field_name( $field_atts['name'] ) ); ?>" id="<?php echo esc_attr( $this->get_field_id( $field_atts['name'] ) ); ?>"> |
| 152 | - <option value=""><?php esc_html_e( '— Select —', 'formidable' ); ?></option> | |
| 191 | + <option value=""><?php esc_html_e( '— Select —' ); ?></option> | |
| 153 | 192 | <?php |
| 154 | 193 | foreach ( $form_atts['form_fields'] as $field ) { |
| 194 | + if ( $field_atts['skipped_fields'] && in_array( $field->type, (array) $field_atts['skipped_fields'], true ) ) { | |
| 195 | + continue; | |
| 196 | + } | |
| 197 | + | |
| 155 | 198 | $type_is_allowed = empty( $field_atts['allowed_fields'] ) || in_array( $field->type, (array) $field_atts['allowed_fields'], true ); |
| 156 | 199 | |
| 157 | 200 | if ( ! $type_is_allowed ) { |
| 158 | 201 | continue; |
| @@ -160,14 +203,35 @@ | ||
| 160 | 203 | |
| 161 | 204 | $has_field = true; |
| 162 | 205 | $key_exists = array_key_exists( $field_atts['name'], $form_atts['form_action']->post_content ); |
| 163 | 206 | ?> |
| 207 | + <?php // phpcs:ignore SlevomatCodingStandard.Files.LineLength.LineTooLong ?> | |
| 164 | 208 | <option value="<?php echo esc_attr( $field->id ); ?>" <?php selected( $key_exists ? $form_atts['form_action']->post_content[ $field_atts['name'] ] : 0, $field->id ); ?>> |
| 165 | - <?php echo esc_attr( FrmAppHelper::truncate( $field->name, 50, 1 ) ); ?> | |
| 209 | + <?php | |
| 210 | + echo esc_html( FrmAppHelper::truncate( $field->name, 50, 1 ) ); | |
| 211 | + | |
| 212 | + if ( 'name' === $field->type && isset( $field_atts['name'] ) ) { | |
| 213 | + switch ( $field_atts['name'] ) { | |
| 214 | + case 'billing_first_name': | |
| 215 | + case 'shipping_first_name': | |
| 216 | + echo ' ('; | |
| 217 | + esc_html_e( 'First', 'formidable' ); | |
| 218 | + echo ')'; | |
| 219 | + break; | |
| 220 | + | |
| 221 | + case 'billing_last_name': | |
| 222 | + case 'shipping_last_name': | |
| 223 | + echo ' ('; | |
| 224 | + esc_html_e( 'Last', 'formidable' ); | |
| 225 | + echo ')'; | |
| 226 | + break; | |
| 227 | + } | |
| 228 | + } | |
| 229 | + ?> | |
| 166 | 230 | </option> |
| 167 | 231 | <?php |
| 168 | 232 | unset( $field ); |
| 169 | - } | |
| 233 | + }//end foreach | |
| 170 | 234 | |
| 171 | 235 | if ( ! $has_field && ! empty( $field_atts['allowed_fields'] ) ) { |
| 172 | 236 | $readable_fields = str_replace( '_', ' ', implode( ', ', (array) $field_atts['allowed_fields'] ) ); |
| 173 | 237 | ?> |
| @@ -181,11 +245,15 @@ | ||
| 181 | 245 | } |
| 182 | 246 | ?> |
| 183 | 247 | </select> |
| 184 | 248 | <?php |
| 249 | + // phpcs:enable Generic.WhiteSpace.ScopeIndent | |
| 185 | 250 | } |
| 186 | 251 | |
| 187 | 252 | public static function get_single_action_type( $action_id, $type = '' ) { |
| 253 | + /** | |
| 254 | + * @var FrmFormAction | |
| 255 | + */ | |
| 188 | 256 | $action_control = FrmFormActionsController::get_form_actions( 'payment' ); |
| 189 | 257 | return $action_control->get_single_action( $action_id ); |
| 190 | 258 | } |
| 191 | 259 | } |