# Creating vendors by referral

In case your platform uses a referral flow to invite vendors to your payments product (for example: an accountant inviting their customers to accept payments via your platform), you should pass information about both the referrer and the referred parties to UNIPaaS upon creation.

## General referral flow

The following describes a typical referral flow, with actions that must be taken on each step:

<table>
  <thead>
    <tr>
      <th>
        User flow
      </th>

      <th>
        Technical steps
      </th>
    </tr>
  </thead>

  <tbody>
    <tr>
      <td>
        A **new** referrer invites a vendor to join your payments product
      </td>

      <td>
        1. Create a vendor for the referrer using a regular [`create vendor`](https://docs.unipaas.com/reference/vendorcontroller_createvendor)' API call. 

        2. Save the referrer's `vendorid` for later

        3. Create the vendor using a [`create vendor`](https://docs.unipaas.com/reference/vendorcontroller_createvendor) API call, add the referrer's `vendorid` to the `referrerVendorId` field. (see example below)
      </td>
    </tr>

    <tr>
      <td>
        An **existing** referrer invites a vendor to join your payments product
      </td>

      <td>
        1. Create the vendor using a [`create vendor`](https://docs.unipaas.com/reference/vendorcontroller_createvendor) API call, add the relevant referrer's `vendorid` to the `referrerVendorId` field. (see example below)
      </td>
    </tr>
  </tbody>
</table>

## Integration example

The following example uses the [`create vendor`](https://docs.unipaas.com/reference/vendorcontroller_createvendor) API call that is used to create all vendors in UNIPaaS.

**1. Creating a referrer**\
Creating a referrer (accountant) profile is exactly same as creating any other vendor:

```json
{
  "firstName": "John",
  "lastName": "Doe",
  "email": "john.doe@example.com",
  "country": "GB",
  "type": "individual"
}
```

The response will include the referrer's `vendorid`, which will be used to link the vendors they invited:

```json
{
  "id": "63ea04cf6d3161e1ba997d52", // Used to connect to invited vendors
  "name": "John Doe",
  "email": "john.doe@example.com",
  "createdAt": "2029-02-13T09:37:19.286Z",
  "updatedAt": "2029-02-13T09:37:19.286Z",
  "merchantId": "62c3ee08f396b3c46e240044"
}
```

**2. Linking an invited vendor to their referrer**

When creating a vendor that was referred by a referrer, use the `referrerVendorId` field to link the vendor with their referrer.

```json
{
  "businessName": "New Vendor",
  "firstName": "John",
  "lastName": "Doe2",
  "email": "john.doe@example.com",
  "country": "GB",
  "phone": "+447911123456",
  "birthDate": "1980-01-01",
  "serviceDescription": "Fast delivery",
  "url": "https://google.com",
  "category": "FOOD_DELIVERY",
  "type": "individual",
  "referrerVendorId":"63ea04cf6d3161e1ba997d52", // Referrer's vendor id 
  "createOnboardingLink": true

}
```
