Blog

One customer resource for the panel and the billing API

An invoice bounces. Finance already has the correct email in its billing system. Sales has the customer open in the panel. Both teams want the next invoice to reach the right person, and neither team wants a nightly sync to overwrite a sales note. What should the billing integration actually be able to do?

Give billing a small contract

For this integration, billing needs to list active accounts and correct a contact email. The panel can continue to edit company names, account status and notes. Install the API adapter, configure its authentication middleware, and register the same customers resource that serves the panel. In CustomerResource, import SeviaFlow\Core\Resources\ApiResource and describe the billing contract.

CustomerResource.php
public static function api(ApiResource $api): ApiResource
{
    return $api
        ->enabled()
        ->readable(['id', 'name', 'email', 'status'])
        ->updatable(['email'])
        ->useFormFieldRules();
}

The billing client can read the company name for an invoice. Its update requests can change only email. Every API caller using this resource gets the same field contract. The resource’s EmailField supplies the validation rule, and the customer policy decides which accounts the authenticated caller may update. Configure a resource API

Follow one correction through both screens

With a status filter named status declared on the table, an authenticated client can request GET /api/admin/resources/customers?filter[status]=active. Choose a customer the client may update. If the local test record is 42, the correction is one request.

Billing request
PATCH /api/admin/resources/customers/42
Content-Type: application/json
Accept: application/json

{"email":"invoices@juniper.example"}

Open customer 42 in the panel. You should see the new email and the rep’s original note. Try a second update with {"email":"missing-at-sign"}. With the form’s email rule enabled, expect a 422 response and an error for email. Refresh the panel and the last valid address should still be there.

Hand the contract to the integration developer

With the default routes, a signed-in developer can open /api/admin/openapi.json to inspect the generated OpenAPI document. Find the customer record path and compare its update schema with the request above. The allowed operations come from the resource’s API configuration. The schema route has its own authentication settings, so a Laravel session can read it by default even when the billing requests use a Sanctum token.

Write a billing-side acceptance test that corrects the address, reads the record back and checks that the response omits notes. The test documents exactly which part of the customer account the two teams agreed to share. Inspect the OpenAPI output