---
title: "Global Hooks & Events"
space: "Integrations"
url: "https://integrations.frappe.cloud/integrations/payment-integration/payment-core/global-hooks-events"
updated: "2026-07-30"
---

Payments app installs framework-wide hooks for integration management.

## Document Events

```python
# In payments/hooks.py
doc_events = {
    "Payment Gateway": {
        "validate": "payment_gateway_enabled"
    }
}
```

## Hook Events

### `payment_gateway_enabled` Gateway Hook

Called when a payment gateway is created or updated:

```python
# In app hooks.py
hook_events = {
    "payment_gateway_enabled": "myapp.utils.gateway_enabled"
}

def gateway_enabled(gateway):
    """Handle payment gateway activation."""
    if gateway == "Stripe":
        configure_stripe_webhooks()
```

### `handle_subscription_notification` Hook

Called for subscription payment webhooks:

```python
hook_events = {
    "handle_subscription_notification": "myapp.subscriptions.handle_notification"
}

def handle_notification(doctype, docname):
    """Process subscription payment notification."""
    integration_request = frappe.get_doc(doctype, docname)
    data = json.loads(integration_request.data)
    # Process subscription payment
```

## Custom Field Management

```python
# In payments/utils/utils.py
def make_custom_fields():
    """Add payment fields to Web Form and other doctypes."""
    create_custom_fields({
        "Web Form": [
            {"fieldname": "accept_payment", "fieldtype": "Check"},
            {"fieldname": "payment_gateway", "fieldtype": "Link"},
            # ... more fields
        ],
        "GoCardless Mandate": [
            {"fieldname": "customer", "fieldtype": "Link", "options": "Customer"}
        ]
    })
```

**Installed Fields:**

- Web Form: Payment acceptance configuration
- GoCardless Mandate: Customer linking (if ERPNext installed)

## Installation Hooks

```python
before_install = "payments.utils.before_install"
after_install = "payments.utils.make_custom_fields"
before_uninstall = "payments.utils.delete_custom_fields"
```