Skip to content

Contracts

Namespace Fomvasss\Billing\Contracts.

ContractMethodsPurpose
BillabletenantId(): ?stringWho pays; the tenant picks credentials. Implemented by the Concerns\Billable trait
Payable—Marker for what is paid for
HasReceiptItemsreceiptItems(): arrayFiscal basket of a payable, see Fiscal receipt items
HasBillingDetailsbillingDetails(): BillingDetailsThe buyer on invoices

Bind in a service provider’s register(); the defaults are in Fomvasss\Billing\Support.

ContractMethodDefaultPurpose
CredentialResolverContractresolve(string $gateway, ?string $tenantId): arrayDefaultCredentialResolver — config("billing.gateways.{$gateway}")Per-tenant / database credentials
RenewalChargeOptionsContractresolve(Subscription $subscription, Payment $payment): ChargeOptionsDefaultRenewalChargeOptions — empty, or one basket line with renewal.receipt_itemsOptions of scheduled renewals
ReissueChargeOptionsContractresolve(Payment $payment): ChargeOptionsDefaultReissueChargeOptions — emptyOptions of pay-link re-issues
CurrencyConverterContractconvert(Money $amount, string $toCurrency, ?DateTimeInterface $at = null): Moneynot boundCurrency conversion step of resolveChargeAmount()
InvoiceSellerContractseller(?string $gateway, ?string $tenantId): BillingDetailsDefaultInvoiceSeller — gateway seller block, else invoices.sellerDocument issuer
InvoiceItemsContractitems(Payment $payment): arrayDefaultInvoiceItems — the payable’s receiptItems()Document lines
InvoiceTemplateResolverview(Invoice $invoice): stringDefaultInvoiceTemplateResolver — $invoice->template or billing::invoices.{type}Template per document
InvoiceViewDataContractdata(Invoice $invoice): arrayDefaultInvoiceViewData — []Extra view variables
InvoiceRendererpdf(string $html): stringDompdfInvoiceRendererHTML → PDF
ContractMethodsCapability flag
PaymentGatewayContract (required)charge(Payment, ChargeOptions): PaymentResult, handleWebhook(BillingWebhookCall): WebhookResult, static label(), credentialFields(), supportedCurrencies(), requiresDashboardWebhook()—
RefundsPaymentsrefund(Payment, ?Money): PaymentResultrefunds
ChecksPaymentStatuscheckStatus(Payment): WebhookResultused by reconciliation
ChecksGatewayHealthhealthCheck(): GatewayHealthhealth
TokenizesPaymentMethodcreateCustomer(Model&Billable): string, attachPaymentMethod(Model&Billable, array $token): PaymentMethod, chargePaymentMethod(Payment, PaymentMethod, ChargeOptions): PaymentResult, detachPaymentMethod(PaymentMethod): voidtokenization
StartsProviderSubscriptionsstartSubscription(Payment, ChargeOptions): PaymentResultsubscriptions
ManagesProviderSubscriptionscancel(Subscription, bool $atPeriodEnd), pause(Subscription, ?DateTimeInterface $until), resume(Subscription), swapPrice(Subscription, Price) — each returns SubscriptionSnapshotsubscriptions
ReportsTrialEnding— (marker)The provider sends its own trial-ending event; local reminders are skipped
SubscriptionGatewayContractdeprecated — use the two abovesubscriptions
SignatureValidatorisValid(Request): boolregistered with registerWebhook()
WebhookResponderrespond(Request): Responseoptional third argument of registerWebhook()

Gateways\AbstractGateway implements the boilerplate. See Writing a gateway.