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

208 lines 6.1 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 frm_icon_font',
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' => 'var(--green)',
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 $currencies = FrmCurrencyHelper::get_currencies();
38 $repeat_times = FrmTransLiteAppHelper::get_repeat_times();
39
40 include FrmTransLiteAppHelper::plugin_path() . '/views/action-settings/payments-options.php';
41 }
42
43 /**
44 * Capturing a payment later is only available in the Stripe add on.
45 * This echos the HTML for a faded out capture payment dropdown.
46 * When it is clicked, it should prompt to install Stripe.
47 *
48 * @since 6.5
49 *
50 * @return void
51 */
52 public function echo_capture_payment_upsell() {
53 // Add an upsell placeholder for the capture payment setting.
54 $upgrading = FrmAddonsController::install_link( 'stripe' );
55 $upgrade_params = array();
56 if ( isset( $upgrading['url'] ) ) {
57 $upgrade_params['data-oneclick'] = json_encode( $upgrading );
58 } else {
59 $upgrade_params['data-requires'] = FrmAddonsController::get_addon_required_plan( 28136428 );
60 }
61 unset( $upgrading );
62 include FrmTransLiteAppHelper::plugin_path() . '/views/action-settings/capture-payments-upsell.php';
63 }
64
65 /**
66 * @return array
67 */
68 public function get_defaults() {
69 $defaults = array(
70 'description' => '',
71 'email' => '',
72 'amount' => '',
73 'type' => '',
74 'interval_count' => 1,
75 'interval' => 'month',
76 'payment_count' => 9999,
77 'trial_interval_count' => 0,
78 'currency' => $this->default_currency(),
79 'gateway' => array(),
80 'credit_card' => '',
81 'billing_first_name' => '',
82 'billing_last_name' => '',
83 );
84 return (array) apply_filters( 'frm_pay_action_defaults', $defaults );
85 }
86
87 /**
88 * @since 6.5, introduced in v2.01 of the Payments submodule.
89 *
90 * @return string
91 */
92 private function default_currency() {
93 $frm_settings = FrmAppHelper::get_settings();
94 $currency = trim( $frm_settings->currency );
95 if ( ! $currency ) {
96 $currency = 'USD';
97 }
98
99 return strtolower( $currency );
100 }
101
102 /**
103 * @param mixed $form_id
104 * @return array
105 */
106 public function get_field_options( $form_id ) {
107
108 $form_id = absint( $form_id );
109 $form_ids = $form_id;
110
111 /**
112 * Allows updating form ids used to query fields for displaying options with in the Payment action.
113 *
114 * @since 6.8
115 *
116 * @param int|int[] $form_ids
117 * @param int $form_id
118 */
119 $form_ids = apply_filters( 'frm_trans_action_get_field_options_form_id', $form_ids, $form_id );
120
121 $form_fields = FrmField::getAll(
122 array(
123 'fi.form_id' => $form_ids,
124 'fi.type not' => array( 'divider', 'end_divider', 'html', 'break', 'captcha', 'rte', 'form' ),
125 ),
126 'field_order'
127 );
128
129 return $form_fields;
130 }
131
132 /**
133 * Get the ID of the credit card field.
134 * We assume there is only a single credit card field in Stripe Lite.
135 * This is saved as part of the Stripe payment action.
136 *
137 * @param array $form_atts
138 * @return int
139 */
140 public function get_credit_card_field_id( $form_atts ) {
141 $field_id = 0;
142
143 foreach ( $form_atts['form_fields'] as $field ) {
144 if ( 'credit_card' === $field->type ) {
145 $field_id = (int) $field->id;
146 break;
147 }
148 }
149
150 return $field_id;
151 }
152
153 /**
154 * Show the dropdown fields for custom form fields.
155 * This is used for first and last name fields.
156 *
157 * @param array $form_atts
158 * @param array $field_atts
159 * @return void
160 */
161 public function show_fields_dropdown( $form_atts, $field_atts ) {
162 if ( ! isset( $field_atts['allowed_fields'] ) ) {
163 $field_atts['allowed_fields'] = array();
164 }
165 $has_field = false;
166 ?>
167 <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'] ) ); ?>">
168 <option value=""><?php esc_html_e( '&mdash; Select &mdash;', 'formidable' ); ?></option>
169 <?php
170 foreach ( $form_atts['form_fields'] as $field ) {
171 $type_is_allowed = empty( $field_atts['allowed_fields'] ) || in_array( $field->type, (array) $field_atts['allowed_fields'], true );
172
173 if ( ! $type_is_allowed ) {
174 continue;
175 }
176
177 $has_field = true;
178 $key_exists = array_key_exists( $field_atts['name'], $form_atts['form_action']->post_content );
179 ?>
180 <option value="<?php echo esc_attr( $field->id ); ?>" <?php selected( $key_exists ? $form_atts['form_action']->post_content[ $field_atts['name'] ] : 0, $field->id ); ?>>
181 <?php echo esc_attr( FrmAppHelper::truncate( $field->name, 50, 1 ) ); ?>
182 </option>
183 <?php
184 unset( $field );
185 }
186
187 if ( ! $has_field && ! empty( $field_atts['allowed_fields'] ) ) {
188 $readable_fields = str_replace( '_', ' ', implode( ', ', (array) $field_atts['allowed_fields'] ) );
189 ?>
190 <option value="">
191 <?php
192 // translators: %s: The comma separated field types expected in the form.
193 echo esc_html( sprintf( __( 'Oops! You need a %s field in your form.', 'formidable' ), $readable_fields ) );
194 ?>
195 </option>
196 <?php
197 }
198 ?>
199 </select>
200 <?php
201 }
202
203 public static function get_single_action_type( $action_id, $type = '' ) {
204 $action_control = FrmFormActionsController::get_form_actions( 'payment' );
205 return $action_control->get_single_action( $action_id );
206 }
207 }
208