| @@ -37,9 +37,9 @@ | ||
| 37 | 37 | ] |
| 38 | 38 | ]; |
| 39 | 39 | |
| 40 | 40 | try{ |
| 41 | - $response = \Depicter::remote()->post( 'v2/client/register', $params ); | |
| 41 | + $response = \Depicter::remote()->post( 'v1/client/register', $params ); | |
| 42 | 42 | |
| 43 | 43 | $payload = JSON::decode( $response->getBody(), true ); |
| 44 | 44 | |
| 45 | 45 | if ( ! empty( $payload['client_key'] ) ) { |
| @@ -55,112 +55,8 @@ | ||
| 55 | 55 | } |
| 56 | 56 | } |
| 57 | 57 | |
| 58 | 58 | /** |
| 59 | - * Get refresh token | |
| 60 | - * | |
| 61 | - * @param bool $force_check | |
| 62 | - * @return string|bool | |
| 63 | - */ | |
| 64 | - public function getRefreshToken( $force_check = false ) { | |
| 65 | - | |
| 66 | - $refreshToken = \Depicter::cache('base')->get( 'refresh_token', '' ); | |
| 67 | - if ( !empty( $refreshToken ) && ! $force_check ) { | |
| 68 | - return $refreshToken; | |
| 69 | - } | |
| 70 | - | |
| 71 | - try{ | |
| 72 | - | |
| 73 | - $params = [ | |
| 74 | - 'form_params' => [ | |
| 75 | - 'version' => DEPICTER_VERSION, | |
| 76 | - 'version_initial' => \Depicter::options()->get('version_initial'), | |
| 77 | - ] | |
| 78 | - ]; | |
| 79 | - | |
| 80 | - $response = \Depicter::remote()->post( 'v2/token/refresh', $params ); | |
| 81 | - | |
| 82 | - $payload = JSON::decode( $response->getBody(), true ); | |
| 83 | - | |
| 84 | - if ( ! isset( $payload['errors'] ) && !empty( $payload['refreshToken'] ) ) { | |
| 85 | - if ( ! empty( $payload['clientKey'] ) ) { | |
| 86 | - \Depicter::options()->set( 'client_key', $payload['clientKey'] ); | |
| 87 | - \Depicter::cache('base')->set( 'is_client_registered', true, DAY_IN_SECONDS ); | |
| 88 | - } | |
| 89 | - \Depicter::cache('base')->set( 'refresh_token', $payload['refreshToken'], DAY_IN_SECONDS ); | |
| 90 | - return $payload['refreshToken']; | |
| 91 | - } | |
| 92 | - } catch ( GuzzleException|\Exception $e ) { | |
| 93 | - \Depicter::options()->set('refresh_token_error_message', $e->getMessage() ); | |
| 94 | - } | |
| 95 | - | |
| 96 | - return false; | |
| 97 | - } | |
| 98 | - | |
| 99 | - /** | |
| 100 | - * Get access token | |
| 101 | - * | |
| 102 | - * @param bool $force_check | |
| 103 | - * @return string|bool | |
| 104 | - */ | |
| 105 | - public function getAccessToken( $force_check = false ) { | |
| 106 | - | |
| 107 | - $accessToken = \Depicter::cache('base')->get( 'access_token', '' ); | |
| 108 | - if ( !empty( $accessToken ) && ! $force_check ) { | |
| 109 | - return $accessToken; | |
| 110 | - } | |
| 111 | - | |
| 112 | - try{ | |
| 113 | - | |
| 114 | - $response = \Depicter::remote()->post( 'v2/token/access', [ | |
| 115 | - 'form_params' => [ | |
| 116 | - 'refresh_token' => $this->getRefreshToken( $force_check ) | |
| 117 | - ] | |
| 118 | - ] ); | |
| 119 | - | |
| 120 | - $payload = JSON::decode( $response->getBody(), true ); | |
| 121 | - | |
| 122 | - if ( ! isset( $payload['errors'] ) && !empty( $payload['accessToken'] ) ) { | |
| 123 | - \Depicter::cache('base')->set( 'access_token', $payload['accessToken'], DAY_IN_SECONDS ); | |
| 124 | - return $payload['accessToken']; | |
| 125 | - } | |
| 126 | - } catch ( GuzzleException|\Exception $e ) { | |
| 127 | - \Depicter::options()->set('access_token_error_message', $e->getMessage() ); | |
| 128 | - } | |
| 129 | - | |
| 130 | - return false; | |
| 131 | - } | |
| 132 | - | |
| 133 | - /** | |
| 134 | - * Get id token | |
| 135 | - * | |
| 136 | - * @return string|bool | |
| 137 | - */ | |
| 138 | - public function getIdToken() { | |
| 139 | - | |
| 140 | - $idToken = \Depicter::cache('base')->get( 'id_token', '' ); | |
| 141 | - if ( !empty( $idToken ) ) { | |
| 142 | - return $idToken; | |
| 143 | - } | |
| 144 | - | |
| 145 | - try{ | |
| 146 | - | |
| 147 | - $response = \Depicter::remote()->post( 'v2/token/id' ); | |
| 148 | - | |
| 149 | - $payload = JSON::decode( $response->getBody(), true ); | |
| 150 | - | |
| 151 | - if ( ! isset( $payload['errors'] ) && !empty( $payload['idToken'] ) ) { | |
| 152 | - \Depicter::cache('base')->set( 'id_token', $payload['idToken'], MONTH_IN_SECONDS ); | |
| 153 | - return $payload['idToken']; | |
| 154 | - } | |
| 155 | - } catch ( GuzzleException|\Exception $e ) { | |
| 156 | - \Depicter::options()->set('id_token_error_message', $e->getMessage() ); | |
| 157 | - } | |
| 158 | - | |
| 159 | - return false; | |
| 160 | - } | |
| 161 | - | |
| 162 | - /** | |
| 163 | 59 | * Send user feedback |
| 164 | 60 | * |
| 165 | 61 | * @param array $bodyParams |
| 166 | 62 | * |
| @@ -211,32 +107,15 @@ | ||
| 211 | 107 | try { |
| 212 | 108 | $response = \Depicter::remote()->post( 'v1/client/validate/activation' ); |
| 213 | 109 | $info = JSON::decode( $response->getBody(), true); |
| 214 | 110 | |
| 215 | - | |
| 216 | 111 | if( is_null( $info['success'] ) ){ |
| 217 | 112 | \Depicter::options()->set('activation_error_message', '' ); |
| 218 | 113 | |
| 219 | 114 | } elseif ( ! empty( $info['data'] ) ) { |
| 220 | 115 | \Depicter::options()->set('subscription_status', $info['data']['status'] ); |
| 221 | - | |
| 222 | - if ( !empty( $info['data']['expires_at'] ) ) { | |
| 223 | - \Depicter::options()->set('subscription_expires_at', $info['data']['expires_at'] ); | |
| 224 | - } | |
| 225 | - | |
| 226 | - if ( !empty( $info['data']['subscription_id'] ) ) { | |
| 227 | - \Depicter::options()->set('subscription_id', $info['data']['subscription_id'] ); | |
| 228 | - } | |
| 229 | - | |
| 230 | - if ( !empty( $info['data']['manual_renew'] ) ) { | |
| 231 | - \Depicter::options()->set('manual_renew', $info['data']['manual_renew'] ); | |
| 232 | - } | |
| 233 | - | |
| 234 | - if ( empty( \Depicter::options()->get('initial_date', '') ) && !empty( $info['data']['created_at'] ) ) { | |
| 235 | - \Depicter::options()->set('initial_date', $info['data']['created_at'] ); | |
| 236 | - } | |
| 237 | - | |
| 238 | - \Depicter::options()->set('user_tier', $info['data']['user_tier'] ?? '' ); | |
| 116 | + \Depicter::options()->set('subscription_expires_at', $info['data']['expires_at'] ); | |
| 117 | + \Depicter::options()->set('user_tier', $info['data']['user_tier'] ); | |
| 239 | 118 | \Depicter::options()->set('activation_error_message', '' ); |
| 240 | 119 | |
| 241 | 120 | if ( $info['data']['status'] == 'active' ) { |
| 242 | 121 | return true; |
| @@ -251,21 +130,8 @@ | ||
| 251 | 130 | |
| 252 | 131 | } catch ( GuzzleException $exception ) { |
| 253 | 132 | \Depicter::options()->set('activation_error_message' , $exception->getMessage() ); |
| 254 | 133 | \Depicter::options()->set('connection_error_message' , $exception->getMessage() ); |
| 255 | - } | |
| 256 | - | |
| 257 | - return false; | |
| 258 | - } | |
| 259 | - | |
| 260 | - /** | |
| 261 | - * check if user is new or not | |
| 262 | - * @return bool | |
| 263 | - */ | |
| 264 | - public function isNewClient() { | |
| 265 | - $initialDate = \Depicter::options()->get('initial_date', ''); | |
| 266 | - if( empty( $initialDate ) || ( time() - strtotime( $initialDate ) <= 2 * DAY_IN_SECONDS ) ){ | |
| 267 | - return empty( \Depicter::documentRepository()->all( [ 'id' ] ) ); | |
| 268 | 134 | } |
| 269 | 135 | |
| 270 | 136 | return false; |
| 271 | 137 | } |