* @brief Deactivates the license on this machine; an offline certificate routes * to OfflineLicense::deactivate() so the UI, CLI, and API share one entry point. */
| 303 | * to OfflineLicense::deactivate() so the UI, CLI, and API share one entry point. |
| 304 | */ |
| 305 | void Licensing::LemonSqueezy::deactivate() |
| 306 | { |
| 307 | if (OfflineLicense::instance().isActivated()) { |
| 308 | OfflineLicense::instance().deactivate(); |
| 309 | return; |
| 310 | } |
| 311 | |
| 312 | if (!isOnlineActivated()) |
| 313 | return; |
| 314 | |
| 315 | if (busy()) |
| 316 | return; |
| 317 | |
| 318 | m_busy = true; |
| 319 | Q_EMIT busyChanged(); |
| 320 | |
| 321 | QJsonObject payload; |
| 322 | payload.insert("license_key", license()); |
| 323 | payload.insert("instance_id", instanceId()); |
| 324 | |
| 325 | auto url = QUrl("https://api.lemonsqueezy.com/v1/licenses/deactivate"); |
| 326 | auto payloadData = QJsonDocument(payload).toJson(QJsonDocument::Compact); |
| 327 | |
| 328 | QNetworkRequest req(url); |
| 329 | req.setTransferTimeout(15 * 1000); |
| 330 | req.setHeader(QNetworkRequest::ContentTypeHeader, "application/vnd.api+json"); |
| 331 | req.setRawHeader("Accept", "application/vnd.api+json"); |
| 332 | |
| 333 | auto* reply = m_manager.post(req, payloadData); |
| 334 | connect(reply, &QNetworkReply::finished, this, [this, reply]() { |
| 335 | if (reply->error() != QNetworkReply::NoError) |
| 336 | qWarning() << "[LemonSqueezy] Deactivation network error:" << reply->errorString(); |
| 337 | |
| 338 | readDeactivationResponse(reply->error() == QNetworkReply::NoError ? reply->readAll() |
| 339 | : QByteArray()); |
| 340 | reply->deleteLater(); |
| 341 | |
| 342 | writeSettings(); |
| 343 | }); |
| 344 | } |
| 345 | |
| 346 | /** |
| 347 | * @brief Opens the Lemon Squeezy customer portal in the default browser. |
nothing calls this directly
no test coverage detected