diff --git a/services/web/app/src/Features/Subscription/PaymentProviderEntities.js b/services/web/app/src/Features/Subscription/PaymentProviderEntities.js index 21bd504caf..4efecba0f5 100644 --- a/services/web/app/src/Features/Subscription/PaymentProviderEntities.js +++ b/services/web/app/src/Features/Subscription/PaymentProviderEntities.js @@ -2,6 +2,7 @@ /** * @import { PaymentProvider } from '../../../../types/subscription/dashboard/subscription' + * @import { CurrencyCode, StripeCurrencyCode } from '../../../../types/subscription/currency' * @import { AddOn } from '../../../../types/subscription/plan' */ @@ -28,7 +29,8 @@ class PaymentProviderSubscription { * @param {number} props.subtotal * @param {number} [props.taxRate] * @param {number} [props.taxAmount] - * @param {string} props.currency + * // Recurly uses uppercase currency codes, but Stripe uses lowercase + * @param {CurrencyCode | StripeCurrencyCode} props.currency * @param {number} props.total * @param {Date} props.periodStart * @param {Date} props.periodEnd @@ -54,7 +56,7 @@ class PaymentProviderSubscription { this.subtotal = props.subtotal this.taxRate = props.taxRate ?? 0 this.taxAmount = props.taxAmount ?? 0 - this.currency = props.currency + this.currency = props.currency.toUpperCase() // ensure that currency codes are always uppercase this.total = props.total this.periodStart = props.periodStart this.periodEnd = props.periodEnd @@ -439,7 +441,7 @@ class PaymentProviderSubscriptionAddOnUpdate { */ constructor(props) { this.code = props.code - this.quantity = props.quantity ?? null + this.quantity = props.quantity this.unitPrice = props.unitPrice ?? null } } @@ -560,7 +562,7 @@ class PaymentProviderCoupon { * @param {object} props * @param {string} props.code * @param {string} props.name - * @param {string} props.description + * @param {string} [props.description] */ constructor(props) { this.code = props.code diff --git a/services/web/app/src/Features/Subscription/RecurlyClient.js b/services/web/app/src/Features/Subscription/RecurlyClient.js index 25332a9c34..2031f50392 100644 --- a/services/web/app/src/Features/Subscription/RecurlyClient.js +++ b/services/web/app/src/Features/Subscription/RecurlyClient.js @@ -28,6 +28,7 @@ const RecurlyMetrics = require('./RecurlyMetrics') * @import { PaymentProviderSubscriptionChangeRequest } from './PaymentProviderEntities' * @import { PaymentProviderSubscriptionUpdateRequest } from './PaymentProviderEntities' * @import { PaymentMethod } from './types' + * @import { CurrencyCode } from '../../../../types/subscription/currency' */ class RecurlyClientWithErrorHandling extends recurly.Client { @@ -488,7 +489,7 @@ function subscriptionFromApi(apiSubscription) { taxRate: apiSubscription.taxInfo?.rate ?? 0, taxAmount: apiSubscription.tax ?? 0, total: apiSubscription.total, - currency: apiSubscription.currency, + currency: /** @type {CurrencyCode} */ (apiSubscription.currency), periodStart: apiSubscription.currentPeriodStartedAt, periodEnd: apiSubscription.currentPeriodEndsAt, collectionMethod: apiSubscription.collectionMethod, diff --git a/services/web/types/stripe/region.ts b/services/web/types/stripe/region.ts new file mode 100644 index 0000000000..b450afa761 --- /dev/null +++ b/services/web/types/stripe/region.ts @@ -0,0 +1 @@ +export type StripeRegion = 'us' | 'uk' diff --git a/services/web/types/subscription/dashboard/subscription.ts b/services/web/types/subscription/dashboard/subscription.ts index db17b25684..120ba16461 100644 --- a/services/web/types/subscription/dashboard/subscription.ts +++ b/services/web/types/subscription/dashboard/subscription.ts @@ -8,7 +8,12 @@ import { } from '../plan' import { User } from '../../user' -export type SubscriptionState = 'active' | 'canceled' | 'expired' | 'paused' +export type SubscriptionState = + | 'active' + | 'canceled' + | 'expired' + | 'paused' + | 'past_due' // when puchasing a new add-on in recurly, we only need to provide the code export type PurchasingAddOnCode = {