[in_app_purchase] payment queue dart ios#1249
Conversation
de3a84b to
ffaf35c
Compare
mklim
left a comment
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
Would this ever be null? Should we handle it like an error if/when it is?
There was a problem hiding this comment.
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", |
There was a problem hiding this comment.
And you should not finish this transaction
Can you go into more detail about this?
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
We should link to the official dev docs on the related methods for all of these too.
packages/in_app_purchase/lib/src/store_kit_wrappers/sk_payment_queue_wrapper.dart
Outdated
Show resolved
Hide resolved
| ); | ||
| } | ||
|
|
||
| /// Finishes a transaction, remove it from the queue. |
There was a problem hiding this comment.
| /// 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]. |
There was a problem hiding this comment.
| /// 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.'); |
There was a problem hiding this comment.
| '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.'); |
packages/in_app_purchase/lib/src/store_kit_wrappers/sk_payment_queue_wrapper.dart
Show resolved
Hide resolved
|
|
||
| /// This class is Dart wrapper around [SKTransactionObserver](https://developer.apple.com/documentation/storekit/skpaymenttransactionobserver?language=objc). | ||
| /// | ||
| /// Must be subclassed and |
|
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. ℹ️ Googlers: Go here for more info. |
|
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. ℹ️ Googlers: Go here for more info. |
b615650 to
237bf2c
Compare
|
CLAs look good, thanks! ℹ️ Googlers: Go here for more info. |
| @"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. " |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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.
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
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