Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Subscription: Allow changing currency #952

Merged
merged 2 commits into from
Aug 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion app/Http/Controllers/Billing/PaymentMethodController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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)
Expand All @@ -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();

Expand Down
1 change: 1 addition & 0 deletions app/Models/UserLog.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
5 changes: 4 additions & 1 deletion lang/en/settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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.',
],
Expand Down
15 changes: 12 additions & 3 deletions resources/views/billing/payment-method.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,25 @@
></billing-management>
</div>


<x-form :action="['billing.payment-method.save']" method="PATCH" direct>
<x-grid type="1/1">
@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
<x-forms.field field="currency" :label="__('settings.subscription.fields.currency')">
<x-forms.select name="currency" :options="$currencies" :selected="auth()->user()->currency()" />
</x-forms.field>

@if (auth()->user()->subscription('kanka')?->ended())
<x-forms.field field="reset_billing" :required="true" :label=" __('settings.subscription.fields.reset')">
<input type="hidden" name="reset_billing" value="0" />
<x-checkbox :text="__('settings.subscription.fields.reset_billing')">
<input type="checkbox" name="reset_billing" value="1" required/>
</x-checkbox>
</x-forms.field>
@endif
<div class="text-right">
<x-buttons.confirm type="primary" outline="true">
<x-icon class="save" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<x-grid type="1/1">
<x-alert type="warning">
<p>
{!! __('settings.subscription.helpers.currency_blocked', ['email' => '<a href="mailto' . config('app.email') . '">' . config('app.email') . '</a>'])!!}
{!! __('settings.subscription.helpers.currency_block', ['email' => '<a href="mailto' . config('app.email') . '">' . config('app.email') . '</a>'])!!}
</p>
</x-alert>
</x-grid>
14 changes: 14 additions & 0 deletions resources/views/settings/subscription/currency/_form.blade.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
<x-grid type="1/1">
@if (auth()->user()->subscription('kanka')?->ended())
@include('settings.subscription.currency._reset')
@endif

<x-forms.field field="currency" :label="__('settings.subscription.fields.currency')">
<x-forms.select name="currency" :options="$currencies" :selected="auth()->user()->currency()" />
</x-forms.field>

@if (auth()->user()->subscription('kanka')?->ended())
<x-forms.field field="reset_billing" :required="true" :label=" __('settings.subscription.fields.reset')">
<input type="hidden" name="reset_billing" value="0" />
<x-checkbox :text="__('settings.subscription.fields.reset_billing')">
<input type="checkbox" name="reset_billing" value="1" required/>
</x-checkbox>
</x-forms.field>
@endif

</x-grid>
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<x-grid type="1/1">
<x-alert type="warning">
<p>
{!! __('settings.subscription.helpers.currency_reset') !!}
</p>
</x-alert>
</x-grid>