Skip to content
This repository was archived by the owner on Apr 26, 2026. It is now read-only.

fix(useIAP): forward PurchaseOptions in getAvailablePurchases and res…#3173

Merged
hyochan merged 2 commits into
mainfrom
fix/use-iap-forward-purchase-options
Mar 25, 2026
Merged

fix(useIAP): forward PurchaseOptions in getAvailablePurchases and res…#3173
hyochan merged 2 commits into
mainfrom
fix/use-iap-forward-purchase-options

Conversation

@hyochan

@hyochan hyochan commented Mar 25, 2026

Copy link
Copy Markdown
Owner

…torePurchases

The hook's getAvailablePurchases and restorePurchases methods were hardcoding PurchaseOptions (alsoPublishToEventListenerIOS, onlyIncludeActiveItemsIOS), making it impossible for hook consumers to customize these values.

This change adds an optional PurchaseOptions parameter to both methods, defaulting to the previous behavior for backward compatibility.

Related to hyochan/expo-iap#329

Summary by CodeRabbit

Release Notes

  • New Features
    • Added optional configuration options to purchase retrieval methods for greater control over which purchases are included in results.
    • New platform-specific settings available: iOS can filter active items and control event listener publishing; Android can include or exclude suspended purchases.

@hyochan hyochan added 🐛 bug Something isn't working ❄️ types Typing issues labels Mar 25, 2026
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request refactors the useIAP hook to provide greater flexibility for consumers when interacting with in-app purchase functionalities. By introducing an optional PurchaseOptions parameter to key methods, it enables developers to fine-tune purchase retrieval and restoration processes, addressing previous limitations where certain options were hardcoded. This change improves the adaptability of the hook while maintaining compatibility with existing implementations.

Highlights

  • Enhanced getAvailablePurchases method: The getAvailablePurchases method in the useIAP hook now accepts an optional PurchaseOptions parameter, allowing consumers to customize its behavior, such as alsoPublishToEventListenerIOS, onlyIncludeActiveItemsIOS, and includeSuspendedAndroid.
  • Enhanced restorePurchases method: The restorePurchases method in the useIAP hook also now accepts an optional PurchaseOptions parameter, which is then forwarded to the internal getAvailablePurchases call, providing consistent customization.
  • Backward Compatibility: Default values are provided for the new PurchaseOptions parameters, ensuring that existing calls to getAvailablePurchases and restorePurchases without these options continue to function as before.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@coderabbitai

coderabbitai Bot commented Mar 25, 2026

Copy link
Copy Markdown

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 0a9407d4-db00-4916-812e-756b149ee88a

📥 Commits

Reviewing files that changed from the base of the PR and between c08b5df and 4a39287.

📒 Files selected for processing (3)
  • src/__tests__/index.test.ts
  • src/hooks/useIAP.ts
  • src/index.ts

📝 Walkthrough

Walkthrough

The changes extend the useIAP hook's public API to accept a PurchaseOptions parameter object in getAvailablePurchases and restorePurchases methods, replacing the previous SKU list parameter. The underlying Android implementation is updated to compute and pass the includeSuspendedAndroid flag through to native IAP calls.

Changes

Cohort / File(s) Summary
useIAP Hook Signatures
src/hooks/useIAP.ts
Updated getAvailablePurchases and restorePurchases method signatures to accept optional PurchaseOptions instead of SKU list or void parameters. Added internal option mapping for alsoPublishToEventListenerIOS, onlyIncludeActiveItemsIOS, and includeSuspendedAndroid with appropriate defaults.
Android Native Call Parameters
src/index.ts
Modified getAvailablePurchases to compute includeSuspended flag from options?.includeSuspendedAndroid (defaulting to false) and include it in both inapp and subscription type native calls.
Test Expectations
src/__tests__/index.test.ts
Updated test expectations to verify that includeSuspended: false is passed in native IAP.instance.getAvailablePurchases calls for both inapp and subscription types.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related issues

Possibly related PRs

Suggested labels

🛠 bugfix, 🤖 android

Poem

🐰 Options bloom where parameters stood,
Android flags now flow as they should,
Suspended items dance through the light,
The hook grows wiser, refactored right! ✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly indicates the main change: forwarding PurchaseOptions to getAvailablePurchases and restorePurchases methods in the useIAP hook, which matches the core objectives of allowing consumers to customize purchase options.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/use-iap-forward-purchase-options

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@codecov

codecov Bot commented Mar 25, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 69.07%. Comparing base (1bbbbae) to head (4a39287).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #3173      +/-   ##
==========================================
+ Coverage   68.97%   69.07%   +0.10%     
==========================================
  Files           9        9              
  Lines        1792     1798       +6     
  Branches      585      589       +4     
==========================================
+ Hits         1236     1242       +6     
  Misses        551      551              
  Partials        5        5              
Flag Coverage Δ
library 69.07% <100.00%> (+0.10%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
src/hooks/useIAP.ts 71.11% <100.00%> (+0.65%) ⬆️
src/index.ts 70.34% <100.00%> (+0.06%) ⬆️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@gemini-code-assist gemini-code-assist Bot 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.

Code Review

This pull request refactors the getAvailablePurchases and restorePurchases methods within the useIAP hook to accept a PurchaseOptions object, allowing for more configurable behavior. The getAvailablePurchasesInternal function has been updated to utilize these options. However, an inconsistency was noted where the restorePurchasesTopLevel function, called by the hook's restorePurchases, does not yet accept PurchaseOptions, potentially leading to hardcoded options being used in its internal getAvailablePurchases call, while the hook's subsequent call uses the provided options. It is suggested to update restorePurchases in src/index.ts to also accept and forward PurchaseOptions for full consistency.

Comment thread src/hooks/useIAP.ts Outdated

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/hooks/useIAP.ts`:
- Around line 275-282: The Android Nitro calls inside getAvailablePurchases (and
the path used by restorePurchases via getAvailablePurchasesInternal) currently
hardcode android options and omit the includeSuspended flag; update the
construction of the Nitro Android options (where { android: { type: 'inapp' } }
/ { android: { type: 'subs' } } is created) to include includeSuspended:
options?.includeSuspendedAndroid ?? false (matching the
NitroAvailablePurchasesAndroidOptions field name), and ensure
getAvailablePurchasesInternal/restorePurchases forwards the same options object
so the Android includeSuspended flag is passed through to Nitro.
- Around line 67-68: getAvailablePurchases is accepting includeSuspendedAndroid
in PurchaseOptions but the Android path in the IAP calls doesn't forward it to
the Nitro layer; update the calls that call IAP.instance.getAvailablePurchases
(for both inapp and subs) to pass an android object with includeSuspended set
from options?.includeSuspendedAndroid ?? false (and keep android.type as 'inapp'
or 'subs') so the NitroAvailablePurchasesAndroidOptions.includeSuspended field
is populated.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 810e66e2-0807-4c45-a8a6-de1db2f03ca7

📥 Commits

Reviewing files that changed from the base of the PR and between 8caf60f and 2fa973a.

📒 Files selected for processing (1)
  • src/hooks/useIAP.ts

Comment thread src/hooks/useIAP.ts
Comment thread src/hooks/useIAP.ts
hyochan and others added 2 commits March 25, 2026 17:22
…torePurchases

The hook's getAvailablePurchases and restorePurchases methods were hardcoding
PurchaseOptions (alsoPublishToEventListenerIOS, onlyIncludeActiveItemsIOS),
making it impossible for hook consumers to customize these values.

This change adds an optional PurchaseOptions parameter to both methods,
defaulting to the previous behavior for backward compatibility.

Related to hyochan/expo-iap#329
- Replace restorePurchasesTopLevel with direct syncIOS call to eliminate
  redundant getAvailablePurchases network request
- Forward includeSuspendedAndroid to Android Nitro calls in getAvailablePurchases
- Update tests for new syncIOS mock and Android includeSuspended param

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@hyochan hyochan force-pushed the fix/use-iap-forward-purchase-options branch from c08b5df to 4a39287 Compare March 25, 2026 08:23
@hyochan hyochan merged commit de94e83 into main Mar 25, 2026
9 checks passed
@hyochan hyochan deleted the fix/use-iap-forward-purchase-options branch March 25, 2026 08:27
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

🐛 bug Something isn't working ❄️ types Typing issues

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant