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:
- Fetch
Payment Gatewaydocument - If
gateway_controlleris None: Load{gateway} Settingsdoctype - If
gateway_controlleris set: Load document fromgateway_settingsandgateway_controller - 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?