---
title: "Controller Utilities"
space: "Integrations"
url: "https://integrations.frappe.cloud/integrations/payment-integration/payment-core/controller-utilities"
updated: "2026-07-30"
---

## Core Utility Functions

### `get_payment_gateway_controller(payment_gateway)`

Retrieves gateway controller instance:

```python
from payments.utils import get_payment_gateway_controller

# Single instance gateway (gateway_controller is None)
controller = get_payment_gateway_controller("Stripe")
# Returns: Stripe Settings document

# Multi instance gateway (gateway_controller is set)
controller = get_payment_gateway_controller("Stripe-Store1")
# Returns: Specific Stripe Settings record
```

**Logic Flow:**

1. Fetch `Payment Gateway` document
2. If `gateway_controller` is None: Load `{gateway} Settings` doctype
3. If `gateway_controller` is set: Load document from `gateway_settings` and `gateway_controller`
4. Throw exception if settings not found

### `get_checkout_url(**kwargs)`

Guest-accessible checkout URL generation:

```python
@frappe.whitelist(allow_guest=True, xss_safe=True)
def get_checkout_url(**kwargs):
    """Generate checkout URL for guest checkout."""
    doc = frappe.get_doc(f"{kwargs['payment_gateway']} Settings")
    return doc.get_payment_url(**kwargs)
```

### `create_payment_gateway(gateway, settings=None, controller=None)`

Automated payment gateway registration:

```python
# Called from gateway settings on_update
create_payment_gateway(
    gateway="Stripe",
    settings="Stripe Settings",
    controller="default_stripe_account"
)
```

### `validate_integration_request(docname)`

Token validation for expired requests:

```python
from payments.utils import validate_integration_request

validate_integration_request(token)
# Throws "Expired Token" if integration request is cancelled
```