-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.js
123 lines (110 loc) · 2.62 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
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
/**
* Sample React Native App
* https://github.com/facebook/react-native
*
* @format
* @flow strict-local
*/
import React from 'react';
import { useState } from 'react';
import type { Node } from 'react';
import { Button } from 'react-native';
import { isAtomeAppInstalled } from 'react-native-atome-paylater';
import { setPaymentUrl } from 'react-native-atome-paylater';
import {
SafeAreaView,
ScrollView,
StatusBar,
StyleSheet,
Text,
useColorScheme,
View,
} from 'react-native';
import {
Colors,
DebugInstructions,
Header,
LearnMoreLinks,
ReloadInstructions,
} from 'react-native/Libraries/NewAppScreen';
const Section = ({ children, title }): Node => {
const isDarkMode = useColorScheme() === 'dark';
return (
<View style={styles.sectionContainer}>
<Text
style={[
styles.sectionTitle,
{
color: isDarkMode ? Colors.white : Colors.black,
},
]}>
{title}
</Text>
<Text
style={[
styles.sectionDescription,
{
color: isDarkMode ? Colors.light : Colors.dark,
},
]}>
{children}
</Text>
</View>
);
};
const App: () => Node = () => {
const isDarkMode = useColorScheme() === 'dark';
const backgroundStyle = {
backgroundColor: isDarkMode ? Colors.darker : Colors.lighter,
};
const [result, setResult] = useState('No');
const init = async () => {
const installed = await isAtomeAppInstalled();
console.log(installed);
setResult(actualResult => installed ? 'Yes' : 'No')
};
const demoHandlePaymantUrl = () => {
fetch('https://demo-app-test.apaylater.net/api/orders', {
method: 'POST',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
},
body: JSON.stringify({
amount: 1234,
currency: 'SGD',
paymentResultUrl: 'atomedemo://appdemo.apaylater.net'
})
}).then(response => {
if (response.ok) return response.json();
throw response;
})
.then(json => {
setPaymentUrl(json.data.appPaymentUrl);
}).catch(err => {
console.error(err);
});
}
React.useEffect(() => {
init();
}, []);
return (
<View style={styles.container}>
<Text>Is Atome App Installed? {result}</Text>
<Text></Text>
<Button
onPress={demoHandlePaymantUrl}
title="Open Atome with payment URL"
color="#841584"
/>
</View>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
alignItems: 'center',
justifyContent: 'center',
}
});
export default App;