Skip to content

Commit

Permalink
Changes after review
Browse files Browse the repository at this point in the history
Put a rock on it
  • Loading branch information
murilopereirame committed May 28, 2024
1 parent c415126 commit 860aaf6
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 17 deletions.
2 changes: 1 addition & 1 deletion src/subscription/BuyOptionBox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { Icon } from "../gui/base/Icon"
import { SegmentControl } from "../gui/base/SegmentControl"
import type { BookingItemFeatureType } from "../api/common/TutanotaConstants"
import { Keys } from "../api/common/TutanotaConstants"
import { asPaymentInterval, formatMonthlyPrice, formatPrice, getCountFromPriceData, getPriceFromPriceData, PaymentInterval } from "./PriceUtils"
import { asPaymentInterval, formatMonthlyPrice, getCountFromPriceData, getPriceFromPriceData, PaymentInterval } from "./PriceUtils"
import type { BookingFacade } from "../api/worker/facades/lazy/BookingFacade.js"
import Stream from "mithril/stream"
import { Icons } from "../gui/base/icons/Icons"
Expand Down
16 changes: 5 additions & 11 deletions src/subscription/UpgradeConfirmSubscriptionPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,10 @@ export class UpgradeConfirmSubscriptionPage implements WizardPageN<UpgradeSubscr
}

private async upgrade(data: UpgradeSubscriptionData) {
// We return early because we do the upgrade after the user has submitted payment which is on the confirmation page
if (data.paymentData.paymentMethod === PaymentMethodType.AppStore) {
const customerIdBytes = base64ToUint8Array(base64ExtToBase64(data.customer!._id))
let result = await locator.mobilePaymentsFacade.requestSubscriptionToPlan(
PlanTypeToName[data.type].toLowerCase(),
data.options.paymentInterval(),
customerIdBytes,
)
if (result.result !== MobilePaymentResultType.Success) {
const success = await this.handleAppStorePayment(data)
if (!success) {
return
}
}
Expand Down Expand Up @@ -102,16 +98,14 @@ export class UpgradeConfirmSubscriptionPage implements WizardPageN<UpgradeSubscr
}

private async handleAppStorePayment(data: UpgradeSubscriptionData): Promise<boolean> {
let customerId

if (!locator.logins.isUserLoggedIn()) {
await locator.logins.createSession(neverNull(data.newAccountData).mailAddress, neverNull(data.newAccountData).password, SessionType.Temporary)
}
customerId = locator.logins.getUserController().user.customer!

const customerId = locator.logins.getUserController().user.customer!
const customerIdBytes = base64ToUint8Array(base64ExtToBase64(customerId))

let result = await showProgressDialog(
const result = await showProgressDialog(
"pleaseWait_msg",
locator.mobilePaymentsFacade.requestSubscriptionToPlan(PlanTypeToName[data.type].toLowerCase(), data.options.paymentInterval(), customerIdBytes),
)
Expand Down
2 changes: 1 addition & 1 deletion src/subscription/UpgradeSubscriptionPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ export class UpgradeSubscriptionPage implements WizardPageN<UpgradeSubscriptionD
data.type = planType
const { planPrices, options } = data
data.price = planPrices.getSubscriptionPriceWithCurrency(options.paymentInterval(), data.type, UpgradePriceType.PlanActualPrice)
let nextYear = planPrices.getSubscriptionPriceWithCurrency(options.paymentInterval(), data.type, UpgradePriceType.PlanNextYearsPrice)
const nextYear = planPrices.getSubscriptionPriceWithCurrency(options.paymentInterval(), data.type, UpgradePriceType.PlanNextYearsPrice)
data.priceNextYear = data.price !== nextYear ? nextYear : null
this.showNextPage()
}
Expand Down
10 changes: 6 additions & 4 deletions src/subscription/UpgradeSubscriptionWizard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,11 @@ export async function showUpgradeWizard(logins: LoginController, acceptedPlans:

const wizardPages = [
wizardPageWrapper(UpgradeSubscriptionPage, new UpgradeSubscriptionPageAttrs(upgradeData)),
wizardPageWrapper(InvoiceAndPaymentDataPage, new InvoiceAndPaymentDataPageAttrs(upgradeData)),
wizardPageWrapper(UpgradeConfirmSubscriptionPage, new InvoiceAndPaymentDataPageAttrs(upgradeData)),
]
if (!isIOSApp()) {
wizardPages.splice(1, 0, wizardPageWrapper(InvoiceAndPaymentDataPage, new InvoiceAndPaymentDataPageAttrs(upgradeData)))
if (isIOSApp()) {
wizardPages.splice(1, 1) // do not show this page on AppStore payment since we are only able to show this single payment method on iOS
}

const deferred = defer<void>()
Expand Down Expand Up @@ -193,11 +194,12 @@ export async function loadSignupWizard(
const wizardPages = [
wizardPageWrapper(UpgradeSubscriptionPage, new UpgradeSubscriptionPageAttrs(signupData)),
wizardPageWrapper(SignupPage, new SignupPageAttrs(signupData)),
wizardPageWrapper(InvoiceAndPaymentDataPage, invoiceAttrs),
wizardPageWrapper(UpgradeConfirmSubscriptionPage, invoiceAttrs),
wizardPageWrapper(UpgradeCongratulationsPage, new UpgradeCongratulationsPageAttrs(signupData)),
]
if (!isIOSApp()) {
wizardPages.splice(2, 0, wizardPageWrapper(InvoiceAndPaymentDataPage, invoiceAttrs))
if (isIOSApp()) {
wizardPages.splice(2, 1) // do not show this page on AppStore payment since we are only able to show this single payment method on iOS
}
const wizardBuilder = createWizardDialog(signupData, wizardPages, async () => {
if (locator.logins.isUserLoggedIn()) {
Expand Down

0 comments on commit 860aaf6

Please sign in to comment.