Payments

Last updated: 2026-11-26

Canvas includes a modular payment system built around PaymentRouter, which discovers installed payment provider packages automatically and routes payment operations to the correct provider based on the paymentModule field.

explanation

Core Concepts

  • PaymentRouter — Discovers installed provider packages via composer metadata and routes initiate(), refund(), chargeRecurring(), and getPaymentOptions() calls to the correct provider based on the paymentModule field.
  • PaymentInterface — The contract every provider package implements.
  • Driver — A concrete provider implementation (e.g. Quellabs\Payments\Mollie\Driver). Registered automatically when its package is installed.
  • paymentModule — A string identifier that selects both the provider and the payment method, e.g. 'mollie_ideal' or 'mollie_creditcard'.
  • Mandate — A customer's authorization for off-session recurring charges, created the first time they complete a payment with sequenceType: SequenceType::First. See Recurring Payments.

Installation

Install the router and at least one provider package:

composer require quellabs/canvas-payments
composer require quellabs/canvas-payments-mollie

PaymentRouter scans installed packages for a provider entry in their composer metadata and registers them automatically.

Supported Providers

The following provider packages are available:

ProviderPackageRecurringSettlements
Adyenquellabs/canvas-payments-adyen——
Buckarooquellabs/canvas-payments-buckaroo——
Klarnaquellabs/canvas-payments-klarna——
Molliequellabs/canvas-payments-mollie✓✓
MultiSafepayquellabs/canvas-payments-multisafepay——
Pay.nlquellabs/canvas-payments-paynl——
PayPal (REST)quellabs/canvas-payments-paypal——
PayPal Express (NVP)quellabs/canvas-payments-paypal-express——
Rabobank Smart Payquellabs/canvas-payments-rabosmartpay——
Stripequellabs/canvas-payments-stripe——
Xpayquellabs/canvas-payments-xpay——

See Recurring Payments and Fetching Settlements for details. Providers without support throw PaymentInitiationException / PaymentMandateException when chargeRecurring(), getMandates(), or revokeMandate() are called — getSettlement(), getSettlementPayments(), getSettlementRefunds(), getSettlementChargebacks(), and listSettlements() throw PaymentSettlementException instead.

Publishing the config file

Each driver requires its own config file for API credentials and settings. Run the corresponding command to publish it to /config:

CommandDescription
sculpt adyen:initPublish config/adyen.php
sculpt buckaroo:initPublish config/buckaroo.php
sculpt klarna:initPublish config/klarna.php
sculpt mollie:initPublish config/mollie.php
sculpt multisafepay:initPublish config/multisafepay.php
sculpt paynl:initPublish config/paynl.php
sculpt paypal:initPublish config/paypal.php
sculpt paypal-express:initPublish config/paypal-express.php
sculpt rabosmartpay:initPublish config/rabosmartpay.php
sculpt stripe:initPublish config/stripe.php
sculpt xpay:initPublish config/xpay.php

Initiating a Payment

Inject PaymentRouter via Canvas DI and call initiate() with a PaymentRequest:

use Quellabs\Payments\Contracts\PaymentInterface;
use Quellabs\Payments\Contracts\PaymentRequest;
use Quellabs\Payments\Contracts\PaymentInitiationException;

class CheckoutService {

    public function __construct(private PaymentInterface $router) {}

    public function startPayment(): string {
        $request = new PaymentRequest(
            paymentModule: 'mollie_ideal',
            amount:        999,   // in minor units — €9.99
            currency:      'EUR',
            description:   'Order #12345',
            issuerId:      'ideal_INGBNL2A',
        );

        try {
            $result = $this->router->initiate($request);

            // Redirect the customer to the payment page
            return $result->redirectUrl;
        } catch (PaymentInitiationException $e) {
            // handle error
        }
    }
}

All amounts are in minor units. 999 represents €9.99, 2500 represents €25.00.

Minor units per currency

Minor units follow the ISO 4217 number of decimals for the currency, the same for every provider. Most currencies have 2 decimals, so the amount is in cents. Zero-decimal currencies such as JPY and ISK have no minor unit: 1000 is ¥1000. Three-decimal currencies such as KWD use thousandths: 1500 is 1.500 KWD.

To convert between major and minor units, use CurrencyDecimals:

use Quellabs\Payments\Contracts\CurrencyDecimals;

CurrencyDecimals::toMinorUnits(9.99, 'EUR');     // 999
CurrencyDecimals::toMinorUnits(1000.0, 'JPY');   // 1000
CurrencyDecimals::toMajorUnits(999, 'EUR');      // 9.99
CurrencyDecimals::formatMajorUnits(999, 'EUR');  // "9.99"
CurrencyDecimals::decimals('KWD');               // 3

PayPal (REST and Express) does not accept fractions of HUF, JPY or TWD. An HUF or TWD amount with a fractional part, such as 100050 (1000.50 HUF), is rejected with PaymentInitiationException or PaymentRefundException and error id invalid_amount.

Handling Webhook Events

When a payment status changes, the provider's webhook controller emits a payment_exchange signal carrying a PaymentState object. Listen for it using the @ListenTo annotation on any Canvas-managed class:

use Quellabs\Canvas\Annotations\ListenTo;
use Quellabs\Payments\Contracts\PaymentState;
use Quellabs\Payments\Contracts\PaymentStatus;

class OrderService {

    /**
     * @ListenTo("payment_exchange")
     */
    public function onPaymentExchange(PaymentState $state): void {
        match ($state->state) {
            PaymentStatus::Paid     => $this->markPaid($state->transactionId, $state->valuePaid),
            PaymentStatus::Canceled => $this->markCanceled($state->transactionId),
            PaymentStatus::Expired  => $this->markExpired($state->transactionId),
            PaymentStatus::Refunded => $this->handleRefund($state),
            default                 => null,
        };
    }
}

Canvas wires the listener automatically. The payment_exchange signal carries only state — database handling belongs to your application.

On PaymentStatus::Paid events, some providers include a paymentReference in the metadata array. When present, this value must be used as the paymentReference in any subsequent RefundRequest instead of the transactionId. Your application is responsible for persisting it alongside the transaction:

PaymentStatus::Paid => $this->markPaid(
    $state->transactionId,
    $state->valuePaid,
    $state->metadata['paymentReference'] ?? null,  // store this if present — required for refunds
),

Issuing a Refund

Call refund() with a RefundRequest. Omitting amount (or passing null) will refund the full payment amount:

use Quellabs\Payments\Contracts\RefundRequest;
use Quellabs\Payments\Contracts\PaymentRefundException;

try {
    $result = $this->router->refund(new RefundRequest(
        paymentReference: 'tr_7UhSN1zuXS',
        paymentModule: 'mollie_ideal',
        amount:        500,   // in minor units — €5.00
        currency:      'EUR',
        description:   'Partial refund for order #12345',
    ));

    echo $result->refundId;
} catch (PaymentRefundException $e) {
    // handle error
}

Fetching Refunds

Retrieve all refunds issued for a payment by calling getRefunds(), resolved by driver name — like exchange(), getMandates(), and revokeMandate(). Note that not all providers expose refund retrieval — check your provider's documentation before relying on this method.

use Quellabs\Payments\Contracts\PaymentInterface;
use Quellabs\Payments\Contracts\PaymentRefundException;

class RefundReportService {

    public function __construct(private PaymentInterface $router) {}

    public function getRefunds(string $driver, string $paymentReference): array {
        try {
            return $this->router->getRefunds($driver, $paymentReference); // array of RefundResult
        } catch (PaymentRefundException $e) {
            // handle error
        }
    }
}

Fetching Settlements

Retrieve a settlement/payout batch, and the individual payments included in it, by calling getSettlement() and getSettlementPayments(), resolved by driver name — like exchange(), getMandates(), and revokeMandate(). Currently only Mollie implements this; every other provider throws PaymentSettlementException with a "not supported" message.

use Quellabs\Payments\Contracts\PaymentInterface;
use Quellabs\Payments\Contracts\PaymentSettlementException;

class SettlementReportService {

    public function __construct(private PaymentInterface $router) {}

    public function reportSettlement(string $settlementId): void {
        try {
            $settlement = $this->router->getSettlement('mollie', $settlementId);
            $payments   = $this->router->getSettlementPayments('mollie', $settlementId); // array of SettlementPaymentInfo

            echo $settlement->reference . ' — ' . $settlement->status->value . ' — ' . $settlement->amount;

            foreach ($payments as $payment) {
                echo $payment->paymentReference . ' — ' . $payment->amount;
            }
        } catch (PaymentSettlementException $e) {
            // handle error
        }
    }
}

$settlementId accepts either the provider's own settlement id, or — for Mollie — the bank-statement reference string it prints on the payout line (e.g. "1234567.2404.03"). Payment amounts returned by getSettlementPayments() are the gross, pre-fee amount — the provider's fee has not yet been netted out.

Refunds and Chargebacks in a Settlement

Refunds and chargebacks deducted from a settlement are fetched with getSettlementRefunds() and getSettlementChargebacks(), resolved by driver name like getSettlementPayments(). Both return every item in the settlement in a single call.

use Quellabs\Payments\Contracts\PaymentInterface;
use Quellabs\Payments\Contracts\PaymentSettlementException;

class SettlementDeductionsService {

    public function __construct(private PaymentInterface $router) {}

    public function reportDeductions(string $settlementId): void {
        try {
            $refunds     = $this->router->getSettlementRefunds('mollie', $settlementId);     // array of SettlementRefundInfo
            $chargebacks = $this->router->getSettlementChargebacks('mollie', $settlementId); // array of SettlementChargebackInfo

            foreach ($refunds as $refund) {
                echo $refund->refundId . ' for ' . $refund->paymentReference . ' — ' . $refund->amount . ' ' . $refund->currency;
            }

            foreach ($chargebacks as $chargeback) {
                echo $chargeback->chargebackId . ' for ' . $chargeback->paymentReference . ' — ' . $chargeback->amount;
            }
        } catch (PaymentSettlementException $e) {
            // handle error
        }
    }
}

Amounts are in minor units and always positive: they are the amount refunded to, or charged back by, the customer.

PropertyTypeDescription
SettlementRefundInfo
refundIdstringProvider's identifier for the refund
paymentReferencestringPayment the refund was made for
amountintAmount refunded, in minor units
currencystringISO 4217 currency code
descriptionstringRefund description; empty when there is none
statusstringRaw provider status (Mollie: 'refunded' or 'failed')
createdAt?\DateTimeImmutableWhen the refund was created
metadataarrayMetadata attached to the refund
SettlementChargebackInfo
chargebackIdstringProvider's identifier for the chargeback
paymentReferencestringPayment that was charged back
amountintAmount charged back, in minor units
currencystringISO 4217 currency code
reasonCode?stringBank reason code (e.g. SEPA 'AC01'), or null
reasonDescription?stringHuman-readable reason, or null
createdAt?\DateTimeImmutableWhen the chargeback was created
reversedAt?\DateTimeImmutableWhen the chargeback was reversed, or null

Both classes also carry provider and settlementId. Mollie gives a chargeback reason only for SEPA Direct Debit payments; for other payment methods reasonCode and reasonDescription are null.

Discovering New Settlements

getSettlement() and getSettlementPayments() both require an already-known settlement id. To discover settlements you haven't seen yet — e.g. a scheduled job reconciling payouts against your own records — call listSettlements() instead. It's resolved by driver name like the methods above, but unlike them it doesn't hide pagination: it returns one page of settlements at a time as a SettlementListResult, carrying an opaque nextCursor you pass back on the next call.

use Quellabs\Payments\Contracts\PaymentInterface;
use Quellabs\Payments\Contracts\PaymentSettlementException;

class SettlementDiscoveryService {

    public function __construct(private PaymentInterface $router) {}

    public function discoverNewSettlements(): void {
        $cursor = null;

        try {
            do {
                $page = $this->router->listSettlements('mollie', $cursor, limit: 50);

                foreach ($page->settlements as $settlement) {
                    if (!$this->alreadyImported($settlement->settlementId)) {
                        $this->import($settlement);
                    }
                }

                $cursor = $page->nextCursor;
            } while ($cursor !== null);
        } catch (PaymentSettlementException $e) {
            // handle error
        }
    }
}

$cursor is opaque — store and pass it back exactly as returned, never parse or construct it yourself. $limit is a provider-specific upper bound on page size (Mollie accepts 1–250, default 50). Sort order is not part of the contract — don't assume newest-first or oldest-first; check the specific provider's documentation before writing discovery logic that depends on it. Currently only Mollie implements listSettlements(); every other provider throws PaymentSettlementException with a "not supported" message, same as getSettlement().

Recurring Payments

Some providers support billing a customer again later without any further customer interaction, using a saved mandate (SEPA direct debit, a tokenized card, etc.). Currently only Mollie implements this; on every other provider the recurring methods throw PaymentInitiationException / PaymentMandateException with a "not supported" message. Check the provider's README before relying on it.

The flow has three steps:

  1. A first payment — a normal initiate() redirect, but flagged so the provider creates a customer and, once completed, attaches a mandate to it.
  2. Any number of recurring charges against that mandate, initiated server-side with no redirect — e.g. from a scheduled job.
  3. Optionally, revoking the mandate once the customer should no longer be billed.

1. First payment — create a customer and mandate

Pass sequenceType: SequenceType::First on the PaymentRequest. If you don't already have a provider customer id, leave customerReference unset — the provider creates one automatically (Mollie sources the name/email from billingAddress). Persist InitiateResult::$customerReference from the response; you'll need it for every recurring charge and mandate lookup afterwards.

use Quellabs\Payments\Contracts\PaymentInterface;
use Quellabs\Payments\Contracts\PaymentRequest;
use Quellabs\Payments\Contracts\SequenceType;
use Quellabs\Payments\Contracts\PaymentInitiationException;

class SubscriptionService {

    public function __construct(private PaymentInterface $router) {}

    public function startSubscription(): string {
        $request = new PaymentRequest(
            paymentModule:  'mollie_ideal',
            amount:         999,   // in minor units — €9.99
            currency:       'EUR',
            description:    'Subscription setup',
            billingAddress: $address, // used to create the provider customer
            sequenceType:   SequenceType::First,
        );

        try {
            $result = $this->router->initiate($request);

            // Persist $result->customerReference on the user/subscription record
            $this->persistCustomerReference($result->customerReference);

            return $result->redirectUrl;
        } catch (PaymentInitiationException $e) {
            // handle error
        }
    }
}

The customer completes this payment like any other initiate() flow — status still arrives via the regular payment_exchange signal.

2. Charging the mandate

Call chargeRecurring() with a RecurringChargeRequest, resolved by paymentModule just like initiate(). There is no browser involved — InitiateResult::$redirectUrl is always null on the result, and the resulting payment's status is delivered through the same payment_exchange signal as any other payment.

use Quellabs\Payments\Contracts\RecurringChargeRequest;
use Quellabs\Payments\Contracts\PaymentInitiationException;

$request = new RecurringChargeRequest(
    paymentModule:     'mollie_ideal',
    customerReference: $customerReference,
    amount:            999,   // in minor units — €9.99
    currency:          'EUR',
    description:       'Subscription renewal',
);

try {
    $result = $this->router->chargeRecurring($request);
    // $result->redirectUrl is always null — wait for the payment_exchange signal
} catch (PaymentInitiationException $e) {
    // handle error
}

3. Inspecting and revoking mandates

getMandates() and revokeMandate() are resolved by driver name, like exchange() and getRefunds():

use Quellabs\Payments\Contracts\PaymentMandateException;

try {
    $mandates = $this->router->getMandates('mollie', $customerReference); // array of MandateInfo

    foreach ($mandates as $mandate) {
        echo $mandate->mandateId . ' — ' . $mandate->status->value;
    }

    // Prevent any further recurring charges against a mandate
    $this->router->revokeMandate('mollie', $customerReference, $mandate->mandateId);
} catch (PaymentMandateException $e) {
    // handle error
}

Scheduling when to charge, and persisting customerReference/mandate ids per user, is your application's responsibility — the payment package only wraps the provider's API calls.

Payment Options

Some payment methods expose issuer or bank selection (iDEAL, KBC, gift cards). Fetch available options to present to the customer before initiating payment:

use Quellabs\Payments\Contracts\PaymentException;

try {
    $issuers = $this->router->getPaymentOptions('mollie_ideal');

    foreach ($issuers as $issuer) {
        echo $issuer['name'] . ' — ' . $issuer['id'];
    }
} catch (PaymentException $e) {
    // handle error
}

Methods without issuer selection return an empty array.

Payment State

PaymentState is emitted via the payment_exchange signal on every webhook hit.

PropertyTypeDescription
providerstringProvider identifier, e.g. 'mollie'
transactionIdstringProvider-assigned transaction ID
statePaymentStatusCurrent payment state
internalStatestringRaw status string from the provider
valuePaidintTotal amount paid in minor units
valueRefundedintTotal amount refunded so far in minor units
currencystringISO 4217 currency code
metadataarrayMetadata passed through from the original request
failureReason?stringProvider's own failure reason for a non-successful payment, or null if not applicable/unknown
mandateId?stringMandate this payment was charged against, or null if not a mandate-based charge/unknown

Currently only Mollie populates failureReason and mandateId; other providers leave both null.

Payment Statuses

StatusDescription
PaymentStatus::PendingPayment is open or pending
PaymentStatus::PaidPayment completed successfully
PaymentStatus::CanceledCustomer canceled — definitive
PaymentStatus::ExpiredCustomer abandoned, or bank transfer timed out
PaymentStatus::FailedPayment failed and cannot be retried
PaymentStatus::RefundedPayment was refunded
PaymentStatus::RedirectPayment requires a redirect to an external page
PaymentStatus::UnknownUnrecognised status from the provider

Discovering Registered Modules

Retrieve all payment module identifiers currently registered across all installed providers:

$modules = $this->router->getRegisteredModules();
// ['mollie', 'mollie_ideal', 'mollie_creditcard', ...]

Adding a Provider Package

Any package can register itself as a payment provider by declaring a provider entry in its composer.json:

"extra": {
    "discover": {
        "payments": {
            "provider": "Quellabs\\Payments\\Mollie\\Driver",
            "config": "/config/mollie.php"
        }
    }
}

The declared class must implement PaymentProviderInterface, which includes chargeRecurring(), getMandates(), revokeMandate(), getSettlement(), getSettlementPayments(), getSettlementRefunds(), getSettlementChargebacks(), and listSettlements() alongside initiate(), refund(), and getPaymentOptions(). PaymentRouter validates this at discovery time and silently skips any class that does not implement it. If your provider doesn't support recurring payments or settlements, implement these methods by throwing PaymentInitiationException / PaymentMandateException (recurring/mandates) or PaymentSettlementException (settlements) rather than omitting them — see the existing provider packages for the expected message format. If two installed packages declare the same module identifier, a RuntimeException is thrown at boot.

Frequently Asked Questions

How does PaymentRouter decide which installed provider handles a given payment?

By the paymentModule field on the request. At construction, PaymentRouter discovers every installed provider package via composer metadata and builds a map from each provider's declared module names to its class; initiate(), refund(), and chargeRecurring() all resolve the correct provider from that map using the module string you pass.

What happens if a provider package is misconfigured — wrong interface, or a module name collision?

A class that doesn't implement PaymentProviderInterface is silently skipped during discovery. Two installed packages declaring the same module identifier, though, is treated as a configuration error — PaymentRouter throws a RuntimeException as soon as it detects the collision while building its module map.

What happens if I call chargeRecurring() or getMandates() on a provider that doesn't support recurring payments?

Currently only Mollie implements the recurring/mandate flow. Every other provider's implementation of chargeRecurring(), getMandates(), and revokeMandate() throws PaymentInitiationException or PaymentMandateException with a "not supported" message rather than silently doing nothing — check the specific provider's README before relying on recurring charges.

Do I need to poll for payment status, or does it always arrive via webhook?

Status updates normally arrive through the payment_exchange signal, fired whenever the provider's webhook controller receives an update — no polling needed for the common case. For reconciling a webhook that was missed, PaymentRouter also exposes exchange($driver, $transactionId) to fetch a payment's current state directly from the provider on demand.

Can I show method-specific options, like iDEAL bank selection, before initiating a payment?

Yes — call getPaymentOptions($paymentModule) to fetch the issuer/option list for a given module and present it to the customer before calling initiate(). Payment methods that don't have this kind of sub-selection just return an empty array.

Is the value I use for a refund always the original transactionId?

Not necessarily. Some providers include a paymentReference in the payment_exchange signal's metadata array on PaymentStatus::Paid — when present, that value must be used as paymentReference on the RefundRequest instead of transactionId. Your application is responsible for persisting it alongside the transaction when it's provided.

What happens if I call getSettlement(), getSettlementPayments(), getSettlementRefunds(), getSettlementChargebacks(), or listSettlements() on a provider that doesn't support settlements?

Currently only Mollie implements settlement fetching and discovery. Every other provider's implementation throws PaymentSettlementException with a "not supported" message rather than returning an empty result — check the specific provider's README before relying on it.

Does listSettlements() return settlements newest-first or oldest-first?

Sort order isn't guaranteed by the contract and is provider-specific — check the provider's documentation before writing discovery logic (e.g. "stop once I see a settlement I've already imported") that depends on a particular order. Don't infer it from an unrelated list method's documented order; it may differ.

How do I pass an amount in a currency without cents, such as JPY?

Pass the amount in the currency's ISO 4217 minor units, the same for every provider. JPY and ISK have no minor unit, so amount: 1000 charges ¥1000. Use CurrencyDecimals::toMinorUnits() to convert a major-unit price for any currency. See Minor units per currency.