Integrations

Integrations

Open in ChatGPT
Ask ChatGPT about this page
Open in Claude
Ask Claude about this page

Global Hooks & Events

Payments app installs framework-wide hooks for integration management.

Document Events

# 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:

# 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:

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

# 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

before_install = "payments.utils.before_install"
after_install = "payments.utils.make_custom_fields"
before_uninstall = "payments.utils.delete_custom_fields"
Last updated 2 months ago
Was this helpful?
Thanks!