expo-iap 3.2.0 → 3.3.0-rc.1
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/android/src/main/java/expo/modules/iap/ExpoIapModule.kt +124 -0
- package/build/modules/android.d.ts +53 -1
- package/build/modules/android.d.ts.map +1 -1
- package/build/modules/android.js +61 -0
- package/build/modules/android.js.map +1 -1
- package/build/types.d.ts +227 -15
- package/build/types.d.ts.map +1 -1
- package/build/types.js.map +1 -1
- package/coverage/clover.xml +57 -51
- package/coverage/coverage-final.json +5 -5
- package/coverage/lcov-report/block-navigation.js +1 -1
- package/coverage/lcov-report/index.html +14 -14
- package/coverage/lcov-report/sorter.js +7 -21
- package/coverage/lcov-report/src/ExpoIap.types.ts.html +1396 -0
- package/coverage/lcov-report/src/helpers/index.html +116 -0
- package/coverage/lcov-report/src/helpers/subscription.ts.html +499 -0
- package/coverage/lcov-report/src/index.html +1 -1
- package/coverage/lcov-report/src/index.ts.html +1 -1
- package/coverage/lcov-report/src/modules/android.ts.html +233 -8
- package/coverage/lcov-report/src/modules/index.html +15 -15
- package/coverage/lcov-report/src/modules/ios.ts.html +1 -1
- package/coverage/lcov-report/src/onside/ExpoOnsideMarketplaceAvailabilityModule.ts.html +145 -0
- package/coverage/lcov-report/src/onside/index.html +131 -0
- package/coverage/lcov-report/src/onside/index.ts.html +253 -0
- package/coverage/lcov-report/src/types/ExpoIapAndroid.types.ts.html +502 -0
- package/coverage/lcov-report/src/types/index.html +116 -0
- package/coverage/lcov-report/src/useIAP.ts.html +1654 -0
- package/coverage/lcov-report/src/utils/constants.ts.html +127 -0
- package/coverage/lcov-report/src/utils/debug.ts.html +1 -1
- package/coverage/lcov-report/src/utils/errorMapping.ts.html +1 -1
- package/coverage/lcov-report/src/utils/index.html +1 -1
- package/coverage/lcov.info +86 -74
- package/ios/expoiap.xcodeproj/project.xcworkspace/contents.xcworkspacedata +7 -0
- package/ios/expoiap.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +8 -0
- package/openiap-versions.json +2 -2
- package/package.json +1 -1
- package/plugin/tsconfig.tsbuildinfo +1 -1
- package/src/modules/android.ts +75 -0
- package/src/types.ts +243 -15
|
@@ -22,6 +22,7 @@ import dev.hyo.openiap.RequestSubscriptionPropsByPlatforms
|
|
|
22
22
|
import dev.hyo.openiap.VerifyPurchaseAndroidOptions
|
|
23
23
|
import dev.hyo.openiap.VerifyPurchaseProps
|
|
24
24
|
import dev.hyo.openiap.VerifyPurchaseWithProviderProps
|
|
25
|
+
import dev.hyo.openiap.store.OpenIapStore
|
|
25
26
|
import expo.modules.kotlin.Promise
|
|
26
27
|
import expo.modules.kotlin.exception.Exceptions
|
|
27
28
|
import expo.modules.kotlin.modules.Module
|
|
@@ -34,6 +35,10 @@ import kotlinx.coroutines.sync.Mutex
|
|
|
34
35
|
import kotlinx.coroutines.sync.withLock
|
|
35
36
|
import java.util.concurrent.ConcurrentLinkedQueue
|
|
36
37
|
import java.util.concurrent.atomic.AtomicBoolean
|
|
38
|
+
import dev.hyo.openiap.BillingProgramAndroid as OpenIapBillingProgram
|
|
39
|
+
import dev.hyo.openiap.ExternalLinkLaunchModeAndroid as OpenIapExternalLinkLaunchMode
|
|
40
|
+
import dev.hyo.openiap.ExternalLinkTypeAndroid as OpenIapExternalLinkType
|
|
41
|
+
import dev.hyo.openiap.LaunchExternalLinkParamsAndroid as OpenIapLaunchExternalLinkParams
|
|
37
42
|
|
|
38
43
|
class ExpoIapModule : Module() {
|
|
39
44
|
companion object {
|
|
@@ -52,6 +57,7 @@ class ExpoIapModule : Module() {
|
|
|
52
57
|
get() = appContext.activityProvider?.currentActivity ?: throw Exceptions.MissingActivity()
|
|
53
58
|
|
|
54
59
|
private val openIap: OpenIapModule by lazy { OpenIapModule(context) }
|
|
60
|
+
private val openIapStore: OpenIapStore by lazy { OpenIapStore(context) }
|
|
55
61
|
private var listenersAttached = false
|
|
56
62
|
private val pendingEvents = ConcurrentLinkedQueue<Pair<String, Map<String, Any?>>>()
|
|
57
63
|
private val connectionReady = AtomicBoolean(false)
|
|
@@ -519,9 +525,127 @@ class ExpoIapModule : Module() {
|
|
|
519
525
|
}
|
|
520
526
|
}
|
|
521
527
|
|
|
528
|
+
// -------------------------------------------------------------------------
|
|
529
|
+
// Billing Programs API (Android 8.2.0+)
|
|
530
|
+
// -------------------------------------------------------------------------
|
|
531
|
+
|
|
532
|
+
AsyncFunction("isBillingProgramAvailableAndroid") { program: String, promise: Promise ->
|
|
533
|
+
ExpoIapLog.payload("isBillingProgramAvailableAndroid", mapOf("program" to program))
|
|
534
|
+
scope.launch {
|
|
535
|
+
try {
|
|
536
|
+
val openIapProgram = mapBillingProgram(program)
|
|
537
|
+
// Note: enableBillingProgram should be called before initConnection
|
|
538
|
+
// for proper BillingClient configuration. Here it's called as a fallback
|
|
539
|
+
// but may have no effect if BillingClient is already initialized.
|
|
540
|
+
val result = openIapStore.isBillingProgramAvailable(openIapProgram)
|
|
541
|
+
val response =
|
|
542
|
+
mapOf(
|
|
543
|
+
"billingProgram" to program,
|
|
544
|
+
"isAvailable" to result.isAvailable,
|
|
545
|
+
)
|
|
546
|
+
ExpoIapLog.result("isBillingProgramAvailableAndroid", response)
|
|
547
|
+
promise.resolve(response)
|
|
548
|
+
} catch (e: Exception) {
|
|
549
|
+
ExpoIapLog.failure("isBillingProgramAvailableAndroid", e)
|
|
550
|
+
promise.reject(OpenIapError.ServiceUnavailable.CODE, e.message, e)
|
|
551
|
+
}
|
|
552
|
+
}
|
|
553
|
+
}
|
|
554
|
+
|
|
555
|
+
AsyncFunction("createBillingProgramReportingDetailsAndroid") { program: String, promise: Promise ->
|
|
556
|
+
ExpoIapLog.payload("createBillingProgramReportingDetailsAndroid", mapOf("program" to program))
|
|
557
|
+
scope.launch {
|
|
558
|
+
try {
|
|
559
|
+
val openIapProgram = mapBillingProgram(program)
|
|
560
|
+
val result = openIapStore.createBillingProgramReportingDetails(openIapProgram)
|
|
561
|
+
val response =
|
|
562
|
+
mapOf(
|
|
563
|
+
"billingProgram" to program,
|
|
564
|
+
"externalTransactionToken" to result.externalTransactionToken,
|
|
565
|
+
)
|
|
566
|
+
ExpoIapLog.result("createBillingProgramReportingDetailsAndroid", response)
|
|
567
|
+
promise.resolve(response)
|
|
568
|
+
} catch (e: Exception) {
|
|
569
|
+
ExpoIapLog.failure("createBillingProgramReportingDetailsAndroid", e)
|
|
570
|
+
promise.reject(OpenIapError.ServiceUnavailable.CODE, e.message, e)
|
|
571
|
+
}
|
|
572
|
+
}
|
|
573
|
+
}
|
|
574
|
+
|
|
575
|
+
AsyncFunction("launchExternalLinkAndroid") { params: Map<String, Any?>, promise: Promise ->
|
|
576
|
+
ExpoIapLog.payload("launchExternalLinkAndroid", params)
|
|
577
|
+
scope.launch {
|
|
578
|
+
try {
|
|
579
|
+
val activity =
|
|
580
|
+
runCatching { currentActivity }
|
|
581
|
+
.onFailure {
|
|
582
|
+
Log.e(TAG, "launchExternalLinkAndroid: Activity missing", it)
|
|
583
|
+
}.getOrNull() ?: run {
|
|
584
|
+
promise.reject(OpenIapError.ServiceUnavailable.CODE, "Activity not available", null)
|
|
585
|
+
return@launch
|
|
586
|
+
}
|
|
587
|
+
|
|
588
|
+
val billingProgram = params["billingProgram"] as? String
|
|
589
|
+
val launchMode = params["launchMode"] as? String ?: "unspecified"
|
|
590
|
+
val linkType = params["linkType"] as? String ?: "unspecified"
|
|
591
|
+
val linkUri = params["linkUri"] as? String
|
|
592
|
+
|
|
593
|
+
if (billingProgram.isNullOrBlank()) {
|
|
594
|
+
promise.reject(OpenIapError.DeveloperError.CODE, "`billingProgram` is a required parameter.", null)
|
|
595
|
+
return@launch
|
|
596
|
+
}
|
|
597
|
+
|
|
598
|
+
if (linkUri.isNullOrBlank()) {
|
|
599
|
+
promise.reject(OpenIapError.DeveloperError.CODE, "`linkUri` is a required and non-empty parameter.", null)
|
|
600
|
+
return@launch
|
|
601
|
+
}
|
|
602
|
+
|
|
603
|
+
val openIapParams =
|
|
604
|
+
OpenIapLaunchExternalLinkParams(
|
|
605
|
+
billingProgram = mapBillingProgram(billingProgram),
|
|
606
|
+
launchMode = mapExternalLinkLaunchMode(launchMode),
|
|
607
|
+
linkType = mapExternalLinkType(linkType),
|
|
608
|
+
linkUri = linkUri,
|
|
609
|
+
)
|
|
610
|
+
|
|
611
|
+
val result = openIapStore.launchExternalLink(activity, openIapParams)
|
|
612
|
+
ExpoIapLog.result("launchExternalLinkAndroid", result)
|
|
613
|
+
promise.resolve(result)
|
|
614
|
+
} catch (e: Exception) {
|
|
615
|
+
ExpoIapLog.failure("launchExternalLinkAndroid", e)
|
|
616
|
+
promise.reject(OpenIapError.ServiceUnavailable.CODE, e.message, e)
|
|
617
|
+
}
|
|
618
|
+
}
|
|
619
|
+
}
|
|
620
|
+
|
|
522
621
|
OnDestroy {
|
|
523
622
|
ExpoIapHelper.cleanupListeners(openIap)
|
|
524
623
|
job.cancel()
|
|
525
624
|
}
|
|
526
625
|
}
|
|
626
|
+
|
|
627
|
+
// -------------------------------------------------------------------------
|
|
628
|
+
// Billing Programs API Helper Functions
|
|
629
|
+
// -------------------------------------------------------------------------
|
|
630
|
+
|
|
631
|
+
private fun mapBillingProgram(program: String): OpenIapBillingProgram =
|
|
632
|
+
when (program) {
|
|
633
|
+
"external-offer" -> OpenIapBillingProgram.ExternalOffer
|
|
634
|
+
"external-content-link" -> OpenIapBillingProgram.ExternalContentLink
|
|
635
|
+
else -> OpenIapBillingProgram.Unspecified
|
|
636
|
+
}
|
|
637
|
+
|
|
638
|
+
private fun mapExternalLinkLaunchMode(mode: String): OpenIapExternalLinkLaunchMode =
|
|
639
|
+
when (mode) {
|
|
640
|
+
"launch-in-external-browser-or-app" -> OpenIapExternalLinkLaunchMode.LaunchInExternalBrowserOrApp
|
|
641
|
+
"caller-will-launch-link" -> OpenIapExternalLinkLaunchMode.CallerWillLaunchLink
|
|
642
|
+
else -> OpenIapExternalLinkLaunchMode.Unspecified
|
|
643
|
+
}
|
|
644
|
+
|
|
645
|
+
private fun mapExternalLinkType(type: String): OpenIapExternalLinkType =
|
|
646
|
+
when (type) {
|
|
647
|
+
"link-to-digital-content-offer" -> OpenIapExternalLinkType.LinkToDigitalContentOffer
|
|
648
|
+
"link-to-app-download" -> OpenIapExternalLinkType.LinkToAppDownload
|
|
649
|
+
else -> OpenIapExternalLinkType.Unspecified
|
|
650
|
+
}
|
|
527
651
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { DeepLinkOptions, MutationField, VerifyPurchaseResultAndroid } from '../types';
|
|
1
|
+
import type { BillingProgramAndroid, BillingProgramAvailabilityResultAndroid, BillingProgramReportingDetailsAndroid, DeepLinkOptions, LaunchExternalLinkParamsAndroid, MutationField, VerifyPurchaseResultAndroid } from '../types';
|
|
2
2
|
export declare function isProductAndroid<T extends {
|
|
3
3
|
platform?: string;
|
|
4
4
|
}>(item: unknown): item is T & {
|
|
@@ -124,4 +124,56 @@ export declare const showAlternativeBillingDialogAndroid: MutationField<'showAlt
|
|
|
124
124
|
* ```
|
|
125
125
|
*/
|
|
126
126
|
export declare const createAlternativeBillingTokenAndroid: MutationField<'createAlternativeBillingTokenAndroid'>;
|
|
127
|
+
/**
|
|
128
|
+
* Check if a specific billing program is available for this user/device (Android only).
|
|
129
|
+
* Available in Google Play Billing Library 8.2.0+.
|
|
130
|
+
*
|
|
131
|
+
* @param program - The billing program to check ('external-offer' or 'external-content-link')
|
|
132
|
+
* @returns Promise resolving to availability result
|
|
133
|
+
*
|
|
134
|
+
* @example
|
|
135
|
+
* ```typescript
|
|
136
|
+
* const result = await isBillingProgramAvailableAndroid('external-offer');
|
|
137
|
+
* if (result.isAvailable) {
|
|
138
|
+
* // Proceed with billing program flow
|
|
139
|
+
* }
|
|
140
|
+
* ```
|
|
141
|
+
*/
|
|
142
|
+
export declare const isBillingProgramAvailableAndroid: (program: BillingProgramAndroid) => Promise<BillingProgramAvailabilityResultAndroid>;
|
|
143
|
+
/**
|
|
144
|
+
* Launch an external link for the specified billing program (Android only).
|
|
145
|
+
* Available in Google Play Billing Library 8.2.0+.
|
|
146
|
+
*
|
|
147
|
+
* @param params - The external link parameters
|
|
148
|
+
* @returns Promise resolving when the link is launched
|
|
149
|
+
*
|
|
150
|
+
* @example
|
|
151
|
+
* ```typescript
|
|
152
|
+
* await launchExternalLinkAndroid({
|
|
153
|
+
* billingProgram: 'external-offer',
|
|
154
|
+
* launchMode: 'launch-in-external-browser-or-app',
|
|
155
|
+
* linkType: 'link-to-digital-content-offer',
|
|
156
|
+
* linkUri: 'https://your-payment-site.com',
|
|
157
|
+
* });
|
|
158
|
+
* ```
|
|
159
|
+
*/
|
|
160
|
+
export declare const launchExternalLinkAndroid: (params: LaunchExternalLinkParamsAndroid) => Promise<void>;
|
|
161
|
+
/**
|
|
162
|
+
* Create billing program reporting details for Google Play reporting (Android only).
|
|
163
|
+
* Available in Google Play Billing Library 8.2.0+.
|
|
164
|
+
*
|
|
165
|
+
* Must be called AFTER successful payment in your payment system.
|
|
166
|
+
* Token must be reported to Google Play backend within 24 hours.
|
|
167
|
+
*
|
|
168
|
+
* @param program - The billing program type
|
|
169
|
+
* @returns Promise resolving to reporting details including the external transaction token
|
|
170
|
+
*
|
|
171
|
+
* @example
|
|
172
|
+
* ```typescript
|
|
173
|
+
* const details = await createBillingProgramReportingDetailsAndroid('external-offer');
|
|
174
|
+
* // Report details.externalTransactionToken to Google Play within 24 hours
|
|
175
|
+
* await reportToGooglePlay(details.externalTransactionToken);
|
|
176
|
+
* ```
|
|
177
|
+
*/
|
|
178
|
+
export declare const createBillingProgramReportingDetailsAndroid: (program: BillingProgramAndroid) => Promise<BillingProgramReportingDetailsAndroid>;
|
|
127
179
|
//# sourceMappingURL=android.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"android.d.ts","sourceRoot":"","sources":["../../src/modules/android.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EACV,eAAe,EACf,aAAa,EACb,2BAA2B,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;;;;;GAgBG;AACH,eAAO,MAAM,yBAAyB,GACpC,QAAQ,+BAA+B,KACtC,OAAO,CAAC,IAAI,CAEd,CAAC;AAEF;;;;;;;;;;;;;;;;GAgBG;AACH,eAAO,MAAM,2CAA2C,GACtD,SAAS,qBAAqB,KAC7B,OAAO,CAAC,qCAAqC,CAE/C,CAAC"}
|
package/build/modules/android.js
CHANGED
|
@@ -183,4 +183,65 @@ export const showAlternativeBillingDialogAndroid = async () => {
|
|
|
183
183
|
export const createAlternativeBillingTokenAndroid = async (sku) => {
|
|
184
184
|
return ExpoIapModule.createAlternativeBillingTokenAndroid(sku);
|
|
185
185
|
};
|
|
186
|
+
// ============================================================================
|
|
187
|
+
// Billing Programs API (Google Play Billing Library 8.2.0+)
|
|
188
|
+
// ============================================================================
|
|
189
|
+
/**
|
|
190
|
+
* Check if a specific billing program is available for this user/device (Android only).
|
|
191
|
+
* Available in Google Play Billing Library 8.2.0+.
|
|
192
|
+
*
|
|
193
|
+
* @param program - The billing program to check ('external-offer' or 'external-content-link')
|
|
194
|
+
* @returns Promise resolving to availability result
|
|
195
|
+
*
|
|
196
|
+
* @example
|
|
197
|
+
* ```typescript
|
|
198
|
+
* const result = await isBillingProgramAvailableAndroid('external-offer');
|
|
199
|
+
* if (result.isAvailable) {
|
|
200
|
+
* // Proceed with billing program flow
|
|
201
|
+
* }
|
|
202
|
+
* ```
|
|
203
|
+
*/
|
|
204
|
+
export const isBillingProgramAvailableAndroid = async (program) => {
|
|
205
|
+
return ExpoIapModule.isBillingProgramAvailableAndroid(program);
|
|
206
|
+
};
|
|
207
|
+
/**
|
|
208
|
+
* Launch an external link for the specified billing program (Android only).
|
|
209
|
+
* Available in Google Play Billing Library 8.2.0+.
|
|
210
|
+
*
|
|
211
|
+
* @param params - The external link parameters
|
|
212
|
+
* @returns Promise resolving when the link is launched
|
|
213
|
+
*
|
|
214
|
+
* @example
|
|
215
|
+
* ```typescript
|
|
216
|
+
* await launchExternalLinkAndroid({
|
|
217
|
+
* billingProgram: 'external-offer',
|
|
218
|
+
* launchMode: 'launch-in-external-browser-or-app',
|
|
219
|
+
* linkType: 'link-to-digital-content-offer',
|
|
220
|
+
* linkUri: 'https://your-payment-site.com',
|
|
221
|
+
* });
|
|
222
|
+
* ```
|
|
223
|
+
*/
|
|
224
|
+
export const launchExternalLinkAndroid = async (params) => {
|
|
225
|
+
return ExpoIapModule.launchExternalLinkAndroid(params);
|
|
226
|
+
};
|
|
227
|
+
/**
|
|
228
|
+
* Create billing program reporting details for Google Play reporting (Android only).
|
|
229
|
+
* Available in Google Play Billing Library 8.2.0+.
|
|
230
|
+
*
|
|
231
|
+
* Must be called AFTER successful payment in your payment system.
|
|
232
|
+
* Token must be reported to Google Play backend within 24 hours.
|
|
233
|
+
*
|
|
234
|
+
* @param program - The billing program type
|
|
235
|
+
* @returns Promise resolving to reporting details including the external transaction token
|
|
236
|
+
*
|
|
237
|
+
* @example
|
|
238
|
+
* ```typescript
|
|
239
|
+
* const details = await createBillingProgramReportingDetailsAndroid('external-offer');
|
|
240
|
+
* // Report details.externalTransactionToken to Google Play within 24 hours
|
|
241
|
+
* await reportToGooglePlay(details.externalTransactionToken);
|
|
242
|
+
* ```
|
|
243
|
+
*/
|
|
244
|
+
export const createBillingProgramReportingDetailsAndroid = async (program) => {
|
|
245
|
+
return ExpoIapModule.createBillingProgramReportingDetailsAndroid(program);
|
|
246
|
+
};
|
|
186
247
|
//# sourceMappingURL=android.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"android.js","sourceRoot":"","sources":["../../src/modules/android.ts"],"names":[],"mappings":"AAAA,wBAAwB;AACxB,OAAO,EAAC,OAAO,EAAC,MAAM,cAAc,CAAC;AAErC,mBAAmB;AACnB,OAAO,aAAa,MAAM,kBAAkB,CAAC;AAiB7C,MAAM,mBAAmB,GAAG,aAAoC,CAAC;AAEjE,cAAc;AACd,MAAM,UAAU,gBAAgB,CAC9B,IAAa;IAEb,OAAO,CACL,IAAI,IAAI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;IAClE,OAAO,OAAO,CAAC,OAAO,CAAC,sCAAsC,CAAC,CAAC;AACjE,CAAC,CAAC;AAEF;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,CAAC,MAAM,0CAA0C,GAEnD,KAAK,IAAI,EAAE;IACb,OAAO,aAAa,CAAC,0CAA0C,EAAE,CAAC;AACpE,CAAC,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,MAAM,CAAC,MAAM,mCAAmC,GAE5C,KAAK,IAAI,EAAE;IACb,OAAO,aAAa,CAAC,mCAAmC,EAAE,CAAC;AAC7D,CAAC,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,MAAM,CAAC,MAAM,oCAAoC,GAE7C,KAAK,EAAE,GAAY,EAAE,EAAE;IACzB,OAAO,aAAa,CAAC,oCAAoC,CAAC,GAAG,CAAC,CAAC;AACjE,CAAC,CAAC","sourcesContent":["// External dependencies\nimport {Linking} from 'react-native';\n\n// Internal modules\nimport ExpoIapModule from '../ExpoIapModule';\n\n// Types\nimport type {\n DeepLinkOptions,\n MutationField,\n VerifyPurchaseResultAndroid,\n} from '../types';\n\ntype NativeAndroidModule = {\n deepLinkToSubscriptionsAndroid?: (params: {\n skuAndroid?: string;\n packageNameAndroid?: string;\n }) => Promise<void> | void;\n getStorefront?: () => Promise<string> | string;\n};\n\nconst nativeAndroidModule = ExpoIapModule as NativeAndroidModule;\n\n// Type guards\nexport function isProductAndroid<T extends {platform?: string}>(\n item: unknown,\n): item is T & {platform: 'android'} {\n return (\n item != null &&\n typeof item === 'object' &&\n 'platform' in item &&\n typeof (item as any).platform === 'string' &&\n (item as any).platform.toLowerCase() === 'android'\n );\n}\n\n/**\n * Deep link to subscriptions screen on Android.\n * @param {Object} params - The parameters object\n * @param {string} params.skuAndroid - The product's SKU (on Android)\n * @param {string} params.packageNameAndroid - The package name of your Android app (e.g., 'com.example.app')\n * @returns {Promise<void>}\n *\n * @example\n * ```typescript\n * await deepLinkToSubscriptionsAndroid({\n * skuAndroid: 'subscription_id',\n * packageNameAndroid: 'com.example.app'\n * });\n * ```\n */\nexport const deepLinkToSubscriptionsAndroid = async (\n options?: DeepLinkOptions | null,\n): Promise<void> => {\n const sku = options?.skuAndroid ?? undefined;\n const packageName = options?.packageNameAndroid ?? undefined;\n\n // Prefer native deep link implementation via OpenIAP module\n if (nativeAndroidModule?.deepLinkToSubscriptionsAndroid) {\n return nativeAndroidModule.deepLinkToSubscriptionsAndroid({\n skuAndroid: sku,\n packageNameAndroid: packageName,\n });\n }\n\n // Fallback to Linking if native method unavailable\n if (!packageName) {\n throw new Error(\n 'packageName is required for deepLinkToSubscriptionsAndroid',\n );\n }\n const base = `https://play.google.com/store/account/subscriptions?package=${encodeURIComponent(\n packageName,\n )}`;\n const url = sku ? `${base}&sku=${encodeURIComponent(sku)}` : base;\n return Linking.openURL(url);\n};\n\n/**\n * Validate receipt for Android. NOTE: This method is here for debugging purposes only. Including\n * your access token in the binary you ship to users is potentially dangerous.\n * Use server side validation instead for your production builds\n *\n * @deprecated Use verifyPurchase instead\n * @param {Object} params - The parameters object\n * @param {string} params.packageName - package name of your app.\n * @param {string} params.productId - product id for your in app product.\n * @param {string} params.productToken - token for your purchase (called 'token' in the API documentation).\n * @param {string} params.accessToken - OAuth access token with androidpublisher scope. Required for authentication.\n * @param {boolean} params.isSub - whether this is subscription or in-app. `true` for subscription.\n * @returns {Promise<ReceiptAndroid>}\n */\nexport const validateReceiptAndroid = async ({\n packageName,\n productId,\n productToken,\n accessToken,\n isSub,\n}: {\n packageName: string;\n productId: string;\n productToken: string;\n accessToken: string;\n isSub?: boolean;\n}): Promise<VerifyPurchaseResultAndroid> => {\n const type = isSub ? 'subscriptions' : 'products';\n\n const url =\n 'https://androidpublisher.googleapis.com/androidpublisher/v3/applications' +\n `/${packageName}/purchases/${type}/${productId}` +\n `/tokens/${productToken}`;\n\n const response = await fetch(url, {\n method: 'GET',\n headers: {\n 'Content-Type': 'application/json',\n Authorization: `Bearer ${accessToken}`,\n },\n });\n\n if (!response.ok) {\n throw Object.assign(new Error(response.statusText), {\n statusCode: response.status,\n });\n }\n\n return response.json();\n};\n\n/**\n * Acknowledge a product (on Android.) No-op on iOS.\n * @param {Object} params - The parameters object\n * @param {string} params.token - The product's token (on Android)\n * @returns {Promise<VoidResult | void>}\n */\nexport const acknowledgePurchaseAndroid: MutationField<\n 'acknowledgePurchaseAndroid'\n> = async (purchaseToken) => {\n const result = await ExpoIapModule.acknowledgePurchaseAndroid(purchaseToken);\n\n if (typeof result === 'boolean') {\n return result;\n }\n\n if (result && typeof result === 'object') {\n const record = result as Record<string, unknown>;\n if (typeof record.success === 'boolean') {\n return record.success;\n }\n if (typeof record.responseCode === 'number') {\n return record.responseCode === 0;\n }\n }\n\n return true;\n};\n\n/**\n * Open the Google Play Store to redeem offer codes (Android only).\n * Note: Google Play does not provide a direct API to redeem codes within the app.\n * This function opens the Play Store where users can manually enter their codes.\n *\n * @returns {Promise<void>}\n */\nexport const openRedeemOfferCodeAndroid = async (): Promise<void> => {\n return Linking.openURL(`https://play.google.com/redeem?code=`);\n};\n\n/**\n * Check if alternative billing is available for this user/device (Android only).\n * Step 1 of alternative billing flow.\n *\n * Returns true if available, false otherwise.\n * Throws OpenIapError.NotPrepared if billing client not ready.\n *\n * @returns {Promise<boolean>}\n *\n * @example\n * ```typescript\n * const isAvailable = await checkAlternativeBillingAvailabilityAndroid();\n * if (isAvailable) {\n * // Proceed with alternative billing flow\n * }\n * ```\n */\nexport const checkAlternativeBillingAvailabilityAndroid: MutationField<\n 'checkAlternativeBillingAvailabilityAndroid'\n> = async () => {\n return ExpoIapModule.checkAlternativeBillingAvailabilityAndroid();\n};\n\n/**\n * Show alternative billing information dialog to user (Android only).\n * Step 2 of alternative billing flow.\n * Must be called BEFORE processing payment in your payment system.\n *\n * Returns true if user accepted, false if user canceled.\n * Throws OpenIapError.NotPrepared if billing client not ready.\n *\n * @returns {Promise<boolean>}\n *\n * @example\n * ```typescript\n * const userAccepted = await showAlternativeBillingDialogAndroid();\n * if (userAccepted) {\n * // Process payment in your payment system\n * const success = await processCustomPayment();\n * if (success) {\n * // Create reporting token\n * const token = await createAlternativeBillingTokenAndroid();\n * // Send token to your backend for Google Play reporting\n * }\n * }\n * ```\n */\nexport const showAlternativeBillingDialogAndroid: MutationField<\n 'showAlternativeBillingDialogAndroid'\n> = async () => {\n return ExpoIapModule.showAlternativeBillingDialogAndroid();\n};\n\n/**\n * Create external transaction token for Google Play reporting (Android only).\n * Step 3 of alternative billing flow.\n * Must be called AFTER successful payment in your payment system.\n * Token must be reported to Google Play backend within 24 hours.\n *\n * Returns token string, or null if creation failed.\n * Throws OpenIapError.NotPrepared if billing client not ready.\n *\n * @param {string} sku - The product SKU that was purchased\n * @returns {Promise<string | null>}\n *\n * @example\n * ```typescript\n * const token = await createAlternativeBillingTokenAndroid('premium_subscription');\n * if (token) {\n * // Send token to your backend\n * await fetch('/api/report-transaction', {\n * method: 'POST',\n * body: JSON.stringify({ token, sku: 'premium_subscription' })\n * });\n * }\n * ```\n */\nexport const createAlternativeBillingTokenAndroid: MutationField<\n 'createAlternativeBillingTokenAndroid'\n> = async (sku?: string) => {\n return ExpoIapModule.createAlternativeBillingTokenAndroid(sku);\n};\n"]}
|
|
1
|
+
{"version":3,"file":"android.js","sourceRoot":"","sources":["../../src/modules/android.ts"],"names":[],"mappings":"AAAA,wBAAwB;AACxB,OAAO,EAAC,OAAO,EAAC,MAAM,cAAc,CAAC;AAErC,mBAAmB;AACnB,OAAO,aAAa,MAAM,kBAAkB,CAAC;AAqB7C,MAAM,mBAAmB,GAAG,aAAoC,CAAC;AAEjE,cAAc;AACd,MAAM,UAAU,gBAAgB,CAC9B,IAAa;IAEb,OAAO,CACL,IAAI,IAAI,IAAI;QACZ,OAAO,IAAI,KAAK,QAAQ;QACxB,UAAU,IAAI,IAAI;QAClB,OAAQ,IAAY,CAAC,QAAQ,KAAK,QAAQ;QACzC,IAAY,CAAC,QAAQ,CAAC,W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EnD,KAAK,IAAI,EAAE;IACb,OAAO,aAAa,CAAC,0CAA0C,EAAE,CAAC;AACpE,CAAC,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,MAAM,CAAC,MAAM,mCAAmC,GAE5C,KAAK,IAAI,EAAE;IACb,OAAO,aAAa,CAAC,mCAAmC,EAAE,CAAC;AAC7D,CAAC,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,MAAM,CAAC,MAAM,oCAAoC,GAE7C,KAAK,EAAE,GAAY,EAAE,EAAE;IACzB,OAAO,aAAa,CAAC,oCAAoC,CAAC,GAAG,CAAC,CAAC;AACjE,CAAC,CAAC;AAEF,+EAA+E;AAC/E,4DAA4D;AAC5D,+EAA+E;AAE/E;;;;;;;;;;;;;;GAcG;AACH,MAAM,CAAC,MAAM,gCAAgC,GAAG,KAAK,EACnD,OAA8B,EACoB,EAAE;IACpD,OAAO,aAAa,CAAC,gCAAgC,CAAC,OAAO,CAAC,CAAC;AACjE,CAAC,CAAC;AAEF;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,CAAC,MAAM,yBAAyB,GAAG,KAAK,EAC5C,MAAuC,EACxB,EAAE;IACjB,OAAO,aAAa,CAAC,yBAAyB,CAAC,MAAM,CAAC,CAAC;AACzD,CAAC,CAAC;AAEF;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,CAAC,MAAM,2CAA2C,GAAG,KAAK,EAC9D,OAA8B,EACkB,EAAE;IAClD,OAAO,aAAa,CAAC,2CAA2C,CAAC,OAAO,CAAC,CAAC;AAC5E,CAAC,CAAC","sourcesContent":["// External dependencies\nimport {Linking} from 'react-native';\n\n// Internal modules\nimport ExpoIapModule from '../ExpoIapModule';\n\n// Types\nimport type {\n BillingProgramAndroid,\n BillingProgramAvailabilityResultAndroid,\n BillingProgramReportingDetailsAndroid,\n DeepLinkOptions,\n LaunchExternalLinkParamsAndroid,\n MutationField,\n VerifyPurchaseResultAndroid,\n} from '../types';\n\ntype NativeAndroidModule = {\n deepLinkToSubscriptionsAndroid?: (params: {\n skuAndroid?: string;\n packageNameAndroid?: string;\n }) => Promise<void> | void;\n getStorefront?: () => Promise<string> | string;\n};\n\nconst nativeAndroidModule = ExpoIapModule as NativeAndroidModule;\n\n// Type guards\nexport function isProductAndroid<T extends {platform?: string}>(\n item: unknown,\n): item is T & {platform: 'android'} {\n return (\n item != null &&\n typeof item === 'object' &&\n 'platform' in item &&\n typeof (item as any).platform === 'string' &&\n (item as any).platform.toLowerCase() === 'android'\n );\n}\n\n/**\n * Deep link to subscriptions screen on Android.\n * @param {Object} params - The parameters object\n * @param {string} params.skuAndroid - The product's SKU (on Android)\n * @param {string} params.packageNameAndroid - The package name of your Android app (e.g., 'com.example.app')\n * @returns {Promise<void>}\n *\n * @example\n * ```typescript\n * await deepLinkToSubscriptionsAndroid({\n * skuAndroid: 'subscription_id',\n * packageNameAndroid: 'com.example.app'\n * });\n * ```\n */\nexport const deepLinkToSubscriptionsAndroid = async (\n options?: DeepLinkOptions | null,\n): Promise<void> => {\n const sku = options?.skuAndroid ?? undefined;\n const packageName = options?.packageNameAndroid ?? undefined;\n\n // Prefer native deep link implementation via OpenIAP module\n if (nativeAndroidModule?.deepLinkToSubscriptionsAndroid) {\n return nativeAndroidModule.deepLinkToSubscriptionsAndroid({\n skuAndroid: sku,\n packageNameAndroid: packageName,\n });\n }\n\n // Fallback to Linking if native method unavailable\n if (!packageName) {\n throw new Error(\n 'packageName is required for deepLinkToSubscriptionsAndroid',\n );\n }\n const base = `https://play.google.com/store/account/subscriptions?package=${encodeURIComponent(\n packageName,\n )}`;\n const url = sku ? `${base}&sku=${encodeURIComponent(sku)}` : base;\n return Linking.openURL(url);\n};\n\n/**\n * Validate receipt for Android. NOTE: This method is here for debugging purposes only. Including\n * your access token in the binary you ship to users is potentially dangerous.\n * Use server side validation instead for your production builds\n *\n * @deprecated Use verifyPurchase instead\n * @param {Object} params - The parameters object\n * @param {string} params.packageName - package name of your app.\n * @param {string} params.productId - product id for your in app product.\n * @param {string} params.productToken - token for your purchase (called 'token' in the API documentation).\n * @param {string} params.accessToken - OAuth access token with androidpublisher scope. Required for authentication.\n * @param {boolean} params.isSub - whether this is subscription or in-app. `true` for subscription.\n * @returns {Promise<ReceiptAndroid>}\n */\nexport const validateReceiptAndroid = async ({\n packageName,\n productId,\n productToken,\n accessToken,\n isSub,\n}: {\n packageName: string;\n productId: string;\n productToken: string;\n accessToken: string;\n isSub?: boolean;\n}): Promise<VerifyPurchaseResultAndroid> => {\n const type = isSub ? 'subscriptions' : 'products';\n\n const url =\n 'https://androidpublisher.googleapis.com/androidpublisher/v3/applications' +\n `/${packageName}/purchases/${type}/${productId}` +\n `/tokens/${productToken}`;\n\n const response = await fetch(url, {\n method: 'GET',\n headers: {\n 'Content-Type': 'application/json',\n Authorization: `Bearer ${accessToken}`,\n },\n });\n\n if (!response.ok) {\n throw Object.assign(new Error(response.statusText), {\n statusCode: response.status,\n });\n }\n\n return response.json();\n};\n\n/**\n * Acknowledge a product (on Android.) No-op on iOS.\n * @param {Object} params - The parameters object\n * @param {string} params.token - The product's token (on Android)\n * @returns {Promise<VoidResult | void>}\n */\nexport const acknowledgePurchaseAndroid: MutationField<\n 'acknowledgePurchaseAndroid'\n> = async (purchaseToken) => {\n const result = await ExpoIapModule.acknowledgePurchaseAndroid(purchaseToken);\n\n if (typeof result === 'boolean') {\n return result;\n }\n\n if (result && typeof result === 'object') {\n const record = result as Record<string, unknown>;\n if (typeof record.success === 'boolean') {\n return record.success;\n }\n if (typeof record.responseCode === 'number') {\n return record.responseCode === 0;\n }\n }\n\n return true;\n};\n\n/**\n * Open the Google Play Store to redeem offer codes (Android only).\n * Note: Google Play does not provide a direct API to redeem codes within the app.\n * This function opens the Play Store where users can manually enter their codes.\n *\n * @returns {Promise<void>}\n */\nexport const openRedeemOfferCodeAndroid = async (): Promise<void> => {\n return Linking.openURL(`https://play.google.com/redeem?code=`);\n};\n\n/**\n * Check if alternative billing is available for this user/device (Android only).\n * Step 1 of alternative billing flow.\n *\n * Returns true if available, false otherwise.\n * Throws OpenIapError.NotPrepared if billing client not ready.\n *\n * @returns {Promise<boolean>}\n *\n * @example\n * ```typescript\n * const isAvailable = await checkAlternativeBillingAvailabilityAndroid();\n * if (isAvailable) {\n * // Proceed with alternative billing flow\n * }\n * ```\n */\nexport const checkAlternativeBillingAvailabilityAndroid: MutationField<\n 'checkAlternativeBillingAvailabilityAndroid'\n> = async () => {\n return ExpoIapModule.checkAlternativeBillingAvailabilityAndroid();\n};\n\n/**\n * Show alternative billing information dialog to user (Android only).\n * Step 2 of alternative billing flow.\n * Must be called BEFORE processing payment in your payment system.\n *\n * Returns true if user accepted, false if user canceled.\n * Throws OpenIapError.NotPrepared if billing client not ready.\n *\n * @returns {Promise<boolean>}\n *\n * @example\n * ```typescript\n * const userAccepted = await showAlternativeBillingDialogAndroid();\n * if (userAccepted) {\n * // Process payment in your payment system\n * const success = await processCustomPayment();\n * if (success) {\n * // Create reporting token\n * const token = await createAlternativeBillingTokenAndroid();\n * // Send token to your backend for Google Play reporting\n * }\n * }\n * ```\n */\nexport const showAlternativeBillingDialogAndroid: MutationField<\n 'showAlternativeBillingDialogAndroid'\n> = async () => {\n return ExpoIapModule.showAlternativeBillingDialogAndroid();\n};\n\n/**\n * Create external transaction token for Google Play reporting (Android only).\n * Step 3 of alternative billing flow.\n * Must be called AFTER successful payment in your payment system.\n * Token must be reported to Google Play backend within 24 hours.\n *\n * Returns token string, or null if creation failed.\n * Throws OpenIapError.NotPrepared if billing client not ready.\n *\n * @param {string} sku - The product SKU that was purchased\n * @returns {Promise<string | null>}\n *\n * @example\n * ```typescript\n * const token = await createAlternativeBillingTokenAndroid('premium_subscription');\n * if (token) {\n * // Send token to your backend\n * await fetch('/api/report-transaction', {\n * method: 'POST',\n * body: JSON.stringify({ token, sku: 'premium_subscription' })\n * });\n * }\n * ```\n */\nexport const createAlternativeBillingTokenAndroid: MutationField<\n 'createAlternativeBillingTokenAndroid'\n> = async (sku?: string) => {\n return ExpoIapModule.createAlternativeBillingTokenAndroid(sku);\n};\n\n// ============================================================================\n// Billing Programs API (Google Play Billing Library 8.2.0+)\n// ============================================================================\n\n/**\n * Check if a specific billing program is available for this user/device (Android only).\n * Available in Google Play Billing Library 8.2.0+.\n *\n * @param program - The billing program to check ('external-offer' or 'external-content-link')\n * @returns Promise resolving to availability result\n *\n * @example\n * ```typescript\n * const result = await isBillingProgramAvailableAndroid('external-offer');\n * if (result.isAvailable) {\n * // Proceed with billing program flow\n * }\n * ```\n */\nexport const isBillingProgramAvailableAndroid = async (\n program: BillingProgramAndroid,\n): Promise<BillingProgramAvailabilityResultAndroid> => {\n return ExpoIapModule.isBillingProgramAvailableAndroid(program);\n};\n\n/**\n * Launch an external link for the specified billing program (Android only).\n * Available in Google Play Billing Library 8.2.0+.\n *\n * @param params - The external link parameters\n * @returns Promise resolving when the link is launched\n *\n * @example\n * ```typescript\n * await launchExternalLinkAndroid({\n * billingProgram: 'external-offer',\n * launchMode: 'launch-in-external-browser-or-app',\n * linkType: 'link-to-digital-content-offer',\n * linkUri: 'https://your-payment-site.com',\n * });\n * ```\n */\nexport const launchExternalLinkAndroid = async (\n params: LaunchExternalLinkParamsAndroid,\n): Promise<void> => {\n return ExpoIapModule.launchExternalLinkAndroid(params);\n};\n\n/**\n * Create billing program reporting details for Google Play reporting (Android only).\n * Available in Google Play Billing Library 8.2.0+.\n *\n * Must be called AFTER successful payment in your payment system.\n * Token must be reported to Google Play backend within 24 hours.\n *\n * @param program - The billing program type\n * @returns Promise resolving to reporting details including the external transaction token\n *\n * @example\n * ```typescript\n * const details = await createBillingProgramReportingDetailsAndroid('external-offer');\n * // Report details.externalTransactionToken to Google Play within 24 hours\n * await reportToGooglePlay(details.externalTransactionToken);\n * ```\n */\nexport const createBillingProgramReportingDetailsAndroid = async (\n program: BillingProgramAndroid,\n): Promise<BillingProgramReportingDetailsAndroid> => {\n return ExpoIapModule.createBillingProgramReportingDetailsAndroid(program);\n};\n"]}
|