Browse documentationOpen

byrcsc/laravel-payrex · 1.x

Quick start.

Accept a first PayRex payment with hosted checkout or a payment intent, and handle the successful webhook.

There are two common ways to start accepting a one-time payment:

  • Create a checkout session when PayRex should host the payment page.
  • Create a payment intent when your application controls the payment form with PayRex Elements.

Hosted checkout is the shorter integration. Payment intents give you more control over the payment experience.

Hosted checkout

Create a checkout session on your server and redirect the customer to its URL:

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

$session = Payrex::checkoutSessions()->create(
    currency: Currency::PHP,
    paymentMethods: ['card', 'gcash'],
    lineItems: [
        [
            'name' => 'Basic plan, one year',
            'amount' => 100_000,
            'quantity' => 1,
        ],
    ],
    description: 'Account renewal',
    successUrl: route('billing.success'),
    cancelUrl: route('billing.cancel'),
);

return redirect()->away($session->url);

100_000 is ₱1,000.00. Amounts are always integers in the currency's smallest unit.

The success URL improves the customer experience, but it is not proof of payment. Activate the purchase from a verified webhook.

Payment intent

For a custom payment form, create an intent on the server:

use ByRcsc\LaravelPayrex\Facades\Payrex;

$intent = Payrex::paymentIntents()->create(
    amount: 100_000,
    paymentMethods: ['card', 'gcash'],
    description: 'Order #1042',
    metadata: ['order_id' => '1042'],
);

return [
    'client_secret' => $intent->clientSecret,
    'public_key' => Payrex::publicKey(),
];

Pass only the public key and client secret to your frontend. Never return PAYREX_SECRET_KEY.

See payment intents for attaching a payment method, handling redirects, and manual capture.

Handle successful payment

Register the package webhook URL with PayRex, then add the endpoint's signing secret to PAYREX_WEBHOOK_SECRET. Listen for the typed event:

namespace App\Listeners;

use App\Models\Order;
use ByRcsc\LaravelPayrex\Events\PaymentIntentSucceeded;
use Illuminate\Contracts\Queue\ShouldQueue;

final class MarkOrderAsPaid implements ShouldQueue
{
    public function handle(PaymentIntentSucceeded $event): void
    {
        $intent = $event->event->paymentIntent();

        if ($intent === null) {
            return;
        }

        Order::query()
            ->where('payrex_payment_intent_id', $intent->id)
            ->whereNull('paid_at')
            ->update(['paid_at' => now()]);
    }
}

Queue listeners and make them idempotent. PayRex may deliver the same event more than once, so store and deduplicate the event ID when one-time processing matters.

No subscription resource

PayRex does not expose a subscription resource, and Laravel PayRex does not simulate one. A checkout session or payment intent creates a single payment.

For recurring billing, create a billing statement for each cycle. Saving a payment method with a setup intent does not itself authorize unattended charges. Confirm off-session support and recurring-charge consent requirements with PayRex before designing that flow.

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

View source