Skip to content

One-Time, Links & Saved Sources

Payments standardizes every one-time transaction through PaymentIntentRequest and Money, shielding your application from driver-specific quirks.

Authorize, Purchase, Capture, Refund & Void

Section titled “Authorize, Purchase, Capture, Refund & Void”
<?php namespace ProcessWire;
use Totoglu\Payments\Domain\Money;
use Totoglu\Payments\Domain\PaymentIntentRequest;
$payments = Payments::requireInstance($wire);
$intent = new PaymentIntentRequest(
amount: Money::fromMinor(490000, 'EUR'),
payableType: 'charter_booking',
payableId: 'CHR-2026-104',
idempotencyKey: 'charter:CHR-2026-104:deposit',
customerEmail: '[email protected]',
customerName: 'Claire Beaumont',
);
// Immediate charge
$sale = $payments->purchase($intent);
// Two-step hold and settle
$hold = $payments->authorize($intent);
$captured = $payments->capture($hold->transactionId, Money::fromMajor('4900.00', 'EUR'));
// Partial or full refund (requires payments-refund permission in admin UI)
$refund = $payments->refund($captured->transactionId, Money::fromMajor('500.00', 'EUR'), 'Fuel adjustment');
// Cancel an uncaptured authorization
$voided = $payments->void($hold->transactionId, 'Guest changed dates');
// Query payable totals
$paid = $payments->isPaid('charter_booking', 'CHR-2026-104');
$summary = $payments->summaryForPayable('charter_booking', 'CHR-2026-104');
  • GatewayRepository Routing: If gatewayHandle is omitted on PaymentIntentRequest, Payments selects the highest-priority enabled gateway that supports the requested currency.
  • Idempotency Fingerprinting: Each idempotencyKey is fingerprinted against the normalized amount, currency, payable, and operation. Retrying the identical request returns the existing ledger transaction; mutating the payload under the same key fails safely.
  • Row-Level Locks: Captures, refunds, and voids acquire SELECT ... FOR UPDATE locks inside a database transaction so concurrent requests cannot over-capture or over-refund.

createPaymentLink() creates a time-limited hosted checkout link backed by a SHA-256 token hash. The plaintext rawToken is returned once at creation time and never stored in plaintext in the database.

<?php namespace ProcessWire;
use Totoglu\Payments\Domain\Money;
$link = $payments->createPaymentLink([
'title' => 'Final Balance: Gulet Blue Horizon (CHR-2026-104)',
'amount' => Money::fromMajor('9800.00', 'EUR'),
'payable_type' => 'charter_invoice',
'payable_id' => 'INV-2026-104',
'customer_email' => '[email protected]',
'expires_in_hours' => 72,
]);
// $link['rawToken'] and $link['url'] (/pay/<rawToken>)
Hosted links automatically transition from Open to Paid when checkout settles and fire Payments::afterPaymentLinkPaid.

For gateways implementing SavedSourceGatewayInterface, you can vault customer payment tokens without storing raw card numbers:

<?php namespace ProcessWire;
$savedSource = $payments->sources()->saveSource([
'user_id' => (int) $user->id,
'gateway_handle' => 'stripe-eur',
'token' => $providerPaymentMethodId,
'label' => 'Visa ending 4242',
]);
$sources = $payments->listSavedSources((int) $user->id);
$payments->revokeSavedSource($savedSource->id, (int) $user->id);

Next steps