1. Setup the Server
1.1 Follow the Server Setup Section
Follow the Server Setup section for backend configuration.2. Build Checkout Page on the Client
2.1 Install the switch-js and react-switch-js Libraries
Install the packages and import them into your code:2.2 Add Vaultera Switch to Your React App
Use switch-js to ensure that you stay PCI compliant by sending payment details directly to the Vaultera Switch server:2.3 Load switch-js
CallloadSwitch with your publishable API keys to configure the library. To get a publishable key, please find it here:
For the backend url you can use https://api.switch.vaultera.co for test environment
2.4 Fetch the Payment and Initialize SwitchElements
Immediately make a request to the endpoint on your server to create a new Payment as soon as your checkout page loads. TheclientSecret returned by your endpoint is used to complete the payment:
2.5 Initialize SwitchElements
Pass the promise fromloadSwitch to the SwitchElements component. This allows the child components to access the Switch service via the SwitchElements parent component. Additionally, pass the client secret as options to the SwitchElement component:
2.6 Setup the State (Optional)
Initialize a state to keep track of payment, display errors, and control the user interface:2.7 Store a Reference to Switch
Access the switch-js library in yourCheckoutForm component by using the useSwitch() and useElements() hooks.