-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.ts
48 lines (45 loc) · 1.42 KB
/
utils.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
import { AndroidApplication, Application, Utils } from "@nativescript/core";
import { PaymentSheet } from './paymentSheet';
//declare const com, Stripe, NSDictionary;
let launchActivityDestroyed = false;
let didInit = false;
export const init = (apiKey: string) => {
if (global.isIOS) {
StripeAPI.setDefaultPublishableKey(apiKey);
}
if (global.isAndroid) {
com.stripe.android.PaymentConfiguration.init(Utils.ad.getApplicationContext(), apiKey);
Application.android.on(AndroidApplication.activityCreatedEvent, (event: any) => {
const activity = event.activity;
if (launchActivityDestroyed || !didInit) {
PaymentSheet._init(activity);
didInit = true;
launchActivityDestroyed = false;
}
});
Application.android.on(AndroidApplication.activityDestroyedEvent, (event: any) => {
const activity = event.activity;
if (activity === Application.android.startActivity) {
launchActivityDestroyed = true;
}
})
}
}
export function toJSON(meta: any, readonly = true) {
if (global.isIOS) {
if (meta instanceof NSDictionary) {
const keys = meta.allKeys;
const count = keys.count;
const json = {};
for (let i = 0; i < count; i++) {
const key = keys.objectAtIndex(i);
json[key] = meta.objectForKey(key);
}
return Object.freeze(json);
}
}
if (readonly) {
return Object.freeze({})
}
return {};
}