Skip to content

A free and open source instant messaging and VoIP chat app built for friends, groups, and communities.

TypeScript fluxerfluxerapp

feat(schema): add dispute reviews, purchase block, Play refunds

Hampus661f7639fc52
diff --git a/packages/errors/src/domains/payment/PaymentDisputeExemptError.ts b/packages/errors/src/domains/payment/PaymentDisputeExemptError.ts
new file mode 100644
index 000000000..ad32a3c59
--- /dev/null
+++ b/packages/errors/src/domains/payment/PaymentDisputeExemptError.ts
@@ -0,0 +1,10 @@
+// SPDX-License-Identifier: AGPL-3.0-or-later
+
+import {APIErrorCodes} from '@fluxer/constants/src/ApiErrorCodes';
+import {ConflictError} from '@fluxer/errors/src/domains/core/ConflictError';
+
+export class PaymentDisputeExemptError extends ConflictError {
+ constructor(reasons: ReadonlyArray<string>) {
+ super({code: APIErrorCodes.PAYMENT_DISPUTE_EXEMPT, data: {reasons: [...reasons]}});
+ }
+}
diff --git a/packages/errors/src/domains/payment/PaymentDisputeReviewClosedError.ts b/packages/errors/src/domains/payment/PaymentDisputeReviewClosedError.ts
new file mode 100644
index 000000000..40b0030dd
--- /dev/null
+++ b/packages/errors/src/domains/payment/PaymentDisputeReviewClosedError.ts
@@ -0,0 +1,10 @@
+// SPDX-License-Identifier: AGPL-3.0-or-later
+
+import {APIErrorCodes} from '@fluxer/constants/src/ApiErrorCodes';
+import {ConflictError} from '@fluxer/errors/src/domains/core/ConflictError';
+
+export class PaymentDisputeReviewClosedError extends ConflictError {
+ constructor() {
+ super({code: APIErrorCodes.PAYMENT_DISPUTE_REVIEW_CLOSED});
+ }
+}
diff --git a/packages/errors/src/domains/payment/PaymentDisputeWarningTooLateError.ts b/packages/errors/src/domains/payment/PaymentDisputeWarningTooLateError.ts
new file mode 100644
index 000000000..ddf78d27b
--- /dev/null
+++ b/packages/errors/src/domains/payment/PaymentDisputeWarningTooLateError.ts
@@ -0,0 +1,10 @@
+// SPDX-License-Identifier: AGPL-3.0-or-later
+
+import {APIErrorCodes} from '@fluxer/constants/src/ApiErrorCodes';
+import {ConflictError} from '@fluxer/errors/src/domains/core/ConflictError';
+
+export class PaymentDisputeWarningTooLateError extends ConflictError {
+ constructor() {
+ super({code: APIErrorCodes.PAYMENT_DISPUTE_WARNING_TOO_LATE});
+ }
+}
diff --git a/packages/errors/src/domains/payment/PremiumPurchaseBlockedError.ts b/packages/errors/src/domains/payment/PremiumPurchaseBlockedError.ts
index 8eae64be7..23ab1785e 100644
--- a/packages/errors/src/domains/payment/PremiumPurchaseBlockedError.ts
+++ b/packages/errors/src/domains/payment/PremiumPurchaseBlockedError.ts
@@ -4,7 +4,7 @@ import {APIErrorCodes} from '@fluxer/constants/src/ApiErrorCodes';
import {ForbiddenError} from '@fluxer/errors/src/domains/core/ForbiddenError';
import type {FluxerErrorData} from '@fluxer/errors/src/FluxerError';
-type PremiumPurchaseBlockedReason = 'lifetime' | 'existing_subscription' | 'purchase_disabled';
+type PremiumPurchaseBlockedReason = 'lifetime' | 'existing_subscription' | 'purchase_disabled' | 'payment_dispute_open';
type PremiumPurchaseBlockingProvider = 'stripe' | 'app_store' | 'google_play';
diff --git a/packages/errors/src/domains/payment/UnknownPaymentDisputeReviewError.ts b/packages/errors/src/domains/payment/UnknownPaymentDisputeReviewError.ts
new file mode 100644
index 000000000..fa5ed6293
--- /dev/null
+++ b/packages/errors/src/domains/payment/UnknownPaymentDisputeReviewError.ts
@@ -0,0 +1,10 @@
+// SPDX-License-Identifier: AGPL-3.0-or-later
+
+import {APIErrorCodes} from '@fluxer/constants/src/ApiErrorCodes';
+import {NotFoundError} from '@fluxer/errors/src/domains/core/NotFoundError';
+
+export class UnknownPaymentDisputeReviewError extends NotFoundError {
+ constructor() {
+ super({code: APIErrorCodes.UNKNOWN_PAYMENT_DISPUTE_REVIEW});
+ }
+}
diff --git a/packages/schema/src/domains/admin/AdminPaymentDisputeSchemas.ts b/packages/schema/src/domains/admin/AdminPaymentDisputeSchemas.ts
new file mode 100644
index 000000000..8169dfa65
--- /dev/null
+++ b/packages/schema/src/domains/admin/AdminPaymentDisputeSchemas.ts
@@ -0,0 +1,155 @@
+// SPDX-License-Identifier: AGPL-3.0-or-later
+
+import {createNamedStringLiteralUnion, SnowflakeStringType} from '@fluxer/schema/src/primitives/SchemaPrimitives';
+import {z} from 'zod';
+
+export const AdminPaymentDisputeProductSchema = createNamedStringLiteralUnion(
+ [
+ ['operator_pass', 'OPERATOR_PASS', 'An Operator Pass purchase or gift, under section 9 of the Operator Pass terms'],
+ ['plutonium', 'PLUTONIUM', 'A Plutonium subscription, purchase or gift, under section 4.4 of the terms of service'],
+ ],
+ 'Product the disputed payment was for',
+);
+
+export const AdminPaymentDisputeReviewBlockerSchema = createNamedStringLiteralUnion(
+ [
+ [
+ 'exempt_reason',
+ 'EXEMPT_REASON',
+ 'The dispute reason is fraudulent, unrecognized, debit_not_authorized, duplicate, credit_not_processed, product_not_received or product_unacceptable',
+ ],
+ ['during_withdrawal', 'DURING_WITHDRAWAL', 'The buyer disputed while the withdrawal right was live'],
+ ['withdrawn', 'WITHDRAWN', 'The buyer withdrew from the purchase'],
+ ['refunded_before_dispute', 'REFUNDED_BEFORE_DISPUTE', 'The payment was refunded before the dispute'],
+ ['perks_not_provided', 'PERKS_NOT_PROVIDED', 'What the payment bought, or a working gift code, was never provided'],
+ [
+ 'perks_removed',
+ 'PERKS_REMOVED',
+ 'The Operator Pass perks were removed under section 8 on or before the dispute date',
+ ],
+ [
+ 'before_terms_effective',
+ 'BEFORE_TERMS_EFFECTIVE',
+ 'A Plutonium payment or its dispute came before the terms that allow closing an account for a dispute took effect',
+ ],
+ ],
+ 'Why the terms rule out finding the dispute unjustified',
+);
+
+export const AdminPaymentDisputeReviewStatusSchema = createNamedStringLiteralUnion(
+ [
+ ['open', 'OPEN', 'Waiting for a person to review it'],
+ ['justified', 'JUSTIFIED', 'Found justified, no action against the account'],
+ [
+ 'unjustified',
+ 'UNJUSTIFIED',
+ 'Found unjustified, the account was warned and is closed if the dispute ends with the money returned',
+ ],
+ ],
+ 'Payment dispute review status',
+);
+
+export const AdminPaymentDisputeReviewResponse = z.object({
+ dispute_id: z.string().describe('Stripe dispute ID'),
+ product: AdminPaymentDisputeProductSchema,
+ order_id: z.string().describe('Disputed order: the checkout session, or the invoice or payment intent of a renewal'),
+ invoice_number: z
+ .string()
+ .nullable()
+ .describe("Stripe's invoice number of the disputed payment, or the charge receipt number when it has no invoice"),
+ purchaser_id: SnowflakeStringType.describe('Account that made the disputed payment'),
+ is_gift: z.boolean().describe('Whether the purchase was a gift'),
+ reason: z.string().describe('Stripe dispute reason code, read as the ground the bank gave'),
+ amount_minor: z.number().int().describe('Disputed amount in minor units'),
+ currency: z.string().describe('Currency of the disputed amount'),
+ evidence_submitted: z.boolean().describe('Whether evidence was submitted to the bank'),
+ evidence_due_by: z.iso.datetime().nullable().describe('Deadline Stripe gives for evidence to the bank'),
+ disputed_at: z.iso.datetime().nullable().describe('When the dispute opened'),
+ closed_at: z.iso.datetime().nullable().describe('When the dispute closed, null while it is open'),
+ outcome: z
+ .string()
+ .nullable()
+ .describe(
+ 'Stripe status the dispute closed with: won also covers a dispute the buyer withdrew, lost means the money was returned',
+ ),
+ purchased_at: z.iso.datetime().nullable().describe('When the payment was made'),
+ perks_started_at: z.iso.datetime().nullable().describe('When what the payment bought, or the gift code, started'),
+ withdrawal_ends_at: z.iso.datetime().nullable().describe('When the withdrawal period ended'),
+ withdrawn_at: z.iso.datetime().nullable().describe('When the buyer withdrew'),
+ refunded_at: z.iso.datetime().nullable().describe('When the payment was first refunded'),
+ perks_removed_at: z.iso
+ .datetime()
+ .nullable()
+ .describe('First Operator Pass perk removal under section 8 on or before the dispute date'),
+ status: AdminPaymentDisputeReviewStatusSchema,
+ blockers: z.array(AdminPaymentDisputeReviewBlockerSchema).describe('Grounds that rule out finding it unjustified'),
+ warnable: z
+ .boolean()
+ .describe(
+ 'Whether it can be marked unjustified now: open, unreviewed, no blockers and enough time before the warning date',
+ ),
+ warning_deadline: z.iso
+ .datetime()
+ .nullable()
+ .describe('Date the warning names, 3 days before evidence_due_by, or the date it would name while unreviewed'),
+ warning_email_sent_at: z.iso.datetime().nullable().describe('When the warning email was sent'),
+ warning_dm_sent_at: z.iso.datetime().nullable().describe('When the warning system message was sent'),
+ warned_at: z.iso
+ .datetime()
+ .nullable()
+ .describe('When the warning was complete, once both the email and the system message were sent'),
+ enforcement_decision_id: SnowflakeStringType.nullable().describe(
+ 'Enforcement decision that closed the account after the dispute ended with the money returned',
+ ),
+ awaited_decision_id: SnowflakeStringType.nullable().describe(
+ 'Other closure decision that holds the account while the closure for this dispute waits. The closure is recorded when that decision ends without the account being deleted',
+ ),
+ decided_at: z.iso.datetime().nullable().describe('When a person decided'),
+ decided_by: SnowflakeStringType.nullable().describe('Staff member who decided'),
+ decision_note: z
+ .string()
+ .nullable()
+ .describe('Note to the account holder given with the decision, shown in the warning and in the enforcement notice'),
+ reversed_at: z.iso.datetime().nullable().describe('When the unjustified finding was reversed after an appeal'),
+ reversed_by: SnowflakeStringType.nullable().describe('Staff member who reversed it'),
+ reversal_note: z.string().nullable().describe('Why it was reversed'),
+ dispute_purchase_at: z.iso
+ .datetime()
+ .nullable()
+ .describe('When a purchase from a store or an older Stripe checkout was first applied while the dispute was open'),
+});
+
+export type AdminPaymentDisputeReviewResponse = z.infer<typeof AdminPaymentDisputeReviewResponse>;
+
+export const AdminPaymentDisputeReviewListResponse = z.object({
+ reviews: z.array(AdminPaymentDisputeReviewResponse).describe('Dispute reviews, newest first'),
+});
+
+export type AdminPaymentDisputeReviewListResponse = z.infer<typeof AdminPaymentDisputeReviewListResponse>;
+
+export const AdminPaymentDisputeIdParam = z.object({
+ dispute_id: z.string().trim().min(1).max(128).describe('Stripe dispute ID'),
+});
+
+export const AdminPaymentDisputeDecisionRequest = z.object({
+ decision: z
+ .enum(['unjustified', 'justified'])
+ .describe('Find the dispute unjustified, which warns the account by email and system message, or justified'),
+ note: z
+ .string()
+ .trim()
+ .max(500)
+ .nullable()
+ .default(null)
+ .describe(
+ 'Note to the account holder, shown in the warning and in the enforcement notice if the account is closed',
+ ),
+});
+
+export type AdminPaymentDisputeDecisionRequest = z.infer<typeof AdminPaymentDisputeDecisionRequest>;
+
+export const AdminPaymentDisputeReversalRequest = z.object({
+ note: z.string().trim().min(1).max(2000).describe('What the appeal showed'),
+});
+
+export type AdminPaymentDisputeReversalRequest = z.infer<typeof AdminPaymentDisputeReversalRequest>;
diff --git a/packages/schema/src/domains/premium/PremiumSchemas.ts b/packages/schema/src/domains/premium/PremiumSchemas.ts
index 585b21d30..4dd8a3101 100644
--- a/packages/schema/src/domains/premium/PremiumSchemas.ts
+++ b/packages/schema/src/domains/premium/PremiumSchemas.ts
@@ -229,6 +229,9 @@ const PremiumEffectiveState = z.object({
premium_grace_ends_at: z.string().nullable().describe('Effective grace timestamp exposed to the client'),
premium_enabled_override: z.boolean().describe('Whether backend premium override is enabled'),
premium_purchase_disabled: z.boolean().describe('Whether premium purchase is disabled for this account'),
+ payment_dispute_open: z
+ .boolean()
+ .describe('Whether a payment dispute this account made is open, which blocks every purchase until it closes'),
premium_perks_disabled: z.boolean().describe('Whether the user temporarily disabled premium perks'),
self_hosted: z.boolean().describe('Whether the instance treats all users as premium because it is self-hosted'),
bot: z.boolean().describe('Whether the account is a bot account with premium-equivalent service access'),
@@ -288,6 +291,10 @@ export const SelfServeRefundIneligibilityReason = z.enum([
export type SelfServeRefundIneligibilityReason = z.infer<typeof SelfServeRefundIneligibilityReason>;
+export const SelfServeRefundProvider = withOpenApiType(z.enum(['stripe', 'google_play']), 'SelfServeRefundProvider');
+
+export type SelfServeRefundProvider = z.infer<typeof SelfServeRefundProvider>;
+
export const SelfServeRefundEligibilityResponse = z.object({
eligible: z
.boolean()
@@ -306,6 +313,7 @@ export const SelfServeRefundEligibilityResponse = z.object({
refund_window_expires_at: z.string().nullable().describe('ISO timestamp after which the 3-day refund window closes'),
cooldown_expires_at: z.string().nullable().describe('ISO timestamp the 30-day cooldown ends, if currently active'),
cancels_subscription: z.boolean().describe('Whether issuing the refund will also cancel the active subscription'),
+ provider: SelfServeRefundProvider.nullable().describe('Who took the payment for the purchase considered for refund'),
});
export type SelfServeRefundEligibilityResponse = z.infer<typeof SelfServeRefundEligibilityResponse>;
@@ -369,9 +377,12 @@ export const SelfServeRefundResponse = z.object({
refunded_amount_cents: z
.number()
.int()
- .describe('Amount actually refunded so far, in the currency minor unit; 0 until the provider confirms success'),
- invoice_amount_paid_cents: z.number().int(),
- currency: z.string(),
+ .nullable()
+ .describe(
+ 'Amount actually refunded so far, in the currency minor unit; 0 until the provider confirms success, null when the store does not report it',
+ ),
+ invoice_amount_paid_cents: z.number().int().nullable(),
+ currency: z.string().nullable(),
subscription_id: z
.string()
.nullable()
@@ -380,6 +391,7 @@ export const SelfServeRefundResponse = z.object({
.string()
.nullable()
.describe('Provider status of the refund (e.g. pending, succeeded, failed); money only moved once succeeded'),
+ provider: SelfServeRefundProvider.describe('Who took the payment that was refunded'),
});
export type SelfServeRefundResponse = z.infer<typeof SelfServeRefundResponse>;
diff --git a/packages/schema/src/domains/premium/StoreBillingSchemas.ts b/packages/schema/src/domains/premium/StoreBillingSchemas.ts
index a1631369e..f0d012c9d 100644
--- a/packages/schema/src/domains/premium/StoreBillingSchemas.ts
+++ b/packages/schema/src/domains/premium/StoreBillingSchemas.ts
@@ -36,7 +36,7 @@ const StorePurchaseStateSchema = withOpenApiType(
);
const StorePurchaseBlockedReasonSchema = withOpenApiType(
- z.enum(['lifetime', 'existing_subscription', 'purchase_disabled']),
+ z.enum(['lifetime', 'existing_subscription', 'purchase_disabled', 'payment_dispute_open']),
'StorePurchaseBlockedReason',
);