> For the complete documentation index, see [llms.txt](https://docs.payr.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.payr.com/payment-interface/payr-sdk/configuration.md).

# Configuration

This page provides the complete reference for configuring the Payr SDK via `PAYR.init()`.

The SDK configuration controls all aspects of the payment experience: which API to connect to, what features to enable, how the UI should look, and how to handle payment outcomes. All payment parameters (amount, reference, features) are set during initialization, making the payment flow simple and consistent.

***

### PAYR.init(config)

Initialize the SDK with your configuration.

<table><thead><tr><th width="135.92578125">Option</th><th width="137.3203125">Type</th><th>Required</th><th width="117.8515625">Default</th><th>Description</th></tr></thead><tbody><tr><td><code>apiBaseUrl</code></td><td><code>string</code></td><td>Yes</td><td>-</td><td>Payr API base URL (no trailing slash)</td></tr><tr><td><code>authToken</code></td><td><code>string</code></td><td>Yes</td><td>-</td><td>Auth token from <code>/user-login/</code> endpoint</td></tr><tr><td><code>container</code></td><td><code>string | HTMLElement</code></td><td>Yes</td><td>-</td><td>CSS selector or DOM element for the payment form</td></tr><tr><td><code>pure_amount</code></td><td><code>number</code></td><td><strong>Required</strong> unless <code>isAmountEditable: true</code></td><td>-</td><td>Base payment amount in <strong>pounds</strong> (e.g., 10.50 for £10.50). </td></tr><tr><td><code>isAmountEditable</code></td><td><code>boolean</code></td><td>No</td><td><code>false</code></td><td>When <code>true</code>, renders an <strong>editable amount input</strong> inside the SDK UI so the user can update the amount within the session. </td></tr><tr><td><code>reference</code></td><td><code>string</code></td><td>No</td><td>-</td><td>Optional payment reference attached to all payments from this session. If omitted, SDK generates <code>PAYR_&#x3C;timestamp></code>.</td></tr><tr><td><code>environment</code></td><td><code>'sandbox' | 'production'</code></td><td>No</td><td><code>'production'</code></td><td>Sandbox for testing, Production for live.</td></tr><tr><td><code>debug</code></td><td><code>boolean</code></td><td>No</td><td><code>false</code></td><td>Enable verbose logging and 3DS verification messages</td></tr><tr><td><code>features</code></td><td><code>object</code></td><td>No</td><td><code>{}</code></td><td>Feature flags (see Features section)</td></tr><tr><td><code>appearance</code></td><td><code>object</code></td><td>No</td><td>Payr defaults</td><td>Theming options for colors, fonts, border radius</td></tr><tr><td><code>onSuccess</code></td><td><code>function</code></td><td>No</td><td>-</td><td>Success callback: <code>(result) => void</code></td></tr><tr><td><code>onError</code></td><td><code>function</code></td><td>No</td><td>-</td><td>Error callback: <code>(error) => void</code></td></tr></tbody></table>

> **Currency:** Always **GBP**. The SDK does not accept a `currency` override.

***

### Amount Behavior

**Fixed Amount (Default):**

The payment amount is set during SDK initialization and remains fixed for the entire session. Users cannot change it.

```javascript
PAYR.init({
  apiBaseUrl: 'https://sandbox-api.mypayr.co.uk',
  authToken: token,
  container: '#payr-payment-form',
  pure_amount: 850.00,  // Fixed amount for this session
  environment: 'sandbox'
});
```

**Editable Amount (Optional):**

Set `isAmountEditable: true` to allow users to enter or change the payment amount in the SDK UI. The payment breakdown updates in real-time as they type.

```javascript
// Empty amount input (user must enter amount)
PAYR.init({
  apiBaseUrl: 'https://sandbox-api.mypayr.co.uk',
  authToken: token,
  container: '#payr-payment-form',
  isAmountEditable: true,  // User can enter/change amount
  environment: 'sandbox'
});

// Pre-filled amount input (user can edit)
PAYR.init({
  apiBaseUrl: 'https://sandbox-api.mypayr.co.uk',
  authToken: token,
  container: '#payr-payment-form',
  pure_amount: 850.00,      // Pre-filled value
  isAmountEditable: true,   // User can change it
  environment: 'sandbox'
});
```

***

### TypeScript Type Safety

`PayrSDKConfig` is a **discriminated union** — TypeScript enforces that `pure_amount` is required unless `isAmountEditable: true`:

```typescript
// ✅ Valid: Fixed amount
PAYR.init({ ..., pure_amount: 10.50 });

// ✅ Valid: Editable amount (empty input)
PAYR.init({ ..., isAmountEditable: true });

// ✅ Valid: Editable amount (pre-filled)
PAYR.init({ ..., isAmountEditable: true, pure_amount: 10.50 });

// ❌ Invalid: Missing pure_amount without isAmountEditable
PAYR.init({ ... }); // TypeScript error
```

***

### Complete Example

```javascript
await PAYR.init({
  // Required
  apiBaseUrl: 'https://sandbox-api.mypayr.co.uk',
  authToken: tokenFromYourBackend,
  container: '#payr-payment-form',
  
  // Amount configuration
  pure_amount: 850.00,      // Fixed amount (£850.00)
  // isAmountEditable: true,  // Uncomment to allow user to change amount
  
  // Environment
  environment: 'sandbox',
  
  // Optional reference
  reference: 'rent-jan-2024',
  
  // Features
  features: {
    apms: true,
    recurring: true,
    applePay: true,
    googlePay: true
  },
  
  // Appearance
  appearance: {
    primaryColor: '#1e3a5f',
    borderRadius: '8px'
  },
  
  // Callbacks
  onSuccess: (result) => {
    console.log('Payment successful:', result);
  },
  onError: (error) => {
    console.error('Payment failed:', error);
  }
});
```

***

### Next Steps

* [**Features**](/payment-interface/payr-sdk/features.md) - Enable payment features (APMs, recurring, wallets)
* [**Payment Flow** ](/payment-interface/payr-sdk/payment-flow.md)- Learn how to trigger payments with `PAYR.pay()`
* [**Customization**](/payment-interface/payr-sdk/customization.md) - Customize colors, fonts, and styling

***

### Support

Need help with SDK configuration? Contact **<support@mypayr.co.uk>**
