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

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