react-native-iap 12.0.3 → 12.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 (38) hide show
  1. package/lib/commonjs/iap.js +143 -110
  2. package/lib/commonjs/iap.js.map +1 -1
  3. package/lib/commonjs/internal/fillProductsWithAdditionalData.js +2 -1
  4. package/lib/commonjs/internal/fillProductsWithAdditionalData.js.map +1 -1
  5. package/lib/commonjs/internal/platform.js +28 -1
  6. package/lib/commonjs/internal/platform.js.map +1 -1
  7. package/lib/commonjs/modules/android.js.map +1 -1
  8. package/lib/commonjs/modules/ios.js.map +1 -1
  9. package/lib/commonjs/types/appleSk2.js +3 -0
  10. package/lib/commonjs/types/appleSk2.js.map +1 -1
  11. package/lib/commonjs/types/index.js +15 -1
  12. package/lib/commonjs/types/index.js.map +1 -1
  13. package/lib/module/iap.js +143 -111
  14. package/lib/module/iap.js.map +1 -1
  15. package/lib/module/internal/fillProductsWithAdditionalData.js +2 -1
  16. package/lib/module/internal/fillProductsWithAdditionalData.js.map +1 -1
  17. package/lib/module/internal/platform.js +24 -0
  18. package/lib/module/internal/platform.js.map +1 -1
  19. package/lib/module/modules/android.js.map +1 -1
  20. package/lib/module/modules/ios.js.map +1 -1
  21. package/lib/module/types/appleSk2.js +2 -0
  22. package/lib/module/types/appleSk2.js.map +1 -1
  23. package/lib/module/types/index.js +12 -0
  24. package/lib/module/types/index.js.map +1 -1
  25. package/lib/typescript/iap.d.ts +4 -4
  26. package/lib/typescript/internal/fillProductsWithAdditionalData.d.ts +2 -1
  27. package/lib/typescript/internal/platform.d.ts +9 -0
  28. package/lib/typescript/modules/android.d.ts +1 -1
  29. package/lib/typescript/modules/ios.d.ts +4 -4
  30. package/lib/typescript/types/index.d.ts +54 -28
  31. package/package.json +1 -1
  32. package/src/iap.ts +130 -74
  33. package/src/internal/fillProductsWithAdditionalData.ts +3 -2
  34. package/src/internal/platform.ts +20 -0
  35. package/src/modules/android.ts +1 -1
  36. package/src/modules/ios.ts +5 -5
  37. package/src/types/appleSk2.ts +2 -0
  38. package/src/types/index.ts +70 -30
@@ -54,10 +54,7 @@ export interface ProductCommon {
54
54
  description: string;
55
55
  price: string;
56
56
  currency: string;
57
- /**
58
- * For Android use subscription.subscriptionOfferDetails[*].pricingPhases.pricingPhaseList[*].formattedPrice
59
- */
60
- localizedPrice?: string;
57
+ localizedPrice: string;
61
58
  countryCode?: string;
62
59
  }
63
60
 
@@ -129,33 +126,61 @@ export interface ProductIOS extends ProductCommon {
129
126
 
130
127
  export type Product = ProductAndroid & ProductIOS;
131
128
 
132
- // Android V5
133
- export interface SubscriptionAndroid extends ProductCommon {
129
+ /**
130
+ * Can be used to distinguish the different platforms' subscription information
131
+ */
132
+ export enum SubscriptionPlatform {
133
+ android = 'android',
134
+ amazon = 'amazon',
135
+ ios = 'ios',
136
+ }
137
+
138
+ /** Android Billing v5 type */
139
+ export interface SubscriptionAndroid {
140
+ platform: SubscriptionPlatform.android;
141
+ productType: 'subs';
142
+ name: string;
143
+ title: string;
144
+ description: string;
145
+ productId: string;
146
+ subscriptionOfferDetails: SubscriptionOfferAndroid[];
147
+ }
148
+
149
+ export interface SubscriptionOfferAndroid {
150
+ offerToken: string;
151
+ pricingPhases: {
152
+ pricingPhaseList: PricingPhaseAndroid[];
153
+ };
154
+ offerTags: string[];
155
+ }
156
+
157
+ export interface PricingPhaseAndroid {
158
+ formattedPrice: string;
159
+ priceCurrencyCode: string;
160
+ /**
161
+ * P1W, P1M, P1Y
162
+ */
163
+ billingPeriod: string;
164
+ billingCycleCount: number;
165
+ priceAmountMicros: string;
166
+ recurrenceMode: number;
167
+ }
168
+
169
+ /**
170
+ * TODO: As of 2022-10-10, this typing is not verified against the real
171
+ * Amazon API. Please update this if you have a more accurate type.
172
+ */
173
+ export interface SubscriptionAmazon extends ProductCommon {
174
+ platform: SubscriptionPlatform.amazon;
134
175
  type: 'subs';
135
176
 
136
177
  productType?: string;
137
178
  name?: string;
138
- subscriptionOfferDetails?: {
139
- offerToken: string;
140
- pricingPhases: {
141
- pricingPhaseList: {
142
- formattedPrice: string;
143
- priceCurrencyCode: string;
144
- /**
145
- * P1W, P1M, P1Y
146
- */
147
- billingPeriod: string;
148
- billingCycleCount: number;
149
- priceAmountMicros: string;
150
- recurrenceMode: number;
151
- }[];
152
- };
153
- offerTags: string[];
154
- }[];
155
179
  }
156
180
 
157
181
  export type SubscriptionIosPeriod = 'DAY' | 'WEEK' | 'MONTH' | 'YEAR' | '';
158
182
  export interface SubscriptionIOS extends ProductCommon {
183
+ platform: SubscriptionPlatform.ios;
159
184
  type: 'subs';
160
185
  discounts?: Discount[];
161
186
  introductoryPrice?: string;
@@ -172,7 +197,11 @@ export interface SubscriptionIOS extends ProductCommon {
172
197
  subscriptionPeriodUnitIOS?: SubscriptionIosPeriod;
173
198
  }
174
199
 
175
- export type Subscription = SubscriptionAndroid & SubscriptionIOS;
200
+ export type Subscription =
201
+ | SubscriptionAndroid
202
+ | SubscriptionAmazon
203
+ | SubscriptionIOS;
204
+
176
205
  export interface RequestPurchaseBaseAndroid {
177
206
  obfuscatedAccountIdAndroid?: string;
178
207
  obfuscatedProfileIdAndroid?: string;
@@ -180,11 +209,11 @@ export interface RequestPurchaseBaseAndroid {
180
209
  }
181
210
 
182
211
  export interface RequestPurchaseAndroid extends RequestPurchaseBaseAndroid {
183
- skus?: Sku[];
212
+ skus: Sku[];
184
213
  }
185
214
 
186
215
  export interface RequestPurchaseIOS {
187
- sku?: Sku;
216
+ sku: Sku;
188
217
  andDangerouslyFinishTransactionAutomaticallyIOS?: boolean;
189
218
  /**
190
219
  * UUID representing user account
@@ -194,7 +223,13 @@ export interface RequestPurchaseIOS {
194
223
  withOffer?: Apple.PaymentDiscount;
195
224
  }
196
225
 
197
- export type RequestPurchase = RequestPurchaseAndroid & RequestPurchaseIOS;
226
+ /** As of 2022-10-12, we only use the `sku` field for Amazon purchases */
227
+ export type RequestPurchaseAmazon = RequestPurchaseIOS;
228
+
229
+ export type RequestPurchase =
230
+ | RequestPurchaseAndroid
231
+ | RequestPurchaseAmazon
232
+ | RequestPurchaseIOS;
198
233
 
199
234
  /**
200
235
  * In order to purchase a new subscription, every sku must have a selected offerToken
@@ -208,13 +243,18 @@ export interface SubscriptionOffer {
208
243
  export interface RequestSubscriptionAndroid extends RequestPurchaseBaseAndroid {
209
244
  purchaseTokenAndroid?: string;
210
245
  prorationModeAndroid?: ProrationModesAndroid;
211
- subscriptionOffers?: SubscriptionOffer[]; // For AndroidBilling V5
246
+ subscriptionOffers: SubscriptionOffer[];
212
247
  }
213
248
 
214
249
  export type RequestSubscriptionIOS = RequestPurchaseIOS;
215
250
 
216
- export type RequestSubscription = RequestSubscriptionAndroid &
217
- RequestSubscriptionIOS;
251
+ /** As of 2022-10-12, we only use the `sku` field for Amazon subscriptions */
252
+ export type RequestSubscriptionAmazon = RequestSubscriptionIOS;
253
+
254
+ export type RequestSubscription =
255
+ | RequestSubscriptionAndroid
256
+ | RequestSubscriptionAmazon
257
+ | RequestSubscriptionIOS;
218
258
 
219
259
  declare module 'react-native' {
220
260
  interface NativeModulesStatic {