Skip to content

PurchasesOrchestrator: fix behavior dealing with nil SKPaymentTransaction.productIdentifier during purchase#1680

Merged
NachoSoto merged 3 commits into
mainfrom
sk1-purchase-no-product-id
Jun 21, 2022
Merged

PurchasesOrchestrator: fix behavior dealing with nil SKPaymentTransaction.productIdentifier during purchase#1680
NachoSoto merged 3 commits into
mainfrom
sk1-purchase-no-product-id

Conversation

@NachoSoto

@NachoSoto NachoSoto commented Jun 9, 2022

Copy link
Copy Markdown
Contributor

Fixes CSDK-119.

PurchasesOrchestrator uses product identifiers for callback keys.
Previously, extractProductIdentifier was allowing SKPayment.productIdentifier to be nil, as long as the product had an identifier.

However, as seen in the newly added test, this resulted in a purchase call that never invoked its callback, because when the transaction would come back, it wouldn't know which callback to use.

Because of this, there is no point starting the purchase if we can't retrieve the product identifier from the transaction, so now we fail early with an error instead of hanging forever.

@NachoSoto NachoSoto added the WIP label Jun 9, 2022

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This currently fails.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Creating the error already logs it, so this was duplicated. The new code relies on the String without hardcoding another error message.

Base automatically changed from sk2-purchase-post-receipt to main June 9, 2022 21:06
@NachoSoto NachoSoto force-pushed the sk1-purchase-no-product-id branch 4 times, most recently from ff15467 to dd4d84b Compare June 16, 2022 17:18
@NachoSoto NachoSoto changed the title [WIP] Fix behavior dealing with nil SKPaymentTransaction.productIdentifier during purchase PurchasesOrchestrator: fix behavior dealing with nil SKPaymentTransaction.productIdentifier during purchase Jun 16, 2022
@NachoSoto NachoSoto requested a review from a team June 16, 2022 17:18
@NachoSoto NachoSoto marked this pull request as ready for review June 16, 2022 17:18
@NachoSoto NachoSoto removed the WIP label Jun 16, 2022

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

⚠️ We didn't have any test coverage for this scenario, so we didn't know that the method in StoreKitWorkarounds actually made the whole purchase hang.

@NachoSoto NachoSoto added the bug label Jun 16, 2022
@NachoSoto

Copy link
Copy Markdown
Contributor Author

This is ready for review.

@taquitos taquitos left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Slight wording suggestion, but 👍

Comment thread Sources/Purchasing/StoreKitAbstractions/StoreKitWorkarounds.swift Outdated
@aboedo aboedo self-requested a review June 17, 2022 16:48

@aboedo aboedo left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I left a question, lmk if I'm reading it wrong

@NachoSoto

Copy link
Copy Markdown
Contributor Author

What's the question? 🤓

@aboedo

aboedo commented Jun 20, 2022

Copy link
Copy Markdown
Member

LOL not sure if it didn't get posted or I'm going nuts, but I'll re-post the question, just a second

Comment on lines 304 to 306

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

why are we ignoring the product identifier from the SKProduct now?
The order should be:
try getting the product id from the product, then from the payment, and then if we still have nothing, raise an error

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

That's explained in the PR description 😇

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Basically that was nice, the problem is when the transaction comes back, we only have that, and if the identifier there is nil we never called the callback. So the test I wrote (for example) hung forever.

So because we didn't have test coverage for that workaround we didn't realize that it was enough to begin the purchase, but then we can't complete it.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I read the description but my brain didn't process it 🤦‍♂️ my apologies.
That makes total sense. I keep thinking that there has to be something that we can do to improve this case, but ultimately I feel like the solution will be to start moving people to SK2 as it matures.
In the meantime, I do think we should have an extensive comment here, since it won't be immediately obvious to folks maintaining this

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

but ultimately I feel like the solution will be to start moving people to SK2 as it matures.

Agreed.

In the meantime, I do think we should have an extensive comment here, since it won't be immediately obvious to folks maintaining this

Good call, adding.

@aboedo

aboedo commented Jun 20, 2022

Copy link
Copy Markdown
Member

Comment on lines 304 to 306

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I read the description but my brain didn't process it 🤦‍♂️ my apologies.
That makes total sense. I keep thinking that there has to be something that we can do to improve this case, but ultimately I feel like the solution will be to start moving people to SK2 as it matures.
In the meantime, I do think we should have an extensive comment here, since it won't be immediately obvious to folks maintaining this

…ansaction.productIdentifier` during purchase

Fixes [CSDK-119].

`PurchasesOrchestrator` uses product identifiers for callback keys.
Previously, `extractProductIdentifier` was allowing `SKPayment.productIdentifier` to be `nil`, as long as the product had an identifier.

However, as seen in the newly added test, this resulted in a purchase call that never invoked its callback, because when the transaction would come back, it wouldn't know which callback to use.

Because of this, there is no point starting the purchase if we can't retrieve the product identifier from the transaction, so now we fail early with an error instead of hanging forever.
@NachoSoto NachoSoto force-pushed the sk1-purchase-no-product-id branch from a82b8a1 to 4b5b3bf Compare June 21, 2022 17:19
@NachoSoto NachoSoto merged commit bdf09e9 into main Jun 21, 2022
@NachoSoto NachoSoto deleted the sk1-purchase-no-product-id branch June 21, 2022 17:28
@NachoSoto NachoSoto mentioned this pull request Jun 30, 2022
NachoSoto added a commit that referenced this pull request Jul 4, 2022
### Changes:
* Replaced `CustomerInfo.nonSubscriptionTransactions` with a new non-`StoreTransaction` type (#1733) via NachoSoto (@NachoSoto)
* `Purchases.configure`: added overload taking a `Configuration.Builder` (#1720) via NachoSoto (@NachoSoto)
* Extract Attribution logic out of Purchases (#1693) via Joshua Liebowitz (@taquitos)
* Remove create alias (#1695) via Joshua Liebowitz (@taquitos)

All attribution APIs can now be accessed from `Purchases.shared.attribution`.

### Improvements:
* Improved purchasing logs, added promotional offer information (#1725) via NachoSoto (@NachoSoto)
* `PurchasesOrchestrator`: don't log attribute errors if there are none (#1742) via NachoSoto (@NachoSoto)
* `FatalErrorUtil`: don't override `fatalError` on release builds (#1736) via NachoSoto (@NachoSoto)
* `SKPaymentTransaction`: added more context to warnings about missing properties (#1731) via NachoSoto (@NachoSoto)
* New SwiftUI Purchase Tester example (#1722) via Josh Holtz (@joshdholtz)
* update docs for `showManageSubscriptions` (#1729) via aboedo (@aboedo)
* `PurchasesOrchestrator`: unify finish transactions between SK1 and SK2 (#1704) via NachoSoto (@NachoSoto)
* `SubscriberAttribute`: converted into `struct` (#1648) via NachoSoto (@NachoSoto)
* `CacheFetchPolicy.notStaleCachedOrFetched`: added warning to docstring (#1708) via NachoSoto (@NachoSoto)
* Clear cached offerings and products after Storefront changes (2/4) (#1583) via Juanpe Catalán (@Juanpe)
* `ROT13`: optimized initialization and removed magic numbers (#1702) via NachoSoto (@NachoSoto)

### Fixes:
* `logIn`/`logOut`: sync attributes before aliasing (#1716) via NachoSoto (@NachoSoto)
* `Purchases.customerInfo(fetchPolicy:)`: actually use `fetchPolicy` parameter (#1721) via NachoSoto (@NachoSoto)
* `PurchasesOrchestrator`: fix behavior dealing with `nil` `SKPaymentTransaction.productIdentifier` during purchase (#1680) via NachoSoto (@NachoSoto)
* `PurchasesOrchestrator.handlePurchasedTransaction`: always refresh receipt data (#1703) via NachoSoto (@NachoSoto)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants