25: Integraties
De meeste apps communiceren uiteindelijk met iets buiten zichzelf: een chatservice, een kalender, een boekhoudbackend, een kaartterminal, een betalingsverwerker. Phlo levert twee families hiervoor, beide in de runtime, zodat er geen SDK hoeft te worden toegevoegd en geen aparte client hoeft te worden aangesloten. Connectors zijn dunne, uniforme wrappers rond JSON REST API's; de betalingsresources omhullen Stripe en SumUp.
25.1: Connectoren
Een connector is een kleine klasse bovenop een derde-partij REST API. Elke connector breidt Connector uit, leest zijn eigen sectie met inloggegevens en retourneert dezelfde resultaatstructuur, zodat het aanroepen van Slack eruitziet als het aanroepen van Shopify.
$slack = Slack::make()
$res = $slack->send('#general', 'Deploy finished')
if ($res->ok) log('sent') else log($res->error)
make() laadt de inloggegevens van de connector uit de sectie in data/creds.ini (Slack leest [Slack], Shopify leest [Shopify], enzovoort). Elke aanroep retourneert een genormaliseerd object, dus je takkeert op ->ok en leest ->data in plaats van een ander foutformaat per service te parseren:
obj(ok: true, status: 200, data: {...}) // success
obj(ok: false, status: 401, error: '...') // failure
Onder de motorkap beheert Connector de aanvraagwerkwoorden (get/post/put/patch/del/form), paginering (paginate()) en auth-headers. Elke connector biedt ook een static fields credential schema, zodat een instellingen scherm of het CMS het kan configureren zonder hard-coding.
Beschikbare connectors
| Groep | Connectors |
|---|---|
| Messaging | Slack, Telegram, Twilio, MessageBird, Resend |
| Cloud | GoogleCalendar, GoogleSheets, MicrosoftGraph |
| Finance | ExactOnline, Moneybird, EBoekhouden |
| Commerce | Lightspeed, Shopify |
Diensten die authenticeren met OAuth2 (Google, Exact) breiden OAuthConnector uit in plaats van Connector. Het houdt een automatisch ververste bearer token in een TokenStore (opgeslagen onder data/tokens/, ververst onder een exclusieve lock), zodat je code gewoon ->events(...) aanroept en de token-infrastructuur onzichtbaar blijft.
Per-connector methodenlijsten leven in de Handleiding onder connectors. Het wordt gegenereerd uit de resourcebestanden, zodat het nooit afwijkt van de 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.
Laatst bijgewerkt op 05-11-2026