mirror of
https://github.com/opensourcepos/opensourcepos.git
synced 2026-04-04 23:24:16 -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
64 lines
1.9 KiB
PHP
64 lines
1.9 KiB
PHP
<?php
|
|
|
|
use App\Libraries\Payments\PaymentProviderRegistry;
|
|
use CodeIgniter\Events\Events;
|
|
|
|
if (!function_exists('register_payment_provider')) {
|
|
function register_payment_provider(App\Libraries\Payments\PaymentProviderInterface $provider): void
|
|
{
|
|
PaymentProviderRegistry::getInstance()->register($provider);
|
|
}
|
|
}
|
|
|
|
if (!function_exists('get_payment_providers')) {
|
|
function get_payment_providers(): array
|
|
{
|
|
return PaymentProviderRegistry::getInstance()->getProviders();
|
|
}
|
|
}
|
|
|
|
if (!function_exists('get_enabled_payment_providers')) {
|
|
function get_enabled_payment_providers(): array
|
|
{
|
|
return PaymentProviderRegistry::getInstance()->getEnabledProviders();
|
|
}
|
|
}
|
|
|
|
if (!function_exists('get_enabled_payment_types')) {
|
|
function get_enabled_payment_types(): array
|
|
{
|
|
return PaymentProviderRegistry::getInstance()->getEnabledPaymentTypes();
|
|
}
|
|
}
|
|
|
|
if (!function_exists('get_payment_provider')) {
|
|
function get_payment_provider(string $providerId): ?App\Libraries\Payments\PaymentProviderInterface
|
|
{
|
|
return PaymentProviderRegistry::getInstance()->getProvider($providerId);
|
|
}
|
|
}
|
|
|
|
if (!function_exists('get_payment_provider_for_type')) {
|
|
function get_payment_provider_for_type(string $paymentTypeKey): ?App\Libraries\Payments\PaymentProviderInterface
|
|
{
|
|
return PaymentProviderRegistry::getInstance()->getProviderForPaymentType($paymentTypeKey);
|
|
}
|
|
}
|
|
|
|
if (!function_exists('payment_provider_content')) {
|
|
function payment_provider_content(string $section, array $data = []): string
|
|
{
|
|
$results = Events::trigger("payment_view:{$section}", $data);
|
|
$output = '';
|
|
if (is_array($results)) {
|
|
foreach ($results as $result) {
|
|
if (is_string($result)) {
|
|
$output .= $result;
|
|
}
|
|
}
|
|
} elseif (is_string($results)) {
|
|
$output = $results;
|
|
}
|
|
return $output;
|
|
}
|
|
} |