Skip to content

Commit

Permalink
Handle transactions asynchronously
Browse files Browse the repository at this point in the history
  • Loading branch information
NachoSoto committed Aug 16, 2023
1 parent 42a9891 commit 7abf1a5
Showing 1 changed file with 33 additions and 31 deletions.
64 changes: 33 additions & 31 deletions Sources/Purchasing/Purchases/PurchasesOrchestrator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1116,40 +1116,42 @@ private extension PurchasesOrchestrator {
let unsyncedAttributes = self.unsyncedAttributes
let adServicesToken = self.attribution.unsyncedAdServicesToken

self.transactionPoster.handlePurchasedTransaction(
purchasedTransaction,
data: .init(
appUserID: self.appUserID,
presentedOfferingID: offeringID,
unsyncedAttributes: unsyncedAttributes,
aadAttributionToken: adServicesToken,
storefront: storefront,
source: self.purchaseSource(for: purchasedTransaction.productIdentifier,
transaction: purchasedTransaction,
restored: restored)
)
) { result in
let completion: (@Sendable(Result<CustomerInfo, PurchasesError>) -> Void)? =
self.getAndRemovePurchaseCompletedCallback(forTransaction: purchasedTransaction)
.map { completion in
return { @Sendable result in
self.operationDispatcher.dispatchOnMainActor {
completion(
purchasedTransaction,
result.value,
result.error?.asPublicError,
result.error?.isCancelledError ?? false
)
self.operationDispatcher.dispatchOnWorkerThread {
self.transactionPoster.handlePurchasedTransaction(
purchasedTransaction,
data: .init(
appUserID: self.appUserID,
presentedOfferingID: offeringID,
unsyncedAttributes: unsyncedAttributes,
aadAttributionToken: adServicesToken,
storefront: storefront,
source: self.purchaseSource(for: purchasedTransaction.productIdentifier,
transaction: purchasedTransaction,
restored: restored)
)
) { result in
let completion: (@Sendable(Result<CustomerInfo, PurchasesError>) -> Void)? =
self.getAndRemovePurchaseCompletedCallback(forTransaction: purchasedTransaction)
.map { completion in
return { @Sendable result in
self.operationDispatcher.dispatchOnMainActor {
completion(
purchasedTransaction,
result.value,
result.error?.asPublicError,
result.error?.isCancelledError ?? false
)
}
}
}
}

self.handleReceiptPost(
result: result,
subscriberAttributes: unsyncedAttributes,
adServicesToken: adServicesToken,
completion: completion
)
self.handleReceiptPost(
result: result,
subscriberAttributes: unsyncedAttributes,
adServicesToken: adServicesToken,
completion: completion
)
}
}
}

Expand Down

0 comments on commit 7abf1a5

Please sign in to comment.