fix(ios): send one _makePurchase message per purchase attempt - #1020
Closed
vegaro wants to merge 1 commit into
Closed
fix(ios): send one _makePurchase message per purchase attempt#1020vegaro wants to merge 1 commit into
vegaro wants to merge 1 commit into
Conversation
purchaseProduct and purchasePackage sent the response twice when the purchase failed: once inside the error branch and once from the unconditional send that follows the if/else. Only the first delivery reached the caller, because _makePurchase clears MakePurchaseCallback before invoking it, so the second message was silently dropped. The win-back offer handlers already had the correct single-send shape; this makes all four consistent. Also replaces `response[@"userCancelled"] = false` with `@NO` in the three places that used it. `false` is 0, so it boxed to nil, and assigning nil through an NSMutableDictionary subscript removes the key instead of storing it — the success payload was shipping without userCancelled at all. Unity read the missing key as false, so the effect was invisible, but the payload did not match what PurchaseResult expects. Co-Authored-By: Claude <noreply@anthropic.com>
Generated by 🚫 Danger |
Member
Author
|
closing in favor of #1042 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What changed
purchaseProductandpurchasePackagesent the response to_makePurchasetwice on failure — once inside the error branch, and again from the unconditional send after theif/else:Only the first delivery reaches the caller today, because
_makePurchaseclearsMakePurchaseCallbackbefore invoking it, so the duplicate is dropped by the null guard. The extraUnitySendMessageis still wasted work on the wrong contract. The two win-back offer handlers already had the correct single-send shape; this makes all four consistent.Also in this PR
response[@"userCancelled"] = falseappeared in three places.falseis0, so it boxes tonil, and assigningnilthrough anNSMutableDictionarysubscript removes the key rather than storing it — the success payload shipped with nouserCancelledfield at all. Unity reads the missing key asfalsevia SimpleJSON, so the behaviour was correct by accident. Replaced with@NOso the payload matches whatPurchaseResultexpects.purchasePackagealready used@NO, which is what made the inconsistency visible.Overlaps with #1008
#1008 rewrites these same lines for request-ID correlation and carries the double send unchanged. It will conflict with this PR, and the duplicate matters more there: once callbacks are consumed by request ID, the second message arrives as an unrecognised request rather than being dropped by a null check.
Verification
archive-ios,archive-ios-cocoapods,build-integration-tests-iosandbuild-subtester-iosall pass on CI, so the plugin builds and links.No test in this repo exercises
PurchasesUnityHelper.mat runtime, and Edit Mode tests do not compile the iOS plugin, so the single-send behaviour on a failed purchase is unverified. Worth a manual check in Subtester (cancel a purchase, confirm one_makePurchaselog line) before this leaves draft.🤖 Generated with Claude Code