Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
34 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
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
more docs and clean up
  • Loading branch information
LouiseHsu committed Sep 5, 2024
commit a6cbd985baf76f807e426b92984486bb3f496323
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ extension InAppPurchasePlugin: InAppPurchase2API {
func finish(id: Int64, completion: @escaping (Result<Void, any Error>) -> Void) {
Task {
print("native finish")
let transaction = try await fetchTransaction(by: UInt64(id));
let transaction = try await fetchTransaction(by: UInt64(id))
if let transaction = transaction {
await transaction.finish()
}
Expand Down Expand Up @@ -151,16 +151,16 @@ extension InAppPurchasePlugin: InAppPurchase2API {
}

func fetchTransaction(by id: UInt64) async throws -> Transaction? {
for await result in Transaction.all {
switch result {
case .verified(let transaction):
if transaction.id == id {
return transaction
}
case .unverified(_, _):
continue
}
for await result in Transaction.all {
switch result {
case .verified(let transaction):
if transaction.id == id {
return transaction
}
case .unverified(_, _):
continue
}
return nil
}
return nil
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ final class InAppPurchase2PluginTests: XCTestCase {
}

func testSuccessfulPurchase() async throws {
plugin.purchase(id: <#T##String#>, options: nil, completion: <#T##(Result<SK2ProductPurchaseResultMessage, any Error>) -> Void#>)
plugin.purchase(
id: <#T##String#>, options: nil,
completion: <#T##(Result<SK2ProductPurchaseResultMessage, any Error>) -> Void#>)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class InAppPurchaseStoreKitPlatform extends InAppPurchasePlatform {

@override
Stream<List<PurchaseDetails>> get purchaseStream => _useStoreKit2
? _sk2transactionObserver.purchaseUpdatedController.stream
? _sk2transactionObserver.transactionsCreatedController.stream
: _observer.purchaseUpdatedController.stream;

/// Callback handler for transaction status changes.
Expand All @@ -66,8 +66,8 @@ class InAppPurchaseStoreKitPlatform extends InAppPurchasePlatform {
onListen: () => SK2Transaction.startListeningToTransactions(),
onCancel: () => SK2Transaction.stopListeningToTransactions(),
);
_sk2transactionObserver =
SK2TransactionObserver(purchaseUpdatedController: updateController2);
_sk2transactionObserver = SK2TransactionObserver(
transactionsCreatedController: updateController2);
InAppPurchase2CallbackAPI.setUp(_sk2transactionObserver);
} else {
// Create a purchaseUpdatedController and notify the native side when to
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
// found in the LICENSE file.

import 'package:flutter/services.dart';
import 'package:in_app_purchase_platform_interface/in_app_purchase_platform_interface.dart';
import '../../store_kit_2_wrappers.dart';

InAppPurchase2API _hostApi = InAppPurchase2API();
Expand Down Expand Up @@ -270,19 +269,30 @@ extension on SK2PriceLocaleMessage {
enum SK2ProductPurchaseResult {
/// The purchase succeeded and results in a transaction.
success,

/// The user canceled the purchase.
userCancelled,

/// The purchase is pending, and requires action from the customer.
pending
}

/// Wrapper around [PurchaseOption]
/// https://developer.apple.com/documentation/storekit/product/purchaseoption
class SK2ProductPurchaseOptions {
/// Creates a new instance of [SK2ProductPurchaseOptions]
SK2ProductPurchaseOptions({this.appAccountToken, this.quantity});

/// Sets a UUID to associate the purchase with an account in your system.
final String? appAccountToken;

/// Indicates the quantity of items the customer is purchasing.
final int? quantity;

/// Convert to pigeon representation [SK2ProductPurchaseOptionsMessage]
SK2ProductPurchaseOptionsMessage convertToPigeon() {
return SK2ProductPurchaseOptionsMessage();
return SK2ProductPurchaseOptionsMessage(
appAccountToken: appAccountToken, quantity: quantity);
}
}

Expand All @@ -297,17 +307,6 @@ extension on SK2ProductPurchaseResultMessage {
return SK2ProductPurchaseResult.pending;
}
}

PurchaseStatus convertToPurchaseStatus() {
switch (this) {
case SK2ProductPurchaseResultMessage.success:
return PurchaseStatus.purchased;
case SK2ProductPurchaseResultMessage.userCancelled:
return PurchaseStatus.canceled;
case SK2ProductPurchaseResultMessage.pending:
return PurchaseStatus.pending;
}
}
}

/// A wrapper around StoreKit2's [Product](https://developer.apple.com/documentation/storekit/product).
Expand Down Expand Up @@ -370,6 +369,9 @@ class SK2Product {
.toList();
}

/// Wrapper for StoreKit's [Product.purchase]
/// https://developer.apple.com/documentation/storekit/product/3791971-purchase
/// Initiates a purchase for the product with the App Store and displays the confirmation sheet.
static Future<SK2ProductPurchaseResult> purchase(String id,
{SK2ProductPurchaseOptions? options}) async {
SK2ProductPurchaseResultMessage result;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,23 +106,26 @@ extension on SK2TransactionMessage {
verificationData: PurchaseVerificationData(
localVerificationData: '', serverVerificationData: '', source: ''),
transactionDate: '',
// Note that with sk2, any transactions that *can* be returned will require to be finished, and are already purchased.
// So set this
// as purchased for all transactions initially.
// Note that with sk2, any transactions that *can* be returned will
// require to be finished, and are already purchased.
// So set this as purchased for all transactions initially.
status: restoring ? PurchaseStatus.restored : PurchaseStatus.purchased,
purchaseID: id.toString(),
);
}
}

/// An observer that listens to all transactions used
/// An observer that listens to all transactions created
class SK2TransactionObserver implements InAppPurchase2CallbackAPI {
SK2TransactionObserver({required this.purchaseUpdatedController});
/// Creates a new instance of [SK2TransactionObserver]
SK2TransactionObserver({required this.transactionsCreatedController});

final StreamController<List<PurchaseDetails>> purchaseUpdatedController;
/// The transactions stream to listen to
final StreamController<List<PurchaseDetails>> transactionsCreatedController;

@override
void onTransactionsUpdated(SK2TransactionMessage newTransaction) {
purchaseUpdatedController.add([newTransaction.convertToDetails()]);
transactionsCreatedController
.add(<PurchaseDetails>[newTransaction.convertToDetails()]);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ class AppStorePurchaseDetails extends PurchaseDetails {
bool get pendingCompletePurchase => _pendingCompletePurchase;
}

/// The class represents the information of a purchase made with the Apple
/// AppStore, when using Storekit2
class SK2PurchaseDetails extends PurchaseDetails {
SK2PurchaseDetails(
{required super.productID,
Expand All @@ -87,6 +89,5 @@ class SK2PurchaseDetails extends PurchaseDetails {
required super.status});

@override
// but not restored
bool get pendingCompletePurchase => status == PurchaseStatus.purchased;
}