authtara-sdk 1.1.8 → 1.1.9

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.
package/dist/index.d.mts CHANGED
@@ -447,6 +447,147 @@ declare class PricingModule {
447
447
  getAppPricing(): Promise<AppPricingResult | null>;
448
448
  }
449
449
 
450
+ /**
451
+ * Authtara SDK - Checkout Module
452
+ *
453
+ * Handles checkout and payment flow for subscriptions.
454
+ * Integrates with Digital Solution's billing system.
455
+ */
456
+
457
+ /**
458
+ * Parameters for creating a checkout session
459
+ */
460
+ interface CreateCheckoutParams {
461
+ /** Tenant ID making the purchase */
462
+ tenantId: string;
463
+ /** User ID initiating the checkout */
464
+ userId: string;
465
+ /** Plan slug (e.g., 'pro', 'basic') */
466
+ planSlug: string;
467
+ /** Billing cycle */
468
+ billingCycle: 'MONTHLY' | 'YEARLY';
469
+ }
470
+ /**
471
+ * Result of creating a checkout session
472
+ */
473
+ interface CheckoutResult {
474
+ /** Unique order identifier */
475
+ orderId: string;
476
+ /** URL to redirect user for payment */
477
+ paymentUrl: string;
478
+ /** Total amount to be charged */
479
+ amount: number;
480
+ /** Currency code (e.g., 'IDR') */
481
+ currency: string;
482
+ /** When the checkout session expires */
483
+ expiresAt: string;
484
+ /** Created subscription ID */
485
+ subscriptionId: string;
486
+ }
487
+ /**
488
+ * Checkout/payment status
489
+ */
490
+ interface CheckoutStatus {
491
+ /** Order identifier */
492
+ orderId: string;
493
+ /** Current status */
494
+ status: 'PENDING' | 'PAID' | 'FAILED' | 'EXPIRED';
495
+ /** Subscription details if available */
496
+ subscription: {
497
+ id: string;
498
+ status: string;
499
+ plan: string;
500
+ } | null;
501
+ /** Payment timestamp if paid */
502
+ paidAt: string | null;
503
+ }
504
+ /**
505
+ * Checkout Module
506
+ *
507
+ * Provides functions for subscription checkout and payment management.
508
+ * Use this to create checkout sessions and verify payment status.
509
+ *
510
+ * @example
511
+ * ```typescript
512
+ * // Create checkout session
513
+ * const checkout = await ds.checkout.create({
514
+ * tenantId: 'tenant-123',
515
+ * userId: 'user-456',
516
+ * planSlug: 'pro',
517
+ * billingCycle: 'MONTHLY'
518
+ * });
519
+ *
520
+ * // Redirect user to payment
521
+ * window.location.href = checkout.paymentUrl;
522
+ *
523
+ * // After payment redirect, verify status
524
+ * const status = await ds.checkout.verify(checkout.orderId);
525
+ * if (status.status === 'PAID') {
526
+ * console.log('Subscription activated!');
527
+ * }
528
+ * ```
529
+ */
530
+ declare class CheckoutModule {
531
+ private readonly httpClient;
532
+ constructor(httpClient: HttpClient);
533
+ /**
534
+ * Create a checkout session for a subscription purchase
535
+ *
536
+ * @param params - Checkout parameters
537
+ * @returns CheckoutResult with payment URL and order details
538
+ *
539
+ * @example
540
+ * ```typescript
541
+ * const checkout = await ds.checkout.create({
542
+ * tenantId: session.tenant.id,
543
+ * userId: session.user.id,
544
+ * planSlug: 'pro',
545
+ * billingCycle: 'MONTHLY'
546
+ * });
547
+ *
548
+ * // Redirect to payment page
549
+ * window.location.href = checkout.paymentUrl;
550
+ * ```
551
+ */
552
+ create(params: CreateCheckoutParams): Promise<CheckoutResult>;
553
+ /**
554
+ * Get checkout/payment status by order ID
555
+ *
556
+ * @param orderId - The order ID from checkout creation
557
+ * @returns CheckoutStatus with current payment status
558
+ *
559
+ * @example
560
+ * ```typescript
561
+ * const status = await ds.checkout.getStatus(orderId);
562
+ * console.log('Payment status:', status.status);
563
+ * ```
564
+ */
565
+ getStatus(orderId: string): Promise<CheckoutStatus>;
566
+ /**
567
+ * Verify checkout and activate subscription
568
+ *
569
+ * Call this after the user returns from the payment gateway.
570
+ * If payment is complete, the subscription will be activated.
571
+ *
572
+ * @param orderId - The order ID from checkout creation
573
+ * @returns CheckoutStatus with updated subscription status
574
+ *
575
+ * @example
576
+ * ```typescript
577
+ * // After redirect from payment gateway
578
+ * const status = await ds.checkout.verify(orderId);
579
+ *
580
+ * if (status.status === 'PAID') {
581
+ * console.log('Subscription activated!', status.subscription);
582
+ * redirect('/dashboard');
583
+ * } else {
584
+ * console.log('Payment failed:', status.status);
585
+ * }
586
+ * ```
587
+ */
588
+ verify(orderId: string): Promise<CheckoutStatus>;
589
+ }
590
+
450
591
  /**
451
592
  * Authtara SDK - Custom Error Classes
452
593
  *
@@ -580,6 +721,10 @@ declare class Authtara {
580
721
  * Pricing module untuk mengambil data pricing aplikasi
581
722
  */
582
723
  readonly pricing: PricingModule;
724
+ /**
725
+ * Checkout module untuk subscription purchase dan payment
726
+ */
727
+ readonly checkout: CheckoutModule;
583
728
  /**
584
729
  * Create new Authtara SDK instance
585
730
  *
@@ -589,4 +734,4 @@ declare class Authtara {
589
734
  constructor(config: AuthtaraConfig);
590
735
  }
591
736
 
592
- export { ApiError, type AppFeature, type AppPlan, type AppPlanFeature, type AppPrice, type AppPricingResult, Authtara, type AuthtaraConfig, AuthtaraError, type CheckEntitlementParams, ConfigurationError, EntitlementDeniedError, type EntitlementResult, type ExchangeResult, InvalidTokenError, type RecordUsageParams, type RecordUsageResult, type SessionVerifyResult, Authtara as default };
737
+ export { ApiError, type AppFeature, type AppPlan, type AppPlanFeature, type AppPrice, type AppPricingResult, Authtara, type AuthtaraConfig, AuthtaraError, type CheckEntitlementParams, type CheckoutResult, type CheckoutStatus, ConfigurationError, type CreateCheckoutParams, EntitlementDeniedError, type EntitlementResult, type ExchangeResult, InvalidTokenError, type RecordUsageParams, type RecordUsageResult, type SessionVerifyResult, Authtara as default };
package/dist/index.d.ts CHANGED
@@ -447,6 +447,147 @@ declare class PricingModule {
447
447
  getAppPricing(): Promise<AppPricingResult | null>;
448
448
  }
449
449
 
450
+ /**
451
+ * Authtara SDK - Checkout Module
452
+ *
453
+ * Handles checkout and payment flow for subscriptions.
454
+ * Integrates with Digital Solution's billing system.
455
+ */
456
+
457
+ /**
458
+ * Parameters for creating a checkout session
459
+ */
460
+ interface CreateCheckoutParams {
461
+ /** Tenant ID making the purchase */
462
+ tenantId: string;
463
+ /** User ID initiating the checkout */
464
+ userId: string;
465
+ /** Plan slug (e.g., 'pro', 'basic') */
466
+ planSlug: string;
467
+ /** Billing cycle */
468
+ billingCycle: 'MONTHLY' | 'YEARLY';
469
+ }
470
+ /**
471
+ * Result of creating a checkout session
472
+ */
473
+ interface CheckoutResult {
474
+ /** Unique order identifier */
475
+ orderId: string;
476
+ /** URL to redirect user for payment */
477
+ paymentUrl: string;
478
+ /** Total amount to be charged */
479
+ amount: number;
480
+ /** Currency code (e.g., 'IDR') */
481
+ currency: string;
482
+ /** When the checkout session expires */
483
+ expiresAt: string;
484
+ /** Created subscription ID */
485
+ subscriptionId: string;
486
+ }
487
+ /**
488
+ * Checkout/payment status
489
+ */
490
+ interface CheckoutStatus {
491
+ /** Order identifier */
492
+ orderId: string;
493
+ /** Current status */
494
+ status: 'PENDING' | 'PAID' | 'FAILED' | 'EXPIRED';
495
+ /** Subscription details if available */
496
+ subscription: {
497
+ id: string;
498
+ status: string;
499
+ plan: string;
500
+ } | null;
501
+ /** Payment timestamp if paid */
502
+ paidAt: string | null;
503
+ }
504
+ /**
505
+ * Checkout Module
506
+ *
507
+ * Provides functions for subscription checkout and payment management.
508
+ * Use this to create checkout sessions and verify payment status.
509
+ *
510
+ * @example
511
+ * ```typescript
512
+ * // Create checkout session
513
+ * const checkout = await ds.checkout.create({
514
+ * tenantId: 'tenant-123',
515
+ * userId: 'user-456',
516
+ * planSlug: 'pro',
517
+ * billingCycle: 'MONTHLY'
518
+ * });
519
+ *
520
+ * // Redirect user to payment
521
+ * window.location.href = checkout.paymentUrl;
522
+ *
523
+ * // After payment redirect, verify status
524
+ * const status = await ds.checkout.verify(checkout.orderId);
525
+ * if (status.status === 'PAID') {
526
+ * console.log('Subscription activated!');
527
+ * }
528
+ * ```
529
+ */
530
+ declare class CheckoutModule {
531
+ private readonly httpClient;
532
+ constructor(httpClient: HttpClient);
533
+ /**
534
+ * Create a checkout session for a subscription purchase
535
+ *
536
+ * @param params - Checkout parameters
537
+ * @returns CheckoutResult with payment URL and order details
538
+ *
539
+ * @example
540
+ * ```typescript
541
+ * const checkout = await ds.checkout.create({
542
+ * tenantId: session.tenant.id,
543
+ * userId: session.user.id,
544
+ * planSlug: 'pro',
545
+ * billingCycle: 'MONTHLY'
546
+ * });
547
+ *
548
+ * // Redirect to payment page
549
+ * window.location.href = checkout.paymentUrl;
550
+ * ```
551
+ */
552
+ create(params: CreateCheckoutParams): Promise<CheckoutResult>;
553
+ /**
554
+ * Get checkout/payment status by order ID
555
+ *
556
+ * @param orderId - The order ID from checkout creation
557
+ * @returns CheckoutStatus with current payment status
558
+ *
559
+ * @example
560
+ * ```typescript
561
+ * const status = await ds.checkout.getStatus(orderId);
562
+ * console.log('Payment status:', status.status);
563
+ * ```
564
+ */
565
+ getStatus(orderId: string): Promise<CheckoutStatus>;
566
+ /**
567
+ * Verify checkout and activate subscription
568
+ *
569
+ * Call this after the user returns from the payment gateway.
570
+ * If payment is complete, the subscription will be activated.
571
+ *
572
+ * @param orderId - The order ID from checkout creation
573
+ * @returns CheckoutStatus with updated subscription status
574
+ *
575
+ * @example
576
+ * ```typescript
577
+ * // After redirect from payment gateway
578
+ * const status = await ds.checkout.verify(orderId);
579
+ *
580
+ * if (status.status === 'PAID') {
581
+ * console.log('Subscription activated!', status.subscription);
582
+ * redirect('/dashboard');
583
+ * } else {
584
+ * console.log('Payment failed:', status.status);
585
+ * }
586
+ * ```
587
+ */
588
+ verify(orderId: string): Promise<CheckoutStatus>;
589
+ }
590
+
450
591
  /**
451
592
  * Authtara SDK - Custom Error Classes
452
593
  *
@@ -580,6 +721,10 @@ declare class Authtara {
580
721
  * Pricing module untuk mengambil data pricing aplikasi
581
722
  */
582
723
  readonly pricing: PricingModule;
724
+ /**
725
+ * Checkout module untuk subscription purchase dan payment
726
+ */
727
+ readonly checkout: CheckoutModule;
583
728
  /**
584
729
  * Create new Authtara SDK instance
585
730
  *
@@ -589,4 +734,4 @@ declare class Authtara {
589
734
  constructor(config: AuthtaraConfig);
590
735
  }
591
736
 
592
- export { ApiError, type AppFeature, type AppPlan, type AppPlanFeature, type AppPrice, type AppPricingResult, Authtara, type AuthtaraConfig, AuthtaraError, type CheckEntitlementParams, ConfigurationError, EntitlementDeniedError, type EntitlementResult, type ExchangeResult, InvalidTokenError, type RecordUsageParams, type RecordUsageResult, type SessionVerifyResult, Authtara as default };
737
+ export { ApiError, type AppFeature, type AppPlan, type AppPlanFeature, type AppPrice, type AppPricingResult, Authtara, type AuthtaraConfig, AuthtaraError, type CheckEntitlementParams, type CheckoutResult, type CheckoutStatus, ConfigurationError, type CreateCheckoutParams, EntitlementDeniedError, type EntitlementResult, type ExchangeResult, InvalidTokenError, type RecordUsageParams, type RecordUsageResult, type SessionVerifyResult, Authtara as default };
package/dist/index.js CHANGED
@@ -406,6 +406,109 @@ var PricingModule = class {
406
406
  }
407
407
  };
408
408
 
409
+ // src/checkout/index.ts
410
+ var CheckoutModule = class {
411
+ constructor(httpClient) {
412
+ if (!httpClient) {
413
+ throw new ConfigurationError("httpClient is required for CheckoutModule");
414
+ }
415
+ this.httpClient = httpClient;
416
+ }
417
+ /**
418
+ * Create a checkout session for a subscription purchase
419
+ *
420
+ * @param params - Checkout parameters
421
+ * @returns CheckoutResult with payment URL and order details
422
+ *
423
+ * @example
424
+ * ```typescript
425
+ * const checkout = await ds.checkout.create({
426
+ * tenantId: session.tenant.id,
427
+ * userId: session.user.id,
428
+ * planSlug: 'pro',
429
+ * billingCycle: 'MONTHLY'
430
+ * });
431
+ *
432
+ * // Redirect to payment page
433
+ * window.location.href = checkout.paymentUrl;
434
+ * ```
435
+ */
436
+ async create(params) {
437
+ if (!params.tenantId) {
438
+ throw new ConfigurationError("tenantId is required");
439
+ }
440
+ if (!params.userId) {
441
+ throw new ConfigurationError("userId is required");
442
+ }
443
+ if (!params.planSlug) {
444
+ throw new ConfigurationError("planSlug is required");
445
+ }
446
+ if (!params.billingCycle) {
447
+ throw new ConfigurationError("billingCycle is required");
448
+ }
449
+ return this.httpClient.post(
450
+ "/api/v1/dev/checkout/create",
451
+ {
452
+ tenantId: params.tenantId,
453
+ userId: params.userId,
454
+ planSlug: params.planSlug,
455
+ billingCycle: params.billingCycle
456
+ }
457
+ );
458
+ }
459
+ /**
460
+ * Get checkout/payment status by order ID
461
+ *
462
+ * @param orderId - The order ID from checkout creation
463
+ * @returns CheckoutStatus with current payment status
464
+ *
465
+ * @example
466
+ * ```typescript
467
+ * const status = await ds.checkout.getStatus(orderId);
468
+ * console.log('Payment status:', status.status);
469
+ * ```
470
+ */
471
+ async getStatus(orderId) {
472
+ if (!orderId) {
473
+ throw new ConfigurationError("orderId is required");
474
+ }
475
+ return this.httpClient.get(
476
+ `/api/v1/dev/checkout/status/${orderId}`
477
+ );
478
+ }
479
+ /**
480
+ * Verify checkout and activate subscription
481
+ *
482
+ * Call this after the user returns from the payment gateway.
483
+ * If payment is complete, the subscription will be activated.
484
+ *
485
+ * @param orderId - The order ID from checkout creation
486
+ * @returns CheckoutStatus with updated subscription status
487
+ *
488
+ * @example
489
+ * ```typescript
490
+ * // After redirect from payment gateway
491
+ * const status = await ds.checkout.verify(orderId);
492
+ *
493
+ * if (status.status === 'PAID') {
494
+ * console.log('Subscription activated!', status.subscription);
495
+ * redirect('/dashboard');
496
+ * } else {
497
+ * console.log('Payment failed:', status.status);
498
+ * }
499
+ * ```
500
+ */
501
+ async verify(orderId) {
502
+ if (!orderId) {
503
+ throw new ConfigurationError("orderId is required");
504
+ }
505
+ return this.httpClient.post(
506
+ "/api/v1/dev/checkout/verify",
507
+ { orderId }
508
+ );
509
+ }
510
+ };
511
+
409
512
  // src/index.ts
410
513
  var Authtara = class {
411
514
  /**
@@ -434,6 +537,7 @@ var Authtara = class {
434
537
  this.billing = new BillingModule(httpClient);
435
538
  this.metering = new MeteringModule(httpClient);
436
539
  this.pricing = new PricingModule(httpClient);
540
+ this.checkout = new CheckoutModule(httpClient);
437
541
  }
438
542
  };
439
543
  var index_default = Authtara;
package/dist/index.mjs CHANGED
@@ -374,6 +374,109 @@ var PricingModule = class {
374
374
  }
375
375
  };
376
376
 
377
+ // src/checkout/index.ts
378
+ var CheckoutModule = class {
379
+ constructor(httpClient) {
380
+ if (!httpClient) {
381
+ throw new ConfigurationError("httpClient is required for CheckoutModule");
382
+ }
383
+ this.httpClient = httpClient;
384
+ }
385
+ /**
386
+ * Create a checkout session for a subscription purchase
387
+ *
388
+ * @param params - Checkout parameters
389
+ * @returns CheckoutResult with payment URL and order details
390
+ *
391
+ * @example
392
+ * ```typescript
393
+ * const checkout = await ds.checkout.create({
394
+ * tenantId: session.tenant.id,
395
+ * userId: session.user.id,
396
+ * planSlug: 'pro',
397
+ * billingCycle: 'MONTHLY'
398
+ * });
399
+ *
400
+ * // Redirect to payment page
401
+ * window.location.href = checkout.paymentUrl;
402
+ * ```
403
+ */
404
+ async create(params) {
405
+ if (!params.tenantId) {
406
+ throw new ConfigurationError("tenantId is required");
407
+ }
408
+ if (!params.userId) {
409
+ throw new ConfigurationError("userId is required");
410
+ }
411
+ if (!params.planSlug) {
412
+ throw new ConfigurationError("planSlug is required");
413
+ }
414
+ if (!params.billingCycle) {
415
+ throw new ConfigurationError("billingCycle is required");
416
+ }
417
+ return this.httpClient.post(
418
+ "/api/v1/dev/checkout/create",
419
+ {
420
+ tenantId: params.tenantId,
421
+ userId: params.userId,
422
+ planSlug: params.planSlug,
423
+ billingCycle: params.billingCycle
424
+ }
425
+ );
426
+ }
427
+ /**
428
+ * Get checkout/payment status by order ID
429
+ *
430
+ * @param orderId - The order ID from checkout creation
431
+ * @returns CheckoutStatus with current payment status
432
+ *
433
+ * @example
434
+ * ```typescript
435
+ * const status = await ds.checkout.getStatus(orderId);
436
+ * console.log('Payment status:', status.status);
437
+ * ```
438
+ */
439
+ async getStatus(orderId) {
440
+ if (!orderId) {
441
+ throw new ConfigurationError("orderId is required");
442
+ }
443
+ return this.httpClient.get(
444
+ `/api/v1/dev/checkout/status/${orderId}`
445
+ );
446
+ }
447
+ /**
448
+ * Verify checkout and activate subscription
449
+ *
450
+ * Call this after the user returns from the payment gateway.
451
+ * If payment is complete, the subscription will be activated.
452
+ *
453
+ * @param orderId - The order ID from checkout creation
454
+ * @returns CheckoutStatus with updated subscription status
455
+ *
456
+ * @example
457
+ * ```typescript
458
+ * // After redirect from payment gateway
459
+ * const status = await ds.checkout.verify(orderId);
460
+ *
461
+ * if (status.status === 'PAID') {
462
+ * console.log('Subscription activated!', status.subscription);
463
+ * redirect('/dashboard');
464
+ * } else {
465
+ * console.log('Payment failed:', status.status);
466
+ * }
467
+ * ```
468
+ */
469
+ async verify(orderId) {
470
+ if (!orderId) {
471
+ throw new ConfigurationError("orderId is required");
472
+ }
473
+ return this.httpClient.post(
474
+ "/api/v1/dev/checkout/verify",
475
+ { orderId }
476
+ );
477
+ }
478
+ };
479
+
377
480
  // src/index.ts
378
481
  var Authtara = class {
379
482
  /**
@@ -402,6 +505,7 @@ var Authtara = class {
402
505
  this.billing = new BillingModule(httpClient);
403
506
  this.metering = new MeteringModule(httpClient);
404
507
  this.pricing = new PricingModule(httpClient);
508
+ this.checkout = new CheckoutModule(httpClient);
405
509
  }
406
510
  };
407
511
  var index_default = Authtara;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "authtara-sdk",
3
- "version": "1.1.8",
3
+ "version": "1.1.9",
4
4
  "description": "SDK Client untuk integrasi dengan DigitalSolution Platform - SSO, Billing, dan Metering",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",