PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 6.8.1
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v6.8.1
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 / FrmTransLiteSubscriptionsController.php

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

161 lines 4.4 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 FrmTransLiteSubscriptionsController extends FrmTransLiteCRUDController {
7
8 /**
9 * @param object $subscription
10 * @return void
11 */
12 public static function load_sidebar_actions( $subscription ) {
13 $date_format = __( 'M j, Y @ G:i', 'formidable' );
14
15 FrmTransLiteActionsController::actions_js();
16
17 $frm_payment = new FrmTransLitePayment();
18 $payments = $frm_payment->get_all_by( $subscription->id, 'sub_id' );
19
20 include FrmTransLiteAppHelper::plugin_path() . '/views/subscriptions/sidebar_actions.php';
21 }
22
23 /**
24 * @since 6.5
25 *
26 * @param object $subscription
27 * @return void
28 */
29 public static function show_receipt_link( $subscription ) {
30 $link = esc_html( $subscription->sub_id );
31 if ( $subscription->sub_id !== 'None' ) {
32 /**
33 * Filter a receipt link for a specific gateway.
34 * For example, Stripe uses frm_sub_stripe_receipt.
35 *
36 * @since 6.5
37 *
38 * @param string $link
39 */
40 $link = apply_filters( 'frm_sub_' . $subscription->paysys . '_receipt', $link );
41 }
42
43 echo FrmAppHelper::kses( $link, array( 'a' ) ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
44 }
45
46 /**
47 * @param object $sub
48 * @param array $atts
49 * @return void
50 */
51 public static function show_cancel_link( $sub, $atts = array() ) {
52 if ( ! isset( $sub->user_id ) ) {
53 global $wpdb;
54 $sub->user_id = $wpdb->get_var( $wpdb->prepare( 'SELECT user_id FROM ' . $wpdb->prefix . 'frm_items WHERE id=%d', $sub->item_id ) );
55 }
56
57 $link = self::cancel_link( $sub, $atts );
58 FrmTransLiteAppHelper::echo_confirmation_link( $link );
59 }
60
61 /**
62 * @param object $sub
63 * @param array $atts
64 * @return string
65 */
66 public static function cancel_link( $sub, $atts = array() ) {
67 $defaults = array(
68 'cancel' => __( 'Cancel', 'formidable' ),
69 'canceled' => __( 'Canceled', 'formidable' ),
70 'confirm' => __( 'Are you sure you want to cancel that subscription?', 'formidable' ),
71 );
72 $atts = array_merge( $defaults, $atts );
73
74 if ( $sub->status === 'active' ) {
75 $link = admin_url( 'admin-ajax.php?action=frm_trans_cancel&sub=' . $sub->id . '&nonce=' . wp_create_nonce( 'frm_trans_ajax' ) );
76 $link = '<a href="' . esc_url( $link ) . '" class="frm_trans_ajax_link" data-frmverify="' . esc_attr( $atts['confirm'] ) . '" data-frmverify-btn="frm-button-red">';
77 $link .= esc_html( $atts['cancel'] );
78 $link .= '</a>';
79 } else {
80 $link = esc_html( $atts['canceled'] );
81 }
82
83 return $link;
84 }
85
86 /**
87 * Handle routing to cancel a subscription.
88 *
89 * @return void
90 */
91 public static function cancel_subscription() {
92 check_ajax_referer( 'frm_trans_ajax', 'nonce' );
93
94 $sub_id = FrmAppHelper::get_param( 'sub', '', 'get', 'sanitize_text_field' );
95 if ( $sub_id ) {
96 $frm_sub = new FrmTransLiteSubscription();
97 $sub = $frm_sub->get_one( $sub_id );
98 if ( $sub ) {
99 $canceled = FrmStrpLiteAppHelper::call_stripe_helper_class( 'cancel_subscription', $sub->sub_id );
100 if ( $canceled ) {
101 self::change_subscription_status(
102 array(
103 'status' => 'future_cancel',
104 'sub' => $sub,
105 )
106 );
107
108 $message = __( 'Canceled', 'formidable' );
109 } else {
110 $message = __( 'Failed', 'formidable' );
111 }
112 } else {
113 $message = __( 'That subscription was not found', 'formidable' );
114 }
115 } else {
116 $message = __( 'Oops! No subscription was selected for cancelation.', 'formidable' );
117 }//end if
118
119 echo esc_html( $message );
120 wp_die();
121 }
122
123 /**
124 * @since 6.5, introduced in v1.12 of the Payments submodule.
125 *
126 * @param array $atts
127 * @return void
128 */
129 public static function change_subscription_status( $atts ) {
130 $frm_sub = new FrmTransLiteSubscription();
131 $frm_sub->update( $atts['sub']->id, array( 'status' => $atts['status'] ) );
132 $atts['sub']->status = $atts['status'];
133
134 FrmTransLiteActionsController::trigger_subscription_status_change( $atts['sub'] );
135 }
136
137 /**
138 * @return null|string
139 */
140 public static function list_subscriptions_shortcode() {
141 if ( ! is_user_logged_in() ) {
142 return;
143 }
144
145 $frm_sub = new FrmTransLiteSubscription();
146 $subscriptions = $frm_sub->get_all_for_user( get_current_user_id() );
147 if ( empty( $subscriptions ) ) {
148 return;
149 }
150
151 FrmTransLiteActionsController::actions_js();
152
153 ob_start();
154 include FrmTransLiteAppHelper::plugin_path() . '/views/subscriptions/list_shortcode.php';
155 $content = ob_get_contents();
156 ob_end_clean();
157
158 return $content;
159 }
160 }
161