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

# Billing Data Prefill

> Prefill customer billing information in checkout to streamline purchases.

Prefilling billing data reduces friction in the checkout process by automatically populating form fields with customer information you already have.

## Available Fields

| Field      | SDK Property            | HTML Attribute                    | Query Parameter            |
| ---------- | ----------------------- | --------------------------------- | -------------------------- |
| Email      | `billingData.email`     | `data-fungies-billing-email`      | `fngs-customer-email`      |
| First Name | `billingData.firstName` | `data-fungies-billing-first-name` | `fngs-customer-first-name` |
| Last Name  | `billingData.lastName`  | `data-fungies-billing-last-name`  | `fngs-customer-last-name`  |
| Country    | `billingData.country`   | `data-fungies-billing-country`    | `fngs-customer-country`    |
| State      | `billingData.state`     | `data-fungies-billing-state`      | `fngs-customer-state`      |
| City       | `billingData.city`      | `data-fungies-billing-city`       | `fngs-customer-city`       |
| ZIP Code   | `billingData.zipCode`   | `data-fungies-billing-zip-code`   | `fngs-customer-zip-code`   |

<Info>
  The legacy `customerEmail` property and `data-fungies-customer-email` attribute are still supported but deprecated. Use `billingData.email` instead.
</Info>

## Usage Examples

### JavaScript SDK

```javascript theme={null}
Fungies.Checkout.open({
  checkoutUrl: "https://yourstore.fungies.io/checkout-element/abc123",
  settings: { mode: "overlay" },
  billingData: {
    email: "john.doe@example.com",
    firstName: "John",
    lastName: "Doe",
    country: "US",
    state: "CA",
    city: "Los Angeles",
    zipCode: "90001"
  }
});
```

### HTML Data Attributes

```html theme={null}
<button
  data-fungies-checkout-url="https://yourstore.fungies.io/checkout-element/abc123"
  data-fungies-mode="overlay"
  data-fungies-billing-email="john.doe@example.com"
  data-fungies-billing-first-name="John"
  data-fungies-billing-last-name="Doe"
  data-fungies-billing-country="US"
  data-fungies-billing-state="CA"
  data-fungies-billing-city="Los Angeles"
  data-fungies-billing-zip-code="90001">
  Buy Now
</button>
```

### Query Parameters (Hosted Checkout)

```
https://yourstore.fungies.io/checkout/offer-id
  ?fngs-customer-email=john.doe@example.com
  &fngs-customer-first-name=John
  &fngs-customer-last-name=Doe
  &fngs-customer-country=US
  &fngs-customer-state=CA
  &fngs-customer-city=Los%20Angeles
  &fngs-customer-zip-code=90001
```

<Warning>
  Remember to URL-encode values that contain special characters (spaces, `@`, etc.).
</Warning>

## Country Codes

The `country` field accepts ISO 3166-1 alpha-2 country codes:

| Code | Country                                                       |
| ---- | ------------------------------------------------------------- |
| `US` | United States                                                 |
| `GB` | United Kingdom                                                |
| `CA` | Canada                                                        |
| `AU` | Australia                                                     |
| `DE` | Germany                                                       |
| `FR` | France                                                        |
| `PL` | Poland                                                        |
| `JP` | Japan                                                         |
| ...  | [Full list](https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2) |

## State/Province Codes

For countries that require state/province selection (US, Canada, Australia, etc.), use the appropriate subdivision codes:

**United States:**

* `CA` - California
* `NY` - New York
* `TX` - Texas
* etc.

**Canada:**

* `ON` - Ontario
* `BC` - British Columbia
* `QC` - Quebec
* etc.

## Field Visibility

Billing fields are only visible in checkout when:

* Billing information is enabled in your checkout settings, **or**
* Your Stripe account is based in India (required by regulations)

If billing fields are hidden, the prefilled data will still be stored with the order.

## Priority Order

When multiple sources provide billing data, this priority is used:

1. **Query parameters / SDK billingData** - Highest priority
2. **Persisted customer data** - From previous sessions (local storage)
3. **IP-based detection** - Automatic country detection
4. **Default values** - Fallback (e.g., United States)

This ensures that explicitly passed billing data always takes precedence over previously saved data.

## Additional Query Parameters

Beyond billing data, hosted checkout supports these query parameters:

| Parameter            | Description            |
| -------------------- | ---------------------- |
| `fngs-quantity`      | Product quantity       |
| `fngs-discount-code` | Discount code to apply |

### Example with Discount

```
https://yourstore.fungies.io/checkout/offer-id
  ?fngs-customer-email=john@example.com
  &fngs-customer-country=US
  &fngs-discount-code=SAVE20
  &fngs-quantity=2
```
