Integrations

Integrations

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

Controller Utilities

Core Utility Functions

get_payment_gateway_controller(payment_gateway)

Retrieves gateway controller instance:

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:

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

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

from payments.utils import validate_integration_request

validate_integration_request(token)
# Throws "Expired Token" if integration request is cancelled
Last updated 2 months ago
Was this helpful?
Thanks!