PluginProbe
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler / 1.6.1
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler v1.6.1
1.6.5 1.6.4 1.6.3 1.6.2 1.6.1 1.6.0 1.5.4 1.5.5 1.5.3 1.5.2 1.5.1 1.5.0 1.4.2 1.4.1 1.4.0 1.3.28 1.3.27 1.3.26 1.3.25 1.3.23 1.3.22 1.3.21 1.3.20 1.3.19 trunk All 48 releases
fluent-cart / app / Modules / StoreManagedRenewal / RenewalModule.php

RenewalModule.php in FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler 1.6.1, at app/Modules/StoreManagedRenewal/RenewalModule.php

48 lines 1.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace FluentCart\App\Modules\StoreManagedRenewal;
4
5 use FluentCart\App\App;
6 use FluentCart\App\Helpers\Status;
7 use FluentCart\App\Modules\StoreManagedRenewal\Services\RenewalService;
8 use FluentCart\Framework\Support\Arr;
9
10 class RenewalModule
11 {
12 public static function register()
13 {
14 $self = new static();
15 App::getInstance()->addAction('fluentcart_loaded', [$self, 'init']);
16 }
17
18 public function init($app)
19 {
20 // Register the scheduler for processing manual subscription renewals
21 (new Services\RenewalScheduler())->register();
22
23 // Handle renewal invoice paid — fired from StatusHelper::syncOrderStatuses() whenever
24 // a renewal order transitions to paid. Covers all payment paths: admin mark-as-paid,
25 // offline gateway, Stripe/Paystack/MercadoPago webhooks — they all go through syncOrderStatuses.
26 add_action('fluent_cart/renewal_paid', function ($data) {
27 RenewalService::handleRenewalPaid(['order' => $data['order'] ?? null]);
28 }, 10, 1);
29
30 // Fired by gateways when a renewal invoice's charge is deferred (e.g. Stripe setup intent).
31 // Marks the invoice as payment_scheduled so the customer and admin know payment is coming.
32 $markRenewalInvoicePaymentScheduled = function ($payload, $legacySubscription = null) {
33 $order = is_array($payload) ? Arr::get($payload, 'order') : $payload;
34
35 if (!$order) {
36 return;
37 }
38
39 if ($order->payment_status === Status::PAYMENT_PENDING) {
40 $order->payment_status = Status::PAYMENT_SCHEDULED;
41 $order->save();
42 }
43 };
44
45 add_action('fluent_cart/renewal/payment_scheduled', $markRenewalInvoicePaymentScheduled, 10, 1);
46 }
47 }
48