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

204 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 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 add_submenu_page( 'formidable', $frm_settings->menu . ' | Payments', 'Payments', 'frm_view_entries', 'formidable-payments', 'FrmTransLitePaymentsController::route' );
18 }
19
20 /**
21 * @return void
22 */
23 public static function route() {
24 $action = isset( $_REQUEST['frm_action'] ) ? 'frm_action' : 'action';
25 $action = FrmAppHelper::get_param( $action, '', 'get', 'sanitize_title' );
26 $type = FrmAppHelper::get_param( 'type', '', 'get', 'sanitize_title' );
27
28 $class_name = $type === 'subscriptions' ? 'FrmTransLiteSubscriptionsController' : 'FrmTransLitePaymentsController';
29 if ( method_exists( $class_name, $action ) ) {
30 $class_name::$action();
31 return;
32 }
33
34 FrmTransLiteListsController::route( $action );
35 }
36
37 /**
38 * @param object $payment
39 * @return void
40 */
41 public static function load_sidebar_actions( $payment ) {
42 FrmTransLiteActionsController::actions_js();
43
44 $date_format = __( 'M j, Y @ G:i', 'formidable' );
45 $created_at = FrmAppHelper::get_localized_date( $date_format, $payment->created_at );
46 include FrmTransLiteAppHelper::plugin_path() . '/views/payments/sidebar_actions.php';
47 }
48
49 /**
50 * Echo a receipt link.
51 *
52 * @param object $payment
53 * @return void
54 */
55 public static function show_receipt_link( $payment ) {
56 $link = esc_html( $payment->receipt_id );
57 $paysys = $payment->paysys;
58
59 if ( $payment->receipt_id !== 'None' && self::should_filter_receipt_link( $paysys ) ) {
60 /**
61 * Filter a receipt link for a specific gateway.
62 * For example, Stripe uses frm_pay_stripe_receipt.
63 *
64 * @param string $link
65 */
66 $link = apply_filters( 'frm_pay_' . $paysys . '_receipt', $link );
67 }
68
69 echo FrmAppHelper::kses( $link, array( 'a' ) ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
70 }
71
72 /**
73 * @param string $paysys
74 *
75 * @return bool
76 */
77 private static function should_filter_receipt_link( $paysys ) {
78 $allowed_types = array( 'stripe', 'authnet_aim' );
79 return in_array( $paysys, $allowed_types, true );
80 }
81
82 /**
83 * Echo a refund link.
84 *
85 * @param object $payment
86 * @return void
87 */
88 public static function show_refund_link( $payment ) {
89 $link = self::refund_link( $payment );
90 FrmTransLiteAppHelper::echo_confirmation_link( $link );
91 }
92
93 /**
94 * Show a link to a payment entry (unless it is deleted).
95 *
96 * @param object $payment
97 * @return void
98 */
99 public static function show_entry_link( $payment ) {
100 $entry = FrmDb::get_col( 'frm_items', array( 'id' => $payment->item_id ) );
101
102 if ( ! $entry ) {
103 // translators: %d: Entry ID.
104 echo esc_html( sprintf( __( '%d (Deleted)', 'formidable' ), $payment->item_id ) );
105 return;
106 }
107
108 ?>
109 <a href="?page=formidable-entries&amp;action=show&amp;frm_action=show&amp;id=<?php echo absint( $payment->item_id ); ?>">
110 <?php echo absint( $payment->item_id ); ?>
111 </a>
112 <?php
113 }
114
115 /**
116 * Get a refund link.
117 *
118 * @param object $payment
119 * @return string
120 */
121 public static function refund_link( $payment ) {
122 if ( $payment->status === 'refunded' ) {
123 $link = esc_html__( 'Refunded', 'formidable' );
124 } else {
125 $confirm = __( 'Are you sure you want to refund that payment?', 'formidable' );
126
127 $link = admin_url( 'admin-ajax.php?action=frm_trans_refund&payment_id=' . $payment->id . '&nonce=' . wp_create_nonce( 'frm_trans_ajax' ) );
128 $link = '<a href="' . esc_url( $link ) . '" class="frm_trans_ajax_link" data-frmverify="' . esc_attr( $confirm ) . '">';
129 $link .= esc_html__( 'Refund', 'formidable' );
130 $link .= '</a>';
131 }
132
133 $paysys = $payment->paysys;
134 if ( self::should_filter_refund_link( $paysys ) ) {
135 /**
136 * Filter the refund link for a specific gateway.
137 * For example, Stripe uses frm_pay_stripe_refund_link.
138 *
139 * @param string $link
140 * @param object $payment
141 */
142 $link = apply_filters( 'frm_pay_' . $paysys . '_refund_link', $link, $payment );
143 }
144
145 return $link;
146 }
147
148 /**
149 * @param string $paysys
150 *
151 * @return bool
152 */
153 private static function should_filter_refund_link( $paysys ) {
154 $allowed_types = array( 'stripe', 'authnet_aim' );
155 return in_array( $paysys, $allowed_types, true );
156 }
157
158 /**
159 * Process the ajax request to refund a payment.
160 *
161 * @return void
162 */
163 public static function refund_payment() {
164 FrmAppHelper::permission_check( 'frm_edit_entries' );
165 check_ajax_referer( 'frm_trans_ajax', 'nonce' );
166
167 $payment_id = FrmAppHelper::get_param( 'payment_id', '', 'get', 'absint' );
168 if ( ! $payment_id ) {
169 wp_die( esc_html__( 'Oops! No payment was selected for refund.', 'formidable' ) );
170 }
171
172 $frm_payment = new FrmTransLitePayment();
173 $payment = $frm_payment->get_one( $payment_id );
174 $refunded = FrmStrpLiteAppHelper::call_stripe_helper_class( 'refund_payment', $payment->receipt_id );
175
176 if ( $refunded ) {
177 self::change_payment_status( $payment, 'refunded' );
178 $message = __( 'Refunded', 'formidable' );
179 } else {
180 $message = __( 'Failed', 'formidable' );
181 }
182
183 wp_die( esc_html( $message ) );
184 }
185
186 /**
187 * Update the status of a payment.
188 *
189 * @param object $payment
190 * @param string $status
191 * @return void
192 */
193 public static function change_payment_status( $payment, $status ) {
194 if ( $status === $payment->status ) {
195 // The payment status has not actually changed.
196 return;
197 }
198
199 $frm_payment = new FrmTransLitePayment();
200 $frm_payment->update( $payment->id, array( 'status' => $status ) );
201 FrmTransLiteActionsController::trigger_payment_status_change( compact( 'status', 'payment' ) );
202 }
203 }
204