← All changes
|
app/Modules/PaymentMethods/StripeGateway/SwitchCustomerMethod.php
+4
-10
1.3.21
→
1.6.5
View file →
| @@ -4,9 +4,8 @@ | ||
| 4 | 4 | |
| 5 | 5 | use FluentCart\App\App; |
| 6 | 6 | use FluentCart\App\Helpers\Status; |
| 7 | 7 | use FluentCart\App\Models\Order; |
| 8 | -use FluentCart\App\Models\OrderTransaction; | |
| 9 | 8 | use FluentCart\App\Models\ProductVariation; |
| 10 | 9 | use FluentCart\App\Models\Subscription; |
| 11 | 10 | use FluentCart\App\Models\SubscriptionMeta; |
| 12 | 11 | use FluentCart\App\Modules\PaymentMethods\StripeGateway\API\API; |
| @@ -29,9 +28,9 @@ | ||
| 29 | 28 | */ |
| 30 | 29 | public function switchPayMethod($data, $subscriptionId) |
| 31 | 30 | { |
| 32 | 31 | if (!$this->validateRequest($data, $subscriptionId)) { |
| 33 | - throw new \Exception('Invalid request'); | |
| 32 | + throw new \Exception(__('Invalid request', 'fluent-cart')); | |
| 34 | 33 | } |
| 35 | 34 | |
| 36 | 35 | $subscriptionModel = Subscription::query()->where('id', $subscriptionId)->first(); |
| 37 | 36 | $currentPaymentMethod = sanitize_text_field(Arr::get($data, 'currentPaymentMethod')); |
| @@ -205,9 +204,8 @@ | ||
| 205 | 204 | |
| 206 | 205 | private function updateSubscription($subscriptionId, $newSub, $plan, $customerId) |
| 207 | 206 | { |
| 208 | 207 | $subscriptionModel = Subscription::query()->where('id', $subscriptionId)->first(); |
| 209 | - $config = $subscriptionModel->config ?: []; | |
| 210 | 208 | |
| 211 | 209 | $subscriptionModel->update([ |
| 212 | 210 | 'vendor_subscription_id' => Arr::get($newSub, 'id'), |
| 213 | 211 | 'vendor_plan_id' => Arr::get($newSub, 'id'), |
| @@ -213,12 +211,11 @@ | ||
| 213 | 211 | 'vendor_plan_id' => Arr::get($newSub, 'id'), |
| 214 | 212 | 'current_payment_method' => 'stripe', |
| 215 | 213 | 'vendor_customer_id' => $customerId, |
| 216 | 214 | 'status' => StripeHelper::transformSubscriptionStatus($newSub), |
| 217 | - 'config' => array_merge($config, [ | |
| 218 | - 'is_trial_days_simulated' => 'yes' | |
| 219 | - ]) | |
| 220 | 215 | ]); |
| 216 | + | |
| 217 | + $subscriptionModel->mergeConfig(['is_trial_days_simulated' => 'yes']); | |
| 221 | 218 | } |
| 222 | 219 | |
| 223 | 220 | private function updateBillingInfo($subscriptionId, $pm) |
| 224 | 221 | { |
| @@ -269,12 +266,9 @@ | ||
| 269 | 266 | $trialDays = SubscriptionHelper::checkTrailDaysLoopHole($subscription, $trialDays); |
| 270 | 267 | |
| 271 | 268 | $billTimes = Arr::get($subscription, 'bill_times'); |
| 272 | 269 | |
| 273 | - $billCount = OrderTransaction::query()->where('subscription_id', $subscription->id) | |
| 274 | - ->where('transaction_type', Status::TRANSACTION_TYPE_CHARGE) | |
| 275 | - ->where('status', Status::TRANSACTION_SUCCEEDED) | |
| 276 | - ->count(); | |
| 270 | + $billCount = $subscription->calculateBillCount(); | |
| 277 | 271 | |
| 278 | 272 | if ($billTimes && $billCount) { |
| 279 | 273 | $billTimes = $billTimes - $billCount; |
| 280 | 274 | } else { |