mirror of
https://github.com/VueFileManager/vuefilemanager.git
synced 2026-04-05 18:23:48 +00:00
credit bonus after user registration
This commit is contained in:
@@ -191,6 +191,14 @@ return [
|
||||
'name' => 'stripe_payment_description',
|
||||
'value' => 'Available credit card or Apple Pay.',
|
||||
],
|
||||
[
|
||||
'name' => 'allowed_registration_bonus',
|
||||
'value' => '0',
|
||||
],
|
||||
[
|
||||
'name' => 'registration_bonus_amount',
|
||||
'value' => null,
|
||||
],
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
BIN
public/assets/images/default-avatar.png
Normal file
BIN
public/assets/images/default-avatar.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 6.3 KiB |
@@ -25,11 +25,11 @@
|
||||
"/chunks/app-language~chunks/dashboard~chunks/files~chunks/invoices~chunks/my-shared-items~chunks/page~8729b0a3.js": "/chunks/app-language~chunks/dashboard~chunks/files~chunks/invoices~chunks/my-shared-items~chunks/page~8729b0a3.js?id=50f7067283a882b798bd",
|
||||
"/chunks/app-language~chunks/dashboard~chunks/invoices~chunks/page-edit~chunks/pages~chunks/plan-creat~d6def0d7.js": "/chunks/app-language~chunks/dashboard~chunks/invoices~chunks/page-edit~chunks/pages~chunks/plan-creat~d6def0d7.js?id=a1836cdd057c0e63adc0",
|
||||
"/chunks/app-others.js": "/chunks/app-others.js?id=dcb25c15345b97c47871",
|
||||
"/chunks/app-payments.js": "/chunks/app-payments.js?id=d5d5deaee0b1c5c263c1",
|
||||
"/chunks/app-payments.js": "/chunks/app-payments.js?id=7b138db0bc1917cab2c6",
|
||||
"/chunks/app-settings.js": "/chunks/app-settings.js?id=5968eed91e41e99efd4c",
|
||||
"/chunks/app-setup.js": "/chunks/app-setup.js?id=c3a013b11ae7bde6f39d",
|
||||
"/chunks/app-setup~chunks/billings-detail~chunks/create-new-password~chunks/database~chunks/email-veri~2c1222b7.js": "/chunks/app-setup~chunks/billings-detail~chunks/create-new-password~chunks/database~chunks/email-veri~2c1222b7.js?id=5963f5d9fb4e759c600a",
|
||||
"/chunks/billing.js": "/chunks/billing.js?id=d554df9d2da3a9e8b1fd",
|
||||
"/chunks/billing.js": "/chunks/billing.js?id=131b8be8787e1bdbc407",
|
||||
"/chunks/billings-detail.js": "/chunks/billings-detail.js?id=ad632d6f7e088dab55a3",
|
||||
"/chunks/billing~chunks/dashboard~chunks/invoices~chunks/pages~chunks/plan-subscribers~chunks/plans~ch~5d1c5841.js": "/chunks/billing~chunks/dashboard~chunks/invoices~chunks/pages~chunks/plan-subscribers~chunks/plans~ch~5d1c5841.js?id=9b836534302d97ac5c73",
|
||||
"/chunks/billing~chunks/settings-storage~chunks/user-storage~chunks/user-subscription.js": "/chunks/billing~chunks/settings-storage~chunks/user-storage~chunks/user-subscription.js?id=2760050e539cc5e9b8ab",
|
||||
@@ -371,5 +371,30 @@
|
||||
"/chunks/admin-account.277102518603ff264d25.hot-update.js": "/chunks/admin-account.277102518603ff264d25.hot-update.js",
|
||||
"/chunks/app-setup~chunks/billings-detail~chunks/create-new-password~chunks/database~chunks/email-veri~2c1222b7.277102518603ff264d25.hot-update.js": "/chunks/app-setup~chunks/billings-detail~chunks/create-new-password~chunks/database~chunks/email-veri~2c1222b7.277102518603ff264d25.hot-update.js",
|
||||
"/chunks/contact-us.277102518603ff264d25.hot-update.js": "/chunks/contact-us.277102518603ff264d25.hot-update.js",
|
||||
"/chunks/homepage.277102518603ff264d25.hot-update.js": "/chunks/homepage.277102518603ff264d25.hot-update.js"
|
||||
"/chunks/homepage.277102518603ff264d25.hot-update.js": "/chunks/homepage.277102518603ff264d25.hot-update.js",
|
||||
"/chunks/app-payments.a94c611beeaec7ef68c7.hot-update.js": "/chunks/app-payments.a94c611beeaec7ef68c7.hot-update.js",
|
||||
"/chunks/app-payments.225b0eeb85bad6a6d4a2.hot-update.js": "/chunks/app-payments.225b0eeb85bad6a6d4a2.hot-update.js",
|
||||
"/chunks/app-payments.38b258414ca99a2565e7.hot-update.js": "/chunks/app-payments.38b258414ca99a2565e7.hot-update.js",
|
||||
"/chunks/app-payments.c408b5bc6e4749239010.hot-update.js": "/chunks/app-payments.c408b5bc6e4749239010.hot-update.js",
|
||||
"/chunks/app-payments.e6b1c607eed19854b614.hot-update.js": "/chunks/app-payments.e6b1c607eed19854b614.hot-update.js",
|
||||
"/chunks/app-payments.d71c36037d70a7e51a0e.hot-update.js": "/chunks/app-payments.d71c36037d70a7e51a0e.hot-update.js",
|
||||
"/chunks/app-payments.1c200c25699ff399881d.hot-update.js": "/chunks/app-payments.1c200c25699ff399881d.hot-update.js",
|
||||
"/chunks/app-payments.1cc1f6258ed047bdcd82.hot-update.js": "/chunks/app-payments.1cc1f6258ed047bdcd82.hot-update.js",
|
||||
"/chunks/app-payments.7ae1eaf2c5d6ac1f9c23.hot-update.js": "/chunks/app-payments.7ae1eaf2c5d6ac1f9c23.hot-update.js",
|
||||
"/chunks/app-payments.ba38aa9b5dfe9e7c3100.hot-update.js": "/chunks/app-payments.ba38aa9b5dfe9e7c3100.hot-update.js",
|
||||
"/chunks/app-payments.7cc9d88543ceaba319ec.hot-update.js": "/chunks/app-payments.7cc9d88543ceaba319ec.hot-update.js",
|
||||
"/chunks/app-payments.4f9a9ecfd62c760e77aa.hot-update.js": "/chunks/app-payments.4f9a9ecfd62c760e77aa.hot-update.js",
|
||||
"/chunks/app-payments.2deb581bff6f8ce5af7e.hot-update.js": "/chunks/app-payments.2deb581bff6f8ce5af7e.hot-update.js",
|
||||
"/chunks/app-payments.c0b3f5caef03b21f650f.hot-update.js": "/chunks/app-payments.c0b3f5caef03b21f650f.hot-update.js",
|
||||
"/chunks/app-payments.19d93d094e55851543b1.hot-update.js": "/chunks/app-payments.19d93d094e55851543b1.hot-update.js",
|
||||
"/chunks/app-payments.306353deb00268f58f58.hot-update.js": "/chunks/app-payments.306353deb00268f58f58.hot-update.js",
|
||||
"/chunks/app-payments.550d3595bfccdedf605c.hot-update.js": "/chunks/app-payments.550d3595bfccdedf605c.hot-update.js",
|
||||
"/chunks/app-payments.0d266fb8a0185ef14424.hot-update.js": "/chunks/app-payments.0d266fb8a0185ef14424.hot-update.js",
|
||||
"/chunks/app-payments.143cd553f7ee394ff4c1.hot-update.js": "/chunks/app-payments.143cd553f7ee394ff4c1.hot-update.js",
|
||||
"/chunks/billing.c040944b6c4ec4a2de95.hot-update.js": "/chunks/billing.c040944b6c4ec4a2de95.hot-update.js",
|
||||
"/chunks/billing.e50a9de7978b8fbd1868.hot-update.js": "/chunks/billing.e50a9de7978b8fbd1868.hot-update.js",
|
||||
"/chunks/billing.461dc4a34199e68429ee.hot-update.js": "/chunks/billing.461dc4a34199e68429ee.hot-update.js",
|
||||
"/chunks/billing.eaf0631ae5f10538907d.hot-update.js": "/chunks/billing.eaf0631ae5f10538907d.hot-update.js",
|
||||
"/chunks/billing.2aeee7e82b62920e2451.hot-update.js": "/chunks/billing.2aeee7e82b62920e2451.hot-update.js",
|
||||
"/chunks/billing.3153d134251a9670bbe8.hot-update.js": "/chunks/billing.3153d134251a9670bbe8.hot-update.js"
|
||||
}
|
||||
|
||||
@@ -34,6 +34,10 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<small class="mt-6 block font-bold">
|
||||
{{ $t('Records are updated on daily bases.') }}
|
||||
</small>
|
||||
</div>
|
||||
</template>
|
||||
<script>
|
||||
|
||||
@@ -15,6 +15,21 @@
|
||||
</AppInputText>
|
||||
</div>
|
||||
|
||||
<!--Metered settings-->
|
||||
<div v-if="config.subscriptionType === 'metered'" class="card shadow-card">
|
||||
<FormLabel icon="bar-chart">
|
||||
{{ $t('Metered Billing Settings') }}
|
||||
</FormLabel>
|
||||
|
||||
<AppInputSwitch :title="$t('Allow Registration Bonus')" :description="$t('User credit automatically user bonus to the balance after user registration.')" :is-last="! allowedRegistrationBonus" class="flex">
|
||||
<SwitchInput @input="$updateText('/admin/settings', 'allowed_registration_bonus', allowedRegistrationBonus)" v-model="allowedRegistrationBonus" :state="allowedRegistrationBonus" />
|
||||
</AppInputSwitch>
|
||||
|
||||
<AppInputText v-if="allowedRegistrationBonus" :title="$t('Registration Bonus Amount')" :description="this.$t('This bonus will be automatically added when user successfully register his account.')" :is-last="true">
|
||||
<input @input="$updateText('/admin/settings', 'registration_bonus_amount', registrationBonusAmount)" v-model="registrationBonusAmount" :placeholder="$t('Type registration bonus amount...')" type="number" class="focus-border-theme input-dark" />
|
||||
</AppInputText>
|
||||
</div>
|
||||
|
||||
<!--Stripe method configuration-->
|
||||
<div v-if="allowedPayments" class="card shadow-card">
|
||||
<img :src="$getPaymentLogo('stripe')" alt="Stripe" class="mb-4 h-8">
|
||||
@@ -235,7 +250,11 @@
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
allowedRegistrationBonus: true,
|
||||
registrationBonusAmount: undefined,
|
||||
|
||||
allowedPayments: false,
|
||||
|
||||
isLoading: false,
|
||||
isError: false,
|
||||
errorMessage: '',
|
||||
@@ -369,6 +388,10 @@
|
||||
this.paypal.isConfigured = true
|
||||
|
||||
this.allowedPayments = this.config.allowed_payments
|
||||
|
||||
// Set metered
|
||||
this.allowedRegistrationBonus = this.config.allowed_registration_bonus
|
||||
this.registrationBonusAmount = this.config.registration_bonus_amount
|
||||
},
|
||||
created() {
|
||||
events.$on('action:confirmed', data => {
|
||||
|
||||
@@ -75,6 +75,10 @@
|
||||
installation: '{{ $installation ?? 'initial' }}',
|
||||
statusCheck: {!! json_encode($status_check) ?? 'undefined' !!},
|
||||
|
||||
// Metered
|
||||
allowed_registration_bonus: {{ $settings->allowed_registration_bonus ?? 0 }},
|
||||
registration_bonus_amount: {{ $settings->registration_bonus_amount ?? 0 }},
|
||||
|
||||
// Payments
|
||||
allowed_payments: {{ $settings->allowed_payments ?? 0 }},
|
||||
subscriptionType: '{{ $settings->subscription_type ?? 'none' }}',
|
||||
|
||||
@@ -14,13 +14,41 @@ class AutoSubscribeForMeteredBillingAction
|
||||
->where('type', 'metered')
|
||||
->first();
|
||||
|
||||
// TODO: add bonus
|
||||
// Get settings
|
||||
$settings = get_settings([
|
||||
'allowed_registration_bonus',
|
||||
'registration_bonus_amount',
|
||||
]);
|
||||
|
||||
// Create user balance
|
||||
$user->balance()->create([
|
||||
'amount' => 0,
|
||||
'currency' => $plan->currency,
|
||||
]);
|
||||
if (intval($settings['allowed_registration_bonus'])) {
|
||||
|
||||
// Create balance with bonus amount
|
||||
$user->balance()->create([
|
||||
'amount' => $settings['registration_bonus_amount'],
|
||||
'currency' => $plan->currency,
|
||||
]);
|
||||
|
||||
// Store transaction bonus
|
||||
$user->transactions()->create([
|
||||
'status' => 'completed',
|
||||
'type' => 'credit',
|
||||
'driver' => 'system',
|
||||
'note' => __('Bonus'),
|
||||
'currency' => $plan->currency,
|
||||
'amount' => $settings['registration_bonus_amount'],
|
||||
]);
|
||||
} else {
|
||||
|
||||
// Create balance with 0 amount
|
||||
$user->balance()->create([
|
||||
'currency' => $plan->currency,
|
||||
]);
|
||||
}
|
||||
|
||||
// Store transaction
|
||||
if (intval($settings['allowed_registration_bonus'])) {
|
||||
}
|
||||
|
||||
// Create user subscription
|
||||
$user->subscription()->create([
|
||||
|
||||
@@ -13,9 +13,7 @@ class CreateNewUserAction extends Controller
|
||||
public function __construct(
|
||||
protected StatefulGuard $guard,
|
||||
protected AutoSubscribeForMeteredBillingAction $autoSubscribeForMeteredBilling,
|
||||
)
|
||||
{
|
||||
}
|
||||
) {}
|
||||
|
||||
/**
|
||||
* Validate and create a new user.
|
||||
|
||||
@@ -53,7 +53,12 @@ class UserSetting extends Model
|
||||
return $link;
|
||||
}
|
||||
|
||||
return null;
|
||||
// Return default avatar
|
||||
foreach (config('vuefilemanager.avatar_sizes') as $item) {
|
||||
$link[$item['name']] = url("/assets/images/default-avatar.png");
|
||||
}
|
||||
|
||||
return $link;
|
||||
}
|
||||
|
||||
public function user(): HasOne
|
||||
|
||||
@@ -66,11 +66,26 @@ class SignFlowTest extends TestCase
|
||||
public function it_register_user_when_metered_billing_is_active()
|
||||
{
|
||||
// Seed default settings
|
||||
Setting::updateOrCreate([
|
||||
'name' => 'subscription_type',
|
||||
], [
|
||||
'value' => 'metered',
|
||||
]);
|
||||
collect([
|
||||
[
|
||||
'name' => 'subscription_type',
|
||||
'value' => 'metered',
|
||||
],
|
||||
[
|
||||
'name' => 'allowed_registration_bonus',
|
||||
'value' => 0,
|
||||
],
|
||||
[
|
||||
'name' => 'registration_bonus_amount',
|
||||
'value' => 15,
|
||||
],
|
||||
])->each(function ($setting) {
|
||||
Setting::updateOrCreate([
|
||||
'name' => $setting['name'],
|
||||
], [
|
||||
'value' => $setting['value'],
|
||||
]);
|
||||
});
|
||||
|
||||
// Create metered plan
|
||||
$plan = Plan::factory()
|
||||
@@ -88,6 +103,7 @@ class SignFlowTest extends TestCase
|
||||
])->assertStatus(201);
|
||||
|
||||
$this
|
||||
->assertDatabaseCount('transactions', 0)
|
||||
->assertDatabaseHas('users', [
|
||||
'email' => 'john@doe.com',
|
||||
])
|
||||
@@ -106,6 +122,77 @@ class SignFlowTest extends TestCase
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function it_register_user_when_metered_billing_is_active_with_registration_bonus()
|
||||
{
|
||||
// Seed default settings
|
||||
collect([
|
||||
[
|
||||
'name' => 'subscription_type',
|
||||
'value' => 'metered',
|
||||
],
|
||||
[
|
||||
'name' => 'allowed_registration_bonus',
|
||||
'value' => 1,
|
||||
],
|
||||
[
|
||||
'name' => 'registration_bonus_amount',
|
||||
'value' => 15,
|
||||
],
|
||||
])->each(function ($setting) {
|
||||
Setting::updateOrCreate([
|
||||
'name' => $setting['name'],
|
||||
], [
|
||||
'value' => $setting['value'],
|
||||
]);
|
||||
});
|
||||
|
||||
// Create metered plan
|
||||
$plan = Plan::factory()
|
||||
->create([
|
||||
'status' => 'active',
|
||||
'type' => 'metered',
|
||||
'currency' => 'USD',
|
||||
]);
|
||||
|
||||
$this->postJson('api/register', [
|
||||
'email' => 'john@doe.com',
|
||||
'password' => 'SecretPassword',
|
||||
'password_confirmation' => 'SecretPassword',
|
||||
'name' => 'John Doe',
|
||||
])->assertStatus(201);
|
||||
|
||||
$user = User::first();
|
||||
|
||||
$this
|
||||
->assertDatabaseHas('users', [
|
||||
'email' => 'john@doe.com',
|
||||
])
|
||||
->assertDatabaseHas('subscriptions', [
|
||||
'status' => 'active',
|
||||
'name' => $plan->name,
|
||||
'ends_at' => null,
|
||||
'renews_at' => now()->addDays(config('subscription.metered_billing.settlement_period')),
|
||||
])
|
||||
->assertDatabaseHas('balances', [
|
||||
'currency' => 'USD',
|
||||
'amount' => 15,
|
||||
])
|
||||
->assertDatabaseHas('transactions', [
|
||||
'user_id' => $user->id,
|
||||
'amount' => 15.00,
|
||||
'currency' => 'USD',
|
||||
'status' => 'completed',
|
||||
'type' => 'credit',
|
||||
'driver' => 'system',
|
||||
])
|
||||
->assertDatabaseHas('user_settings', [
|
||||
'name' => 'John Doe',
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user