Skip to content

Gateway integration

Supported gateways

Provider constant Value Class
GatewayProvider::MOBILEPAY mobilepay MobilePayGateway
GatewayProvider::FRISBII frisbii FrisbiiGateway

Frisbii surfaces multiple WooCommerce payment methods: Credit Card, Apple Pay, Google Pay, MobilePay Online, iDEAL, and PayPal.

Using gateways

Never call gateway clients directly from outside the Core layer. Always go through the container-provided services:

// Get agreement service from container
$agreementService = $container->get( AgreementService::class );

// Create an agreement (mandate) for a subscription
$response = $agreementService->createAgreement( $createAgreementRequest );

// Get payment service
$paymentService = $container->get( PaymentService::class );

// Create a recurring payment against an existing agreement
$response = $paymentService->createRecurringPayment( $createRecurringPaymentRequest );

Request factory pattern

Build request objects via the provided factories rather than instantiating them directly:

$factory = $container->get( PaymentRequestFactory::class );
$request = $factory->createCaptureRequest( $payment );

Gateway interface hierarchy

BasePaymentGatewayInterface
├── PaymentGatewayInterface        # create, capture, refund, cancel
├── RecurringPaymentGatewayInterface  # createRecurring, captureRecurring, …
├── AgreementSessionGatewayInterface  # createAgreementSession
└── PaymentSessionGatewayInterface    # createPaymentSession

Both MobilePayGateway and FrisbiiGateway implement the relevant interfaces for their supported operations.

Customer provisioning

Some providers require the customer to exist on their side before an agreement can be created. Agreement adapters for those implement CustomerProvisioningAdapterInterface, which exposes the provider customer handle and the payload used to create the customer.

FrisbiiGateway::ensureCustomerExists() resolves a handle Frisbii will accept — creating the customer when it is missing — and records it on the request, so the payload is built from that same handle. It runs on every path that names the customer: both agreement session types, the standalone charge session, and the payment method import.

Recording the handle needs ResolvedCustomerHandleAwareInterface, which is deliberately separate from CustomerAwareRequestInterface: knowing which customer a request is for is universal, whereas carrying a resolved provider handle is a capability only some providers need. It is checked with instanceof, like CustomerProvisioningAdapterInterface. A request that does not implement it still gets its customer provisioned — it just gets the natural handle, with no escalation, because there would be nowhere to record the result.

Guest orders

A guest has no WooCommerce account, so there is no customer handle to derive and nothing to provision. The customer is named after the order instead, by the adapter. The handle has to be stable for the order — PaymentService::createPayment() creates a fresh session when the amount changes, and a new handle per attempt would leave a trail of customers per order.

The shape and the reasoning behind it are the provider's: Frisbii → Guest handles.

Reading a provider handle back

Handles are built by the adapter, so reading them belongs there too: ProviderHandleAdapterInterface exposes customerHandleBelongsTo() and orderIdFromHandle(), and FrisbiiPaymentAdapter implements them.

Without an inverse, callers improvise, and every improvisation breaks the moment PAYMENTHUB_HANDLE_PREFIX is set — a prefixed handle is neither an integer nor an order id:

(int) 'dev-52'                        // 0, not 52
$payment['order_id'] = 'dev-129614';  // TypeError - the column is int

Both were live in FrisbiiWebhookHandler and made every webhook-created payment fail on an environment with a prefix configured.

The same applies to finding a payment again: order_id is an integer column, so a handle has to be read back before it can be looked up. ext_payment_id stores the handle as it came and remains the fallback.

Importing an existing payment method

Gateways that can adopt a card which already exists at the provider — rather than creating one through a checkout session — implement AgreementImportGatewayInterface. FrisbiiGateway does, by exchanging a one-time token for a permanent payment method reference through POST /v1/payment_method.

The import goes through the same customer provisioning as a normal agreement, so a card can be attached to a customer who has never been through a Frisbii checkout — or whose Frisbii record has been deleted. It is used to migrate cards from a previous provider — see Migrations.

Provider error codes stay in the gateway

ApiException::getErrorCode() carries whatever numeric code the provider sent, because an HTTP status cannot tell two of a provider's errors apart — Frisbii's 106 and 108 are both 400.

The code itself means nothing outside the provider that issued it. PaymentService and everything else in Core/Services serves every registered provider, so a rule such as "106 means there was nothing to cancel" belongs in the gateway, not above it. Put one there and the next provider to implement the same interface inherits it silently.

FrisbiiGateway::cancelPayment() is the worked example: it catches its own 106 ("Invoice must be authorized"), which means there was no reservation to void, and answers 204 — the outcome the caller asked for, reported in terms the service understands. Every other code is rethrown untouched.

Adding a new gateway

See Architecture → Adding a new gateway.