forked from hyochan/react-native-iap
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.d.ts
271 lines (234 loc) · 10.6 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
import { EmitterSubscription } from 'react-native';
import * as Apple from './apple'
interface Common {
title: string;
description: string;
price: string;
currency: string;
localizedPrice: string;
}
export interface Product<ID extends string> extends Common {
type: 'inapp' | 'iap';
productId: ID;
}
export interface Subscription<ID extends string> extends Common {
type: 'subs' | 'sub';
productId: ID;
introductoryPrice?: string;
introductoryPricePaymentModeIOS?: string;
introductoryPriceNumberOfPeriodsIOS?: string;
introductoryPriceSubscriptionPeriodIOS?: string;
subscriptionPeriodNumberIOS?: string;
subscriptionPeriodUnitIOS?: string;
introductoryPriceCyclesAndroid?: string;
introductoryPricePeriodAndroid?: string;
subscriptionPeriodAndroid?: string;
freeTrialPeriodAndroid?: string;
}
export interface ProductPurchase {
productId: string;
transactionId?: string;
transactionDate: number;
transactionReceipt: string;
purchaseToken?: string;
dataAndroid?: string;
signatureAndroid?: string;
autoRenewingAndroid?: boolean;
isAcknowledgedAndroid?: boolean;
purchaseStateAndroid?: number;
originalTransactionDateIOS?: string;
originalTransactionIdentifierIOS?: string;
}
export interface PurchaseResult {
responseCode?: number;
debugMessage?: string;
}
export interface PurchaseError {
responseCode?: number;
debugMessage?: string;
}
export interface SubscriptionPurchase extends ProductPurchase {
autoRenewingAndroid: boolean;
originalTransactionDateIOS: string;
originalTransactionIdentifierIOS: string;
}
export type Purchase = ProductPurchase | SubscriptionPurchase;
/**
* Init module for purchase flow. Required on Android. In ios it will check wheter user canMakePayment.
* @returns {Promise<string>}
*/
export function initConnection() : Promise<string>;
/**
* End billing client. Will enchance android app's performance by releasing service. No-op on iOS.
* @returns {Promise<void>}
*/
export function endConnectionAndroid() : Promise<void>;
/**
* Consume all items in android. No-op in iOS.
* @returns {Promise<void>}
*/
export function consumeAllItemsAndroid() : Promise<void>;
/**
* Get a list of products (consumable and non-consumable items, but not subscriptions)
* @param skus The item skus
*/
export function getProducts<A extends string, B extends string, C extends string, D extends string, E extends string, F extends string>(skus: [A, B, C, D, E, F]): Promise<[Product<A>, Product<B>, Product<C>, Product<D>, Product<E>, Product<F>]>;
export function getProducts<A extends string, B extends string, C extends string, D extends string, E extends string>(skus: [A, B, C, D, E]): Promise<[Product<A>, Product<B>, Product<C>, Product<D>, Product<E>]>;
export function getProducts<A extends string, B extends string, C extends string, D extends string>(skus: [A, B, C, D]): Promise<[Product<A>, Product<B>, Product<C>, Product<D>]>;
export function getProducts<A extends string, B extends string, C extends string>(skus: [A, B, C]): Promise<[Product<A>, Product<B>, Product<C>]>;
export function getProducts<A extends string, B extends string>(skus: [A, B]): Promise<[Product<A>, Product<B>]>;
export function getProducts<A extends string>(skus: [A]): Promise<[Product<A>]>;
export function getProducts(skus: string[]): Promise<Product<string>[]>;
/**
* Get a list of subscriptions
* @param skus The item skus
*/
export function getSubscriptions<A extends string, B extends string, C extends string, D extends string, E extends string, F extends string>(skus: [A, B, C, D, E, F]): Promise<[Subscription<A>, Subscription<B>, Subscription<C>, Subscription<D>, Subscription<E>, Subscription<F>]>;
export function getSubscriptions<A extends string, B extends string, C extends string, D extends string, E extends string>(skus: [A, B, C, D, E]): Promise<[Subscription<A>, Subscription<B>, Subscription<C>, Subscription<D>, Subscription<E>]>;
export function getSubscriptions<A extends string, B extends string, C extends string, D extends string>(skus: [A, B, C, D]): Promise<[Subscription<A>, Subscription<B>, Subscription<C>, Subscription<D>]>;
export function getSubscriptions<A extends string, B extends string, C extends string>(skus: [A, B, C]): Promise<[Subscription<A>, Subscription<B>, Subscription<C>]>;
export function getSubscriptions<A extends string, B extends string>(skus: [A, B]): Promise<[Subscription<A>, Subscription<B>]>;
export function getSubscriptions<A extends string>(skus: [A]): Promise<[Subscription<A>]>;
export function getSubscriptions(skus: string[]): Promise<Subscription<string>[]>;
/**
* Gets an invetory of purchases made by the user regardless of consumption status
* @returns {Promise<Purchase[]>}
*/
export function getPurchaseHistory() : Promise<Purchase[]>;
/**
* Get all purchases made by the user (either non-consumable, or haven't been consumed yet)
* @returns {Promise<Purchase[]>}
*/
export function getAvailablePurchases() : Promise<Purchase[]>;
/**
* Buy a product
*
* @deprecated
* @param {string} sku The product's sku/ID
* @returns {Promise<Purchase>}
*/
export function buyProduct(sku: string) : Promise<ProductPurchase>;
/**
* Request a purchase
*
* @param {string} sku The product's sku/ID
* @param {boolean} andDangerouslyFinishTransactionAutomatically 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.
* @returns {Promise<string>}
*/
export function requestPurchase(sku: string, andDangerouslyFinishTransactionAutomatically?: boolean) : Promise<string>;
/**
* Create a subscription to a sku
*
* @deprecated
* @param {string} sku The product's sku/ID
* @param {string} [oldSku] Optional old product's ID for upgrade/downgrade (Android only)
* @param {number} [prorationMode] Optional proration mode for upgrade/downgrade (Android only)
* @returns {Promise<Purchase>}
*/
export function buySubscription(sku: string, oldSku?: string, prorationMode?: number) : Promise<SubscriptionPurchase>;
/**
* Request a subscription to a sku
*
* @param {string} sku The product's sku/ID
* @param {string} [oldSku] Optional old product's ID for upgrade/downgrade (Android only)
* @param {number} [prorationMode] Optional proration mode for upgrade/downgrade (Android only)
* @returns {Promise<string>}
*/
export function requestSubscription(sku: string, oldSku?: string, prorationMode?: number) : Promise<string>;
/**
* Buy a product with offer
*
* @param {string} sku The product unique identifier
* @param {string} forUser An user identifier on your service (username or user id)
* @param {Apple.PaymentDiscount} withOffer The offer information
*
* @returns {Promise<void>}
*/
export function buyProductWithOfferIOS(sku: string, forUser: string, withOffer: Apple.PaymentDiscount) : Promise<void>;
/**
* Buy a product with a specified quantity (iOS only)
* @param {string} sku The product's sku/ID
* @param {number} quantity The amount of product to buy
* @returns {Promise<Purchase>}
*/
export function buyProductWithQuantityIOS(sku: string, quantity: number) : Promise<ProductPurchase>;
/**
* Request a purchase with specified quantity (iOS only)
*
* @param {string} sku The product's sku/ID
* @param {number} quantity The amount of product to buy
* @returns {Promise<Purchase>}
*/
export function requestPurchaseWithQuantityIOS(sku: string, quantity: number) : Promise<string>;
/**
* 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 {null}
*/
export function finishTransactionIOS(transactionId: string): void;
/**
* Clear Transaction (iOS only)
* Finish remaining transactions. Related to issue #257
* link : https://github.com/dooboolab/react-native-iap/issues/257
* @returns void
*/
export function clearTransactionIOS(): void;
/**
* Clear valid Products (iOS only)
* Remove all products which are validated by Apple server.
* @returns {null}
*/
export function clearProductsIOS(): void;
/**
* Acknowledge a purchase (on Android.) No-op on iOS.
* This is applied to non-consumable or subscriptions.
* @param {string} token The product's token (on Android)
* @returns {Promise}
*/
export function acknowledgePurchaseAndroid(token: string, developerPayload?: string) : Promise<PurchaseResult>;
/**
* Consume a purchase (on Android.) No-op on iOS.
* It acknowledges consumable products. If it isn't consumable, use `acknowledgePurchaseAndroid` instead.
* @param {string} token The product's token (on Android)
* @returns {Promise}
*/
export function consumePurchaseAndroid(token: string, developerPayload?: string) : Promise<PurchaseResult>;
/**
* Validate receipt for iOS.
* @param receiptBody the receipt body to send to apple server.
* @param isTest whether this is in test environment which is sandbox.
*/
export function validateReceiptIos(receiptBody: Apple.ReceiptValidationRequest, isTest: boolean): Promise<Apple.ReceiptValidationResponse | false>;
/**
* Validate receipt for Android.
* @param packageName package name of your app.
* @param productId product id for your in app product.
* @param productToken token for your purchase. Found in `transanctionReceipt` after `buyProduct` method.
* @param accessToken accessToken from googleApis.
* @param isSub whether this is subscription or inapp. `true` for subscription.
*/
export function validateReceiptAndroid(packageName: string, productId: string, productToken: string, accessToken: string, isSub: boolean): Promise<object | false>;
/**
* Add IAP purchase event in ios.
* @deprecated
* @returns {callback(e: Event)}
*/
export function addAdditionalSuccessPurchaseListenerIOS(fn: Function) : EmitterSubscription;
/**
* Subscribe a listener when purchase is updated.
* @returns {callback(e: ProductPurchase)}
*/
export function purchaseUpdatedListener(fn: Function) : EmitterSubscription;
/**
* Subscribe a listener when purchase got error.
* @returns {callback(e: PurchaseError)}
*/
export function purchaseErrorListener(fn: Function) : EmitterSubscription;
/**
* Request current receipt base64 encoded (IOS only)
* @returns {Promise<string>}
*/
export function requestReceiptIOS(): Promise<string>;