-
Notifications
You must be signed in to change notification settings - Fork 9.7k
[in_app_purchase] make payment objc #1231
Conversation
SKPayment *payment = [self.paymentsCache objectForKey:productID]; | ||
// User can use payment object with mutable = true and add simulatesAskToBuyInSandBox = true to | ||
// test the payment flow. | ||
if (!payment || [paymentMap[@"mutable"] boolValue] == YES) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This ends up creating a mutable payment whenever payment isn't specified, not just when mutable
is explicitly specified as an option. Is that something we want to do?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The mutable keyword is indeed confusing. I created this for user to test the payment in sandbox, I have updated the mutable keyword to usePaymentObject
in a different branch. Do you think changing the keyboard to usePaymentObject
makes more sense here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I think that makes sense.
I'm still a little confused over the code silently creating an SkMutable
payment object whenever it can't find a pre-existing payment in the map. Do we want to default to that or would it make sense to error if we can't find an existing payment instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh you are right. Going to update. I am also going to re arrange the code a bit to make it more readable.
SKMutablePayment *mutablePayment = [[SKMutablePayment alloc] init]; | ||
mutablePayment.productIdentifier = productID; | ||
NSNumber *quantity = [paymentMap objectForKey:@"quantity"]; | ||
if (quantity) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we panic and bail here if we don't have a quantity?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should update the quantity to default to 1 here, ill update.
for (SKPaymentTransaction *transcation in transactions) { | ||
[maps addObject:[FIAObjectTranslator getMapFromSKPaymentTransaction:transcation]]; | ||
} | ||
[self.callbackChannel invokeMethod:@"updatedTransaction" arguments:maps]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: I think it would be a little clearer to name these methods "Transactions" here and below, since there's multiple transactions in each method.
|
||
- (void)handleTransactionsRemoved:(NSArray<SKPaymentTransaction *> *)transactions { | ||
NSMutableArray *maps = [NSMutableArray new]; | ||
for (SKPaymentTransaction *transcation in transactions) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: s/transcation/transaction/g
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 can find more info about SignCLA and this PR by following this 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. Googlers can find more info about SignCLA and this PR by following this link. |
71e0a40
to
253f67a
Compare
543862d
to
253f67a
Compare
c8b670c
to
7f9e5a9
Compare
CLAs look good, thanks! Googlers can find more info about SignCLA and this PR by following this link. |
Mistakenly sent out a bunch of review requests due to the file owners setting. Please ignore the requests. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
// the product to process the payment. | ||
SKProduct *product = [self.productsCache objectForKey:productID]; | ||
if (product) { | ||
payment = [SKPayment paymentWithProduct:product]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can users set quantity this way?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is not supported with the regular purchase flow, user will need to use the custom payment object.
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 can find more info about SignCLA and this PR by following this link. |
ceb3960
to
f3cdb83
Compare
CLAs look good, thanks! Googlers can find more info about SignCLA and this PR by following this link. |
The objective-c portion of add payment flow.
Since there is no dart code in this PR, it could be hard to trace what is going on. Included 2 purchase flows below to better explain.
A regular flow of a user to process a purchase will be as such:
-[InAppPurchasePlugin startProductRequest:result:]
-[InAppPurchasePlugin addPayment:result:]
using the payment object gotten from step 2.updatedTransaction
in dart waiting for the transaction to be at state of 'purchased'-[InAppPurchasePlugin finishTransaction:result:]
with the transaction gotten from step 4.A app store purchase flow will be as such:
shouldAddStorePayment
in dart.shouldAddStorePayment
return true, the payment object will be automatically added to the queue using-[InAppPurchasePlugin addPayment:result:]
(called by our plugin code, not the programmer)flutter/flutter#26328