Skip to content

Customers

Manage customer records for associating with payments and billing statements.

Create a Customer

php
use LegionHQ\LaravelPayrex\Facades\Payrex;

$customer = Payrex::customers()->create([
    'name' => 'Juan Dela Cruz',       // Required
    'email' => 'juan@example.com',      // Required
]);
php
use LegionHQ\LaravelPayrex\Facades\Payrex;

$customer = Payrex::customers()->create([
    'name' => 'Juan Dela Cruz',
    'email' => 'juan@example.com',
    'billing_details' => [
        'phone' => '+639171234567',
        'address' => [
            'line1' => '123 Main St',
            'line2' => 'Suite 456',
            'city' => 'Manila',
            'state' => 'NCR',
            'postal_code' => '1000',
            'country' => 'PH',
        ],
    ],
    'billing_statement_prefix' => 'JUAN',
]);
php
use LegionHQ\LaravelPayrex\Facades\Payrex;

$customer = Payrex::customers()->create([
    'name' => 'Juan Dela Cruz',
    'email' => 'juan@example.com',
    'metadata' => [
        'user_id' => 'usr_123',
        'plan' => 'premium',
    ],
]);

Returns a Customer resource.

Currency

The currency parameter sets the customer's default currency preference. Like other resources, it is automatically populated from your PAYREX_CURRENCY config if not provided explicitly.

Example Response:

json
{
    "id": "cus_xxxxx",
    "resource": "customer",
    "billing_statement_prefix": "PKYG9MA2",
    "billing": null,
    "email": "juan@example.com",
    "currency": "PHP",
    "livemode": false,
    "metadata": null,
    "name": "Juan Dela Cruz",
    "next_billing_statement_sequence_number": "1",
    "created_at": 1721726975,
    "updated_at": 1721726975
}

Parameters

ParameterTypeRequiredDescription
namestringYesCustomer name
emailstringYesCustomer email
currencystringNoCustomer's currency preference. Defaults to config PAYREX_CURRENCY.
billing_detailsobjectNoPhone and address (see below)
billing_statement_prefixstringNoBilling statement number prefix. Must be 3–15 uppercase letters or numbers (e.g., ACME, CORP123).
next_billing_statement_sequence_numberintegerNoNext sequence number
metadataobjectNoKey-value pairs

Billing Statement Prefix

If you don't provide a billing_statement_prefix when creating a customer, PayRex automatically generates a random alphanumeric prefix (e.g., PKYG9MA2). This prefix is used to number billing statements for the customer (e.g., PKYG9MA2-0001). The prefix must be 3–15 characters, uppercase letters and numbers only.

Billing Details Object

php
'billing_details' => [
    'phone' => '+639171234567',
    'address' => [
        'line1' => '123 Main St',   // Street address
        'line2' => 'Suite 456',     // Optional
        'city' => 'Manila',
        'state' => 'NCR',
        'postal_code' => '1000',
        'country' => 'PH',          // Two-letter ISO code
    ],
],

List Customers

Finding a customer without the ID

If you don't have the PayRex customer ID but know the customer's email, name, or metadata, use list() with filters as a lookup alternative to retrieve():

php
$customers = Payrex::customers()->list([
    'email' => 'juan@example.com',
]);

$customer = $customers->data[0] ?? null; // First match
php
$customers = Payrex::customers()->list([
    'limit' => 10,
]);

foreach ($customers->data as $customer) {
    echo $customer->name;
}

if ($customers->hasMore) {
    // Fetch next page
}
php
// Search by name
$customers = Payrex::customers()->list([
    'name' => 'Juan',
    'limit' => 10,
]);

// Search by email
$customers = Payrex::customers()->list([
    'email' => 'juan@example.com',
]);

// Search by metadata
$customers = Payrex::customers()->list([
    'metadata' => ['internal_id' => '12345'],
]);

Returns a list of Customer resources.

List Parameters

ParameterTypeRequiredDescription
limitintNoNumber of results (min: 1, max: 100)
beforestringNoCursor for backward pagination (resource ID)
afterstringNoCursor for forward pagination (resource ID)
namestringNoSearch customers by name
emailstringNoSearch customers by email address
metadataobjectNoSearch customers by stored metadata (e.g., ['internal_id' => '12345'])

Example Response:

json
{
    "resource": "list",
    "data": [
        {
            "id": "cus_xxxxx",
            "resource": "customer",
            "billing_statement_prefix": "PKYG9MA2",
            "billing": null,
            "email": "juan@example.com",
            "currency": "PHP",
            "livemode": false,
            "metadata": null,
            "name": "Juan Dela Cruz",
            "next_billing_statement_sequence_number": "1",
            "created_at": 1721726975,
            "updated_at": 1721726975
        },
        {
            "id": "cus_yyyyy",
            "resource": "customer",
            "billing_statement_prefix": "MARIA",
            "billing": null,
            "email": "maria@example.com",
            "currency": "PHP",
            "livemode": false,
            "metadata": null,
            "name": "Maria Santos",
            "next_billing_statement_sequence_number": "1",
            "created_at": 1721727000,
            "updated_at": 1721727000
        }
    ],
    "has_more": false
}

Pagination

php
// In a controller — returns a CursorPaginator for UI pagination
$customers = Payrex::customers()->paginate(perPage: 10);

See Pagination for more details on cursor-based pagination.

Retrieve a Customer

php
$customer = Payrex::customers()->retrieve('cus_xxxxx');

echo $customer->name;                          // 'Juan Dela Cruz'
echo $customer->email;                         // 'juan@example.com'
echo $customer->billingStatementPrefix;        // 'PKYG9MA2'
echo $customer->currency;                      // 'PHP'

Returns a Customer resource.

Update a Customer

php
use LegionHQ\LaravelPayrex\Facades\Payrex;

$customer = Payrex::customers()->update('cus_xxxxx', [
    'name' => 'Juan Dela Cruz Jr.',
    'email' => 'juan.jr@example.com',
]);
php
use LegionHQ\LaravelPayrex\Facades\Payrex;

$customer = Payrex::customers()->update('cus_xxxxx', [
    'name' => 'Juan Dela Cruz Jr.',
    'billing_details' => [
        'phone' => '+639181234567',
        'address' => [
            'line1' => '456 Updated St',
            'city' => 'Quezon City',
            'state' => 'NCR',
            'postal_code' => '1100',
            'country' => 'PH',
        ],
    ],
]);
php
use LegionHQ\LaravelPayrex\Facades\Payrex;

$customer = Payrex::customers()->update('cus_xxxxx', [
    'metadata' => ['tier' => 'premium'],
]);

Returns a Customer resource.

Example Response:

json
{
    "id": "cus_xxxxx",
    "resource": "customer",
    "billing_statement_prefix": "PKYG9MA2",
    "billing": {
        "phone": "+639181234567",
        "address": {
            "line1": "456 Updated St",
            "line2": null,
            "city": "Quezon City",
            "state": "NCR",
            "postal_code": "1100",
            "country": "PH"
        }
    },
    "email": "juan.jr@example.com",
    "currency": "PHP",
    "livemode": false,
    "metadata": null,
    "name": "Juan Dela Cruz Jr.",
    "next_billing_statement_sequence_number": "1",
    "created_at": 1721726975,
    "updated_at": 1721727100
}

Delete a Customer

php
$result = Payrex::customers()->delete('cus_xxxxx');

Returns a Deleted Resource.

Example Response:

json
{
    "id": "cus_xxxxx",
    "resource": "customer",
    "deleted": true
}

Deleted Customers

Deleted customers can still be retrieved via retrieve(). The returned object will include a deleted: true field. This is useful for auditing or displaying historical data.

Customer Resource

FieldTypeDescription
idstringUnique identifier (cus_ prefix)
resourcestringAlways customer
namestringCustomer name
emailstringCustomer email
currencystringThree-letter ISO currency code
billing_statement_prefixstring|nullBilling statement number prefix
next_billing_statement_sequence_numberstringNext sequence number
billingobject|nullPhone and address details
metadataobject|nullKey-value pairs
livemodebooleanLive or test mode
created_atintegerUnix timestamp
updated_atintegerUnix timestamp

Property Access

Response field names above are shown in snake_case (matching the raw API response). In PHP, access them as camelCase typed properties on the DTO — e.g., billing_statement_prefix becomes $customer->billingStatementPrefix. See Response Data for details.

Further Reading

Released under the MIT License.