Skip to content

Payments

A payment represents a successful or failed charge against a payment method. Payments are created automatically when a payment intent succeeds — you don't create them directly.

Retrieve a Payment

php
use LegionHQ\LaravelPayrex\Facades\Payrex;

$payment = Payrex::payments()->retrieve('pay_xxxxx');

echo $payment->amount;          // 4569600
echo $payment->fee;             // 2500
echo $payment->netAmount;       // 4549257
echo $payment->status;          // PaymentStatus::Paid
echo $payment->refunded;        // false
echo $payment->billing['name'];           // 'Juan Dela Cruz'
echo $payment->billing['email'];          // 'juan@example.com'
echo $payment->paymentMethod['type'];     // 'card'
echo $payment->paymentMethod['card']['brand']; // 'visa'

Returns a Payment resource.

Example Response:

json
{
    "id": "pay_xxxxx",
    "resource": "payment",
    "amount": 4569600,
    "amount_refunded": 0,
    "billing": {
        "name": "Juan Dela Cruz",
        "email": "juan@example.com",
        "phone": null,
        "address": {
            "line1": "123453",
            "line2": null,
            "city": "Pasay",
            "state": "Metro Manila",
            "postal_code": "1829",
            "country": "PH"
        }
    },
    "currency": "PHP",
    "description": null,
    "fee": 2500,
    "livemode": false,
    "metadata": null,
    "net_amount": 4549257,
    "payment_intent_id": "pi_xxxxx",
    "payment_method": {
        "type": "card",
        "card": {
            "first6": "511111",
            "last4": "1111",
            "brand": "visa"
        }
    },
    "status": "paid",
    "customer": null,
    "page_session": null,
    "refunded": false,
    "created_at": 1747235098,
    "updated_at": 1747263620
}

Billing Object

Contains the billing details collected during payment:

json
{
    "name": "Juan Dela Cruz",
    "email": "juan@example.com",
    "phone": null,
    "address": {
        "line1": "123453",
        "line2": null,
        "city": "Pasay",
        "state": "Metro Manila",
        "postal_code": "1829",
        "country": "PH"
    }
}

Payment Method Object

The structure depends on the payment method type used.

Card payment:

json
{
    "type": "card",
    "card": {
        "first6": "511111",
        "last4": "1111",
        "brand": "visa"
    }
}

QR PH payment:

json
{
    "type": "qrph",
    "qrph": {
        "account_name": "Juan Dela Cruz",
        "last4_account_number": "7890",
        "account_institution": "BPIXXXXX",
        "account_institution_name": "BPI"
    }
}

GCash payment:

json
{
    "type": "gcash",
    "gcash": {
        "account_name": "Juan Dela Cruz",
        "account_number": "09171234567"
    }
}

Maya payment:

json
{
    "type": "maya",
    "maya": {
        "account_name": "Juan Dela Cruz",
        "account_number": "09171234567"
    }
}

Page Session Object

Present when the payment was processed through PayRex Pages. Contains custom field data and line items from the checkout. null for payments created via Payment Intents or Elements.

json
{
    "custom_fields": [
        {
            "id": "cf_xxxxx",
            "name": "Company Name",
            "value": "Acme Corp"
        }
    ],
    "line_items": [
        {
            "id": "li_xxxxx",
            "price_id": "price_xxxxx",
            "price_amount": 99900,
            "price_description": "Monthly subscription",
            "product_id": "prod_xxxxx",
            "product_name": "Pro Plan",
            "product_description": "Full access to all features",
            "quantity": "1",
            "total_amount": 99900
        }
    ]
}
FieldTypeDescription
custom_fieldsarrayCustom fields collected from the customer during checkout
custom_fields[].idstringUnique identifier of the custom field
custom_fields[].namestringName of the custom field
custom_fields[].valuestringValue provided by the customer
line_itemsarrayProducts purchased (only for Pages with storefront template)
line_items[].idstringUnique identifier of the line item
line_items[].price_idstringUnique identifier of the Price resource
line_items[].price_amountintegerBase amount of the Price resource in cents
line_items[].price_descriptionstringDescription of the Price resource
line_items[].product_idstringID of the Product resource
line_items[].product_namestringName of the Product resource
line_items[].product_descriptionstringDescription of the Product resource
line_items[].quantitystringQuantity selected by the customer
line_items[].total_amountnumberQuantity multiplied by price amount

Accessing Page Session Data

php
$payment = Payrex::payments()->retrieve('pay_xxxxx');

// Access via the pageSession property (array)
$customFields = $payment->pageSession['custom_fields'] ?? [];
$lineItems = $payment->pageSession['line_items'] ?? [];

// Or via array access on the raw response
$customFields = $payment['page_session']['custom_fields'] ?? [];

Update a Payment

Update a payment's description or metadata:

php
use LegionHQ\LaravelPayrex\Facades\Payrex;

$payment = Payrex::payments()->update('pay_xxxxx', [
    'description' => 'ORD-2026-0042',
]);
php
use LegionHQ\LaravelPayrex\Facades\Payrex;

$payment = Payrex::payments()->update('pay_xxxxx', [
    'description' => 'ORD-2026-0042',
    'metadata' => ['order_id' => 'ORD-001', 'updated' => 'true'],
]);

Returns a Payment resource.

Example Response:

json
{
    "id": "pay_xxxxx",
    "resource": "payment",
    "amount": 4569600,
    "amount_refunded": 0,
    "billing": {
        "name": "Juan Dela Cruz",
        "email": "juan@example.com",
        "phone": null,
        "address": {
            "line1": "123453",
            "line2": null,
            "city": "Pasay",
            "state": "Metro Manila",
            "postal_code": "1829",
            "country": "PH"
        }
    },
    "currency": "PHP",
    "description": "ORD-2026-0042",
    "fee": 2500,
    "livemode": false,
    "metadata": {
        "order_id": "ORD-001",
        "updated": "true"
    },
    "net_amount": 4549257,
    "payment_intent_id": "pi_xxxxx",
    "payment_method": {
        "type": "card",
        "card": {
            "first6": "511111",
            "last4": "1111",
            "brand": "visa"
        }
    },
    "status": "paid",
    "customer": null,
    "page_session": null,
    "refunded": false,
    "created_at": 1747235098,
    "updated_at": 1747263700
}

Payment Resource

FieldTypeDescription
idstringUnique identifier (pay_ prefix)
resourcestringAlways payment
amountintegerPayment amount in cents
amount_refundedintegerTotal refunded amount in cents
billingobjectCustomer billing information (see below)
currencystringThree-letter ISO currency code
descriptionstring|nullReference text
feeintegerPayRex transaction fee in cents
net_amountintegerAmount transferred to your account (amount - fee)
payment_intent_idstringAssociated payment intent ID
payment_methodobjectPayment method details (see below)
statusstringpaid or failed (see PaymentStatus)
customerstring|Customer|nullAssociated customer (string ID or expanded Customer object)
page_sessionobject|nullPage session details when payment originated from PayRex Pages (see below)
refundedbooleanWhether the payment has been refunded
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., amount_refunded becomes $payment->amountRefunded. See Response Data for details.

Further Reading

Released under the MIT License.