Feature: Moving Payment Methods to DB, adding fees, Transaction Updates, Refund Updates, General Updates to Payments
This commit is contained in:
@@ -2,24 +2,37 @@
|
||||
|
||||
namespace Modules\Core\Providers;
|
||||
|
||||
use Illuminate\Support\Facades\Event;
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
use Lunar\Facades\ModelManifest;
|
||||
use Lunar\Models\Contracts\Transaction as TransactionContract;
|
||||
use Lunar\Pipelines\Cart\ApplyShipping;
|
||||
use Modules\Core\Command\SyncPaymentDriversCommand;
|
||||
use Modules\Core\Payment\Drivers\BankTransferPaymentDriver;
|
||||
use Modules\Core\Payment\Drivers\OfflinePaymentDriver;
|
||||
use Modules\Core\Payment\Drivers\StripePaymentDriver;
|
||||
use Modules\Core\Payment\Events\PaymentMethodCreated;
|
||||
use Modules\Core\Payment\Events\PaymentMethodDeleted;
|
||||
use Modules\Core\Payment\Events\PaymentMethodUpdated;
|
||||
use Modules\Core\Payment\Listeners\LogPaymentMethodActivity;
|
||||
use Modules\Core\Payment\Models\CoreTransaction;
|
||||
use Modules\Core\Payment\Services\PaymentDriverRegistry;
|
||||
|
||||
class PaymentServiceProvider extends ServiceProvider
|
||||
{
|
||||
public function register(): void
|
||||
{
|
||||
$this->mergeConfigFrom(__DIR__ . '/../../config/payment.php', 'payment');
|
||||
|
||||
$this->app->singleton(PaymentDriverRegistry::class);
|
||||
}
|
||||
|
||||
public function boot(): void
|
||||
{
|
||||
config([
|
||||
'lunar.payments.types' => array_merge(
|
||||
config('lunar.payments.types', []),
|
||||
config('payment.types', [])
|
||||
),
|
||||
]);
|
||||
$registry = $this->app->make(PaymentDriverRegistry::class);
|
||||
$registry->register('offline', OfflinePaymentDriver::class, 'Offline / Manual');
|
||||
$registry->register('stripe', StripePaymentDriver::class, 'Stripe');
|
||||
$registry->register('bank-transfer', BankTransferPaymentDriver::class, 'Bank Transfer');
|
||||
|
||||
$cartPipeline = config('lunar.cart.pipelines.cart', []);
|
||||
$insertAfter = array_search(ApplyShipping::class, $cartPipeline, true);
|
||||
@@ -39,6 +52,27 @@ class PaymentServiceProvider extends ServiceProvider
|
||||
|
||||
config(['lunar.cart.pipelines.cart' => $cartPipeline]);
|
||||
|
||||
// Same contract-swap mechanism this codebase already uses for
|
||||
// Customer/Staff (see e.g. consuming apps' own AppServiceProvider,
|
||||
// ModelManifest::replace(Contracts\Customer::class, ...)) — every
|
||||
// place Lunar's own code resolves a transaction via
|
||||
// Transaction::modelClass() (Order::transactions()'s own relation
|
||||
// included) gets Modules\Core\Payment\Models\CoreTransaction
|
||||
// instead of the vendor's own Transaction. That subclass's
|
||||
// driver() override is the ENTIRE fix for the admin panel's
|
||||
// refund/capture actions silently landing on our real payment
|
||||
// system — see CoreTransaction's own docblock. Lunar's own
|
||||
// Payments facade/PaymentManager is never touched at all.
|
||||
ModelManifest::replace(TransactionContract::class, CoreTransaction::class);
|
||||
|
||||
Event::listen(PaymentMethodCreated::class, [LogPaymentMethodActivity::class, 'handleCreated']);
|
||||
Event::listen(PaymentMethodUpdated::class, [LogPaymentMethodActivity::class, 'handleUpdated']);
|
||||
Event::listen(PaymentMethodDeleted::class, [LogPaymentMethodActivity::class, 'handleDeleted']);
|
||||
|
||||
$this->loadRoutesFrom(__DIR__ . '/../Payment/routes/webhooks.php');
|
||||
|
||||
if ($this->app->runningInConsole()) {
|
||||
$this->commands([SyncPaymentDriversCommand::class]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user