forked from chirag04/react-native-in-app-utils
-
Notifications
You must be signed in to change notification settings - Fork 6
/
index.js
76 lines (59 loc) · 2.27 KB
/
index.js
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
import { NativeEventEmitter, NativeModules, Platform } from "react-native";
const { InAppUtils } = NativeModules;
const InAppUtilsEmitter = new NativeEventEmitter(InAppUtils);
const promisify = fn => (...args) =>
new Promise((resolve, reject) => {
fn(...args, (err, res) => (err ? reject(err) : resolve(res)));
});
const IAU = Platform.select({
ios: {
loadProducts: (products, cb) =>
cb
? InAppUtils.loadProducts(products, cb)
: promisify(InAppUtils.loadProducts)(products),
canMakePayments: cb =>
cb
? InAppUtils.canMakePayments(cb)
: promisify(InAppUtils.canMakePayments)(),
purchaseProduct: (productIdentifier, cb) =>
cb
? InAppUtils.purchaseProduct(productIdentifier, cb)
: promisify(InAppUtils.purchaseProduct)(productIdentifier),
purchaseProductForUser: (productIdentifier, username, cb) =>
cb
? InAppUtils.purchaseProductForUser(productIdentifier, username, cb)
: promisify(InAppUtils.purchaseProductForUser)(
productIdentifier,
username
),
restorePurchases: cb =>
cb
? InAppUtils.restorePurchases(cb)
: promisify(InAppUtils.restorePurchases)(),
restorePurchasesForUser: (username, cb) =>
cb
? InAppUtils.restorePurchasesForUser(username, cb)
: promisify(InAppUtils.restorePurchasesForUser)(username),
receiptData: cb =>
cb ? InAppUtils.receiptData(cb) : promisify(InAppUtils.receiptData)(),
shouldFinishTransactions: (finishTransactions, cb) =>
cb
? InAppUtils.shouldFinishTransactions(finishTransactions, cb)
: promisify(InAppUtils.shouldFinishTransactions)(finishTransactions),
getPurchaseTransactions: cb =>
cb
? InAppUtils.getPurchaseTransactions(cb)
: promisify(InAppUtils.getPurchaseTransactions)(),
finishCurrentTransaction: cb =>
cb
? InAppUtils.finishCurrentTransaction(cb)
: promisify(InAppUtils.finishCurrentTransaction)(),
clearCompletedTransactions: cb =>
cb
? InAppUtils.clearCompletedTransactions(cb)
: promisify(InAppUtils.clearCompletedTransactions)(),
addListener: (...args) => InAppUtilsEmitter.addListener(...args)
},
android: {}
});
export default IAU;