Skip to content

Commit

Permalink
Adds App Store payment support on Calendar App
Browse files Browse the repository at this point in the history
Co-authored-by: André Dias <[email protected]>
  • Loading branch information
mup and andrehgdias committed Nov 28, 2024
1 parent dbcd5b5 commit 87ce57b
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 19 deletions.
5 changes: 1 addition & 4 deletions src/common/subscription/PriceUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import { UserError } from "../api/main/UserError.js"
import { isIOSApp } from "../api/common/Env"
import { MobilePlanPrice } from "../native/common/generatedipc/MobilePlanPrice"
import { locator } from "../api/main/CommonLocator.js"
import { client } from "../misc/ClientDetector"
import { isReferenceDateWithinCyberMondayCampaign } from "../misc/CyberMondayUtils.js"

export const enum PaymentInterval {
Expand Down Expand Up @@ -179,9 +178,7 @@ export class PriceAndConfigProvider {
const price = this.getSubscriptionPrice(paymentInterval, subscription, type)
const rawPrice = price.toString()

const supportsAppStorePayments = isIOSApp()

if (supportsAppStorePayments) {
if (isIOSApp()) {
return this.getAppStorePaymentsSubscriptionPrice(subscription, paymentInterval, rawPrice, type)
} else {
const displayPrice = formatPrice(price, true)
Expand Down
43 changes: 28 additions & 15 deletions src/common/subscription/SubscriptionViewer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ import { showManageThroughAppStoreDialog } from "./PaymentViewer.js"
import type { UpdatableSettingsViewer } from "../settings/Interfaces.js"
import { client } from "../misc/ClientDetector.js"
import { AppStoreSubscriptionService } from "../api/entities/sys/Services.js"
import { AppType } from "../misc/ClientConstants.js"

assertMainOrNode()
const DAY = 1000 * 60 * 60 * 24
Expand Down Expand Up @@ -414,26 +415,38 @@ export class SubscriptionViewer implements UpdatableSettingsViewer {
const isMailSubscription = appStoreSubscriptionData.app === SubscriptionApp.Mail

if (client.isCalendarApp() && isMailSubscription) {
const dialogResult = await Dialog.confirm(() => lang.get("handleSubscriptionOnApp_msg", { "{1}": "Tuta Mail" }), "yes_label")
if (!dialogResult) {
return false
}

const query = `settings=subscription`
locator.systemFacade.openMailApp(stringToBase64(query))
return false
return await this.handleAppOpen(SubscriptionApp.Mail)
} else if (!client.isCalendarApp() && !isMailSubscription) {
const dialogResult = await Dialog.confirm(() => lang.get("handleSubscriptionOnApp_msg", { "{1}": "Tuta Calendar" }), "yes_label")
if (!dialogResult) {
return false
}
return await this.handleAppOpen(SubscriptionApp.Calendar)
}

return true
}

private async handleAppOpen(app: SubscriptionApp) {
const appName = app === SubscriptionApp.Calendar ? "Tuta Calendar" : "Tuta Mail"
const dialogResult = await Dialog.confirm(() => lang.get("handleSubscriptionOnApp_msg", { "{1}": appName }), "yes_label")
const query = stringToBase64(`settings=subscription`)

const query = `settings=subscription`
locator.systemFacade.openCalendarApp(stringToBase64(query))
if (!dialogResult) {
return false
}

return true
if (app === SubscriptionApp.Calendar) {
locator.systemFacade.openCalendarApp(query)
} else {
locator.systemFacade.openMailApp(query)
}

return false
}

private openAppDialogCallback(open: boolean, app: AppType.Mail | AppType.Calendar) {
if (!open) {
return
}

const appName = app === AppType.Mail ? "Tuta Mail" : "Tuta Calendar"
}

private showOrderAgreement(): boolean {
Expand Down

0 comments on commit 87ce57b

Please sign in to comment.