react-native-iap 12.8.3 → 12.8.5

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.
Files changed (97) hide show
  1. package/android/build.gradle +1 -1
  2. package/ios/RNIapIos.swift +28 -31
  3. package/ios/RNIapIosSk2.swift +3 -3
  4. package/lib/commonjs/eventEmitter.js.map +1 -1
  5. package/lib/commonjs/hooks/index.js.map +1 -1
  6. package/lib/commonjs/hooks/useIAP.js.map +1 -1
  7. package/lib/commonjs/hooks/withIAPContext.js.map +1 -1
  8. package/lib/commonjs/iap.js.map +1 -1
  9. package/lib/commonjs/index.js.map +1 -1
  10. package/lib/commonjs/internal/enhancedFetch.js.map +1 -1
  11. package/lib/commonjs/internal/fillProductsWithAdditionalData.js.map +1 -1
  12. package/lib/commonjs/internal/index.js.map +1 -1
  13. package/lib/commonjs/internal/platform.js.map +1 -1
  14. package/lib/commonjs/modules/amazon.js.map +1 -1
  15. package/lib/commonjs/modules/android.js.map +1 -1
  16. package/lib/commonjs/modules/common.js.map +1 -1
  17. package/lib/commonjs/modules/index.js.map +1 -1
  18. package/lib/commonjs/modules/ios.js +27 -8
  19. package/lib/commonjs/modules/ios.js.map +1 -1
  20. package/lib/commonjs/modules/iosSk2.js.map +1 -1
  21. package/lib/commonjs/purchaseError.js.map +1 -1
  22. package/lib/commonjs/types/amazon.js.map +1 -1
  23. package/lib/commonjs/types/android.js.map +1 -1
  24. package/lib/commonjs/types/apple.js.map +1 -1
  25. package/lib/commonjs/types/appleSk2.js.map +1 -1
  26. package/lib/commonjs/types/index.js.map +1 -1
  27. package/lib/module/eventEmitter.js.map +1 -1
  28. package/lib/module/hooks/index.js.map +1 -1
  29. package/lib/module/hooks/useIAP.js.map +1 -1
  30. package/lib/module/hooks/withIAPContext.js.map +1 -1
  31. package/lib/module/iap.js.map +1 -1
  32. package/lib/module/index.js.map +1 -1
  33. package/lib/module/internal/enhancedFetch.js.map +1 -1
  34. package/lib/module/internal/fillProductsWithAdditionalData.js.map +1 -1
  35. package/lib/module/internal/index.js.map +1 -1
  36. package/lib/module/internal/platform.js.map +1 -1
  37. package/lib/module/modules/amazon.js.map +1 -1
  38. package/lib/module/modules/android.js.map +1 -1
  39. package/lib/module/modules/common.js.map +1 -1
  40. package/lib/module/modules/index.js.map +1 -1
  41. package/lib/module/modules/ios.js +27 -8
  42. package/lib/module/modules/ios.js.map +1 -1
  43. package/lib/module/modules/iosSk2.js.map +1 -1
  44. package/lib/module/purchaseError.js.map +1 -1
  45. package/lib/module/types/amazon.js.map +1 -1
  46. package/lib/module/types/android.js.map +1 -1
  47. package/lib/module/types/apple.js.map +1 -1
  48. package/lib/module/types/appleSk2.js.map +1 -1
  49. package/lib/module/types/index.js.map +1 -1
  50. package/lib/typescript/plugin/src/withIAP.d.ts +1 -0
  51. package/lib/typescript/plugin/src/withIAP.d.ts.map +1 -0
  52. package/lib/typescript/src/eventEmitter.d.ts +1 -0
  53. package/lib/typescript/src/eventEmitter.d.ts.map +1 -0
  54. package/lib/typescript/src/hooks/index.d.ts +1 -0
  55. package/lib/typescript/src/hooks/index.d.ts.map +1 -0
  56. package/lib/typescript/src/hooks/useIAP.d.ts +1 -0
  57. package/lib/typescript/src/hooks/useIAP.d.ts.map +1 -0
  58. package/lib/typescript/src/hooks/withIAPContext.d.ts +1 -0
  59. package/lib/typescript/src/hooks/withIAPContext.d.ts.map +1 -0
  60. package/lib/typescript/src/iap.d.ts +1 -0
  61. package/lib/typescript/src/iap.d.ts.map +1 -0
  62. package/lib/typescript/src/index.d.ts +1 -0
  63. package/lib/typescript/src/index.d.ts.map +1 -0
  64. package/lib/typescript/src/internal/enhancedFetch.d.ts +1 -1
  65. package/lib/typescript/src/internal/enhancedFetch.d.ts.map +1 -0
  66. package/lib/typescript/src/internal/fillProductsWithAdditionalData.d.ts +1 -0
  67. package/lib/typescript/src/internal/fillProductsWithAdditionalData.d.ts.map +1 -0
  68. package/lib/typescript/src/internal/index.d.ts +1 -0
  69. package/lib/typescript/src/internal/index.d.ts.map +1 -0
  70. package/lib/typescript/src/internal/platform.d.ts +1 -0
  71. package/lib/typescript/src/internal/platform.d.ts.map +1 -0
  72. package/lib/typescript/src/modules/amazon.d.ts +1 -0
  73. package/lib/typescript/src/modules/amazon.d.ts.map +1 -0
  74. package/lib/typescript/src/modules/android.d.ts +1 -0
  75. package/lib/typescript/src/modules/android.d.ts.map +1 -0
  76. package/lib/typescript/src/modules/common.d.ts +1 -0
  77. package/lib/typescript/src/modules/common.d.ts.map +1 -0
  78. package/lib/typescript/src/modules/index.d.ts +1 -0
  79. package/lib/typescript/src/modules/index.d.ts.map +1 -0
  80. package/lib/typescript/src/modules/ios.d.ts +30 -10
  81. package/lib/typescript/src/modules/ios.d.ts.map +1 -0
  82. package/lib/typescript/src/modules/iosSk2.d.ts +1 -0
  83. package/lib/typescript/src/modules/iosSk2.d.ts.map +1 -0
  84. package/lib/typescript/src/purchaseError.d.ts +1 -0
  85. package/lib/typescript/src/purchaseError.d.ts.map +1 -0
  86. package/lib/typescript/src/types/amazon.d.ts +1 -0
  87. package/lib/typescript/src/types/amazon.d.ts.map +1 -0
  88. package/lib/typescript/src/types/android.d.ts +1 -0
  89. package/lib/typescript/src/types/android.d.ts.map +1 -0
  90. package/lib/typescript/src/types/apple.d.ts +1 -0
  91. package/lib/typescript/src/types/apple.d.ts.map +1 -0
  92. package/lib/typescript/src/types/appleSk2.d.ts +1 -0
  93. package/lib/typescript/src/types/appleSk2.d.ts.map +1 -0
  94. package/lib/typescript/src/types/index.d.ts +1 -0
  95. package/lib/typescript/src/types/index.d.ts.map +1 -0
  96. package/package.json +20 -20
  97. package/src/modules/ios.ts +29 -10
@@ -32,7 +32,7 @@ type clearTransaction = () => Promise<void>;
32
32
  type clearProducts = () => Promise<void>;
33
33
  type promotedProduct = () => Promise<ProductIOS | null>;
34
34
  type buyPromotedProduct = () => Promise<void>;
35
- type requestReceipt = (refresh: boolean) => Promise<string>;
35
+ type requestReceipt = (refresh: boolean) => Promise<string | undefined | null>;
36
36
 
37
37
  type finishTransaction = (transactionIdentifier: string) => Promise<boolean>;
38
38
 
@@ -56,7 +56,6 @@ export interface IosModuleProps extends NativeModuleProps {
56
56
 
57
57
  /**
58
58
  * Get the current receipt base64 encoded in IOS.
59
- * @param {forceRefresh?:boolean}
60
59
  * @returns {Promise<ProductPurchase[]>}
61
60
  */
62
61
  export const getPendingPurchasesIOS = async (): Promise<ProductPurchase[]> =>
@@ -64,25 +63,45 @@ export const getPendingPurchasesIOS = async (): Promise<ProductPurchase[]> =>
64
63
 
65
64
  /**
66
65
  * Get the current receipt base64 encoded in IOS.
66
+ *
67
+ * The sequence should be as follows:
68
+ * Call getReceiptIOS({forceRefresh: false}). That will return the cached receipt that is available on TestFlight and Production.
69
+ * In the case of Sandbox the receipt might not be cached, causing it to return nil.
70
+ * In that case you might want to let the user that they will to be prompted for credentials.
71
+ * If they accept, call it again with `getReceiptIOS({forceRefresh:true}) If it fails or the user declines, assume they haven't purchased any items.
72
+ * Reference: https://developer.apple.com/forums/thread/662350
73
+ *
67
74
  * From: https://apphud.com/blog/app-store-receipt-validation#what-is-app-store-receipt
68
- > Does a receipt always exist in the app?
69
- > If a user downloaded the app from the App Store – yes. However, in sandbox if your app was installed via Xcode or Testflight, then there won't be a receipt until you make a purchase or restore.
75
+ > Q: Does a receipt always exist in the app?
76
+ > A: If a user downloaded the app from the App Store – yes. However, in sandbox if your app was installed via Xcode or Testflight, then there won't be a receipt until you make a purchase or restore.
70
77
  *
71
78
  ## Usage
72
79
  ```tsx
73
- import {useCallback} from 'react';
74
80
  import {getReceiptIOS} from 'react-native-iap';
75
-
76
- const receipt = useCallback(async () => await getReceiptIOS({forceRefresh: false}));
81
+ try{
82
+ let receipt = await getReceiptIOS({forceRefresh: false});
83
+ if(!receipt){
84
+ // Let user know that they might get prompted for credentials
85
+ const shouldShowPrompt = // Display UI with details, Did user agree?. this only for Sandbox testing
86
+ if(shouldShowPrompt){
87
+ receipt = await getReceiptIOS({forceRefresh: true});
88
+ }
89
+ }
90
+ }catch(error:Error){
91
+ // error while getting the receipt, it might indicate an invalid receipt of a connection error while trying to get it
92
+ }
93
+ // If !receipt assume user doesn't own the items
77
94
  ```
78
- * @param {forceRefresh?:boolean} Requests the receipt from Bundle.main.appStoreReceiptURL. Based on the note above, looks like forceRefresh only makes sense when testing an app not downloaded from the Appstore.
79
- * @returns {Promise<string>} The receipt data
95
+ * @param {forceRefresh?:boolean} Requests the receipt from Bundle.main.appStoreReceiptURL.
96
+ Based on the note above, looks like forceRefresh only makes sense when testing an app not downloaded from the Appstore.
97
+ And only afer a direct user action.
98
+ * @returns {Promise<string | undefined | null>} The receipt data
80
99
  */
81
100
  export const getReceiptIOS = async ({
82
101
  forceRefresh,
83
102
  }: {
84
103
  forceRefresh?: boolean;
85
- }): Promise<string> => {
104
+ }): Promise<string | undefined | null> => {
86
105
  if (!isIosStorekit2()) {
87
106
  return RNIapIos.requestReceipt(forceRefresh ?? false);
88
107
  } else {