@revenuecat/purchases-js 0.2.2 → 0.3.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.
@@ -372,6 +372,28 @@ export declare interface Price {
372
372
  readonly formattedPrice: string;
373
373
  }
374
374
 
375
+ /**
376
+ * Represents the price and duration information for a phase of the purchase option.
377
+ * @public
378
+ */
379
+ export declare interface PricingPhase {
380
+ /**
381
+ * The duration of the purchase option price in ISO 8601 format.
382
+ * For applicable options (trials, initial/promotional prices), otherwise null
383
+ */
384
+ readonly periodDuration: string | null;
385
+ /**
386
+ * The price for the purchase option.
387
+ * Null in case of trials.
388
+ */
389
+ readonly price: Price | null;
390
+ /**
391
+ * The number of cycles this option's price repeats.
392
+ * I.e. 2 subscription cycles, 0 if not applicable.
393
+ */
394
+ readonly cycleCount: number;
395
+ }
396
+
375
397
  /**
376
398
  * Represents product's listing details.
377
399
  * @public
@@ -383,20 +405,80 @@ export declare interface Product {
383
405
  readonly identifier: string;
384
406
  /**
385
407
  * Name of the product.
408
+ * @deprecated - Use {@link Product.title} instead.
386
409
  */
387
410
  readonly displayName: string;
388
411
  /**
389
- * Price of the product.
412
+ * The title of the product as configured in the RevenueCat dashboard.
413
+ */
414
+ readonly title: string;
415
+ /**
416
+ * The description of the product as configured in the RevenueCat dashboard.
417
+ */
418
+ readonly description: string | null;
419
+ /**
420
+ * Price of the product. In the case of subscriptions, this will match the
421
+ * default option's base phase price.
390
422
  */
391
423
  readonly currentPrice: Price;
392
424
  /**
393
- * The period duration for a subscription product.
425
+ * The period duration for a subscription product. This will match the default
426
+ * option's base phase period duration.
394
427
  */
395
428
  readonly normalPeriodDuration: string | null;
396
429
  /**
397
430
  * The offering ID used to obtain this product.
398
431
  */
399
432
  readonly presentedOfferingIdentifier: string;
433
+ /**
434
+ * The default subscription option for this product. Null if no subscription
435
+ * options are available like in the case of consumables and non-consumables.
436
+ */
437
+ readonly defaultSubscriptionOption: SubscriptionOption | null;
438
+ /**
439
+ * A dictionary with all the possible subscription options available for this
440
+ * product. Each key contains the key to be used when executing a purchase.
441
+ *
442
+ * If retrieved through getOfferings the offers are only the ones the customer is
443
+ * entitled to.
444
+ */
445
+ readonly subscriptionOptions: {
446
+ [optionId: string]: SubscriptionOption;
447
+ };
448
+ }
449
+
450
+ /**
451
+ * Represents a possible option to purchase a product.
452
+ * @public
453
+ */
454
+ export declare interface PurchaseOption {
455
+ /**
456
+ * The unique id for a purchase option
457
+ */
458
+ readonly id: string;
459
+ }
460
+
461
+ /**
462
+ * Parameters used to customise the purchase flow when invoking the `.purchase` method.
463
+ * @public
464
+ */
465
+ export declare interface PurchaseParams {
466
+ /**
467
+ * The package you want to purchase. Obtained from {@link Purchases.getOfferings}.
468
+ */
469
+ rcPackage: Package;
470
+ /**
471
+ * The option to be used for this purchase. If not specified or null the default one will be used.
472
+ */
473
+ purchaseOption?: PurchaseOption | null;
474
+ /**
475
+ * The HTML element where the billing view should be added. If undefined, a new div will be created at the root of the page and appended to the body.
476
+ */
477
+ htmlTarget?: HTMLElement;
478
+ /**
479
+ * The email of the user. If undefined, RevenueCat will ask the customer for their email.
480
+ */
481
+ customerEmail?: string;
400
482
  }
401
483
 
402
484
  /**
@@ -451,87 +533,117 @@ export declare class Purchases {
451
533
  * package from {@link Purchases.getOfferings}. This method will present the purchase
452
534
  * form on your site, using the given HTML element as the mount point, if
453
535
  * provided, or as a modal if not.
536
+ * @deprecated - please use .purchase
454
537
  * @param rcPackage - The package you want to purchase. Obtained from {@link Purchases.getOfferings}.
455
- * @param customerEmail - The email of the user. If null, RevenueCat will ask the customer for their email.
456
- * @param htmlTarget - The HTML element where the billing view should be added. If null, a new div will be created at the root of the page and appended to the body.
457
- * @returns The customer info after the purchase is completed successfuly.
538
+ * @param customerEmail - The email of the user. If undefined, RevenueCat will ask the customer for their email.
539
+ * @param htmlTarget - The HTML element where the billing view should be added. If undefined, a new div will be created at the root of the page and appended to the body.
540
+ * @returns a Promise for the customer info after the purchase is completed successfully.
458
541
  * @throws {@link PurchasesError} if there is an error while performing the purchase. If the {@link PurchasesError.errorCode} is {@link ErrorCode.UserCancelledError}, the user cancelled the purchase.
459
542
  */
460
543
  purchasePackage(rcPackage: Package, customerEmail?: string, htmlTarget?: HTMLElement): Promise<{
461
544
  customerInfo: CustomerInfo;
462
545
  }>;
463
546
  /**
464
- * Gets latest available {@link CustomerInfo}.
465
- * @returns The latest {@link CustomerInfo}.
466
- * @throws {@link PurchasesError} if there is an error while fetching the customer info.
547
+ * Method to perform a purchase for a given package. You can obtain the
548
+ * package from {@link Purchases.getOfferings}. This method will present the purchase
549
+ * form on your site, using the given HTML element as the mount point, if
550
+ * provided, or as a modal if not.
551
+ * @param params - The parameters object to customise the purchase flow. Check {@link PurchaseParams}
552
+ * @returns a Promise for the customer info after the purchase is completed successfully.
553
+ * @throws {@link PurchasesError} if there is an error while performing the purchase. If the {@link PurchasesError.errorCode} is {@link ErrorCode.UserCancelledError}, the user cancelled the purchase.
467
554
  */
468
- getCustomerInfo(): Promise<CustomerInfo>;
555
+ purchase(params: PurchaseParams): Promise<{
556
+ customerInfo: CustomerInfo;
557
+ }>;
469
558
  /**
470
- * Gets the current app user id.
471
- */
472
- getAppUserId(): string;
559
+ * Gets latest available {@link CustomerInfo}.
560
+ * @returns The latest {@link CustomerInfo}.
561
+ * @throws {@link PurchasesError} if there is an error while fetching the customer info.
562
+ */
563
+ getCustomerInfo(): Promise<CustomerInfo>;
564
+ /**
565
+ * Gets the current app user id.
566
+ */
567
+ getAppUserId(): string;
568
+ /**
569
+ * Change the current app user id. Returns the customer info for the new
570
+ * user id.
571
+ * @param newAppUserId - The user id to change to.
572
+ */
573
+ changeUser(newAppUserId: string): Promise<CustomerInfo>;
574
+ /**
575
+ * @returns Whether the SDK is using a sandbox API Key.
576
+ */
577
+ isSandbox(): boolean;
578
+ /**
579
+ * Closes the Purchases instance. You should never have to do this normally.
580
+ */
581
+ close(): void;
582
+ }
583
+
473
584
  /**
474
- * Change the current app user id. Returns the customer info for the new
475
- * user id.
476
- * @param newAppUserId - The user id to change to.
585
+ * Error class for Purchases SDK. You should handle these errors and react
586
+ * accordingly in your app.
587
+ * @public
477
588
  */
478
- changeUser(newAppUserId: string): Promise<CustomerInfo>;
589
+ export declare class PurchasesError extends Error {
590
+ /**
591
+ * Error code for the error. This is useful to appropriately react to
592
+ * different error situations.
593
+ */
594
+ readonly errorCode: ErrorCode;
595
+ /**
596
+ * Underlying error message. This provides more details on the error and
597
+ * can be useful for debugging and logging.
598
+ */
599
+ readonly underlyingErrorMessage?: string | null | undefined;
600
+ constructor(
601
+ /**
602
+ * Error code for the error. This is useful to appropriately react to
603
+ * different error situations.
604
+ */
605
+ errorCode: ErrorCode,
606
+ /**
607
+ * Message for the error. This is useful for debugging and logging.
608
+ */
609
+ message?: string,
610
+ /**
611
+ * Underlying error message. This provides more details on the error and
612
+ * can be useful for debugging and logging.
613
+ */
614
+ underlyingErrorMessage?: string | null | undefined);
615
+ toString: () => string;
616
+ }
617
+
479
618
  /**
480
- * @returns Whether the SDK is using a sandbox API Key.
619
+ * The store where the user originally subscribed.
620
+ * @public
481
621
  */
482
- isSandbox(): boolean;
622
+ export declare type Store = "app_store" | "mac_app_store" | "play_store" | "amazon" | "stripe" | "rc_billing" | "promotional" | "unknown";
623
+
483
624
  /**
484
- * Closes the Purchases instance. You should never have to do this normally.
625
+ * Represents a possible option to purchase a subscription product.
626
+ * @public
485
627
  */
486
- close(): void;
487
- }
628
+ export declare interface SubscriptionOption extends PurchaseOption {
629
+ /**
630
+ * The base phase for a SubscriptionOption, represents
631
+ * the price that the customer will be charged after all the discounts have
632
+ * been consumed and the period at which it will renew.
633
+ */
634
+ readonly base: PricingPhase;
635
+ /**
636
+ * The trial information for this subscription option if available.
637
+ */
638
+ readonly trial: PricingPhase | null;
639
+ }
488
640
 
489
- /**
490
- * Error class for Purchases SDK. You should handle these errors and react
491
- * accordingly in your app.
492
- * @public
493
- */
494
- export declare class PurchasesError extends Error {
495
- /**
496
- * Error code for the error. This is useful to appropriately react to
497
- * different error situations.
498
- */
499
- readonly errorCode: ErrorCode;
500
- /**
501
- * Underlying error message. This provides more details on the error and
502
- * can be useful for debugging and logging.
503
- */
504
- readonly underlyingErrorMessage?: string | null | undefined;
505
- constructor(
506
- /**
507
- * Error code for the error. This is useful to appropriately react to
508
- * different error situations.
509
- */
510
- errorCode: ErrorCode,
511
- /**
512
- * Message for the error. This is useful for debugging and logging.
513
- */
514
- message?: string,
515
- /**
516
- * Underlying error message. This provides more details on the error and
517
- * can be useful for debugging and logging.
518
- */
519
- underlyingErrorMessage?: string | null | undefined);
520
- toString: () => string;
521
- }
522
-
523
- /**
524
- * The store where the user originally subscribed.
525
- * @public
526
- */
527
- export declare type Store = "app_store" | "mac_app_store" | "play_store" | "amazon" | "stripe" | "rc_billing" | "promotional" | "unknown";
528
-
529
- /**
530
- * Error indicating that the SDK was accessed before it was initialized.
531
- * @public
532
- */
533
- export declare class UninitializedPurchasesError extends Error {
534
- constructor();
535
- }
641
+ /**
642
+ * Error indicating that the SDK was accessed before it was initialized.
643
+ * @public
644
+ */
645
+ export declare class UninitializedPurchasesError extends Error {
646
+ constructor();
647
+ }
536
648
 
537
- export { }
649
+ export { }