-
Notifications
You must be signed in to change notification settings - Fork 2
/
App.jsx
38 lines (34 loc) · 974 Bytes
/
App.jsx
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
import { PayPalScriptProvider } from "@paypal/react-paypal-js";
import { PaymentForm } from "./PaymentForm";
import { useState, useEffect } from "react";
const App = () => {
const [clientToken, setClientToken] = useState(null);
const initialOptions = {
"client-id": "YOUR_PAYPAL_CLIENT_ID",
"data-client-token": clientToken,
components: "hosted-fields,buttons",
"enable-funding": "paylater,venmo",
"data-sdk-integration-source": "integrationbuilder_ac",
};
useEffect(() => {
(async () => {
const response = await fetch("/api/token", {
method: "POST",
});
const { client_token } = await response.json();
setClientToken(client_token);
})();
}, []);
return (
<>
{clientToken ? (
<PayPalScriptProvider options={initialOptions}>
<PaymentForm />
</PayPalScriptProvider>
) : (
<h4>WAITING ON CLIENT TOKEN</h4>
)}
</>
);
};
export default App;