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

# Getting Started with Flinks Pay

Complete the following steps to set up Flinks Pay.

1. Set up your environments.

2. Set up your API connection.

3. Add the Flinks Connect iframe to your page.

4. Depending on the payment method you are using, complete one of the following:

   * [Set up Flinks Pay using E-Transfer](./e-transfer/setup-flinks-pay).
   * [Set up Flinks Pay using EFT Debit](./eft/setup-flinks-pay).

5. Go to production.

<Note>
  <p class="h4">Flinks Pay is currently only available in Canada.</p>
</Note>

## Set up your environments

Flinks provides two environments to you when you start the integration process:

* **Sandbox:** a testing space that you use to set up your Flinks integration and test that it's working correctly.
* **Production:** a live production space that allows you to connect real accounts and start using your Flinks product.

### Set up the sandbox environment

Flinks provides you with a Sandbox environment that you can use to try out our products. Use it to test your integration and confirm everything is working as expected.

<Note>
  <p class="h4">Flinks Pay is currently only available in Canada.</p>
</Note>

Here's what to do with it:

1. When you're ready to get started, contact your Flinks Representative and ask them to set you up with a test environment.
2. Flinks provides you with a test institution, Flinks Capital, that you can use for testing purposes. For security and privacy reasons, you can't make live connections to real financial institutions in this environment.
3. Build your integration and connect to our APIs using the Sandbox environment.
4. When you're ready, move over to the Production environment.

### Set up the production environment

Ask your Flinks Representative to set you up with a private Production environment in advance, so that you're ready to go-live when testing is complete.

When the development and testing process in the Sandbox environment is complete, it's time to move your Flinks configuration over to the Production environment. Make sure that all of your API calls and iframe URLs are pointing to your private Production environment and not the Sandbox environment.

Once you go live, you can start connecting to real accounts and experience the full Flinks service.

You can still make requests to Flinks Capital in the Production environment at no cost, but you'll receive an invoice for all successful live requests.

## Set Up Your API Connection

To set up your API Connection with Flinks, you will have to make your first API call before receiving data. The following sections will walk you through this process.

### Make your first API call

This is the first API request that needs to be executed whenever you want to retrieve data from a connected account.

Flinks API needs to confirm the validity of the request and to know which account you want to retrieve data from. To do so, you will exchange your `loginId` for a new `requestId`.

For that, the [/Authorize](../../api/authorize/endpoints/authorize) endpoint needs to be called using a POST method, and it requires a `loginId` and the parameter MostRecentCached:true.

To make it more concrete, let's suppose that you are opening a new session to retrieve the data for the `loginId: 5e115eac-1209-4f19-641c-08d6d484e2fe`:

```curl curl theme={null}
curl -X POST \
  https://toolbox-api.private.fin.ag/v3/43387ca6-0391-4c82-857d-70d95f087ecb/BankingServices/Authorize \
  -H 'Content-Type: application/json' \
  -d '{
	"LoginId":"5e115eac-1209-4f19-641c-08d6d484e2fe",
	"MostRecentCached":true
}'
```

This is how your response will look like:

```json json{ theme={null}
    "Links": [...],
    "HttpStatusCode": 200,
    "Login": {
        "Username": "Greatday",
        "IsScheduledRefresh": false,
        "LastRefresh": "2019-05-09T13:47:46.5227901",
        "Type": "Personal",
        "Id": "5e115eac-1209-4f19-641c-08d6d484e2fe"
    },
    "Institution": "FlinksCapital",
    "RequestId": "1243c283-e0ca-4fda-a5e4-343068430190"
}
```

The `loginId` (`5e115eac-1209-4f19-641c-08d6d484e2fe`) was successfully exchanged for a requestid (1243c283-e0ca-4fda-a5e4-343068430190). Now that the session is active, we have everything we need to place a call to retrieve financial data.

### Receive data from us

The next step is for your server to send a request for data. This request uses the [/GetAccountsDetail](../../api/connect/endpoints/account-linking/get-accounts-detail) endpoint, which also needs to be made using a POST method, and only requires the acquired `requestId`.

Continuing our example using our `requestId` (`1243c283-e0ca-4fda-a5e4-343068430190`), it looks like this:

```curl curl theme={null}
curl -X POST \
  https://toolbox-api.private.fin.ag/v3/43387ca6-0391-4c82-857d-70d95f087ecb/BankingServices/GetAccountsDetail \
  -H 'Content-Type: application/json' \
  -d '{
	"RequestId":"1243c283-e0ca-4fda-a5e4-343068430190"
}'
```

The most common first response to get in a request for data returns an `HTTP 202 FlinksCode:OPERATION_PENDING`, meaning that the data you are requesting is still being processed.

Here's an example of a typical API response for data pending processing:

```json json theme={null}
{
    "FlinksCode": "OPERATION_PENDING",
    "Links": [...],
    "HttpStatusCode": 202,
    "Message": "Your operation is still processing",
    "RequestId": "1243c283-e0ca-4fda-a5e4-343068430190"
}
```

Because of this, your server needs to expect and be able to handle this response and proceed-poll the request (link to async poll code samples) to receive the data, which is described in the next step.

<Warning>
  <p class="h4">When sending requests for data...</p>

  Your integration must handle the 202 OPERATION\_PENDING response.
</Warning>

### Receive pending data

For requests that are still pending for data processing, only the requestId is needed, but the parameter goes directly into the API URL as it's a `GET` request.

While you receive the response `HTTP 202 FlinksCode:OPERATION_PENDING`, you need to keep calling this endpoint every 10 seconds for a maximum of 30 minutes.

```curl Curl theme={null}
curl -X GET \
  https://toolbox-api.private.fin.ag/v3/43387ca6-0391-4c82-857d-70d95f087ecb/BankingServices/GetAccountsDetailAsync/1243c283-e0ca-4fda-a5e4-343068430190 \
  -H 'Content-Type: application/json'
```

<Warning>
  <p class="h4">If you're still receiving 202 OPERATION PENDING</p>

  In case your data is still pending, you need to call this endpoint every 10 seconds for a maximum of 30 minutes. This doesn't mean that your request is going to take that long, but this global timeout is required to avoid infinite loops.
</Warning>

Once your data is done being processed, the API will respond with an HTTP 200 and a JSON payload containing all the data we collected from the financial institution in a standard format. Your app server will be ready to start handling it according to your use case.

```curl Curl theme={null}
{
    "HttpStatusCode": 200,
    "Accounts": [
        {
            "Transactions": [
                {
                    "Date": "2019-04-22",
                    "Code": null,
                    "Description": "national money",
                    "Debit": 12.08,
                    "Credit": null,
                    "Balance": 49993.96,
                    "Id": "633b976e-c713-4b59-9717-3ec407bdde8b"
                },
                {
                    "Date": "2019-04-21",
                    "Code": null,
                    "Description": "TrxChe@Cr12.07",
                    "Debit": null,
                    "Credit": 12.07,
                    "Balance": 50006.04,
                    "Id": "ac25ab22-2828-4174-9653-23bb8918b7c4"
                }
            ],
            "TransitNumber": "77777",
            "InstitutionNumber": "777",
            "OverdraftLimit": 0,
            "Title": "Chequing CAD",
            "AccountNumber": "1111000",
            "Balance": {
                "Available": null,
                "Current": 49993.96,
                "Limit": null
            },
            "Category": "Operations",
            "Type": "Chequing",
            "Currency": "CAD",
            "Holder": {
                "Name": "John Doe",
                "Address": {
                    "CivicAddress": "1275 avenue des Canadiens-de-Montréal",
                    "City": "Montréal",
                    "Province": "QC",
                    "PostalCode": "H3B 5E8",
                    "POBox": null,
                    "Country": "CA"
                },
                "Email": "johndoe@flinks.com",
                "PhoneNumber": "(514) 333-7777"
            },
            "Id": "ae1dac72-70da-4626-fed8-08d682e1ff4a"
        },
        {...}
    ],
    "Login": {
        "Username": "Greatday",
        "IsScheduledRefresh": false,
        "LastRefresh": "2019-05-09T13:47:46.5227901",
        "Type": "Personal",
        "Id": "5e115eac-1209-4f19-641c-08d6d484e2fe"
    },
    "Institution": "FlinksCapital",
    "RequestId": "1243c283-e0ca-4fda-a5e4-343068430190"
}
```

## Add the Flinks Connect iframe to your page

1. Play around with the [Flinks Connect widget](../connect/flinks-connect/widget#flinks-connect-widget) and determine how you want to set it up. This is what your end-users will interact with to link their bank accounts.
2. Generate your code snippet. To do this with the Flinks Connect widget, select Generate.
3. Embed the code snippet into your web page, application, or webview. This adds an iframe with Flinks Connect inside of it:

```html html theme={null}
<!-- Flinks Connect -->
<iframe
  height="760"
  src="https://toolbox-iframe.private.fin.ag/?demo=true&redirectUrl=https://flinks.com/contact/thank-you&innerRedirect=true&consentEnable=true&customerName=FinTech&headerEnable=true&institutionFilterEnable=true"
>
</iframe>

<!-- Event Listener -->
<script>
  window.addEventListener("message", function (e) {
    console.log(e.data);
  });
</script>
```

In the example above, we are using the Sandbox environment. Do all of your configurations and testing in this environment, then change it to your production environment before going live.

If you are integrating the Flinks Connect iframe with React Native, see the [React Native setup instructions](/guides/connect/flinks-connect/add-flinks-connect-iframe#react-native-integration).
