Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.

[in_app_purchase] payment queue dart ios#1249

Merged
cyanglaz merged 66 commits intoflutter:masterfrom
cyanglaz:iap_payment_queue_dart_ios
Feb 28, 2019
Merged

[in_app_purchase] payment queue dart ios#1249
cyanglaz merged 66 commits intoflutter:masterfrom
cyanglaz:iap_payment_queue_dart_ios

Conversation

@cyanglaz
Copy link
Contributor

@cyanglaz cyanglaz commented Feb 21, 2019

Dart side for add payment in StoreKit.

Fixed some bug in the Objective-C code.

Removed add payment with only product identifier in Objective-C since it seems unnecessary.

Part of flutter/flutter#26328

@cyanglaz cyanglaz force-pushed the iap_payment_queue_dart_ios branch from de3a84b to ffaf35c Compare February 22, 2019 22:34
Copy link
Contributor

@mklim mklim left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the delay! Basically looks solid, some questions.

updatedTransactions:(NSArray<SKPaymentTransaction *> *)transactions {
for (SKPaymentTransaction *transaction in transactions) {
[self.transactionsSetter setObject:transaction forKey:transaction.transactionIdentifier];
if (transaction.transactionIdentifier) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would this ever be null? Should we handle it like an error if/when it is?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apple handles the transaction identifier strangely, the identifier is null when the state the purchasing. I should probably put a comment on it.

stringWithFormat:@"The transaction with transactionIdentifer:%@ does not "
@"exsit. Note that if the transactionState is "
@"purchasing, the transactionIdentifier will be "
@"nil(null). And you should not finish this transaction",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And you should not finish this transaction

Can you go into more detail about this?

Copy link
Contributor Author

@cyanglaz cyanglaz Feb 28, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, by apple's document finish transaction with transactionIdentifier of purchasing will throw exception; I will put something similar here.https://developer.apple.com/documentation/storekit/skpaymentqueue/1506003-finishtransaction?language=objc

/// payment follow.
/// You must set the observer right when App launches to avoid missing callback when your user
/// started a purchase flow from the App Store.
void setTransactionObserver(SKTransactionObserverWrapper observer) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any way we could take this as a param at construction time instead? It would force users to set this as soon as this object is instantiated.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since the payment queue is a singleton, there is no actually a construction time. User can technically call SKPaymentQueue() everywhere to refer the defaultPaymentQueue. So I didn't want user to have to put the observer each time when they refer to the singleton.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right. Hmm. I think it may be worth converting this from a singleton into a constructed class just to enforce that this is configured ASAP. What do you think? Could be done in a followup PR too.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's do more offline discussion on this and will create another PR if we reach a different approach.

/// the transaction that is generated by the payment.
/// The [productIdentifier] must match one of the product that is returned in [SKRequestMaker.startProductRequest].
/// to test the payment in the [sandbox](https://developer.apple.com/apple-pay/sandbox-testing/).
Future<void> addPayment(SKPaymentWrapper payment) async {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should link to the official dev docs on the related methods for all of these too.

);
}

/// Finishes a transaction, remove it from the queue.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// Finishes a transaction, remove it from the queue.
/// Finishes a transaction and removes it from the queue.

///
/// This method should be called from a observer callback when receiving notification from the payment queue. You should only
/// call this method after the transaction is successfully processed and the functionality purchased by the user is unlocked.
/// Itt will throw a Platform exception if the [SKPaymentTransactionWrapper.transactionState] is [SKPaymentTransactionStateWrapper.purchasing].
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// Itt will throw a Platform exception if the [SKPaymentTransactionWrapper.transactionState] is [SKPaymentTransactionStateWrapper.purchasing].
/// It will throw a Platform exception if the [SKPaymentTransactionWrapper.transactionState] is [SKPaymentTransactionStateWrapper.purchasing].

// Triage a method channel call from the platform and triggers the correct observer method.
Future<dynamic> _handleObserverCallbacks(MethodCall call) {
assert(_observer != null,
'in_app_purchase]: (Fatal)The observer has not been set but we received a purchase transaction notification. Please ensure the observer has been set using `setTransactionObserver`. Make sure the observer is added right at the App Launch.');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
'in_app_purchase]: (Fatal)The observer has not been set but we received a purchase transaction notification. Please ensure the observer has been set using `setTransactionObserver`. Make sure the observer is added right at the App Launch.');
'[in_app_purchase]: (Fatal)The observer has not been set but we received a purchase transaction notification. Please ensure the observer has been set using `setTransactionObserver`. Make sure the observer is added right at the App Launch.');


/// This class is Dart wrapper around [SKTransactionObserver](https://developer.apple.com/documentation/storekit/skpaymenttransactionobserver?language=objc).
///
/// Must be subclassed and
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: doc missing.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OMG lol! Sorry.

@googlebot
Copy link

We found a Contributor License Agreement for you (the sender of this pull request), but were unable to find agreements for all the commit author(s) or Co-authors. If you authored these, maybe you used a different email address in the git commits than was used to sign the CLA (login here to double check)? If these were authored by someone else, then they will need to sign a CLA as well, and confirm that they're okay with these being contributed to Google.
In order to pass this check, please resolve this problem and have the pull request author add another comment and the bot will run again. If the bot doesn't comment, it means it doesn't think anything has changed.

ℹ️ Googlers: Go here for more info.

@googlebot
Copy link

We found a Contributor License Agreement for you (the sender of this pull request), but were unable to find agreements for all the commit author(s) or Co-authors. If you authored these, maybe you used a different email address in the git commits than was used to sign the CLA (login here to double check)? If these were authored by someone else, then they will need to sign a CLA as well, and confirm that they're okay with these being contributed to Google.
In order to pass this check, please resolve this problem and have the pull request author add another comment and the bot will run again. If the bot doesn't comment, it means it doesn't think anything has changed.

ℹ️ Googlers: Go here for more info.

@cyanglaz cyanglaz force-pushed the iap_payment_queue_dart_ios branch from b615650 to 237bf2c Compare February 28, 2019 05:26
@googlebot
Copy link

CLAs look good, thanks!

ℹ️ Googlers: Go here for more info.

Copy link
Contributor

@mklim mklim left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@"The transaction with transactionIdentifer:%@ does not "
@"exsit. Note that if the transactionState is "
@"purchasing, the transactionIdentifier will be "
@"nil(null). And you should not finish this transaction. "
Copy link
Contributor

@mklim mklim Feb 28, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Sorry, on second thought and after getting the full info I think everything after the sentence about transactionIdentifier being null isn't needed here. It's helpful to know but it's not necessarily relevant, and we don't want to clog up the error logs with extraneous info.

/// payment follow.
/// You must set the observer right when App launches to avoid missing callback when your user
/// started a purchase flow from the App Store.
void setTransactionObserver(SKTransactionObserverWrapper observer) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right. Hmm. I think it may be worth converting this from a singleton into a constructed class just to enforce that this is configured ASAP. What do you think? Could be done in a followup PR too.

@cyanglaz cyanglaz merged commit a533148 into flutter:master Feb 28, 2019
@cyanglaz cyanglaz deleted the iap_payment_queue_dart_ios branch February 28, 2019 23:28
romaluca pushed a commit to romaluca/plugins that referenced this pull request Mar 6, 2019
Dart side for add payment in StoreKit.
Fixed some bug in the Objective-C code.
Removed add payment with only product identifier in Objective-C since it seems unnecessary.
Part of flutter/flutter#26328
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants