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 3.9 3.9-beta 3.9.1 3.9.2 3.9.3 4.0 4.0.1 4.0.2 4.0.3 4.1 4.1-beta 4.1.1 4.1.2 4.2 4.2-beta 4.2.1 4.2.2 4.3 4.3.1 4.4 4.4.1 4.4.2 4.5 4.5.1 4.6 4.6.1 4.7 4.8 4.8.1 4.9 4.9.1 4.9.2 5.0 5.0.1
contact-form-7 / modules / stripe / service.php
contact-form-7 / modules / stripe Last commit date
api.php 3 years ago index.asset.php 3 years ago index.js 4 years ago service.php 3 years ago stripe.php 3 years ago style.css 4 years ago
service.php
261 lines
1 <?php
2
3 if ( ! class_exists( 'WPCF7_Service' ) ) {
4 return;
5 }
6
7 class WPCF7_Stripe extends WPCF7_Service {
8
9 private static $instance;
10 private $api_keys;
11
12
13 public static function get_instance() {
14 if ( empty( self::$instance ) ) {
15 self::$instance = new self;
16 }
17
18 return self::$instance;
19 }
20
21
22 private function __construct() {
23 $option = WPCF7::get_option( 'stripe' );
24
25 if ( isset( $option['api_keys']['publishable'] )
26 and isset( $option['api_keys']['secret'] ) ) {
27 $this->api_keys = array(
28 'publishable' => $option['api_keys']['publishable'],
29 'secret' => $option['api_keys']['secret'],
30 );
31 }
32 }
33
34
35 public function get_title() {
36 return __( 'Stripe', 'contact-form-7' );
37 }
38
39
40 public function is_active() {
41 return (bool) $this->get_api_keys();
42 }
43
44
45 public function api() {
46 if ( $this->is_active() ) {
47 $api = new WPCF7_Stripe_API( $this->api_keys['secret'] );
48 return $api;
49 }
50 }
51
52
53 public function get_api_keys() {
54 return $this->api_keys;
55 }
56
57
58 public function get_categories() {
59 return array( 'payments' );
60 }
61
62
63 public function icon() {
64 }
65
66
67 public function link() {
68 echo wpcf7_link(
69 'https://stripe.com/',
70 'stripe.com'
71 );
72 }
73
74
75 protected function menu_page_url( $args = '' ) {
76 $args = wp_parse_args( $args, array() );
77
78 $url = menu_page_url( 'wpcf7-integration', false );
79 $url = add_query_arg( array( 'service' => 'stripe' ), $url );
80
81 if ( ! empty( $args ) ) {
82 $url = add_query_arg( $args, $url );
83 }
84
85 return $url;
86 }
87
88
89 protected function save_data() {
90 WPCF7::update_option( 'stripe', array(
91 'api_keys' => $this->api_keys,
92 ) );
93 }
94
95
96 protected function reset_data() {
97 $this->api_keys = null;
98 $this->save_data();
99 }
100
101
102 public function load( $action = '' ) {
103 if ( 'setup' == $action and 'POST' == $_SERVER['REQUEST_METHOD'] ) {
104 check_admin_referer( 'wpcf7-stripe-setup' );
105
106 if ( ! empty( $_POST['reset'] ) ) {
107 $this->reset_data();
108 $redirect_to = $this->menu_page_url( 'action=setup' );
109 } else {
110 $publishable = isset( $_POST['publishable'] ) ?
111 trim( $_POST['publishable'] ) : '';
112 $secret = isset( $_POST['secret'] ) ? trim( $_POST['secret'] ) : '';
113
114 if ( $publishable and $secret ) {
115 $this->api_keys = array(
116 'publishable' => $publishable,
117 'secret' => $secret,
118 );
119 $this->save_data();
120
121 $redirect_to = $this->menu_page_url( array(
122 'message' => 'success',
123 ) );
124 } else {
125 $redirect_to = $this->menu_page_url( array(
126 'action' => 'setup',
127 'message' => 'invalid',
128 ) );
129 }
130 }
131
132 wp_safe_redirect( $redirect_to );
133 exit();
134 }
135 }
136
137
138 public function admin_notice( $message = '' ) {
139 if ( 'invalid' == $message ) {
140 echo sprintf(
141 '<div class="notice notice-error"><p><strong>%1$s</strong>: %2$s</p></div>',
142 esc_html( __( "Error", 'contact-form-7' ) ),
143 esc_html( __( "Invalid key values.", 'contact-form-7' ) )
144 );
145 }
146
147 if ( 'success' == $message ) {
148 echo sprintf(
149 '<div class="notice notice-success"><p>%s</p></div>',
150 esc_html( __( 'Settings saved.', 'contact-form-7' ) )
151 );
152 }
153 }
154
155
156 public function display( $action = '' ) {
157 echo sprintf(
158 '<p>%s</p>',
159 // https://stripe.com/docs/partners/support#intro
160 esc_html( __( "Stripe is a simple and powerful way to accept payments online. Stripe has no setup fees, no monthly fees, and no hidden costs. Millions of businesses rely on Stripe’s software tools to accept payments securely and expand globally.", 'contact-form-7' ) )
161 );
162
163 echo sprintf(
164 '<p><strong>%s</strong></p>',
165 wpcf7_link(
166 __( 'https://contactform7.com/stripe-integration/', 'contact-form-7' ),
167 __( 'Stripe integration', 'contact-form-7' )
168 )
169 );
170
171 if ( $this->is_active() ) {
172 echo sprintf(
173 '<p class="dashicons-before dashicons-yes">%s</p>',
174 esc_html( __( "Stripe is active on this site.", 'contact-form-7' ) )
175 );
176 }
177
178 if ( 'setup' == $action ) {
179 $this->display_setup();
180 } elseif ( is_ssl() or WP_DEBUG ) {
181 echo sprintf(
182 '<p><a href="%1$s" class="button">%2$s</a></p>',
183 esc_url( $this->menu_page_url( 'action=setup' ) ),
184 esc_html( __( 'Setup Integration', 'contact-form-7' ) )
185 );
186 } else {
187 echo sprintf(
188 '<p class="dashicons-before dashicons-warning">%s</p>',
189 esc_html( __( "Stripe is not available on this site. It requires an HTTPS-enabled site.", 'contact-form-7' ) )
190 );
191 }
192 }
193
194
195 private function display_setup() {
196 $api_keys = $this->get_api_keys();
197
198 if ( $api_keys ) {
199 $publishable = $api_keys['publishable'];
200 $secret = $api_keys['secret'];
201 } else {
202 $publishable = '';
203 $secret = '';
204 }
205
206 ?>
207 <form method="post" action="<?php echo esc_url( $this->menu_page_url( 'action=setup' ) ); ?>">
208 <?php wp_nonce_field( 'wpcf7-stripe-setup' ); ?>
209 <table class="form-table">
210 <tbody>
211 <tr>
212 <th scope="row"><label for="publishable"><?php echo esc_html( __( 'Publishable Key', 'contact-form-7' ) ); ?></label></th>
213 <td><?php
214 if ( $this->is_active() ) {
215 echo esc_html( $publishable );
216 echo sprintf(
217 '<input type="hidden" value="%s" id="publishable" name="publishable" />',
218 esc_attr( $publishable )
219 );
220 } else {
221 echo sprintf(
222 '<input type="text" aria-required="true" value="%s" id="publishable" name="publishable" class="regular-text code" />',
223 esc_attr( $publishable )
224 );
225 }
226 ?></td>
227 </tr>
228 <tr>
229 <th scope="row"><label for="secret"><?php echo esc_html( __( 'Secret Key', 'contact-form-7' ) ); ?></label></th>
230 <td><?php
231 if ( $this->is_active() ) {
232 echo esc_html( wpcf7_mask_password( $secret ) );
233 echo sprintf(
234 '<input type="hidden" value="%s" id="secret" name="secret" />',
235 esc_attr( $secret )
236 );
237 } else {
238 echo sprintf(
239 '<input type="text" aria-required="true" value="%s" id="secret" name="secret" class="regular-text code" />',
240 esc_attr( $secret )
241 );
242 }
243 ?></td>
244 </tr>
245 </tbody>
246 </table>
247 <?php
248 if ( $this->is_active() ) {
249 submit_button(
250 _x( 'Remove Keys', 'API keys', 'contact-form-7' ),
251 'small', 'reset'
252 );
253 } else {
254 submit_button( __( 'Save Changes', 'contact-form-7' ) );
255 }
256 ?>
257 </form>
258 <?php
259 }
260 }
261