| @@ -30,8 +30,18 @@ | ||
| 30 | 30 | 'trial_end_date' => DateTime::gmtNow()->addDays(3)->format('Y-m-d H:i:s'), |
| 31 | 31 | ], |
| 32 | 32 | ]; |
| 33 | 33 | |
| 34 | + if (Str::startsWith($template, 'order.reminder.renewal_overdue.')) { | |
| 35 | + if (Str::contains($template, '.final.')) { | |
| 36 | + $previewData['reminder']['stage'] = 'overdue_7'; | |
| 37 | + } elseif (Str::contains($template, '.followup.')) { | |
| 38 | + $previewData['reminder']['stage'] = 'overdue_3'; | |
| 39 | + } else { | |
| 40 | + $previewData['reminder']['stage'] = 'overdue_1'; | |
| 41 | + } | |
| 42 | + } | |
| 43 | + | |
| 34 | 44 | if (Str::startsWith($template, 'subscription.')) { |
| 35 | 45 | $previewData['transaction'] = $subscription->getLatestTransaction(); |
| 36 | 46 | |
| 37 | 47 | if (Str::contains($template, 'trial_end')) { |
| @@ -37,8 +47,12 @@ | ||
| 37 | 47 | if (Str::contains($template, 'trial_end')) { |
| 38 | 48 | $previewData['reminder']['stage'] = 'trial_end_3'; |
| 39 | 49 | } |
| 40 | 50 | |
| 51 | + if (Str::contains($template, 'renewal_failed')) { | |
| 52 | + $previewData['error'] = __('Your card was declined.', 'fluent-cart'); | |
| 53 | + } | |
| 54 | + | |
| 41 | 55 | if (Str::contains($template, 'canceled')) { |
| 42 | 56 | $previewData['reason'] = __('canceled on customer request', 'fluent-cart'); |
| 43 | 57 | $previewData['subscription'] = $this->getDummySubscription($previewData['order']); |
| 44 | 58 | } |
| @@ -59,13 +73,18 @@ | ||
| 59 | 73 | |
| 60 | 74 | private function getDummyTransaction(): object |
| 61 | 75 | { |
| 62 | 76 | return new class { |
| 63 | - public $created_at = ''; | |
| 77 | + public $created_at; | |
| 64 | 78 | public $total = 4900; |
| 65 | 79 | public $vendor_charge_id = 'ch_preview_123'; |
| 66 | 80 | public $order = null; |
| 67 | 81 | |
| 82 | + public function __construct() | |
| 83 | + { | |
| 84 | + $this->created_at = DateTime::gmtNow(); | |
| 85 | + } | |
| 86 | + | |
| 68 | 87 | public function getPaymentMethodText() |
| 69 | 88 | { |
| 70 | 89 | return 'card'; |
| 71 | 90 | } |
| @@ -76,9 +95,9 @@ | ||
| 76 | 95 | { |
| 77 | 96 | $customer = $this->getDummyCustomer(); |
| 78 | 97 | $transaction = $this->getDummyTransaction(); |
| 79 | 98 | |
| 80 | - return new class($customer, $transaction, new Collection()) { | |
| 99 | + $order = new class($customer, $transaction, new Collection()) { | |
| 81 | 100 | public $id = 1001; |
| 82 | 101 | public $uuid = 'preview-order-uuid'; |
| 83 | 102 | public $invoice_no = 'FC-1001'; |
| 84 | 103 | public $customer; |
| @@ -98,8 +117,9 @@ | ||
| 98 | 117 | public $total_amount = 4900; |
| 99 | 118 | public $total_paid = 0; |
| 100 | 119 | public $total_refund = 0; |
| 101 | 120 | public $payment_status = 'pending'; |
| 121 | + public $config = []; | |
| 102 | 122 | private $latestTransaction; |
| 103 | 123 | |
| 104 | 124 | public function __construct($customer, $transaction, $emptyCollection) |
| 105 | 125 | { |
| @@ -106,14 +126,28 @@ | ||
| 106 | 126 | $this->customer = $customer; |
| 107 | 127 | $this->latestTransaction = $transaction; |
| 108 | 128 | $this->order_items = new Collection([ |
| 109 | 129 | [ |
| 110 | - 'post_title' => 'Sample Product', | |
| 111 | - 'quantity' => 1, | |
| 112 | - 'title' => 'Standard Plan', | |
| 113 | - 'payment_type' => 'onetime', | |
| 114 | - 'payment_info' => '', | |
| 115 | - 'formatted_total' => '$49.00', | |
| 130 | + 'post_title' => 'Sample Product', | |
| 131 | + 'quantity' => 1, | |
| 132 | + 'title' => 'Standard Plan', | |
| 133 | + 'payment_type' => 'onetime', | |
| 134 | + 'payment_info' => '', | |
| 135 | + 'formatted_total' => '$49.00', | |
| 136 | + 'package_info' => __('Package: Medium Box · 30 × 20 × 15 cm · Wt: 2 kg · Shipping wt: 2.5 kg', 'fluent-cart'), | |
| 137 | + 'other_info' => [ | |
| 138 | + 'package_name' => 'Medium Box', | |
| 139 | + 'package_type' => 'box', | |
| 140 | + 'package_length' => 30, | |
| 141 | + 'package_width' => 20, | |
| 142 | + 'package_height' => 15, | |
| 143 | + 'package_dimension_unit' => 'cm', | |
| 144 | + 'weight' => 2, | |
| 145 | + 'weight_unit' => 'kg', | |
| 146 | + 'package_weight' => 0.5, | |
| 147 | + 'package_weight_unit' => 'kg', | |
| 148 | + 'package_slug' => 'medium-box', | |
| 149 | + ], | |
| 116 | 150 | ], |
| 117 | 151 | ]); |
| 118 | 152 | $this->subscriptions = $emptyCollection; |
| 119 | 153 | $this->orderTaxRates = $emptyCollection; |
| @@ -125,8 +159,26 @@ | ||
| 125 | 159 | { |
| 126 | 160 | return '#'; |
| 127 | 161 | } |
| 128 | 162 | |
| 163 | + public function getMeta($metaKey, $defaultValue = false) | |
| 164 | + { | |
| 165 | + if ($metaKey === 'due_date') { | |
| 166 | + return gmdate('Y-m-d H:i:s', strtotime('+7 days')); | |
| 167 | + } | |
| 168 | + return $defaultValue; | |
| 169 | + } | |
| 170 | + | |
| 171 | + public function isReverseChargeTaxOrder() | |
| 172 | + { | |
| 173 | + return false; | |
| 174 | + } | |
| 175 | + | |
| 176 | + public function getOrderRcMode() | |
| 177 | + { | |
| 178 | + return 'fixed'; | |
| 179 | + } | |
| 180 | + | |
| 129 | 181 | public function getLatestTransaction() |
| 130 | 182 | { |
| 131 | 183 | return $this->latestTransaction; |
| 132 | 184 | } |
| @@ -140,8 +192,14 @@ | ||
| 140 | 192 | { |
| 141 | 193 | return new Collection([]); |
| 142 | 194 | } |
| 143 | 195 | }; |
| 196 | + | |
| 197 | + // Templates reach the order through the transaction too (e.g. the | |
| 198 | + // renewal admin email's $transaction->order->getViewUrl('admin')). | |
| 199 | + $transaction->order = $order; | |
| 200 | + | |
| 201 | + return $order; | |
| 144 | 202 | } |
| 145 | 203 | |
| 146 | 204 | private function getDummySubscription($order): object |
| 147 | 205 | { |
| @@ -151,8 +209,9 @@ | ||
| 151 | 209 | return new class($customer, $transaction, $order) { |
| 152 | 210 | public $id = 2001; |
| 153 | 211 | public $uuid = 'preview-subscription-uuid'; |
| 154 | 212 | public $item_name = 'Sample Subscription'; |
| 213 | + public $display_item_name = 'Sample Subscription'; | |
| 155 | 214 | public $billing_interval = 'yearly'; |
| 156 | 215 | public $next_billing_date; |
| 157 | 216 | public $recurring_total = 4900; |
| 158 | 217 | public $status = 'active'; |
| @@ -165,8 +224,9 @@ | ||
| 165 | 224 | { |
| 166 | 225 | $this->customer = $customer; |
| 167 | 226 | $this->latestTransaction = $transaction; |
| 168 | 227 | $this->order = $order; |
| 228 | + $transaction->order = $order; | |
| 169 | 229 | $this->next_billing_date = \FluentCart\App\Services\DateTime\DateTime::gmtNow()->addDays(30)->format('Y-m-d H:i:s'); |
| 170 | 230 | $this->trial_ends_at = \FluentCart\App\Services\DateTime\DateTime::gmtNow()->addDays(3)->format('Y-m-d H:i:s'); |
| 171 | 231 | } |
| 172 | 232 | |
| @@ -182,8 +242,13 @@ | ||
| 182 | 242 | |
| 183 | 243 | public function getReactivateUrl() |
| 184 | 244 | { |
| 185 | 245 | return '#'; |
| 246 | + } | |
| 247 | + | |
| 248 | + public function getPaymentMethodText() | |
| 249 | + { | |
| 250 | + return 'Visa ***4242'; | |
| 186 | 251 | } |
| 187 | 252 | }; |
| 188 | 253 | } |
| 189 | 254 | } |