-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.tsx
99 lines (88 loc) · 2.49 KB
/
index.tsx
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
//@ts-ignore
import { NativeModules, Platform } from 'react-native';
const LINKING_ERROR =
`The library 'apple-pay' doesn't seem to be linked. Make sure: \n\n` +
Platform.select({ ios: "- You have run 'pod install'\n", default: '' }) +
'- You rebuilt the app after installing the package\n' +
'\n';
const ApplePayApi = NativeModules.ApplePayApi
? NativeModules.ApplePayApi
: new Proxy(
{},
{
get() {
throw new Error(LINKING_ERROR);
},
},
);
interface ApplePayResponse {
token: string;
success: boolean;
}
export type TAppleCardTypeEnum = '3DS' | 'Debit' | 'Credit';
export interface IApplePay {
amount: number;
charge: number;
total: number;
countryCode: string;
currencyCode: string;
description: string;
title: string;
cardTypes: TAppleCardTypeEnum[];
authToken?: string;
apiUrl?: string;
noApi?: boolean;
isReject?: boolean;
isSimulator?: boolean;
data?: Record<string, any>;
}
export async function getApplePayApi(data: IApplePay): Promise<ApplePayResponse> {
const amount = data.amount;
const charge = data.charge;
const total = data.total;
const countryCode = data.countryCode;
const currencyCode = data.currencyCode;
const description = data.description;
const title = data.title;
const cardTypes = data.cardTypes;
const authToken = data.authToken || undefined;
const apiUrl = data.apiUrl || undefined;
const noApi = data.noApi || false;
const isReject = data.isReject || false;
const isSimulator = data.isSimulator || false;
const extraData = data.data || undefined;
return await ApplePayApi.getApplePayApi(
amount,
charge,
total,
countryCode,
currencyCode,
description,
title,
cardTypes,
authToken,
apiUrl,
noApi,
isReject,
isSimulator,
extraData
);
}
export function canMakePayments(): Promise<boolean> {
return ApplePayApi.canMakePayments();
}
export function canSetupCards(): Promise<boolean> {
return ApplePayApi.canSetupCards();
}
export function navigateToSetup(): Promise<void> {
return ApplePayApi.navigateToSetup();
}
export async function isMakePayment(): Promise<boolean> {
try {
const result = await canMakePayments();
return result;
} catch (error) {
console.error('Error checking payment capability:', error);
return false;
}
}