* @brief Persists fresh license fields, installs the commercial token, and notifies QML. */
| 609 | * @brief Persists fresh license fields, installs the commercial token, and notifies QML. |
| 610 | */ |
| 611 | void Licensing::LemonSqueezy::applyValidatedLicense(const QJsonObject& json, |
| 612 | const bool cachedResponse) |
| 613 | { |
| 614 | const auto meta = json.value("meta").toObject(); |
| 615 | const auto instance = json.value("instance").toObject(); |
| 616 | const auto licenseKey = json.value("license_key").toObject(); |
| 617 | |
| 618 | m_activated = true; |
| 619 | m_licensingData = json; |
| 620 | m_instanceId = instance.value("id").toString(); |
| 621 | m_variantName = meta.value("variant_name").toString(); |
| 622 | m_instanceName = instance.value("name").toString(); |
| 623 | m_seatLimit = licenseKey.value("activation_limit").toInt(-1); |
| 624 | m_seatUsage = licenseKey.value("activation_usage").toInt(-1); |
| 625 | m_customerName = meta.value("customer_name").toString(); |
| 626 | m_customerEmail = meta.value("customer_email").toString(); |
| 627 | m_activationDate = instance.value("created_at").toVariant().toDateTime(); |
| 628 | |
| 629 | updateAppNameFromVariant(m_variantName); |
| 630 | |
| 631 | CommercialToken token; |
| 632 | token.setVariantName(m_variantName); |
| 633 | token.setInstanceName(m_instanceName); |
| 634 | token.setGraceDaysRemaining(cachedResponse ? m_gracePeriod : 30); |
| 635 | token.setFeatureTier(tierFromVariant(m_variantName)); |
| 636 | token.seal(); |
| 637 | CommercialToken::setCurrent(token); |
| 638 | |
| 639 | m_busy = false; |
| 640 | Q_EMIT busyChanged(); |
| 641 | Q_EMIT licenseDataChanged(); |
| 642 | |
| 643 | if (!cachedResponse) { |
| 644 | const auto dt = QDateTime::currentDateTime().toString(Qt::RFC2822Date); |
| 645 | m_settings.beginGroup("licensing"); |
| 646 | m_settings.setValue("lastCheck", m_simpleCrypt.encryptToString(dt)); |
| 647 | m_settings.endGroup(); |
| 648 | } |
| 649 | |
| 650 | if (!m_silentValidation) { |
| 651 | m_silentValidation = true; |
| 652 | Q_EMIT activatedChanged(); |
| 653 | Misc::Utilities::showMessageBox( |
| 654 | tr("Your license has been successfully activated."), |
| 655 | tr("Thank you for supporting Serial Studio!\nYou now have access to all premium features."), |
| 656 | QMessageBox::Information); |
| 657 | } |
| 658 | } |
| 659 | |
| 660 | /** |
| 661 | * @brief Processes the response from the license validation request. |
nothing calls this directly
no test coverage detected