PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 6.22
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v6.22
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 / controllers / FrmTransLitePaymentsController.php

FrmTransLitePaymentsController.php in Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More 6.22, at stripe/controllers/FrmTransLitePaymentsController.php

250 lines 6.9 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 FrmTransLitePaymentsController extends FrmTransLiteCRUDController {
7
8 /**
9 * @return void
10 */
11 public static function menu() {
12 if ( FrmTransLiteAppHelper::should_fallback_to_paypal() ) {
13 return;
14 }
15
16 $frm_settings = FrmAppHelper::get_settings();
17
18 // Remove the PayPal submenu (PayPal payments will just appear in the regular Payments page).
19 remove_action( 'admin_menu', 'FrmPaymentsController::menu', 26 );
20
21 if ( in_array( FrmAppHelper::simple_get( 'action' ), array( 'edit', 'new' ), true ) && is_callable( 'FrmPaymentsController::route' ) ) {
22 // Use the PayPal addon for add new and edit routing if it is active.
23 // This is required to support the "edit" link when using the Stripe Lite table view.
24 // It is also required for the "Add New" button to work on the payments table page.
25 $menu_route = 'FrmPaymentsController::route';
26 } else {
27 $menu_route = 'FrmTransLitePaymentsController::route';
28 }
29
30 $payments_string = __( 'Payments', 'formidable' );
31 add_submenu_page(
32 'formidable',
33 $frm_settings->menu . ' | ' . $payments_string,
34 self::payments_menu_title( $payments_string ),
35 'frm_view_entries',
36 'formidable-payments',
37 $menu_route
38 );
39 }
40
41 /**
42 * @since 6.11.1
43 *
44 * @param string $payments_string
45 *
46 * @return string
47 */
48 private static function payments_menu_title( $payments_string ) {
49 ob_start();
50 echo esc_html( $payments_string );
51 FrmAppHelper::show_pill_text();
52 return ob_get_clean();
53 }
54
55 /**
56 * @return void
57 */
58 public static function route() {
59 $action = isset( $_REQUEST['frm_action'] ) ? 'frm_action' : 'action';
60 $action = FrmAppHelper::get_param( $action, '', 'get', 'sanitize_title' );
61 $type = FrmAppHelper::get_param( 'type', '', 'get', 'sanitize_title' );
62
63 $class_name = $type === 'subscriptions' ? 'FrmTransLiteSubscriptionsController' : 'FrmTransLitePaymentsController';
64 if ( method_exists( $class_name, $action ) ) {
65 $class_name::$action();
66 return;
67 }
68
69 FrmTransLiteListsController::route( $action );
70 }
71
72 /**
73 * @param object $payment
74 * @return void
75 */
76 public static function load_sidebar_actions( $payment ) {
77 FrmTransLiteActionsController::actions_js();
78
79 $date_format = __( 'M j, Y @ G:i', 'formidable' );
80 $created_at = FrmAppHelper::get_localized_date( $date_format, $payment->created_at );
81 include FrmTransLiteAppHelper::plugin_path() . '/views/payments/sidebar_actions.php';
82 }
83
84 /**
85 * Echo a receipt link.
86 *
87 * @param object $payment
88 * @return void
89 */
90 public static function show_receipt_link( $payment ) {
91 $link = esc_html( $payment->receipt_id );
92 $paysys = $payment->paysys;
93
94 if ( $payment->receipt_id !== 'None' && self::should_filter_receipt_link( $paysys ) ) {
95 /**
96 * Filter a receipt link for a specific gateway.
97 * For example, Stripe uses frm_pay_stripe_receipt.
98 *
99 * @param string $link
100 */
101 $link = apply_filters( 'frm_pay_' . $paysys . '_receipt', $link );
102 }
103
104 FrmAppHelper::kses_echo( $link, array( 'a' ) );
105 }
106
107 /**
108 * @param string $paysys
109 *
110 * @return bool
111 */
112 private static function should_filter_receipt_link( $paysys ) {
113 $allowed_types = array( 'stripe', 'authnet_aim' );
114 return in_array( $paysys, $allowed_types, true );
115 }
116
117 /**
118 * Echo a refund link.
119 *
120 * @param object $payment
121 * @return void
122 */
123 public static function show_refund_link( $payment ) {
124 $link = self::refund_link( $payment );
125 FrmTransLiteAppHelper::echo_confirmation_link( $link );
126 }
127
128 /**
129 * Show a link to a payment entry (unless it is deleted).
130 *
131 * @param object $payment
132 * @return void
133 */
134 public static function show_entry_link( $payment ) {
135 $entry = FrmDb::get_col( 'frm_items', array( 'id' => $payment->item_id ) );
136
137 if ( ! $entry ) {
138 // translators: %d: Entry ID.
139 echo esc_html( sprintf( __( '%d (Deleted)', 'formidable' ), $payment->item_id ) );
140 return;
141 }
142
143 ?>
144 <a href="?page=formidable-entries&amp;action=show&amp;frm_action=show&amp;id=<?php echo absint( $payment->item_id ); ?>">
145 <?php echo absint( $payment->item_id ); ?>
146 </a>
147 <?php
148 }
149
150 /**
151 * Get a refund link.
152 *
153 * @param object $payment
154 * @return string
155 */
156 public static function refund_link( $payment ) {
157 if ( $payment->status === 'refunded' ) {
158 $link = esc_html__( 'Refunded', 'formidable' );
159 } else {
160 $confirm = __( 'Are you sure you want to refund that payment?', 'formidable' );
161
162 $link = admin_url( 'admin-ajax.php?action=frm_trans_refund&payment_id=' . $payment->id . '&nonce=' . wp_create_nonce( 'frm_trans_ajax' ) );
163 $link = '<a href="' . esc_url( $link ) . '" class="frm_trans_ajax_link" data-frmverify="' . esc_attr( $confirm ) . '">';
164 $link .= esc_html__( 'Refund', 'formidable' );
165 $link .= '</a>';
166 }
167
168 $paysys = $payment->paysys;
169 if ( self::should_filter_refund_link( $paysys ) ) {
170 /**
171 * Filter the refund link for a specific gateway.
172 * For example, Stripe uses frm_pay_stripe_refund_link.
173 *
174 * @param string $link
175 * @param object $payment
176 */
177 $link = apply_filters( 'frm_pay_' . $paysys . '_refund_link', $link, $payment );
178 }
179
180 return $link;
181 }
182
183 /**
184 * @param string $paysys
185 *
186 * @return bool
187 */
188 private static function should_filter_refund_link( $paysys ) {
189 $allowed_types = array( 'stripe', 'authnet_aim' );
190 return in_array( $paysys, $allowed_types, true );
191 }
192
193 /**
194 * Process the ajax request to refund a payment.
195 *
196 * @return void
197 */
198 public static function refund_payment() {
199 FrmAppHelper::permission_check( 'frm_edit_entries' );
200 check_ajax_referer( 'frm_trans_ajax', 'nonce' );
201
202 $payment_id = FrmAppHelper::get_param( 'payment_id', '', 'get', 'absint' );
203 if ( ! $payment_id ) {
204 wp_die( esc_html__( 'Oops! No payment was selected for refund.', 'formidable' ) );
205 }
206
207 $frm_payment = new FrmTransLitePayment();
208 $payment = $frm_payment->get_one( $payment_id );
209
210 switch ( $payment->paysys ) {
211 case 'stripe':
212 $refunded = FrmStrpLiteAppHelper::call_stripe_helper_class( 'refund_payment', $payment->receipt_id );
213 break;
214 case 'square':
215 $refunded = FrmSquareLiteConnectHelper::refund_payment( $payment->receipt_id );
216 break;
217 default:
218 $refunded = false;
219 break;
220 }
221
222 if ( $refunded ) {
223 self::change_payment_status( $payment, 'refunded' );
224 $message = __( 'Refunded', 'formidable' );
225 } else {
226 $message = __( 'Failed', 'formidable' );
227 }
228
229 wp_die( esc_html( $message ) );
230 }
231
232 /**
233 * Update the status of a payment.
234 *
235 * @param object $payment
236 * @param string $status
237 * @return void
238 */
239 public static function change_payment_status( $payment, $status ) {
240 if ( $status === $payment->status ) {
241 // The payment status has not actually changed.
242 return;
243 }
244
245 $frm_payment = new FrmTransLitePayment();
246 $frm_payment->update( $payment->id, array( 'status' => $status ) );
247 FrmTransLiteActionsController::trigger_payment_status_change( compact( 'status', 'payment' ) );
248 }
249 }
250