PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / trunk
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More vtrunk
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 / helpers / FrmStrpLiteAppHelper.php

FrmStrpLiteAppHelper.php in Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More trunk, at stripe/helpers/FrmStrpLiteAppHelper.php

175 lines 4.1 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 FrmStrpLiteAppHelper {
7
8 /**
9 * @var FrmStrpLiteSettings|null
10 */
11 private static $settings;
12
13 /**
14 * @return string
15 */
16 public static function plugin_path() {
17 return FrmAppHelper::plugin_path() . '/stripe/';
18 }
19
20 /**
21 * @return string
22 */
23 public static function plugin_folder() {
24 return basename( self::plugin_path() );
25 }
26
27 /**
28 * @return string
29 */
30 public static function plugin_url() {
31 return FrmAppHelper::plugin_url() . '/stripe/';
32 }
33
34 /**
35 * @param string $function
36 * @param array ...$params
37 *
38 * @return mixed
39 */
40 public static function call_stripe_helper_class( $function, ...$params ) {
41 if ( self::should_use_stripe_connect() && is_callable( "FrmStrpLiteConnectApiAdapter::$function" ) ) {
42 return FrmStrpLiteConnectApiAdapter::$function( ...$params );
43 }
44 return false;
45 }
46
47 /**
48 * @return bool true if we're using connect (versus the legacy integration).
49 */
50 public static function should_use_stripe_connect() {
51 if ( ! class_exists( 'FrmStrpLiteConnectApiAdapter' ) ) {
52 require __DIR__ . '/FrmStrpLiteConnectApiAdapter.php';
53 }
54 return FrmStrpLiteConnectApiAdapter::initialize_api();
55 }
56
57 /**
58 * @return bool true if either connect or the legacy integration is set up.
59 */
60 public static function stripe_is_configured() {
61 return self::call_stripe_helper_class( 'initialize_api' );
62 }
63
64 /**
65 * If test mode is running, save the id somewhere else
66 *
67 * @return string
68 */
69 public static function get_customer_id_meta_name() {
70 $meta_name = '_frmstrp_customer_id';
71
72 if ( 'test' === self::active_mode() ) {
73 $meta_name .= '_test';
74 }
75
76 return $meta_name;
77 }
78
79 /**
80 * @return FrmStrpLiteSettings
81 */
82 public static function get_settings() {
83 if ( ! isset( self::$settings ) ) {
84 self::$settings = new FrmStrpLiteSettings();
85 }
86 return self::$settings;
87 }
88
89 /**
90 * @return string
91 *
92 * @psalm-return 'live'|'test'
93 */
94 public static function active_mode() {
95 return self::get_settings()->settings->test_mode ? 'test' : 'live';
96 }
97
98 /**
99 * Add education about Stripe fees.
100 *
101 * @param string $content UTM Content for the admin upgrade link.
102 * @param array|false|string $gateway Gateway or list of gateways this applies to.
103 *
104 * @return void
105 */
106 public static function fee_education( $content = 'tip', $gateway = false ) {
107 if ( ! FrmAddonsController::payment_fees_apply( 'stripe' ) ) {
108 return;
109 }
110
111 $classes = 'frm-light-tip show_stripe';
112
113 if ( $gateway && ! array_intersect( (array) $gateway, array( 'stripe' ) ) ) {
114 $classes .= ' frm_hidden';
115 }
116
117 FrmTipsHelper::show_tip(
118 array(
119 'link' => array(
120 'campaign' => 'stripe-fee',
121 'content' => $content,
122 ),
123 'tip' => 'Pay as you go pricing: 3% fee per-transaction + Stripe fees.',
124 'call' => __( 'Upgrade to save on fees.', 'formidable' ),
125 'class' => $classes,
126 ),
127 'p'
128 );
129 }
130
131 /**
132 * Show a message to connect Stripe with link to settings.
133 *
134 * @return void
135 */
136 public static function not_connected_warning() {
137 // phpcs:disable Generic.WhiteSpace.ScopeIndent
138 ?>
139 <div class="frm_warning_style">
140 <span>
141 <?php
142 printf(
143 /* translators: %1$s: Link HTML, %2$s: End link */
144 esc_html__( 'Credit Cards will not work without connecting %1$sStripe%2$s, %3$sSquare%4$s, or %5$sPayPal%6$s first.', 'formidable' ),
145 // %1$s
146 '<a href="' . esc_url( admin_url( 'admin.php?page=formidable-settings&t=stripe_settings' ) ) . '" target="_blank">',
147 // %2$s
148 '</a>',
149 // %3$s
150 '<a href="' . esc_url( admin_url( 'admin.php?page=formidable-settings&t=square_settings' ) ) . '" target="_blank">',
151 // %4$s
152 '</a>',
153 // %5$s
154 '<a href="' . esc_url( admin_url( 'admin.php?page=formidable-settings&t=paypal_settings' ) ) . '" target="_blank">',
155 // %6$s
156 '</a>'
157 );
158 ?>
159 </span>
160 </div>
161 <?php
162 // phpcs:enable Generic.WhiteSpace.ScopeIndent
163 }
164
165 /**
166 * @deprecated 6.22
167 *
168 * @return bool
169 */
170 public static function is_debug() {
171 _deprecated_function( __METHOD__, '6.22' );
172 return defined( 'WP_DEBUG' ) && WP_DEBUG;
173 }
174 }
175