PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 6.35
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v6.35
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
formidable / stripe / models / FrmTransLiteAction.php

FrmTransLiteAction.php in Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More 6.35, at stripe/models/FrmTransLiteAction.php

260 lines 7.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 if ( ! defined( 'ABSPATH' ) ) {
3 die( 'You are not allowed to call this page directly.' );
4 }
5
6 class FrmTransLiteAction extends FrmFormAction {
7
8 public function __construct() {
9 $action_ops = array(
10 'classes' => 'frm_stripe_icon frm_credit_card_alt_icon frmfont',
11 // This is 99 in the Payments submodule but Stripe Lite only supports a single action.
12 'limit' => 1,
13 'active' => true,
14 // After user registration.
15 'priority' => 45,
16 'event' => array( 'create' ),
17 'color' => '#3fac25',
18 );
19
20 $this->FrmFormAction( 'payment', __( 'Collect a Payment', 'formidable' ), $action_ops );
21 }
22
23 /**
24 * @param WP_Post $instance
25 * @param array $args
26 */
27 public function form( $instance, $args = array() ) {
28 $form_action = $instance;
29
30 global $wpdb;
31
32 $list_fields = self::get_defaults();
33 $action_control = $this;
34 $options = $form_action->post_content;
35 $form_fields = $this->get_field_options( $args['form']->id );
36 $field_dropdown_atts = compact( 'form_fields', 'form_action' );
37 $repeat_times = FrmTransLiteAppHelper::get_repeat_times();
38 $gateways = FrmTransLiteAppHelper::get_gateways();
39
40 if ( ! isset( $form_action->post_content['payment_limit'] ) ) {
41 $form_action->post_content['payment_limit'] = '';
42 }
43
44 include FrmTransLiteAppHelper::plugin_path() . '/views/action-settings/payments-options.php';
45 }
46
47 /**
48 * Capturing a payment later is only available in the Stripe add on.
49 * This echos the HTML for a faded out capture payment dropdown.
50 * When it is clicked, it should prompt to install Stripe.
51 *
52 * @since 6.5
53 *
54 * @param string $selected_gateway The selected gateway for the given payment action.
55 *
56 * @return void
57 */
58 public function echo_capture_payment_upsell( $selected_gateway = 'stripe' ) {
59 // Add an upsell placeholder for the capture payment setting.
60 $upgrading = FrmAddonsController::install_link( 'stripe' );
61 $upgrade_params = array();
62
63 if ( isset( $upgrading['url'] ) ) {
64 $upgrade_params['data-oneclick'] = json_encode( $upgrading );
65 } else {
66 $upgrade_params['data-requires'] = FrmAddonsController::get_addon_required_plan( 28136428 );
67 }
68 unset( $upgrading );
69 include FrmTransLiteAppHelper::plugin_path() . '/views/action-settings/capture-payments-upsell.php';
70 }
71
72 /**
73 * @return array
74 */
75 public function get_defaults() {
76 $defaults = array(
77 'description' => '',
78 'email' => '',
79 'amount' => '',
80 'type' => '',
81 'interval_count' => 1,
82 'interval' => 'month',
83 'payment_count' => 9999,
84 'trial_interval_count' => 0,
85 'currency' => $this->default_currency(),
86 'gateway' => array(),
87 'credit_card' => '',
88 'billing_first_name' => '',
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',
96 );
97 return (array) apply_filters( 'frm_pay_action_defaults', $defaults );
98 }
99
100 /**
101 * @since 6.5, introduced in v2.01 of the Payments submodule.
102 *
103 * @return string
104 */
105 private function default_currency() {
106 $frm_settings = FrmAppHelper::get_settings();
107 $currency = trim( $frm_settings->currency );
108
109 if ( ! $currency ) {
110 $currency = 'USD';
111 }
112
113 return strtolower( $currency );
114 }
115
116 /**
117 * @param mixed $form_id
118 *
119 * @return array
120 */
121 public function get_field_options( $form_id ) {
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(
136 array(
137 'fi.form_id' => $form_ids,
138 'fi.type not' => array( 'divider', 'end_divider', 'html', 'break', 'captcha', 'rte', 'form' ),
139 ),
140 'field_order'
141 );
142 }
143
144 /**
145 * Get the ID of the credit card field.
146 * We assume there is only a single credit card field in Stripe Lite.
147 * This is saved as part of the Stripe payment action.
148 *
149 * @param array $form_atts
150 *
151 * @return int
152 */
153 public function get_credit_card_field_id( $form_atts ) {
154 $field_id = 0;
155
156 foreach ( $form_atts['form_fields'] as $field ) {
157 if ( 'credit_card' === $field->type ) {
158 $field_id = (int) $field->id;
159 break;
160 }
161 }
162
163 return $field_id;
164 }
165
166 /**
167 * Show the dropdown fields for custom form fields.
168 * This is used for first and last name fields.
169 *
170 * @since 6.18 The `$field_atts` might contain `skipped_fields`. By default, the submit field is skipped.
171 *
172 * @param array $form_atts
173 * @param array $field_atts
174 *
175 * @return void
176 */
177 public function show_fields_dropdown( $form_atts, $field_atts ) {
178 if ( ! isset( $field_atts['allowed_fields'] ) ) {
179 $field_atts['allowed_fields'] = array();
180 }
181
182 if ( ! isset( $field_atts['skipped_fields'] ) ) {
183 $field_atts['skipped_fields'] = array( FrmSubmitHelper::FIELD_TYPE );
184 }
185
186 $has_field = false;
187 // phpcs:disable Generic.WhiteSpace.ScopeIndent
188 ?>
189 <?php // phpcs:ignore SlevomatCodingStandard.Files.LineLength.LineTooLong ?>
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'] ) ); ?>">
191 <option value=""><?php esc_html_e( '&mdash; Select &mdash;' ); ?></option>
192 <?php
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
198 $type_is_allowed = empty( $field_atts['allowed_fields'] ) || in_array( $field->type, (array) $field_atts['allowed_fields'], true );
199
200 if ( ! $type_is_allowed ) {
201 continue;
202 }
203
204 $has_field = true;
205 $key_exists = array_key_exists( $field_atts['name'], $form_atts['form_action']->post_content );
206 ?>
207 <?php // phpcs:ignore SlevomatCodingStandard.Files.LineLength.LineTooLong ?>
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 ); ?>>
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 ?>
230 </option>
231 <?php
232 unset( $field );
233 }//end foreach
234
235 if ( ! $has_field && ! empty( $field_atts['allowed_fields'] ) ) {
236 $readable_fields = str_replace( '_', ' ', implode( ', ', (array) $field_atts['allowed_fields'] ) );
237 ?>
238 <option value="">
239 <?php
240 // translators: %s: The comma separated field types expected in the form.
241 echo esc_html( sprintf( __( 'Oops! You need a %s field in your form.', 'formidable' ), $readable_fields ) );
242 ?>
243 </option>
244 <?php
245 }
246 ?>
247 </select>
248 <?php
249 // phpcs:enable Generic.WhiteSpace.ScopeIndent
250 }
251
252 public static function get_single_action_type( $action_id, $type = '' ) {
253 /**
254 * @var FrmFormAction
255 */
256 $action_control = FrmFormActionsController::get_form_actions( 'payment' );
257 return $action_control->get_single_action( $action_id );
258 }
259 }
260