Download the PHP package paynexus/laravel-paynexus without Composer

On this page you can find all versions of the php package paynexus/laravel-paynexus. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package laravel-paynexus

# PayNexus Laravel Plugin [![Latest Version](https://img.shields.io/packagist/v/paynexus/laravel-paynexus?style=flat-square)](https://packagist.org/packages/paynexus/laravel-paynexus) [![License](https://img.shields.io/packagist/l/paynexus/laravel-paynexus?style=flat-square)](https://github.com/MCBANKSKE/paynexus-laravel-plugin/blob/main/LICENSE) [![Laravel](https://img.shields.io/badge/Laravel-8%2B-FF2D20?style=flat-square&logo=laravel)](https://laravel.com) [![PHP](https://img.shields.io/badge/PHP-8.0%2B-777BB4?style=flat-square&logo=php)](https://php.net) **Accept M-Pesa payments through PayNexus in any Laravel application** A powerful client SDK that connects your Laravel application to the PayNexus payment platform, handling M-Pesa STK Push, real-time payment status tracking, webhook processing, and automatic local record-keeping. [Documentation](#-) • [Installation](#installation) • [Quick Start](#quick-start) • [API Reference](#api-reference)

✨ Features

⚠️ Plugin vs Platform

This plugin is for external Laravel applications (e.g., ecommerce stores, SaaS apps) that want to accept payments through PayNexus.

Component Description
PayNexus Platform The payment gateway platform at paynexus.co.ke that processes payments
This Plugin A Laravel package that YOUR application installs to connect to the PayNexus platform

Note: If you're looking for the PayNexus platform source code, that's a separate repository. This plugin is the client SDK for merchants integrating with PayNexus.


📑 Table of Contents


🔄 How It Works

Payment Flow:

  1. Initiate — Your app calls PayNexus::initiatePayment(...). A payment record is created both on PayNexus and in your local paynexus_payments table.
  2. STK Push — PayNexus sends an M-Pesa STK Push to the customer's phone.
  3. Customer pays — The customer enters their PIN on their phone.
  4. Callback — M-Pesa sends a callback to PayNexus. PayNexus updates its record and fires a webhook to your app.
  5. Webhook received — This plugin receives the webhook, updates the local paynexus_payments record, and dispatches a Laravel event (PaymentCompleted or PaymentFailed).
  6. Your listener — Your EventServiceProvider listener marks the order as paid, sends a receipt, etc.

Both records always match. If the webhook is missed, you can call PayNexus::pollStatus(...) or PayNexus::getPaymentByCheckoutId(...) to sync manually.


📦 Installation

Install the package via Composer:

The service provider and facade are auto-discovered by Laravel.

Publish Config and Migration


⚙️ Configuration

Add these to your .env file:

🔑 Where to Get Credentials

Credential Location Usage
Secret Key (sk_…) PayNexus Dashboard → API Keys Write operations (initiate payments, manage webhooks). Keep server-side only.
Public Key (pk_…) PayNexus Dashboard → API Keys Read operations only (merchant info, payment status). Safe for client-side code.
Webhook Secret PayNexus Dashboard → Webhooks Generate a webhook pointing to https://yourapp.com/paynexus/webhook

🔓 Public Key Allowed Operations

Public keys (pk_) can perform the following read-only operations:

Merchant Information

Payment Read Operations

M-Pesa Operations

Webhook Read Operations

API Key Read Operations

Invoice Read Operations

Receipt Read Operations

🔒 Public Key Blocked Operations

Public keys (pk_) are blocked from these write operations at the middleware level:

Payment Write Operations

Webhook Management

API Key Management

Invoice Management

Receipt Management


🚀 Quick Start


📚 API Reference

👤 Merchant

🏢 Businesses

💳 Payment Accounts

💰 Initiate Payment

Two endpoints are available:

Idempotency Protection:

To prevent duplicate payments, you can provide an idempotency key:

If a payment with the same idempotency_key already exists, the existing payment details will be returned instead of creating a new one. This is especially useful for handling network retries and preventing duplicate charges.

Benefits of idempotency:

Response:

Both methods also create a local paynexus_payments record automatically.

📊 Payment Status

⏱️ Poll for Completion

Blocks until the payment reaches a terminal state or times out:

📋 List Payments

✅ Phone Validation

🔗 Webhooks


🔔 Webhook Integration

The plugin automatically registers a POST route at /paynexus/webhook (configurable via PAYNEXUS_WEBHOOK_PATH).

Queue Support for Webhooks

For production environments, you can enable queue processing for webhooks to improve reliability:

When enabled, webhooks are dispatched to a queue job (ProcessPayNexusWebhook) with configurable retry behavior:

Benefits of queue processing:

Handling Webhook Failures:

When a webhook job exhausts its retry attempts, a WebhookProcessingFailed event is dispatched. You can listen for this event:

PayNexus sends this payload when a payment completes:

Headers sent with each webhook: Header Description
X-PayNexus-Signature HMAC-SHA256 of the JSON body using your webhook secret
X-PayNexus-Timestamp Unix timestamp — used for replay protection

The webhook controller:

  1. Verifies the X-PayNexus-Signature header (HMAC-SHA256 of the JSON body using your webhook secret).
  2. Checks X-PayNexus-Timestamp for replay protection (rejects payloads older than 5 minutes by default).
  3. Finds or creates the matching paynexus_payments record.
  4. Updates the local record's status.
  5. Dispatches a Laravel event (PaymentCompleted or PaymentFailed).

Setup in PayNexus dashboard:

  1. Go to Webhooks in your PayNexus merchant panel.
  2. Add a webhook pointing to https://yourapp.com/paynexus/webhook.
  3. Copy the generated secret and set PAYNEXUS_WEBHOOK_SECRET in your .env.

🎯 Events

Event When Properties
PayNexus\Events\PaymentCompleted Webhook reports payment.completed $payment (PaynexusPayment), $payload (array)
PayNexus\Events\PaymentFailed Webhook reports payment.failed $payment (PaynexusPayment), $payload (array), $reason (string)
PayNexus\Events\PaymentInitiated After initiatePayment() succeeds $payment (PaynexusPayment)

Register listeners in your EventServiceProvider:


📦 Local Payment Records

Every payment initiated through the plugin creates a row in the paynexus_payments table.

🔍 Payment Verification

The plugin tracks verification data from the payment provider:

👤 Manual Confirmation

For payments that need manual review:

🔗 Polymorphic Relationship

Link payments to any of your models:


🛒 Ecommerce Integration Guide

📦 Order Checkout Flow

Here is a complete end-to-end checkout flow for an ecommerce store.

Step 1: Order Model Setup

Step 2: Orders Migration

🛍️ Cart Checkout Controller

Routes:

⚡ Payment Status Page (Livewire)

If you use Livewire, here is a component that polls automatically:

🎧 Handling Webhooks in Your App

🔄 Subscription Integration

For subscription-based applications:

Subscription Model:

Subscription Payment Controller:

� Manual Payment Verification

For payments that require manual admin review:


⚠️ Error Handling

The plugin provides specific exceptions for different error scenarios:


🧪 Testing

Mocking HTTP Requests


🌐 JavaScript Polling

For client-side payment status polling:


� Custom Webhook Handler

If you need custom webhook handling beyond the built-in controller:

Register your custom webhook route:


�� Configuration Reference

Key Env Variable Default Description
secret_key PAYNEXUS_SECRET_KEY Your PayNexus secret key (sk_…) - Required for write operations
public_key PAYNEXUS_PUBLIC_KEY Your PayNexus public key (pk_…) - Optional, for read operations
base_url PAYNEXUS_BASE_URL https://paynexus.co.ke PayNexus API base URL
currency PAYNEXUS_CURRENCY KES Default currency
webhook.secret PAYNEXUS_WEBHOOK_SECRET HMAC secret for webhook signature verification
webhook.path PAYNEXUS_WEBHOOK_PATH /paynexus/webhook Webhook receiver route
webhook.tolerance 300 Max age (seconds) for webhook timestamp
polling.interval PAYNEXUS_POLL_INTERVAL 3 Seconds between pollStatus queries
polling.timeout PAYNEXUS_POLL_TIMEOUT 120 Max seconds pollStatus will block
http.timeout PAYNEXUS_HTTP_TIMEOUT 30 HTTP request timeout (seconds)
http.retry_times PAYNEXUS_HTTP_RETRIES 2 Number of retries on connection failure
http.retry_sleep PAYNEXUS_HTTP_RETRY_SLEEP 500 Milliseconds between retries
log_channel PAYNEXUS_LOG_CHANNEL null Custom log channel
queue.webhooks PAYNEXUS_QUEUE_WEBHOOKS false Enable queue processing for webhooks
queue.connection PAYNEXUS_QUEUE_CONNECTION default Queue connection for webhooks
queue.queue PAYNEXUS_QUEUE_NAME default Queue name for webhooks
retry.webhook_max_attempts PAYNEXUS_WEBHOOK_MAX_ATTEMPTS 3 Max retry attempts for webhook jobs
retry.webhook_backoff PAYNEXUS_WEBHOOK_BACKOFF exponential Retry backoff strategy (linear, exponential, constant)
retry.webhook_base_delay PAYNEXUS_WEBHOOK_BASE_DELAY 1000 Base delay in milliseconds for retries

Advanced Configuration Options

Queue Webhooks:

Retry Configuration:

Custom Webhook Path:

Custom Polling Settings:

HTTP Client Settings:

Custom Log Channel:

Then in config/logging.php:

🔑 Getting API Keys

To use this plugin, you need API keys from the PayNexus platform:

  1. Register at paynexus.co.ke to create an account
  2. Choose a subscription plan that fits your needs
  3. Navigate to the merchant panel after registration
  4. Create a business in your merchant dashboard
  5. Add a payment account (e.g., M-Pesa till number) to your business
  6. Navigate to API Keys and select the appropriate API key for the specific payment account you created
    • Secret Key (sk_): For initiating payments and write operations. Keep this server-side only.
    • Public Key (pk_): For read operations like checking payment status. Safe to use in client-side code.
  7. Configure webhook in PayNexus dashboard pointing to https://yourapp.com/paynexus/webhook
  8. Copy the webhook secret and set PAYNEXUS_WEBHOOK_SECRET in your .env

💬 Support


🔧 Troubleshooting

"PayNexus secret key is required"

"Unable to reach PayNexus API"

"Invalid PayNexus webhook signature"

Payment stays "pending"

Local record not updating


📄 License

MIT — see LICENSE.


**Built with ❤️ for the Laravel community** [PayNexus](https://paynexus.co.ke) • [GitHub](https://github.com/MCBANKSKE/paynexus-laravel-plugin)

All versions of laravel-paynexus with dependencies

PHP Build Version
Package Version
Requires php Version ^8.2
illuminate/support Version ^11.0|^12.0
illuminate/http Version ^11.0|^12.0
illuminate/database Version ^11.0|^12.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package paynexus/laravel-paynexus contains the following files

Loading the files please wait ...