leopaulo88/asaas-sdk-laravel 问题修复 & 功能扩展

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

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

leopaulo88/asaas-sdk-laravel

Composer 安装命令:

composer require leopaulo88/asaas-sdk-laravel

包简介

Laravel SDK for Asaas payment gateway integration

README 文档

README

Latest Version on Packagist Total Downloads License

A comprehensive Laravel SDK for integrating with the Asaas payment platform. This package provides a clean, fluent interface for managing customers, payments, subscriptions, transfers, webhooks, and more.

Features

  • 🎯 Complete API Coverage - Support for all major Asaas API endpoints
  • 🔄 Webhook Management - Full webhook configuration and event handling
  • 💳 Payment Processing - PIX, Boleto, Credit Card payments with installments
  • 📅 Subscription Management - Recurring payment subscriptions
  • 💸 Transfer Operations - PIX and TED transfers between accounts
  • 👥 Customer Management - Complete customer lifecycle management
  • 🏦 Account Operations - Account information and sub-account creation
  • 🔒 Secure Tokenization - PCI-compliant credit card tokenization
  • 📊 Financial Reports - Balance and transaction statistics
  • Fluent Interface - Elegant, readable code with method chaining
  • 🛡️ Type Safety - Comprehensive entity validation
  • 🧪 Well Tested - Extensive test coverage with Pest PHP

Installation

You can install the package via Composer:

composer require leopaulo88/asaas-sdk-laravel

Publish the configuration file:

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

Add your Asaas credentials to your .env file:

ASAAS_API_KEY=your_api_key_here
ASAAS_ENVIRONMENT=sandbox  # or 'production'

Quick Start

Basic Payment Creation

use Leopaulo88\Asaas\Facades\Asaas;

// Create a customer
$customer = Asaas::customers()->create([
    'name' => 'John Doe',
    'email' => 'john@example.com',
    'cpfCnpj' => '12345678901'
]);

// Create a PIX payment
$payment = Asaas::payments()->create([
    'customer' => $customer->id,
    'billingType' => 'PIX',
    'value' => 100.00,
    'dueDate' => '2025-02-15',
    'description' => 'Product purchase'
]);

// Get PIX QR Code
$pixQrCode = Asaas::payments()->pixQrCode($payment->id);
echo "QR Code: {$pixQrCode->encodedImage}";

Webhook Configuration

// Create a webhook to receive payment notifications
$webhook = Asaas::webhooks()->create([
    'name' => 'Payment Notifications',
    'url' => 'https://myapp.com/webhooks/asaas',
    'email' => 'admin@myapp.com',
    'enabled' => true,
    'sendType' => 'SEQUENTIALLY',
    'events' => [
        'PAYMENT_CREATED',
        'PAYMENT_CONFIRMED',
        'PAYMENT_RECEIVED'
    ]
]);

Subscription Management

// Create a monthly subscription
$subscription = Asaas::subscriptions()->create([
    'customer' => $customer->id,
    'billingType' => 'CREDIT_CARD',
    'value' => 29.90,
    'nextDueDate' => '2025-02-01',
    'cycle' => 'MONTHLY',
    'description' => 'Premium Plan'
]);

Available Resources

Customer Management

// Create customers
$customer = Asaas::customers()->create($data);

// List customers with filters
$customers = Asaas::customers()->list(['name' => 'John']);

// Update customer
$customer = Asaas::customers()->update($customerId, $data);

// Find specific customer
$customer = Asaas::customers()->find($customerId);

Payment Processing

// Create payments (PIX, Boleto, Credit Card)
$payment = Asaas::payments()->create($data);

// Get payment information
$payment = Asaas::payments()->find($paymentId);

// Process refunds
$refund = Asaas::payments()->refund($paymentId, $amount);

// Capture authorized payments
$payment = Asaas::payments()->capture($paymentId);

Transfer Operations

// PIX transfer
$transfer = Asaas::transfers()->create([
    'value' => 500.00,
    'pixAddressKey' => '11999999999',
    'pixAddressKeyType' => 'PHONE',
    'description' => 'PIX transfer'
]);

// Bank transfer (TED)
$transfer = Asaas::transfers()->create([
    'value' => 1000.00,
    'bankAccount' => [
        'bank' => ['code' => '033'],
        'accountName' => 'John Doe',
        'ownerName' => 'John Doe',
        'cpfCnpj' => '12345678901',
        'agency' => '1234',
        'account' => '56789-0'
    ],
    'operationType' => 'TED'
]);

Webhook Management

// Create webhook
$webhook = Asaas::webhooks()->create($data);

// List webhooks
$webhooks = Asaas::webhooks()->list();

// Update webhook
$webhook = Asaas::webhooks()->update($webhookId, $data);

// Remove webhook
Asaas::webhooks()->remove($webhookId);

Account Operations

// Get account information
$account = Asaas::accounts()->info();

// Create sub-account with webhooks
$account = Asaas::accounts()->create([
    'name' => 'Sub Account',
    'email' => 'sub@example.com',
    'cpfCnpj' => '12345678901',
    'webhooks' => [$webhookConfig]
]);

Credit Card Tokenization

// Tokenize credit card for secure storage
$token = Asaas::creditCards()->tokenize([
    'customer' => $customerId,
    'creditCard' => [
        'holderName' => 'John Doe',
        'number' => '4111111111111111',
        'expiryMonth' => '12',
        'expiryYear' => '2028',
        'ccv' => '123'
    ]
]);

// Use token in payments
$payment = Asaas::payments()->create([
    'customer' => $customerId,
    'billingType' => 'CREDIT_CARD',
    'value' => 150.00,
    'creditCardToken' => $token->creditCardToken
]);

Financial Information

// Get account balance
$balance = Asaas::finance()->balance();

// Get payment statistics
$stats = Asaas::finance()->statistics();

// Get split statistics
$splitStats = Asaas::finance()->splitStatistics();

Entity-Based Approach

The SDK supports both array-based and entity-based approaches for type safety and better IDE support:

use Leopaulo88\Asaas\Entities\Payment\PaymentCreate;use Leopaulo88\Asaas\Entities\Webhook\WebhookCreate;

// Using entities with fluent interface
$payment = PaymentCreate::make()
    ->customer('cus_123456')
    ->billingType('PIX')
    ->value(100.00)
    ->dueDate('2025-02-15')
    ->description('Product purchase');

$result = Asaas::payments()->create($payment);

// WebhookCreate entity
$webhook = (new WebhookCreate)
    ->name('Payment WebhookCreate')
    ->url('https://myapp.com/webhook')
    ->enabled(true)
    ->sendType('SEQUENTIALLY')
    ->events(['PAYMENT_CONFIRMED', 'PAYMENT_RECEIVED']);

Environment Configuration

The package supports both sandbox and production environments:

// Use specific environment
$payment = Asaas::withApiKey($apiKey, 'production')
    ->payments()
    ->create($data);

// Multiple tenants/accounts
$payment = Asaas::withApiKey($tenant->api_key)
    ->payments()
    ->create($data);

Event Handling

Available Webhook Events

Payment Events

  • PAYMENT_CREATED - Payment was created
  • PAYMENT_CONFIRMED - Payment was confirmed
  • PAYMENT_RECEIVED - Payment was received
  • PAYMENT_OVERDUE - Payment is overdue
  • PAYMENT_REFUNDED - Payment was refunded

Subscription Events

  • SUBSCRIPTION_CREATED - Subscription was created
  • SUBSCRIPTION_UPDATED - Subscription was updated
  • SUBSCRIPTION_DELETED - Subscription was deleted

Transfer Events

  • TRANSFER_CREATED - Transfer was created
  • TRANSFER_DONE - Transfer was completed
  • TRANSFER_FAILED - Transfer failed

Webhook Implementation Example

// In your webhook controller
public function handle(Request $request)
{
    $payload = $request->json()->all();
    $event = $payload['event'];
    
    switch ($event) {
        case 'PAYMENT_CONFIRMED':
            $this->handlePaymentConfirmed($payload['payment']);
            break;
        case 'SUBSCRIPTION_CREATED':
            $this->handleSubscriptionCreated($payload['subscription']);
            break;
    }
    
    return response('OK', 200);
}

Error Handling

The SDK provides comprehensive error handling:

use Leopaulo88\Asaas\Exceptions\{
    BadRequestException,
    UnauthorizedException,
    NotFoundException
};

try {
    $payment = Asaas::payments()->create($data);
} catch (BadRequestException $e) {
    // Validation errors
    $errors = $e->getErrors();
    foreach ($errors as $field => $messages) {
        echo "Field {$field}: " . implode(', ', $messages);
    }
} catch (UnauthorizedException $e) {
    // Invalid API key
    echo "Authentication failed: " . $e->getMessage();
} catch (NotFoundException $e) {
    // Resource not found
    echo "Resource not found: " . $e->getMessage();
}

Testing

Run the test suite:

./vendor/bin/pest

Documentation

Comprehensive documentation is available in the docs/ directory:

Contributing

Please see CONTRIBUTING for details on how to contribute to this project.

Security

If you discover any security-related issues, please email the maintainer instead of using the issue tracker.

License

This package is open-sourced software licensed under the MIT license.

Support

Changelog

Please see CHANGELOG for more information on what has changed recently.

Made with ❤️ for the Laravel community

leopaulo88/asaas-sdk-laravel 适用场景与选型建议

leopaulo88/asaas-sdk-laravel 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1.56k 次下载、GitHub Stars 达 6, 最近一次更新时间为 2025 年 07 月 20 日, 在 PHP 生态内属于活跃度较高的组件。

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

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

围绕 leopaulo88/asaas-sdk-laravel 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

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