react-native-iap 14.1.1-rc.1 â 14.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/NitroIap.podspec +2 -0
- package/README.md +9 -9
- package/android/build.gradle +2 -1
- package/android/consumer-rules.pro +7 -0
- package/app.plugin.js +1 -1
- package/ios/HybridRnIap.swift +380 -1192
- package/lib/module/helpers/subscription.js.map +1 -1
- package/lib/module/hooks/useIAP.js +74 -58
- package/lib/module/hooks/useIAP.js.map +1 -1
- package/lib/module/index.js +20 -3
- package/lib/module/index.js.map +1 -1
- package/lib/module/types.js +8 -0
- package/lib/module/types.js.map +1 -1
- package/lib/module/utils/error.js.map +1 -1
- package/lib/module/utils/errorMapping.js +33 -0
- package/lib/module/utils/errorMapping.js.map +1 -0
- package/lib/module/utils/type-bridge.js +19 -0
- package/lib/module/utils/type-bridge.js.map +1 -1
- package/lib/typescript/src/helpers/subscription.d.ts.map +1 -1
- package/lib/typescript/src/hooks/useIAP.d.ts +4 -4
- package/lib/typescript/src/hooks/useIAP.d.ts.map +1 -1
- package/lib/typescript/src/index.d.ts +7 -3
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/lib/typescript/src/types.d.ts +19 -0
- package/lib/typescript/src/types.d.ts.map +1 -1
- package/lib/typescript/src/utils/error.d.ts.map +1 -1
- package/lib/typescript/src/utils/errorMapping.d.ts +5 -0
- package/lib/typescript/src/utils/errorMapping.d.ts.map +1 -0
- package/lib/typescript/src/utils/type-bridge.d.ts +3 -2
- package/lib/typescript/src/utils/type-bridge.d.ts.map +1 -1
- package/package.json +5 -2
- package/plugin/tsconfig.tsbuildinfo +1 -1
- package/src/helpers/subscription.ts +30 -30
- package/src/hooks/useIAP.ts +252 -230
- package/src/index.ts +366 -340
- package/src/types.ts +21 -0
- package/src/utils/error.ts +19 -19
- package/src/utils/errorMapping.ts +44 -0
- package/src/utils/type-bridge.ts +127 -93
- package/ios/ErrorUtils.swift +0 -153
- package/ios/ProductStore.swift +0 -43
- package/ios/reactnativeiap.xcodeproj/project.xcworkspace/contents.xcworkspacedata +0 -7
- package/ios/reactnativeiap.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +0 -8
- package/plugin/build/src/withIAP.d.ts +0 -3
- package/plugin/build/src/withIAP.js +0 -81
- package/plugin/build/tsconfig.tsbuildinfo +0 -1
package/ios/ErrorUtils.swift
DELETED
|
@@ -1,153 +0,0 @@
|
|
|
1
|
-
import Foundation
|
|
2
|
-
import StoreKit
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Error utilities for iOS IAP operations
|
|
6
|
-
* Provides centralized error handling and JSON error formatting
|
|
7
|
-
* Matches the error codes from existing react-native-iap implementations
|
|
8
|
-
*/
|
|
9
|
-
struct IapErrorCode {
|
|
10
|
-
// Constants for code usage - safe pattern without force unwrapping
|
|
11
|
-
static let unknown = "E_UNKNOWN"
|
|
12
|
-
static let serviceError = "E_SERVICE_ERROR"
|
|
13
|
-
static let userCancelled = "E_USER_CANCELLED"
|
|
14
|
-
static let userError = "E_USER_ERROR"
|
|
15
|
-
static let itemUnavailable = "E_ITEM_UNAVAILABLE"
|
|
16
|
-
static let remoteError = "E_REMOTE_ERROR"
|
|
17
|
-
static let networkError = "E_NETWORK_ERROR"
|
|
18
|
-
static let receiptFailed = "E_RECEIPT_FAILED"
|
|
19
|
-
static let receiptFinishedFailed = "E_RECEIPT_FINISHED_FAILED"
|
|
20
|
-
static let notPrepared = "E_NOT_PREPARED"
|
|
21
|
-
static let notEnded = "E_NOT_ENDED"
|
|
22
|
-
static let alreadyOwned = "E_ALREADY_OWNED"
|
|
23
|
-
static let developerError = "E_DEVELOPER_ERROR"
|
|
24
|
-
static let purchaseError = "E_PURCHASE_ERROR"
|
|
25
|
-
static let syncError = "E_SYNC_ERROR"
|
|
26
|
-
static let deferredPayment = "E_DEFERRED_PAYMENT"
|
|
27
|
-
static let transactionValidationFailed = "E_TRANSACTION_VALIDATION_FAILED"
|
|
28
|
-
static let billingResponseJsonParseError = "E_BILLING_RESPONSE_JSON_PARSE_ERROR"
|
|
29
|
-
static let interrupted = "E_INTERRUPTED"
|
|
30
|
-
static let iapNotAvailable = "E_IAP_NOT_AVAILABLE"
|
|
31
|
-
static let activityUnavailable = "E_ACTIVITY_UNAVAILABLE"
|
|
32
|
-
static let alreadyPrepared = "E_ALREADY_PREPARED"
|
|
33
|
-
static let pending = "E_PENDING"
|
|
34
|
-
static let connectionClosed = "E_CONNECTION_CLOSED"
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* Error data structure for iOS IAP errors
|
|
39
|
-
*/
|
|
40
|
-
struct IapErrorData {
|
|
41
|
-
let code: String
|
|
42
|
-
let message: String
|
|
43
|
-
|
|
44
|
-
init(code: String, message: String) {
|
|
45
|
-
self.code = code
|
|
46
|
-
self.message = message
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
/**
|
|
51
|
-
* Helper class for iOS error handling
|
|
52
|
-
*/
|
|
53
|
-
@available(iOS 15.0, *)
|
|
54
|
-
class ErrorUtils {
|
|
55
|
-
|
|
56
|
-
/**
|
|
57
|
-
* Get error data from StoreKit error
|
|
58
|
-
*/
|
|
59
|
-
static func getStoreKitErrorData(_ error: Error) -> IapErrorData {
|
|
60
|
-
if let storeKitError = error as? StoreKitError {
|
|
61
|
-
return getStoreKitErrorData(storeKitError)
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
// Handle other error types
|
|
65
|
-
if error is CancellationError {
|
|
66
|
-
return IapErrorData(code: IapErrorCode.userCancelled, message: "Purchase was cancelled")
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
// Fallback for unknown errors
|
|
70
|
-
return IapErrorData(code: IapErrorCode.unknown, message: error.localizedDescription)
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
/**
|
|
74
|
-
* Get error data from specific StoreKitError
|
|
75
|
-
*/
|
|
76
|
-
static func getStoreKitErrorData(_ error: StoreKitError) -> IapErrorData {
|
|
77
|
-
switch error {
|
|
78
|
-
case .userCancelled:
|
|
79
|
-
return IapErrorData(code: IapErrorCode.userCancelled, message: "User cancelled the purchase")
|
|
80
|
-
case .networkError:
|
|
81
|
-
return IapErrorData(code: IapErrorCode.networkError, message: "Network error occurred during purchase")
|
|
82
|
-
case .systemError:
|
|
83
|
-
return IapErrorData(code: IapErrorCode.serviceError, message: "System error occurred")
|
|
84
|
-
case .notAvailableInStorefront:
|
|
85
|
-
return IapErrorData(code: IapErrorCode.itemUnavailable, message: "Product not available in current storefront")
|
|
86
|
-
case .notEntitled:
|
|
87
|
-
return IapErrorData(code: IapErrorCode.alreadyOwned, message: "User not entitled to this product")
|
|
88
|
-
default:
|
|
89
|
-
return IapErrorData(code: IapErrorCode.unknown, message: "Unknown StoreKit error: \\(error.localizedDescription)")
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
/**
|
|
94
|
-
* Create JSON error string from error data
|
|
95
|
-
*/
|
|
96
|
-
static func createErrorJson(
|
|
97
|
-
code: String,
|
|
98
|
-
message: String,
|
|
99
|
-
underlyingError: Error? = nil,
|
|
100
|
-
productId: String? = nil,
|
|
101
|
-
additionalData: [String: Any] = [:]
|
|
102
|
-
) -> String {
|
|
103
|
-
var errorMap: [String: Any] = [
|
|
104
|
-
"code": code,
|
|
105
|
-
"message": message
|
|
106
|
-
]
|
|
107
|
-
|
|
108
|
-
if let error = underlyingError {
|
|
109
|
-
errorMap["underlyingError"] = error.localizedDescription
|
|
110
|
-
|
|
111
|
-
// Add NSError specific information if available
|
|
112
|
-
if let nsError = error as NSError? {
|
|
113
|
-
errorMap["domain"] = nsError.domain
|
|
114
|
-
errorMap["errorCode"] = nsError.code
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
if let productId = productId {
|
|
119
|
-
errorMap["productId"] = productId
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
// Add any additional data
|
|
123
|
-
for (key, value) in additionalData {
|
|
124
|
-
errorMap[key] = value
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
// Convert to JSON
|
|
128
|
-
do {
|
|
129
|
-
let jsonData = try JSONSerialization.data(withJSONObject: errorMap, options: [])
|
|
130
|
-
if let jsonString = String(data: jsonData, encoding: .utf8) {
|
|
131
|
-
return jsonString
|
|
132
|
-
}
|
|
133
|
-
} catch {
|
|
134
|
-
print("[ErrorUtils] Failed to serialize error to JSON: \\(error)")
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
// Fallback to simple format
|
|
138
|
-
return "\\(code): \\(message)"
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
/**
|
|
142
|
-
* Create JSON error string from Swift Error
|
|
143
|
-
*/
|
|
144
|
-
static func createErrorJson(from error: Error, productId: String? = nil) -> String {
|
|
145
|
-
let errorData = getStoreKitErrorData(error)
|
|
146
|
-
return createErrorJson(
|
|
147
|
-
code: errorData.code,
|
|
148
|
-
message: errorData.message,
|
|
149
|
-
underlyingError: error,
|
|
150
|
-
productId: productId
|
|
151
|
-
)
|
|
152
|
-
}
|
|
153
|
-
}
|
package/ios/ProductStore.swift
DELETED
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import Foundation
|
|
2
|
-
import StoreKit
|
|
3
|
-
|
|
4
|
-
@available(iOS 15.0, *)
|
|
5
|
-
actor ProductStore {
|
|
6
|
-
private(set) var products: [String: Product] = [:]
|
|
7
|
-
|
|
8
|
-
func addProduct(_ product: Product) {
|
|
9
|
-
self.products[product.id] = product
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
func addProducts(_ products: [Product]) {
|
|
13
|
-
for product in products {
|
|
14
|
-
self.products[product.id] = product
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
func getAllProducts() -> [Product] {
|
|
19
|
-
return Array(self.products.values)
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
func getProduct(productID: String) -> Product? {
|
|
23
|
-
return self.products[productID]
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
func getAllSubscriptionProductIds() -> [String] {
|
|
27
|
-
return products.values.compactMap { product in
|
|
28
|
-
// Check if the product is a subscription
|
|
29
|
-
if product.subscription != nil {
|
|
30
|
-
return product.id
|
|
31
|
-
}
|
|
32
|
-
return nil
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
func removeAll() {
|
|
37
|
-
products.removeAll()
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
func performOnActor(_ action: @escaping (isolated ProductStore) -> Void) async {
|
|
41
|
-
action(self)
|
|
42
|
-
}
|
|
43
|
-
}
|
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const config_plugins_1 = require("expo/config-plugins");
|
|
4
|
-
const pkg = require('../../package.json');
|
|
5
|
-
// Global flag to prevent duplicate logs
|
|
6
|
-
let hasLoggedPluginExecution = false;
|
|
7
|
-
const addLineToGradle = (content, anchor, lineToAdd, offset = 1) => {
|
|
8
|
-
const lines = content.split('\n');
|
|
9
|
-
const index = lines.findIndex((line) => line.match(anchor));
|
|
10
|
-
if (index === -1) {
|
|
11
|
-
console.warn(`Anchor "${anchor}" not found in build.gradle. Appending to end.`);
|
|
12
|
-
lines.push(lineToAdd);
|
|
13
|
-
}
|
|
14
|
-
else {
|
|
15
|
-
lines.splice(index + offset, 0, lineToAdd);
|
|
16
|
-
}
|
|
17
|
-
return lines.join('\n');
|
|
18
|
-
};
|
|
19
|
-
const modifyAppBuildGradle = (gradle) => {
|
|
20
|
-
let modified = gradle;
|
|
21
|
-
// Add billing library dependencies to app-level build.gradle
|
|
22
|
-
const billingDep = ` implementation "com.android.billingclient:billing-ktx:8.0.0"`;
|
|
23
|
-
const gmsDep = ` implementation "com.google.android.gms:play-services-base:18.1.0"`;
|
|
24
|
-
let hasAddedDependency = false;
|
|
25
|
-
if (!modified.includes(billingDep)) {
|
|
26
|
-
modified = addLineToGradle(modified, /dependencies\s*{/, billingDep);
|
|
27
|
-
hasAddedDependency = true;
|
|
28
|
-
}
|
|
29
|
-
if (!modified.includes(gmsDep)) {
|
|
30
|
-
modified = addLineToGradle(modified, /dependencies\s*{/, gmsDep, 1);
|
|
31
|
-
hasAddedDependency = true;
|
|
32
|
-
}
|
|
33
|
-
// Log only once and only if we actually added dependencies
|
|
34
|
-
if (hasAddedDependency && !hasLoggedPluginExecution) {
|
|
35
|
-
console.log('đ ī¸ react-native-iap: Added billing dependencies to build.gradle');
|
|
36
|
-
}
|
|
37
|
-
return modified;
|
|
38
|
-
};
|
|
39
|
-
const withIapAndroid = (config) => {
|
|
40
|
-
// Add IAP dependencies to app build.gradle
|
|
41
|
-
config = (0, config_plugins_1.withAppBuildGradle)(config, (config) => {
|
|
42
|
-
config.modResults.contents = modifyAppBuildGradle(config.modResults.contents);
|
|
43
|
-
return config;
|
|
44
|
-
});
|
|
45
|
-
config = (0, config_plugins_1.withAndroidManifest)(config, (config) => {
|
|
46
|
-
const manifest = config.modResults;
|
|
47
|
-
if (!manifest.manifest['uses-permission']) {
|
|
48
|
-
manifest.manifest['uses-permission'] = [];
|
|
49
|
-
}
|
|
50
|
-
const permissions = manifest.manifest['uses-permission'];
|
|
51
|
-
const billingPerm = { $: { 'android:name': 'com.android.vending.BILLING' } };
|
|
52
|
-
const alreadyExists = permissions.some((p) => p.$['android:name'] === 'com.android.vending.BILLING');
|
|
53
|
-
if (!alreadyExists) {
|
|
54
|
-
permissions.push(billingPerm);
|
|
55
|
-
if (!hasLoggedPluginExecution) {
|
|
56
|
-
console.log('â
Added com.android.vending.BILLING to AndroidManifest.xml');
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
else {
|
|
60
|
-
if (!hasLoggedPluginExecution) {
|
|
61
|
-
console.log('âšī¸ com.android.vending.BILLING already exists in AndroidManifest.xml');
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
return config;
|
|
65
|
-
});
|
|
66
|
-
return config;
|
|
67
|
-
};
|
|
68
|
-
const withIAP = (config, _props) => {
|
|
69
|
-
try {
|
|
70
|
-
const result = withIapAndroid(config);
|
|
71
|
-
// Set flag after first execution to prevent duplicate logs
|
|
72
|
-
hasLoggedPluginExecution = true;
|
|
73
|
-
return result;
|
|
74
|
-
}
|
|
75
|
-
catch (error) {
|
|
76
|
-
config_plugins_1.WarningAggregator.addWarningAndroid('react-native-iap', `react-native-iap plugin encountered an error: ${error}`);
|
|
77
|
-
console.error('react-native-iap plugin error:', error);
|
|
78
|
-
return config;
|
|
79
|
-
}
|
|
80
|
-
};
|
|
81
|
-
exports.default = (0, config_plugins_1.createRunOncePlugin)(withIAP, pkg.name, pkg.version);
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"root":["../src/withiap.ts"],"version":"5.9.2"}
|