react-native-iap 11.0.0-rc.2 → 11.0.0-rc.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.
Files changed (57) hide show
  1. package/ios/IapSerializationUtils.swift +50 -11
  2. package/ios/IapTypes.swift +1 -6
  3. package/ios/RNIapIos.m +3 -0
  4. package/ios/RNIapIos.swift +12 -3
  5. package/ios/RNIapIosSk2.m +6 -1
  6. package/ios/RNIapIosSk2.swift +37 -16
  7. package/lib/commonjs/eventEmitter.js +145 -2
  8. package/lib/commonjs/eventEmitter.js.map +1 -1
  9. package/lib/commonjs/hooks/withIAPContext.js +8 -1
  10. package/lib/commonjs/hooks/withIAPContext.js.map +1 -1
  11. package/lib/commonjs/iap.js +81 -37
  12. package/lib/commonjs/iap.js.map +1 -1
  13. package/lib/commonjs/internal/platform.js +33 -4
  14. package/lib/commonjs/internal/platform.js.map +1 -1
  15. package/lib/commonjs/modules/ios.js +5 -2
  16. package/lib/commonjs/modules/ios.js.map +1 -1
  17. package/lib/commonjs/modules/iosSk2.js.map +1 -1
  18. package/lib/commonjs/types/apple.js +24 -0
  19. package/lib/commonjs/types/apple.js.map +1 -1
  20. package/lib/commonjs/types/appleSk2.js +3 -3
  21. package/lib/commonjs/types/appleSk2.js.map +1 -1
  22. package/lib/commonjs/types/index.js.map +1 -1
  23. package/lib/module/eventEmitter.js +141 -1
  24. package/lib/module/eventEmitter.js.map +1 -1
  25. package/lib/module/hooks/withIAPContext.js +9 -2
  26. package/lib/module/hooks/withIAPContext.js.map +1 -1
  27. package/lib/module/iap.js +77 -30
  28. package/lib/module/iap.js.map +1 -1
  29. package/lib/module/internal/platform.js +25 -2
  30. package/lib/module/internal/platform.js.map +1 -1
  31. package/lib/module/modules/ios.js +5 -2
  32. package/lib/module/modules/ios.js.map +1 -1
  33. package/lib/module/modules/iosSk2.js.map +1 -1
  34. package/lib/module/types/apple.js +15 -0
  35. package/lib/module/types/apple.js.map +1 -1
  36. package/lib/module/types/appleSk2.js +3 -3
  37. package/lib/module/types/appleSk2.js.map +1 -1
  38. package/lib/module/types/index.js.map +1 -1
  39. package/lib/typescript/eventEmitter.d.ts +133 -0
  40. package/lib/typescript/hooks/withIAPContext.d.ts +2 -0
  41. package/lib/typescript/iap.d.ts +25 -4
  42. package/lib/typescript/internal/platform.d.ts +3 -1
  43. package/lib/typescript/modules/ios.d.ts +2 -1
  44. package/lib/typescript/modules/iosSk2.d.ts +3 -2
  45. package/lib/typescript/types/apple.d.ts +1 -0
  46. package/lib/typescript/types/appleSk2.d.ts +31 -2
  47. package/lib/typescript/types/index.d.ts +1 -0
  48. package/package.json +1 -1
  49. package/src/eventEmitter.ts +144 -2
  50. package/src/hooks/withIAPContext.tsx +15 -0
  51. package/src/iap.ts +55 -17
  52. package/src/internal/platform.ts +24 -2
  53. package/src/modules/ios.ts +7 -3
  54. package/src/modules/iosSk2.ts +5 -2
  55. package/src/types/apple.ts +15 -0
  56. package/src/types/appleSk2.ts +42 -5
  57. package/src/types/index.ts +1 -0
@@ -27,3 +27,18 @@ export interface PaymentDiscount {
27
27
  */
28
28
  timestamp: number;
29
29
  }
30
+
31
+ export const offerToRecord = (
32
+ offer: PaymentDiscount | undefined,
33
+ ): Record<keyof PaymentDiscount, string> | undefined => {
34
+ if (!offer) {
35
+ return undefined;
36
+ }
37
+ return {
38
+ identifier: offer.identifier,
39
+ keyIdentifier: offer.keyIdentifier,
40
+ nonce: offer.nonce,
41
+ signature: offer.signature,
42
+ timestamp: offer.timestamp.toString(),
43
+ };
44
+ };
@@ -1,5 +1,32 @@
1
+ import type {PurchaseError} from '../purchaseError';
2
+
1
3
  import type {ProductIOS, Purchase, SubscriptionIOS} from '.';
2
4
  import type * as Apple from './apple';
5
+
6
+ export type SubscriptionPeriod = {
7
+ unit: 'day' | 'week' | 'month' | 'year';
8
+ value: number;
9
+ };
10
+
11
+ export type PaymentMode = 'freeTrial' | 'payAsYouGo' | 'payUpFront';
12
+
13
+ export type SubscriptionOffer = {
14
+ displayPrice: string;
15
+ id: string;
16
+ paymentMode: PaymentMode;
17
+ period: SubscriptionPeriod;
18
+ periodCount: number;
19
+ price: number;
20
+ type: 'introductory' | 'promotional';
21
+ };
22
+
23
+ export type SubscriptionInfo = {
24
+ introductoryOffer?: SubscriptionOffer;
25
+ promotionalOffers?: SubscriptionOffer[];
26
+ subscriptionGroupID: string;
27
+ subscriptionPeriod: SubscriptionPeriod;
28
+ };
29
+
3
30
  export type ProductSk2 = {
4
31
  description: string;
5
32
  displayName: string;
@@ -8,7 +35,7 @@ export type ProductSk2 = {
8
35
  isFamilyShareable: boolean;
9
36
  jsonRepresentation: string;
10
37
  price: number;
11
- subscription: any; //TODO
38
+ subscription: SubscriptionInfo;
12
39
  type: 'autoRenewable' | 'consumable' | 'nonConsumable' | 'nonRenewable';
13
40
  };
14
41
  export const productSk2Map = ({
@@ -25,7 +52,7 @@ export const productSk2Map = ({
25
52
  type: 'iap',
26
53
  price: String(price),
27
54
  localizedPrice: displayPrice,
28
- currency: '', //TODO: Not avaiable on new API, use localizedPrice instead?
55
+ currency: '', // Not avaiable on new API, use localizedPrice instead
29
56
  };
30
57
  return prod;
31
58
  };
@@ -44,7 +71,7 @@ export const subscriptionSk2Map = ({
44
71
  type: 'subs',
45
72
  price: String(price),
46
73
  localizedPrice: displayPrice,
47
- currency: '', //TODO: Not avaiable on new API, use localizedPrice instead?
74
+ currency: '', // Not avaiable on new API, use localizedPrice instead
48
75
  };
49
76
  return prod;
50
77
  };
@@ -75,6 +102,16 @@ export type TransactionSk2 = {
75
102
  webOrderLineItemID: number;
76
103
  };
77
104
 
105
+ export type TransactionError = PurchaseError;
106
+
107
+ /**
108
+ * Only one of `transaction` and `error` is not undefined at the time
109
+ */
110
+ export type TransactionEvent = {
111
+ transaction?: TransactionSk2;
112
+ error?: TransactionError;
113
+ };
114
+
78
115
  export type SubscriptionStatus =
79
116
  | 'expired'
80
117
  | 'inBillingRetryPeriod'
@@ -138,7 +175,7 @@ export interface PaymentDiscountSk2 {
138
175
 
139
176
  export const offerSk2Map = (
140
177
  offer: Apple.PaymentDiscount | undefined,
141
- ): PaymentDiscountSk2 | undefined => {
178
+ ): Record<keyof PaymentDiscountSk2, string> | undefined => {
142
179
  if (!offer) {
143
180
  return undefined;
144
181
  }
@@ -147,6 +184,6 @@ export const offerSk2Map = (
147
184
  keyID: offer.keyIdentifier,
148
185
  nonce: offer.nonce,
149
186
  signature: offer.signature,
150
- timestamp: offer.timestamp,
187
+ timestamp: offer.timestamp.toString(),
151
188
  };
152
189
  };
@@ -147,6 +147,7 @@ export interface SubscriptionAndroid extends ProductCommon {
147
147
  recurrenceMode: number;
148
148
  }[];
149
149
  };
150
+ offerTags: string[];
150
151
  }[];
151
152
  }
152
153