-
Notifications
You must be signed in to change notification settings - Fork 2
/
app.js
65 lines (56 loc) · 1.92 KB
/
app.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
import Stripe from 'ti.stripe';
const win = Ti.UI.createWindow({
backgroundColor: '#fff',
});
let credentials = {};
win.addEventListener('open', () => initialize());
const button = Ti.UI.createButton({ title: 'Show payment sheet', enabled: false });
button.addEventListener('click', () => action());
win.add(button);
win.open();
async function initialize() {
credentials = await getCredentials();
Stripe.initialize({
publishableKey: credentials.publishableKey
});
}
function action() {
Stripe.showPaymentSheet({
callback: event => {
console.warn(event);
},
merchantDisplayName: 'Test',
customerEphemeralKeySecret: credentials.ephemeralKey,
paymentIntentClientSecret: credentials.paymentIntent,
customerId: credentials.customer,
merchantId: credentials.merchantId, // For Apple Pay Support
merchantCountryCode: credentials.merchantCountryCode, // For Apple / Google Pay Support
googlePayTest:response['stripe_info']['googlePayTest'], // For Google Pay Support, set to True for test environment
// appearance: {
// font: {
// fontFamily: 'PT Mono',
// fontSize: 20
// },
// colors: {
// background: 'red',
// text: 'blue',
// textSecondary: 'green',
// primary: 'yellow'
// }
// }
});
}
function getCredentials() {
return new Promise((resolve, reject) => {
const httpCLient = Ti.Network.createHTTPClient({
onload: function() {
const json = JSON.parse(this.responseText);
button.enabled = true;
resolve(json);
},
onerror: err => console.error(err)
});
httpCLient.open('POST', 'https://stripe-mobile-payment-sheet.glitch.me/checkout');
httpCLient.send()
});
}