Appearance
Payments
Online and offline payment methods for orders and anything else payable.
kitloom/ · admins: kitloom/, kitloom/
Video lessons
Recorded in the Filament admin; the Nova admin works the same way.
Payments for any model. An order, an invoice or a booking implements Payable, takes the Has trait, and $order- sends the payer to the gateway; the webhook calls $order-. The engine is fomvasss/laravel-billing: its billing_ table, its gateways (Monobank, LiqPay, WayForPay, Hutko, Stripe, Paddle) and its webhook pipeline. This package adds PayPal, Mollie and Square, the model side, offline methods, the gateway keys in the site's settings, its own events and the landing page.
The admin is kitloom/payments-filament or kitloom/payments-nova.
A payable model
php
use Fomvasss\Billing\Models\Payment;
use Fomvasss\Billing\Support\Money;
use Kitloom\Payments\Concerns\HasPayments;
use Kitloom\Payments\Contracts\Payable;
class Order extends Model implements Payable
{
use HasPayments;
public function payableAmount(): Money
{
return Money::fromDecimal($this->total, $this->currency);
}
public function payableReturnUrl(Payment $payment): string
{
return route('orders.received', $this);
}
public function paid(Payment $payment): void
{
$this->markProcessing();
}
}payable, payable and tenant have defaults in the trait: "Order #12", the model itself as the payer, no tenant. Override payable to return the user when there is one: a user model that implements laravel-billing's Billable becomes the payment's billable; any other (the skeletons' App\) is written into the payment's meta. and the model pays as itself, since laravel-billing asks the billable for its tenant on every charge, webhook and refund.
php
$checkout = $order->pay($request->input('payment_method')); // a Checkout
return $checkout->redirect(); // the gateway, or the order page for an offline method
$order->isPaid();
$order->latestPayment();
$order->payments; // charges and refunds, newest firstMethods
Payments:: lists what the payer may choose: the gateways switched on in the settings and the offline methods from kitloom- (bacs, cod) that nobody switched off. <x- renders them as radio buttons.
A shop brought over from WooCommerce keeps the offline methods it had. bacs and cod are WooCommerce's own ids, so what the site's settings do not say is read from WooCommerce's woocommerce_ / woocommerce_: whether the method is on, its title, its description and its instructions. A method WooCommerce kept no settings for is off, as in WooCommerce (a database with WooCommerce's woocommerce_ is taken for its shop). Saving the method here writes the site's own option, which counts from then on; WooCommerce's is left as it is.
An offline method has instructions too — what the payer is told once the order is placed, where the description is what the checkout says before: the method's instructions (Method::; the settings page's Instructions, else WooCommerce's, else the defaults in kitloom-). A bank transfer also has the accounts to pay into, Method::, read from WooCommerce's woocommerce_ (account name, number, bank, sort code, IBAN, BIC; they are not edited here yet). Bank lists them as WooCommerce's "Our bank details" do: the fields filled in, the sort code by the name the payer's country gives it (BSB, routing number…). The shop shows both on the "order received" page and in its emails.
An offline payment stays pending until the admin marks it paid: Payments:: runs paid() and fires the event, as a webhook would. Payments:: and Payments:: do the rest; a refund of an offline payment is a record of money given back by hand, a refund of an online one goes through the gateway.
Settings
One option per method, kitloom_: enabled, title, description and credentials. Credentials are encrypted with the application key; what is saved wins over config/ and the environment. Methods\ reads and writes them, the admin packages edit them, and the gateway's credential says which keys it needs. A key of type boolean (PayPal's and Square's sandbox) is a switch on the settings page, saved as 1 or 0.
PayPal
PayPal is a gateway of this package (laravel-billing has none), on PayPal's REST API — Orders v2, no SDK. The payer is sent to PayPal to approve the payment, comes back, and the order is captured there and then: the page they land on already says paid. The webhook — and, an hour on, the reconciliation of pending payments — captures it too when the payer closed the tab before coming back, and a payment is announced paid only once whichever got there first.
Keys. On developer.paypal.com, sign in with the PayPal business account and open Apps & Credentials. The switch at the top says Sandbox or Live: each has its own apps and keys. Create an app (type Merchant), or open the default one, and copy its Client ID into client_ and its Secret key into client_ on the Payments settings page.
Sandbox or live. Turn sandbox on with a Sandbox app's keys: payments go to api-m.sandbox.paypal.com, no money moves, and you pay with one of the sandbox personal accounts PayPal made for you (Testing Tools → Sandbox Accounts). Off is live, with the Live app's keys. Keys of one with the switch of the other fail with PayPal's "Client Authentication failed".
Webhook. In the same app, under Webhooks, choose Add Webhook, paste the Webhook address the settings page shows (https://) and tick these events:
- Checkout order approved (
CHECKOUT.)ORDER. APPROVED - Payment capture completed (
PAYMENT.)CAPTURE. COMPLETED - Payment capture denied (
PAYMENT.) and declined (CAPTURE. DENIED PAYMENT.)CAPTURE. DECLINED - Payment capture refunded (
PAYMENT.) and reversed (CAPTURE. REFUNDED PAYMENT.)CAPTURE. REVERSED
Save it, then copy the Webhook ID PayPal shows beside it into webhook_. Every notification is checked with PayPal against that id; without it, or with another app's, every notification is refused (403) and PayPal tries again for a few days. A sandbox app needs a webhook of its own.
Refunds. A refund from the payment's screen goes back to the PayPal transaction, in full or in part. A refund made in PayPal, or a dispute PayPal decided for the buyer, comes in by the webhook and is recorded on the payment. The payment's reference, once paid, is PayPal's transaction id (the capture), as PayPal's activity lists it; the order's id is kept in its meta..
Currencies. AUD, BRL, CAD, CNY, CZK, DKK, EUR, GBP, HKD, HUF, ILS, JPY, MXN, MYR, NOK, NZD, PHP, PLN, SEK, SGD, CHF, THB, TWD and USD. HUF, JPY and TWD are paid in whole units: an amount with a fraction in them is refused before the payer is sent anywhere. Which of them your account takes depends on its country; billing. narrows the list.
Mollie
Mollie is a gateway of this package, on Mollie's Payments API v2, no SDK. The payer is sent to Mollie's checkout and picks how to pay there — card, iDEAL, Bancontact, SEPA, Klarna and the rest, whichever you switched on in Mollie — then comes back to the site. Mollie tells the site through a webhook; the site also asks Mollie when the payer comes back, so the page they land on already says paid.
Key. In the Mollie dashboard open Developers → API keys and copy the key into api_ on the Payments settings page. There is no sandbox switch: a key starting with test_ takes test payments (Mollie shows a page where you choose the outcome, no money moves), a key starting with live_ takes real ones. The live key works once Mollie has approved the account. Which methods the payer is offered is set in Mollie, under Settings → Website profiles → Payment methods — test and live each have their own list.
Webhook. Nothing to set up: the address — the Webhook address the settings page shows, https:// — goes to Mollie with every payment. Mollie's notification only names the payment, unsigned; the site fetches that payment from Mollie with your key and settles it by what Mollie says, so a notification nobody at Mollie sent changes nothing. A site Mollie cannot reach (localhost, a . name, a private address) sends no address at all, as Mollie would refuse the payment; the payer's return and the reconciliation of pending payments ask Mollie instead.
Outcomes. Paid is paid; failed is failed; a payment the payer canceled, or one that expired unpaid, is canceled. Open and pending ones wait.
Refunds. A refund from the payment's screen goes back through Mollie, in full or in part; Mollie pays it out with its next run. A refund made in Mollie's dashboard, or a chargeback, comes in by the same webhook and is recorded on the payment by Mollie's running totals, once. The payment's reference is Mollie's payment id (tr_).
Currencies. AUD, BGN, BRL, CAD, CHF, CZK, DKK, EUR, GBP, HKD, HUF, ILS, ISK, JPY, MXN, NOK, NZD, PHP, PLN, RON, SEK, SGD, TWD, USD and ZAR. JPY and ISK are paid in whole units. Several methods (iDEAL, Bancontact, SEPA) take euros only; Mollie offers the payer those that take the payment's currency. billing. narrows it.
Square
Square is a gateway of this package, on Square's Checkout API (payment links), no SDK. The payer is sent to a Square checkout page for the amount, pays by card or a wallet Square offers there, and comes back; the site reads the order from Square there and then, so the page they land on already says paid. The webhook does the same when the payer closed the tab.
Keys. On developer.squareup.com, sign in with the Square account and open your application (or create one) under Applications. The switch at the top of Credentials says Sandbox or Production: each has its own Access token — copy it into access_. Then open Locations in the same application (or Square Dashboard → Settings → Locations) and copy the Location ID of the shop the payments go to into location_. A location takes payments in its own country's currency only: a US location, dollars.
Sandbox or live. Turn sandbox on with the Sandbox access token: payments go to connect.squareupsandbox.com, no money moves, and you pay with Square's test card numbers (4111 1111 1111 1111, any future date, any CVV). Off is live, with the Production token. A token of one with the switch of the other is refused as unauthorized.
Webhook. In the same application open Webhooks → Subscriptions (Sandbox or Production, as the token) and choose Add subscription. Paste the Webhook address the settings page shows (https://) as the URL — exactly, as Square signs every notification with it — and tick these events:
payment.andcreated payment.updated refund.andcreated refund.updated
Save it, open the subscription and copy its Signature key into webhook_. Every notification is checked against that key; without it, or with another subscription's, every notification is refused (403) and Square tries again for a while. Sandbox and Production need a subscription each.
Outcomes. A completed payment is paid. A card Square declined leaves the link open — the payer may try another card on it — so nothing fails at once; a link nobody paid within a day (billing.) is canceled by the reconciliation. Paid late after all, it is paid.
Refunds. A refund from the payment's screen goes back to the Square payment, in full or in part; while the card network has it, it waits, and Square's refund. settles it — or, turned down, gives back what it held. A refund made in Square's dashboard comes in by the webhook and is recorded once. The payment's reference, once paid, is Square's payment id, as the dashboard's transactions list it; the order's id is kept in its meta..
Currencies. USD, CAD, GBP, EUR, AUD and JPY — Square's markets (the US, Canada, the UK, Ireland, France, Spain, Australia, Japan), each in the location's own currency. JPY is paid in whole yen. billing. narrows the list to your location's.
AI agents
With kitloom/ai installed, an agent whose user has manage_ reads the ways to pay (payments_): each gateway and offline method, whether it is on, the currencies it takes, whether it refunds, which credentials a gateway needs and which are still empty, and whether its webhook needs setting up in the gateway's dashboard — so it can say why a checkout fails. Never a credential's value, never a bank account's details; it changes nothing (the option is protected). kitloom- false — no such tool.
Events
Kitloom\: Payment, Payment, Payment, Payment, Payment and Checkout, each with the Payment and payable(). Payment fires after the payable's paid(). Checkout is the payer's browser coming back, unverified — fulfil on Payment only.
Routes
POST billing/— laravel-billing's webhook, no CSRF, signature-checked, handled on the queue.webhooks/ {gateway} GET|POST billing/→return/ {payment}/ {outcome} GET payments/→ the payable'slanding/ {outcome}?payment= payable.Return Url() GET billing/— the permanent pay link for emails and invoices;pay/ {payment} <x-.payments:: pay- button : payment="$payment" / >
Personal data
With kitloom/privacy installed, Privacy → Export Personal Data lists a person's payments — those their account made, and any whose stored data carries their email address: number, method, amount, status, dates and the gateway's reference — and the gateways' notifications that named them. Erase Personal Data does not delete payments: the accounts need the amount, currency, dates, method and the gateway's reference, and these stay. What the gateway answered (raw_) is cleared, the address is replaced with deleted@site. in the payment's meta, and the body of each notification that carried it goes; the notification's row stays, as it is what keeps a gateway's repeated delivery from being handled twice. A payment still pending and a notification not handled yet are kept and reported: erase again once they are settled. The payment services keep their own records — the person asks them. kitloom- false leaves the payments out of both.
Installing
The package's migrations run with the application's. php artisan payments: checks the queue the webhooks run on, lists the methods and prints the webhook addresses that must be registered in a gateway's dashboard. Pending payments past their link's lifetime are reconciled every fifteen minutes when the scheduler runs, on one server of several, by a lock in the cache, so a site on several servers needs a shared cache store (Redis, the database) — with each server's own cache the lock is local and the task runs on every one.
Tests
Fake makes laravel-billing's fake gateway the default method; Fake, fail() and cancel() answer as the gateway would. The tests boot the application of the skeleton they run from.