@apexara/stripe 1.0.2

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.
Files changed (65) hide show
  1. package/README.md +1003 -0
  2. package/dist/apex-stripe.d.ts +23 -0
  3. package/dist/apex-stripe.d.ts.map +1 -0
  4. package/dist/apex-stripe.js +41 -0
  5. package/dist/client.d.ts +7 -0
  6. package/dist/client.d.ts.map +1 -0
  7. package/dist/client.js +14 -0
  8. package/dist/errors/http-error.d.ts +7 -0
  9. package/dist/errors/http-error.d.ts.map +1 -0
  10. package/dist/errors/http-error.js +14 -0
  11. package/dist/index.d.ts +16 -0
  12. package/dist/index.d.ts.map +1 -0
  13. package/dist/index.js +48 -0
  14. package/dist/models/config.model.d.ts +31 -0
  15. package/dist/models/config.model.d.ts.map +1 -0
  16. package/dist/models/config.model.js +2 -0
  17. package/dist/models/index.d.ts +5 -0
  18. package/dist/models/index.d.ts.map +1 -0
  19. package/dist/models/index.js +20 -0
  20. package/dist/models/stripe.model.d.ts +69 -0
  21. package/dist/models/stripe.model.d.ts.map +1 -0
  22. package/dist/models/stripe.model.js +2 -0
  23. package/dist/models/subscription.model.d.ts +24 -0
  24. package/dist/models/subscription.model.d.ts.map +1 -0
  25. package/dist/models/subscription.model.js +2 -0
  26. package/dist/models/webhook.model.d.ts +43 -0
  27. package/dist/models/webhook.model.d.ts.map +1 -0
  28. package/dist/models/webhook.model.js +2 -0
  29. package/dist/services/checkout/checkout.service.d.ts +31 -0
  30. package/dist/services/checkout/checkout.service.d.ts.map +1 -0
  31. package/dist/services/checkout/checkout.service.js +119 -0
  32. package/dist/services/connected-account/connected-account.service.d.ts +25 -0
  33. package/dist/services/connected-account/connected-account.service.d.ts.map +1 -0
  34. package/dist/services/connected-account/connected-account.service.js +46 -0
  35. package/dist/services/customer/customer.service.d.ts +14 -0
  36. package/dist/services/customer/customer.service.d.ts.map +1 -0
  37. package/dist/services/customer/customer.service.js +23 -0
  38. package/dist/services/invoice/invoice.service.d.ts +24 -0
  39. package/dist/services/invoice/invoice.service.d.ts.map +1 -0
  40. package/dist/services/invoice/invoice.service.js +65 -0
  41. package/dist/services/payment-link/payment-link.service.d.ts +18 -0
  42. package/dist/services/payment-link/payment-link.service.d.ts.map +1 -0
  43. package/dist/services/payment-link/payment-link.service.js +53 -0
  44. package/dist/services/payment-method/payment-method.service.d.ts +43 -0
  45. package/dist/services/payment-method/payment-method.service.d.ts.map +1 -0
  46. package/dist/services/payment-method/payment-method.service.js +89 -0
  47. package/dist/services/price/price.service.d.ts +17 -0
  48. package/dist/services/price/price.service.d.ts.map +1 -0
  49. package/dist/services/price/price.service.js +32 -0
  50. package/dist/services/subscription/subscription.service.d.ts +89 -0
  51. package/dist/services/subscription/subscription.service.d.ts.map +1 -0
  52. package/dist/services/subscription/subscription.service.js +272 -0
  53. package/dist/tests/helpers.d.ts +5 -0
  54. package/dist/tests/helpers.d.ts.map +1 -0
  55. package/dist/tests/helpers.js +96 -0
  56. package/dist/utils/helpers.d.ts +15 -0
  57. package/dist/utils/helpers.d.ts.map +1 -0
  58. package/dist/utils/helpers.js +41 -0
  59. package/dist/webhooks/webhook.dispatcher.d.ts +25 -0
  60. package/dist/webhooks/webhook.dispatcher.d.ts.map +1 -0
  61. package/dist/webhooks/webhook.dispatcher.js +105 -0
  62. package/dist/webhooks/webhook.handler.d.ts +39 -0
  63. package/dist/webhooks/webhook.handler.d.ts.map +1 -0
  64. package/dist/webhooks/webhook.handler.js +70 -0
  65. package/package.json +57 -0
@@ -0,0 +1,23 @@
1
+ import Stripe from 'stripe';
2
+ import { PriceService } from './services/price/price.service';
3
+ import { InvoiceService } from './services/invoice/invoice.service';
4
+ import { CheckoutService } from './services/checkout/checkout.service';
5
+ import { CustomerService } from './services/customer/customer.service';
6
+ import { PaymentLinkService } from './services/payment-link/payment-link.service';
7
+ import { SubscriptionService } from './services/subscription/subscription.service';
8
+ import { PaymentMethodService } from './services/payment-method/payment-method.service';
9
+ import { ConnectedAccountService } from './services/connected-account/connected-account.service';
10
+ import { StripeClientConfig, StripeServiceConfig } from './models/config.model';
11
+ export declare class ApexStripe {
12
+ constructor(clientConfig: StripeClientConfig, serviceConfig?: StripeServiceConfig);
13
+ readonly client: Stripe;
14
+ readonly checkout: CheckoutService;
15
+ readonly customers: CustomerService;
16
+ readonly invoices: InvoiceService;
17
+ readonly paymentLinks: PaymentLinkService;
18
+ readonly paymentMethods: PaymentMethodService;
19
+ readonly prices: PriceService;
20
+ readonly connectedAccounts: ConnectedAccountService;
21
+ readonly subscriptions: SubscriptionService;
22
+ }
23
+ //# sourceMappingURL=apex-stripe.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"apex-stripe.d.ts","sourceRoot":"","sources":["../src/apex-stripe.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,QAAQ,CAAC;AAI5B,OAAO,EAAE,YAAY,EAAE,MAAM,gCAAgC,CAAC;AAC9D,OAAO,EAAE,cAAc,EAAE,MAAM,oCAAoC,CAAC;AACpE,OAAO,EAAE,eAAe,EAAE,MAAM,sCAAsC,CAAC;AACvE,OAAO,EAAE,eAAe,EAAE,MAAM,sCAAsC,CAAC;AACvE,OAAO,EAAE,kBAAkB,EAAE,MAAM,8CAA8C,CAAC;AAClF,OAAO,EAAE,mBAAmB,EAAE,MAAM,8CAA8C,CAAC;AACnF,OAAO,EAAE,oBAAoB,EAAE,MAAM,kDAAkD,CAAC;AACxF,OAAO,EAAE,uBAAuB,EAAE,MAAM,wDAAwD,CAAC;AAEjG,OAAO,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAiBhF,qBAAa,UAAU;gBAGnB,YAAY,EAAE,kBAAkB,EAChC,aAAa,CAAC,EAAE,mBAAmB;IAcrC,SAAgB,MAAM,EAAE,MAAM,CAAC;IAC/B,SAAgB,QAAQ,EAAE,eAAe,CAAC;IAC1C,SAAgB,SAAS,EAAE,eAAe,CAAC;IAC3C,SAAgB,QAAQ,EAAE,cAAc,CAAC;IACzC,SAAgB,YAAY,EAAE,kBAAkB,CAAC;IACjD,SAAgB,cAAc,EAAE,oBAAoB,CAAC;IACrD,SAAgB,MAAM,EAAE,YAAY,CAAC;IACrC,SAAgB,iBAAiB,EAAE,uBAAuB,CAAC;IAC3D,SAAgB,aAAa,EAAE,mBAAmB,CAAC;CAEpD"}
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ApexStripe = void 0;
4
+ const client_1 = require("./client");
5
+ const price_service_1 = require("./services/price/price.service");
6
+ const invoice_service_1 = require("./services/invoice/invoice.service");
7
+ const checkout_service_1 = require("./services/checkout/checkout.service");
8
+ const customer_service_1 = require("./services/customer/customer.service");
9
+ const payment_link_service_1 = require("./services/payment-link/payment-link.service");
10
+ const subscription_service_1 = require("./services/subscription/subscription.service");
11
+ const payment_method_service_1 = require("./services/payment-method/payment-method.service");
12
+ const connected_account_service_1 = require("./services/connected-account/connected-account.service");
13
+ const DEFAULTS = {
14
+ currency: 'usd',
15
+ orderPaymentMethods: ['card', 'link', 'cashapp', 'klarna'],
16
+ subscriptionPaymentMethods: ['card', 'link', 'cashapp'],
17
+ setupIntentPaymentMethods: ['card'],
18
+ checkoutUiMode: 'custom',
19
+ allowPromotionCodes: true,
20
+ savePaymentMethod: true,
21
+ orderInvoiceCreation: true,
22
+ invoiceCollectionMethod: 'send_invoice',
23
+ invoiceDaysUntilDue: 3,
24
+ invoicePaymentMethodTypes: ['card', 'link'],
25
+ connectedAccountType: 'express',
26
+ };
27
+ class ApexStripe {
28
+ constructor(clientConfig, serviceConfig) {
29
+ const config = { ...DEFAULTS, ...serviceConfig };
30
+ this.client = (0, client_1.createStripeClient)(clientConfig);
31
+ this.checkout = new checkout_service_1.CheckoutService(this.client, config);
32
+ this.customers = new customer_service_1.CustomerService(this.client);
33
+ this.invoices = new invoice_service_1.InvoiceService(this.client, config);
34
+ this.paymentLinks = new payment_link_service_1.PaymentLinkService(this.client, config);
35
+ this.paymentMethods = new payment_method_service_1.PaymentMethodService(this.client);
36
+ this.prices = new price_service_1.PriceService(this.client, config);
37
+ this.connectedAccounts = new connected_account_service_1.ConnectedAccountService(this.client, config);
38
+ this.subscriptions = new subscription_service_1.SubscriptionService(this.client, config);
39
+ }
40
+ }
41
+ exports.ApexStripe = ApexStripe;
@@ -0,0 +1,7 @@
1
+ import Stripe from 'stripe';
2
+ import { StripeClientConfig } from './models/config.model';
3
+ /**
4
+ * Creates and returns a configured Stripe client.
5
+ */
6
+ export declare function createStripeClient(config: StripeClientConfig): Stripe;
7
+ //# sourceMappingURL=client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,QAAQ,CAAC;AAE5B,OAAO,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAI3D;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,kBAAkB,GAAG,MAAM,CAErE"}
package/dist/client.js ADDED
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.createStripeClient = createStripeClient;
7
+ const stripe_1 = __importDefault(require("stripe"));
8
+ const DEFAULT_API_VERSION = '2025-08-27.basil';
9
+ /**
10
+ * Creates and returns a configured Stripe client.
11
+ */
12
+ function createStripeClient(config) {
13
+ return new stripe_1.default(config.secretKey, { apiVersion: config.apiVersion ?? DEFAULT_API_VERSION });
14
+ }
@@ -0,0 +1,7 @@
1
+ export declare class HttpError extends Error {
2
+ readonly status: number;
3
+ readonly message: string;
4
+ constructor(status: number, message: string);
5
+ readonly shouldSendEmail?: boolean;
6
+ }
7
+ //# sourceMappingURL=http-error.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"http-error.d.ts","sourceRoot":"","sources":["../../src/errors/http-error.ts"],"names":[],"mappings":"AAAA,qBAAa,SAAU,SAAQ,KAAK;aAGhB,MAAM,EAAE,MAAM;aACd,OAAO,EAAE,MAAM;gBADf,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,MAAM;IASjC,SAAgB,eAAe,CAAC,EAAE,OAAO,CAAC;CAE3C"}
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.HttpError = void 0;
4
+ class HttpError extends Error {
5
+ constructor(status, message) {
6
+ super(message);
7
+ this.status = status;
8
+ this.message = message;
9
+ if (status < 500) {
10
+ this.shouldSendEmail = false;
11
+ }
12
+ }
13
+ }
14
+ exports.HttpError = HttpError;
@@ -0,0 +1,16 @@
1
+ export { ApexStripe } from './apex-stripe';
2
+ export { createStripeClient } from './client';
3
+ export { HttpError } from './errors/http-error';
4
+ export { getBillingCycleLabel, calculateAffiliateSubscriptionPayoutPercent, calculateAffiliatePaymentPayoutAmount } from './utils/helpers';
5
+ export { WebhookDispatcher } from './webhooks/webhook.dispatcher';
6
+ export { StripeWebhookHandler } from './webhooks/webhook.handler';
7
+ export { PriceService } from './services/price/price.service';
8
+ export { InvoiceService } from './services/invoice/invoice.service';
9
+ export { CheckoutService } from './services/checkout/checkout.service';
10
+ export { CustomerService } from './services/customer/customer.service';
11
+ export { PaymentLinkService } from './services/payment-link/payment-link.service';
12
+ export { SubscriptionService } from './services/subscription/subscription.service';
13
+ export { PaymentMethodService } from './services/payment-method/payment-method.service';
14
+ export { ConnectedAccountService } from './services/connected-account/connected-account.service';
15
+ export * from './models';
16
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAE3C,OAAO,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAC;AAE9C,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAEhD,OAAO,EAAE,oBAAoB,EAAE,2CAA2C,EAAE,qCAAqC,EAAE,MAAM,iBAAiB,CAAC;AAE3I,OAAO,EAAE,iBAAiB,EAAE,MAAM,+BAA+B,CAAC;AAClE,OAAO,EAAE,oBAAoB,EAAE,MAAM,4BAA4B,CAAC;AAElE,OAAO,EAAE,YAAY,EAAE,MAAM,gCAAgC,CAAC;AAC9D,OAAO,EAAE,cAAc,EAAE,MAAM,oCAAoC,CAAC;AACpE,OAAO,EAAE,eAAe,EAAE,MAAM,sCAAsC,CAAC;AACvE,OAAO,EAAE,eAAe,EAAE,MAAM,sCAAsC,CAAC;AACvE,OAAO,EAAE,kBAAkB,EAAE,MAAM,8CAA8C,CAAC;AAClF,OAAO,EAAE,mBAAmB,EAAE,MAAM,8CAA8C,CAAC;AACnF,OAAO,EAAE,oBAAoB,EAAE,MAAM,kDAAkD,CAAC;AACxF,OAAO,EAAE,uBAAuB,EAAE,MAAM,wDAAwD,CAAC;AAEjG,cAAc,UAAU,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,48 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.ConnectedAccountService = exports.PaymentMethodService = exports.SubscriptionService = exports.PaymentLinkService = exports.CustomerService = exports.CheckoutService = exports.InvoiceService = exports.PriceService = exports.StripeWebhookHandler = exports.WebhookDispatcher = exports.calculateAffiliatePaymentPayoutAmount = exports.calculateAffiliateSubscriptionPayoutPercent = exports.getBillingCycleLabel = exports.HttpError = exports.createStripeClient = exports.ApexStripe = void 0;
18
+ var apex_stripe_1 = require("./apex-stripe");
19
+ Object.defineProperty(exports, "ApexStripe", { enumerable: true, get: function () { return apex_stripe_1.ApexStripe; } });
20
+ var client_1 = require("./client");
21
+ Object.defineProperty(exports, "createStripeClient", { enumerable: true, get: function () { return client_1.createStripeClient; } });
22
+ var http_error_1 = require("./errors/http-error");
23
+ Object.defineProperty(exports, "HttpError", { enumerable: true, get: function () { return http_error_1.HttpError; } });
24
+ var helpers_1 = require("./utils/helpers");
25
+ Object.defineProperty(exports, "getBillingCycleLabel", { enumerable: true, get: function () { return helpers_1.getBillingCycleLabel; } });
26
+ Object.defineProperty(exports, "calculateAffiliateSubscriptionPayoutPercent", { enumerable: true, get: function () { return helpers_1.calculateAffiliateSubscriptionPayoutPercent; } });
27
+ Object.defineProperty(exports, "calculateAffiliatePaymentPayoutAmount", { enumerable: true, get: function () { return helpers_1.calculateAffiliatePaymentPayoutAmount; } });
28
+ var webhook_dispatcher_1 = require("./webhooks/webhook.dispatcher");
29
+ Object.defineProperty(exports, "WebhookDispatcher", { enumerable: true, get: function () { return webhook_dispatcher_1.WebhookDispatcher; } });
30
+ var webhook_handler_1 = require("./webhooks/webhook.handler");
31
+ Object.defineProperty(exports, "StripeWebhookHandler", { enumerable: true, get: function () { return webhook_handler_1.StripeWebhookHandler; } });
32
+ var price_service_1 = require("./services/price/price.service");
33
+ Object.defineProperty(exports, "PriceService", { enumerable: true, get: function () { return price_service_1.PriceService; } });
34
+ var invoice_service_1 = require("./services/invoice/invoice.service");
35
+ Object.defineProperty(exports, "InvoiceService", { enumerable: true, get: function () { return invoice_service_1.InvoiceService; } });
36
+ var checkout_service_1 = require("./services/checkout/checkout.service");
37
+ Object.defineProperty(exports, "CheckoutService", { enumerable: true, get: function () { return checkout_service_1.CheckoutService; } });
38
+ var customer_service_1 = require("./services/customer/customer.service");
39
+ Object.defineProperty(exports, "CustomerService", { enumerable: true, get: function () { return customer_service_1.CustomerService; } });
40
+ var payment_link_service_1 = require("./services/payment-link/payment-link.service");
41
+ Object.defineProperty(exports, "PaymentLinkService", { enumerable: true, get: function () { return payment_link_service_1.PaymentLinkService; } });
42
+ var subscription_service_1 = require("./services/subscription/subscription.service");
43
+ Object.defineProperty(exports, "SubscriptionService", { enumerable: true, get: function () { return subscription_service_1.SubscriptionService; } });
44
+ var payment_method_service_1 = require("./services/payment-method/payment-method.service");
45
+ Object.defineProperty(exports, "PaymentMethodService", { enumerable: true, get: function () { return payment_method_service_1.PaymentMethodService; } });
46
+ var connected_account_service_1 = require("./services/connected-account/connected-account.service");
47
+ Object.defineProperty(exports, "ConnectedAccountService", { enumerable: true, get: function () { return connected_account_service_1.ConnectedAccountService; } });
48
+ __exportStar(require("./models"), exports);
@@ -0,0 +1,31 @@
1
+ import Stripe from 'stripe';
2
+ type PaymentMethodType = Stripe.Checkout.SessionCreateParams.PaymentMethodType;
3
+ type SubscriptionPaymentMethodType = Stripe.SubscriptionCreateParams.PaymentSettings.PaymentMethodType;
4
+ export interface StripeProcessingFees {
5
+ flat: number; /** Flat fee in cents (e.g. 30 for $0.30) */
6
+ percent: number; /** Percentage as decimal (e.g. 0.029 for 2.9%) */
7
+ }
8
+ export interface StripeClientConfig {
9
+ secretKey: string;
10
+ apiVersion?: Stripe.LatestApiVersion; /** Defaults to '2025-08-27.basil' */
11
+ }
12
+ export interface StripeServiceConfig {
13
+ currency?: string; /** Defaults to 'usd' */
14
+ orderPaymentMethods?: PaymentMethodType[]; /** Defaults to ['card', 'link', 'cashapp', 'klarna'] */
15
+ subscriptionPaymentMethods?: PaymentMethodType[]; /** Defaults to ['card', 'link', 'cashapp'] */
16
+ setupIntentPaymentMethods?: PaymentMethodType[]; /** Defaults to ['card'] */
17
+ checkoutUiMode?: 'custom' | 'embedded' | 'hosted'; /** Defaults to 'custom' */
18
+ allowPromotionCodes?: boolean; /** Defaults to true */
19
+ savePaymentMethod?: boolean; /** Defaults to true */
20
+ orderInvoiceCreation?: boolean; /** Defaults to true */
21
+ invoiceCollectionMethod?: 'send_invoice' | 'charge_automatically'; /** Defaults to 'send_invoice' */
22
+ invoiceDaysUntilDue?: number; /** Defaults to 3 */
23
+ invoicePaymentMethodTypes?: SubscriptionPaymentMethodType[]; /** Defaults to ['card', 'link'] */
24
+ connectedAccountType?: Stripe.AccountCreateParams['type']; /** Defaults to 'express' */
25
+ }
26
+ export interface WebhookHandlerConfig {
27
+ webhookSecret: string;
28
+ connectedWebhookSecret?: string;
29
+ }
30
+ export {};
31
+ //# sourceMappingURL=config.model.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.model.d.ts","sourceRoot":"","sources":["../../src/models/config.model.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,QAAQ,CAAC;AAE5B,KAAK,iBAAiB,GAAG,MAAM,CAAC,QAAQ,CAAC,mBAAmB,CAAC,iBAAiB,CAAC;AAC/E,KAAK,6BAA6B,GAAG,MAAM,CAAC,wBAAwB,CAAC,eAAe,CAAC,iBAAiB,CAAC;AAEvG,MAAM,WAAW,oBAAoB;IACnC,IAAI,EAAE,MAAM,CAAC,CAAC,4CAA4C;IAC1D,OAAO,EAAE,MAAM,CAAC,CAAC,kDAAkD;CACpE;AAKD,MAAM,WAAW,kBAAkB;IACjC,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,CAAC,EAAE,MAAM,CAAC,gBAAgB,CAAC,CAAC,qCAAqC;CAC5E;AAED,MAAM,WAAW,mBAAmB;IAElC,QAAQ,CAAC,EAAE,MAAM,CAAC,CAAC,wBAAwB;IAG3C,mBAAmB,CAAC,EAAE,iBAAiB,EAAE,CAAC,CAAC,wDAAwD;IACnG,0BAA0B,CAAC,EAAE,iBAAiB,EAAE,CAAC,CAAC,8CAA8C;IAChG,yBAAyB,CAAC,EAAE,iBAAiB,EAAE,CAAC,CAAC,2BAA2B;IAG5E,cAAc,CAAC,EAAE,QAAQ,GAAG,UAAU,GAAG,QAAQ,CAAC,CAAC,2BAA2B;IAC9E,mBAAmB,CAAC,EAAE,OAAO,CAAC,CAAC,uBAAuB;IACtD,iBAAiB,CAAC,EAAE,OAAO,CAAC,CAAC,uBAAuB;IACpD,oBAAoB,CAAC,EAAE,OAAO,CAAC,CAAC,uBAAuB;IAGvD,uBAAuB,CAAC,EAAE,cAAc,GAAG,sBAAsB,CAAC,CAAC,iCAAiC;IACpG,mBAAmB,CAAC,EAAE,MAAM,CAAC,CAAC,oBAAoB;IAClD,yBAAyB,CAAC,EAAE,6BAA6B,EAAE,CAAC,CAAC,mCAAmC;IAGhG,oBAAoB,CAAC,EAAE,MAAM,CAAC,mBAAmB,CAAC,MAAM,CAAC,CAAC,CAAC,4BAA4B;CACxF;AAGD,MAAM,WAAW,oBAAoB;IACnC,aAAa,EAAE,MAAM,CAAC;IACtB,sBAAsB,CAAC,EAAE,MAAM,CAAC;CACjC"}
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,5 @@
1
+ export * from './config.model';
2
+ export * from './stripe.model';
3
+ export * from './webhook.model';
4
+ export * from './subscription.model';
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/models/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,iBAAiB,CAAC;AAChC,cAAc,sBAAsB,CAAC"}
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./config.model"), exports);
18
+ __exportStar(require("./stripe.model"), exports);
19
+ __exportStar(require("./webhook.model"), exports);
20
+ __exportStar(require("./subscription.model"), exports);
@@ -0,0 +1,69 @@
1
+ import Stripe from 'stripe';
2
+ export interface SubscriptionSyncFields {
3
+ status: Stripe.Subscription.Status;
4
+ cancelAtPeriodEnd: boolean;
5
+ currentPeriodStart: Date | null;
6
+ currentPeriodEnd: Date | null;
7
+ itemId: string;
8
+ }
9
+ export interface AffiliatePaymentParams {
10
+ accountId: string;
11
+ amount: number;
12
+ }
13
+ export interface AffiliateSubscriptionParams {
14
+ transferData: Stripe.SubscriptionUpdateParams['transfer_data'];
15
+ metadata: Record<string, string>;
16
+ }
17
+ export interface CreatePaymentCheckoutSessionParams {
18
+ mode: 'payment';
19
+ customerId: string;
20
+ name: string;
21
+ cost: number;
22
+ quantity: number;
23
+ returnUrl: string;
24
+ metadata?: Record<string, string>;
25
+ affiliate?: AffiliatePaymentParams;
26
+ }
27
+ export interface CreateSubscriptionCheckoutSessionParams {
28
+ mode: 'subscription';
29
+ customerId: string;
30
+ priceIds: string[];
31
+ quantity: number;
32
+ returnUrl: string;
33
+ metadata?: Record<string, string>;
34
+ affiliate?: AffiliateSubscriptionParams;
35
+ }
36
+ export type CreateCheckoutSessionParams = CreatePaymentCheckoutSessionParams | CreateSubscriptionCheckoutSessionParams;
37
+ export interface CreatePaymentLinkParams {
38
+ name: string;
39
+ cost: number;
40
+ redirectUrl: string;
41
+ metadata?: Record<string, string>;
42
+ affiliate?: AffiliatePaymentParams;
43
+ }
44
+ export interface PaymentLinkResult {
45
+ id: string;
46
+ url: string;
47
+ productId: string;
48
+ priceId: string;
49
+ }
50
+ export interface CreateCustomPriceParams {
51
+ cost: number;
52
+ billingPeriod: 'day' | 'week' | 'month' | 'year';
53
+ billingIntervalCount: number;
54
+ label: string;
55
+ stripeProductId: string;
56
+ metadata?: Record<string, string>;
57
+ }
58
+ export interface CreateInvoiceParams {
59
+ customerId: string;
60
+ amount: number;
61
+ description: string;
62
+ metadata?: Record<string, string>;
63
+ transferData?: Stripe.InvoiceCreateParams['transfer_data'];
64
+ }
65
+ export interface PendingActivationInvoice {
66
+ subscriptionId: string;
67
+ hostedInvoiceUrl: string | null;
68
+ }
69
+ //# sourceMappingURL=stripe.model.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"stripe.model.d.ts","sourceRoot":"","sources":["../../src/models/stripe.model.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,QAAQ,CAAC;AAE5B,MAAM,WAAW,sBAAsB;IACrC,MAAM,EAAE,MAAM,CAAC,YAAY,CAAC,MAAM,CAAC;IACnC,iBAAiB,EAAE,OAAO,CAAC;IAC3B,kBAAkB,EAAE,IAAI,GAAG,IAAI,CAAC;IAChC,gBAAgB,EAAE,IAAI,GAAG,IAAI,CAAC;IAC9B,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,sBAAsB;IACrC,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,2BAA2B;IAC1C,YAAY,EAAE,MAAM,CAAC,wBAAwB,CAAC,eAAe,CAAC,CAAC;IAC/D,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAClC;AAED,MAAM,WAAW,kCAAkC;IACjD,IAAI,EAAE,SAAS,CAAC;IAChB,UAAU,EAAE,MAAM,CAAC;IACnB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAClC,SAAS,CAAC,EAAE,sBAAsB,CAAC;CACpC;AAED,MAAM,WAAW,uCAAuC;IACtD,IAAI,EAAE,cAAc,CAAC;IACrB,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,EAAE,MAAM,EAAE,CAAC;IACnB,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAClC,SAAS,CAAC,EAAE,2BAA2B,CAAC;CACzC;AAED,MAAM,MAAM,2BAA2B,GACnC,kCAAkC,GAClC,uCAAuC,CAAC;AAE5C,MAAM,WAAW,uBAAuB;IACtC,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAClC,SAAS,CAAC,EAAE,sBAAsB,CAAC;CACpC;AAED,MAAM,WAAW,iBAAiB;IAChC,EAAE,EAAE,MAAM,CAAC;IACX,GAAG,EAAE,MAAM,CAAC;IACZ,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,uBAAuB;IACtC,IAAI,EAAE,MAAM,CAAC;IACb,aAAa,EAAE,KAAK,GAAG,MAAM,GAAG,OAAO,GAAG,MAAM,CAAC;IACjD,oBAAoB,EAAE,MAAM,CAAC;IAC7B,KAAK,EAAE,MAAM,CAAC;IACd,eAAe,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACnC;AAED,MAAM,WAAW,mBAAmB;IAClC,UAAU,EAAE,MAAM,CAAC;IACnB,MAAM,EAAE,MAAM,CAAC;IACf,WAAW,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAClC,YAAY,CAAC,EAAE,MAAM,CAAC,mBAAmB,CAAC,eAAe,CAAC,CAAC;CAC5D;AAED,MAAM,WAAW,wBAAwB;IACvC,cAAc,EAAE,MAAM,CAAC;IACvB,gBAAgB,EAAE,MAAM,GAAG,IAAI,CAAC;CACjC"}
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,24 @@
1
+ import Stripe from 'stripe';
2
+ export interface ScheduleDowngradeOptions {
3
+ quantity?: number;
4
+ transferData?: Stripe.SubscriptionScheduleUpdateParams.Phase['transfer_data'];
5
+ phaseMetadata?: Record<string, string>;
6
+ scheduleMetadata?: Record<string, string>;
7
+ }
8
+ export interface SwitchSubscriptionPlanOptions {
9
+ quantity?: number;
10
+ proration?: Stripe.SubscriptionUpdateParams['proration_behavior'];
11
+ }
12
+ export interface CreateInvoiceSubscriptionOptions {
13
+ daysUntilDue?: number;
14
+ paymentMethodTypes?: Stripe.SubscriptionCreateParams.PaymentSettings.PaymentMethodType[];
15
+ metadata?: Record<string, string>;
16
+ transferData?: Stripe.SubscriptionCreateParams['transfer_data'];
17
+ quantity?: number;
18
+ }
19
+ export interface CreateInvoiceSubscriptionResult {
20
+ subscription: Stripe.Subscription;
21
+ invoiceId: string;
22
+ invoiceUrl: string | null;
23
+ }
24
+ //# sourceMappingURL=subscription.model.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"subscription.model.d.ts","sourceRoot":"","sources":["../../src/models/subscription.model.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,QAAQ,CAAC;AAE5B,MAAM,WAAW,wBAAwB;IACvC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAElB,YAAY,CAAC,EAAE,MAAM,CAAC,gCAAgC,CAAC,KAAK,CAAC,eAAe,CAAC,CAAC;IAE9E,aAAa,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAEvC,gBAAgB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAC3C;AAED,MAAM,WAAW,6BAA6B;IAC5C,QAAQ,CAAC,EAAE,MAAM,CAAC;IAElB,SAAS,CAAC,EAAE,MAAM,CAAC,wBAAwB,CAAC,oBAAoB,CAAC,CAAC;CACnE;AAED,MAAM,WAAW,gCAAgC;IAC/C,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,kBAAkB,CAAC,EAAE,MAAM,CAAC,wBAAwB,CAAC,eAAe,CAAC,iBAAiB,EAAE,CAAC;IACzF,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAClC,YAAY,CAAC,EAAE,MAAM,CAAC,wBAAwB,CAAC,eAAe,CAAC,CAAC;IAChE,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,+BAA+B;IAC9C,YAAY,EAAE,MAAM,CAAC,YAAY,CAAC;IAClC,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;CAC3B"}
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,43 @@
1
+ import Stripe from 'stripe';
2
+ export interface WebhookEventStore {
3
+ /**
4
+ * Atomically tries to record a new event.
5
+ * Returns true if the event is new and should be processed.
6
+ * Returns false if the event was already processed (duplicate).
7
+ *
8
+ * Implementations should use a unique index or equivalent to ensure
9
+ * the check-and-insert is atomic (prevents duplicate processing on
10
+ * concurrent webhook deliveries of the same event).
11
+ */
12
+ tryInsert(eventId: string, type: string): Promise<boolean>;
13
+ }
14
+ export interface CheckoutCompletedPayload {
15
+ session: Stripe.Checkout.Session;
16
+ metadata: Stripe.Metadata;
17
+ }
18
+ export interface InvoicePaidPayload {
19
+ event: Stripe.InvoicePaidEvent;
20
+ invoice: Stripe.Invoice;
21
+ }
22
+ export interface InvoicePaymentFailedPayload {
23
+ event: Stripe.InvoicePaymentFailedEvent;
24
+ invoice: Stripe.Invoice;
25
+ failReason: string | null;
26
+ }
27
+ export interface SubscriptionDeletedPayload {
28
+ event: Stripe.CustomerSubscriptionDeletedEvent;
29
+ subscription: Stripe.Subscription;
30
+ }
31
+ export interface ConnectedAccountUpdatedPayload {
32
+ account: Stripe.Account;
33
+ }
34
+ export interface WebhookHooks {
35
+ eventStore: WebhookEventStore;
36
+ onCheckoutCompleted?(payload: CheckoutCompletedPayload): Promise<void>;
37
+ onInvoicePaid?(payload: InvoicePaidPayload): Promise<void>;
38
+ onInvoicePaymentFailed?(payload: InvoicePaymentFailedPayload): Promise<void>;
39
+ onSubscriptionDeleted?(payload: SubscriptionDeletedPayload): Promise<void>;
40
+ onConnectedAccountUpdated?(payload: ConnectedAccountUpdatedPayload): Promise<void>;
41
+ onError?(context: string, error: unknown): void;
42
+ }
43
+ //# sourceMappingURL=webhook.model.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"webhook.model.d.ts","sourceRoot":"","sources":["../../src/models/webhook.model.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,QAAQ,CAAC;AAI5B,MAAM,WAAW,iBAAiB;IAChC;;;;;;;;OAQG;IACH,SAAS,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;CAC5D;AAID,MAAM,WAAW,wBAAwB;IACvC,OAAO,EAAE,MAAM,CAAC,QAAQ,CAAC,OAAO,CAAC;IACjC,QAAQ,EAAE,MAAM,CAAC,QAAQ,CAAC;CAC3B;AAED,MAAM,WAAW,kBAAkB;IACjC,KAAK,EAAE,MAAM,CAAC,gBAAgB,CAAC;IAC/B,OAAO,EAAE,MAAM,CAAC,OAAO,CAAC;CACzB;AAED,MAAM,WAAW,2BAA2B;IAC1C,KAAK,EAAE,MAAM,CAAC,yBAAyB,CAAC;IACxC,OAAO,EAAE,MAAM,CAAC,OAAO,CAAC;IACxB,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;CAC3B;AAED,MAAM,WAAW,0BAA0B;IACzC,KAAK,EAAE,MAAM,CAAC,gCAAgC,CAAC;IAC/C,YAAY,EAAE,MAAM,CAAC,YAAY,CAAC;CACnC;AAED,MAAM,WAAW,8BAA8B;IAC7C,OAAO,EAAE,MAAM,CAAC,OAAO,CAAC;CACzB;AAID,MAAM,WAAW,YAAY;IAG3B,UAAU,EAAE,iBAAiB,CAAC;IAI9B,mBAAmB,CAAC,CAAC,OAAO,EAAE,wBAAwB,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAIvE,aAAa,CAAC,CAAC,OAAO,EAAE,kBAAkB,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAI3D,sBAAsB,CAAC,CAAC,OAAO,EAAE,2BAA2B,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAG7E,qBAAqB,CAAC,CAAC,OAAO,EAAE,0BAA0B,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAG3E,yBAAyB,CAAC,CAAC,OAAO,EAAE,8BAA8B,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAInF,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,GAAG,IAAI,CAAC;CACjD"}
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,31 @@
1
+ import Stripe from 'stripe';
2
+ import { StripeServiceConfig } from './../../models/config.model';
3
+ import { CreateCheckoutSessionParams } from './../../models/stripe.model';
4
+ export declare class CheckoutService {
5
+ private readonly stripe;
6
+ private readonly config;
7
+ constructor(stripe: Stripe, config: Required<StripeServiceConfig>);
8
+ /**
9
+ * Creates a Stripe Checkout session and returns the client secret.
10
+ */
11
+ createCheckoutSession(params: CreateCheckoutSessionParams): Promise<string | null>;
12
+ /**
13
+ * Creates a SetupIntent session for collecting a payment method without an immediate charge.
14
+ */
15
+ createSetupIntentSession(customerId: string): Promise<string | null>;
16
+ /**
17
+ * Expires a checkout session. Silently succeeds if the session is already expired.
18
+ */
19
+ expireCheckoutSession(sessionId: string): Promise<void>;
20
+ /**
21
+ * Retrieves a checkout session, optionally with expanded fields.
22
+ */
23
+ retrieveCheckoutSession(sessionId: string, options?: Stripe.Checkout.SessionRetrieveParams): Promise<Stripe.Checkout.Session>;
24
+ /**
25
+ * Retrieves a payment intent, optionally with expanded fields.
26
+ */
27
+ getPaymentIntent(paymentIntentId: string, options?: Stripe.PaymentIntentRetrieveParams): Promise<Stripe.PaymentIntent>;
28
+ private buildPaymentSessionParams;
29
+ private buildSubscriptionSessionParams;
30
+ }
31
+ //# sourceMappingURL=checkout.service.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"checkout.service.d.ts","sourceRoot":"","sources":["../../../src/services/checkout/checkout.service.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,QAAQ,CAAC;AAE5B,OAAO,EAAE,mBAAmB,EAAE,MAAM,6BAA6B,CAAC;AAClE,OAAO,EAAE,2BAA2B,EAA+E,MAAM,6BAA6B,CAAC;AAEvJ,qBAAa,eAAe;IAGxB,OAAO,CAAC,QAAQ,CAAC,MAAM;IACvB,OAAO,CAAC,QAAQ,CAAC,MAAM;gBADN,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,QAAQ,CAAC,mBAAmB,CAAC;IAIxD;;OAEG;IACU,qBAAqB,CAAC,MAAM,EAAE,2BAA2B,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC;IAW/F;;OAEG;IACU,wBAAwB,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC;IAUjF;;OAEG;IACU,qBAAqB,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAWpE;;OAEG;IACU,uBAAuB,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,CAAC,QAAQ,CAAC,qBAAqB,GAAG,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,OAAO,CAAC;IAM1I;;OAEG;IACU,gBAAgB,CAAC,eAAe,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,CAAC,2BAA2B,GAAG,OAAO,CAAC,MAAM,CAAC,aAAa,CAAC;IAMnI,OAAO,CAAC,yBAAyB;IAyCjC,OAAO,CAAC,8BAA8B;CA+BvC"}
@@ -0,0 +1,119 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CheckoutService = void 0;
4
+ class CheckoutService {
5
+ constructor(stripe, config) {
6
+ this.stripe = stripe;
7
+ this.config = config;
8
+ }
9
+ // Checkout sessions
10
+ /**
11
+ * Creates a Stripe Checkout session and returns the client secret.
12
+ */
13
+ async createCheckoutSession(params) {
14
+ const sessionParams = params.mode === 'subscription'
15
+ ? this.buildSubscriptionSessionParams(params)
16
+ : this.buildPaymentSessionParams(params);
17
+ const session = await this.stripe.checkout.sessions.create(sessionParams);
18
+ return session.client_secret;
19
+ }
20
+ /**
21
+ * Creates a SetupIntent session for collecting a payment method without an immediate charge.
22
+ */
23
+ async createSetupIntentSession(customerId) {
24
+ const session = await this.stripe.setupIntents.create({
25
+ customer: customerId,
26
+ payment_method_types: this.config.setupIntentPaymentMethods,
27
+ usage: 'off_session',
28
+ });
29
+ return session.client_secret;
30
+ }
31
+ /**
32
+ * Expires a checkout session. Silently succeeds if the session is already expired.
33
+ */
34
+ async expireCheckoutSession(sessionId) {
35
+ await this.stripe.checkout.sessions.expire(sessionId)
36
+ .catch(err => {
37
+ const isAlreadyExpired = err && typeof err === 'object' && 'code' in err && err.code === 'resource_missing';
38
+ if (!isAlreadyExpired) {
39
+ throw err;
40
+ }
41
+ });
42
+ }
43
+ /**
44
+ * Retrieves a checkout session, optionally with expanded fields.
45
+ */
46
+ async retrieveCheckoutSession(sessionId, options) {
47
+ return this.stripe.checkout.sessions.retrieve(sessionId, options);
48
+ }
49
+ // Payment intents
50
+ /**
51
+ * Retrieves a payment intent, optionally with expanded fields.
52
+ */
53
+ async getPaymentIntent(paymentIntentId, options) {
54
+ return this.stripe.paymentIntents.retrieve(paymentIntentId, options);
55
+ }
56
+ // Private helpers
57
+ buildPaymentSessionParams(params) {
58
+ const { customerId, name, cost, returnUrl, affiliate } = params;
59
+ const sessionParams = {
60
+ ui_mode: this.config.checkoutUiMode,
61
+ mode: 'payment',
62
+ customer: customerId,
63
+ allow_promotion_codes: this.config.allowPromotionCodes,
64
+ payment_method_types: this.config.orderPaymentMethods,
65
+ line_items: [{
66
+ quantity: params.quantity,
67
+ price_data: {
68
+ currency: this.config.currency,
69
+ product_data: { name },
70
+ unit_amount: cost,
71
+ },
72
+ }],
73
+ metadata: params.metadata,
74
+ return_url: returnUrl,
75
+ };
76
+ if (this.config.savePaymentMethod) {
77
+ sessionParams.saved_payment_method_options = { payment_method_save: 'enabled' };
78
+ }
79
+ if (this.config.orderInvoiceCreation) {
80
+ sessionParams.invoice_creation = {
81
+ enabled: true,
82
+ invoice_data: { metadata: params.metadata },
83
+ };
84
+ }
85
+ if (affiliate) {
86
+ sessionParams.payment_intent_data = {
87
+ transfer_data: { destination: affiliate.accountId, amount: affiliate.amount },
88
+ };
89
+ }
90
+ return sessionParams;
91
+ }
92
+ buildSubscriptionSessionParams(params) {
93
+ const { customerId, priceIds, returnUrl, affiliate } = params;
94
+ const sessionParams = {
95
+ ui_mode: this.config.checkoutUiMode,
96
+ mode: 'subscription',
97
+ payment_method_types: this.config.subscriptionPaymentMethods,
98
+ subscription_data: {
99
+ billing_mode: { type: 'flexible' },
100
+ },
101
+ line_items: priceIds.map(priceId => ({ quantity: params.quantity, price: priceId })),
102
+ customer: customerId,
103
+ metadata: params.metadata,
104
+ return_url: returnUrl,
105
+ };
106
+ if (this.config.savePaymentMethod) {
107
+ sessionParams.saved_payment_method_options = { payment_method_save: 'enabled' };
108
+ }
109
+ if (affiliate?.transferData) {
110
+ sessionParams.subscription_data = {
111
+ ...sessionParams.subscription_data,
112
+ transfer_data: affiliate.transferData,
113
+ metadata: affiliate.metadata,
114
+ };
115
+ }
116
+ return sessionParams;
117
+ }
118
+ }
119
+ exports.CheckoutService = CheckoutService;
@@ -0,0 +1,25 @@
1
+ import Stripe from 'stripe';
2
+ import { StripeServiceConfig } from './../../models/config.model';
3
+ export declare class ConnectedAccountService {
4
+ private readonly stripe;
5
+ private readonly config;
6
+ constructor(stripe: Stripe, config: Required<StripeServiceConfig>);
7
+ /**
8
+ * Creates a new Stripe Connect account and returns its ID.
9
+ */
10
+ createConnectedAccount(metadata?: Record<string, string>): Promise<string>;
11
+ /**
12
+ * Permanently deletes a connected account.
13
+ */
14
+ deleteConnectedAccount(accountId: string): Promise<void>;
15
+ /**
16
+ * Creates a one-time URL for a connected account to complete onboarding or access their dashboard.
17
+ * Defaults to account_onboarding type.
18
+ */
19
+ createAccountLink(accountId: string, refreshUrl: string, returnUrl: string, type?: Stripe.AccountLinkCreateParams['type']): Promise<string>;
20
+ /**
21
+ * Creates a login link for an Express connected account dashboard.
22
+ */
23
+ createLoginLink(accountId: string): Promise<string>;
24
+ }
25
+ //# sourceMappingURL=connected-account.service.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"connected-account.service.d.ts","sourceRoot":"","sources":["../../../src/services/connected-account/connected-account.service.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,QAAQ,CAAC;AAE5B,OAAO,EAAE,mBAAmB,EAAE,MAAM,6BAA6B,CAAC;AAElE,qBAAa,uBAAuB;IAGhC,OAAO,CAAC,QAAQ,CAAC,MAAM;IACvB,OAAO,CAAC,QAAQ,CAAC,MAAM;gBADN,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,QAAQ,CAAC,mBAAmB,CAAC;IAExD;;OAEG;IACU,sBAAsB,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,OAAO,CAAC,MAAM,CAAC;IASvF;;OAEG;IACU,sBAAsB,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAIrE;;;OAGG;IACU,iBAAiB,CAAC,SAAS,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,IAAI,GAAE,MAAM,CAAC,uBAAuB,CAAC,MAAM,CAAwB,GAAG,OAAO,CAAC,MAAM,CAAC;IAW9K;;OAEG;IACU,eAAe,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;CAMjE"}