PluginProbe
Booktics – Appointment Booking Calendar for Service Businesses / 1.0.3
Booktics – Appointment Booking Calendar for Service Businesses v1.0.3
1.0.29 1.0.28 1.0.27 1.0.26 1.0.25 1.0.24 1.0.23 1.0.22 1.0.21 1.0.20 1.0.19 trunk 1.0.0 1.0.1 1.0.10 1.0.11 1.0.12 1.0.13 1.0.14 1.0.15 1.0.16 1.0.17 1.0.18 1.0.2 1.0.3 All 31 releases
booktics / core / module / stripe-addon / handler / stripe_handler.php

stripe_handler.php in Booktics – Appointment Booking Calendar for Service Businesses 1.0.3, at core/module/stripe-addon/handler/stripe_handler.php

95 lines 3.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Booktics\Module\Stripe_Addon\Handler;
4
5 use Booktics\Module\Stripe_Addon\Service\Stripe_Payment_Method;
6 use Booktics\Settings\Settings;
7
8 class Stripe_Handler {
9 /**
10 * Get the redirect URI for Stripe OAuth callback.
11 *
12 * @return string The redirect URI
13 */
14 private function get_redirect_uri( $type = 'test' ) {
15 $nonce = wp_create_nonce( 'booktics_stripe_callback' );
16
17 return admin_url( 'admin-ajax.php?action=booktics_stripe_callback&type=' . $type . '&_wpnonce=' . $nonce );
18 }
19
20 /**
21 * Get the Stripe secret key.
22 *
23 * @return string The Stripe secret key
24 */
25 public static function get_stripe_secret_key() {
26 $response = wp_remote_get( STRIPE_CONNECT_DOMAIN . '/wp-json/stripe/secret-key?type=' . Stripe_Payment_Method::account_type() );
27 if ( is_wp_error( $response ) ) {
28 return '';
29 }
30
31 return json_decode( wp_remote_retrieve_body( $response ) );
32 }
33
34 /**
35 * Get the Stripe Publishable key.
36 *
37 * @return string The Stripe publishable key
38 */
39 public static function get_stripe_publishable_key() {
40 $response = wp_remote_get( STRIPE_CONNECT_DOMAIN . '/wp-json/stripe/publishable-key?type=' . Stripe_Payment_Method::account_type() );
41 if ( is_wp_error( $response ) ) {
42 return '';
43 }
44
45 return json_decode( wp_remote_retrieve_body( $response ) );
46 }
47
48 /**
49 * Handle the OAuth callback from Stripe.
50 *
51 * @param array $request The request data
52 *
53 * @return \WP_REST_Response The response object
54 */
55 public static function handle_callback( $request ) {
56 if ( ! isset( $_GET['_wpnonce'] ) || ! wp_verify_nonce( wp_unslash( $_GET['_wpnonce'] ), 'booktics_stripe_callback' ) ) {
57 return rest_ensure_response( [
58 'status' => 'error',
59 'message' => __( 'Invalid security token', 'booktics' )
60 ] );
61 }
62
63 $account_id = isset( $_GET['account_id'] ) ? sanitize_text_field( wp_unslash( $_GET['account_id'] ) ) : '';
64 $type = isset( $_GET['type'] ) ? sanitize_text_field( wp_unslash( $_GET['type'] ) ) : 'test';
65
66 if ( ! $account_id ) {
67 return rest_ensure_response( [
68 'status' => 'error',
69 'message' => __( 'Missing account_id parameter', 'booktics' )
70 ] );
71 }
72
73 if ( ! empty( $account_id ) ) {
74 Settings::update( 'stripe_account_id', $account_id );
75 Settings::update( 'stripe_account_type', $type );
76
77 wp_redirect( admin_url( 'admin.php?page=booktics#/settings?tab=payment' ) );
78 exit;
79 }
80
81 return rest_ensure_response( [
82 'status' => 'error',
83 'message' => __( 'Stripe connection failed', 'booktics' )
84 ] );
85 }
86
87 /**
88 * Get the Stripe Connect authorization URL.
89 *
90 * @return string The authorization URL
91 */
92 public function get_connect_url( $type = 'test' ) {
93 return STRIPE_CONNECT_DOMAIN . '/stripe/connect?type=' . $type . '&redirect_uri=' . base64_encode( $this->get_redirect_uri( $type ) );
94 }
95 }