Skip to content

Change user cancelled behavior in custom entitlement computation mode#2447

Closed
tonidero wants to merge 1 commit into
custom-entitlement-disabled-apifrom
change-user-cancelled-behavior-in-custom-entitlements-mode
Closed

Change user cancelled behavior in custom entitlement computation mode#2447
tonidero wants to merge 1 commit into
custom-entitlement-disabled-apifrom
change-user-cancelled-behavior-in-custom-entitlements-mode

Conversation

@tonidero

Copy link
Copy Markdown
Contributor

Description

Change user cancelled behavior in custom entitlement mode. Now for

@NachoSoto

Copy link
Copy Markdown
Contributor

Awesome 👍🏻 I'll add tests for this.

@NachoSoto

Copy link
Copy Markdown
Contributor

TODO: add an assertion to ensure there's no customer info request in this case.

error: error
))
let publicError = ErrorUtils.purchasesError(withUntypedError: error).asPublicError
let userCancelled = publicError.code == ErrorCode.purchaseCancelledError.rawValue

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.

Oh I see why you needed this now. We need to compare the error domain too though, I'll fix that.

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.

I'm changing it to this:

Suggested change
let userCancelled = publicError.code == ErrorCode.purchaseCancelledError.rawValue
let userCancelled = publicError.isCancelledError

// This detects if `Product.PurchaseResult.userCancelled` is true.
let (userCancelled, sk2Transaction) = try await self.storeKit2TransactionListener
.handle(purchaseResult: result)
if self.systemInfo.dangerousSettings.customEntitlementComputation {

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.

I think this was missing also checking userCancelled.

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.

Ah yes you're completely right. Didn't have time to test this 👍

} catch StoreKitError.userCancelled {
if self.systemInfo.dangerousSettings.customEntitlementComputation {
throw ErrorUtils.purchaseCancelledError()
}

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.

I'm not sure if this error would be catched by the following catches... Still had to test each of these cases to make sure it behaved as I expected

// This detects if `Product.PurchaseResult.userCancelled` is true.
let (userCancelled, sk2Transaction) = try await self.storeKit2TransactionListener
.handle(purchaseResult: result)
if self.systemInfo.dangerousSettings.customEntitlementComputation {

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.

Ah yes you're completely right. Didn't have time to test this 👍

@tonidero tonidero changed the title Change user cancelled behavior in custom entitlement mode Change user cancelled behavior in custom entitlement computation mode Apr 26, 2023
NachoSoto added a commit that referenced this pull request Apr 26, 2023
…PurchasesOrchestrator` for cancelled purchases

Fixes SDK-3088
Supersedes #2447

Note that it's currently impossible to test this for SK2, so we only have SK1 tests (we have a Radar for that).

The next step will be to deprecate the current API to remove the `userCancelled` property and make this the new behavior.
See also #1910 for an explanation of the different return values of the purchase APIs.
@NachoSoto

Copy link
Copy Markdown
Contributor

Closing in favor of #2449

@NachoSoto NachoSoto closed this Apr 26, 2023
@NachoSoto NachoSoto deleted the change-user-cancelled-behavior-in-custom-entitlements-mode branch April 26, 2023 16:11
NachoSoto added a commit that referenced this pull request Apr 26, 2023
…cancelled purchases (#2449)

Fixes SDK-3088
Supersedes #2447

Thanks to @tonidero for doing most of this.

Note that it's currently impossible to test this for SK2, so we only
have SK1 tests (we have a Radar for that).

The next step will be to deprecate the current API to remove the
`userCancelled` property and make this the new behavior.
See also #1910 for an explanation of the different return values of the
purchase APIs.
NachoSoto added a commit that referenced this pull request Apr 26, 2023
…cancelled purchases (#2449)

Fixes SDK-3088
Supersedes #2447

Thanks to @tonidero for doing most of this.

Note that it's currently impossible to test this for SK2, so we only
have SK1 tests (we have a Radar for that).

The next step will be to deprecate the current API to remove the
`userCancelled` property and make this the new behavior.
See also #1910 for an explanation of the different return values of the
purchase APIs.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants