mirror of
https://github.com/opensourcepos/opensourcepos.git
synced 2026-04-02 22:36:21 -04:00
This commit introduces a comprehensive payment provider architecture to enable
seamless integration with external payment gateways like SumUp and PayPal/Zettle.
Architecture:
- PaymentProviderInterface: Contract for all payment providers
- PaymentProviderBase: Abstract base class with common functionality
- PaymentProviderRegistry: Singleton registry for provider management
- PaymentTransaction model: Transaction tracking and status management
Infrastructure:
- Webhook controller: Endpoint for external payment callbacks
- Payment events: payment_initiated, payment_completed, sale_completed
- payment_helper.php: Helper functions for payment provider content
- Migration for ospos_payment_transactions table
Core changes:
- Add Events::trigger('payment_options') in locale_helper.php
- Add Events::trigger('sale_completed') in Sales controller
- Add Events::trigger('payment_initiated') in postAddPayment()
- Add webhook routes for /payments/webhook/{provider}
Provider stubs:
- SumUpProvider: Card reader terminal integration
- PayPalProvider: Card reader and QR code payment integration
Related issues: #4346, #4322, #3232, #3789, #3790, #2275
58 lines
1.7 KiB
PHP
58 lines
1.7 KiB
PHP
<?php
|
|
|
|
namespace App\Events;
|
|
|
|
use App\Libraries\Payments\PaymentProviderRegistry;
|
|
use CodeIgniter\Events\Events;
|
|
use Config\Services;
|
|
|
|
class PaymentEvents
|
|
{
|
|
public static function initialize(): void
|
|
{
|
|
Events::on('payment_initiated', [static::class, 'onPaymentInitiated']);
|
|
Events::on('payment_completed', [static::class, 'onPaymentCompleted']);
|
|
Events::on('payment_failed', [static::class, 'onPaymentFailed']);
|
|
Events::on('sale_completed', [static::class, 'onSaleCompleted']);
|
|
}
|
|
|
|
public static function onPaymentInitiated(array $data): void
|
|
{
|
|
log_message('debug', sprintf(
|
|
'Payment initiated: type=%s, amount=%s, sale_id=%s',
|
|
$data['payment_type'] ?? 'unknown',
|
|
$data['amount'] ?? 0,
|
|
$data['sale_id'] ?? 'pending'
|
|
));
|
|
}
|
|
|
|
public static function onPaymentCompleted(array $data): void
|
|
{
|
|
log_message('debug', sprintf(
|
|
'Payment completed: type=%s, amount=%s, sale_id=%s',
|
|
$data['payment_type'] ?? 'unknown',
|
|
$data['amount'] ?? 0,
|
|
$data['sale_id'] ?? 'pending'
|
|
));
|
|
}
|
|
|
|
public static function onPaymentFailed(array $data): void
|
|
{
|
|
log_message('warning', sprintf(
|
|
'Payment failed: type=%s, amount=%s, error=%s',
|
|
$data['payment_type'] ?? 'unknown',
|
|
$data['amount'] ?? 0,
|
|
$data['error'] ?? 'unknown error'
|
|
));
|
|
}
|
|
|
|
public static function onSaleCompleted(array $data): void
|
|
{
|
|
log_message('info', sprintf(
|
|
'Sale completed: sale_id=%s, total=%s, payments=%s',
|
|
$data['sale_id'] ?? 'unknown',
|
|
$data['total'] ?? 0,
|
|
json_encode($data['payments'] ?? [])
|
|
));
|
|
}
|
|
} |