From 6de7679262404a44b0334384ebf6e2b1984e79f0 Mon Sep 17 00:00:00 2001 From: Itzamna Serrano <72818019+spitfire305@users.noreply.github.com> Date: Wed, 21 Aug 2024 14:42:20 -0600 Subject: [PATCH] Subscription: Allow changing currency (#952) * Subscription: Allow changing currency --------- Co-authored-by: spitfire305 --- .../Billing/PaymentMethodController.php | 17 ++++++++++++++++- app/Models/UserLog.php | 1 + lang/en/settings.php | 5 ++++- .../views/billing/payment-method.blade.php | 15 ++++++++++++--- .../subscription/currency/_blocked.blade.php | 2 +- .../subscription/currency/_form.blade.php | 14 ++++++++++++++ .../subscription/currency/_reset.blade.php | 7 +++++++ 7 files changed, 55 insertions(+), 6 deletions(-) create mode 100644 resources/views/settings/subscription/currency/_reset.blade.php diff --git a/app/Http/Controllers/Billing/PaymentMethodController.php b/app/Http/Controllers/Billing/PaymentMethodController.php index cdee3a7f9e..b99705eb76 100644 --- a/app/Http/Controllers/Billing/PaymentMethodController.php +++ b/app/Http/Controllers/Billing/PaymentMethodController.php @@ -4,6 +4,7 @@ use App\Http\Controllers\Controller; use App\Http\Requests\Settings\UserBillingStore; +use App\Models\UserLog; use App\Services\Users\CurrencyService; use Illuminate\Support\Facades\Auth; @@ -51,7 +52,7 @@ public function index() public function currency() { - $content = auth()->user()->subscribed('kanka') || auth()->user()->subscription('kanka')?->ended() ? + $content = auth()->user()->subscribed('kanka') ? '_blocked' : '_form'; return view('settings.subscription.currency.edit') ->with('content', $content) @@ -66,6 +67,20 @@ public function save(UserBillingStore $request) $user = $request->user(); $from = $request->get('from', 'billing.payment-method'); + + if ($request->get('reset_billing') && ($request->get('currency') != $user->currency())) { + $paymentMethods = $user->paymentMethods(); + + foreach ($paymentMethods as $method) { + $method->delete(); + } + $user->subscriptions()->delete(); + + $user->card_expires_at = null; + $user->stripe_id = null; + $user->log(UserLog::TYPE_CURRENCY_SWITCH); + } + $user->saveSettings($request->only('currency')); $user->save(); diff --git a/app/Models/UserLog.php b/app/Models/UserLog.php index d8e622584d..3bba12e830 100644 --- a/app/Models/UserLog.php +++ b/app/Models/UserLog.php @@ -46,6 +46,7 @@ class UserLog extends Model public const TYPE_EMAIL_UPDATE = 40; public const TYPE_SOCIAL_SWITCH = 41; + public const TYPE_CURRENCY_SWITCH = 42; public const TYPE_USER_SWITCH = 50; public const TYPE_USER_REVERT = 51; diff --git a/lang/en/settings.php b/lang/en/settings.php index 06d311b3ea..50a2946218 100644 --- a/lang/en/settings.php +++ b/lang/en/settings.php @@ -186,6 +186,8 @@ 'active_since' => 'Active since', 'active_until' => 'Active until', 'billing' => 'Billing', + 'reset' => 'Reset billing information', + 'reset_billing' => 'I understand that changing currency will lose my billing history and require me to re-enter my payment method.', 'currency' => 'Billing Currency', 'payment_method' => 'Payment method', 'plan' => 'Current plan', @@ -196,7 +198,8 @@ 'alternatives-2' => 'Pay for your subscription using :method. This is a one time payment that doesn\'t automatically renew at at the end of the subscription.', 'alternatives_warning' => 'Upgrading your subscription when using this method is not possible. Please subscribe again when your current one ends.', 'alternatives_yearly' => 'We only accept yearly subscriptions when subscribing with :method', - 'currency_blocked' => 'It is not possible to change currency once you have had an active Kanka subscription. Please contact us at :email for assistance.', + 'currency_block' => 'It is not possible to change currency while you have an active Kanka subscription, you can change your currency once your current subscription ends.', + 'currency_reset' => 'Changing your currency of choice will delete your billing history and will require you to re-enter a payment method.', 'paypal_v3' => 'Safely pay for your yearly subscription using PayPal.', 'stripe' => 'Your billing information is processed and stored safely through :stripe.', ], diff --git a/resources/views/billing/payment-method.blade.php b/resources/views/billing/payment-method.blade.php index 9a186d12ed..b4a1828820 100644 --- a/resources/views/billing/payment-method.blade.php +++ b/resources/views/billing/payment-method.blade.php @@ -32,16 +32,25 @@ > - - @if (auth()->user()->subscribed('kanka') || auth()->user()->subscription('kanka')?->ended()) + @if (auth()->user()->subscribed('kanka')) @include('settings.subscription.currency._blocked') @else + @if (auth()->user()->subscription('kanka')?->ended()) + @include('settings.subscription.currency._reset') + @endif - + @if (auth()->user()->subscription('kanka')?->ended()) + + + + + + + @endif
diff --git a/resources/views/settings/subscription/currency/_blocked.blade.php b/resources/views/settings/subscription/currency/_blocked.blade.php index e380428ef8..9bea6e0800 100644 --- a/resources/views/settings/subscription/currency/_blocked.blade.php +++ b/resources/views/settings/subscription/currency/_blocked.blade.php @@ -1,7 +1,7 @@

- {!! __('settings.subscription.helpers.currency_blocked', ['email' => '' . config('app.email') . ''])!!} + {!! __('settings.subscription.helpers.currency_block', ['email' => '' . config('app.email') . ''])!!}

diff --git a/resources/views/settings/subscription/currency/_form.blade.php b/resources/views/settings/subscription/currency/_form.blade.php index 5f46d3446d..bd5fb86e27 100644 --- a/resources/views/settings/subscription/currency/_form.blade.php +++ b/resources/views/settings/subscription/currency/_form.blade.php @@ -1,5 +1,19 @@ + @if (auth()->user()->subscription('kanka')?->ended()) + @include('settings.subscription.currency._reset') + @endif + + + @if (auth()->user()->subscription('kanka')?->ended()) + + + + + + + @endif + diff --git a/resources/views/settings/subscription/currency/_reset.blade.php b/resources/views/settings/subscription/currency/_reset.blade.php new file mode 100644 index 0000000000..bc451cbcfb --- /dev/null +++ b/resources/views/settings/subscription/currency/_reset.blade.php @@ -0,0 +1,7 @@ + + +

+ {!! __('settings.subscription.helpers.currency_reset') !!} +

+
+