elitehub / payment
Pacote modular para integração com múltiplos gateways de pagamento
Installs: 9
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 0
Open Issues: 0
pkg:composer/elitehub/payment
Requires
- php: ^8.4
- illuminate/support: ^10.0|^11.0|^12.0
- mercadopago/dx-php: ^3.0
README
Pacote Laravel para integração modular, leve e desacoplada com múltiplos gateways de pagamento — como Mercado Pago, com suporte a PIX, Checkout e expansão customizada.
🚀 Instalação
composer require elitehub/payment
O pacote registra automaticamente o PaymentServiceProvider e executa:
- Cópia do arquivo
config/payments.php - Migrations de
payment_providersepayment_methods - Models padrão:
PaymentProviderePaymentMethod
Se quiser publicar manualmente:
php artisan vendor:publish --provider="EliteHub\Payment\Providers\PaymentServiceProvider"
🧱 Estrutura gerada
app/
└── Models/
├── PaymentProvider.php
├── PaymentMethod.php
database/
└── migrations/
├── create_payment_providers_table.php
├── create_payment_methods_table.php
config/
└── payments.php
⚡ Exemplo de uso
$order = [ 'id' => 555, 'total' => 59.90, 'user' => ['email' => 'user@teste.com'], 'items' => collect([ [ 'product' => ['id' => 1, 'name' => 'Plano Premium'], 'price' => 59.90 ] ]) ]; $method = PaymentMethod::with('provider') ->where('method_key', 'pix') ->whereHas('provider', fn($q) => $q->where('provider_key', 'mercadopago')) ->firstOrFail(); $payment = [ 'payment_method' => $method->method_key, 'reference' => uniqid('ref_', true), ]; $gateway = PaymentManager::resolve($method->provider); $response = $gateway->initiate($order, $payment); return response()->json($response);
✅ Nenhum model é obrigatório — apenas informe o payment_method (ex: pix, preference) e o PaymentManager cuida do resto.
💡 Fluxo interno
- O cliente envia
payment_method(ex:"pix"); - O
PaymentManageridentifica o provedor ativo (mercadopago); - O gateway correspondente inicia a cobrança;
- O retorno traz QR Code, URL ou dados de checkout.
💳 Exemplo de resposta (PIX)
{
"type": "pix",
"reference": "ref_695b97a0dd6323.41320692",
"qr_code": "000201...",
"qr_code_base64": "data:image/png;base64,...",
"expires_at": "2026-01-05T12:00:00Z"
}
💳 Exemplo de resposta (Checkout)
{
"type": "preference",
"reference": "ref_695b97a0dd6323.41320692",
"checkout_url": "https://www.mercadopago.com/checkout/v1/redirect?pref_id=...",
"sandbox_url": "https://sandbox.mercadopago.com/checkout/v1/redirect?pref_id=..."
}
🔌 Gateways disponíveis
| Gateway | Provider Key | Métodos |
|---|---|---|
| Mercado Pago | mercadopago |
pix, preference |
Para criar novos gateways, implemente:
EliteHub\Payment\Contracts\PaymentGatewayInterface
⚙️ Configuração
Arquivo: config/payments.php
return [ 'gateways' => [ 'mercadopago' => [ 'token' => env('MERCADOPAGO_TOKEN'), 'webhook' => env('MERCADOPAGO_WEBHOOK_URL', 'https://example.com/webhook'), ], ], ];
Arquivo .env:
MERCADOPAGO_TOKEN=SEU_TOKEN_AQUI MERCADOPAGO_WEBHOOK_URL=https://seusite.com/webhook
🧩 Criando um novo Gateway
1️⃣ Crie src/Gateways/MeuGateway.php
use EliteHub\Payment\Contracts\PaymentGatewayInterface; use Illuminate\Http\Request; class MeuGateway implements PaymentGatewayInterface { public function initiate($order, $payment) { // Lógica de cobrança customizada } public function handleWebhook(Request $request) { // Lógica de callback (notificação) } }
2️⃣ Registre o gateway no PaymentManager:
return match ($provider->provider_key) { 'mercadopago' => app(MercadoPagoGateway::class), 'meugateway' => app(MeuGateway::class), default => throw new Exception('Gateway não suportado'), };
🧾 Logs e Debug
use Illuminate\Support\Facades\Log; Log::info('Order enviada', $order); Log::info('Payment criado', $payment);
✅ Recursos
| Recurso | Suporte |
|---|---|
| Múltiplos gateways | ✅ |
| Estrutura modular | ✅ |
| PIX e Checkout | ✅ |
| Independente de Models | ✅ |
| Publicação automática | ✅ |
| Extensível com novos gateways | ✅ |
| Compatível com Laravel 10+ | ✅ |
🧑💻 Autor
EliteHub Technologies
Desenvolvido por EliteHub
para soluções modulares e escaláveis de pagamento em Laravel.
🪪 Licença
Open-source sob a licença MIT.