PluginProbe
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler / 1.6.5
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler v1.6.5
1.6.6 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 All 49 releases
← All changes | app/Services/OrderService.php +40 -2 1.4.0 → 1.6.5 View file →
@@ -6,8 +6,9 @@
6 6 use FluentCart\Api\StoreSettings;
7 7 use FluentCart\App\App;
8 8 use FluentCart\App\Helpers\AddressHelper;
9 9 use FluentCart\App\Helpers\Helper;
10 +use FluentCart\App\Helpers\Status;
10 11 use FluentCart\App\Models\Model;
11 12 use FluentCart\App\Models\Order;
12 13 use FluentCart\App\Models\OrderItem;
13 14 use FluentCart\App\Models\OrderMeta;
@@ -13,8 +14,10 @@
13 14 use FluentCart\App\Models\OrderMeta;
14 15 use FluentCart\App\Models\OrderTransaction;
15 16 use FluentCart\App\Models\ProductVariation;
16 17 use FluentCart\App\Models\Subscription;
18 +use FluentCart\App\Modules\Subscriptions\Services\SystemChargeService;
19 +use FluentCart\App\Services\Payments\PaymentHelper;
17 20 use FluentCart\Framework\Support\Arr;
18 21
19 22 class OrderService
20 23 {
@@ -618,12 +621,33 @@
618 621 'reactivate_url' => $subscription->getReactivateUrl(),
619 622 'can_upgrade' => $subscription->canUpgrade(),
620 623 'can_switch_payment_method' => $subscription->canSwitchPaymentMethod(),
621 624 'can_update_payment_method' => $subscription->canUpdatePaymentMethod(),
622 - 'item_name' => $subscription->item_name
625 + 'collection_method' => $subscription->collection_method,
626 + 'is_auto_charged' => $subscription->isSystem(),
627 + 'item_name' => $subscription->display_item_name
623 628 ];
624 629 }
625 630
631 + /**
632 + * A system renewal order still inside its auto-charge retry window has no
633 + * Pay Now — the charge is coming automatically. Other renewals unaffected.
634 + */
635 + protected static function renewalPayNowAllowed(Order $order): bool
636 + {
637 + if (!$order->parent_id) {
638 + return true;
639 + }
640 +
641 + $subscription = Subscription::query()->where('parent_order_id', $order->parent_id)->first();
642 +
643 + if (!$subscription || !$subscription->isSystem()) {
644 + return true;
645 + }
646 +
647 + return SystemChargeService::isExhausted($subscription, $order);
648 + }
649 +
626 650 public static function transformTransaction(OrderTransaction $transaction)
627 651 {
628 652 $data = [
629 653 'uuid' => $transaction->uuid,
@@ -644,13 +668,27 @@
644 668 if ($transaction->order && self::canGenerateReceiptPdf()) {
645 669 $data['receipt_view_url'] = $transaction->order->getReceiptViewUrl();
646 670 }
647 671
672 + if ($transaction->order
673 + && $transaction->order->type === Status::ORDER_TYPE_RENEWAL
674 + && $transaction->status === Status::TRANSACTION_PENDING
675 + && self::renewalPayNowAllowed($transaction->order)
676 + ) {
677 + $data['custom_checkout_url'] = add_query_arg([
678 + 'fluent-cart' => 'custom_checkout',
679 + 'order_hash' => $transaction->order->uuid,
680 + ], home_url('/'));
681 + }
682 +
648 683 return $data;
649 684 }
650 685
651 686 public static function canGenerateReceiptPdf(): bool
652 687 {
653 - return App::isProActive() && defined('FLUENT_PDF');
688 + return (bool) apply_filters(
689 + 'fluent_cart/pdf/can_generate_receipt',
690 + App::isProActive() && defined('FLUENT_PDF')
691 + );
654 692 }
655 693
656 694 }