# Sign-up

Let a business customer register through Briqpay without making a purchase. Your backend creates a sign-up session, your page shows it, and a webhook and Read session give you the customer's details once they finish.

With a sign-up session, Briqpay collects a customer's details and registers them. There is no cart and no payment.

The flow follows the same three steps as the [Payment Module](https://developer.briqpay.com/docs/payment-module.md): your backend creates a session, your page shows it, and Briqpay tells you when it is done.

## How it works

1. **Your backend creates a session** with `product.type` set to `signup`.
2. **Your page shows the sign-up.** The session comes with an HTML snippet that embeds Briqpay's iFrame.
3. **The customer completes the sign-up.** Briqpay marks the session `completed`, redirects the customer to your page and sends a `session_status` webhook.
4. **Your backend reads the session** to get the customer's details.

```sequence title="A sign-up from start to finish"
lanes: Customer, Your page, Your backend, Briqpay
Customer -> Your page: Visits your registration page
Your backend -> Briqpay: Create session with product.type signup
Briqpay --> Your backend: sessionId and htmlSnippet
Your backend -> Your page: Show the htmlSnippet
Customer -> Briqpay: Fills in the details and submits
Briqpay -> Your page: Redirect to urls.redirect
Briqpay -> Your backend: session_status webhook
Your backend -> Briqpay: Read session
Briqpay --> Your backend: Status and the customer's data
```

## Before you start

You need API credentials for the playground. Get them by registering in the [Merchant Portal](https://app.briqpay.com). See [Authentication](https://developer.briqpay.com/docs/authentication.md) for the details.

Sign-up also has to be set up for your account in Briqpay, and `country` must be one of your markets.

Every request uses HTTP Basic authentication, with your merchant ID as the username and your secret as the password:

```http title="Authentication"
Authorization: Basic <base64(merchantId:secret)>
```

| Environment | Base URL                             |
| ----------- | ------------------------------------ |
| Playground  | `https://playground-api.briqpay.com` |
| Production  | `https://api.briqpay.com`            |

## 1. Create a session

Call [Create session](https://developer.briqpay.com/api-reference/create-session.md) from your backend when the customer reaches your registration page. Never call the API from the browser: the request carries your secret.

```bash title="cURL"
curl -X POST 'https://playground-api.briqpay.com/v3/session' \
  -H 'Authorization: Basic <base64(merchantId:secret)>' \
  -H 'Content-Type: application/json' \
  -d '{
  "product": { "type": "signup", "intent": "signup" },
  "customerType": "business",
  "country": "SE",
  "locale": "sv-se",
  "urls": {
    "redirect": "https://example.com/redirect"
  },
  "hooks": [
    {
      "eventType": "session_status",
      "statuses": ["completed"],
      "method": "POST",
      "url": "https://example.com/notifications"
    }
  ]
}'
```

These fields are required: `product`, `customerType`, `country`, `locale` and `urls.redirect`. Unlike a payment session, a sign-up session doesn't need `urls.terms`.

- `product.type` is `signup`. `product.intent` is optional, but if you send it, it must be `signup`. A payment intent is rejected with a `400`.
- `customerType` is `business` or `consumer`. This guide covers business customers.
- `hooks` can only hold `session_status` events for a sign-up session. Any other event type is rejected with a `400`.

The response (`201`) is the full session. You need two of its fields:

- `sessionId`: store it. You need it to read the session.
- `htmlSnippet`: the HTML that shows the sign-up on your page.

## 2. Show the sign-up

Put the `htmlSnippet` where the sign-up belongs on your page. Give it at least 640 pixels of width on desktop, and as much width as possible on mobile.

The snippet also loads Briqpay's JS SDK. If you insert the snippet with JavaScript instead of in your server-rendered HTML, add the SDK to your page's `<head>` yourself:

```html title="HTML"
<script async src="https://api.briqpay.com/briq.min.js" id="briq-sdk"></script>
```

The [SDK guide](https://developer.briqpay.com/docs/sdk.md) covers the SDK in full.

## 3. Handle the completed session

When the customer submits the sign-up, the session gets the status `completed`. Two things happen:

- The customer's browser is sent to your `urls.redirect`. Briqpay redirects the top window of the page, not just the iFrame. To handle the redirect yourself, set `config.disableSessionCompleteRedirect` to `true` when you create the session.
- Briqpay sends the `session_status` webhook to the URL in your `hooks`.

`completed` is the only status a `session_status` hook can have, and `statuses` is required: a hook without it is rejected. The webhook has `event`, `status` and `sessionId`, plus your `references` as top-level fields. With `POST` it is the request body. With `GET` the same fields are query parameters.

```json title="session_status webhook"
{
  "event": "session_status",
  "status": "completed",
  "sessionId": "61c16f84-b42e-4e1c-a114-a117a6e1e27d"
}
```

The webhook only tells you that the session is complete. It carries none of the customer's data. Webhooks can arrive more than once, and you should check that they came from Briqpay. Both are covered in [Webhooks](https://developer.briqpay.com/docs/payment-module.md#webhooks).

## 4. Read the customer's data

Call [Read session](https://developer.briqpay.com/api-reference/read-session.md) with the `sessionId`, after the redirect or when the webhook arrives. Use the webhook as the trigger and treat the redirect only as the customer's return to your site.

```bash title="cURL"
curl 'https://playground-api.briqpay.com/v3/session/<sessionId>' \
  -H 'Authorization: Basic <base64(merchantId:secret)>'
```

Once the session is complete, the customer's data is in `data`. Each object is only present when Briqpay holds that data:

| Field                | What it holds                                                                 |
| -------------------- | ----------------------------------------------------------------------------- |
| `data.company`       | `cin` (company number), `name` and, with some lookup providers, `vatNumber`   |
| `data.billing`       | Contact details and address, including `companyName` and `cin` for businesses |
| `data.shipping`      | Delivery address, if the sign-up collected one                                |
| `data.vatValidation` | The VAT number the customer gave (`vatNo`), whether it is valid (`valid`), and the session's `country` |

Answers to a custom form, an order note or terms checkboxes you configured are returned in `data.customForm1`, `data.orderNote` and `data.terms`.

> [!NOTE]
> Which details a customer is asked for depends on the steps set up for your sign-up in Briqpay, not on your request. Always check for missing values.
