graigdev/payment 问题修复 & 功能扩展

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

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

graigdev/payment

Composer 安装命令:

composer require graigdev/payment

包简介

A Laravel package that generates payment codes for subscriptions with wallet management

README 文档

README

A Laravel package that generates payment codes for subscriptions with wallet management.

Features

  • Wallet management system
  • Payment code generation and redemption
  • Transaction tracking
  • Configurable settings

Installation

You can install the package via composer:

composer require graigdev/payment

Then publish the config file:

php artisan vendor:publish --tag="payment-config"

Optional: Publish Migrations and Models

You can publish the migrations to customize them before running:

php artisan vendor:publish --tag="payment-migrations"

Publishing Models

You have two options to publish the models:

Option 1: Using the vendor:publish command:

php artisan vendor:publish --tag="payment-models"

Option 2: Using the custom command (recommended):

php artisan payment:publish-models

The custom command automatically adjusts namespaces and references within the models. Use the --force flag to overwrite existing models:

php artisan payment:publish-models --force

If you publish the models, all references in your code should be updated from GraigDev\Payment\Models to App\Models\Payment.

Finally, run the migrations:

php artisan migrate

Usage

Wallet Management

Each user has a wallet that can be used to manage their balance.

// Get a user's wallet
$wallet = \GraigDev\Payment\Models\Wallet::where('user_id', auth()->id())->first();

// If you published the models, use this instead:
// $wallet = \App\Models\Payment\Wallet::where('user_id', auth()->id())->first();

// Deposit funds
$wallet->deposit(100, 'Manual deposit');

// Withdraw funds
$wallet->withdraw(50, 'Manual withdrawal');

Payment Codes

Generate and redeem payment codes:

// Generate a payment code
$paymentCode = \GraigDev\Payment\Models\PaymentCode::create([
    'code' => 'PAY-' . strtoupper(Str::random(10)),
    'amount' => 100,
    'description' => 'Subscription payment',
    'generated_by' => auth()->id(),
]);

// Redeem a payment code
$code = 'PAY-ABCDEFGHIJ';
$paymentCode = \GraigDev\Payment\Models\PaymentCode::where('code', $code)
    ->unused()
    ->valid()
    ->first();

if ($paymentCode) {
    $paymentCode->markAsUsed(auth()->id());
    $wallet->deposit($paymentCode->amount, 'Redeemed code: ' . $code);
}

Transactions

View transaction history:

// Get all transactions for a wallet
$transactions = $wallet->transactions;

// Get transactions of a specific type
$deposits = $wallet->transactions()->ofType('DEPOSIT')->get();

Configuration

You can configure the package by editing the config/payment.php file:

return [
    // Payment code settings
    'code_prefix' => 'PAY',
    'code_length' => 10,
    
    // Wallet settings
    'currency' => 'USD',
    'min_withdrawal' => 10,
    
    // Transaction types
    'transaction_types' => [
        'deposit' => 'DEPOSIT',
        'withdrawal' => 'WITHDRAWAL',
        'transfer' => 'TRANSFER',
        'payment' => 'PAYMENT',
        'refund' => 'REFUND',
    ],
];

License

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

graigdev/payment 适用场景与选型建议

graigdev/payment 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 9 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 04 月 04 日, 在 PHP 生态内属于活跃度较高的组件。

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

围绕 graigdev/payment 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-04-04