diff --git a/inc/class.mspecs-api-client.php b/inc/class.mspecs-api-client.php index 3b93c21..542ab67 100644 --- a/inc/class.mspecs-api-client.php +++ b/inc/class.mspecs-api-client.php @@ -207,4 +207,4 @@ public function add_buyer_to_viewing_slot($deal_id, $viewing_id, $slot_id, $buye public function generate_webhook_secret(){ return $this->request('PUT', 'provider/webhookSecret'); } -} \ No newline at end of file +} diff --git a/inc/class.mspecs-rest-api.php b/inc/class.mspecs-rest-api.php new file mode 100644 index 0000000..360c1fb --- /dev/null +++ b/inc/class.mspecs-rest-api.php @@ -0,0 +1,29 @@ + 'GET', + 'callback' => array('Mspecs_Rest_Api', 'handle_redirect'), + )); + }); + } + + public static function handle_redirect(){ + $token = $_GET['token']; + $token_parts = explode('.', $token); + $payload = $token_parts[1]; + $payload = base64_decode($payload); + + $payload = json_decode($payload, true); + + if(!$payload){ + echo 'Error decoding payload: '.json_last_error_msg(); + return; + } + + do_action( 'redirect_to_deal', $payload); + } +} + diff --git a/inc/class.mspecs-webhook.php b/inc/class.mspecs-webhook.php index 9254a55..e33f1cc 100644 --- a/inc/class.mspecs-webhook.php +++ b/inc/class.mspecs-webhook.php @@ -121,4 +121,4 @@ public static function install(){ $api_client->update_service($service_id, $data); } } -} \ No newline at end of file +} diff --git a/inc/class.mspecs.php b/inc/class.mspecs.php index 7b5f2cd..e41aac0 100644 --- a/inc/class.mspecs.php +++ b/inc/class.mspecs.php @@ -13,6 +13,7 @@ public static function init() { Mspecs_Sync_Manager::init(); Mspecs_Webhook::init(); Mspecs_Error_Handler::init(); + Mspecs_Rest_Api::init(); self::register_post_types(); } @@ -161,4 +162,4 @@ public static function get_api_client(){ return $api_client; } -} \ No newline at end of file +} diff --git a/mspecs.php b/mspecs.php index ca684a7..04dd5a3 100644 --- a/mspecs.php +++ b/mspecs.php @@ -22,6 +22,7 @@ require_once( MSPECS_PLUGIN_DIR . 'inc/class.mspecs-sync-manager.php' ); require_once( MSPECS_PLUGIN_DIR . 'inc/class.mspecs-webhook.php' ); require_once( MSPECS_PLUGIN_DIR . 'inc/class.mspecs-error-handler.php' ); +require_once( MSPECS_PLUGIN_DIR . 'inc/class.mspecs-rest-api.php' ); require_once( MSPECS_PLUGIN_DIR . 'public-api.php' ); add_action( 'init', array( 'Mspecs', 'init' ) ); @@ -29,4 +30,4 @@ function mspecs_test(){ mspecs_log('Test'); -} \ No newline at end of file +}