PHPackages                             zaenalrfn/laravel-paypal-checkout - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Payment Processing](/categories/payments)
4. /
5. zaenalrfn/laravel-paypal-checkout

ActiveLibrary[Payment Processing](/categories/payments)

zaenalrfn/laravel-paypal-checkout
=================================

A secure and production-ready PayPal Checkout integration for Laravel with DTO-based payloads and verified webhooks

v1.0.1(3mo ago)11MITPHPPHP ^8.2

Since Jan 29Pushed 3mo agoCompare

[ Source](https://github.com/zaenalrfn/laravel-paypal-checkout)[ Packagist](https://packagist.org/packages/zaenalrfn/laravel-paypal-checkout)[ RSS](/packages/zaenalrfn-laravel-paypal-checkout/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (7)Versions (3)Used By (0)

Laravel PayPal Package
======================

[](#laravel-paypal-package)

[![Latest Version](https://camo.githubusercontent.com/7e7386d01ffdada641226441e6eaaee29e30089693e2ad9dd9a84d3c425df2e8/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f7a61656e616c72666e2f6c61726176656c2d70617970616c2d636865636b6f75742e737667)](https://packagist.org/packages/zaenalrfn/laravel-paypal-checkout)[![Total Downloads](https://camo.githubusercontent.com/f5d8aa11a9ac2f54a055cda76dd9f2f6e7e9b4932c60db66e222409adb42f40d/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f7a61656e616c72666e2f6c61726176656c2d70617970616c2d636865636b6f75742e737667)](https://packagist.org/packages/zaenalrfn/laravel-paypal-checkout)[![License](https://camo.githubusercontent.com/5b972550d5a50cf0c016479227facacffd881a9edc3cfd24e93742c5461b305f/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f7a61656e616c72666e2f6c61726176656c2d70617970616c2d636865636b6f75742e737667)](https://packagist.org/packages/zaenalrfn/laravel-paypal-checkout)

A modern, clean, and well-tested PayPal payment gateway integration for Laravel 11 &amp; 12.

Features
--------

[](#features)

✅ **Simple &amp; Intuitive API** - Fluent interface for creating orders and processing payments
✅ **Webhook Support** - Secure webhook verification and event handling
✅ **Type-Safe DTOs** - Immutable data transfer objects for better code quality
✅ **Comprehensive Logging** - Dedicated PayPal log channel for debugging
✅ **Test Coverage** - Well-tested codebase with Pest PHP
✅ **Laravel 12 Ready** - Compatible with Laravel 11 and 12

Installation
------------

[](#installation)

Install via Composer:

```
composer require zaenalrfn/laravel-paypal-checkout
```

Configuration
-------------

[](#configuration)

### 1. Publish Configuration

[](#1-publish-configuration)

```
php artisan vendor:publish --tag=paypal-config
```

This creates `config/paypal.php` with all available options.

### 2. Environment Variables

[](#2-environment-variables)

Add your PayPal credentials to `.env`:

```
# PayPal Mode (sandbox or live)
PAYPAL_MODE=sandbox

# Sandbox Credentials
PAYPAL_SANDBOX_CLIENT_ID=your-sandbox-client-id
PAYPAL_SANDBOX_CLIENT_SECRET=your-sandbox-client-secret

# Production Credentials (when ready)
PAYPAL_LIVE_CLIENT_ID=your-live-client-id
PAYPAL_LIVE_CLIENT_SECRET=your-live-client-secret

# Webhook ID (get from PayPal Dashboard)
PAYPAL_WEBHOOK_ID=your-webhook-id

# Optional: Disable webhook verification in development
PAYPAL_VERIFY_WEBHOOK=true
```

### 3. Get PayPal Credentials

[](#3-get-paypal-credentials)

1. Go to [PayPal Developer Dashboard](https://developer.paypal.com/dashboard/)
2. Create an app or select existing one
3. Copy **Client ID** and **Secret**
4. For webhooks: Go to **Webhooks** → Create webhook → Copy **Webhook ID**

Usage
-----

[](#usage)

### Creating a PayPal Order

[](#creating-a-paypal-order)

```
use Zaenalrfn\LaravelPayPal\Facades\PayPal;
use Zaenalrfn\LaravelPayPal\DTO\{CheckoutOrderData, PurchaseUnitData, AmountData};

// Build order data
$order = CheckoutOrderData::capture()
    ->addPurchaseUnit(
        new PurchaseUnitData(
            new AmountData('USD', '10.00'),
            'ORDER-123'  // Optional reference ID
        )
    )
    ->withReturnUrl('https://yoursite.com/payment/success')
    ->withCancelUrl('https://yoursite.com/payment/cancel');

// Create order with PayPal
$response = PayPal::checkout()->create($order);

// Get approval URL
$approvalUrl = collect($response['links'])
    ->firstWhere('rel', 'approve')['href'];

// Redirect user to PayPal
return redirect($approvalUrl);
```

### Capturing a Payment

[](#capturing-a-payment)

After user approves payment on PayPal:

```
use Zaenalrfn\LaravelPayPal\Facades\PayPal;

// Get order ID from PayPal callback
$orderId = $request->query('token');

// Capture the payment
$response = PayPal::checkout()->capture($orderId);

if ($response['status'] === 'COMPLETED') {
    // Payment successful!
    $captureId = $response['purchase_units'][0]['payments']['captures'][0]['id'];

    // Store in database, fulfill order, etc.
}
```

### Processing Refunds

[](#processing-refunds)

```
use Zaenalrfn\LaravelPayPal\Facades\PayPal;

$response = PayPal::payment()->refund($captureId, [
    'amount' => [
        'currency_code' => 'USD',
        'value' => '10.00'
    ],
    'note_to_payer' => 'Refund for order #123'
]);
```

Webhook Setup
-------------

[](#webhook-setup)

### 1. Create Webhook in PayPal Dashboard

[](#1-create-webhook-in-paypal-dashboard)

1. Go to [PayPal Developer Dashboard](https://developer.paypal.com/dashboard/)
2. Select your app
3. Click **Webhooks** → **Add Webhook**
4. Webhook URL: `https://yoursite.com/api/paypal/webhook`
5. Select events:
    - `PAYMENT.CAPTURE.COMPLETED`
    - `PAYMENT.CAPTURE.DENIED`
    - `PAYMENT.CAPTURE.REFUNDED`
6. Save and copy the **Webhook ID**
7. Add to `.env`: `PAYPAL_WEBHOOK_ID=your-webhook-id`

### 2. Webhook Route

[](#2-webhook-route)

The package automatically registers the webhook route:

```
POST /api/paypal/webhook

```

### 3. Handle Webhook Events

[](#3-handle-webhook-events)

Extend the `WebhookHandler` to customize event handling:

```
namespace App\PayPal;

use Zaenalrfn\LaravelPayPal\Webhooks\WebhookHandler as BaseHandler;
use Zaenalrfn\LaravelPayPal\Support\PayPalLogger;

class CustomWebhookHandler extends BaseHandler
{
    protected function paymentCompleted(array $event): void
    {
        $captureId = $event['resource']['id'] ?? null;

        // Update your database
        \App\Models\Payment::where('capture_id', $captureId)
            ->update(['status' => 'completed']);

        PayPalLogger::info('Payment completed', ['capture_id' => $captureId]);
    }
}
```

Then bind it in your `AppServiceProvider`:

```
$this->app->bind(
    \Zaenalrfn\LaravelPayPal\Webhooks\WebhookHandler::class,
    \App\PayPal\CustomWebhookHandler::class
);
```

Testing
-------

[](#testing)

### Running Tests

[](#running-tests)

```
cd packages/laravel-paypal
./vendor/bin/pest
```

### Development Mode

[](#development-mode)

For local testing without valid webhook signatures:

```
PAYPAL_VERIFY_WEBHOOK=false
```

**⚠️ WARNING:** Never disable webhook verification in production!

Logging
-------

[](#logging)

All PayPal interactions are logged to a dedicated channel:

```
storage/logs/paypal-{date}.log

```

View logs:

```
tail -f storage/logs/paypal-$(date +%Y-%m-%d).log
```

Troubleshooting
---------------

[](#troubleshooting)

### Webhook 500 Error

[](#webhook-500-error)

**Problem:** Webhook returns 500 Internal Server Error

**Solutions:**

1. **Wrong Webhook ID** - Verify `PAYPAL_WEBHOOK_ID` matches PayPal Dashboard
2. **Environment Mismatch** - Sandbox webhook ID only works with sandbox credentials
3. **Development Testing** - Set `PAYPAL_VERIFY_WEBHOOK=false` for local testing

### Authentication Failed

[](#authentication-failed)

**Problem:** "PayPal authentication failed" error

**Solutions:**

1. Verify `PAYPAL_SANDBOX_CLIENT_ID` and `PAYPAL_SANDBOX_CLIENT_SECRET` are correct
2. Check `PAYPAL_MODE` matches your credentials (sandbox vs live)
3. Ensure credentials are from the correct PayPal app

### Order Creation Failed

[](#order-creation-failed)

**Problem:** Order creation returns 400 error

**Solutions:**

1. Verify amount format: must be string with 2 decimals (e.g., "10.00")
2. Check currency code is valid (USD, EUR, GBP, etc.)
3. Ensure at least one purchase unit is added

Security
--------

[](#security)

- ✅ Webhook signature verification enabled by default
- ✅ No credentials in code (environment variables only)
- ✅ Dedicated exception handling with context
- ✅ Comprehensive logging for audit trails

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE) for more information.

Credits
-------

[](#credits)

- [Zaenal Arifin](https://github.com/zaenalrfn)
- [All Contributors](../../contributors)

Support
-------

[](#support)

- **Issues:** [GitHub Issues](https://github.com/zaenalrfn/laravel-paypal/issues)
- **Documentation:** [PayPal API Docs](https://developer.paypal.com/docs/api/overview/)

###  Health Score

36

—

LowBetter than 82% of packages

Maintenance80

Actively maintained with recent releases

Popularity3

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity48

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~0 days

Total

2

Last Release

104d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/dfa50826c640ad5feaa200dd77615b7f770b3c037c91f390fbedc74384e36823?d=identicon)[zaenalrfn](/maintainers/zaenalrfn)

---

Top Contributors

[![zaenalrfn](https://avatars.githubusercontent.com/u/79745345?v=4)](https://github.com/zaenalrfn "zaenalrfn (6 commits)")

---

Tags

gatewaylaravelpaymentpaypallaravelpaymentgatewaypaypalcheckoutlaravel paypallaravel-paypal-checkout

###  Code Quality

TestsPest

### Embed Badge

![Health badge](/badges/zaenalrfn-laravel-paypal-checkout/health.svg)

```
[![Health](https://phpackages.com/badges/zaenalrfn-laravel-paypal-checkout/health.svg)](https://phpackages.com/packages/zaenalrfn-laravel-paypal-checkout)
```

###  Alternatives

[shetabit/payment

Laravel Payment Gateway Integration Package

944330.1k5](/packages/shetabit-payment)[sebdesign/laravel-viva-payments

A Laravel package for integrating the Viva Payments gateway

4845.9k](/packages/sebdesign-laravel-viva-payments)[omalizadeh/laravel-multi-payment

A driver-based laravel package for online payments via multiple gateways

491.1k](/packages/omalizadeh-laravel-multi-payment)[sostheblack/moip

Laravel Package for Moip.

171.9k](/packages/sostheblack-moip)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
