expo-iap 4.2.2 → 4.2.4
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/build/index.d.ts +126 -33
- package/build/index.d.ts.map +1 -1
- package/build/index.js +123 -33
- package/build/index.js.map +1 -1
- package/build/kit-api.d.ts +54 -0
- package/build/kit-api.d.ts.map +1 -0
- package/build/kit-api.js +156 -0
- package/build/kit-api.js.map +1 -0
- package/build/modules/android.d.ts +22 -0
- package/build/modules/android.d.ts.map +1 -1
- package/build/modules/android.js +37 -0
- package/build/modules/android.js.map +1 -1
- package/build/modules/ios.d.ts +69 -1
- package/build/modules/ios.d.ts.map +1 -1
- package/build/modules/ios.js +73 -1
- package/build/modules/ios.js.map +1 -1
- package/build/types.d.ts +241 -75
- package/build/types.d.ts.map +1 -1
- package/build/types.js.map +1 -1
- package/build/useIAP.d.ts.map +1 -1
- package/build/useIAP.js +125 -3
- package/build/useIAP.js.map +1 -1
- package/build/useWebhookEvents.d.ts +26 -0
- package/build/useWebhookEvents.d.ts.map +1 -0
- package/build/useWebhookEvents.js +105 -0
- package/build/useWebhookEvents.js.map +1 -0
- package/build/webhook-client.d.ts +82 -0
- package/build/webhook-client.d.ts.map +1 -0
- package/build/webhook-client.js +176 -0
- package/build/webhook-client.js.map +1 -0
- package/openiap-versions.json +2 -2
- package/package.json +1 -1
- package/src/index.ts +141 -33
- package/src/kit-api.ts +229 -0
- package/src/modules/android.ts +47 -0
- package/src/modules/ios.ts +74 -1
- package/src/types.ts +247 -75
- package/src/useIAP.ts +125 -3
- package/src/useWebhookEvents.ts +155 -0
- package/src/webhook-client.ts +314 -0
package/src/types.ts
CHANGED
|
@@ -585,118 +585,176 @@ export interface LimitedQuantityInfoAndroid {
|
|
|
585
585
|
}
|
|
586
586
|
|
|
587
587
|
export interface Mutation {
|
|
588
|
-
/**
|
|
588
|
+
/**
|
|
589
|
+
* Acknowledge a non-consumable purchase. Required within 3 days or Google auto-refunds.
|
|
590
|
+
* See: https://www.openiap.dev/docs/apis/android/acknowledge-purchase-android
|
|
591
|
+
*/
|
|
589
592
|
acknowledgePurchaseAndroid: Promise<boolean>;
|
|
590
|
-
/**
|
|
593
|
+
/**
|
|
594
|
+
* Present the refund request sheet (iOS 15+). See also Features → Refund.
|
|
595
|
+
* See: https://www.openiap.dev/docs/apis/ios/begin-refund-request-ios
|
|
596
|
+
*/
|
|
591
597
|
beginRefundRequestIOS?: Promise<(string | null)>;
|
|
592
598
|
/**
|
|
593
|
-
* Check
|
|
594
|
-
* Step 1 of alternative billing flow
|
|
599
|
+
* Check whether alternative billing is available for the user. Step 1 of the alternative billing flow.
|
|
595
600
|
*
|
|
596
|
-
* Returns true if available, false otherwise
|
|
597
|
-
* Throws OpenIapError.NotPrepared if billing client not ready
|
|
601
|
+
* Returns true if available, false otherwise.
|
|
602
|
+
* Throws OpenIapError.NotPrepared if billing client not ready.
|
|
603
|
+
* See: https://www.openiap.dev/docs/apis/android/check-alternative-billing-availability-android
|
|
598
604
|
*/
|
|
599
605
|
checkAlternativeBillingAvailabilityAndroid: Promise<boolean>;
|
|
600
|
-
/**
|
|
606
|
+
/**
|
|
607
|
+
* Clear pending transactions in the queue (sandbox helper).
|
|
608
|
+
* See: https://www.openiap.dev/docs/apis/ios/clear-transaction-ios
|
|
609
|
+
*/
|
|
601
610
|
clearTransactionIOS: Promise<boolean>;
|
|
602
|
-
/**
|
|
611
|
+
/**
|
|
612
|
+
* Consume a consumable purchase so it can be re-bought.
|
|
613
|
+
* See: https://www.openiap.dev/docs/apis/android/consume-purchase-android
|
|
614
|
+
*/
|
|
603
615
|
consumePurchaseAndroid: Promise<boolean>;
|
|
604
616
|
/**
|
|
605
|
-
* Create
|
|
606
|
-
*
|
|
607
|
-
*
|
|
608
|
-
* Token must be reported to Google Play backend within 24 hours
|
|
617
|
+
* Create a reporting token for an alternative billing flow. Step 3 of the alternative billing flow.
|
|
618
|
+
* Must be called AFTER successful payment in your payment system.
|
|
619
|
+
* Token must be reported to Google Play backend within 24 hours.
|
|
609
620
|
*
|
|
610
|
-
* Returns token string, or null if creation failed
|
|
611
|
-
* Throws OpenIapError.NotPrepared if billing client not ready
|
|
621
|
+
* Returns token string, or null if creation failed.
|
|
622
|
+
* Throws OpenIapError.NotPrepared if billing client not ready.
|
|
623
|
+
* See: https://www.openiap.dev/docs/apis/android/create-alternative-billing-token-android
|
|
612
624
|
*/
|
|
613
625
|
createAlternativeBillingTokenAndroid?: Promise<(string | null)>;
|
|
614
626
|
/**
|
|
615
|
-
* Create reporting
|
|
616
|
-
* Replaces the deprecated createExternalOfferReportingDetailsAsync API
|
|
627
|
+
* Create the reporting payload Google requires after a Developer-Provided Billing transaction (Play Billing 8.3.0+).
|
|
628
|
+
* Replaces the deprecated createExternalOfferReportingDetailsAsync API.
|
|
617
629
|
*
|
|
618
|
-
*
|
|
619
|
-
*
|
|
620
|
-
*
|
|
630
|
+
* Returns external transaction token needed for reporting external transactions.
|
|
631
|
+
* Throws OpenIapError.NotPrepared if billing client not ready.
|
|
632
|
+
* See: https://www.openiap.dev/docs/apis/android/create-billing-program-reporting-details-android
|
|
621
633
|
*/
|
|
622
634
|
createBillingProgramReportingDetailsAndroid: Promise<BillingProgramReportingDetailsAndroid>;
|
|
623
|
-
/**
|
|
635
|
+
/**
|
|
636
|
+
* Open the platform's subscription management UI.
|
|
637
|
+
* See: https://www.openiap.dev/docs/apis/deep-link-to-subscriptions
|
|
638
|
+
*/
|
|
624
639
|
deepLinkToSubscriptions: Promise<void>;
|
|
625
|
-
/**
|
|
640
|
+
/**
|
|
641
|
+
* Close the store connection and release resources.
|
|
642
|
+
* See: https://www.openiap.dev/docs/apis/end-connection
|
|
643
|
+
*/
|
|
626
644
|
endConnection: Promise<boolean>;
|
|
627
|
-
/**
|
|
645
|
+
/**
|
|
646
|
+
* Complete a transaction after server-side verification. Required on Android within 3 days.
|
|
647
|
+
* See: https://www.openiap.dev/docs/apis/finish-transaction
|
|
648
|
+
*/
|
|
628
649
|
finishTransaction: Promise<void>;
|
|
629
|
-
/**
|
|
650
|
+
/**
|
|
651
|
+
* Initialize the store connection. Call before any IAP API.
|
|
652
|
+
* See: https://www.openiap.dev/docs/apis/init-connection
|
|
653
|
+
*/
|
|
630
654
|
initConnection: Promise<boolean>;
|
|
631
655
|
/**
|
|
632
|
-
* Check
|
|
633
|
-
* Replaces the deprecated isExternalOfferAvailableAsync API
|
|
656
|
+
* Check whether a billing program (e.g., External Payments) is available for the current user.
|
|
657
|
+
* Replaces the deprecated isExternalOfferAvailableAsync API.
|
|
634
658
|
*
|
|
635
|
-
* Available in Google Play Billing Library 8.2.0
|
|
636
|
-
* Returns availability result with isAvailable flag
|
|
637
|
-
* Throws OpenIapError.NotPrepared if billing client not ready
|
|
659
|
+
* Available in Google Play Billing Library 8.2.0+.
|
|
660
|
+
* Returns availability result with isAvailable flag.
|
|
661
|
+
* Throws OpenIapError.NotPrepared if billing client not ready.
|
|
662
|
+
* See: https://www.openiap.dev/docs/apis/android/is-billing-program-available-android
|
|
638
663
|
*/
|
|
639
664
|
isBillingProgramAvailableAndroid: Promise<BillingProgramAvailabilityResultAndroid>;
|
|
640
665
|
/**
|
|
641
|
-
* Launch external link flow
|
|
642
|
-
* Replaces the deprecated showExternalOfferInformationDialog API
|
|
666
|
+
* Launch an external content/offer link from inside the Billing Programs flow (Play Billing 8.2.0+).
|
|
667
|
+
* Replaces the deprecated showExternalOfferInformationDialog API.
|
|
643
668
|
*
|
|
644
|
-
*
|
|
645
|
-
*
|
|
646
|
-
*
|
|
669
|
+
* Shows Play Store dialog and optionally launches external URL.
|
|
670
|
+
* Throws OpenIapError.NotPrepared if billing client not ready.
|
|
671
|
+
* See: https://www.openiap.dev/docs/apis/android/launch-external-link-android
|
|
647
672
|
*/
|
|
648
673
|
launchExternalLinkAndroid: Promise<boolean>;
|
|
649
|
-
/**
|
|
674
|
+
/**
|
|
675
|
+
* Show the App Store offer code redemption sheet.
|
|
676
|
+
* See: https://www.openiap.dev/docs/apis/ios/present-code-redemption-sheet-ios
|
|
677
|
+
*/
|
|
650
678
|
presentCodeRedemptionSheetIOS: Promise<boolean>;
|
|
651
|
-
/**
|
|
679
|
+
/**
|
|
680
|
+
* Present an external purchase link, StoreKit External (iOS 16+).
|
|
681
|
+
* See: https://www.openiap.dev/docs/apis/ios/present-external-purchase-link-ios
|
|
682
|
+
*/
|
|
652
683
|
presentExternalPurchaseLinkIOS: Promise<ExternalPurchaseLinkResultIOS>;
|
|
653
684
|
/**
|
|
654
|
-
* Present external purchase notice sheet (iOS 17.4+).
|
|
655
|
-
* Uses ExternalPurchase.presentNoticeSheet() which returns a token when user continues.
|
|
685
|
+
* Present the external purchase notice sheet (iOS 17.4+).
|
|
686
|
+
* Uses ExternalPurchase.presentNoticeSheet() which returns a token when the user continues.
|
|
656
687
|
* Reference: https://developer.apple.com/documentation/storekit/externalpurchase/presentnoticesheet()
|
|
688
|
+
* See: https://www.openiap.dev/docs/apis/ios/present-external-purchase-notice-sheet-ios
|
|
657
689
|
*/
|
|
658
690
|
presentExternalPurchaseNoticeSheetIOS: Promise<ExternalPurchaseNoticeResultIOS>;
|
|
659
|
-
/**
|
|
691
|
+
/**
|
|
692
|
+
* Initiate a purchase or subscription flow; rely on events for final state.
|
|
693
|
+
* See: https://www.openiap.dev/docs/apis/request-purchase
|
|
694
|
+
*/
|
|
660
695
|
requestPurchase?: Promise<(Purchase | Purchase[] | null)>;
|
|
661
696
|
/**
|
|
662
|
-
*
|
|
697
|
+
* Buy the currently promoted product.
|
|
663
698
|
*
|
|
664
699
|
* @deprecated Use promotedProductListenerIOS to receive the productId,
|
|
665
700
|
* then call requestPurchase with that SKU instead. In StoreKit 2,
|
|
666
701
|
* promoted products can be purchased directly via the standard purchase flow.
|
|
702
|
+
* See: https://www.openiap.dev/docs/apis/ios/request-purchase-on-promoted-product-ios
|
|
667
703
|
* @deprecated Use promotedProductListenerIOS + requestPurchase instead
|
|
668
704
|
*/
|
|
669
705
|
requestPurchaseOnPromotedProductIOS: Promise<boolean>;
|
|
670
|
-
/**
|
|
706
|
+
/**
|
|
707
|
+
* Restore non-consumable and active subscription purchases.
|
|
708
|
+
* See: https://www.openiap.dev/docs/apis/restore-purchases
|
|
709
|
+
*/
|
|
671
710
|
restorePurchases: Promise<void>;
|
|
672
711
|
/**
|
|
673
|
-
*
|
|
674
|
-
*
|
|
675
|
-
* Must be called BEFORE processing payment in your payment system
|
|
712
|
+
* Display Google's alternative billing information dialog. Step 2 of the alternative billing flow.
|
|
713
|
+
* Must be called BEFORE processing payment in your payment system.
|
|
676
714
|
*
|
|
677
|
-
* Returns true if user accepted, false if user canceled
|
|
678
|
-
* Throws OpenIapError.NotPrepared if billing client not ready
|
|
715
|
+
* Returns true if user accepted, false if user canceled.
|
|
716
|
+
* Throws OpenIapError.NotPrepared if billing client not ready.
|
|
717
|
+
* See: https://www.openiap.dev/docs/apis/android/show-alternative-billing-dialog-android
|
|
679
718
|
*/
|
|
680
719
|
showAlternativeBillingDialogAndroid: Promise<boolean>;
|
|
681
720
|
/**
|
|
682
|
-
*
|
|
683
|
-
* Displays the system disclosure notice sheet for custom external purchase links.
|
|
721
|
+
* Present the disclosure sheet required before linking out via ExternalPurchaseCustomLink (iOS 18.1+).
|
|
684
722
|
* Call this after a deliberate customer interaction before linking out to external purchases.
|
|
685
723
|
* Reference: https://developer.apple.com/documentation/storekit/externalpurchasecustomlink/shownotice(type:)
|
|
724
|
+
* See: https://www.openiap.dev/docs/apis/ios/show-external-purchase-custom-link-notice-ios
|
|
686
725
|
*/
|
|
687
726
|
showExternalPurchaseCustomLinkNoticeIOS: Promise<ExternalPurchaseCustomLinkNoticeResultIOS>;
|
|
688
|
-
/**
|
|
727
|
+
/**
|
|
728
|
+
* Present the manage-subscriptions sheet and return changed purchases (iOS 15+).
|
|
729
|
+
* See: https://www.openiap.dev/docs/apis/ios/show-manage-subscriptions-ios
|
|
730
|
+
*/
|
|
689
731
|
showManageSubscriptionsIOS: Promise<PurchaseIOS[]>;
|
|
690
|
-
/**
|
|
732
|
+
/**
|
|
733
|
+
* Force sync transactions with the App Store (iOS 15+).
|
|
734
|
+
* See: https://www.openiap.dev/docs/apis/ios/sync-ios
|
|
735
|
+
*/
|
|
691
736
|
syncIOS: Promise<boolean>;
|
|
692
737
|
/**
|
|
693
|
-
* Validate purchase receipts with the configured providers
|
|
738
|
+
* Deprecated. Validate purchase receipts with the configured providers — use verifyPurchase instead.
|
|
739
|
+
* See: https://www.openiap.dev/docs/features/validation#verify-purchase
|
|
694
740
|
* @deprecated Use verifyPurchase
|
|
695
741
|
*/
|
|
696
742
|
validateReceipt: Promise<VerifyPurchaseResult>;
|
|
697
|
-
/**
|
|
743
|
+
/**
|
|
744
|
+
* Verify a purchase against your own backend. Returns a platform-specific
|
|
745
|
+
* variant of VerifyPurchaseResult — VerifyPurchaseResultIOS exposes isValid
|
|
746
|
+
* + receipt/JWS metadata, VerifyPurchaseResultAndroid carries Play Store
|
|
747
|
+
* receipt fields (no isValid), and VerifyPurchaseResultHorizon uses success.
|
|
748
|
+
* Inspect the concrete variant before reading fields.
|
|
749
|
+
* See: https://www.openiap.dev/docs/features/validation#verify-purchase
|
|
750
|
+
*/
|
|
698
751
|
verifyPurchase: Promise<VerifyPurchaseResult>;
|
|
699
|
-
/**
|
|
752
|
+
/**
|
|
753
|
+
* Verify via a managed provider without standing up your own server. The
|
|
754
|
+
* PurchaseVerificationProvider enum currently exposes only IAPKit; platform
|
|
755
|
+
* availability may differ by implementation.
|
|
756
|
+
* See: https://www.openiap.dev/docs/features/validation#verify-purchase-with-provider
|
|
757
|
+
*/
|
|
700
758
|
verifyPurchaseWithProvider: Promise<VerifyPurchaseWithProviderResult>;
|
|
701
759
|
}
|
|
702
760
|
|
|
@@ -1234,66 +1292,117 @@ export type PurchaseVerificationProvider = 'iapkit';
|
|
|
1234
1292
|
|
|
1235
1293
|
export interface Query {
|
|
1236
1294
|
/**
|
|
1237
|
-
* Check
|
|
1238
|
-
* Uses ExternalPurchase.canPresent
|
|
1295
|
+
* Check eligibility for the external purchase notice sheet (iOS 17.4+).
|
|
1296
|
+
* Uses ExternalPurchase.canPresent.
|
|
1297
|
+
* See: https://www.openiap.dev/docs/apis/ios/can-present-external-purchase-notice-ios
|
|
1239
1298
|
*/
|
|
1240
1299
|
canPresentExternalPurchaseNoticeIOS: Promise<boolean>;
|
|
1241
|
-
/**
|
|
1300
|
+
/**
|
|
1301
|
+
* Get the user's current entitlement for a product, using StoreKit 2 (iOS 15+).
|
|
1302
|
+
* See: https://www.openiap.dev/docs/apis/ios/current-entitlement-ios
|
|
1303
|
+
*/
|
|
1242
1304
|
currentEntitlementIOS?: Promise<(PurchaseIOS | null)>;
|
|
1243
|
-
/**
|
|
1305
|
+
/**
|
|
1306
|
+
* Fetch products or subscriptions from the store.
|
|
1307
|
+
* See: https://www.openiap.dev/docs/apis/fetch-products
|
|
1308
|
+
*/
|
|
1244
1309
|
fetchProducts: Promise<(ProductOrSubscription[] | Product[] | ProductSubscription[] | null)>;
|
|
1245
|
-
/**
|
|
1310
|
+
/**
|
|
1311
|
+
* Get details of all currently active subscriptions (filters by subscriptionIds when provided).
|
|
1312
|
+
* See: https://www.openiap.dev/docs/apis/get-active-subscriptions
|
|
1313
|
+
*/
|
|
1246
1314
|
getActiveSubscriptions: Promise<ActiveSubscription[]>;
|
|
1247
1315
|
/**
|
|
1248
|
-
*
|
|
1316
|
+
* List every StoreKit transaction (finished + unfinished) for the current user.
|
|
1249
1317
|
* Requires the SK2ConsumableTransactionHistory Info.plist key in the host app
|
|
1250
1318
|
* for finished consumables to be included (iOS 18+).
|
|
1251
1319
|
* Unlike getAvailablePurchases, always returns the iOS-specific PurchaseIOS shape.
|
|
1320
|
+
* See: https://www.openiap.dev/docs/apis/ios/get-all-transactions-ios
|
|
1252
1321
|
*/
|
|
1253
1322
|
getAllTransactionsIOS: Promise<PurchaseIOS[]>;
|
|
1254
|
-
/**
|
|
1323
|
+
/**
|
|
1324
|
+
* Fetch the app transaction (iOS 16+).
|
|
1325
|
+
* See: https://www.openiap.dev/docs/apis/ios/get-app-transaction-ios
|
|
1326
|
+
*/
|
|
1255
1327
|
getAppTransactionIOS?: Promise<(AppTransaction | null)>;
|
|
1256
|
-
/**
|
|
1328
|
+
/**
|
|
1329
|
+
* List active purchases for the current user.
|
|
1330
|
+
* See: https://www.openiap.dev/docs/apis/get-available-purchases
|
|
1331
|
+
*/
|
|
1257
1332
|
getAvailablePurchases: Promise<Purchase[]>;
|
|
1258
1333
|
/**
|
|
1259
|
-
*
|
|
1260
|
-
* Use this token
|
|
1334
|
+
* Fetch a token for Apple's External Purchase Server reporting API (iOS 18.1+).
|
|
1335
|
+
* Use this token to report transactions made through ExternalPurchaseCustomLink.
|
|
1261
1336
|
* Reference: https://developer.apple.com/documentation/storekit/externalpurchasecustomlink/token(for:)
|
|
1337
|
+
* See: https://www.openiap.dev/docs/apis/ios/get-external-purchase-custom-link-token-ios
|
|
1262
1338
|
*/
|
|
1263
1339
|
getExternalPurchaseCustomLinkTokenIOS: Promise<ExternalPurchaseCustomLinkTokenResultIOS>;
|
|
1264
|
-
/**
|
|
1340
|
+
/**
|
|
1341
|
+
* List unfinished StoreKit transactions in the queue.
|
|
1342
|
+
* See: https://www.openiap.dev/docs/apis/ios/get-pending-transactions-ios
|
|
1343
|
+
*/
|
|
1265
1344
|
getPendingTransactionsIOS: Promise<PurchaseIOS[]>;
|
|
1266
|
-
/**
|
|
1345
|
+
/**
|
|
1346
|
+
* Read the App Store-promoted product, if any (iOS 11+).
|
|
1347
|
+
* See: https://www.openiap.dev/docs/apis/ios/get-promoted-product-ios
|
|
1348
|
+
*/
|
|
1267
1349
|
getPromotedProductIOS?: Promise<(ProductIOS | null)>;
|
|
1268
|
-
/**
|
|
1350
|
+
/**
|
|
1351
|
+
* Get base64-encoded receipt data (legacy validation).
|
|
1352
|
+
* See: https://www.openiap.dev/docs/apis/ios/get-receipt-data-ios
|
|
1353
|
+
*/
|
|
1269
1354
|
getReceiptDataIOS?: Promise<(string | null)>;
|
|
1270
|
-
/**
|
|
1355
|
+
/**
|
|
1356
|
+
* Return the user's storefront country code.
|
|
1357
|
+
* See: https://www.openiap.dev/docs/apis/get-storefront
|
|
1358
|
+
*/
|
|
1271
1359
|
getStorefront: Promise<string>;
|
|
1272
1360
|
/**
|
|
1273
|
-
* Get the current App Store storefront country code
|
|
1361
|
+
* Deprecated. Get the current App Store storefront country code — use cross-platform getStorefront instead.
|
|
1362
|
+
* See: https://www.openiap.dev/docs/apis/ios/get-storefront-ios
|
|
1274
1363
|
* @deprecated Use getStorefront
|
|
1275
1364
|
*/
|
|
1276
1365
|
getStorefrontIOS: Promise<string>;
|
|
1277
|
-
/**
|
|
1366
|
+
/**
|
|
1367
|
+
* Return the JWS string for a transaction (StoreKit 2).
|
|
1368
|
+
* See: https://www.openiap.dev/docs/apis/ios/get-transaction-jws-ios
|
|
1369
|
+
*/
|
|
1278
1370
|
getTransactionJwsIOS?: Promise<(string | null)>;
|
|
1279
|
-
/**
|
|
1371
|
+
/**
|
|
1372
|
+
* Check whether the user has any active subscription.
|
|
1373
|
+
* See: https://www.openiap.dev/docs/apis/has-active-subscriptions
|
|
1374
|
+
*/
|
|
1280
1375
|
hasActiveSubscriptions: Promise<boolean>;
|
|
1281
1376
|
/**
|
|
1282
|
-
* Check
|
|
1377
|
+
* Check eligibility for the custom-link variant of external purchase (iOS 18.1+).
|
|
1283
1378
|
* Returns true if the app can use custom external purchase links.
|
|
1284
1379
|
* Reference: https://developer.apple.com/documentation/storekit/externalpurchasecustomlink/iseligible
|
|
1380
|
+
* See: https://www.openiap.dev/docs/apis/ios/is-eligible-for-external-purchase-custom-link-ios
|
|
1285
1381
|
*/
|
|
1286
1382
|
isEligibleForExternalPurchaseCustomLinkIOS: Promise<boolean>;
|
|
1287
|
-
/**
|
|
1383
|
+
/**
|
|
1384
|
+
* Check intro-offer eligibility for a subscription group.
|
|
1385
|
+
* See: https://www.openiap.dev/docs/apis/ios/is-eligible-for-intro-offer-ios
|
|
1386
|
+
*/
|
|
1288
1387
|
isEligibleForIntroOfferIOS: Promise<boolean>;
|
|
1289
|
-
/**
|
|
1388
|
+
/**
|
|
1389
|
+
* Check whether a transaction's JWS verification passed (StoreKit 2).
|
|
1390
|
+
* See: https://www.openiap.dev/docs/apis/ios/is-transaction-verified-ios
|
|
1391
|
+
*/
|
|
1290
1392
|
isTransactionVerifiedIOS: Promise<boolean>;
|
|
1291
|
-
/**
|
|
1393
|
+
/**
|
|
1394
|
+
* Get the latest verified transaction for a product, using StoreKit 2.
|
|
1395
|
+
* See: https://www.openiap.dev/docs/apis/ios/latest-transaction-ios
|
|
1396
|
+
*/
|
|
1292
1397
|
latestTransactionIOS?: Promise<(PurchaseIOS | null)>;
|
|
1293
|
-
/**
|
|
1398
|
+
/**
|
|
1399
|
+
* Get subscription status objects from StoreKit 2 (iOS 15+).
|
|
1400
|
+
* See: https://www.openiap.dev/docs/apis/ios/subscription-status-ios
|
|
1401
|
+
*/
|
|
1294
1402
|
subscriptionStatusIOS: Promise<SubscriptionStatusIOS[]>;
|
|
1295
1403
|
/**
|
|
1296
|
-
*
|
|
1404
|
+
* Deprecated. Legacy App Store receipt validation — use verifyPurchase instead.
|
|
1405
|
+
* See: https://www.openiap.dev/docs/apis/ios/validate-receipt-ios
|
|
1297
1406
|
* @deprecated Use verifyPurchase
|
|
1298
1407
|
*/
|
|
1299
1408
|
validateReceiptIOS: Promise<VerifyPurchaseResultIOS>;
|
|
@@ -1787,6 +1896,8 @@ export interface SubscriptionProductReplacementParamsAndroid {
|
|
|
1787
1896
|
*/
|
|
1788
1897
|
export type SubscriptionReplacementModeAndroid = 'unknown-replacement-mode' | 'with-time-proration' | 'charge-prorated-price' | 'charge-full-price' | 'without-proration' | 'deferred' | 'keep-existing';
|
|
1789
1898
|
|
|
1899
|
+
export type SubscriptionState = 'active' | 'expired' | 'in-billing-retry' | 'in-grace-period' | 'paused' | 'refunded' | 'revoked' | 'unknown';
|
|
1900
|
+
|
|
1790
1901
|
export interface SubscriptionStatusIOS {
|
|
1791
1902
|
renewalInfo?: (RenewalInfoIOS | null);
|
|
1792
1903
|
state: string;
|
|
@@ -1948,6 +2059,67 @@ export interface VerifyPurchaseWithProviderResult {
|
|
|
1948
2059
|
|
|
1949
2060
|
export type VoidResult = void;
|
|
1950
2061
|
|
|
2062
|
+
export type WebhookCancellationReason = 'billing-error' | 'other' | 'price-increase-declined' | 'product-unavailable' | 'refunded' | 'user-canceled';
|
|
2063
|
+
|
|
2064
|
+
export interface WebhookEvent {
|
|
2065
|
+
/** Reason for cancellation, when applicable. */
|
|
2066
|
+
cancellationReason?: (WebhookCancellationReason | null);
|
|
2067
|
+
/** Localized currency code (ISO 4217) at event time, when available. */
|
|
2068
|
+
currency?: (string | null);
|
|
2069
|
+
environment: WebhookEventEnvironment;
|
|
2070
|
+
/** When the current subscription period ends. Epoch milliseconds. */
|
|
2071
|
+
expiresAt?: (number | null);
|
|
2072
|
+
/**
|
|
2073
|
+
* Stable identifier suitable for idempotency. Derived from the source notification
|
|
2074
|
+
* UUID where the store provides one (ASN v2 `notificationUUID`, RTDN message id);
|
|
2075
|
+
* otherwise hashed from the canonicalized payload.
|
|
2076
|
+
*/
|
|
2077
|
+
id: string;
|
|
2078
|
+
/** Time the underlying event occurred at the store. Epoch milliseconds. */
|
|
2079
|
+
occurredAt: number;
|
|
2080
|
+
platform: IapPlatform;
|
|
2081
|
+
/**
|
|
2082
|
+
* Price in micros (1/1,000,000 of the currency unit) at event time, when available.
|
|
2083
|
+
* Matches Google Play's `priceAmountMicros` convention; iOS values are converted.
|
|
2084
|
+
*/
|
|
2085
|
+
priceAmountMicros?: (number | null);
|
|
2086
|
+
/** Product the event pertains to. May be null for account-level events. */
|
|
2087
|
+
productId?: (string | null);
|
|
2088
|
+
/** kit project that owns the subscription / purchase this event refers to. */
|
|
2089
|
+
projectId: string;
|
|
2090
|
+
/**
|
|
2091
|
+
* Cross-platform purchase identity used to correlate this event with an existing
|
|
2092
|
+
* purchase record. iOS: `originalTransactionId`. Android: `purchaseToken`.
|
|
2093
|
+
* Null for `TestNotification` events (Apple ASN v2 / Google RTDN test
|
|
2094
|
+
* payloads carry no transaction); always present for every other event type.
|
|
2095
|
+
*/
|
|
2096
|
+
purchaseToken?: (string | null);
|
|
2097
|
+
/**
|
|
2098
|
+
* Original signed payload from the store. ASN v2 events expose the JWS string;
|
|
2099
|
+
* RTDN events expose the base64-decoded Pub/Sub message JSON. Provided so that
|
|
2100
|
+
* consumers can independently verify or extract platform-specific fields. kit
|
|
2101
|
+
* always validates this payload before emitting the event.
|
|
2102
|
+
*/
|
|
2103
|
+
rawSignedPayload?: (string | null);
|
|
2104
|
+
/** Time kit ingested and normalized this event. Epoch milliseconds. */
|
|
2105
|
+
receivedAt: number;
|
|
2106
|
+
/** When auto-renewal will charge again. Epoch milliseconds. */
|
|
2107
|
+
renewsAt?: (number | null);
|
|
2108
|
+
source: WebhookEventSource;
|
|
2109
|
+
/**
|
|
2110
|
+
* Normalized subscription state at the time of event, when the event refers to
|
|
2111
|
+
* a subscription. Null for one-time purchase events.
|
|
2112
|
+
*/
|
|
2113
|
+
subscriptionState?: (SubscriptionState | null);
|
|
2114
|
+
type: WebhookEventType;
|
|
2115
|
+
}
|
|
2116
|
+
|
|
2117
|
+
export type WebhookEventEnvironment = 'production' | 'sandbox' | 'xcode';
|
|
2118
|
+
|
|
2119
|
+
export type WebhookEventSource = 'apple-app-store-server-notifications-v2' | 'google-play-real-time-developer-notifications' | 'meta-horizon-reconciler';
|
|
2120
|
+
|
|
2121
|
+
export type WebhookEventType = 'purchase-consumption-request' | 'purchase-refunded' | 'subscription-canceled' | 'subscription-expired' | 'subscription-in-billing-retry' | 'subscription-in-grace-period' | 'subscription-paused' | 'subscription-price-change' | 'subscription-product-changed' | 'subscription-recovered' | 'subscription-renewed' | 'subscription-resumed' | 'subscription-revoked' | 'subscription-started' | 'subscription-uncanceled' | 'test-notification';
|
|
2122
|
+
|
|
1951
2123
|
/**
|
|
1952
2124
|
* Win-back offer input for iOS 18+ (StoreKit 2)
|
|
1953
2125
|
* Win-back offers are used to re-engage churned subscribers.
|
package/src/useIAP.ts
CHANGED
|
@@ -252,6 +252,30 @@ export function useIAP(options?: UseIAPOptions): UseIap {
|
|
|
252
252
|
}
|
|
253
253
|
}, []);
|
|
254
254
|
|
|
255
|
+
/**
|
|
256
|
+
* Retrieve products or subscriptions from the store by SKU.
|
|
257
|
+
*
|
|
258
|
+
* @param params `ProductRequest` — `skus` (string[]) and optional `type`
|
|
259
|
+
* (`'in-app' | 'subs' | 'all'`, defaults to `'in-app'`).
|
|
260
|
+
* @returns Promise that resolves when the request is dispatched; results land in the
|
|
261
|
+
* hook's reactive `products` / `subscriptions` state.
|
|
262
|
+
* @throws When the store rejects the request (empty `skus`, not connected,
|
|
263
|
+
* network/store error). Unknown SKUs are simply omitted from the result, not thrown.
|
|
264
|
+
*
|
|
265
|
+
* @example
|
|
266
|
+
* ```ts
|
|
267
|
+
* const { fetchProducts, products } = useIAP();
|
|
268
|
+
* await fetchProducts({
|
|
269
|
+
* skus: ['com.app.coins_100', 'com.app.premium'],
|
|
270
|
+
* type: 'in-app',
|
|
271
|
+
* });
|
|
272
|
+
* ```
|
|
273
|
+
*
|
|
274
|
+
* @remarks This is a regular promise-based call. Don't confuse with `request*` APIs
|
|
275
|
+
* (`requestPurchase`), which are event-based.
|
|
276
|
+
*
|
|
277
|
+
* @see {@link https://www.openiap.dev/docs/apis/fetch-products}
|
|
278
|
+
*/
|
|
255
279
|
const fetchProductsInternal = useCallback(
|
|
256
280
|
async (params: {
|
|
257
281
|
skus: string[];
|
|
@@ -349,6 +373,27 @@ export function useIAP(options?: UseIAPOptions): UseIap {
|
|
|
349
373
|
],
|
|
350
374
|
);
|
|
351
375
|
|
|
376
|
+
/**
|
|
377
|
+
* List the user's unfinished purchases — non-consumables, active subscriptions, and any
|
|
378
|
+
* pending transactions not yet finished.
|
|
379
|
+
*
|
|
380
|
+
* @param options Optional `PurchaseOptions`. iOS-only flags:
|
|
381
|
+
* `alsoPublishToEventListenerIOS`, `onlyIncludeActiveItemsIOS`.
|
|
382
|
+
* @returns Promise that resolves when the request is dispatched; results land in the
|
|
383
|
+
* hook's reactive `availablePurchases` state.
|
|
384
|
+
* @throws When the platform query fails.
|
|
385
|
+
*
|
|
386
|
+
* @example
|
|
387
|
+
* ```ts
|
|
388
|
+
* const { getAvailablePurchases, availablePurchases } = useIAP();
|
|
389
|
+
* await getAvailablePurchases();
|
|
390
|
+
* for (const p of availablePurchases) {
|
|
391
|
+
* if (await verifyOnServer(p)) await finishTransaction({ purchase: p, isConsumable: false });
|
|
392
|
+
* }
|
|
393
|
+
* ```
|
|
394
|
+
*
|
|
395
|
+
* @see {@link https://www.openiap.dev/docs/apis/get-available-purchases}
|
|
396
|
+
*/
|
|
352
397
|
const getAvailablePurchasesInternal = useCallback(
|
|
353
398
|
async (options?: PurchaseOptions): Promise<void> => {
|
|
354
399
|
try {
|
|
@@ -368,6 +413,11 @@ export function useIAP(options?: UseIAPOptions): UseIap {
|
|
|
368
413
|
[invokeOnError],
|
|
369
414
|
);
|
|
370
415
|
|
|
416
|
+
/**
|
|
417
|
+
* Get details of all currently active subscriptions.
|
|
418
|
+
*
|
|
419
|
+
* @see {@link https://www.openiap.dev/docs/apis/get-active-subscriptions}
|
|
420
|
+
*/
|
|
371
421
|
const getActiveSubscriptionsInternal = useCallback(
|
|
372
422
|
async (subscriptionIds?: string[]): Promise<void> => {
|
|
373
423
|
try {
|
|
@@ -382,6 +432,11 @@ export function useIAP(options?: UseIAPOptions): UseIap {
|
|
|
382
432
|
[invokeOnError],
|
|
383
433
|
);
|
|
384
434
|
|
|
435
|
+
/**
|
|
436
|
+
* Check whether the user has any active subscription.
|
|
437
|
+
*
|
|
438
|
+
* @see {@link https://www.openiap.dev/docs/apis/has-active-subscriptions}
|
|
439
|
+
*/
|
|
385
440
|
const hasActiveSubscriptionsInternal = useCallback(
|
|
386
441
|
async (subscriptionIds?: string[]): Promise<boolean> => {
|
|
387
442
|
try {
|
|
@@ -394,6 +449,29 @@ export function useIAP(options?: UseIAPOptions): UseIap {
|
|
|
394
449
|
[],
|
|
395
450
|
);
|
|
396
451
|
|
|
452
|
+
/**
|
|
453
|
+
* Complete a purchase transaction. Call after server-side verification to remove it
|
|
454
|
+
* from the queue.
|
|
455
|
+
*
|
|
456
|
+
* @param args.purchase The `Purchase` to finalize.
|
|
457
|
+
* @param args.isConsumable `true` for consumables (consumes the token so the SKU can be
|
|
458
|
+
* re-bought, e.g. coins); `false` (default) for non-consumables and subscriptions.
|
|
459
|
+
* @returns Promise that resolves once the platform finalizes the transaction.
|
|
460
|
+
* @throws When the platform finalize call fails.
|
|
461
|
+
*
|
|
462
|
+
* @example
|
|
463
|
+
* ```ts
|
|
464
|
+
* // Inside purchaseUpdatedListener:
|
|
465
|
+
* if (await verifyOnServer(purchase)) {
|
|
466
|
+
* await finishTransaction({ purchase, isConsumable: false });
|
|
467
|
+
* }
|
|
468
|
+
* ```
|
|
469
|
+
*
|
|
470
|
+
* @remarks **Critical:** Android purchases must be finalized within 3 days or Google
|
|
471
|
+
* auto-refunds. iOS unfinished transactions replay on every app launch.
|
|
472
|
+
*
|
|
473
|
+
* @see {@link https://www.openiap.dev/docs/apis/finish-transaction}
|
|
474
|
+
*/
|
|
397
475
|
const finishTransaction = useCallback(
|
|
398
476
|
async ({
|
|
399
477
|
purchase,
|
|
@@ -410,6 +488,33 @@ export function useIAP(options?: UseIAPOptions): UseIap {
|
|
|
410
488
|
[toPurchaseInput],
|
|
411
489
|
);
|
|
412
490
|
|
|
491
|
+
/**
|
|
492
|
+
* Initiate a purchase or subscription flow. The result is delivered through
|
|
493
|
+
* `purchaseUpdatedListener` — NOT the return value.
|
|
494
|
+
*
|
|
495
|
+
* @param props `RequestPurchaseProps`, discriminated by `type`:
|
|
496
|
+
* - `type: 'in-app'` — pass `request.apple.sku` (iOS) and/or `request.google.skus` (Android).
|
|
497
|
+
* - `type: 'subs'` — same shape, plus `request.google.subscriptionOffers: [{ sku, offerToken }]`.
|
|
498
|
+
* @returns Promise that resolves when the request is dispatched; the actual purchase
|
|
499
|
+
* outcome lands in the hook's `onPurchaseSuccess` / `onPurchaseError` callbacks.
|
|
500
|
+
* @throws Synchronous rejection from the store (e.g. `E_NOT_PREPARED`, validation failure).
|
|
501
|
+
*
|
|
502
|
+
* @example
|
|
503
|
+
* ```ts
|
|
504
|
+
* await requestPurchase({
|
|
505
|
+
* request: {
|
|
506
|
+
* apple: { sku: 'com.app.premium' },
|
|
507
|
+
* google: { skus: ['com.app.premium'] },
|
|
508
|
+
* },
|
|
509
|
+
* type: 'in-app',
|
|
510
|
+
* });
|
|
511
|
+
* ```
|
|
512
|
+
*
|
|
513
|
+
* @remarks Event-based. Listen for the result via {@link purchaseUpdatedListener} /
|
|
514
|
+
* {@link purchaseErrorListener}, or use `useIAP({ onPurchaseSuccess, onPurchaseError })`.
|
|
515
|
+
*
|
|
516
|
+
* @see {@link https://www.openiap.dev/docs/apis/request-purchase}
|
|
517
|
+
*/
|
|
413
518
|
const requestPurchaseWithReset = useCallback(
|
|
414
519
|
(requestObj: MutationRequestPurchaseArgs) => {
|
|
415
520
|
return requestPurchaseInternal(requestObj);
|
|
@@ -436,9 +541,11 @@ export function useIAP(options?: UseIAPOptions): UseIap {
|
|
|
436
541
|
],
|
|
437
542
|
);
|
|
438
543
|
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
544
|
+
/**
|
|
545
|
+
* Restore non-consumable and active subscription purchases.
|
|
546
|
+
*
|
|
547
|
+
* @see {@link https://www.openiap.dev/docs/apis/restore-purchases}
|
|
548
|
+
*/
|
|
442
549
|
const restorePurchasesInternal = useCallback(
|
|
443
550
|
async (options?: PurchaseOptions): Promise<void> => {
|
|
444
551
|
try {
|
|
@@ -463,14 +570,29 @@ export function useIAP(options?: UseIAPOptions): UseIap {
|
|
|
463
570
|
[invokeOnError],
|
|
464
571
|
);
|
|
465
572
|
|
|
573
|
+
/**
|
|
574
|
+
* Deprecated. Use verifyPurchase instead — same input/output shape.
|
|
575
|
+
*
|
|
576
|
+
* @see {@link https://www.openiap.dev/docs/apis/validate-receipt}
|
|
577
|
+
*/
|
|
466
578
|
const validateReceipt = useCallback(async (props: VerifyPurchaseProps) => {
|
|
467
579
|
return validateReceiptInternal(props);
|
|
468
580
|
}, []);
|
|
469
581
|
|
|
582
|
+
/**
|
|
583
|
+
* Verify a purchase against your own backend (returns isValid + raw store metadata).
|
|
584
|
+
*
|
|
585
|
+
* @see {@link https://www.openiap.dev/docs/features/validation#verify-purchase}
|
|
586
|
+
*/
|
|
470
587
|
const verifyPurchase = useCallback(async (props: VerifyPurchaseProps) => {
|
|
471
588
|
return verifyPurchaseInternal(props);
|
|
472
589
|
}, []);
|
|
473
590
|
|
|
591
|
+
/**
|
|
592
|
+
* Verify via a managed provider — currently only `iapkit` (IAPKit). The PurchaseVerificationProvider enum exposes no other provider literal today.
|
|
593
|
+
*
|
|
594
|
+
* @see {@link https://www.openiap.dev/docs/features/validation#verify-purchase-with-provider}
|
|
595
|
+
*/
|
|
474
596
|
const verifyPurchaseWithProvider = useCallback(
|
|
475
597
|
async (props: VerifyPurchaseWithProviderProps) => {
|
|
476
598
|
return verifyPurchaseWithProviderInternal(props);
|