›
›
›
  1. docs
  2. ›
  3. byrcsc/laravel-payrex
1.x
Browse documentationOpenClose

Getting started

  • Introduction
  • Installation and setup
  • Quick start

Core concepts

  • Client and resources
  • Data objects and enums
  • Errors and retries
  • Pagination

Accepting payments

  • Payment intents
  • Checkout sessions
  • Setup intents
  • Payments and refunds

Customers and billing

  • Customers
  • Eloquent customers
  • Billing statements
  • Payouts

Webhooks

  • Receiving webhooks
  • Events and listeners
  • Managing endpoints

Advanced usage

  • Testing
  • Security and operations
  • Troubleshooting

Getting started

  • Introduction
  • Installation and setup
  • Quick start

Core concepts

  • Client and resources
  • Data objects and enums
  • Errors and retries
  • Pagination

Accepting payments

  • Payment intents
  • Checkout sessions
  • Setup intents
  • Payments and refunds

Customers and billing

  • Customers
  • Eloquent customers
  • Billing statements
  • Payouts

Webhooks

  • Receiving webhooks
  • Events and listeners
  • Managing endpoints

Advanced usage

  • Testing
  • Security and operations
  • Troubleshooting

byrcsc/laravel-payrex · 1.x

Payment intents.

Manage a PayRex payment intent through collection, capture, or cancellation.

A payment intent tracks the lifecycle of collecting one amount. Use it when your application controls the payment form with PayRex Elements or needs manual capture.

Create an intent

use ByRcsc\LaravelPayrex\Enums\Currency;
use ByRcsc\LaravelPayrex\Enums\PaymentMethodType;
use ByRcsc\LaravelPayrex\Facades\Payrex;

$intent = Payrex::paymentIntents()->create(
    amount: 10_000,
    paymentMethods: [
        PaymentMethodType::Card,
        PaymentMethodType::Gcash,
    ],
    currency: Currency::PHP,
    description: 'Order #1042',
    customerId: 'cus_...',
    statementDescriptor: 'RCSC ORDER',
    metadata: ['order_id' => '1042'],
);

The complete signature is:

create(
    int $amount,
    array $paymentMethods = [],
    Currency $currency = Currency::PHP,
    ?string $description = null,
    ?string $customerId = null,
    ?array $paymentMethodOptions = null,
    ?string $statementDescriptor = null,
    ?array $metadata = null,
    array $options = [],
): PaymentIntent

Amounts use the smallest currency unit. For Philippine pesos, 10_000 is ₱100.00. The package locally enforces PayRex's documented payment-intent range of 2_000 through 5_999_999_999 centavos: ₱20.00 through ₱59,999,999.99. The check runs on create(), on update() when an amount is supplied, and on capture(), throwing InvalidArgumentException before any request is sent.

Attach a payment method

After PayRex Elements returns a pm_... token, attach it to start the charge:

$intent = Payrex::paymentIntents()->attach(
    id: $intentId,
    paymentMethodId: $paymentMethodId,
);

if ($intent->requiresAction()) {
    return redirect()->away($intent->redirectUrl());
}

The clientSecret and public key may be sent to the frontend. The PayRex secret key may not.

Retrieve and update

$intent = Payrex::paymentIntents()->retrieve('pi_...');

$intent = Payrex::paymentIntents()->update(
    id: $intent->id,
    amount: 12_500,
    description: 'Order #1042, updated',
    customerId: 'cus_...',
);

update() accepts id, optional amount, optional description, optional customerId, and options. Null fields are omitted.

Cancel an intent

$intent = Payrex::paymentIntents()->cancel('pi_...');

The returned object contains the status PayRex assigned after cancellation.

Manual capture

Request manual card capture in paymentMethodOptions:

use ByRcsc\LaravelPayrex\Enums\CaptureType;

$intent = Payrex::paymentIntents()->create(
    amount: 10_000,
    paymentMethods: ['card'],
    paymentMethodOptions: [
        'card' => [
            'capture_type' => CaptureType::Manual,
        ],
    ],
);

After the payer authorizes the payment, the intent can reach awaiting_capture. Capture all or part of the authorized amount:

$intent = Payrex::paymentIntents()->capture(
    id: $intent->id,
    amount: 10_000,
);

amount is required. There is no "capture whatever was authorized" shorthand; pass amountCapturable when you intend to capture the full authorization.

Use captureBeforeAt to observe the capture deadline when PayRex includes it. Listen for PaymentIntentAwaitingCapture and PaymentIntentSucceeded instead of relying on a browser redirect.

Installments

Installment types are a list under the relevant payment method:

use ByRcsc\LaravelPayrex\Enums\InstallmentType;

$intent = Payrex::paymentIntents()->create(
    amount: 100_000,
    paymentMethods: ['bdo_installment'],
    paymentMethodOptions: [
        'bdo_installment' => [
            'installment_types' => [
                InstallmentType::Zero,
                InstallmentType::Regular,
            ],
        ],
    ],
);

Account eligibility and installment rules are enforced by PayRex.

Read the result

Useful PaymentIntent properties include:

$intent->id;
$intent->status;
$intent->amount;
$intent->amountReceived;
$intent->amountCapturable;
$intent->clientSecret;
$intent->nextAction;
$intent->lastPaymentError;
$intent->latestPayment;
$intent->paymentMethodId;
$intent->captureBeforeAt;
$intent->customer;
$intent->metadata;
$intent->raw;

Convenience methods include hasSucceeded(), requiresAction(), and redirectUrl().

lastPaymentError is the decoded PayRex error array from the most recent failed attempt, or null. Read it when an intent stalls instead of reaching succeeded.

What to read next

  • Payments and refunds to inspect the resulting charge or refund it.
  • Receiving webhooks to confirm the final intent state.
  • Setup intents when you need to save a method without charging it.
PreviousPaginationNextCheckout sessions

Laravel PayRex is an unofficial community SDK and is not affiliated with PayRex.

View source

On this page

  1. Create an intent
  2. Attach a payment method
  3. Retrieve and update
  4. Cancel an intent
  5. Manual capture
  6. Installments
  7. Read the result
  8. What to read next