> ## Documentation Index
> Fetch the complete documentation index at: https://docs.switch.vaultera.co/llms.txt
> Use this file to discover all available pages before exploring further.

# Server Setup

# Server Setup

### Create a payment using S2S Call

To create a payment intent, send a request to either our sandbox or production endpoint. For detailed information, refer to the [**API Reference**](https://docs.switch.vaultera.co/api-reference/payments/payments--create) documentation.

Upon successful creation, you will receive a `client_secret`, which must be provided to the SDK to render it properly.

```javascript theme={"system"}
// Example Usage :- Can be Modified
async function createPaymentIntent() {
    /* Add respective env enpoints
     - Sandbox - https://api.test.switch.vaultera.co
     - Prod - https://api.switch.vaultera.co
    */
    const request = {
        "amount": 1000,
        "currency": "ISK"
    }

    const url = process.env.SWITCH_URL || "https://api.test.switch.vaultera.co";
    const apiResponse = await fetch(`${url}/payments`, {
        method: "POST",
        headers: {
            "Content-Type": "application/json",
            Accept: "application/json",
            "api-key": process.env.API_KEY,
        },
        body: JSON.stringify(request),
    });
    const paymentIntent = await apiResponse.json();

    if (paymentIntent.error) {
        console.error("Error - ", paymentIntent.error);
        throw new Error(paymentIntent?.error?.message ?? "Something went wrong.");
    }
    return paymentIntent;
}
```

*To integrate Web SDK, follow* [*Node And React*](node-and-react.md)*,* [*Node and HTML*](node-and-html.md) *and* [*Vanilla JS and REST API Integration*](vanilla-js-and-rest-api-integration.md)*.*

<Callout type="info">
  In case your integrating the ExpressCheckout (mentioned later below), instead of creating multiple paymentIntents for the same customer session, you can also use [paymentsUpdate API](https://api-reference.switch.vaultera.co/api-reference/payments/payments--update) for better analytics.
</Callout>

*Note: This is full code for reference*

```javascript theme={"system"}
const express = require('express');
const cors = require('cors'); // to allow cross-origin requests
const app = express();
const port = process.env.PORT || 3000;

app.use(cors());
app.use(express.json());

async function createPaymentIntent() {
    /* Add respective env enpoints
     - Sandbox - https://api.test.switch.vaultera.co
     - Prod - https://api.switch.vaultera.co
    */
    const request = {
        "amount": 1000,
        "currency": "ISK"
    }

    const url = process.env.SWITCH_URL || "https://api.test.switch.vaultera.co";
    const apiResponse = await fetch(`${url}/payments`, {
        method: "POST",
        headers: {
            "Content-Type": "application/json",
            Accept: "application/json",
            "api-key": process.env.API_KEY,
        },
        body: JSON.stringify(request),
    });
    const paymentIntent = await apiResponse.json();

    if (paymentIntent.error) {
        console.error("Error - ", paymentIntent.error);
        throw new Error(paymentIntent?.error?.message ?? "Something went wrong.");
    }
    return paymentIntent;
}

app.post('/create-payment', async (req, res) => {
    try {
        const paymentIntent = await createPaymentIntent();
        res.json(paymentIntent);
    } catch (error) {
        res.status(500).json({ error: error.message });
    }
});

app.post('/health', async (req, res) => {
    try {
        res.json({ message: 'Server is running' });
    } catch (error) {
        res.status(500).json({ error: error.message });
    }
});

app.use((err, req, res, next) => {
    console.error(err.stack);
    res.status(500).json({ error: 'Internal server error' });
});

app.listen(port, () => {
    console.log(`Server running on port ${port}`);
});
```
