25: Integrations

Most apps eventually talk to something outside themselves: a chat service, a calendar, an accounting back-end, a card terminal, a payment processor. Phlo ships two families for this, both in the runtime, so there is no SDK to bolt on and no separate client to wire up. Connectors are thin, uniform wrappers around JSON REST APIs; the payment resources wrap Stripe and SumUp.

25.1: Connectors

A connector is a small class over one third-party REST API. Every connector extends Connector, reads its own credentials section, and returns the same result shape, so calling Slack looks like calling Shopify.

$slack = Slack::make()
$res = $slack->send('#general', 'Deploy finished')
if ($res->ok) log('sent') else log($res->error)

make() loads the connector's credentials from its section in data/creds.ini (Slack reads [Slack], Shopify reads [Shopify], and so on). Every call returns a normalized object, so you branch on ->ok and read ->data instead of parsing a different error format per service:

obj(ok: true,  status: 200, data: {...})   // success
obj(ok: false, status: 401, error: '...')  // failure

Under the hood Connector handles the request verbs (get/post/put/patch/del/form), pagination (paginate()) and auth headers. Each connector also exposes a static fields credential schema, so a settings screen or the CMS can configure it without hard-coding.

Available connectors

GroupConnectors
MessagingSlack, Telegram, Twilio, MessageBird, Resend
CloudGoogleCalendar, GoogleSheets, MicrosoftGraph
FinanceExactOnline, Moneybird, EBoekhouden
CommerceLightspeed, Shopify

Services that authenticate with OAuth2 (Google, Exact) extend OAuthConnector instead of Connector. It keeps an auto-refreshed bearer token in a TokenStore (persisted under data/tokens/, refreshed under an exclusive lock), so your code just calls ->events(...) and the token plumbing stays invisible.

Per-connector method lists live in the Manual under connectors. It is generated from the resource files, so it never drifts from the code.

25.2: Payments

Stripe

The Stripe resource is a thin layer over the official stripe/stripe-php SDK (add it with Composer). Call Stripe::boot() once with your secret key, then use the static helpers:

Stripe::boot(%creds->Stripe)
$session = Stripe::checkout([
	'mode' => 'subscription',
	'line_items' => [['price' => 'price_123', 'quantity' => 1]],
	'success_url' => 'https://example.com/done',
	'cancel_url' => 'https://example.com/pricing',
])
location($session->url)

checkout() creates a Checkout Session, portal($customerId, $returnUrl) opens the Billing Portal, and verifyWebhook($payload, $sigHeader, $secret) validates an incoming event before you act on it. customer, createCustomer, subscription, subscriptions, product and price cover the rest of the common surface.

Mollie

Mollie::make()->pay(9.50, 'Order 7', $redirectUrl, $webhookUrl) starts a payment and Mollie::checkout($payment) is where you send the customer. The webhook carries only the id of the payment, so ask Mollie::make()->payment($id) what happened and read it with Mollie::paid(). The webhook carries no cookie and no browser header, so the CSRF guard lets it through without an entry in %CSRF.except. A test key runs the whole flow without money.

SumUp

SumUp handles card-present payments on a paired SumUp Solo reader over the Cloud API. It is a connector (SumUp::make(), [SumUp] credentials), so it returns the same obj(ok, ...) result:

$res = SumUp::make()->createReaderCheckout(1250, 'EUR', description: 'Table 4')

createReaderCheckout($amountMinor, $currency, ...) pushes a checkout to the reader (the amount is in minor units, so 1250 is €12.50). transaction() and transactions() look up the result, and terminateReaderCheckout() cancels a pending one.

25.3: Mail

mail::send(to:, subject:, html:) goes out through the transport in the [mail] section of creds: sendmail (the default), smtp, resend, graph, or log, which writes the message to data/mail.log for development. Header values stay on one line and HTML gets a text part. Over SMTP a password only goes out over TLS, unless tls = none says otherwise.

mail::later(...) takes the same arguments and sends from a process of its own. A send that fails stays in data/mail/, and mail::retry() from a task sends it again.

25.4: Webhooks

Check the signature before reading anything from the body:

route POST webhook stripe {
	webhook::stripe(%creds->Stripe->webhookSecret) || error('Bad signature', 400)
	if (!webhook::once(%payload->id)) return output('seen')
}

Also hmac(), slack() and standard(). %req->header('Name') and %req->body give what a signature of your own needs.

25.5: Uploads

Enable files/upload and every request with a file reports its progress: the html element gets the class uploading and --upload from 0 to 1, and document receives an upload event. An <input type=file data-upload> sends a large file in parts that resume after a break, and upload::take($id) gives the finished file. prop %upload.canUpload => (bool)%account->user says who may; what nobody took for a day is cleared.

A file field holds the server to accept and maxSize, and img turns a phone photo upright.

25.6: Text and files from outside

sanitize_html($html) keeps the markup of a mail or an editor and removes what can run. markdown::html($md) renders markdown with the text escaped first. HTTP($url, public: true) reaches only a public address, for a URL someone gave you. CSV::download($rows, 'export.csv') and XLSX::download(['Sheet' => $rows], 'export.xlsx') write rows no spreadsheet will run as formulas.

25.7: Credentials per record

When each customer has an account of their own, the record holds the credentials: $shop->connector = Shopify::seal(['token' => $token]) encrypts them with the key in the [connectors] section of creds, and Shopify::for($shop)->get('orders') uses them. seal() needs security/encryption.

25.8: Small formats

qr::svg($text) draws a QR code as inline SVG, without a library. ICS::download($events, 'agenda.ics') writes a calendar file and ICS::feed($events) a feed a calendar subscribes to. feed::output('My blog', $items) serves an Atom feed. PDOK::make()->address('1012RJ', 147) gives a Dutch address from the government's open register, without a key.

25.9: Without a line

The offline resource keeps an app working when the line is gone: pages come from a service worker, posts wait in a queue in the browser and go out in order when the line is back.

prop %offline.pages = ['orders']
prop %offline.queue = ['note']
prop %offline.owner => (string)%session->user

route async POST note {
	offline::once(fn() => note::create(text: %payload->text, at: offline::at()))
	return apply(main: $this->main)
}

view head:
%offline

An answer can get lost after the work is done, so a post can arrive twice. offline::once() commits a mark and the work together, and the second time does nothing. A refusal moves a post aside with its reason, a 5xx stops the queue because the order matters, and with another owner on the device the cached pages go and the queue waits for the person it belongs to. html.offline, html.queued and [data-offline-count] are there for your CSS, and the queue event for your scripts.

Last updated on 5 November 2026

We use essential cookies to make this site work. With your permission we also use analytics to improve the site.