diff --git a/index.d.ts b/index.d.ts index 962d16a5c..996d000e1 100644 --- a/index.d.ts +++ b/index.d.ts @@ -3,23 +3,95 @@ export interface Skus { android: string[]; } -export interface ItemDescription { - type?: string; // only on Android +export type ItemDescription = ItemDescriptionAndroid | ItemDescriptionIos + +export type SkuTypeAndroid = 'INAPP' | 'SUBS' + +export interface ItemDescriptionAndroid { + type: SkuTypeAndroid; + productId: string; + title: string; + description: string; + price: string; + currency: string; + price_currency: string; + localizedPrice: string; +} + +export interface ItemDescriptionIos { productId: string; title: string; description: string; - price: number | string; // number on iOS, string on Android + price: number; currency: string; - localizedPrice: string; // only on Android } +/** + * Get purchasable items in array. + * @param {Skus} skus + * @returns {Promise} Promise of the array of purchasable items + */ export function getItems(skus: Skus) : Promise; + +/** + * Get subscription items. + * @param {Skus} skus + * @returns {Promise} Promise of the array of subscription items + */ export function getSubscribeItems(skus: Skus) : Promise; + +/** + * Purchase item. + * @param {string} item + * @returns {Promise} Promise of the ... + */ export function buyItem(item: string) : Promise; + +/** + * Buy subscription item. + * @param {string} item + * @returns {Promise} Promise of the ... + */ export function buySubscribeItem(item: string) : Promise; + +/** + * Refresh all items to make them available to buy again. + * @returns {Promise} Promise of the refreshed items. +*/ export function refreshAllItems() : Promise; -export function prepareAndroid() : Promise | void; -export function refreshPurchaseItemsAndroid(type: string | null) : void; -export function getPurchasedItemsAndroid(type: string | null) : Promise | void; -export function consumeItemAndroid(token: string) : Promise | void; \ No newline at end of file +/** + * Prepare IAP module for android. Should be called in android before using any methods in RNIap. + * @returns {Promise|null} Promise of the messages, or null if the Platform is not Android. + */ +export function prepareAndroid() : Promise | null; + +/** + * Refresh purchased items for android. + * What is different from refreshAllItems is that this method can get parameter to refresh INAPP items or SUBS items. + * @param {SkuTypeAndroid} [type] `'INAPP'` or `'SUBS'` + */ +export function refreshPurchaseItemsAndroid(type?: SkuTypeAndroid) : void; + +/** + * Get purchased items for android. + * This method also gets parameter to refresh INAPP items or SUBS items. + * @param {SkuTypeAndroid} [type] `'INAPP'` or `'SUBS'` + * @returns {Promise|null} Promise of the purchased items, or null if the Platform is not Android. + */ +export function getPurchasedItemsAndroid(type?: SkuTypeAndroid) : Promise | null; + +/** + * Consume item for android. + * After buying some item from consumable item in android, you can use this method to consume it. + * Therefore you can purchase the item again. + * @param {string} token + * @returns {boolean|null} Promise of the status of billing response, or null if the Platform is not Android. + */ +export function consumeItemAndroid(token: string) : Promise | null; + +/** + * TODO: Add description here. + * @returns {Promise|null} Promise of somthing, or null if the Platform is not iOS + */ +export function restoreIosNonConsumableProducts() : Promise | null; diff --git a/index.js b/index.js index 161282aee..79934e5e0 100644 --- a/index.js +++ b/index.js @@ -178,6 +178,8 @@ export const prepareAndroid = () => { resolve(msg); }); }); + } else { + return null; } }; @@ -209,6 +211,8 @@ export const getPurchasedItemsAndroid = (type: string | null) => { } ); }); + } else { + return null; } }; @@ -226,6 +230,8 @@ export const consumeItemAndroid = (token: string) => { resolve(success); }); }); + } else { + return null; } };