Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix the next year price being shown if it is the same price as the first year in the sign up wizard #7936

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/common/subscription/InvoiceAndPaymentDataPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ export class InvoiceAndPaymentDataPage implements WizardPageN<UpgradeSubscriptio
a.data.paymentData,
null,
a.data.upgradeType === UpgradeType.Signup,
a.data.price,
neverNull(a.data.price?.rawPrice),
neverNull(a.data.accountingInfo),
).then((success) => {
if (success) {
Expand Down
6 changes: 5 additions & 1 deletion src/common/subscription/PriceUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,11 @@ export class PriceAndConfigProvider {
: this.getMonthlySubscriptionPrice(subscription, type)
}

// Returns the subscription price with the currency formatting on iOS and as a plain period seperated number on other platforms
/**
* Returns the subscription price with the currency formatting on iOS and as a plain period seperated number on other platforms
*
* The `rawPrice` is taken from Tuta servers regardless of whether the client is on iOS
*/
getSubscriptionPriceWithCurrency(paymentInterval: PaymentInterval, subscription: PlanType, type: UpgradePriceType): SubscriptionPrice {
const price = this.getSubscriptionPrice(paymentInterval, subscription, type)
const rawPrice = price.toString()
Expand Down
6 changes: 3 additions & 3 deletions src/common/subscription/UpgradeConfirmSubscriptionPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ export class UpgradeConfirmSubscriptionPage implements WizardPageN<UpgradeSubscr
}),
m(TextField, {
label: isYearly ? "priceFirstYear_label" : "price_label",
value: buildPriceString(attrs.data.displayPrice, attrs.data.options),
value: buildPriceString(attrs.data.price?.displayPrice ?? "0", attrs.data.options),
isReadOnly: true,
}),
this.renderPriceNextYear(attrs),
Expand Down Expand Up @@ -189,10 +189,10 @@ export class UpgradeConfirmSubscriptionPage implements WizardPageN<UpgradeSubscr
}

private renderPriceNextYear(attrs: WizardPageAttrs<UpgradeSubscriptionData>) {
return attrs.data.priceNextYear
return attrs.data.nextYearPrice
? m(TextField, {
label: "priceForNextYear_label",
value: buildPriceString(attrs.data.priceNextYear, attrs.data.options),
value: buildPriceString(attrs.data.nextYearPrice.displayPrice, attrs.data.options),
isReadOnly: true,
})
: null
Expand Down
14 changes: 6 additions & 8 deletions src/common/subscription/UpgradeSubscriptionPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,8 @@ export class UpgradeSubscriptionPage implements WizardPageN<UpgradeSubscriptionD
// Confirmation of free/business dialog (click on ok)
this.__signupFreeTest?.getStage(1).complete()
data.type = PlanType.Free
data.price = "0"
data.priceNextYear = "0"
data.price = null
data.nextYearPrice = null
this.showNextPage()
}
})
Expand Down Expand Up @@ -207,12 +207,10 @@ export class UpgradeSubscriptionPage implements WizardPageN<UpgradeSubscriptionD
data.type = planType
const { planPrices, options } = data
try {
// `data.price` is used for the amount parameter in the Braintree credit card verification call, so we do not include currency locale outside iOS.
const subscriptionPrice = planPrices.getSubscriptionPriceWithCurrency(options.paymentInterval(), data.type, UpgradePriceType.PlanActualPrice)
data.price = subscriptionPrice.rawPrice
data.displayPrice = subscriptionPrice.displayPrice
const nextYear = planPrices.getSubscriptionPriceWithCurrency(options.paymentInterval(), data.type, UpgradePriceType.PlanNextYearsPrice).displayPrice
data.priceNextYear = data.price !== nextYear ? nextYear : null
// `data.price.rawPrice` is used for the amount parameter in the Braintree credit card verification call, so we do not include currency locale outside iOS.
data.price = planPrices.getSubscriptionPriceWithCurrency(options.paymentInterval(), data.type, UpgradePriceType.PlanActualPrice)
const nextYear = planPrices.getSubscriptionPriceWithCurrency(options.paymentInterval(), data.type, UpgradePriceType.PlanNextYearsPrice)
data.nextYearPrice = data.price.rawPrice !== nextYear.rawPrice ? nextYear : null
} catch (e) {
console.error(e)
Dialog.message("appStoreNotAvailable_msg")
Expand Down
21 changes: 7 additions & 14 deletions src/common/subscription/UpgradeSubscriptionWizard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import { StorageBehavior } from "../misc/UsageTestModel"
import { FeatureListProvider, SelectedSubscriptionOptions } from "./FeatureListProvider"
import { queryAppStoreSubscriptionOwnership, UpgradeType } from "./SubscriptionUtils"
import { UpgradeConfirmSubscriptionPage } from "./UpgradeConfirmSubscriptionPage.js"
import { asPaymentInterval, PaymentInterval, PriceAndConfigProvider } from "./PriceUtils"
import { asPaymentInterval, PaymentInterval, PriceAndConfigProvider, SubscriptionPrice } from "./PriceUtils"
import { formatNameAndAddress } from "../api/common/utils/CommonFormatter.js"
import { LoginController } from "../api/main/LoginController.js"
import { MobilePaymentSubscriptionOwnership } from "../native/common/generatedipc/MobilePaymentSubscriptionOwnership.js"
Expand All @@ -49,13 +49,8 @@ export type UpgradeSubscriptionData = {
invoiceData: InvoiceData
paymentData: PaymentData
type: PlanType
// Subscription price as a float
price: string
// Subscription price as a formatted string with the currency symbol and with decimal separator from local
// On iOS: in the local currency
// Else: in Euro
displayPrice: string
priceNextYear: string | null
price: SubscriptionPrice | null
nextYearPrice: SubscriptionPrice | null
accountingInfo: AccountingInfo | null
// not initially set for signup but loaded in InvoiceAndPaymentDataPage
customer: Customer | null
Expand Down Expand Up @@ -101,10 +96,9 @@ export async function showUpgradeWizard(logins: LoginController, acceptedPlans:
paymentMethod: getPaymentMethodType(accountingInfo) || (await getDefaultPaymentMethod(locator.appStorePaymentPicker)),
creditCardData: null,
},
price: "",
displayPrice: "",
price: null,
type: PlanType.Revolutionary,
priceNextYear: null,
nextYearPrice: null,
accountingInfo: accountingInfo,
customer: customer,
newAccountData: null,
Expand Down Expand Up @@ -190,9 +184,8 @@ export async function loadSignupWizard(
paymentMethod: await getDefaultPaymentMethod(locator.appStorePaymentPicker),
creditCardData: null,
},
price: "",
displayPrice: "",
priceNextYear: null,
price: null,
nextYearPrice: null,
type: PlanType.Free,
accountingInfo: null,
customer: null,
Expand Down