Skip to content

Commit

Permalink
1.6.41
Browse files Browse the repository at this point in the history
  • Loading branch information
Sergey Korney committed Oct 1, 2024
1 parent 5f80306 commit ac6a3f6
Show file tree
Hide file tree
Showing 26 changed files with 445 additions and 103 deletions.
2 changes: 1 addition & 1 deletion AffiseAttributionLib.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

Pod::Spec.new do |spec|
spec.name = "AffiseAttributionLib"
spec.version = ENV['LIB_VERSION'] || "1.6.40"
spec.version = ENV['LIB_VERSION'] || "1.6.41"
spec.summary = "Affise Attribution iOS library"
spec.description = "Affise SDK is a software you can use to collect app usage statistics, device identifiers, deeplink usage, track install referrer."
spec.homepage = "https://github.com/affise/sdk-ios"
Expand Down
2 changes: 1 addition & 1 deletion AffiseAttributionLib/Classes/internal/BuildConfig.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Foundation

internal struct BuildConfig {
static let AFFISE_VERSION = "1.6.40"
static let AFFISE_VERSION = "1.6.41"
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,6 @@ public class AffiseProductPrice: NSObject {
formatter.numberStyle = .currency

let currencyCode = locale.currencyCode ?? ""

// if #available(iOS 16, *) {
// currencyCode = locale.currency?.identifier ?? "" // TODO
// }

self.init(
value: value,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ public enum AffiseSubscriptionError: Error {
case notInitialized
case productNotFound([String])
case purchaseFailed(Error?)
case userCancelled
}

extension AffiseSubscriptionError: CustomStringConvertible {
Expand All @@ -13,6 +14,7 @@ extension AffiseSubscriptionError: CustomStringConvertible {
case .notInitialized: return "affise not initialized"
case .productNotFound(let ids): return "product not found [\(ids.joined(separator: ", "))]"
case .purchaseFailed(let error): return "purchase failed: \(error?.localizedDescription ?? "")"
case .userCancelled: return "user cancelled"
}
}
}
4 changes: 4 additions & 0 deletions AffiseAttributionLib/Classes/utils/Array+Serialized.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ public extension Array where Element == (String, Any?) {
return "\"\(key)\":[\"\(value.joined(separator: "\",\""))\"]"
} else if let value = value as? [String] {
return "\"\(key)\":[\(value.joined(separator: ","))]"
} else if let value = value as? (String, Any?) {
return "\"\(key)\":\([value].jsonString())"
// } else if let value = value as? [String: Any?] {
// return "\"\(key)\":\(value.jsonString())"
} else if let value = value as? [(String, Any?)] {
return "\"\(key)\":\(value.jsonString())"
} else if let value = value as? [[(String, Any?)]] {
Expand Down
2 changes: 1 addition & 1 deletion AffiseInternal.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

Pod::Spec.new do |spec|
spec.name = "AffiseInternal"
spec.version = ENV['LIB_VERSION'] || "1.6.40"
spec.version = ENV['LIB_VERSION'] || "1.6.41"
spec.summary = "Affise Internal library"
spec.description = "Affise Internal wrapper library for crossplatform"
spec.homepage = "https://github.com/affise/sdk-ios"
Expand Down
4 changes: 2 additions & 2 deletions AffiseInternal/Classes/data/DataMapper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public class DataMapper {
DataName.PRODUCT: fromProduct(data.product),
DataName.ORDER_ID: data.orderId,
DataName.ORIGINAL_ORDER_ID: data.originalOrderId,
// DataName.PURCHASE: (data.purchase as? CustomStringConvertible)?.description, // TODO
// DataName.PURCHASE: data.purchase,
]
}

Expand All @@ -81,7 +81,7 @@ public class DataMapper {
DataName.PRODUCT_TYPE: product.productType?.enumValue,
DataName.PRICE: fromPrice(product.price),
DataName.SUBSCRIPTION: fromSubscription(product.subscription),
// DataName.PRODUCT_DETAILS: (product.productDetails as? CustomStringConvertible)?.description, // TODO
// DataName.PRODUCT_DETAILS: product.productDetails,
]
}

Expand Down
2 changes: 1 addition & 1 deletion AffiseModule.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

Pod::Spec.new do |s|
s.name = "AffiseModule"
s.version = ENV["LIB_VERSION"] || "1.6.40"
s.version = ENV["LIB_VERSION"] || "1.6.41"
s.summary = "Affise Modules"
s.description = "Affise module collection"
s.homepage = "https://github.com/affise/sdk-ios"
Expand Down
2 changes: 1 addition & 1 deletion AffiseModule/Advertising/Classes/AdvertisingModule.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import Foundation
@objc(AffiseAdvertisingModule)
public final class AdvertisingModule: AffiseModule {

public override var version: String { "1.6.40" }
public override var version: String { "1.6.41" }

private lazy var advertisingIdManager: AdvertisingIdManager = AdvertisingIdManagerImpl()

Expand Down
2 changes: 1 addition & 1 deletion AffiseModule/Link/Classes/LinkModule.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import AffiseAttributionLib
@objc(AffiseLinkModule)
public final class LinkModule: AffiseModule {

public override var version: String { "1.6.40" }
public override var version: String { "1.6.41" }

private var useCase: LinkResolveUseCase? = nil

Expand Down
2 changes: 1 addition & 1 deletion AffiseModule/Status/Classes/StatusModule.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import AffiseAttributionLib
@objc(AffiseStatusModule)
public final class StatusModule: AffiseModule {

public override var version: String { "1.6.40" }
public override var version: String { "1.6.41" }

private var checkStatusUseCase: CheckStatusUseCase? = nil
private var referrerUseCase: ReferrerUseCase? = nil
Expand Down
2 changes: 1 addition & 1 deletion AffiseModule/Subscription/Classes/SubscriptionModule.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import AffiseAttributionLib
@objc(AffiseSubscriptionModule)
public final class SubscriptionModule: AffiseModule {

public override var version: String { "1.6.40" }
public override var version: String { "1.6.41" }

lazy var storeManager: StoreManager = StoreManager()

Expand Down
16 changes: 14 additions & 2 deletions AffiseModule/Subscription/Classes/store/StoreManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,20 @@ import AffiseAttributionLib

internal class StoreManager: NSObject {

lazy var productManager: ProductManager = ProductManager()
lazy var transactionManager: TransactionManager = TransactionManager(productManager: productManager)
lazy var productManager: ProductManager = {
if #available(iOS 15.0, *) {
return ProductManagerSK2()
}
return ProductManagerSK1()
}()

lazy var transactionManager: TransactionManager = {
if #available(iOS 15.0, *) {
return TransactionManagerSK2(productManager: productManager)
}
return TransactionManagerSK1(productManager: productManager)
}()


func fetchProducts(_ productsIds: [String], _ callback: @escaping AffiseResultCallback<AffiseProductsResult>) {
productManager.fetchProducts(productsIds, callback)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import Foundation
import StoreKit
import AffiseAttributionLib

protocol ProductManager {
func fetchProducts(_ productsIds: [String], _ callback: @escaping AffiseResultCallback<AffiseProductsResult>)

func product(_ id: String) -> Any
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import Foundation
import StoreKit
import AffiseAttributionLib

protocol TransactionManager {
func purchase(_ product: AffiseProduct, _ type: AffiseProductType?, _ callback: @escaping AffiseResultCallback<AffisePurchasedInfo>)
}
78 changes: 58 additions & 20 deletions AffiseModule/Subscription/Classes/store/event/OperationEvent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,69 @@ import StoreKit
import AffiseAttributionLib

internal enum OperationEvent {

static func create(_ transaction: SKPaymentTransaction, product: SKProduct, type: AffiseProductType?, failed: Bool) -> Event? {
var timeUnit = ""
var numberOfUnits: Int64 = 0

if #available(iOS 11.2, *) {
timeUnit = product.subscriptionPeriod?.unitType.enumValue ?? ""
numberOfUnits = Int64(product.subscriptionPeriod?.numberOfUnits ?? 0)
}

return create(
orderId: transaction.transactionIdentifier,
originalOrderId: transaction.original?.transactionIdentifier,
productId: product.productIdentifier,
timeUnit: timeUnit,
numberOfUnits: numberOfUnits,
price: product.price.floatValue,
currency: product.priceLocale.currencyCode ?? "",

type: type ?? product.toAffiseSubscriptionType ?? .CONSUMABLE,
failed: failed
)
}

@available(iOS 15, *)
static func create(_ transaction: Transaction?, product: Product, type: AffiseProductType?, failed: Bool) -> Event? {
var timeUnit = product.subscription?.subscriptionPeriod.unitType.enumValue ?? ""
var numberOfUnits: Int = product.subscription?.subscriptionPeriod.value ?? 0
var orderId: String? = nil
var originalOrderId: String? = nil

if let transaction = transaction {
orderId = "\(transaction.id)"
originalOrderId = "\(transaction.originalID)"
}

return create(
orderId: orderId,
originalOrderId: originalOrderId,
productId: "\(product.id)",
timeUnit: timeUnit,
numberOfUnits: Int64(numberOfUnits),
price: NSDecimalNumber(decimal: product.price).floatValue,
currency: product.priceFormatStyle.currencyCode,

type: product.toAffiseSubscriptionType ?? type ?? .CONSUMABLE,
failed: failed
)
}

static func create(orderId: String?, originalOrderId: String?, productId: String, timeUnit: String, numberOfUnits: Int64, price: Float, currency: String, type: AffiseProductType, failed: Bool) -> Event? {
var event: Event?
let eventType: AffiseProductType = type ?? product.toAffiseSubscriptionType ?? .CONSUMABLE

let orderId: String? = transaction.transactionIdentifier
let originalOrderId: String? = transaction.original?.transactionIdentifier

switch eventType {

switch type {
case .CONSUMABLE, .NON_CONSUMABLE:
if failed {
event = AfFailedPurchaseEvent()
} else {
event = AfPurchaseEvent()
}
let _ = event?
.addPredefinedParameter(.PRODUCT_ID, string: product.productIdentifier)
.addPredefinedParameter(.PRODUCT_TYPE, string: eventType.enumValue)
.addPredefinedParameter(.PRODUCT_ID, string: productId)
.addPredefinedParameter(.PRODUCT_TYPE, string: type.enumValue)

case .RENEWABLE_SUBSCRIPTION, .NON_RENEWABLE_SUBSCRIPTION:
if failed {
Expand All @@ -32,17 +78,9 @@ internal enum OperationEvent {
}
}

var timeUnit = ""
var numberOfUnits: Int64 = 0

if #available(iOS 11.2, *) {
timeUnit = product.subscriptionPeriod?.unitType.enumValue ?? ""
numberOfUnits = Int64(product.subscriptionPeriod?.numberOfUnits ?? 0)
}

let _ = event?
.addPredefinedParameter(.SUBSCRIPTION_ID, string: product.productIdentifier)
.addPredefinedParameter(.SUBSCRIPTION_TYPE, string: eventType.enumValue)
.addPredefinedParameter(.SUBSCRIPTION_ID, string: productId)
.addPredefinedParameter(.SUBSCRIPTION_TYPE, string: type.enumValue)
.addPredefinedParameter(.UNIT, string: timeUnit)
.addPredefinedParameter(.QUANTITY, long: numberOfUnits)

Expand All @@ -52,7 +90,7 @@ internal enum OperationEvent {
return event?
.addPredefinedParameter(.ORDER_ID, string: orderId ?? "")
.addPredefinedParameter(.ORIGINAL_ORDER_ID, string: originalOrderId ?? "")
.addPredefinedParameter(.CURRENCY, string: product.priceLocale.currencyCode ?? "")
.addPredefinedParameter(.PRICE, float: product.price.floatValue)
.addPredefinedParameter(.CURRENCY, string: currency)
.addPredefinedParameter(.PRICE, float: price)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import StoreKit
import AffiseAttributionLib


internal class ProductManager: NSObject {
internal class ProductManagerSK1: NSObject {

private let queue = DispatchQueue(label: "Affise.ProductFetcher")

Expand All @@ -12,20 +12,6 @@ internal class ProductManager: NSObject {
private var callbacks: [[String]: [AffiseResultCallback<AffiseProductsResult>]] = [:]

private var requests: [SKRequest:[String]] = [:]

func fetchProducts(_ productsIds: [String], _ callback: @escaping AffiseResultCallback<AffiseProductsResult>) {
queue.async { [weak self] in
guard let self = self else { return }

if let callbacks = self.callbacks[productsIds] {
self.callbacks[productsIds] = callbacks + [callback]
return
}

self.callbacks[productsIds] = [callback]
self.productsRequest(productsIds)
}
}

func productsRequest(_ ids: [String]) {
let request = SKProductsRequest(productIdentifiers: Set(ids))
Expand All @@ -36,7 +22,7 @@ internal class ProductManager: NSObject {
}


extension ProductManager: SKProductsRequestDelegate {
extension ProductManagerSK1: SKProductsRequestDelegate {

func productsRequest(_ request: SKProductsRequest, didReceive response: SKProductsResponse) {
queue.async { [weak self] in
Expand Down Expand Up @@ -99,3 +85,24 @@ extension ProductManager: SKProductsRequestDelegate {
return (ids, handlers)
}
}

extension ProductManagerSK1: ProductManager {

func fetchProducts(_ productsIds: [String], _ callback: @escaping AffiseResultCallback<AffiseProductsResult>) {
queue.async { [weak self] in
guard let self = self else { return }

if let callbacks = self.callbacks[productsIds] {
self.callbacks[productsIds] = callbacks + [callback]
return
}

self.callbacks[productsIds] = [callback]
self.productsRequest(productsIds)
}
}

func product(_ id: String) -> Any {
return self.products[id]
}
}
Loading

0 comments on commit ac6a3f6

Please sign in to comment.