PluginProbe
Timetics – Appointment Booking Calendar & Scheduling / 1.0.22
Timetics – Appointment Booking Calendar & Scheduling v1.0.22
1.0.61 1.0.60 1.0.59 1.0.58 1.0.57 1.0.56 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.19 1.0.2 1.0.20 1.0.21 1.0.22 1.0.23 1.0.24 All 62 releases
timetics / core / integrations / stripe / api-stripe.php

api-stripe.php in Timetics – Appointment Booking Calendar & Scheduling 1.0.22, at core/integrations/stripe/api-stripe.php

93 lines 2.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Stripe payment api
4 *
5 * @package Timetics
6 */
7 namespace Timetics\Core\Integrations\Stripe;
8
9 use Timetics\Base\Api;
10 use Timetics\Utils\Singleton;
11 use WP_HTTP_Response;
12
13 /**
14 * Class Api Stripe
15 */
16 class Api_Stripe extends Api {
17 use Singleton;
18
19 /**
20 * Store api namespace
21 *
22 * @var string
23 */
24 protected $namespace = 'timetics/v1';
25
26 /**
27 * Store rest base
28 *
29 * @var string
30 */
31 protected $rest_base = 'stripe';
32
33 /**
34 * Register rest routes
35 *
36 * @return void
37 */
38 public function register_routes() {
39 /**
40 * Register route
41 *
42 * @var void
43 */
44 register_rest_route(
45 $this->namespace, $this->rest_base . '/payment', [
46 [
47 'methods' => \WP_REST_Server::CREATABLE,
48 'callback' => [ $this, 'create_payment' ],
49 'permission_callback' => function () {
50 return true;
51 },
52 ],
53 ]
54 );
55 }
56
57 /**
58 * Create stripe payment
59 *
60 * @param WP_Rest_Request $request
61 *
62 * @return JSON
63 */
64 public function create_payment( $request ) {
65 $data = json_decode( $request->get_body(), true );
66
67 $amount = ! empty( $data['amount'] ) ? floatval( $data['amount'] ) : 0;
68 $currency = ! empty( $data['currency'] ) ? sanitize_text_field( $data['currency'] ) : '';
69
70 $payment = new StripePayment();
71
72 $payment = $payment->create_payment(
73 [
74 'amount' => $amount * 100,
75 'currency' => $currency,
76 ]
77 );
78
79 if ( is_wp_error( $data ) ) {
80 $response = [
81 'success' => 0,
82 'status_code' => 403,
83 'message' => $payment->get_error_message(),
84 ];
85
86 return new WP_HTTP_Response( $response, 403 );
87 }
88
89 return rest_ensure_response( $payment );
90 }
91 }
92
93