puntodev/paypal-fake 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

puntodev/paypal-fake

Composer 安装命令:

composer require --dev puntodev/paypal-fake

包简介

Fake PayPal API Client for testing

README 文档

README

A fake PayPal API server for testing Laravel applications. It replaces the real PayPal client with a mock implementation that simulates the full checkout flow without hitting the PayPal API.

Installation

composer require --dev puntodev/paypal-fake

Activation

Set the environment variable in your .env or phpunit.xml:

PAYPAL_USE_FAKE=true

The service provider auto-registers and swaps the PayPal binding in the container with PayPalFake.

How It Works

The library has four main components:

PayPalFake

Extends PayPal and manages global test state. Stores orders in a file-based cache, records method calls for assertions, and provides a reset() method to clean up between tests.

PayPalFakeApi

Extends PayPalApi with mock implementations:

  • createOrder(array $order) — Generates a fake order ID, stores it in cache, and returns the expected response structure.
  • findOrderById(string $id) — Retrieves a stored order from cache.
  • captureOrder(string $orderId) — Simulates payment capture. Throws a RequestException if the order was marked as declined.
  • verifyIpn(string $querystring) — Always returns 'VERIFIED'.

FakeCheckoutController

Exposes HTTP routes that simulate PayPal's checkout UI:

Method Route Description
GET /paypal-fake/checkout/{orderId} Displays a styled checkout page with Approve, Decline, and Cancel buttons
POST /paypal-fake/checkout/{orderId}/approve Simulates approval and posts a webhook to your app
POST /paypal-fake/checkout/{orderId}/decline Marks the order as declined
GET /paypal-fake/checkout/{orderId}/cancel Redirects to the order's cancel URL

PayPalFakeServiceProvider

When PAYPAL_USE_FAKE is true, it binds PayPalFake as a singleton in place of PayPal, registers the checkout routes, and loads the Blade views.

Checkout Flow

Your test creates an order via PayPalFakeApi::createOrder()
        ↓
Order is stored in file cache (300s TTL)
        ↓
Test or browser approves the order
        ↓
Webhook POSTed to /paypal/webhook/{providerId}
        ↓
Test captures payment via PayPalFakeApi::captureOrder()
        ↓
Assertions via PayPalFake::getCalls()

Usage

Automated Tests

use Puntodev\PaymentsFake\PayPalFake;
use Puntodev\Payments\PayPal;
use Puntodev\Payments\OrderBuilder;

// Get the fake client
$client = app(PayPal::class)->defaultClient();

// Create an order
$order = (new OrderBuilder())
    ->currency('USD')
    ->amount(25.00)
    ->make();

$created = $client->createOrder($order);

// Capture the payment
$captured = $client->captureOrder($created['id']);

// Assert calls were made
$calls = PayPalFake::getCalls('createOrder');
$this->assertCount(1, $calls);

// Clean up
PayPalFake::reset();

Manual Browser Testing

Start your Laravel app with PAYPAL_USE_FAKE=true and navigate to /paypal-fake/checkout/{orderId} after creating an order. The checkout page lets you click Approve, Decline, or Cancel to test the full flow, including webhooks hitting your application.

Test Helpers

Method Description
PayPalFake::storeOrder($id, $order) Store an order in the fake cache
PayPalFake::getStoredOrder($id) Retrieve a stored order
PayPalFake::markOrderAsDeclined($id) Mark an order as declined
PayPalFake::isOrderDeclined($id) Check if an order is declined
PayPalFake::recordCall($method, $args) Record a method call
PayPalFake::getCalls($method) Get recorded calls, optionally filtered by method
PayPalFake::reset() Clear all stored state and recorded calls

Development

Code style is enforced with Laravel Pint (laravel preset, see pint.json). The test suite is fully isolated — it never reaches the network, so no PayPal credentials are required.

composer install
composer test            # run the test suite (vendor/bin/phpunit)
composer test-coverage   # generate an HTML coverage report under ./coverage
composer lint            # check code style (vendor/bin/pint --test) — this is what CI runs
composer format          # fix code style (vendor/bin/pint)

Please run composer format before opening a pull request. See CONTRIBUTING.md for the full contribution guide.

Requirements

  • PHP >= 8.4
  • Laravel 13+

Changelog

See CHANGELOG.md for the list of changes per version.

Releases are cut from GitHub's "Generate release notes" button (grouping configured in .github/release.yml). When a release is published, the update-changelog workflow writes its notes into CHANGELOG.md and commits them back to main.

puntodev/paypal-fake 适用场景与选型建议

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

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

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

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

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-03-28