mirror of
https://github.com/streetwriters/notesnook.git
synced 2025-12-23 23:19:40 +01:00
core: add endpoints for getting all products for new plans
This commit is contained in:
@@ -17,26 +17,59 @@ You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import { SubscriptionPlan, SubscriptionPlanId } from "../types.js";
|
||||
import http from "../utils/http.js";
|
||||
|
||||
export type Product = {
|
||||
export type SKUResponse = {
|
||||
country: string;
|
||||
countryCode: string;
|
||||
sku?: string;
|
||||
price?: string;
|
||||
discount: number;
|
||||
};
|
||||
|
||||
const BASE_URL = `https://notesnook.com/api/v1/prices`;
|
||||
export interface PlanPrice {
|
||||
gross: number;
|
||||
net: number;
|
||||
tax: number;
|
||||
currency?: string;
|
||||
}
|
||||
|
||||
export type Period = "monthly" | "yearly" | "5-year";
|
||||
|
||||
export type Discount = {
|
||||
type: "regional" | "promo";
|
||||
code?: string;
|
||||
recurring: boolean;
|
||||
amount: number;
|
||||
};
|
||||
|
||||
export interface Plan {
|
||||
plan: SubscriptionPlan;
|
||||
recurring: boolean;
|
||||
id: string;
|
||||
name?: string;
|
||||
period: Period;
|
||||
price: PlanPrice;
|
||||
currency: string;
|
||||
currencySymbol?: string;
|
||||
originalPrice?: PlanPrice;
|
||||
discount?: Discount;
|
||||
country: string;
|
||||
}
|
||||
|
||||
const BASE_URL = `https://notesnook.com/api/v2/prices`;
|
||||
export class Pricing {
|
||||
static sku(
|
||||
platform: "android" | "ios" | "web",
|
||||
period: "monthly" | "yearly"
|
||||
): Promise<Product> {
|
||||
return http.get(`${BASE_URL}/skus/${platform}/${period}`);
|
||||
period: Period,
|
||||
plan: SubscriptionPlanId
|
||||
): Promise<SKUResponse> {
|
||||
return http.get(
|
||||
`${BASE_URL}/skus?platform=${platform}&period=${period}&plan=${plan}`
|
||||
);
|
||||
}
|
||||
|
||||
static price(period: "monthly" | "yearly" = "monthly"): Promise<Product> {
|
||||
return http.get(`${BASE_URL}/${period}`);
|
||||
static products(): Promise<Plan[]> {
|
||||
return http.get(`${BASE_URL}/products`);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user