# Set up your environment

This topic describes how to set up your Rebilly environment and add data needed to process transactions such as products, pricing plans, customers, and orders.

## Set up a payment gateway

To process transactions, you must have at least one payment gateway configured in your Rebilly account.
If you are testing in the sandbox environment, a test payment gateway called `TestProcessor` is already configured.
For more information, see [Set up a payment gateway](/docs/settings/set-up-a-gateway).

To route transactions dynamically between payment gateways based on real-time data and selected parameters, see [Payment gateway routing](/docs/settings/gateway-routing).

## Configure payment methods

Payment methods that are displayed in payment forms, such as payment cards and digital wallets, are configured when setting up a gateway account.
If you are testing in the sandbox environment, configure payment methods to display in the `TestProcessor` gateway.

- To add a digital wallet, such as Google Pay™, Apple Pay, or Samsung Pay, as a payment method, see [Set up digital wallets](/docs/dev-docs/digital-wallets).
- To add other payment methods, such as ACH, PayPal, and more, see [Set up a payment gateway](/docs/settings/set-up-a-gateway).

To learn how to configure payment methods in forms, such as display order and location-based display, see [Configure payment methods in forms](/docs/settings/payment-methods#configure-payment-methods-in-forms).

## Activate the ready to payout instruction

To process payouts, you must have an active payment gateway with payout settings configured.
This process describes how to activate the ready to payout instruction on the `TestProcessor` payment gateway in the sandbox environment.

The `TestProcessor` payment gateway is automatically configured in the sandbox environment when you sign up to Rebilly.
For more information on payment gateway settings, see [Set up a payment gateway](/docs/settings/set-up-a-gateway).

1. [Log in or sign up to Rebilly](https://app-sandbox.rebilly.com/).
2. In the left navigation bar, press **Settings**.
3. In the **Configuration** section, press **Gateway accounts**.
4. In the **ID** column, press **TestProcessor**.
5. In the right of the page, press **Edit gateway account**.
6. Scroll down to the **Ready to payout instruction** section, and turn on the **Activate this gateway for payouts** toggle.
7. Select one of the following options:
    - **Covered payout:** Process payouts on this gateway only if it previously processed a payment for the same, or a greater, amount.
    - **Approved payments:** Process payouts of any amount on this gateway if the customer has a previously approved transaction, in the same currency, on this gateway.
    - **All payments:** Process payouts of any amount on this gateway.
8. Scroll to the bottom of the page and press **Save gateway account**.

To learn how to configure which payout methods are displayed to customers, see [Configure payout methods displayed to customers](/docs/settings/payment-methods#configure-payout-methods-displayed-to-customers).

## Obtain IDs and API keys

Learn how to get your website ID, organization ID, and API keys in your Rebilly sandbox account.

When you first log in to Rebilly, you create an organization as part of the setup process.
A default website is created when a new organization is created.
For more information, see [Organizations and websites](/docs/settings/organizations-and-websites).

**Obtain your organization ID and website ID**

1. [Log in or sign up to Rebilly](https://app-sandbox.rebilly.com/).
2. In the left navigation bar, press **Settings**.
3. In the **Management** section, press **My organization & websites**.
4. In the **Organization details** section, note the **ID** value.
5. In the **Website** section, note the **ID** value.

**Obtain your publishable API key**

1. [Log in or sign up to Rebilly](https://app-sandbox.rebilly.com/).
2. In the left navigation bar, press **Automations**.
3. In the **Development** section, press **API keys**.
  If you do not have any publishable API keys, see [Create an API key](/docs/dev-docs/api-keys#create-an-api-key).
4. Select a publishable key and copy the **Key** value.

**Obtain your secret API key**

1. [Log in or sign up to Rebilly](https://app-sandbox.rebilly.com/).
2. In the left navigation bar, press **Automations**.
3. In the **Development** section, press **API keys**.
  If you do not have any secret keys, see [Create an API key](/docs/dev-docs/api-keys#create-an-api-key).
4. Select a secret key and copy the **Key** value.

## Configure content security policy

If your website uses a Content Security Policy (CSP), complete this section before you embed payment forms.
This is not required for hosted payment forms.

Embedded forms load content in iframes from two Rebilly domains:

- `framepay.rebilly.com` serves the payment card fields.
  If this domain is not in the `frame-src` directive, the card number, expiration date, and CVV fields do not render.
- `www.secure-payments.app` serves 3D Secure authentication and other approval flows during payment confirmation.
  If this domain is not in the `frame-src` directive, a blank modal is displayed after a customer enters payment details and presses confirm.

To update your CSP:

1. Add `https://*.rebilly.com` and `https://*.secure-payments.app` to the `frame-src` directive.
2. Optionally, if your CSP restricts external scripts or API calls: Add `https://*.rebilly.com` to the `script-src` and `connect-src` directives.
3. Deploy or publish the updated CSP before you test payments.

## Add data to your Rebilly environment

This section describes how to add data to your sandbox environment using the Rebilly API.

### Create a product

This API interaction creates a product in your Rebilly sandbox account.
For more information, see [Create a product](/docs/dev-docs/api/products/postproduct/).

To create a product you must have your Rebilly website ID, organization ID, and secret API key.
For more information, see [Obtain IDs and API keys](#obtain-ids-and-api-keys).

**How to use the interactive example**

1. Enter your organization ID:
    1. Locate and press `server /`, then in the **Server variables** section, press **Edit s**.
    2. In the **Value** field, enter your organization ID and press **Save**.
2. Enter your secret API key:
    1. Press **Security**.
    2. In the **API key** field, enter your secret Rebilly sandbox API key.
      For more information, see [Obtain IDs and API keys](#obtain-ids-and-api-keys).
3. Optionally, to change the product details, press **Body**.
4. Press **Send**.

The `id` value from this response is used in [Create a pricing plan](#create-a-pricing-plan).

### Create a pricing plan

This API interaction creates a pricing plan for a product in your Rebilly sandbox account.
For more information, see [Create a plan](/docs/dev-docs/api/plans/postplan/).

To create a pricing plan, you must have a product ID.
For more information, see [Create a product](#create-a-product).

**How to use the interactive example**

1. Enter your organization ID:
    1. Locate and press `server /`, then in the **Server variables** section, press **Edit s**.
    2. In the **Value** field, enter your organization ID and press **Save**.
2. Enter your secret API key:
    1. Press **Security**.
    2. In the **API key** field, enter your secret Rebilly sandbox API key.
      For more information, see [Obtain IDs and API keys](#obtain-ids-and-api-keys).
3. Enter the product ID from the [Create a product](#create-a-product) response.
    1. Press **Body**.
    2. In the `productId` field, enter the `id` value from the [Create a product](#create-a-product) response.
    3. Optionally, change the plan details.
4. Press **Send**.

### Create a customer

This API interaction creates a customer in your Rebilly sandbox account and also prevents duplicate customers.
If the customer already has an identifier within your system, that customer is updated.
If the customer does not have an identifier, a new customer is created.

For detailed information about this API operation, see [Upsert a customer](/catalog/all/customers/putcustomer).

**How to use the interactive example**

1. Enter your organization ID:
    1. Locate and press `server /`, then in the **Server variables** section, press **Edit s**.
    2. In the **Value** field, enter your organization ID and press **Save**.
2. Enter your secret API key:
    1. Press **Security**.
    2. In the **API key** field, enter your secret Rebilly sandbox API key.
      For more information, see [Obtain IDs and API keys](#obtain-ids-and-api-keys).
3. Enter a customer ID:
    1. Press **Path**.
    2. In the input field, enter a customer ID.
      Example: `cus_01HDP7FFX2PGDVH1995EA4QY95`.
4. Enter your website ID:
    1. Press **Body**.
    2. In the `websiteId` field, enter your website ID.
    3. Optionally, change the customer details.
5. Press **Send**.
  Take note of the `id` value from this response.
  This value is used as the `customerId` later in this tutorial.

### Create an order

This API interaction creates an order in your Rebilly sandbox account.

To create an order, you must have a customer ID and a plan ID.
For more information, see [Create a customer](#create-a-customer) and [Create a pricing plan](#create-a-pricing-plan).

**How to use the interactive example**

1. Enter your organization ID:
    1. Locate and press `server /`, then in the **Server variables** section, press **Edit s**.
    2. In the **Value** field, enter your organization ID and press **Save**.
2. Enter your secret API key:
    1. Press **Security**.
    2. In the **API key** field, enter your secret Rebilly sandbox API key.
      For more information, see [Obtain IDs and API keys](#obtain-ids-and-api-keys).
3. Enter the customer ID, plan ID, and website ID:
    1. Press **Headers**, then in the `Organization-Id` field, enter your organization ID.
    2. Press **Body**.
    3. In the `customerId` field, enter the `id` value from the [create a customer](#create-a-customer) response.
    4. In `items.plan.id`, enter the `id` value from the [create a pricing plan](#create-a-pricing-plan) response.
    5. In the `websiteId` field, enter your website ID.
4. Press **Send**.
