Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
b126a15
pigeon stuff
LouiseHsu Sep 3, 2024
ae9095a
refactored AND working heh
LouiseHsu Sep 4, 2024
c38b66f
format
LouiseHsu Sep 4, 2024
268a50e
pre refactor for cache
LouiseHsu Sep 4, 2024
f6ec07a
.
LouiseHsu Sep 4, 2024
aa36dfd
fix configuration file
LouiseHsu Sep 5, 2024
8724d40
more docs
LouiseHsu Sep 5, 2024
a6cbd98
more docs and clean up
LouiseHsu Sep 5, 2024
b75eec7
.
LouiseHsu Sep 13, 2024
4d2fd59
FIXED TESTING ISSUE
LouiseHsu Sep 24, 2024
aeef979
native tests are donesies
LouiseHsu Sep 25, 2024
acf499f
moreeee clean up and tests,
LouiseHsu Sep 26, 2024
c3c7204
format, comments, remove prints
LouiseHsu Sep 26, 2024
9021b6f
versioning, analyze
LouiseHsu Sep 26, 2024
666df56
symlink the test files
LouiseHsu Sep 26, 2024
97b746f
fix mac cant build
LouiseHsu Sep 26, 2024
add5bf5
podspec, licensing
LouiseHsu Sep 26, 2024
06b42d0
.
LouiseHsu Sep 27, 2024
0701d2a
remove any to get around old linter
LouiseHsu Sep 27, 2024
8f225c0
remove more anys to appease format gods
LouiseHsu Sep 27, 2024
2c6efdb
Merge branch 'main' into iap_add_purchase
LouiseHsu Sep 27, 2024
72ce51c
a lil bit of refactioring
LouiseHsu Oct 1, 2024
2e940fe
Merge branch 'iap_add_purchase' of github.com:LouiseHsu/packages into…
LouiseHsu Oct 1, 2024
442c158
better error messages
LouiseHsu Oct 1, 2024
f48510b
some refactoring
LouiseHsu Oct 1, 2024
6076bf1
.
LouiseHsu Oct 1, 2024
d8dcad2
remove uneeded filed
LouiseHsu Oct 2, 2024
9c2893b
oops pathing
LouiseHsu Oct 2, 2024
1a74fb7
.
LouiseHsu Oct 2, 2024
1b688ae
.
LouiseHsu Oct 2, 2024
74c2de3
.
LouiseHsu Oct 4, 2024
71c9a1b
.
LouiseHsu Oct 4, 2024
582156b
no message
LouiseHsu Oct 4, 2024
e6bec70
.
LouiseHsu Oct 7, 2024
80795b9
.
LouiseHsu Oct 7, 2024
66362c3
.
LouiseHsu Oct 8, 2024
e554f5e
rename getter
LouiseHsu Oct 8, 2024
5a08a58
.
LouiseHsu Oct 8, 2024
0428829
try embeding?
LouiseHsu Oct 8, 2024
7c38281
rerun tests
LouiseHsu Oct 8, 2024
ec5c05c
change files so theyre relative to project rather than group
LouiseHsu Oct 10, 2024
44bcde2
.
LouiseHsu Oct 14, 2024
192b004
change from symlink
LouiseHsu Oct 15, 2024
63be3ea
.
LouiseHsu Oct 15, 2024
edead37
-m "revert"
LouiseHsu Oct 15, 2024
3ece0be
Revert "change from symlink"
LouiseHsu Oct 15, 2024
1681503
remove dev team?
LouiseHsu Oct 15, 2024
1f6957f
.
LouiseHsu Oct 15, 2024
abca747
.
LouiseHsu Oct 15, 2024
d22f360
try without test files at all
LouiseHsu Oct 16, 2024
f47a111
pls
LouiseHsu Oct 16, 2024
dbc619c
remove tests again
LouiseHsu Oct 16, 2024
7eb3d9d
Revert "remove tests again"
LouiseHsu Oct 16, 2024
1af5bff
link both storekittest and storekit
LouiseHsu Oct 16, 2024
32458c3
remove mac tests
LouiseHsu Oct 16, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
a lil bit of refactioring
  • Loading branch information
LouiseHsu committed Oct 1, 2024
commit 72ce51c3fae1f72123293af440f2a8fbb3f5bc57
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public class InAppPurchasePlugin: NSObject, FlutterPlugin, InAppPurchaseAPI {
public var registrar: FlutterPluginRegistrar?
// This property is optional, as it requires self to exist to be initialized.
public var paymentQueueHandler: FLTPaymentQueueHandlerProtocol?

internal var updateListenerTask: Any?
internal var transactionListenerAPI: TransactionCallbacks? = nil

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// found in the LICENSE file.

@available(iOS 15.0, macOS 12.0, *)
extension InAppPurchasePlugin: InAppPurchase2API {
extension InAppPurchasePlugin: @preconcurrency InAppPurchase2API {
// MARK: - Pigeon Functions

// Wrapper method around StoreKit2's canMakePayments() method
Expand Down Expand Up @@ -37,6 +37,7 @@ extension InAppPurchasePlugin: InAppPurchase2API {

// Gets the appropriate product, then calls purchase on it.
// https://developer.apple.com/documentation/storekit/product/3791971-purchase
@MainActor
func purchase(
id: String, options: SK2ProductPurchaseOptionsMessage?,
completion: @escaping (Result<SK2ProductPurchaseResultMessage, Error>) -> Void
Expand All @@ -58,32 +59,34 @@ extension InAppPurchasePlugin: InAppPurchase2API {
case .success(let verification):
switch verification {
case .verified(let transaction):
DispatchQueue.main.async {
self.transactionListenerAPI?.transactionUpdated(updatedTransactions: transaction)
}
self.transactionListenerAPI?.transactionUpdated(updatedTransactions: transaction)
completion(.success(result.convertToPigeon()))
case .unverified(_, let error):
completion(.failure(error))
}
case .pending:
completion(
.success(.pending))
.failure(
PigeonError(
code: "storekit2_purchase_pending",
message: "This transaction is still pending.", details: "")))
case .userCancelled:
completion(
.failure(
PigeonError(
code: "storekit2_purchase_cancelled",
message: "this transaction has been cancelled", details: "")))
message: "This transaction has been cancelled.", details: "")))
@unknown default:
fatalError()
fatalError("An unknown StoreKit PurchaseResult has been encountered.")
}
} catch {
completion(.failure(error))
}

}
}

/// Wrapper method around StoreKit2's transactions() method
/// https://developer.apple.com/documentation/storekit/product/3851116-products
func transactions(
completion: @escaping (Result<[SK2TransactionMessage], Error>) -> Void
) {
Expand All @@ -97,26 +100,21 @@ extension InAppPurchasePlugin: InAppPurchase2API {
}
}

/// Wrapper method around StoreKit2's finish() method https://developer.apple.com/documentation/storekit/transaction/3749694-finish
func finish(id: Int64, completion: @escaping (Result<Void, Error>) -> Void) {
Task {
let transaction = try await fetchTransaction(by: UInt64(id))
if let transaction = transaction {
await transaction.finish()
}

}
}

/// This Task listens to Transation.updates as shown here
/// https://developer.apple.com/documentation/storekit/transaction/3851206-updates
/// This function should be called as soon as the app starts to avoid missing any Transactions done outside of the app.
func startListeningToTransactions() throws {
self.updateListenerTask = self.listenForTransactions()
}

func stopListeningToTransactions() throws {
self.updateListenerTask = nil
}

func listenForTransactions() -> Task<Void, Error> {
return Task.detached {
self.updateListenerTask = Task {
for await verificationResult in Transaction.updates {
switch verificationResult {
case .verified(let transaction):
Expand All @@ -126,25 +124,29 @@ extension InAppPurchasePlugin: InAppPurchase2API {
}
}
}
}

func stopListeningToTransactions() throws {
self.updateListenerTask = nil
}

func rawTransactions() async -> [Transaction] {
/// Helper function that fetches and unwraps all verified transactions
private func rawTransactions() async -> [Transaction] {
var transactions: [Transaction] = []

for await verificationResult in Transaction.all {
switch verificationResult {
case .verified(let transaction):
transactions.append(transaction)
case .unverified(_, _):
// Handle unverified transactions if necessary
break
}
}
return transactions
}

func fetchTransaction(by id: UInt64) async throws -> Transaction? {
/// Helper function to fetch specific transaction
private func fetchTransaction(by id: UInt64) async throws -> Transaction? {
for await result in Transaction.all {
switch result {
case .verified(let transaction):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

class TransactionCallbacks: InAppPurchase2CallbackAPI {
var callbackAPI: InAppPurchase2CallbackAPI
final class TransactionCallbacks: InAppPurchase2CallbackAPI {
let callbackAPI: InAppPurchase2CallbackAPI

init(binaryMessenger: FlutterBinaryMessenger) {
callbackAPI = InAppPurchase2CallbackAPI(binaryMessenger: binaryMessenger)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class InAppPurchaseStoreKitPlatform extends InAppPurchasePlatform {
InAppPurchaseStoreKitPlatform();

/// Experimental flag for StoreKit2.
static bool _useStoreKit2 = false;
static bool _useStoreKit2 = true;

static late SKPaymentQueueWrapper _skPaymentQueueWrapper;
static late _TransactionObserver _observer;
Expand Down