Skip to content

Commit

Permalink
Merge pull request #40 from dooboolab/dev
Browse files Browse the repository at this point in the history
From dev, improve typings, with JSDoc
  • Loading branch information
hyochan authored Feb 26, 2018
2 parents ab0d90b + 70c23b4 commit 5c91392
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 8 deletions.
88 changes: 80 additions & 8 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<ItemDescription[]>} Promise of the array of purchasable items
*/
export function getItems(skus: Skus) : Promise<ItemDescription[]>;

/**
* Get subscription items.
* @param {Skus} skus
* @returns {Promise<ItemDescription[]>} Promise of the array of subscription items
*/
export function getSubscribeItems(skus: Skus) : Promise<ItemDescription[]>;

/**
* Purchase item.
* @param {string} item
* @returns {Promise<string>} Promise of the ...
*/
export function buyItem(item: string) : Promise<string>;

/**
* Buy subscription item.
* @param {string} item
* @returns {Promise<any>} Promise of the ...
*/
export function buySubscribeItem(item: string) : Promise<any>;

/**
* Refresh all items to make them available to buy again.
* @returns {Promise<any>} Promise of the refreshed items.
*/
export function refreshAllItems() : Promise<any>;

export function prepareAndroid() : Promise<string> | void;
export function refreshPurchaseItemsAndroid(type: string | null) : void;
export function getPurchasedItemsAndroid(type: string | null) : Promise<any> | void;
export function consumeItemAndroid(token: string) : Promise<string> | void;
/**
* Prepare IAP module for android. Should be called in android before using any methods in RNIap.
* @returns {Promise<string>|null} Promise of the messages, or null if the Platform is not Android.
*/
export function prepareAndroid() : Promise<string> | 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<any>|null} Promise of the purchased items, or null if the Platform is not Android.
*/
export function getPurchasedItemsAndroid(type?: SkuTypeAndroid) : Promise<any> | 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<boolean> | null;

/**
* TODO: Add description here.
* @returns {Promise<Object>|null} Promise of somthing, or null if the Platform is not iOS
*/
export function restoreIosNonConsumableProducts() : Promise<Object> | null;
6 changes: 6 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,8 @@ export const prepareAndroid = () => {
resolve(msg);
});
});
} else {
return null;
}
};

Expand Down Expand Up @@ -209,6 +211,8 @@ export const getPurchasedItemsAndroid = (type: string | null) => {
}
);
});
} else {
return null;
}
};

Expand All @@ -226,6 +230,8 @@ export const consumeItemAndroid = (token: string) => {
resolve(success);
});
});
} else {
return null;
}
};

Expand Down

0 comments on commit 5c91392

Please sign in to comment.