-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Sergey Korney
committed
Apr 1, 2024
1 parent
f2d0c52
commit b5b21ff
Showing
36 changed files
with
1,150 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
AffiseAttributionLib/Classes/events/predefined/FailedPurchaseEvent.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
AffiseAttributionLib/Classes/internal/platform/InternalModules.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
AffiseAttributionLib/Classes/modules/subscription/AffiseProduct.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 ?? "")\")" | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
AffiseAttributionLib/Classes/modules/subscription/AffiseProductType.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
AffiseAttributionLib/Classes/modules/subscription/AffiseProductsResult.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: ", "))])" | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
AffiseAttributionLib/Classes/modules/subscription/AffisePurchasedInfo.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 ?? "")\")" | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
AffiseAttributionLib/Classes/modules/subscription/AffiseResult.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
5 changes: 5 additions & 0 deletions
5
AffiseAttributionLib/Classes/modules/subscription/AffiseSubscriptionApi.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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>) | ||
} |
17 changes: 17 additions & 0 deletions
17
AffiseAttributionLib/Classes/modules/subscription/AffiseSubscriptionError.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)" | ||
} | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
AffiseAttributionLib/Classes/modules/subscription/TimeUnitType.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
34
AffiseModule/Subscription/Classes/SubscriptionModule.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
17
AffiseModule/Subscription/Classes/store/StoreManager.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} | ||
|
Oops, something went wrong.