-
Notifications
You must be signed in to change notification settings - Fork 28
/
index.ios.js
85 lines (68 loc) · 2.43 KB
/
index.ios.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
77
78
79
80
81
82
83
84
85
var React = require('react-native');
var NativeModules = React.NativeModules;
var { StripeNativeManager } = NativeModules;
var iOSConstants = {
PKAddressFieldNone: 0,
PKAddressFieldPostalAddress: 1 << 0,
PKAddressFieldPhone: 1 << 1,
PKAddressFieldEmail: 1 << 2,
PKAddressFieldName: 1 << 3,
};
iOSConstants.PKAddressFieldAll =
iOSConstants.PKAddressFieldPostalAddress|
iOSConstants.PKAddressFieldPhone|
iOSConstants.PKAddressFieldEmail|
iOSConstants.PKAddressFieldName;
var Error = {
SNUserCanceled: 1000, // user canceled Apple Pay
SNOtherError: 2000, // misc. error
};
var StripeNativeDomain = "com.lockehart.lib.StripeNative";
var NativeStripe = {
openPaymentSetup: StripeNativeManager.openPaymentSetup,
createTokenWithCard: StripeNativeManager.createTokenWithCard,
success: StripeNativeManager.success,
failure: StripeNativeManager.failure,
init: (stripePublishableKey, applePayMerchantId) => {
return StripeNativeManager.initWithStripePublishableKey(stripePublishableKey, applePayMerchantId);
},
canMakePayments() {
return StripeNativeManager.canMakePayments().then(function (retList) {
// Data always comes back from native as a list. We wrap this method to
// fix that.
return retList[0];
});
},
canMakePaymentsUsingNetworks() {
return StripeNativeManager.canMakePaymentsUsingNetworks().then(function (retList) {
// Data always comes back from native as a list. We wrap this method to
// fix that.
return retList[0];
});
},
paymentRequestWithApplePay(items, merchantName, options) {
options = options || {};
// Set up total as last item
var totalItem = {
label: merchantName,
amount: getTotal(items).toString()
};
// Set amounts as strings
var summaryItems = JSON.parse(JSON.stringify(items));
summaryItems.forEach(function (i) {
i.amount = i.amount.toString();
});
summaryItems.push(totalItem);
return StripeNativeManager.paymentRequestWithApplePay(summaryItems, options);
},
paymentRequestWithCardForm(items) {
return StripeNativeManager.paymentRequestWithCardForm(getTotal(items).toFixed(2).toString());
},
};
function getTotal (items) {
return items.map(i => i.amount).reduce((a,b)=>a+b, 0);
}
NativeStripe.iOSConstants = iOSConstants;
NativeStripe.Error = Error;
NativeStripe.StripeNativeDomain = StripeNativeDomain;
module.exports = NativeStripe;