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

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