> Source: https://developers.terrawallet.us/docs/sdk/pay-js . Terra Wallet developer docs (early access).

# SDK: pay-js

```bash
# npm install @terrawallet/pay-js (not published yet; name may change)
```

> **Not published.** Today, create the payment intent on your server and redirect the customer to its
> `checkout_url`. See [Hosted checkout](https://developers.terrawallet.us/docs/pay/hosted-checkout.md).

## What it will include

- Checkout as a **modal** or **inline** on your own page, for a payment intent your server created.
- A **subscribe button** for plans.
- The same security rules as hosted checkout: the full address always shown, your payout wallet verified on the
  page, and Terra's prompts impossible to hide or restyle.
- Embedded checkout can be framed only by the origins you allowlist.

## A preview of the shape

```js
// Preview API, not installable. Names may change.
import { TerraPay } from "@terrawallet/pay-js";

document.querySelector("#checkout").addEventListener("click", async () => {
  // Your server creates the payment intent with its secret key and returns the pi_ id.
  const { paymentIntentId } = await fetch("/api/checkout", { method: "POST" }).then((r) => r.json());
  TerraPay.open({ paymentId: paymentIntentId, theme: { mode: "auto" } });
});
```

## The flow that works today

```js
// Works with the v1 API once your account has access: redirect to hosted checkout.
document.querySelector("#checkout").addEventListener("click", async () => {
  const res = await fetch("/api/checkout", { method: "POST" }); // your server endpoint
  const { checkoutUrl } = await res.json();                      // the intent's checkout_url
  window.location.assign(checkoutUrl);
});
```
