Skip to content
This repository was archived by the owner on Oct 16, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"cSpell.words": [
"hyodotdev",
"inapp",
"netrc",
"openiap",
"skus",
Expand Down
81 changes: 81 additions & 0 deletions CLAUDE.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,58 @@
# Claude Development Guidelines for OpenIAP

## Function Naming Conventions

### Platform-Specific Functions

- **iOS-specific functions MUST have `IOS` suffix**
- **Android-specific functions MUST have `Android` suffix**
- **Cross-platform functions have NO suffix**

#### Examples

##### ✅ Correct
```swift
// iOS-specific functions
func presentCodeRedemptionSheetIOS()
func showManageSubscriptionsIOS()
func deepLinkToSubscriptionsIOS()
func getPromotedProductIOS()
func requestPurchaseOnPromotedProductIOS()
func syncIOS()
func getReceiptDataIOS()

// Cross-platform functions
func initConnection()
func fetchProducts()
func requestPurchase()
func finishTransaction()
```

##### ❌ Incorrect
```swift
// Missing IOS suffix for iOS-specific
func presentCodeRedemptionSheet() // Should be presentCodeRedemptionSheetIOS()
func showManageSubscriptions() // Should be showManageSubscriptionsIOS()

// Unnecessary suffix for cross-platform
func requestPurchaseIOS() // Should be requestPurchase() if cross-platform
```

### API Naming Alignment

- **MUST match openiap.dev API naming**
- **Use exact same function names as React Native OpenIAP**

#### Standard API Names
- `initConnection()` - Initialize IAP connection
- `endConnection()` - End IAP connection
- `fetchProducts()` - Fetch products from store
- `getProducts()` - Get cached products
- `getAvailablePurchases()` - Get available/restored purchases
- `requestPurchase()` - Request a purchase
- `finishTransaction()` - Finish a transaction
- `restorePurchases()` - Restore previous purchases

## Swift Naming Conventions for Acronyms

### General Rule
Expand Down Expand Up @@ -41,6 +94,34 @@
- Build with: `swift build`
- Use real product IDs: `dev.hyo.martie.10bulbs`, `dev.hyo.martie.30bulbs`

## File Organization

### Directory Structure

- **Sources/Models/**: OpenIAP official types that match [openiap.dev/docs/types](https://www.openiap.dev/docs/types)
- `Product.swift` - OpenIapProduct and related types
- `Purchase.swift` - OpenIapPurchase and related types
- `ActiveSubscription.swift` - ActiveSubscription type
- `PurchaseError.swift` - PurchaseError type
- `Receipt.swift` - Receipt validation types
- etc.

- **Sources/Helpers/**: Internal helper classes (NOT in OpenIAP official types)
- `ProductManager.swift` - Thread-safe product caching
- `IapStatus.swift` - UI status management for SwiftUI

- **Sources/**: Main module files
- `OpenIapModule.swift` - Core implementation
- `OpenIapStore.swift` - SwiftUI-friendly store
- `OpenIapProtocol.swift` - API interface definitions
- `OpenIapError.swift` - Error definitions

### Naming Rules

- **Models**: Must match OpenIAP specification exactly
- **Helpers**: Use descriptive names ending with purpose (Manager, Cache, Status, etc.)
- **Avoid confusing names**: Don't use "Store" for caching classes (use Cache, Manager instead)

## Development Notes

- Purchase Flow should display real-time purchase events
Expand Down
9 changes: 8 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,13 @@ swift test
- **Acronyms as suffix**: Use all caps (`ProductIAP`, `ManagerIOS`)
- See [CLAUDE.md](CLAUDE.md) for detailed naming rules

#### OpenIap Prefix (Public Models)

- Prefix all public model types with `OpenIap`.
- Examples: `OpenIapProduct`, `OpenIapPurchase`, `OpenIapProductRequest`, `OpenIapRequestPurchaseProps`, `OpenIapPurchaseOptions`, `OpenIapReceiptValidationProps`, `OpenIapReceiptValidationResult`, `OpenIapActiveSubscription`, `OpenIapPurchaseState`, `OpenIapPurchaseOffer`, `OpenIapProductType`, `OpenIapProductTypeIOS`.
- Private/internal helper types do not need the prefix.
- When renaming existing types, add a public `typealias` from the old name to the new name to preserve source compatibility, then migrate usages incrementally.

## Testing

All new features must include tests:
Expand Down Expand Up @@ -111,4 +118,4 @@ Feel free to:

## License

By contributing, you agree that your contributions will be licensed under the MIT License.
By contributing, you agree that your contributions will be licensed under the MIT License.
82 changes: 73 additions & 9 deletions Example/Martie.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,23 @@
C0E1F5FC2C8F1AB000123456 /* SubscriptionFlowScreen.swift in Sources */ = {isa = PBXBuildFile; fileRef = C0E1F5FB2C8F1AB000123456 /* SubscriptionFlowScreen.swift */; };
C0E1F5FE2C8F1AB500123456 /* AvailablePurchasesScreen.swift in Sources */ = {isa = PBXBuildFile; fileRef = C0E1F5FD2C8F1AB500123456 /* AvailablePurchasesScreen.swift */; };
C0E1F6002C8F1ABA00123456 /* OfferCodeScreen.swift in Sources */ = {isa = PBXBuildFile; fileRef = C0E1F5FF2C8F1ABA00123456 /* OfferCodeScreen.swift */; };
C0E1F6022C8F1AC000123456 /* StoreViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = C0E1F6012C8F1AC000123456 /* StoreViewModel.swift */; };
C0E1F6042C8F1AC500123456 /* AppColors.swift in Sources */ = {isa = PBXBuildFile; fileRef = C0E1F6032C8F1AC500123456 /* AppColors.swift */; };
C0E1F6072C8F1AD000123456 /* OpenIAP in Frameworks */ = {isa = PBXBuildFile; productRef = C0E1F6062C8F1AD000123456 /* OpenIAP */; };
C0UI00012D00000000000001 /* FeatureCard.swift in Sources */ = {isa = PBXBuildFile; fileRef = C0UI10012D00000000000001 /* FeatureCard.swift */; };
C0UI00022D00000000000002 /* LoadingCard.swift in Sources */ = {isa = PBXBuildFile; fileRef = C0UI10022D00000000000002 /* LoadingCard.swift */; };
C0UI00032D00000000000003 /* EmptyStateCard.swift in Sources */ = {isa = PBXBuildFile; fileRef = C0UI10032D00000000000003 /* EmptyStateCard.swift */; };
C0UI00042D00000000000004 /* SectionHeaderView.swift in Sources */ = {isa = PBXBuildFile; fileRef = C0UI10042D00000000000004 /* SectionHeaderView.swift */; };
C0UI00052D00000000000005 /* ProductListCard.swift in Sources */ = {isa = PBXBuildFile; fileRef = C0UI10052D00000000000005 /* ProductListCard.swift */; };
C0UI00062D00000000000006 /* ProductGridCard.swift in Sources */ = {isa = PBXBuildFile; fileRef = C0UI10062D00000000000006 /* ProductGridCard.swift */; };
C0UI00072D00000000000007 /* ActivePurchaseCard.swift in Sources */ = {isa = PBXBuildFile; fileRef = C0UI10072D00000000000007 /* ActivePurchaseCard.swift */; };
C0UI00082D00000000000008 /* InstructionRow.swift in Sources */ = {isa = PBXBuildFile; fileRef = C0UI10082D00000000000008 /* InstructionRow.swift */; };
C0UI00092D00000000000009 /* ProductCard.swift in Sources */ = {isa = PBXBuildFile; fileRef = C0UI10092D00000000000009 /* ProductCard.swift */; };
C0UI000A2D0000000000000A /* SubscriptionCard.swift in Sources */ = {isa = PBXBuildFile; fileRef = C0UI100A2D0000000000000A /* SubscriptionCard.swift */; };
C0UI000B2D0000000000000B /* PurchaseHistoryCard.swift in Sources */ = {isa = PBXBuildFile; fileRef = C0UI100B2D0000000000000B /* PurchaseHistoryCard.swift */; };
C0UI000C2D0000000000000C /* InstructionCard.swift in Sources */ = {isa = PBXBuildFile; fileRef = C0UI100C2D0000000000000C /* InstructionCard.swift */; };
C0UI000D2D0000000000000D /* TestingNotesCard.swift in Sources */ = {isa = PBXBuildFile; fileRef = C0UI100D2D0000000000000D /* TestingNotesCard.swift */; };
C0UI000E2D0000000000000E /* TestingNote.swift in Sources */ = {isa = PBXBuildFile; fileRef = C0UI100E2D0000000000000E /* TestingNote.swift */; };
C0UI000F2D0000000000000F /* PurchaseCard.swift in Sources */ = {isa = PBXBuildFile; fileRef = C0UI100F2D0000000000000F /* PurchaseCard.swift */; };
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
Expand All @@ -32,8 +46,22 @@
C0E1F5FB2C8F1AB000123456 /* SubscriptionFlowScreen.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SubscriptionFlowScreen.swift; sourceTree = "<group>"; };
C0E1F5FD2C8F1AB500123456 /* AvailablePurchasesScreen.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AvailablePurchasesScreen.swift; sourceTree = "<group>"; };
C0E1F5FF2C8F1ABA00123456 /* OfferCodeScreen.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OfferCodeScreen.swift; sourceTree = "<group>"; };
C0E1F6012C8F1AC000123456 /* StoreViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StoreViewModel.swift; sourceTree = "<group>"; };
C0E1F6032C8F1AC500123456 /* AppColors.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppColors.swift; sourceTree = "<group>"; };
C0UI10012D00000000000001 /* FeatureCard.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FeatureCard.swift; sourceTree = "<group>"; };
C0UI10022D00000000000002 /* LoadingCard.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LoadingCard.swift; sourceTree = "<group>"; };
C0UI10032D00000000000003 /* EmptyStateCard.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EmptyStateCard.swift; sourceTree = "<group>"; };
C0UI10042D00000000000004 /* SectionHeaderView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SectionHeaderView.swift; sourceTree = "<group>"; };
C0UI10052D00000000000005 /* ProductListCard.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProductListCard.swift; sourceTree = "<group>"; };
C0UI10062D00000000000006 /* ProductGridCard.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProductGridCard.swift; sourceTree = "<group>"; };
C0UI10072D00000000000007 /* ActivePurchaseCard.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ActivePurchaseCard.swift; sourceTree = "<group>"; };
C0UI10082D00000000000008 /* InstructionRow.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InstructionRow.swift; sourceTree = "<group>"; };
C0UI10092D00000000000009 /* ProductCard.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProductCard.swift; sourceTree = "<group>"; };
C0UI100A2D0000000000000A /* SubscriptionCard.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SubscriptionCard.swift; sourceTree = "<group>"; };
C0UI100B2D0000000000000B /* PurchaseHistoryCard.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PurchaseHistoryCard.swift; sourceTree = "<group>"; };
C0UI100C2D0000000000000C /* InstructionCard.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InstructionCard.swift; sourceTree = "<group>"; };
C0UI100D2D0000000000000D /* TestingNotesCard.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TestingNotesCard.swift; sourceTree = "<group>"; };
C0UI100E2D0000000000000E /* TestingNote.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TestingNote.swift; sourceTree = "<group>"; };
C0UI100F2D0000000000000F /* PurchaseCard.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PurchaseCard.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -67,9 +95,9 @@
C0E1F5E72C8F1A9400123456 /* OpenIapExample */ = {
isa = PBXGroup;
children = (
C0E1F6082C8F1AD500123456 /* Screens */,
C0E1F6092C8F1ADB00123456 /* ViewModels */,
C0E1F60A2C8F1AE000123456 /* Models */,
C0E1F6082C8F1AD500123456 /* Screens */,
C0E1F5E82C8F1A9400123456 /* OpenIapExampleApp.swift */,
C0E1F5EA2C8F1A9400123456 /* ContentView.swift */,
C0E1F5EC2C8F1A9500123456 /* Assets.xcassets */,
Expand All @@ -89,6 +117,7 @@
C0E1F6082C8F1AD500123456 /* Screens */ = {
isa = PBXGroup;
children = (
C0UI20012D00000000000001 /* uis */,
C0E1F5F72C8F1AA300123456 /* HomeScreen.swift */,
C0E1F5F92C8F1AAB00123456 /* PurchaseFlowScreen.swift */,
C0E1F5FB2C8F1AB000123456 /* SubscriptionFlowScreen.swift */,
Expand All @@ -101,7 +130,6 @@
C0E1F6092C8F1ADB00123456 /* ViewModels */ = {
isa = PBXGroup;
children = (
C0E1F6012C8F1AC000123456 /* StoreViewModel.swift */,
);
path = ViewModels;
sourceTree = "<group>";
Expand All @@ -114,6 +142,28 @@
path = Models;
sourceTree = "<group>";
};
C0UI20012D00000000000001 /* uis */ = {
isa = PBXGroup;
children = (
C0UI10012D00000000000001 /* FeatureCard.swift */,
C0UI10022D00000000000002 /* LoadingCard.swift */,
C0UI10032D00000000000003 /* EmptyStateCard.swift */,
C0UI10042D00000000000004 /* SectionHeaderView.swift */,
C0UI10052D00000000000005 /* ProductListCard.swift */,
C0UI10062D00000000000006 /* ProductGridCard.swift */,
C0UI10072D00000000000007 /* ActivePurchaseCard.swift */,
C0UI10082D00000000000008 /* InstructionRow.swift */,
C0UI10092D00000000000009 /* ProductCard.swift */,
C0UI100A2D0000000000000A /* SubscriptionCard.swift */,
C0UI100B2D0000000000000B /* PurchaseHistoryCard.swift */,
C0UI100C2D0000000000000C /* InstructionCard.swift */,
C0UI100D2D0000000000000D /* TestingNotesCard.swift */,
C0UI100E2D0000000000000E /* TestingNote.swift */,
C0UI100F2D0000000000000F /* PurchaseCard.swift */,
);
path = uis;
sourceTree = "<group>";
};
/* End PBXGroup section */

/* Begin PBXNativeTarget section */
Expand Down Expand Up @@ -152,7 +202,7 @@
};
};
};
buildConfigurationList = C0E1F5E02C8F1A9400123456 /* Build configuration list for PBXProject "OpenIapExample" */;
buildConfigurationList = C0E1F5E02C8F1A9400123456 /* Build configuration list for PBXProject "Martie" */;
compatibilityVersion = "Xcode 14.0";
developmentRegion = en;
hasScannedForEncodings = 0;
Expand Down Expand Up @@ -196,9 +246,23 @@
C0E1F5FC2C8F1AB000123456 /* SubscriptionFlowScreen.swift in Sources */,
C0E1F5FE2C8F1AB500123456 /* AvailablePurchasesScreen.swift in Sources */,
C0E1F6002C8F1ABA00123456 /* OfferCodeScreen.swift in Sources */,
C0E1F6022C8F1AC000123456 /* StoreViewModel.swift in Sources */,
C0E1F6042C8F1AC500123456 /* AppColors.swift in Sources */,
C0E1F5E92C8F1A9400123456 /* OpenIapExampleApp.swift in Sources */,
C0UI00012D00000000000001 /* FeatureCard.swift in Sources */,
C0UI00022D00000000000002 /* LoadingCard.swift in Sources */,
C0UI00032D00000000000003 /* EmptyStateCard.swift in Sources */,
C0UI00042D00000000000004 /* SectionHeaderView.swift in Sources */,
C0UI00052D00000000000005 /* ProductListCard.swift in Sources */,
C0UI00062D00000000000006 /* ProductGridCard.swift in Sources */,
C0UI00072D00000000000007 /* ActivePurchaseCard.swift in Sources */,
C0UI00082D00000000000008 /* InstructionRow.swift in Sources */,
C0UI00092D00000000000009 /* ProductCard.swift in Sources */,
C0UI000A2D0000000000000A /* SubscriptionCard.swift in Sources */,
C0UI000B2D0000000000000B /* PurchaseHistoryCard.swift in Sources */,
C0UI000C2D0000000000000C /* InstructionCard.swift in Sources */,
C0UI000D2D0000000000000D /* TestingNotesCard.swift in Sources */,
C0UI000E2D0000000000000E /* TestingNote.swift in Sources */,
C0UI000F2D0000000000000F /* PurchaseCard.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -335,7 +399,7 @@
DEVELOPMENT_TEAM = PRDQGB267K;
ENABLE_PREVIEWS = YES;
GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_KEY_CFBundleDisplayName = "OpenIAP Example";
INFOPLIST_KEY_CFBundleDisplayName = OpenIAP;
INFOPLIST_KEY_UIApplicationSceneManifest_Generation = YES;
INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES;
INFOPLIST_KEY_UILaunchScreen_Generation = YES;
Expand Down Expand Up @@ -366,7 +430,7 @@
DEVELOPMENT_TEAM = PRDQGB267K;
ENABLE_PREVIEWS = YES;
GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_KEY_CFBundleDisplayName = "OpenIAP Example";
INFOPLIST_KEY_CFBundleDisplayName = OpenIAP;
INFOPLIST_KEY_UIApplicationSceneManifest_Generation = YES;
INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES;
INFOPLIST_KEY_UILaunchScreen_Generation = YES;
Expand All @@ -389,7 +453,7 @@
/* End XCBuildConfiguration section */

/* Begin XCConfigurationList section */
C0E1F5E02C8F1A9400123456 /* Build configuration list for PBXProject "OpenIapExample" */ = {
C0E1F5E02C8F1A9400123456 /* Build configuration list for PBXProject "Martie" */ = {
isa = XCConfigurationList;
buildConfigurations = (
C0E1F5F12C8F1A9500123456 /* Debug */,
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"images" : [
{
"filename" : "AppIcon.png",
"idiom" : "universal",
"platform" : "ios",
"size" : "1024x1024"
Expand Down
6 changes: 5 additions & 1 deletion Example/OpenIapExample/OpenIapExampleApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,13 @@ import OpenIAP
@main
@available(iOS 15.0, *)
struct OpenIapExampleApp: App {
init() {
// Enable verbose logging for the example app only
OpenIapLog.setEnabled(true)
}
var body: some Scene {
WindowGroup {
ContentView()
}
}
}
}
Loading