Procházet zdrojové kódy

Merge pull request #26639 from overleaf/kh-support-stripe-us

[web] support regional Stripe accounts

GitOrigin-RevId: d414d310d8db495635d8e0d3b057e3f56b2f044e
Kristina před 1 rokem
rodič
revize
3bdc8316e9

+ 6 - 4
services/web/app/src/Features/Subscription/PaymentProviderEntities.js

@@ -2,6 +2,7 @@
 
 
 /**
 /**
  * @import { PaymentProvider } from '../../../../types/subscription/dashboard/subscription'
  * @import { PaymentProvider } from '../../../../types/subscription/dashboard/subscription'
+ * @import { CurrencyCode, StripeCurrencyCode } from '../../../../types/subscription/currency'
  * @import { AddOn } from '../../../../types/subscription/plan'
  * @import { AddOn } from '../../../../types/subscription/plan'
  */
  */
 
 
@@ -28,7 +29,8 @@ class PaymentProviderSubscription {
    * @param {number} props.subtotal
    * @param {number} props.subtotal
    * @param {number} [props.taxRate]
    * @param {number} [props.taxRate]
    * @param {number} [props.taxAmount]
    * @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 {number} props.total
    * @param {Date} props.periodStart
    * @param {Date} props.periodStart
    * @param {Date} props.periodEnd
    * @param {Date} props.periodEnd
@@ -54,7 +56,7 @@ class PaymentProviderSubscription {
     this.subtotal = props.subtotal
     this.subtotal = props.subtotal
     this.taxRate = props.taxRate ?? 0
     this.taxRate = props.taxRate ?? 0
     this.taxAmount = props.taxAmount ?? 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.total = props.total
     this.periodStart = props.periodStart
     this.periodStart = props.periodStart
     this.periodEnd = props.periodEnd
     this.periodEnd = props.periodEnd
@@ -439,7 +441,7 @@ class PaymentProviderSubscriptionAddOnUpdate {
    */
    */
   constructor(props) {
   constructor(props) {
     this.code = props.code
     this.code = props.code
-    this.quantity = props.quantity ?? null
+    this.quantity = props.quantity
     this.unitPrice = props.unitPrice ?? null
     this.unitPrice = props.unitPrice ?? null
   }
   }
 }
 }
@@ -560,7 +562,7 @@ class PaymentProviderCoupon {
    * @param {object} props
    * @param {object} props
    * @param {string} props.code
    * @param {string} props.code
    * @param {string} props.name
    * @param {string} props.name
-   * @param {string} props.description
+   * @param {string} [props.description]
    */
    */
   constructor(props) {
   constructor(props) {
     this.code = props.code
     this.code = props.code

+ 2 - 1
services/web/app/src/Features/Subscription/RecurlyClient.js

@@ -28,6 +28,7 @@ const RecurlyMetrics = require('./RecurlyMetrics')
  * @import { PaymentProviderSubscriptionChangeRequest } from './PaymentProviderEntities'
  * @import { PaymentProviderSubscriptionChangeRequest } from './PaymentProviderEntities'
  * @import { PaymentProviderSubscriptionUpdateRequest } from './PaymentProviderEntities'
  * @import { PaymentProviderSubscriptionUpdateRequest } from './PaymentProviderEntities'
  * @import { PaymentMethod } from './types'
  * @import { PaymentMethod } from './types'
+ * @import { CurrencyCode } from '../../../../types/subscription/currency'
  */
  */
 
 
 class RecurlyClientWithErrorHandling extends recurly.Client {
 class RecurlyClientWithErrorHandling extends recurly.Client {
@@ -488,7 +489,7 @@ function subscriptionFromApi(apiSubscription) {
     taxRate: apiSubscription.taxInfo?.rate ?? 0,
     taxRate: apiSubscription.taxInfo?.rate ?? 0,
     taxAmount: apiSubscription.tax ?? 0,
     taxAmount: apiSubscription.tax ?? 0,
     total: apiSubscription.total,
     total: apiSubscription.total,
-    currency: apiSubscription.currency,
+    currency: /** @type {CurrencyCode} */ (apiSubscription.currency),
     periodStart: apiSubscription.currentPeriodStartedAt,
     periodStart: apiSubscription.currentPeriodStartedAt,
     periodEnd: apiSubscription.currentPeriodEndsAt,
     periodEnd: apiSubscription.currentPeriodEndsAt,
     collectionMethod: apiSubscription.collectionMethod,
     collectionMethod: apiSubscription.collectionMethod,

+ 1 - 0
services/web/types/stripe/region.ts

@@ -0,0 +1 @@
+export type StripeRegion = 'us' | 'uk'

+ 6 - 1
services/web/types/subscription/dashboard/subscription.ts

@@ -8,7 +8,12 @@ import {
 } from '../plan'
 } from '../plan'
 import { User } from '../../user'
 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
 // when puchasing a new add-on in recurly, we only need to provide the code
 export type PurchasingAddOnCode = {
 export type PurchasingAddOnCode = {