-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.js
96 lines (90 loc) · 2.61 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
import { StatusBar } from "expo-status-bar";
import React, { useEffect, useState } from "react";
import { Button, StyleSheet, Text, View, TextInput } from "react-native";
import { PaymentModule } from "terra-module-js";
let paymentModule = new PaymentModule();
export default function App() {
const [orderCode, setOrderCode] = useState("");
const [orderId, setOrderId] = useState("");
const [amount, setAmount] = useState(0);
useEffect(() => {
// paymentModule
paymentModule
.initPaymentGateway(
"PVSDK1",
"PE1118CC50322",
"RETAIL",
"354deb9bf68088199d8818f71c01951f",
"https://payment.stage.tekoapis.net/"
)
.then((result) => {
if (result.status_code === 200) {
paymentModule.addCashMethod("1", "2", "VNPAY").then((result) => {
console.log(result);
});
paymentModule.addQrMethod("VNPAY").then((result) => {
console.log(result);
});
paymentModule.addSposMethod("4814", "VNPAY").then((result) => {
console.log(result);
});
} else {
alert(result.error);
}
});
}, []);
const startPayment = () => {
if (orderCode === "" || orderId === "" || amount === 0) {
return;
}
paymentModule
.startPayment(orderId, orderCode, "", amount, 1000)
.then((result) => {
switch (result.status_code) {
case 200:
alert("Success " + result.status_code);
break;
case 500:
alert(result.error);
break;
default:
alert(JSON.stringify(result));
}
});
};
return (
<View style={styles.container}>
<TextInput
style={{ borderWidth: 1, width: 200, margin: 10 }}
placeholder="Order code"
onChangeText={setOrderCode}
/>
<TextInput
style={{ borderWidth: 1, width: 200, margin: 10 }}
placeholder="Order id"
onChangeText={setOrderId}
/>
<TextInput
style={{ borderWidth: 1, width: 200, margin: 10 }}
placeholder="Amount"
keyboardType="numeric"
onChangeText={setAmount}
/>
<Button title="Click to pay" onPress={startPayment} />
<Text>
Chú ý: orderId, orderCode cần cung cấp đúng với merchant có yêu cầu bắt
buộc phải tạo đơn thành công
</Text>
<StatusBar style="auto" />
</View>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: "#fff",
alignItems: "center",
justifyContent: "center",
padding: 20,
},
});