Skip to content

Commit

Permalink
1.6.28
Browse files Browse the repository at this point in the history
  • Loading branch information
Sergey Korney committed Apr 1, 2024
1 parent f2d0c52 commit b5b21ff
Show file tree
Hide file tree
Showing 36 changed files with 1,150 additions and 30 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.27"
spec.version = ENV['LIB_VERSION'] || "1.6.28"
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
1 change: 1 addition & 0 deletions AffiseAttributionLib/Classes/events/EventName.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public enum EventName: String {
case ORDER_RETURN_REQUEST = "OrderReturnRequest"
case ORDER_RETURN_REQUEST_CANCEL = "OrderReturnRequestCancel"
case PURCHASE = "Purchase"
case FAILED_PURCHASE = "FailedPurchase"
case RATE = "Rate"
case RE_ENGAGE = "ReEngage"
case RESERVE = "Reserve"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ public enum PredefinedString: Int {
case NETWORK
case UNIT
case PLACEMENT
case PRODUCT_TYPE
case SUBSCRIPTION_TYPE
case ORIGINAL_ORDER_ID

var enumValue: String {
switch self {
Expand Down Expand Up @@ -141,6 +144,9 @@ public enum PredefinedString: Int {
case .NETWORK: return "network"
case .UNIT: return "unit"
case .PLACEMENT: return "placement"
case .PRODUCT_TYPE: return "product_type"
case .SUBSCRIPTION_TYPE: return "subscription_type"
case .ORIGINAL_ORDER_ID: return "original_order_id"
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import Foundation

/**
* Event FailedPurchase use
*
* @property userData any custom data.
* @property timeStampMillis the timestamp event in milliseconds.
*/
@objc
public class FailedPurchaseEvent : NativeEvent {

override public func getName() -> String {
return EventName.FAILED_PURCHASE.eventName
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
public class InternalModules {

public static func getModule(_ name: AffiseModules) -> AffiseModule? {
return Affise.getApi()?.moduleManager.getModule(name)
}
}
2 changes: 2 additions & 0 deletions AffiseAttributionLib/Classes/modules/AffiseModules.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@ import Foundation
public enum AffiseModules: Int {
case Advertising
case Status
case Subscription

internal var enumValue: String {
switch self {
case .Advertising: return "Advertising"
case .Status: return "Status"
case .Subscription: return "Subscription"
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import Foundation

@objc
public class AffiseProduct: NSObject {

public internal(set) var type: AffiseProductType?

public internal(set) var productId: String?

public internal(set) var localizedTitle: String?

public internal(set) var localizedDescription: String?

public internal(set) var price: Decimal?

public internal(set) var currencyCode: String?

public internal(set) var currencySymbol: String?

public internal(set) var regionCode: String?

public internal(set) var priceLocale: Locale?

public internal(set) var skData: Any? = nil

public convenience init(
type: AffiseProductType?,
productId: String?,
localizedTitle: String?,
localizedDescription: String?,
price: Decimal?,
priceLocale: Locale?,
skData: Any?
) {
self.init()
self.type = type
self.productId = productId
self.localizedTitle = localizedTitle
self.localizedDescription = localizedDescription
self.price = price
self.currencyCode = priceLocale?.currencyCode
self.currencySymbol = priceLocale?.currencySymbol
self.regionCode = priceLocale?.regionCode
self.priceLocale = priceLocale
self.skData = skData
}

public override var description: String {
"AffiseProduct(productId=\"\(productId ?? "")\", localizedTitle=\"\(localizedTitle ?? "")\", price=\"\(price ?? 0)\", currencyCode=\"\(currencyCode ?? "")\", type=\"\(type?.enumValue ?? "")\")"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
@objc
public enum AffiseProductType: Int {

case CONSUMABLE
case NON_CONSUMABLE
case RENEWABLE_SUBSCRIPTION
case NON_RENEWABLE_SUBSCRIPTION

public var enumValue: String {
switch self {
case .CONSUMABLE: return "consumable"
case .NON_CONSUMABLE: return "non_consumable"
case .RENEWABLE_SUBSCRIPTION: return "renewable_subscription"
case .NON_RENEWABLE_SUBSCRIPTION: return "non_renewable_subscription"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
@objc
public class AffiseProductsResult: NSObject {

public let products: [String: AffiseProduct]

public let invalidIds: [String]

public init(products: [String: AffiseProduct], invalid: [String]) {
self.products = products
self.invalidIds = invalid
}

public override var description: String {
"AffiseProductsResult(products=[\(products.keys.joined(separator: ", "))], invalidIds=[\(invalidIds.joined(separator: ", "))])"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import Foundation


@objc
public class AffisePurchasedInfo: NSObject {

public internal(set) var product: AffiseProduct?

public internal(set) var operationDate: Date?

public internal(set) var orderId: String?

public internal(set) var originalOrderId: String?

public internal(set) var skData: Any? = nil

public convenience init(_ transaction: Any?, _ product: AffiseProduct?, orderId: String? = nil, originalOrderId: String?, operationDate: Date?) {
self.init()
self.skData = transaction
self.product = product
self.orderId = orderId
self.originalOrderId = originalOrderId
self.operationDate = operationDate
}

public override var description: String {
"AffisePurchasedInfo(productId=\"\(product?.productId ?? "")\", orderId=\"\(orderId ?? "")\", originalOrderId=\"\(originalOrderId ?? "")\")"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import Foundation

public typealias AffiseResult<Success> = Swift.Result<Success, Error>

public typealias AffiseResultCallback<Success> = (AffiseResult<Success>) -> Void
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
public protocol AffiseSubscriptionApi {
static func fetchProducts(_ productsIds: [String], _ callback: @escaping AffiseResultCallback<AffiseProductsResult>)

static func purchase(_ productId: String, _ type: AffiseProductType?, _ callback: @escaping AffiseResultCallback<AffisePurchasedInfo>)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import Foundation

public enum AffiseSubscriptionError: Error {
case notInitialized
case productNotFound([String])
case purchaseFailed(Error?)
}

extension AffiseSubscriptionError: CustomStringConvertible {
public var description: String {
switch self {
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)"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
@objc
public enum TimeUnitType: Int {

case DAY
case WEEK
case MONTH
case YEAR

public var enumValue: String {
switch self {
case .DAY: return "day"
case .WEEK: return "week"
case .MONTH: return "month"
case .YEAR: return "year"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import Foundation
class AffSDKVersionProvider: StringPropertyProvider {

override func provide() -> String? {
return "1.6.27"
return "1.6.28"
}

public override func getOrder() -> Float {
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.27"
spec.version = ENV['LIB_VERSION'] || "1.6.28"
spec.summary = "Affise Internal library"
spec.description = "Affise Internal wrapper library for crossplatform"
spec.homepage = "https://github.com/affise/sdk-ios"
Expand Down
7 changes: 6 additions & 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.27"
s.version = ENV["LIB_VERSION"] || "1.6.28"
s.summary = "Affise Modules"
s.description = "Affise module collection"
s.homepage = "https://github.com/affise/sdk-ios"
Expand All @@ -32,4 +32,9 @@ Pod::Spec.new do |s|
s.subspec "Advertising" do |sub|
sub.source_files = "AffiseModule/Advertising/Classes/**/*.{swift}"
end

s.subspec "Subscription" do |sub|
sub.source_files = "AffiseModule/Subscription/Classes/**/*.{swift}"
sub.framework = "StoreKit"
end
end
13 changes: 13 additions & 0 deletions AffiseModule/Subscription/Classes/AffiseExt.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import AffiseAttributionLib


extension Affise: AffiseSubscriptionApi {

public static func fetchProducts(_ ids: [String], _ callback: @escaping AffiseResultCallback<AffiseProductsResult>) {
SubscriptionModule.fetchProducts(ids, callback)
}

public static func purchase(_ id: String, _ type: AffiseProductType? = nil, _ callback: @escaping AffiseResultCallback<AffisePurchasedInfo>) {
SubscriptionModule.purchase(id, type, callback)
}
}
34 changes: 34 additions & 0 deletions AffiseModule/Subscription/Classes/SubscriptionModule.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import AffiseAttributionLib
import Foundation
import UIKit


@objc(AffiseSubscriptionModule)
internal final class SubscriptionModule: AffiseModule {

private(set) static var instance: SubscriptionModule? = nil

lazy var storeManager: StoreManager = StoreManager()

override public func start() {
SubscriptionModule.instance = self
}
}


extension SubscriptionModule: AffiseSubscriptionApi {

public static func fetchProducts(_ productsIds: [String], _ callback: @escaping AffiseResultCallback<AffiseProductsResult>) {
guard let module = instance else {
return callback(.failure(AffiseSubscriptionError.notInitialized))
}
module.storeManager.fetchProducts(productsIds, callback)
}

public static func purchase(_ productId: String, _ type: AffiseProductType? = nil, _ callback: @escaping AffiseResultCallback<AffisePurchasedInfo>) {
guard let module = instance else {
return callback(.failure(AffiseSubscriptionError.notInitialized))
}
module.storeManager.purchase(productId, type, callback)
}
}
17 changes: 17 additions & 0 deletions AffiseModule/Subscription/Classes/store/StoreManager.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import AffiseAttributionLib


internal class StoreManager: NSObject {

lazy var productManager: ProductManager = ProductManager()
lazy var transactionManager: TransactionManager = TransactionManager(productManager: productManager)

func fetchProducts(_ productsIds: [String], _ callback: @escaping AffiseResultCallback<AffiseProductsResult>) {
productManager.fetchProducts(productsIds, callback)
}

func purchase(_ productId: String, _ type: AffiseProductType?, _ callback: @escaping AffiseResultCallback<AffisePurchasedInfo>) {
transactionManager.purchase(productId, type, callback)
}
}

Loading

0 comments on commit b5b21ff

Please sign in to comment.