chore: remove calling payments server for subscriptions if using third party api hosts (#2398)

This commit is contained in:
Karol Sójko
2023-08-09 13:16:19 +02:00
committed by GitHub
parent e05d8c9e76
commit 90dcb33a44
24 changed files with 233 additions and 89 deletions

View File

@@ -52,4 +52,6 @@ export const Web_TYPES = {
LoadPurchaseFlowUrl: Symbol.for('LoadPurchaseFlowUrl'),
OpenSubscriptionDashboard: Symbol.for('OpenSubscriptionDashboard'),
PanesForLayout: Symbol.for('PanesForLayout'),
GetHost: Symbol.for('GetHost'),
IsApplicationUsingThirdPartyHost: Symbol.for('IsApplicationUsingThirdPartyHost'),
}

View File

@@ -17,7 +17,7 @@ import {
} from '@standardnotes/ui-services'
import { DependencyContainer } from '@standardnotes/utils'
import { Web_TYPES } from './Types'
import { BackupServiceInterface, isDesktopDevice } from '@standardnotes/snjs'
import { BackupServiceInterface, GetHost, IsApplicationUsingThirdPartyHost, isDesktopDevice } from '@standardnotes/snjs'
import { DesktopManager } from '../Device/DesktopManager'
import { MomentsService } from '@/Controllers/Moments/MomentsService'
import { PersistenceService } from '@/Controllers/Abstract/PersistenceService'
@@ -195,6 +195,14 @@ export class WebDependencies extends DependencyContainer {
return new PanesForLayout(this.get<IsTabletOrMobileScreen>(Web_TYPES.IsTabletOrMobileScreen))
})
this.bind(Web_TYPES.GetHost, () => {
return new GetHost(application.legacyApi)
})
this.bind(Web_TYPES.IsApplicationUsingThirdPartyHost, () => {
return new IsApplicationUsingThirdPartyHost(this.get<GetHost>(Web_TYPES.GetHost))
})
this.bind(Web_TYPES.IsTabletOrMobileScreen, () => {
return new IsTabletOrMobileScreen(application.environment)
})
@@ -320,7 +328,11 @@ export class WebDependencies extends DependencyContainer {
})
this.bind(Web_TYPES.GetPurchaseFlowUrl, () => {
return new GetPurchaseFlowUrl(application, application.legacyApi)
return new GetPurchaseFlowUrl(
application,
application.legacyApi,
this.get<IsApplicationUsingThirdPartyHost>(Web_TYPES.IsApplicationUsingThirdPartyHost),
)
})
this.bind(Web_TYPES.SyncStatusController, () => {

View File

@@ -1,17 +1,30 @@
import { isDesktopApplication } from '@/Utils'
import { ApplicationInterface, LegacyApiServiceInterface, Result, UseCaseInterface } from '@standardnotes/snjs'
import {
ApplicationInterface,
IsApplicationUsingThirdPartyHost,
LegacyApiServiceInterface,
Result,
UseCaseInterface,
} from '@standardnotes/snjs'
export class GetPurchaseFlowUrl implements UseCaseInterface<string> {
constructor(
private application: ApplicationInterface,
private legacyApi: LegacyApiServiceInterface,
private isApplicationUsingThirdPartyHostUseCase: IsApplicationUsingThirdPartyHost,
) {}
async execute(): Promise<Result<string>> {
const currentUrl = window.location.origin
const successUrl = isDesktopApplication() ? 'standardnotes://' : currentUrl
if (this.application.sessions.isSignedOut() || this.application.isThirdPartyHostUsed()) {
const isThirdPartyHostUsedOrError = this.isApplicationUsingThirdPartyHostUseCase.execute()
if (isThirdPartyHostUsedOrError.isFailed()) {
return Result.fail(isThirdPartyHostUsedOrError.getError()!)
}
const isThirdPartyHostUsed = isThirdPartyHostUsedOrError.getValue()
if (this.application.sessions.isSignedOut() || isThirdPartyHostUsed) {
return Result.ok(`${window.purchaseUrl}/offline?&success_url=${successUrl}`)
}