-
Notifications
You must be signed in to change notification settings - Fork 1
/
App.tsx
70 lines (64 loc) · 1.72 KB
/
App.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
import React from "react";
import { PayButton } from "@candypay/elements-mobile-sdk";
import { StyleSheet, Text, ToastAndroid, View } from "react-native";
import "react-native-get-random-values";
import "react-native-url-polyfill/auto";
import { CandyPay } from "@candypay/checkout-sdk";
export default function App() {
const candypay = new CandyPay({
api_keys: {
public_api_key: "cp_public_3MoKzcFD_8Kj1omMYHxGCgFKyKcg1r7Yk",
private_api_key: "cp_private_Xf3V26ep_GydrbWYamSgZG5o8YCVbstRA",
},
network: "mainnet",
config: {
collect_shipping_address: false,
},
});
const intentHandler = async () => {
const response = await candypay.paymentIntent.create({
tokens: ["shdw"],
items: [
{
name: "Test Product 1",
image: "https://candypay.fun/assets/logo.png",
price: 1,
quantity: 1,
},
],
});
return response;
};
const showToast = (msg: string) => {
ToastAndroid.show(`${msg}`, ToastAndroid.SHORT);
};
return (
<View style={styles.container}>
<Text>Open up App.tsx to start working on your app!</Text>
<PayButton
network="mainnet"
appIdentity={{ name: "My expo app" }}
intentHandler={intentHandler}
onSuccess={() => {
showToast("Success");
}}
onError={(error) => {
showToast(`Error: ${error as unknown as string}`);
}}
/>
</View>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
alignContent: "center",
paddingTop: "50%",
paddingBottom: "50%",
backgroundColor: "#fff",
alignItems: "center",
justifyContent: "center",
width: "80%",
alignSelf: "center",
},
});