Skip to content

Commit

Permalink
Merge pull request #194 from qonversion/release/5.0.0
Browse files Browse the repository at this point in the history
Release 5.0.0
  • Loading branch information
SpertsyanKM authored Jul 5, 2024
2 parents 33b63f7 + 5171487 commit 2336e3e
Show file tree
Hide file tree
Showing 9 changed files with 134 additions and 74 deletions.
4 changes: 2 additions & 2 deletions QonversionSandwich.podspec
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Pod::Spec.new do |s|
excluded_files = ['ios/sandwich/AutomationsSandwich.swift', 'ios/sandwich/AutomationsEventListener.swift', 'ios/sandwich/AutomationsMappers.swift']
s.name = 'QonversionSandwich'
s.version = '4.5.0'
s.version = '5.0.0'
s.summary = 'qonversion.io'
s.swift_version = '5.0'
s.description = <<-DESC
Expand All @@ -19,5 +19,5 @@ Pod::Spec.new do |s|
s.source_files = 'ios/sandwich/**/*.{h,m,swift}'
s.pod_target_xcconfig = { 'DEFINES_MODULE' => 'YES' }

s.dependency "Qonversion", "5.10.0"
s.dependency "Qonversion", "5.11.0"
end
2 changes: 1 addition & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
buildscript {
ext {
release = [
versionName: "4.5.0"
versionName: "5.0.0"
]
}
}
Expand Down
2 changes: 1 addition & 1 deletion android/sandwich/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
buildscript {
ext.qonversion_version = '7.5.0'
ext.qonversion_version = '8.0.0'
}

plugins {
Expand Down
11 changes: 11 additions & 0 deletions android/sandwich/src/main/kotlin/io/qonversion/sandwich/Mappers.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import com.qonversion.android.sdk.dto.offerings.QOffering
import com.qonversion.android.sdk.dto.offerings.QOfferings
import com.qonversion.android.sdk.dto.products.QProduct
import com.qonversion.android.sdk.dto.products.QProductInAppDetails
import com.qonversion.android.sdk.dto.products.QProductInstallmentPlanDetails
import com.qonversion.android.sdk.dto.products.QProductOfferDetails
import com.qonversion.android.sdk.dto.products.QSubscriptionPeriod
import com.qonversion.android.sdk.dto.products.QProductPrice
Expand Down Expand Up @@ -102,6 +103,7 @@ fun QProductPricingPhase.toMap(): BridgeData {
"isBasePlan" to isBasePlan
)
}

fun QProductOfferDetails.toMap(): BridgeData {
return mapOf(
"basePlanId" to basePlanId,
Expand All @@ -110,6 +112,7 @@ fun QProductOfferDetails.toMap(): BridgeData {
"tags" to tags,
"pricingPhases" to pricingPhases.map { it.toMap() },
"basePlan" to basePlan?.toMap(),
"installmentPlanDetails" to installmentPlanDetails?.toMap(),
"trialPhase" to trialPhase?.toMap(),
"introPhase" to introPhase?.toMap(),
"hasTrial" to hasTrial,
Expand All @@ -118,6 +121,13 @@ fun QProductOfferDetails.toMap(): BridgeData {
)
}

fun QProductInstallmentPlanDetails.toMap(): BridgeData {
return mapOf(
"commitmentPaymentsCount" to commitmentPaymentsCount,
"subsequentCommitmentPaymentsCount" to subsequentCommitmentPaymentsCount
)
}

fun QProductPrice.toMap(): BridgeData {
return mapOf(
"priceAmountMicros" to priceAmountMicros,
Expand Down Expand Up @@ -152,6 +162,7 @@ fun QProductStoreDetails.toMap(): BridgeData {
"isInApp" to isInApp,
"isSubscription" to isSubscription,
"isPrepaid" to isPrepaid,
"isInstallment" to isInstallment
)
}

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,11 @@ class QonversionSandwich(
productId: String,
offerId: String?,
applyOffer: Boolean?,
resultListener: PurchaseResultListener
resultListener: ResultListener
) {
val currentActivity = activityProvider.currentActivity
?: run {
resultListener.onError(noActivityForPurchaseError.toSandwichError(), false)
resultListener.onError(noActivityForPurchaseError.toSandwichError())
return
}

Expand All @@ -105,7 +105,7 @@ class QonversionSandwich(
purchaseModel.removeOffer()
}

val purchaseCallback = getPurchaseCallback(resultListener)
val purchaseCallback = getEntitlementsCallback(resultListener)
Qonversion.shared.purchase(currentActivity, purchaseModel, purchaseCallback)
}

Expand All @@ -115,11 +115,11 @@ class QonversionSandwich(
applyOffer: Boolean?,
oldProductId: String,
updatePolicyKey: String?,
resultListener: PurchaseResultListener
resultListener: ResultListener
) {
val currentActivity = activityProvider.currentActivity
?: run {
resultListener.onError(noActivityForPurchaseError.toSandwichError(), false)
resultListener.onError(noActivityForPurchaseError.toSandwichError())
return
}

Expand All @@ -135,7 +135,7 @@ class QonversionSandwich(
purchaseUpdateModel.removeOffer()
}

val purchaseCallback = getPurchaseCallback(resultListener)
val purchaseCallback = getEntitlementsCallback(resultListener)
Qonversion.shared.updatePurchase(
currentActivity,
purchaseUpdateModel,
Expand Down Expand Up @@ -298,7 +298,7 @@ class QonversionSandwich(
fun attachUserToExperiment(experimentId: String, groupId: String, resultListener: ResultListener) {
Qonversion.shared.attachUserToExperiment(experimentId, groupId, object : QonversionExperimentAttachCallback {
override fun onSuccess() {
resultListener.onSuccess(emptySuccessResult())
resultListener.onSuccess(emptyResult(success = true))
}

override fun onError(error: QonversionError) {
Expand All @@ -310,7 +310,7 @@ class QonversionSandwich(
fun detachUserFromExperiment(experimentId: String, resultListener: ResultListener) {
Qonversion.shared.detachUserFromExperiment(experimentId, object : QonversionExperimentAttachCallback {
override fun onSuccess() {
resultListener.onSuccess(emptySuccessResult())
resultListener.onSuccess(emptyResult(success = true))
}

override fun onError(error: QonversionError) {
Expand All @@ -323,7 +323,7 @@ class QonversionSandwich(
Qonversion.shared.attachUserToRemoteConfiguration(remoteConfigurationId, object :
QonversionRemoteConfigurationAttachCallback {
override fun onSuccess() {
resultListener.onSuccess(emptySuccessResult())
resultListener.onSuccess(emptyResult(success = true))
}

override fun onError(error: QonversionError) {
Expand All @@ -336,7 +336,7 @@ class QonversionSandwich(
Qonversion.shared.detachUserFromRemoteConfiguration(remoteConfigurationId, object :
QonversionRemoteConfigurationAttachCallback {
override fun onSuccess() {
resultListener.onSuccess(emptySuccessResult())
resultListener.onSuccess(emptyResult(success = true))
}

override fun onError(error: QonversionError) {
Expand All @@ -351,12 +351,18 @@ class QonversionSandwich(
Qonversion.shared.syncHistoricalData()
}

fun isFallbackFileAccessible(resultListener: ResultListener) {
val isAccessible = Qonversion.shared.isFallbackFileAccessible()

resultListener.onSuccess(emptyResult(success = isAccessible))
}

// endregion

// region Private

private fun emptySuccessResult(): BridgeData {
return mapOf("success" to true)
private fun emptyResult(success: Boolean): BridgeData {
return mapOf("success" to success)
}

private interface ProductCallback {
Expand Down Expand Up @@ -434,18 +440,6 @@ class QonversionSandwich(
}
}

private fun getPurchaseCallback(resultListener: PurchaseResultListener) =
object : QonversionEntitlementsCallback {
override fun onSuccess(entitlements: Map<String, QEntitlement>) {
resultListener.onSuccess(entitlements.toEntitlementsMap())
}

override fun onError(error: QonversionError) {
val isCancelled = error.code == QonversionErrorCode.CanceledPurchase
resultListener.onError(error.toSandwichError(), isCancelled)
}
}

private fun getUserCallback(resultListener: ResultListener) =
object : QonversionUserCallback {
override fun onSuccess(user: QUser) {
Expand Down
2 changes: 1 addition & 1 deletion fastlane/report.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@



<testcase classname="fastlane.lanes" name="0: default_platform" time="0.000222">
<testcase classname="fastlane.lanes" name="0: default_platform" time="0.00017">

</testcase>

Expand Down
87 changes: 80 additions & 7 deletions ios/sandwich/Mappers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,81 @@ extension BridgeData {

extension NSError {
func toSandwichError() -> SandwichError {
// The commented codes below are for the next major iOS SDK version.
// After upgrading to that major replace two dictionaries of codes with this single one.
// let codes = [
// Qonversion.Error.unknown.rawValue: "Unknown",
// Qonversion.Error.purchaseCanceled.rawValue: "PurchaseCanceled",
// Qonversion.Error.productNotFound.rawValue: "ProductNotFound",
// Qonversion.Error.clientInvalid.rawValue: "ClientInvalid",
// Qonversion.Error.paymentInvalid.rawValue: "PaymentInvalid",
// Qonversion.Error.paymentNotAllowed.rawValue: "PaymentNotAllowed",
// Qonversion.Error.storeProductNotAvailable.rawValue: "StoreProductNotAvailable",
// Qonversion.Error.cloudServicePermissionDenied.rawValue: "CloudServicePermissionDenied",
// Qonversion.Error.cloudServiceNetworkConnectionFailed.rawValue: "CloudServiceNetworkConnectionFailed",
// Qonversion.Error.cloudServiceRevoked.rawValue: "CloudServiceRevoked",
// Qonversion.Error.privacyAcknowledgementRequired.rawValue: "PrivacyAcknowledgementRequired",
// Qonversion.Error.unauthorizedRequestData.rawValue: "UnauthorizedRequestData",
// Qonversion.Error.networkConnectionFailed.rawValue: "NetworkConnectionFailed",
// Qonversion.Error.internalError.rawValue: "InternalError",
// Qonversion.Error.purchasePending.rawValue: "PurchasePending",
// Qonversion.Error.remoteConfigurationNotAvailable.rawValue: "RemoteConfigurationNotAvailable",
// Qonversion.Error.failedToReceiveData.rawValue: "FailedToReceiveData",
// Qonversion.Error.responseParsingFailed.rawValue: "ResponseParsingFailed",
// Qonversion.Error.incorrectRequest.rawValue: "IncorrectRequest",
// Qonversion.Error.backendError.rawValue: "BackendError",
// Qonversion.Error.invalidCredentials.rawValue: "InvalidCredentials",
// Qonversion.Error.invalidClientUID.rawValue: "InvalidClientUid",
// Qonversion.Error.unknownClientPlatform.rawValue: "UnknownClientPlatform",
// Qonversion.Error.fraudPurchase.rawValue: "FraudPurchase",
// Qonversion.Error.featureNotSupported.rawValue: "FeatureNotSupported",
// Qonversion.Error.appleStoreError.rawValue: "AppleStoreError",
// Qonversion.Error.purchaseInvalid.rawValue: "PurchaseInvalid",
// Qonversion.Error.projectConfigError.rawValue: "ProjectConfigError",
// Qonversion.Error.invalidStoreCredentials.rawValue: "InvalidStoreCredentials",
// Qonversion.Error.receiptValidationError.rawValue: "ReceiptValidationError",
// Qonversion.Error.apiRateLimitExceeded.rawValue: "ApiRateLimitExceeded",
// ]
let codes = [
Qonversion.Error.unknown.rawValue: "Unknown",
Qonversion.Error.cancelled.rawValue: "PurchaseCanceled",
Qonversion.Error.productNotFound.rawValue: "ProductNotFound",
Qonversion.Error.clientInvalid.rawValue: "ClientInvalid",
Qonversion.Error.paymentInvalid.rawValue: "PaymentInvalid",
Qonversion.Error.paymentNotAllowed.rawValue: "PaymentNotAllowed",
Qonversion.Error.storeProductNotAvailable.rawValue: "StoreProductNotAvailable",
Qonversion.Error.cloudServicePermissionDenied.rawValue: "CloudServicePermissionDenied",
Qonversion.Error.cloudServiceNetworkConnectionFailed.rawValue: "CloudServiceNetworkConnectionFailed",
Qonversion.Error.cloudServiceRevoked.rawValue: "CloudServiceRevoked",
Qonversion.Error.privacyAcknowledgementRequired.rawValue: "PrivacyAcknowledgementRequired",
Qonversion.Error.unauthorizedRequestData.rawValue: "UnauthorizedRequestData",
Qonversion.Error.connectionFailed.rawValue: "NetworkConnectionFailed",
Qonversion.Error.internalError.rawValue: "InternalError",
Qonversion.Error.storePaymentDeferred.rawValue: "PurchasePending",
Qonversion.Error.remoteConfigurationNotAvailable.rawValue: "RemoteConfigurationNotAvailable",
]
let apiErrorCodes = [
Qonversion.APIError.failedReceiveData.rawValue: "FailedToReceiveData",
Qonversion.APIError.failedParseResponse.rawValue: "ResponseParsingFailed",
Qonversion.APIError.incorrectRequest.rawValue: "IncorrectRequest",
Qonversion.APIError.internalError.rawValue: "BackendError",
Qonversion.APIError.invalidCredentials.rawValue: "InvalidCredentials",
Qonversion.APIError.invalidClientUID.rawValue: "InvalidClientUid",
Qonversion.APIError.unknownClientPlatform.rawValue: "UnknownClientPlatform",
Qonversion.APIError.fraudPurchase.rawValue: "FraudPurchase",
Qonversion.APIError.featureNotSupported.rawValue: "FeatureNotSupported",
Qonversion.APIError.appleStoreError.rawValue: "AppleStoreError",
Qonversion.APIError.purchaseInvalid.rawValue: "PurchaseInvalid",
Qonversion.APIError.projectConfigError.rawValue: "ProjectConfigError",
Qonversion.APIError.invalidStoreCredentials.rawValue: "InvalidStoreCredentials",
Qonversion.APIError.receiptValidation.rawValue: "ReceiptValidationError",
Qonversion.APIError.rateLimitExceeded.rawValue: "ApiRateLimitExceeded",
]

let strCode = (domain == QonversionApiErrorDomain ? apiErrorCodes[code] : codes[code]) ?? "Unknown"

return SandwichError(
code: String(code),
code: strCode,
domain: domain,
details: localizedDescription,
additionalMessage: userInfo[NSDebugDescriptionErrorKey] as? String
Expand All @@ -54,12 +127,12 @@ extension NSError {

extension Qonversion.Product {
func toMap() -> BridgeData {
var subscriptionPeriodMap: BridgeData? = nil
var trialPeriodMap: BridgeData? = nil;
if #available(iOS 11.2, macOS 10.13.2, watchOS 6.2, tvOS 11.2, *) {
subscriptionPeriodMap = subscriptionPeriod?.toMap()
trialPeriodMap = trialPeriod?.toMap();
};
var subscriptionPeriodMap: BridgeData? = nil
var trialPeriodMap: BridgeData? = nil;
if #available(iOS 11.2, macOS 10.13.2, watchOS 6.2, tvOS 11.2, *) {
subscriptionPeriodMap = subscriptionPeriod?.toMap()
trialPeriodMap = trialPeriod?.toMap();
};

return [
"id": qonversionID,
Expand Down
Loading

0 comments on commit 2336e3e

Please sign in to comment.