@classytic/revenue 2.1.3 → 2.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
- import { n as SubscriptionRepository, r as TransactionRepository, t as SettlementRepository } from "../settlement.repository-BAdc9qGl.mjs";
1
+ import { n as SubscriptionRepository, r as TransactionRepository, t as SettlementRepository } from "../settlement.repository-CfvgX3et.mjs";
2
2
 
3
3
  //#region src/repositories/create-repositories.ts
4
4
  function createRevenueRepositories(models, builtInPlugins, hostPlugins = {}) {
@@ -1,4 +1,5 @@
1
- import { t as REVENUE_EVENTS } from "./event-constants-Dn1TKahe.mjs";
1
+ import { t as REVENUE_EVENTS } from "./event-constants-DM_-A57b.mjs";
2
+ import { PAYMENT_METHOD_KIND } from "@classytic/primitives/payment-method-kind";
2
3
  import { createEvent, matchEventPattern } from "@classytic/primitives/events";
3
4
  import { z } from "zod";
4
5
 
@@ -71,6 +72,7 @@ var InProcessRevenueBus = class {
71
72
  * });
72
73
  * ```
73
74
  */
75
+ const PAYMENT_METHOD_KIND_VALUES = Object.values(PAYMENT_METHOD_KIND);
74
76
  function defineRevenueEvent(input) {
75
77
  const { name, version = 1, description, zodSchema } = input;
76
78
  return {
@@ -96,7 +98,8 @@ const transactionRef = z.object({
96
98
  publicId: z.string().optional(),
97
99
  status: z.string().optional(),
98
100
  monetizationType: z.string().optional(),
99
- amount: money.optional()
101
+ amount: money.optional(),
102
+ methodKind: z.enum(PAYMENT_METHOD_KIND_VALUES)
100
103
  }).passthrough();
101
104
  const subscriptionRef = z.object({
102
105
  _id: z.union([z.string(), z.any()]).optional(),
@@ -136,9 +139,52 @@ const paymentRefundedSchema = z.object({
136
139
  transaction: transactionRef,
137
140
  refundTransaction: transactionRef,
138
141
  refundAmount: money,
142
+ originalAmount: money,
139
143
  reason: z.string().optional(),
140
144
  isPartialRefund: z.boolean()
141
145
  });
146
+ const paymentAuthorizedSchema = z.object({
147
+ transaction: transactionRef,
148
+ authorizedAmount: money,
149
+ expiresAt: z.iso.datetime().optional()
150
+ });
151
+ const paymentCapturedSchema = z.object({
152
+ transaction: transactionRef,
153
+ capturedAmount: money,
154
+ authorizedAmount: money,
155
+ isPartial: z.boolean()
156
+ });
157
+ const paymentAuthVoidedSchema = z.object({
158
+ transaction: transactionRef,
159
+ voidedAmount: money,
160
+ reason: z.string().optional()
161
+ });
162
+ const paymentDisputedSchema = z.object({
163
+ transaction: transactionRef,
164
+ disputeId: z.string(),
165
+ disputedAmount: money,
166
+ reason: z.string(),
167
+ status: z.string(),
168
+ evidenceDueBy: z.iso.datetime().optional()
169
+ });
170
+ const paymentDisputeWonSchema = z.object({
171
+ transaction: transactionRef,
172
+ disputeId: z.string(),
173
+ recoveredAmount: money
174
+ });
175
+ const paymentDisputeLostSchema = z.object({
176
+ transaction: transactionRef,
177
+ disputeId: z.string(),
178
+ lostAmount: money,
179
+ feeAmount: money.optional()
180
+ });
181
+ const paymentSettledSchema = z.object({
182
+ transaction: transactionRef,
183
+ settledAmount: money,
184
+ feeAmount: money.optional(),
185
+ payoutId: z.string().optional(),
186
+ expectedArrivalAt: z.iso.datetime().optional()
187
+ });
142
188
  const monetizationCreatedSchema = z.object({
143
189
  monetizationType: z.string(),
144
190
  transaction: transactionRef
@@ -288,6 +334,41 @@ const PaymentRefunded = defineRevenueEvent({
288
334
  description: "A payment transaction was (partially or fully) refunded.",
289
335
  zodSchema: paymentRefundedSchema
290
336
  });
337
+ const PaymentAuthorized = defineRevenueEvent({
338
+ name: REVENUE_EVENTS.PAYMENT_AUTHORIZED,
339
+ description: "A payment authorisation hold was placed (funds NOT captured).",
340
+ zodSchema: paymentAuthorizedSchema
341
+ });
342
+ const PaymentCaptured = defineRevenueEvent({
343
+ name: REVENUE_EVENTS.PAYMENT_CAPTURED,
344
+ description: "A previously-authorised payment was captured (full or partial).",
345
+ zodSchema: paymentCapturedSchema
346
+ });
347
+ const PaymentAuthVoided = defineRevenueEvent({
348
+ name: REVENUE_EVENTS.PAYMENT_AUTH_VOIDED,
349
+ description: "An uncaptured payment authorisation was voided.",
350
+ zodSchema: paymentAuthVoidedSchema
351
+ });
352
+ const PaymentDisputed = defineRevenueEvent({
353
+ name: REVENUE_EVENTS.PAYMENT_DISPUTED,
354
+ description: "A dispute / chargeback was opened against a payment.",
355
+ zodSchema: paymentDisputedSchema
356
+ });
357
+ const PaymentDisputeWon = defineRevenueEvent({
358
+ name: REVENUE_EVENTS.PAYMENT_DISPUTE_WON,
359
+ description: "A payment dispute was resolved in the merchant's favour.",
360
+ zodSchema: paymentDisputeWonSchema
361
+ });
362
+ const PaymentDisputeLost = defineRevenueEvent({
363
+ name: REVENUE_EVENTS.PAYMENT_DISPUTE_LOST,
364
+ description: "A payment dispute was lost — funds permanently debited.",
365
+ zodSchema: paymentDisputeLostSchema
366
+ });
367
+ const PaymentSettled = defineRevenueEvent({
368
+ name: REVENUE_EVENTS.PAYMENT_SETTLED,
369
+ description: "Payment funds settled to the merchant bank account.",
370
+ zodSchema: paymentSettledSchema
371
+ });
291
372
  const MonetizationCreated = defineRevenueEvent({
292
373
  name: REVENUE_EVENTS.MONETIZATION_CREATED,
293
374
  description: "A monetization transaction (purchase, free grant, …) was created.",
@@ -430,6 +511,13 @@ const revenueEventDefinitions = [
430
511
  PaymentProcessing,
431
512
  PaymentRequiresAction,
432
513
  PaymentRefunded,
514
+ PaymentAuthorized,
515
+ PaymentCaptured,
516
+ PaymentAuthVoided,
517
+ PaymentDisputed,
518
+ PaymentDisputeWon,
519
+ PaymentDisputeLost,
520
+ PaymentSettled,
433
521
  MonetizationCreated,
434
522
  PurchaseCreated,
435
523
  FreeCreated,