承接 zaenalrfn/laravel-paypal-checkout 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

zaenalrfn/laravel-paypal-checkout

Composer 安装命令:

composer require zaenalrfn/laravel-paypal-checkout

包简介

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

README 文档

README

Latest Version Total Downloads License

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

Features

Simple & 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

Install via Composer:

composer require zaenalrfn/laravel-paypal-checkout

Configuration

1. Publish Configuration

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

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

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

  1. Go to PayPal Developer 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

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

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

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

1. Create Webhook in PayPal Dashboard

  1. Go to PayPal Developer Dashboard
  2. Select your app
  3. Click WebhooksAdd 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

The package automatically registers the webhook route:

POST /api/paypal/webhook

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

Running Tests

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

Development Mode

For local testing without valid webhook signatures:

PAYPAL_VERIFY_WEBHOOK=false

⚠️ WARNING: Never disable webhook verification in production!

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

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

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

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

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

License

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

Credits

Support

zaenalrfn/laravel-paypal-checkout 适用场景与选型建议

zaenalrfn/laravel-paypal-checkout 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 3 次下载、GitHub Stars 达 1, 最近一次更新时间为 2026 年 01 月 29 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「payment」 「checkout」 「gateway」 「paypal」 「laravel」 「laravel-paypal」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 zaenalrfn/laravel-paypal-checkout 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 zaenalrfn/laravel-paypal-checkout 我们能提供哪些服务?
定制开发 / 二次开发

基于 zaenalrfn/laravel-paypal-checkout 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 3
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 20
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-01-29