›
byrcsc/laravel-payrex · 1.x
Accept a one-time payment and confirm it through a verified webhook.
There are two common ways to start accepting a one-time payment:
Hosted checkout is the shorter integration. Payment intents give you more control over the payment experience.
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.
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.
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.
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.