UNPKG

3.48 kBTypeScriptView Raw
1/**
2 * @name InAppPurchase
3 * @description
4 * A lightweight Cordova plugin for in app purchases on iOS/Android.
5 *
6 * @usage
7 * ```ts
8 * import {InAppPurchase} from 'ionic-native';
9 *
10 * InAppPurchase
11 * .getProducts(['com.yourapp.prod1', 'com.yourapp.prod2', ...])
12 * .then((products) => {
13 * console.log(products);
14 * // [{ productId: 'com.yourapp.prod1', 'title': '...', description: '...', price: '...' }, ...]
15 * })
16 * .catch((err) => {
17 * console.log(err);
18 * });
19 *
20 *
21 * InAppPurchase
22 * .buy('com.yourapp.prod1')
23 * .then((data)=> {
24 * console.log(data);
25 * // {
26 * // transactionId: ...
27 * // receipt: ...
28 * // signature: ...
29 * // }
30 * })
31 * .catch((err)=> {
32 * console.log(err);
33 * });
34 *
35 * ```
36 *
37 * @advanced
38 *
39 * ```ts
40 * // fist buy the product...
41 * InAppPurchase
42 * .buy('com.yourapp.consumable_prod1')
43 * .then(data => InAppPurchase.consume(data.productType, data.receipt, data.signature))
44 * .then(() => console.log('product was successfully consumed!'))
45 * .catch( err=> console.log(err))
46 * ```
47 *
48 *
49 */
50export declare class InAppPurchase {
51 /**
52 * Retrieves a list of full product data from Apple/Google. This method must be called before making purchases.
53 * @param {array<string>} productId an array of product ids.
54 * @returns {Promise<any>} Returns a Promise that resolves with an array of objects.
55 */
56 static getProducts(productId: string[]): Promise<any>;
57 /**
58 * Buy a product that matches the productId.
59 * @param {string} productId A string that matches the product you want to buy.
60 * @returns {Promise<{transactionId: string, receipt: string, signature: string, productType: string}>} Returns a Promise that resolves with the transaction details.
61 */
62 static buy(productId: string): Promise<{
63 transactionId: string;
64 receipt: string;
65 signature: string;
66 productType: string;
67 }>;
68 /**
69 * Same as buy, but for subscription based products.
70 * @param {string} productId A string that matches the product you want to subscribe to.
71 * @returns {Promise<{transactionId: string, receipt: string, signature: string, productType: string}>} Returns a Promise that resolves with the transaction details.
72 */
73 static subscribe(productId: string): Promise<{
74 transactionId: string;
75 receipt: string;
76 signature: string;
77 productType: string;
78 }>;
79 /**
80 * Call this function after purchasing a "consumable" product to mark it as consumed. On Android, you must consume products that you want to let the user purchase multiple times. If you will not consume the product after a purchase, the next time you will attempt to purchase it you will get the error message:
81 * @param {string} productType
82 * @param {string} receipt
83 * @param {string} signature
84 * @returns {Promise<any>}
85 */
86 static consume(productType: string, receipt: string, signature: string): Promise<any>;
87 /**
88 * Restore all purchases from the store
89 * @returns {Promise<any>} Returns a promise with an array of purchases.
90 */
91 static restorePurchases(): Promise<any>;
92 /**
93 * Get the receipt.
94 * @returns {Promise<string>} Returns a promise that contains the string for the receipt
95 */
96 static getReceipt(): Promise<string>;
97}