forked from zhengdianfang/react-native-iap
-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.d.ts
300 lines (300 loc) · 14.3 KB
/
index.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
import * as Apple from './type/apple';
import { EmitterSubscription } from 'react-native';
interface Common {
title: string;
description: string;
price: string;
currency: string;
localizedPrice: string;
}
export declare enum IAPErrorCode {
E_IAP_NOT_AVAILABLE = "E_IAP_NOT_AVAILABLE",
E_UNKNOWN = "E_UNKNOWN",
E_USER_CANCELLED = "E_USER_CANCELLED",
E_USER_ERROR = "E_USER_ERROR",
E_ITEM_UNAVAILABLE = "E_ITEM_UNAVAILABLE",
E_REMOTE_ERROR = "E_REMOTE_ERROR",
E_NETWORK_ERROR = "E_NETWORK_ERROR",
E_SERVICE_ERROR = "E_SERVICE_ERROR",
E_RECEIPT_FAILED = "E_RECEIPT_FAILED",
E_RECEIPT_FINISHED_FAILED = "E_RECEIPT_FINISHED_FAILED",
E_NOT_PREPARED = "E_NOT_PREPARED",
E_NOT_ENDED = "E_NOT_ENDED",
E_ALREADY_OWNED = "E_ALREADY_OWNED",
E_DEVELOPER_ERROR = "E_DEVELOPER_ERROR",
E_BILLING_RESPONSE_JSON_PARSE_ERROR = "E_BILLING_RESPONSE_JSON_PARSE_ERROR"
}
export declare enum ProrationModesAndroid {
IMMEDIATE_WITH_TIME_PRORATION = 1,
IMMEDIATE_AND_CHARGE_PRORATED_PRICE = 2,
IMMEDIATE_WITHOUT_PRORATION = 3,
DEFERRED = 4,
UNKNOWN_SUBSCRIPTION_UPGRADE_DOWNGRADE_POLICY = 0
}
export interface Discount {
identifier: string;
type: string;
numberOfPeriods: string;
price: string;
localizedPrice: string;
paymentMode: string;
subscriptionPeriod: string;
}
export interface Product extends Common {
type: 'inapp' | 'iap';
productId: string;
}
export interface Subscription extends Common {
type: 'subs' | 'sub';
productId: string;
discounts?: Discount[];
introductoryPrice?: string;
introductoryPricePaymentModeIOS?: string;
introductoryPriceNumberOfPeriodsIOS?: string;
introductoryPriceSubscriptionPeriodIOS?: string;
subscriptionPeriodNumberIOS?: string;
subscriptionPeriodUnitIOS?: string;
introductoryPriceCyclesAndroid?: string;
introductoryPricePeriodAndroid?: string;
subscriptionPeriodAndroid?: string;
freeTrialPeriodAndroid?: string;
}
export declare enum PurchaseStateAndroid {
UNSPECIFIED_STATE = 0,
PURCHASED = 1,
PENDING = 2
}
interface ProductPurchase {
productId: string;
transactionId?: string;
transactionDate: number;
transactionReceipt: string;
purchaseToken?: string;
dataAndroid?: string;
signatureAndroid?: string;
autoRenewingAndroid?: boolean;
purchaseStateAndroid?: PurchaseStateAndroid;
originalTransactionDateIOS?: string;
originalTransactionIdentifierIOS?: string;
isAcknowledgedAndroid?: boolean;
}
export interface PurchaseResult {
responseCode?: number;
debugMessage?: string;
code?: string;
message?: string;
}
export interface PurchaseError {
responseCode?: number;
debugMessage?: string;
code?: string;
message?: string;
}
export declare type InAppPurchase = ProductPurchase;
export interface SubscriptionPurchase extends ProductPurchase {
autoRenewingAndroid?: boolean;
originalTransactionDateIOS?: string;
originalTransactionIdentifierIOS?: string;
}
export declare type Purchase = InAppPurchase | SubscriptionPurchase;
export declare const PROMOTED_PRODUCT = "iap-promoted-product";
/**
* Init module for purchase flow. Required on Android. In ios it will check wheter user canMakePayment.
* @returns {Promise<boolean>}
*/
export declare const initConnection: () => Promise<boolean>;
/**
* End module for purchase flow. Required on Android. No-op on iOS.
* @returns {Promise<void>}
*/
export declare const endConnectionAndroid: () => Promise<void>;
/**
* Consume all remaining tokens. Android only.
* @returns {Promise<string[]>}
*/
export declare const consumeAllItemsAndroid: () => Promise<string[]>;
/**
* Get a list of products (consumable and non-consumable items, but not subscriptions)
* @param {string[]} skus The item skus
* @returns {Promise<Product[]>}
*/
export declare const getProducts: (skus: string[]) => Promise<Product[]>;
/**
* Get a list of subscriptions
* @param {string[]} skus The item skus
* @returns {Promise<Subscription[]>}
*/
export declare const getSubscriptions: (skus: string[]) => Promise<Subscription[]>;
/**
* Gets an invetory of purchases made by the user regardless of consumption status
* @returns {Promise<(InAppPurchase | SubscriptionPurchase)[]>}
*/
export declare const getPurchaseHistory: () => Promise<(ProductPurchase | SubscriptionPurchase)[]>;
/**
* Get all purchases made by the user (either non-consumable, or haven't been consumed yet)
* @returns {Promise<(InAppPurchase | SubscriptionPurchase)[]>}
*/
export declare const getAvailablePurchases: () => Promise<(ProductPurchase | SubscriptionPurchase)[]>;
/**
* Request a purchase for product. This will be received in `PurchaseUpdatedListener`.
* @param {string} sku The product's sku/ID
* @param {boolean} [andDangerouslyFinishTransactionAutomaticallyIOS] You should set this to false 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.
* @param {string} [developerIdAndroid] Specify an optional obfuscated string of developer profile name.
* @param {string} [userIdAndroid] Specify an optional obfuscated string that is uniquely associated with the user's account in.
* @returns {Promise<InAppPurchase>}
*/
export declare const requestPurchase: (sku: string, andDangerouslyFinishTransactionAutomaticallyIOS?: boolean, developerIdAndroid?: string, accountIdAndroid?: string) => Promise<ProductPurchase>;
/**
* Request a purchase for product. This will be received in `PurchaseUpdatedListener`.
* @param {string} sku The product's sku/ID
* @param {boolean} [andDangerouslyFinishTransactionAutomaticallyIOS] You should set this to false 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.
* @param {string} [oldSkuAndroid] SKU that the user is upgrading or downgrading from.
* @param {ProrationModesAndroid} [prorationModeAndroid] UNKNOWN_SUBSCRIPTION_UPGRADE_DOWNGRADE_POLICY, IMMEDIATE_WITH_TIME_PRORATION, IMMEDIATE_AND_CHARGE_PRORATED_PRICE, IMMEDIATE_WITHOUT_PRORATION, DEFERRED
* @param {string} [developerIdAndroid] Specify an optional obfuscated string of developer profile name.
* @param {string} [userIdAndroid] Specify an optional obfuscated string that is uniquely associated with the user's account in.
* @returns {Promise<void>}
*/
export declare const requestSubscription: (sku: string, andDangerouslyFinishTransactionAutomaticallyIOS?: boolean, oldSkuAndroid?: string, prorationModeAndroid?: ProrationModesAndroid, developerIdAndroid?: string, userIdAndroid?: string) => Promise<SubscriptionPurchase>;
/**
* Request a purchase for product. This will be received in `PurchaseUpdatedListener`.
* @param {string} sku The product's sku/ID
* @returns {Promise<void>}
*/
export declare const requestPurchaseWithQuantityIOS: (sku: string, quantity: number) => Promise<ProductPurchase>;
/**
* Finish Transaction (iOS only)
* Similar to `consumePurchaseAndroid`. Tells StoreKit that you have delivered the purchase to the user and StoreKit can now let go of the transaction.
* Call this after you have persisted the purchased state to your server or local data in your app.
* `react-native-iap` will continue to deliver the purchase updated events with the successful purchase until you finish the transaction. **Even after the app has relaunched.**
* @param {string} transactionId The transactionId of the function that you would like to finish.
* @returns {Promise<void>}
*/
export declare const finishTransactionIOS: (transactionId: string) => Promise<void>;
/**
* Finish Transaction (both platforms)
* Abstracts `finishTransactionIOS`, `consumePurchaseAndroid`, `acknowledgePurchaseAndroid` in to one method.
* @param {object} purchase The purchase that you would like to finish.
* @param {boolean} isConsumable Checks if purchase is consumable. Has effect on `android`.
* @param {string} developerPayloadAndroid Android developerPayload.
* @returns {Promise<string | void> }
*/
export declare const finishTransaction: (purchase: ProductPurchase, isConsumable?: boolean, developerPayloadAndroid?: string) => Promise<string | void>;
/**
* Clear Transaction (iOS only)
* Finish remaining transactions. Related to issue #257 and #801
* link : https://github.com/dooboolab/react-native-iap/issues/257
* https://github.com/dooboolab/react-native-iap/issues/801
* @returns {Promise<void>}
*/
export declare const clearTransactionIOS: () => Promise<void>;
/**
* Clear valid Products (iOS only)
* Remove all products which are validated by Apple server.
* @returns {void}
*/
export declare const clearProductsIOS: () => void;
/**
* Acknowledge a product (on Android.) No-op on iOS.
* @param {string} token The product's token (on Android)
* @returns {Promise<PurchaseResult | void>}
*/
export declare const acknowledgePurchaseAndroid: (token: string, developerPayload?: string) => Promise<void | PurchaseResult>;
/**
* Consume a product (on Android.) No-op on iOS.
* @param {string} token The product's token (on Android)
* @returns {Promise<PurchaseResult>}
*/
export declare const consumePurchaseAndroid: (token: string, developerPayload?: string) => Promise<PurchaseResult>;
/**
* Should Add Store Payment (iOS only)
* Indicates the the App Store purchase should continue from the app instead of the App Store.
* @returns {Promise<Product>}
*/
export declare const getPromotedProductIOS: () => Promise<Product>;
/**
* Buy the currently selected promoted product (iOS only)
* Initiates the payment process for a promoted product. Should only be called in response to the `iap-promoted-product` event.
* @returns {Promise<void>}
*/
export declare const buyPromotedProductIOS: () => Promise<void>;
/**
* Buy products or subscriptions with offers (iOS only)
*
* Runs the payment process with some infor you must fetch
* from your server.
* @param {string} sku The product identifier
* @param {string} forUser An user identifier on you system
* @param {Apple.PaymentDiscount} withOffer The offer information
* @param {string} withOffer.identifier The offer identifier
* @param {string} withOffer.keyIdentifier Key identifier that it uses to generate the signature
* @param {string} withOffer.nonce An UUID returned from the server
* @param {string} withOffer.signature The actual signature returned from the server
* @param {number} withOffer.timestamp The timestamp of the signature
* @returns {Promise<void>}
*/
export declare const requestPurchaseWithOfferIOS: (sku: string, forUser: string, withOffer: Apple.PaymentDiscount) => Promise<void>;
/**
* Validate receipt for iOS.
* @param {object} receiptBody the receipt body to send to apple server.
* @param {boolean} isTest whether this is in test environment which is sandbox.
* @returns {Promise<Apple.ReceiptValidationResponse | false>}
*/
export declare const validateReceiptIos: (receiptBody: object, isTest?: boolean) => Promise<false | Apple.ReceiptValidationResponse>;
/**
* Validate receipt for Android.
* @param {string} packageName package name of your app.
* @param {string} productId product id for your in app product.
* @param {string} productToken token for your purchase.
* @param {string} accessToken accessToken from googleApis.
* @param {boolean} isSub whether this is subscription or inapp. `true` for subscription.
* @returns {Promise<object>}
*/
export declare const validateReceiptAndroid: (packageName: string, productId: string, productToken: string, accessToken: string, isSub?: boolean) => Promise<false | object>;
/**
* Add IAP purchase event in ios.
* @returns {callback(e: InAppPurchase | ProductPurchase)}
*/
export declare const purchaseUpdatedListener: (e: any) => EmitterSubscription;
/**
* Add IAP purchase error event in ios.
* @returns {callback(e: PurchaseError)}
*/
export declare const purchaseErrorListener: (e: any) => EmitterSubscription;
/**
* Get the current receipt base64 encoded in IOS.
* @returns {Promise<string>}
*/
export declare const getReceiptIOS: () => Promise<string>;
/**
* Get the pending purchases in IOS.
* @returns {Promise<ProductPurchase[]>}
*/
export declare const getPendingPurchasesIOS: () => Promise<ProductPurchase[]>;
declare const iapUtils: {
IAPErrorCode: typeof IAPErrorCode;
initConnection: () => Promise<boolean>;
endConnectionAndroid: () => Promise<void>;
getProducts: (skus: string[]) => Promise<Product[]>;
getSubscriptions: (skus: string[]) => Promise<Subscription[]>;
getPurchaseHistory: () => Promise<(ProductPurchase | SubscriptionPurchase)[]>;
getAvailablePurchases: () => Promise<(ProductPurchase | SubscriptionPurchase)[]>;
getPendingPurchasesIOS: () => Promise<ProductPurchase[]>;
consumeAllItemsAndroid: () => Promise<string[]>;
clearProductsIOS: () => void;
clearTransactionIOS: () => Promise<void>;
acknowledgePurchaseAndroid: (token: string, developerPayload?: string) => Promise<void | PurchaseResult>;
consumePurchaseAndroid: (token: string, developerPayload?: string) => Promise<PurchaseResult>;
validateReceiptIos: (receiptBody: object, isTest?: boolean) => Promise<false | Apple.ReceiptValidationResponse>;
validateReceiptAndroid: (packageName: string, productId: string, productToken: string, accessToken: string, isSub?: boolean) => Promise<false | object>;
requestPurchase: (sku: string, andDangerouslyFinishTransactionAutomaticallyIOS?: boolean, developerIdAndroid?: string, accountIdAndroid?: string) => Promise<ProductPurchase>;
requestPurchaseWithQuantityIOS: (sku: string, quantity: number) => Promise<ProductPurchase>;
finishTransactionIOS: (transactionId: string) => Promise<void>;
finishTransaction: (purchase: ProductPurchase, isConsumable?: boolean, developerPayloadAndroid?: string) => Promise<string | void>;
requestSubscription: (sku: string, andDangerouslyFinishTransactionAutomaticallyIOS?: boolean, oldSkuAndroid?: string, prorationModeAndroid?: ProrationModesAndroid, developerIdAndroid?: string, userIdAndroid?: string) => Promise<SubscriptionPurchase>;
purchaseUpdatedListener: (e: any) => EmitterSubscription;
purchaseErrorListener: (e: any) => EmitterSubscription;
getReceiptIOS: () => Promise<string>;
getPromotedProductIOS: () => Promise<Product>;
buyPromotedProductIOS: () => Promise<void>;
};
export default iapUtils;