react-native-iap 10.0.5 → 10.1.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.
Files changed (73) hide show
  1. package/README.md +28 -112
  2. package/android/src/amazon/java/com/dooboolab/RNIap/RNIapAmazonModule.kt +1 -2
  3. package/ios/RNIapIos.swift +9 -8
  4. package/lib/commonjs/eventEmitter.js +7 -4
  5. package/lib/commonjs/eventEmitter.js.map +1 -1
  6. package/lib/commonjs/hooks/index.js +19 -0
  7. package/lib/commonjs/hooks/index.js.map +1 -0
  8. package/lib/commonjs/hooks/useIAP.js +8 -4
  9. package/lib/commonjs/hooks/useIAP.js.map +1 -1
  10. package/lib/commonjs/iap.js +47 -23
  11. package/lib/commonjs/iap.js.map +1 -1
  12. package/lib/commonjs/modules/amazon.js +12 -0
  13. package/lib/commonjs/modules/amazon.js.map +1 -0
  14. package/lib/commonjs/modules/android.js +12 -0
  15. package/lib/commonjs/modules/android.js.map +1 -0
  16. package/lib/commonjs/modules/common.js +2 -0
  17. package/lib/commonjs/modules/common.js.map +1 -0
  18. package/lib/commonjs/modules/index.js +58 -0
  19. package/lib/commonjs/modules/index.js.map +1 -0
  20. package/lib/commonjs/modules/ios.js +6 -0
  21. package/lib/commonjs/modules/ios.js.map +1 -0
  22. package/lib/commonjs/types/amazon.js.map +1 -1
  23. package/lib/commonjs/types/apple.js +0 -163
  24. package/lib/commonjs/types/apple.js.map +1 -1
  25. package/lib/commonjs/types/index.js +11 -1
  26. package/lib/commonjs/types/index.js.map +1 -1
  27. package/lib/module/eventEmitter.js +8 -4
  28. package/lib/module/eventEmitter.js.map +1 -1
  29. package/lib/module/hooks/index.js +2 -0
  30. package/lib/module/hooks/index.js.map +1 -0
  31. package/lib/module/hooks/useIAP.js +6 -4
  32. package/lib/module/hooks/useIAP.js.map +1 -1
  33. package/lib/module/iap.js +48 -22
  34. package/lib/module/iap.js.map +1 -1
  35. package/lib/module/modules/amazon.js +3 -0
  36. package/lib/module/modules/amazon.js.map +1 -0
  37. package/lib/module/modules/android.js +3 -0
  38. package/lib/module/modules/android.js.map +1 -0
  39. package/lib/module/modules/common.js +2 -0
  40. package/lib/module/modules/common.js.map +1 -0
  41. package/lib/module/modules/index.js +5 -0
  42. package/lib/module/modules/index.js.map +1 -0
  43. package/lib/module/modules/ios.js +2 -0
  44. package/lib/module/modules/ios.js.map +1 -0
  45. package/lib/module/types/amazon.js.map +1 -1
  46. package/lib/module/types/apple.js +0 -151
  47. package/lib/module/types/apple.js.map +1 -1
  48. package/lib/module/types/index.js +9 -0
  49. package/lib/module/types/index.js.map +1 -1
  50. package/lib/typescript/hooks/index.d.ts +1 -0
  51. package/lib/typescript/hooks/useIAP.d.ts +6 -3
  52. package/lib/typescript/iap.d.ts +14 -13
  53. package/lib/typescript/modules/amazon.d.ts +23 -0
  54. package/lib/typescript/modules/android.d.ts +24 -0
  55. package/lib/typescript/modules/common.d.ts +13 -0
  56. package/lib/typescript/modules/index.d.ts +4 -0
  57. package/lib/typescript/modules/ios.d.ts +32 -0
  58. package/lib/typescript/types/amazon.d.ts +8 -0
  59. package/lib/typescript/types/apple.d.ts +0 -399
  60. package/lib/typescript/types/index.d.ts +19 -0
  61. package/package.json +3 -1
  62. package/src/eventEmitter.ts +7 -7
  63. package/src/hooks/index.ts +1 -0
  64. package/src/hooks/useIAP.ts +11 -5
  65. package/src/iap.ts +76 -41
  66. package/src/modules/amazon.ts +40 -0
  67. package/src/modules/android.ts +65 -0
  68. package/src/modules/common.ts +16 -0
  69. package/src/modules/index.ts +4 -0
  70. package/src/modules/ios.ts +57 -0
  71. package/src/types/amazon.ts +9 -0
  72. package/src/types/apple.ts +0 -438
  73. package/src/types/index.ts +29 -0
package/README.md CHANGED
@@ -1,23 +1,18 @@
1
- # ![image](https://user-images.githubusercontent.com/27461460/75094417-20321b00-55ce-11ea-8de7-a1df42a4b7df.png)
1
+ ![image](https://user-images.githubusercontent.com/27461460/75094417-20321b00-55ce-11ea-8de7-a1df42a4b7df.png)
2
+
3
+ ---
2
4
 
3
5
  [![Version](http://img.shields.io/npm/v/react-native-iap.svg?style=flat-square)](https://npmjs.org/package/react-native-iap)
4
6
  [![Next Version](https://img.shields.io/npm/v/react-native-iap/next)](https://npmjs.org/package/react-native-iap)
5
-
6
7
  [![Download](http://img.shields.io/npm/dm/react-native-iap.svg?style=flat-square)](https://npmjs.org/package/react-native-iap)
7
- [![CI](https://github.com/dooboolab/react-native-iap/actions/workflows/ci.yml/badge.svg)](https://github.com/dooboolab/react-native-iap/actions/workflows/ci.yml)
8
- [![document](https://github.com/dooboolab/react-native-iap/actions/workflows/deploy-documentation.yml/badge.svg)](https://github.com/dooboolab/react-native-iap/actions/workflows/deploy-documentation.yml)
9
- [![License](https://img.shields.io/npm/l/react-native-iap.svg)](https://npmjs.org/package/react-native-iap)
10
- [![Vulnerabilities](https://img.shields.io/snyk/vulnerabilities/github/dooboolab/react-native-iap.svg)](https://github.com/dooboolab/react-native-iap)
11
- [![Issue Opened](https://img.shields.io/opencollective/all/react-native-iap.svg)](https://opencollective.com/react-native-iap#backers)
12
- [![Issue Opened](https://img.shields.io/github/issues/dooboolab/react-native-iap.svg)](https://github.com/dooboolab/react-native-iap/issues)
13
- [![Issue Closed](https://img.shields.io/github/issues-closed/dooboolab/react-native-iap.svg)](https://github.com/dooboolab/react-native-iap/issues?q=is%3Aissue+is%3Aclosed)
14
- [![PR Opened](https://img.shields.io/github/issues-pr/dooboolab/react-native-iap.svg)](https://github.com/dooboolab/react-native-iap/pulls)
15
- [![PR Closed](https://img.shields.io/github/issues-pr-closed/dooboolab/react-native-iap.svg)](https://github.com/dooboolab/react-native-iap/pulls?q=is%3Apr+is%3Aclosed)
8
+ [![Backers and Sponsors](https://img.shields.io/opencollective/all/react-native-iap.svg)](https://opencollective.com/react-native-iap)
16
9
  [![FOSSA Status](https://app.fossa.com/api/projects/git%2Bgithub.com%2Fdooboolab%2Freact-native-iap.svg?type=shield)](https://app.fossa.com/projects/git%2Bgithub.com%2Fdooboolab%2Freact-native-iap?ref=badge_shield)
17
10
 
11
+ ---
12
+
18
13
  ## Documentation
19
14
 
20
- Published in [website](https://react-native-iap.dooboolab.com).
15
+ Read the [documentation](https://react-native-iap.dooboolab.com). See the [troubleshooting](https://react-native-iap.dooboolab.com/docs/guides/troubleshooting#common-issues) for the common issues to avoid.
21
16
 
22
17
  ## Our maintainers
23
18
 
@@ -54,109 +49,26 @@ Please [fund the project](https://opencollective.com/react-native-iap) if you ar
54
49
 
55
50
  - The sample code is out in [Sponsor page](https://github.com/hyochan/dooboolab.com/blob/main/src/components/pages/Sponsor.tsx) in [dooboolab.com](https://github.com/hyochan/dooboolab.com) repository which sadly is rejected by Apple because of lacking product features. I will work on another example project to support this module. More information in [#1241 commment](https://github.com/dooboolab/react-native-iap/issues/1241#issuecomment-798540785).
56
51
 
57
- ## Introduction
58
-
59
- This react-native module will help you access the In-app purchases capabilities of your phone on the `Android`, `iOS` platforms and the `Amazon` platform (Beta).
60
-
61
- **Keep in mind** `react-native-iap` will provide the basic features you need but is not a turnkey solution, implementing In-app purchases in your app will still require quite some work.<br/>
62
- Also, implementing the client side is only one side of the coin, you'll have to implement the server side to validate your receipts (which is probably the most time consuming part to do it correctly).
63
-
64
- If you're looking for a module going further than react-native-iap, we recommend using [react-native-iaphub](https://github.com/iaphub/react-native-iaphub) which is taking care of everything from the client side to the server side.
65
-
66
- ⚠️ Most of users experiencing issues are caused by:
67
-
68
- - A device simulator, use a real device for testing!
69
- - The sandbox environment of the project not being configured properly ([Configure android sandbox](https://www.iaphub.com/docs/set-up-android/configure-sandbox-testing), [Configure ios sandbox](https://www.iaphub.com/docs/set-up-ios/configure-sandbox-testing/))
70
- - An incorrect usage of the library
71
-
72
- ## Demo
73
-
74
- > ![demo.gif](https://user-images.githubusercontent.com/27461460/52619625-87aa8a80-2ee5-11e9-9aee-6691c34408f3.gif)
75
-
76
- <!-- Inline anchors -->
77
-
78
- [a-acknowledge-purchase-android]: #finishing-a-purchase
79
- [a-migration-guide]: #migration-guide
80
- [a-purchase-flow]: #new-purchase-flow
81
-
82
- <!-- Official Blog -->
83
-
84
- [blog-config-steps]: https://medium.com/p/121622d26b67
85
- [blog-v3-note]: https://medium.com/p/1259e0b0c017
86
-
87
- <!-- Internals -->
88
-
89
- [contribute]: https://github.com/dooboolab/react-native-iap/blob/main/CONTRIBUTING.md
90
- [example]: https://github.com/dooboolab/react-native-iap/tree/main/IapExample
91
- [issue-126-c1]: https://github.com/dooboolab/react-native-iap/issues/126#issuecomment-439084872
92
- [issue-174]: https://github.com/dooboolab/react-native-iap/issues/174
93
- [issue-203]: https://github.com/dooboolab/react-native-iap/issues/203
94
- [issue-237]: https://github.com/dooboolab/react-native-iap/issues/237
95
- [issue-256]: https://github.com/dooboolab/react-native-iap/issues/256
96
- [issue-263]: https://github.com/dooboolab/react-native-iap/issues/263
97
- [issue-283]: https://github.com/dooboolab/react-native-iap/issues/283
98
- [issue-307-c1]: https://github.com/dooboolab/react-native-iap/issues/307#issuecomment-447745027
99
- [issue-307]: https://github.com/dooboolab/react-native-iap/issues/307
100
- [open-collective-backer]: https://opencollective.com/react-native-iap#backer
101
- [open-collective-sponsor]: https://opencollective.com/react-native-iap#sponsor
102
- [open-collective]: https://opencollective.com/react-native-iap
103
- [readme-deprecated]: https://github.com/dooboolab/react-native-iap/blob/main/README_DEPRECATED.md
104
-
105
- <!-- Externals -->
106
-
107
- [android-acknowledge-purchase]: https://developer.android.com/reference/com/android/billingclient/api/BillingClient.html#acknowledgePurchase(com.android.billingclient.api.AcknowledgePurchaseParams,%20com.android.billingclient.api.AcknowledgePurchaseResponseListener) 'BillingClient#acknowledgePurchase()'
108
- [android-end-connection]: https://developer.android.com/reference/com/android/billingclient/api/BillingClient.html#endConnection() 'BillingClient#endConnection()'
109
- [android-iap-validation-guide]: https://developer.android.com/google/play/billing/billing_library_overview
110
- [android-migrate-androidx]: https://developer.android.com/jetpack/androidx/migrate
111
- [android-sku-details]: https://developer.android.com/reference/com/android/billingclient/api/SkuDetails
112
- [apple-iap-promoting]: https://developer.apple.com/app-store/promoting-in-app-purchases/
113
- [apple-iap-validation-guide]: https://developer.apple.com/library/content/releasenotes/General/ValidateAppStoreReceipt/Chapters/ValidateRemotely.html
114
- [apple-store-kit-flow]: https://forums.developer.apple.com/thread/6431#14831
115
- [google-api-nodejs-client]: https://github.com/googleapis/google-api-nodejs-client/
116
- [google-play-console]: https://play.google.com/apps/publish/
117
- [stackoverflow-android-iap-validation]: https://stackoverflow.com/questions/35127086
118
- [android-access-token-example-repo]: https://github.com/Bang9/android-get-access-token-example
119
-
120
- ## Quick News
52
+ ## Configuration of Play Store & App Store Connect
121
53
 
122
- - We had hard time supporting `react-native-iap` issues that did not provide working codes or any other examples. Therefore, we've decided to make an `example` app called [DoobooIAP](https://github.com/hyochan/DoobooIAP), which will contain all the features of `IAP`'s and willing to continuously improve to support real-life examples. [@Bang9](http://github.com/bang9) who had been helping many others for `react-native-iap`, is willing to support this repo so he will grant $300 of our income in `opencollective` as described in [#855](https://github.com/dooboolab/react-native-iap/issues/855) :tada:.
123
- - `react-native-iap@4.0.8` ~ `react-native-iap@4.1.0` is incompatible with `react-native <0.61`. This is fixed in `react-native-iap@4.1.1` and above.
124
- - `react-native-iap@4.0.0` has been released. You can see [#716](https://github.com/dooboolab/react-native-iap/pull/716) for updates.
125
- - In the past, `react-native-iap@^3.*` has been updated very promptly for migration issues.
126
- Don't get surprised too much on why it is bumping up version so quickly these days.
127
- 1. Migrated to new `AndroidX` APIs.
128
- 2. Migrated to new `Android` billing client which is `> 2.0.0`.
129
- - [`acknowledgePurchase()`][android-acknowledge-purchase] has been added since `3.2.0` which is very important.
130
- 3. New [Purchase Flow][a-purchase-flow]
131
- 4. More is coming in `iOS 13`.
54
+ - Please refer to this [Blog post](https://medium.com/p/121622d26b67).
132
55
 
133
- ## Breaking Changes
134
-
135
- [7.4.0]
136
-
137
- - Now using React's Context to manage IAP state
138
- - Introduce `withIAPContext` HOC ([how to use](docs/docs/usage_instructions/using_hooks.md))
139
-
140
- [7.1.0]
56
+ ## Example
141
57
 
142
- - `androidOldSku` is no longer required [#1438](https://github.com/dooboolab/react-native-iap/pull/1438).
58
+ Follow [this guide](./IapExample/README.md) to get the example running.
143
59
 
144
- [6.1.0]
60
+ ## Our maintainers
145
61
 
146
- - Creates two variants: `play` and `amazon` and only uses the required code.
147
- ```
148
- NOTE: This would be a breaking change with a very simple fix described in the documentation. To add: `missingDimensionStrategy 'store', 'play'` `in build.gradle`
149
- ```
150
- [3.0.0+]
151
- [react-native-iap V3 note][blog-v3-note]
62
+ Please [fund the project](https://opencollective.com/react-native-iap) if you are willing the maintainers to make the repository sustainable.
152
63
 
153
- ## Configuration of Google Play & iTunes Connect
64
+ - [andresesfm](https://github.com/andresesfm)
65
+ - [jeremybarbet](https://github.com/jeremybarbet)
154
66
 
155
- - Please refer to [Blog][blog-config-steps].
67
+ > The fund goes to maintainers.
156
68
 
157
- ## Example
69
+ ## Acknowledgements
158
70
 
159
- Follow [this guide](./IapExample/README.md) to get the example running.
71
+ If you're looking for a module going further than `react-native-iap`, we recommend using [react-native-iaphub](https://github.com/iaphub/react-native-iaphub) which is taking care of everything from the client-side to the server-side.
160
72
 
161
73
  ## Sponsoring
162
74
 
@@ -164,24 +76,28 @@ Since `IAP` itself is not perfect on each platform, we desperately need
164
76
  this project to be maintained. If you'd like to help us, please consider being
165
77
  with us in [Open Collective](https://opencollective.com/react-native-iap).
166
78
 
79
+ ### Supporter
80
+
81
+ - [hyochan](https://github.com/hyochan)
82
+
167
83
  ### Sponsors
168
84
 
169
85
  Support this project by becoming a sponsor. Your logo will show up here with
170
- a link to your website. [Become a sponsor][open-collective-sponsor].
171
- <a href="https://opencollective.com/react-native-iap#sponsors" target="_blank"><img src="https://opencollective.com/react-native-iap/sponsors.svg?width=890"></a>
86
+ a link to your website. [Become a sponsor](https://opencollective.com/react-native-iap#sponsor).
87
+ <a href="https://opencollective.com/react-native-iap#sponsors" target="_blank"><img src="https://opencollective.com/react-native-iap/sponsors.svg?width=890" /></a>
172
88
 
173
89
  ### Backers
174
90
 
175
- Please be our [Backers][open-collective-backer].
176
- <a href="https://opencollective.com/react-native-iap#backers" target="_blank"><img src="https://opencollective.com/react-native-iap/backers.svg?width=890"></a>
91
+ Please be our [Backers](https://opencollective.com/react-native-iap#backer).
92
+ <a href="https://opencollective.com/react-native-iap#backers" target="_blank"><img src="https://opencollective.com/react-native-iap/backers.svg?width=890" /></a>
177
93
 
178
94
  ### Contributing
179
95
 
180
- Please make sure to read the [Contributing Guide][contribute] before making a pull request.
96
+ Please make sure to read the [Contributing Guide](https://github.com/dooboolab/react-native-iap/blob/main/CONTRIBUTING.md) before making a pull request.
181
97
  Thank you to all the people who helped to maintain and upgrade this project!
182
98
 
183
99
  <a href="graphs/contributors"><img src="https://opencollective.com/react-native-iap/contributors.svg?width=890" /></a>
184
100
 
185
- <hr>
101
+ ---
186
102
 
187
103
  [![FOSSA Status](https://app.fossa.com/api/projects/git%2Bgithub.com%2Fdooboolab%2Freact-native-iap.svg?type=large)](https://app.fossa.com/projects/git%2Bgithub.com%2Fdooboolab%2Freact-native-iap?ref=badge_large)
@@ -50,8 +50,7 @@ class RNIapAmazonModule(reactContext: ReactApplicationContext) :
50
50
  @ReactMethod
51
51
  fun flushFailedPurchasesCachedAsPending(promise: Promise) {
52
52
  // No-op
53
- val items = WritableNativeArray()
54
- promise.resolve(items)
53
+ promise.resolve(true)
55
54
  }
56
55
 
57
56
  @ReactMethod
@@ -311,6 +311,7 @@ class RNIapIos: RCTEventEmitter, SKRequestDelegate, SKPaymentTransactionObserver
311
311
  }
312
312
  }
313
313
  if let prod = product {
314
+ addPromise(forKey: prod.productIdentifier, resolve: resolve, reject: reject)
314
315
  let payment = SKMutablePayment(product: prod)
315
316
  payment.quantity = quantity
316
317
  SKPaymentQueue.default().add(payment)
@@ -733,15 +734,15 @@ class RNIapIos: RCTEventEmitter, SKRequestDelegate, SKPaymentTransactionObserver
733
734
  switch product.introductoryPrice?.paymentMode {
734
735
  case .freeTrial:
735
736
  introductoryPricePaymentMode = "FREETRIAL"
736
- introductoryPriceNumberOfPeriods = NSNumber(value: product.introductoryPrice?.subscriptionPeriod.numberOfUnits ?? 0).stringValue
737
+ introductoryPriceNumberOfPeriods = String( product.introductoryPrice?.subscriptionPeriod.numberOfUnits ?? 0)
737
738
 
738
739
  case .payAsYouGo:
739
740
  introductoryPricePaymentMode = "PAYASYOUGO"
740
- introductoryPriceNumberOfPeriods = NSNumber(value: product.introductoryPrice?.numberOfPeriods ?? 0).stringValue
741
+ introductoryPriceNumberOfPeriods = String( product.introductoryPrice?.numberOfPeriods ?? 0)
741
742
 
742
743
  case .payUpFront:
743
744
  introductoryPricePaymentMode = "PAYUPFRONT"
744
- introductoryPriceNumberOfPeriods = NSNumber(value: product.introductoryPrice?.subscriptionPeriod.numberOfUnits ?? 0).stringValue
745
+ introductoryPriceNumberOfPeriods = String( product.introductoryPrice?.subscriptionPeriod.numberOfUnits ?? 0)
745
746
 
746
747
  default:
747
748
  introductoryPricePaymentMode = ""
@@ -818,8 +819,8 @@ class RNIapIos: RCTEventEmitter, SKRequestDelegate, SKPaymentTransactionObserver
818
819
  let formatter = NumberFormatter()
819
820
  formatter.numberStyle = .currency
820
821
  let priceLocale: Locale? = discount.priceLocale
821
- if let pLocale = priceLocale {
822
- formatter.locale = pLocale
822
+ if let priceLocale = priceLocale {
823
+ formatter.locale = priceLocale
823
824
  }
824
825
  localizedPrice = formatter.string(from: discount.price)
825
826
  var numberOfPeriods: String?
@@ -827,17 +828,17 @@ class RNIapIos: RCTEventEmitter, SKRequestDelegate, SKPaymentTransactionObserver
827
828
  switch discount.paymentMode {
828
829
  case .freeTrial:
829
830
  paymendMode = "FREETRIAL"
830
- numberOfPeriods = NSNumber(value: discount.subscriptionPeriod.numberOfUnits ).stringValue
831
+ numberOfPeriods = String(discount.subscriptionPeriod.numberOfUnits)
831
832
  break
832
833
 
833
834
  case .payAsYouGo:
834
835
  paymendMode = "PAYASYOUGO"
835
- numberOfPeriods = NSNumber(value: discount.numberOfPeriods).stringValue
836
+ numberOfPeriods = String(discount.numberOfPeriods)
836
837
  break
837
838
 
838
839
  case .payUpFront:
839
840
  paymendMode = "PAYUPFRONT"
840
- numberOfPeriods = NSNumber(value: discount.subscriptionPeriod.numberOfUnits ).stringValue
841
+ numberOfPeriods = String(discount.subscriptionPeriod.numberOfUnits )
841
842
  break
842
843
 
843
844
  default:
@@ -11,12 +11,11 @@ var _iap = require("./iap");
11
11
 
12
12
  var _internal = require("./internal");
13
13
 
14
- const eventEmitter = new _reactNative.NativeEventEmitter((0, _iap.getNativeModule)());
15
14
  /**
16
15
  * Add IAP purchase event
17
16
  */
18
-
19
17
  const purchaseUpdatedListener = listener => {
18
+ const eventEmitter = new _reactNative.NativeEventEmitter((0, _iap.getNativeModule)());
20
19
  const emitterSubscription = eventEmitter.addListener('purchase-updated', listener);
21
20
 
22
21
  if (_internal.isAndroid) {
@@ -32,7 +31,10 @@ const purchaseUpdatedListener = listener => {
32
31
 
33
32
  exports.purchaseUpdatedListener = purchaseUpdatedListener;
34
33
 
35
- const purchaseErrorListener = listener => eventEmitter.addListener('purchase-error', listener);
34
+ const purchaseErrorListener = listener => {
35
+ const eventEmitter = new _reactNative.NativeEventEmitter((0, _iap.getNativeModule)());
36
+ return eventEmitter.addListener('purchase-error', listener);
37
+ };
36
38
  /**
37
39
  * Add IAP promoted subscription event
38
40
  *
@@ -44,7 +46,8 @@ exports.purchaseErrorListener = purchaseErrorListener;
44
46
 
45
47
  const promotedProductListener = listener => {
46
48
  if (_internal.isIos) {
47
- return new _reactNative.NativeEventEmitter((0, _iap.getIosModule)()).addListener('iap-promoted-product', listener);
49
+ const eventEmitter = new _reactNative.NativeEventEmitter((0, _iap.getIosModule)());
50
+ return eventEmitter.addListener('iap-promoted-product', listener);
48
51
  }
49
52
 
50
53
  return null;
@@ -1 +1 @@
1
- {"version":3,"names":["eventEmitter","NativeEventEmitter","getNativeModule","purchaseUpdatedListener","listener","emitterSubscription","addListener","isAndroid","getAndroidModule","startListening","purchaseErrorListener","promotedProductListener","isIos","getIosModule"],"sources":["eventEmitter.ts"],"sourcesContent":["import {EmitterSubscription, NativeEventEmitter} from 'react-native';\n\nimport {getAndroidModule, getIosModule, getNativeModule} from './iap';\nimport {isAndroid, isIos} from './internal';\nimport type {PurchaseError} from './purchaseError';\nimport type {Purchase} from './types';\n\nconst eventEmitter = new NativeEventEmitter(getNativeModule());\n\n/**\n * Add IAP purchase event\n */\nexport const purchaseUpdatedListener = (\n listener: (event: Purchase) => void,\n) => {\n const emitterSubscription = eventEmitter.addListener(\n 'purchase-updated',\n listener,\n );\n\n if (isAndroid) {\n getAndroidModule().startListening();\n }\n\n return emitterSubscription;\n};\n\n/**\n * Add IAP purchase error event\n */\nexport const purchaseErrorListener = (\n listener: (error: PurchaseError) => void,\n): EmitterSubscription => eventEmitter.addListener('purchase-error', listener);\n\n/**\n * Add IAP promoted subscription event\n *\n * @platform iOS\n */\nexport const promotedProductListener = (listener: () => void) => {\n if (isIos) {\n return new NativeEventEmitter(getIosModule()).addListener(\n 'iap-promoted-product',\n listener,\n );\n }\n\n return null;\n};\n"],"mappings":";;;;;;;AAAA;;AAEA;;AACA;;AAIA,MAAMA,YAAY,GAAG,IAAIC,+BAAJ,CAAuB,IAAAC,oBAAA,GAAvB,CAArB;AAEA;AACA;AACA;;AACO,MAAMC,uBAAuB,GAClCC,QADqC,IAElC;EACH,MAAMC,mBAAmB,GAAGL,YAAY,CAACM,WAAb,CAC1B,kBAD0B,EAE1BF,QAF0B,CAA5B;;EAKA,IAAIG,mBAAJ,EAAe;IACb,IAAAC,qBAAA,IAAmBC,cAAnB;EACD;;EAED,OAAOJ,mBAAP;AACD,CAbM;AAeP;AACA;AACA;;;;;AACO,MAAMK,qBAAqB,GAChCN,QADmC,IAEXJ,YAAY,CAACM,WAAb,CAAyB,gBAAzB,EAA2CF,QAA3C,CAFnB;AAIP;AACA;AACA;AACA;AACA;;;;;AACO,MAAMO,uBAAuB,GAAIP,QAAD,IAA0B;EAC/D,IAAIQ,eAAJ,EAAW;IACT,OAAO,IAAIX,+BAAJ,CAAuB,IAAAY,iBAAA,GAAvB,EAAuCP,WAAvC,CACL,sBADK,EAELF,QAFK,CAAP;EAID;;EAED,OAAO,IAAP;AACD,CATM"}
1
+ {"version":3,"names":["purchaseUpdatedListener","listener","eventEmitter","NativeEventEmitter","getNativeModule","emitterSubscription","addListener","isAndroid","getAndroidModule","startListening","purchaseErrorListener","promotedProductListener","isIos","getIosModule"],"sources":["eventEmitter.ts"],"sourcesContent":["import {EmitterSubscription, NativeEventEmitter} from 'react-native';\n\nimport {getAndroidModule, getIosModule, getNativeModule} from './iap';\nimport {isAndroid, isIos} from './internal';\nimport type {PurchaseError} from './purchaseError';\nimport type {Purchase} from './types';\n\n/**\n * Add IAP purchase event\n */\nexport const purchaseUpdatedListener = (\n listener: (event: Purchase) => void,\n) => {\n const eventEmitter = new NativeEventEmitter(getNativeModule());\n const emitterSubscription = eventEmitter.addListener(\n 'purchase-updated',\n listener,\n );\n\n if (isAndroid) {\n getAndroidModule().startListening();\n }\n\n return emitterSubscription;\n};\n\n/**\n * Add IAP purchase error event\n */\nexport const purchaseErrorListener = (\n listener: (error: PurchaseError) => void,\n): EmitterSubscription => {\n const eventEmitter = new NativeEventEmitter(getNativeModule());\n return eventEmitter.addListener('purchase-error', listener);\n};\n\n/**\n * Add IAP promoted subscription event\n *\n * @platform iOS\n */\nexport const promotedProductListener = (listener: () => void) => {\n if (isIos) {\n const eventEmitter = new NativeEventEmitter(getIosModule());\n return eventEmitter.addListener('iap-promoted-product', listener);\n }\n\n return null;\n};\n"],"mappings":";;;;;;;AAAA;;AAEA;;AACA;;AAIA;AACA;AACA;AACO,MAAMA,uBAAuB,GAClCC,QADqC,IAElC;EACH,MAAMC,YAAY,GAAG,IAAIC,+BAAJ,CAAuB,IAAAC,oBAAA,GAAvB,CAArB;EACA,MAAMC,mBAAmB,GAAGH,YAAY,CAACI,WAAb,CAC1B,kBAD0B,EAE1BL,QAF0B,CAA5B;;EAKA,IAAIM,mBAAJ,EAAe;IACb,IAAAC,qBAAA,IAAmBC,cAAnB;EACD;;EAED,OAAOJ,mBAAP;AACD,CAdM;AAgBP;AACA;AACA;;;;;AACO,MAAMK,qBAAqB,GAChCT,QADmC,IAEX;EACxB,MAAMC,YAAY,GAAG,IAAIC,+BAAJ,CAAuB,IAAAC,oBAAA,GAAvB,CAArB;EACA,OAAOF,YAAY,CAACI,WAAb,CAAyB,gBAAzB,EAA2CL,QAA3C,CAAP;AACD,CALM;AAOP;AACA;AACA;AACA;AACA;;;;;AACO,MAAMU,uBAAuB,GAAIV,QAAD,IAA0B;EAC/D,IAAIW,eAAJ,EAAW;IACT,MAAMV,YAAY,GAAG,IAAIC,+BAAJ,CAAuB,IAAAU,iBAAA,GAAvB,CAArB;IACA,OAAOX,YAAY,CAACI,WAAb,CAAyB,sBAAzB,EAAiDL,QAAjD,CAAP;EACD;;EAED,OAAO,IAAP;AACD,CAPM"}
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+
7
+ var _useIAP = require("./useIAP");
8
+
9
+ Object.keys(_useIAP).forEach(function (key) {
10
+ if (key === "default" || key === "__esModule") return;
11
+ if (key in exports && exports[key] === _useIAP[key]) return;
12
+ Object.defineProperty(exports, key, {
13
+ enumerable: true,
14
+ get: function () {
15
+ return _useIAP[key];
16
+ }
17
+ });
18
+ });
19
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":[],"sources":["index.ts"],"sourcesContent":["export * from './useIAP';\n"],"mappings":";;;;;;AAAA;;AAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA"}
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.useIAP = useIAP;
6
+ exports.useIAP = void 0;
7
7
 
8
8
  var _react = require("react");
9
9
 
@@ -11,7 +11,7 @@ var _iap = require("../iap");
11
11
 
12
12
  var _withIAPContext = require("./withIAPContext");
13
13
 
14
- function useIAP() {
14
+ const useIAP = () => {
15
15
  const {
16
16
  connected,
17
17
  products,
@@ -90,7 +90,11 @@ function useIAP() {
90
90
  getProducts,
91
91
  getSubscriptions,
92
92
  getAvailablePurchases,
93
- getPurchaseHistory
93
+ getPurchaseHistory,
94
+ requestPurchase: _iap.requestPurchase,
95
+ requestSubscription: _iap.requestSubscription
94
96
  };
95
- }
97
+ };
98
+
99
+ exports.useIAP = useIAP;
96
100
  //# sourceMappingURL=useIAP.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["useIAP","connected","products","promotedProductsIOS","subscriptions","purchaseHistory","availablePurchases","currentPurchase","currentPurchaseError","initConnectionError","setProducts","setSubscriptions","setAvailablePurchases","setPurchaseHistory","setCurrentPurchase","setCurrentPurchaseError","useIAPContext","getProducts","useCallback","skus","iapGetProducts","getSubscriptions","iapGetSubscriptions","getAvailablePurchases","iapGetAvailablePurchases","getPurchaseHistory","iapGetPurchaseHistory","finishTransaction","purchase","isConsumable","developerPayloadAndroid","iapFinishTransaction","err","productId","undefined"],"sources":["useIAP.ts"],"sourcesContent":["import {useCallback} from 'react';\n\nimport {\n finishTransaction as iapFinishTransaction,\n getAvailablePurchases as iapGetAvailablePurchases,\n getProducts as iapGetProducts,\n getPurchaseHistory as iapGetPurchaseHistory,\n getSubscriptions as iapGetSubscriptions,\n} from '../iap';\nimport type {PurchaseError} from '../purchaseError';\nimport type {Product, Purchase, Subscription} from '../types';\n\nimport {useIAPContext} from './withIAPContext';\n\ntype IAP_STATUS = {\n connected: boolean;\n products: Product[];\n promotedProductsIOS: Product[];\n subscriptions: Subscription[];\n purchaseHistory: Purchase[];\n availablePurchases: Purchase[];\n currentPurchase?: Purchase;\n currentPurchaseError?: PurchaseError;\n initConnectionError?: Error;\n finishTransaction: ({\n purchase,\n isConsumable,\n developerPayloadAndroid,\n }: {\n purchase: Purchase;\n isConsumable?: boolean;\n developerPayloadAndroid?: string;\n }) => Promise<string | void>;\n getAvailablePurchases: () => Promise<void>;\n getPurchaseHistory: () => Promise<void>;\n getProducts: ({skus}: {skus: string[]}) => Promise<void>;\n getSubscriptions: ({skus}: {skus: string[]}) => Promise<void>;\n};\n\nexport function useIAP(): IAP_STATUS {\n const {\n connected,\n products,\n promotedProductsIOS,\n subscriptions,\n purchaseHistory,\n availablePurchases,\n currentPurchase,\n currentPurchaseError,\n initConnectionError,\n setProducts,\n setSubscriptions,\n setAvailablePurchases,\n setPurchaseHistory,\n setCurrentPurchase,\n setCurrentPurchaseError,\n } = useIAPContext();\n\n const getProducts = useCallback(\n async ({skus}: {skus: string[]}): Promise<void> => {\n setProducts(await iapGetProducts({skus}));\n },\n [setProducts],\n );\n\n const getSubscriptions = useCallback(\n async ({skus}: {skus: string[]}): Promise<void> => {\n setSubscriptions(await iapGetSubscriptions({skus}));\n },\n [setSubscriptions],\n );\n\n const getAvailablePurchases = useCallback(async (): Promise<void> => {\n setAvailablePurchases(await iapGetAvailablePurchases());\n }, [setAvailablePurchases]);\n\n const getPurchaseHistory = useCallback(async (): Promise<void> => {\n setPurchaseHistory(await iapGetPurchaseHistory());\n }, [setPurchaseHistory]);\n\n const finishTransaction = useCallback(\n async ({\n purchase,\n isConsumable,\n developerPayloadAndroid,\n }: {\n purchase: Purchase;\n isConsumable?: boolean;\n developerPayloadAndroid?: string;\n }): Promise<string | void> => {\n try {\n return await iapFinishTransaction({\n purchase,\n isConsumable,\n developerPayloadAndroid,\n });\n } catch (err) {\n throw err;\n } finally {\n if (purchase.productId === currentPurchase?.productId) {\n setCurrentPurchase(undefined);\n }\n\n if (purchase.productId === currentPurchaseError?.productId) {\n setCurrentPurchaseError(undefined);\n }\n }\n },\n [\n currentPurchase?.productId,\n currentPurchaseError?.productId,\n setCurrentPurchase,\n setCurrentPurchaseError,\n ],\n );\n\n return {\n connected,\n products,\n promotedProductsIOS,\n subscriptions,\n purchaseHistory,\n availablePurchases,\n currentPurchase,\n currentPurchaseError,\n initConnectionError,\n finishTransaction,\n getProducts,\n getSubscriptions,\n getAvailablePurchases,\n getPurchaseHistory,\n };\n}\n"],"mappings":";;;;;;;AAAA;;AAEA;;AAUA;;AA2BO,SAASA,MAAT,GAA8B;EACnC,MAAM;IACJC,SADI;IAEJC,QAFI;IAGJC,mBAHI;IAIJC,aAJI;IAKJC,eALI;IAMJC,kBANI;IAOJC,eAPI;IAQJC,oBARI;IASJC,mBATI;IAUJC,WAVI;IAWJC,gBAXI;IAYJC,qBAZI;IAaJC,kBAbI;IAcJC,kBAdI;IAeJC;EAfI,IAgBF,IAAAC,6BAAA,GAhBJ;EAkBA,MAAMC,WAAW,GAAG,IAAAC,kBAAA,EAClB,cAAmD;IAAA,IAA5C;MAACC;IAAD,CAA4C;IACjDT,WAAW,CAAC,MAAM,IAAAU,gBAAA,EAAe;MAACD;IAAD,CAAf,CAAP,CAAX;EACD,CAHiB,EAIlB,CAACT,WAAD,CAJkB,CAApB;EAOA,MAAMW,gBAAgB,GAAG,IAAAH,kBAAA,EACvB,eAAmD;IAAA,IAA5C;MAACC;IAAD,CAA4C;IACjDR,gBAAgB,CAAC,MAAM,IAAAW,qBAAA,EAAoB;MAACH;IAAD,CAApB,CAAP,CAAhB;EACD,CAHsB,EAIvB,CAACR,gBAAD,CAJuB,CAAzB;EAOA,MAAMY,qBAAqB,GAAG,IAAAL,kBAAA,EAAY,YAA2B;IACnEN,qBAAqB,CAAC,MAAM,IAAAY,0BAAA,GAAP,CAArB;EACD,CAF6B,EAE3B,CAACZ,qBAAD,CAF2B,CAA9B;EAIA,MAAMa,kBAAkB,GAAG,IAAAP,kBAAA,EAAY,YAA2B;IAChEL,kBAAkB,CAAC,MAAM,IAAAa,uBAAA,GAAP,CAAlB;EACD,CAF0B,EAExB,CAACb,kBAAD,CAFwB,CAA3B;EAIA,MAAMc,iBAAiB,GAAG,IAAAT,kBAAA,EACxB,eAQ8B;IAAA,IARvB;MACLU,QADK;MAELC,YAFK;MAGLC;IAHK,CAQuB;;IAC5B,IAAI;MACF,OAAO,MAAM,IAAAC,sBAAA,EAAqB;QAChCH,QADgC;QAEhCC,YAFgC;QAGhCC;MAHgC,CAArB,CAAb;IAKD,CAND,CAME,OAAOE,GAAP,EAAY;MACZ,MAAMA,GAAN;IACD,CARD,SAQU;MACR,IAAIJ,QAAQ,CAACK,SAAT,MAAuB1B,eAAvB,aAAuBA,eAAvB,uBAAuBA,eAAe,CAAE0B,SAAxC,CAAJ,EAAuD;QACrDnB,kBAAkB,CAACoB,SAAD,CAAlB;MACD;;MAED,IAAIN,QAAQ,CAACK,SAAT,MAAuBzB,oBAAvB,aAAuBA,oBAAvB,uBAAuBA,oBAAoB,CAAEyB,SAA7C,CAAJ,EAA4D;QAC1DlB,uBAAuB,CAACmB,SAAD,CAAvB;MACD;IACF;EACF,CA3BuB,EA4BxB,CACE3B,eADF,aACEA,eADF,uBACEA,eAAe,CAAE0B,SADnB,EAEEzB,oBAFF,aAEEA,oBAFF,uBAEEA,oBAAoB,CAAEyB,SAFxB,EAGEnB,kBAHF,EAIEC,uBAJF,CA5BwB,CAA1B;EAoCA,OAAO;IACLd,SADK;IAELC,QAFK;IAGLC,mBAHK;IAILC,aAJK;IAKLC,eALK;IAMLC,kBANK;IAOLC,eAPK;IAQLC,oBARK;IASLC,mBATK;IAULkB,iBAVK;IAWLV,WAXK;IAYLI,gBAZK;IAaLE,qBAbK;IAcLE;EAdK,CAAP;AAgBD"}
1
+ {"version":3,"names":["useIAP","connected","products","promotedProductsIOS","subscriptions","purchaseHistory","availablePurchases","currentPurchase","currentPurchaseError","initConnectionError","setProducts","setSubscriptions","setAvailablePurchases","setPurchaseHistory","setCurrentPurchase","setCurrentPurchaseError","useIAPContext","getProducts","useCallback","skus","iapGetProducts","getSubscriptions","iapGetSubscriptions","getAvailablePurchases","iapGetAvailablePurchases","getPurchaseHistory","iapGetPurchaseHistory","finishTransaction","purchase","isConsumable","developerPayloadAndroid","iapFinishTransaction","err","productId","undefined","requestPurchase","iapRequestPurchase","requestSubscription","iapRequestSubscription"],"sources":["useIAP.ts"],"sourcesContent":["import {useCallback} from 'react';\n\nimport {\n finishTransaction as iapFinishTransaction,\n getAvailablePurchases as iapGetAvailablePurchases,\n getProducts as iapGetProducts,\n getPurchaseHistory as iapGetPurchaseHistory,\n getSubscriptions as iapGetSubscriptions,\n requestPurchase as iapRequestPurchase,\n requestSubscription as iapRequestSubscription,\n} from '../iap';\nimport type {PurchaseError} from '../purchaseError';\nimport type {Product, Purchase, PurchaseResult, Subscription} from '../types';\n\nimport {useIAPContext} from './withIAPContext';\n\ntype IAP_STATUS = {\n connected: boolean;\n products: Product[];\n promotedProductsIOS: Product[];\n subscriptions: Subscription[];\n purchaseHistory: Purchase[];\n availablePurchases: Purchase[];\n currentPurchase?: Purchase;\n currentPurchaseError?: PurchaseError;\n initConnectionError?: Error;\n finishTransaction: ({\n purchase,\n isConsumable,\n developerPayloadAndroid,\n }: {\n purchase: Purchase;\n isConsumable?: boolean;\n developerPayloadAndroid?: string;\n }) => Promise<string | boolean | PurchaseResult | void>;\n getAvailablePurchases: () => Promise<void>;\n getPurchaseHistory: () => Promise<void>;\n getProducts: ({skus}: {skus: string[]}) => Promise<void>;\n getSubscriptions: ({skus}: {skus: string[]}) => Promise<void>;\n requestPurchase: typeof iapRequestPurchase;\n requestSubscription: typeof iapRequestSubscription;\n};\n\nexport const useIAP = (): IAP_STATUS => {\n const {\n connected,\n products,\n promotedProductsIOS,\n subscriptions,\n purchaseHistory,\n availablePurchases,\n currentPurchase,\n currentPurchaseError,\n initConnectionError,\n setProducts,\n setSubscriptions,\n setAvailablePurchases,\n setPurchaseHistory,\n setCurrentPurchase,\n setCurrentPurchaseError,\n } = useIAPContext();\n\n const getProducts = useCallback(\n async ({skus}: {skus: string[]}): Promise<void> => {\n setProducts(await iapGetProducts({skus}));\n },\n [setProducts],\n );\n\n const getSubscriptions = useCallback(\n async ({skus}: {skus: string[]}): Promise<void> => {\n setSubscriptions(await iapGetSubscriptions({skus}));\n },\n [setSubscriptions],\n );\n\n const getAvailablePurchases = useCallback(async (): Promise<void> => {\n setAvailablePurchases(await iapGetAvailablePurchases());\n }, [setAvailablePurchases]);\n\n const getPurchaseHistory = useCallback(async (): Promise<void> => {\n setPurchaseHistory(await iapGetPurchaseHistory());\n }, [setPurchaseHistory]);\n\n const finishTransaction = useCallback(\n async ({\n purchase,\n isConsumable,\n developerPayloadAndroid,\n }: {\n purchase: Purchase;\n isConsumable?: boolean;\n developerPayloadAndroid?: string;\n }): Promise<string | boolean | PurchaseResult | void> => {\n try {\n return await iapFinishTransaction({\n purchase,\n isConsumable,\n developerPayloadAndroid,\n });\n } catch (err) {\n throw err;\n } finally {\n if (purchase.productId === currentPurchase?.productId) {\n setCurrentPurchase(undefined);\n }\n\n if (purchase.productId === currentPurchaseError?.productId) {\n setCurrentPurchaseError(undefined);\n }\n }\n },\n [\n currentPurchase?.productId,\n currentPurchaseError?.productId,\n setCurrentPurchase,\n setCurrentPurchaseError,\n ],\n );\n\n return {\n connected,\n products,\n promotedProductsIOS,\n subscriptions,\n purchaseHistory,\n availablePurchases,\n currentPurchase,\n currentPurchaseError,\n initConnectionError,\n finishTransaction,\n getProducts,\n getSubscriptions,\n getAvailablePurchases,\n getPurchaseHistory,\n requestPurchase: iapRequestPurchase,\n requestSubscription: iapRequestSubscription,\n };\n};\n"],"mappings":";;;;;;;AAAA;;AAEA;;AAYA;;AA6BO,MAAMA,MAAM,GAAG,MAAkB;EACtC,MAAM;IACJC,SADI;IAEJC,QAFI;IAGJC,mBAHI;IAIJC,aAJI;IAKJC,eALI;IAMJC,kBANI;IAOJC,eAPI;IAQJC,oBARI;IASJC,mBATI;IAUJC,WAVI;IAWJC,gBAXI;IAYJC,qBAZI;IAaJC,kBAbI;IAcJC,kBAdI;IAeJC;EAfI,IAgBF,IAAAC,6BAAA,GAhBJ;EAkBA,MAAMC,WAAW,GAAG,IAAAC,kBAAA,EAClB,cAAmD;IAAA,IAA5C;MAACC;IAAD,CAA4C;IACjDT,WAAW,CAAC,MAAM,IAAAU,gBAAA,EAAe;MAACD;IAAD,CAAf,CAAP,CAAX;EACD,CAHiB,EAIlB,CAACT,WAAD,CAJkB,CAApB;EAOA,MAAMW,gBAAgB,GAAG,IAAAH,kBAAA,EACvB,eAAmD;IAAA,IAA5C;MAACC;IAAD,CAA4C;IACjDR,gBAAgB,CAAC,MAAM,IAAAW,qBAAA,EAAoB;MAACH;IAAD,CAApB,CAAP,CAAhB;EACD,CAHsB,EAIvB,CAACR,gBAAD,CAJuB,CAAzB;EAOA,MAAMY,qBAAqB,GAAG,IAAAL,kBAAA,EAAY,YAA2B;IACnEN,qBAAqB,CAAC,MAAM,IAAAY,0BAAA,GAAP,CAArB;EACD,CAF6B,EAE3B,CAACZ,qBAAD,CAF2B,CAA9B;EAIA,MAAMa,kBAAkB,GAAG,IAAAP,kBAAA,EAAY,YAA2B;IAChEL,kBAAkB,CAAC,MAAM,IAAAa,uBAAA,GAAP,CAAlB;EACD,CAF0B,EAExB,CAACb,kBAAD,CAFwB,CAA3B;EAIA,MAAMc,iBAAiB,GAAG,IAAAT,kBAAA,EACxB,eAQyD;IAAA,IARlD;MACLU,QADK;MAELC,YAFK;MAGLC;IAHK,CAQkD;;IACvD,IAAI;MACF,OAAO,MAAM,IAAAC,sBAAA,EAAqB;QAChCH,QADgC;QAEhCC,YAFgC;QAGhCC;MAHgC,CAArB,CAAb;IAKD,CAND,CAME,OAAOE,GAAP,EAAY;MACZ,MAAMA,GAAN;IACD,CARD,SAQU;MACR,IAAIJ,QAAQ,CAACK,SAAT,MAAuB1B,eAAvB,aAAuBA,eAAvB,uBAAuBA,eAAe,CAAE0B,SAAxC,CAAJ,EAAuD;QACrDnB,kBAAkB,CAACoB,SAAD,CAAlB;MACD;;MAED,IAAIN,QAAQ,CAACK,SAAT,MAAuBzB,oBAAvB,aAAuBA,oBAAvB,uBAAuBA,oBAAoB,CAAEyB,SAA7C,CAAJ,EAA4D;QAC1DlB,uBAAuB,CAACmB,SAAD,CAAvB;MACD;IACF;EACF,CA3BuB,EA4BxB,CACE3B,eADF,aACEA,eADF,uBACEA,eAAe,CAAE0B,SADnB,EAEEzB,oBAFF,aAEEA,oBAFF,uBAEEA,oBAAoB,CAAEyB,SAFxB,EAGEnB,kBAHF,EAIEC,uBAJF,CA5BwB,CAA1B;EAoCA,OAAO;IACLd,SADK;IAELC,QAFK;IAGLC,mBAHK;IAILC,aAJK;IAKLC,eALK;IAMLC,kBANK;IAOLC,eAPK;IAQLC,oBARK;IASLC,mBATK;IAULkB,iBAVK;IAWLV,WAXK;IAYLI,gBAZK;IAaLE,qBAbK;IAcLE,kBAdK;IAeLU,eAAe,EAAEC,oBAfZ;IAgBLC,mBAAmB,EAAEC;EAhBhB,CAAP;AAkBD,CA/FM"}
@@ -7,8 +7,6 @@ exports.validateReceiptIos = exports.validateReceiptAndroid = exports.validateRe
7
7
 
8
8
  var _reactNative = require("react-native");
9
9
 
10
- var _apple = require("./types/apple");
11
-
12
10
  var _internal = require("./internal");
13
11
 
14
12
  var _types = require("./types");
@@ -18,8 +16,8 @@ const {
18
16
  RNIapModule,
19
17
  RNIapAmazonModule
20
18
  } = _reactNative.NativeModules;
21
- const ANDROID_ITEM_TYPE_SUBSCRIPTION = 'subs';
22
- const ANDROID_ITEM_TYPE_IAP = 'inapp';
19
+ const ANDROID_ITEM_TYPE_SUBSCRIPTION = _types.ProductType.subs;
20
+ const ANDROID_ITEM_TYPE_IAP = _types.ProductType.inapp;
23
21
 
24
22
  const getInstallSourceAndroid = () => {
25
23
  return RNIapModule ? _types.InstallSourceAndroid.GOOGLE_PLAY : _types.InstallSourceAndroid.AMAZON;
@@ -112,7 +110,7 @@ const getProducts = _ref => {
112
110
  const products = await getAndroidModule().getItemsByType(ANDROID_ITEM_TYPE_IAP, skus);
113
111
  return (0, _internal.fillProductsWithAdditionalData)(products);
114
112
  }
115
- }) || Promise.resolve)();
113
+ }) || (() => Promise.reject(new Error('Unsupported Platform'))))();
116
114
  };
117
115
  /**
118
116
  * Get a list of subscriptions
@@ -136,7 +134,7 @@ const getSubscriptions = _ref2 => {
136
134
  const subscriptions = await getAndroidModule().getItemsByType(ANDROID_ITEM_TYPE_SUBSCRIPTION, skus);
137
135
  return (0, _internal.fillProductsWithAdditionalData)(subscriptions);
138
136
  }
139
- }) || Promise.resolve)();
137
+ }) || (() => Promise.reject(new Error('Unsupported Platform'))))();
140
138
  };
141
139
  /**
142
140
  * Gets an inventory of purchases made by the user regardless of consumption status
@@ -155,11 +153,11 @@ const getPurchaseHistory = () => (_reactNative.Platform.select({
155
153
  return await RNIapAmazonModule.getAvailableItems();
156
154
  }
157
155
 
158
- const products = await getAndroidModule().getPurchaseHistoryByType(ANDROID_ITEM_TYPE_IAP);
159
- const subscriptions = await getAndroidModule().getPurchaseHistoryByType(ANDROID_ITEM_TYPE_SUBSCRIPTION);
156
+ const products = await RNIapModule.getPurchaseHistoryByType(ANDROID_ITEM_TYPE_IAP);
157
+ const subscriptions = await RNIapModule.getPurchaseHistoryByType(ANDROID_ITEM_TYPE_SUBSCRIPTION);
160
158
  return products.concat(subscriptions);
161
159
  }
162
- }) || Promise.resolve)();
160
+ }) || (() => Promise.resolve([])))();
163
161
  /**
164
162
  * Get all purchases made by the user (either non-consumable, or haven't been consumed yet)
165
163
  * @returns {Promise<(ProductPurchase | SubscriptionPurchase)[]>}
@@ -177,11 +175,11 @@ const getAvailablePurchases = () => (_reactNative.Platform.select({
177
175
  return await RNIapAmazonModule.getAvailableItems();
178
176
  }
179
177
 
180
- const products = await getAndroidModule().getAvailableItemsByType(ANDROID_ITEM_TYPE_IAP);
181
- const subscriptions = await getAndroidModule().getAvailableItemsByType(ANDROID_ITEM_TYPE_SUBSCRIPTION);
178
+ const products = await RNIapModule.getAvailableItemsByType(ANDROID_ITEM_TYPE_IAP);
179
+ const subscriptions = await RNIapModule.getAvailableItemsByType(ANDROID_ITEM_TYPE_SUBSCRIPTION);
182
180
  return products.concat(subscriptions);
183
181
  }
184
- }) || Promise.resolve)();
182
+ }) || (() => Promise.resolve([])))();
185
183
  /**
186
184
  * Request a purchase for product. This will be received in `PurchaseUpdatedListener`.
187
185
  * @param {string} sku The product's sku/ID
@@ -209,6 +207,10 @@ const requestPurchase = _ref3 => {
209
207
  } = _ref3;
210
208
  return (_reactNative.Platform.select({
211
209
  ios: async () => {
210
+ if (!sku) {
211
+ return Promise.reject(new Error('sku is required for iOS purchase'));
212
+ }
213
+
212
214
  if (andDangerouslyFinishTransactionAutomaticallyIOS) {
213
215
  console.warn('You are dangerously allowing react-native-iap to finish your transaction automatically. You should set andDangerouslyFinishTransactionAutomatically to false when calling requestPurchase and call finishTransaction manually when you have delivered the purchased goods to the user. It defaults to true to provide backwards compatibility. Will default to false in version 4.0.0.');
214
216
  }
@@ -217,9 +219,17 @@ const requestPurchase = _ref3 => {
217
219
  },
218
220
  android: async () => {
219
221
  if (_internal.isAmazon) {
222
+ if (!sku) {
223
+ return Promise.reject(new Error('sku is required for Amazon purchase'));
224
+ }
225
+
220
226
  return RNIapAmazonModule.buyItemByType(sku);
221
227
  } else {
222
- return getAndroidModule().buyItemByType(ANDROID_ITEM_TYPE_IAP, skus !== null && skus !== void 0 && skus.length ? skus : [sku], null, -1, obfuscatedAccountIdAndroid, obfuscatedProfileIdAndroid, [], isOfferPersonalized ?? false);
228
+ if (!(sku !== null && sku !== void 0 && sku.length) && !sku) {
229
+ return Promise.reject(new Error('skus is required for Android purchase'));
230
+ }
231
+
232
+ return getAndroidModule().buyItemByType(ANDROID_ITEM_TYPE_IAP, skus !== null && skus !== void 0 && skus.length ? skus : [sku], undefined, -1, obfuscatedAccountIdAndroid, obfuscatedProfileIdAndroid, [], isOfferPersonalized ?? false);
223
233
  }
224
234
  }
225
235
  }) || Promise.resolve)();
@@ -254,6 +264,10 @@ const requestSubscription = _ref4 => {
254
264
  } = _ref4;
255
265
  return (_reactNative.Platform.select({
256
266
  ios: async () => {
267
+ if (!sku) {
268
+ return Promise.reject(new Error('sku is required for iOS subscription'));
269
+ }
270
+
257
271
  if (andDangerouslyFinishTransactionAutomaticallyIOS) {
258
272
  console.warn('You are dangerously allowing react-native-iap to finish your transaction automatically. You should set andDangerouslyFinishTransactionAutomatically to false when calling requestPurchase and call finishTransaction manually when you have delivered the purchased goods to the user. It defaults to true to provide backwards compatibility. Will default to false in version 4.0.0.');
259
273
  }
@@ -262,17 +276,20 @@ const requestSubscription = _ref4 => {
262
276
  },
263
277
  android: async () => {
264
278
  if (_internal.isAmazon) {
279
+ if (!sku) {
280
+ return Promise.reject(new Error('sku is required for Amazon purchase'));
281
+ }
282
+
265
283
  return RNIapAmazonModule.buyItemByType(sku);
266
284
  } else {
267
285
  if (!(subscriptionOffers !== null && subscriptionOffers !== void 0 && subscriptionOffers.length)) {
268
- Promise.reject('subscriptionOffers are required for Google Play Subscriptions');
269
- return;
286
+ return Promise.reject('subscriptionOffers are required for Google Play Subscriptions');
270
287
  }
271
288
 
272
289
  return RNIapModule.buyItemByType(ANDROID_ITEM_TYPE_SUBSCRIPTION, subscriptionOffers === null || subscriptionOffers === void 0 ? void 0 : subscriptionOffers.map(so => so.sku), purchaseTokenAndroid, prorationModeAndroid, obfuscatedAccountIdAndroid, obfuscatedProfileIdAndroid, subscriptionOffers === null || subscriptionOffers === void 0 ? void 0 : subscriptionOffers.map(so => so.offerToken), isOfferPersonalized ?? false);
273
290
  }
274
291
  }
275
- }) || Promise.resolve)();
292
+ }) || (() => Promise.resolve(null)))();
276
293
  };
277
294
  /**
278
295
  * Request a purchase for product. This will be received in `PurchaseUpdatedListener`.
@@ -314,22 +331,28 @@ const finishTransaction = _ref6 => {
314
331
  } = _ref6;
315
332
  return (_reactNative.Platform.select({
316
333
  ios: async () => {
317
- return getIosModule().finishTransaction(purchase.transactionId);
334
+ const transactionId = purchase.transactionId;
335
+
336
+ if (!transactionId) {
337
+ return Promise.reject(new Error('transactionId required to finish iOS transaction'));
338
+ }
339
+
340
+ return getIosModule().finishTransaction(transactionId);
318
341
  },
319
342
  android: async () => {
320
- if (purchase) {
343
+ if (purchase !== null && purchase !== void 0 && purchase.purchaseToken) {
321
344
  if (isConsumable) {
322
345
  return getAndroidModule().consumeProduct(purchase.purchaseToken, developerPayloadAndroid);
323
346
  } else if (purchase.userIdAmazon || !purchase.isAcknowledgedAndroid && purchase.purchaseStateAndroid === _types.PurchaseStateAndroid.PURCHASED) {
324
347
  return getAndroidModule().acknowledgePurchase(purchase.purchaseToken, developerPayloadAndroid);
325
348
  } else {
326
- throw new Error('purchase is not suitable to be purchased');
349
+ return Promise.reject(new Error('purchase is not suitable to be purchased'));
327
350
  }
328
- } else {
329
- throw new Error('purchase is not assigned');
330
351
  }
352
+
353
+ return Promise.reject(new Error('purchase is not suitable to be purchased'));
331
354
  }
332
- }) || Promise.resolve)();
355
+ }) || (() => Promise.reject(new Error('Unsupported Platform'))))();
333
356
  };
334
357
  /**
335
358
  * Clear Transaction (iOS only)
@@ -407,6 +430,7 @@ exports.getPromotedProductIOS = getPromotedProductIOS;
407
430
  const buyPromotedProductIOS = () => getIosModule().buyPromotedProduct();
408
431
 
409
432
  exports.buyPromotedProductIOS = buyPromotedProductIOS;
433
+ const TEST_RECEIPT = 21007;
410
434
 
411
435
  const requestAgnosticReceiptValidationIos = async receiptBody => {
412
436
  const response = await (0, _internal.enhancedFetch)('https://buy.itunes.apple.com/verifyReceipt', {
@@ -415,7 +439,7 @@ const requestAgnosticReceiptValidationIos = async receiptBody => {
415
439
  }); // Best practice is to check for test receipt and check sandbox instead
416
440
  // https://developer.apple.com/documentation/appstorereceipts/verifyreceipt
417
441
 
418
- if (response && response.status === _apple.ReceiptValidationStatus.TEST_RECEIPT) {
442
+ if (response && response.status === TEST_RECEIPT) {
419
443
  const testResponse = await (0, _internal.enhancedFetch)('https://sandbox.itunes.apple.com/verifyReceipt', {
420
444
  method: 'POST',
421
445
  body: receiptBody