diff --git a/addon/components/extension-monetize-form.hbs b/addon/components/extension-monetize-form.hbs index 91368b0..5f0d921 100644 --- a/addon/components/extension-monetize-form.hbs +++ b/addon/components/extension-monetize-form.hbs @@ -1,14 +1,20 @@ - - - - {{#if @extension.payment_required}} - {{!-- + {{#if this.lookupStripeConnectAccount.isRunning}} +
+ +
+ {{else}} + {{#if this.hasStripeConnectAccount}} + + + + {{#if @extension.payment_required}} + {{!-- --}} - {{#if @extension.subscription_required}} - - + + + + + {{else}} +
+ + + + + + +
+ {{/if}} + {{/if}} {{else}} -
- - - - - - +
+
+
+
+

Your account is not setup to accept payments yet.

+

To accept payments for extensions, you must complete the onboard process via Stripe.

+
+
+
{{/if}} {{/if}} diff --git a/addon/components/extension-monetize-form.js b/addon/components/extension-monetize-form.js index a6db37c..893fe18 100644 --- a/addon/components/extension-monetize-form.js +++ b/addon/components/extension-monetize-form.js @@ -1,7 +1,25 @@ import Component from '@glimmer/component'; import { tracked } from '@glimmer/tracking'; +import { inject as service } from '@ember/service'; +import { task } from 'ember-concurrency'; export default class ExtensionMonetizeFormComponent extends Component { + @service fetch; @tracked subscriptionModelOptions = ['flat_rate', 'tiered', 'usage']; @tracked billingPeriodOptions = ['daily', 'weekly', 'monthly', 'quarterly', 'yearly']; + @tracked hasStripeConnectAccount = false; + + constructor() { + super(...arguments); + this.lookupStripeConnectAccount.perform(); + } + + @task *lookupStripeConnectAccount() { + try { + const { hasStripeConnectAccount } = yield this.fetch.get('payments/has-stripe-connect-account', {}, { namespace: '~registry/v1' }); + this.hasStripeConnectAccount = hasStripeConnectAccount; + } catch (error) { + this.hasStripeConnectAccount = false; + } + } } diff --git a/addon/controllers/developers/extensions/edit/monetize.js b/addon/controllers/developers/extensions/edit/monetize.js index b40a769..3b7777f 100644 --- a/addon/controllers/developers/extensions/edit/monetize.js +++ b/addon/controllers/developers/extensions/edit/monetize.js @@ -1,7 +1,3 @@ import Controller from '@ember/controller'; -import { tracked } from '@glimmer/tracking'; -export default class DevelopersExtensionsEditMonetizeController extends Controller { - @tracked subscriptionModelOptions = ['flat_rate', 'tiered', 'usage']; - @tracked billingPeriodOptions = ['daily', 'weekly', 'monthly', 'quarterly', 'yearly']; -} +export default class DevelopersExtensionsEditMonetizeController extends Controller {} diff --git a/addon/controllers/developers/payments/index.js b/addon/controllers/developers/payments/index.js index d2289e1..1a631bc 100644 --- a/addon/controllers/developers/payments/index.js +++ b/addon/controllers/developers/payments/index.js @@ -1,7 +1,10 @@ import Controller from '@ember/controller'; import { tracked } from '@glimmer/tracking'; +import { inject as service } from '@ember/service'; +import { task } from 'ember-concurrency'; export default class DevelopersPaymentsIndexController extends Controller { + @service fetch; @tracked hasStripeConnectAccount = true; @tracked table; @tracked page = 1; @@ -37,4 +40,13 @@ export default class DevelopersPaymentsIndexController extends Controller { width: '20%', }, ]; + + @task *lookupStripeConnectAccount() { + try { + const { hasStripeConnectAccount } = yield this.fetch.get('payments/has-stripe-connect-account', {}, { namespace: '~registry/v1' }); + this.hasStripeConnectAccount = hasStripeConnectAccount; + } catch (error) { + this.hasStripeConnectAccount = false; + } + } } diff --git a/addon/routes/developers/payments/index.js b/addon/routes/developers/payments/index.js index bf0a00a..544e517 100644 --- a/addon/routes/developers/payments/index.js +++ b/addon/routes/developers/payments/index.js @@ -15,12 +15,7 @@ export default class DevelopersPaymentsIndexRoute extends Route { return this.fetch.get('payments/author-received', {}, { namespace: '~registry/v1' }); } - async setupController(controller) { - try { - const { hasStripeConnectAccount } = await this.fetch.get('payments/has-stripe-connect-account', {}, { namespace: '~registry/v1' }); - controller.hasStripeConnectAccount = hasStripeConnectAccount; - } catch (error) { - controller.hasStripeConnectAccount = false; - } + setupController(controller) { + controller.lookupStripeConnectAccount.perform(); } } diff --git a/addon/templates/developers/payments/index.hbs b/addon/templates/developers/payments/index.hbs index 09a9bb9..054e8b7 100644 --- a/addon/templates/developers/payments/index.hbs +++ b/addon/templates/developers/payments/index.hbs @@ -1,34 +1,42 @@ -
- Total Amount: - {{format-currency @model.total_amount "USD"}} -
+ {{#if this.hasStripeConnectAccount}} +
+ Total Amount: + {{format-currency @model.total_amount "USD"}} +
+ {{/if}}
- {{#if this.hasStripeConnectAccount}} - + {{#if this.lookupStripeConnectAccount.isRunning}} +
+ +
{{else}} -
-
-
-
-

Your account is not setup to accept payments yet.

-

To accept payments for extensions, you must complete the onboard process via Stripe.

-
+ {{else}} +
+
+
+
+

Your account is not setup to accept payments yet.

+

To accept payments for extensions, you must complete the onboard process via Stripe.

+
- + {{/if}} {{/if}} \ No newline at end of file diff --git a/composer.json b/composer.json index 65b326c..8fdc025 100644 --- a/composer.json +++ b/composer.json @@ -1,6 +1,6 @@ { "name": "fleetbase/registry-bridge", - "version": "0.0.10", + "version": "0.0.11", "description": "Internal Bridge between Fleetbase API and Extensions Registry", "keywords": [ "fleetbase-extension", diff --git a/extension.json b/extension.json index 119dae1..b7f7a57 100644 --- a/extension.json +++ b/extension.json @@ -1,6 +1,6 @@ { "name": "Registry Bridge", - "version": "0.0.10", + "version": "0.0.11", "description": "Internal Bridge between Fleetbase API and Extensions Registry", "repository": "https://github.com/fleetbase/registry-bridge", "license": "AGPL-3.0-or-later", diff --git a/package.json b/package.json index 2cd3111..d464f52 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@fleetbase/registry-bridge-engine", - "version": "0.0.10", + "version": "0.0.11", "description": "Internal Bridge between Fleetbase API and Extensions Registry", "fleetbase": { "route": "extensions" diff --git a/server/src/Http/Controllers/Internal/v1/RegistryAuthController.php b/server/src/Http/Controllers/Internal/v1/RegistryAuthController.php index fbc7193..922bb8b 100644 --- a/server/src/Http/Controllers/Internal/v1/RegistryAuthController.php +++ b/server/src/Http/Controllers/Internal/v1/RegistryAuthController.php @@ -40,21 +40,27 @@ public function composerAuthentication(Request $request) return response()->error('Invalid registry token provided for authentication.', 401); } - // Fetch unauthorized extensions - $unauthorizedExtensions = RegistryExtension::where('payment_required', true) - ->whereDoesntHave('purchases', function ($query) use ($registryUser) { - $query->where('company_uuid', $registryUser->company_uuid); - }) - ->whereHas('currentBundle') - ->with('currentBundle') - ->get(); - - // Map to unathorized to package names - $unauthorizedExtensionNames = $unauthorizedExtensions->map(function ($registryExtension) { - $composerJson = $registryExtension->currentBundle->meta['composer.json'] ?? []; - - return $composerJson['name'] ?? null; - })->filter()->values(); + // Init unauthorized extensions + $unauthorizedExtensionNames = collect(); + + // Unless admin the registry user is only allowed access to their extensions + if ($registryUser->isNotAdmin()) { + // Fetch unauthorized extensions + $unauthorizedExtensions = RegistryExtension::where('payment_required', true) + ->whereDoesntHave('purchases', function ($query) use ($registryUser) { + $query->where('company_uuid', $registryUser->company_uuid); + }) + ->whereHas('currentBundle') + ->with('currentBundle') + ->get(); + + // Map to unathorized to package names + $unauthorizedExtensionNames = $unauthorizedExtensions->map(function ($registryExtension) { + $composerJson = $registryExtension->currentBundle->meta['composer.json'] ?? []; + + return $composerJson['name'] ?? null; + })->filter()->values(); + } // Done return response()->json([