declare namespace midas {
interface MinigameAPI {
showMenu(options?: MenuShowOptions): Promise<ShowResult>;
hideMenu(options?: MenuHideOptions): void;
showPayment(options: PaymentShowOptions): Promise<PaymentResult>;
hidePayment(): void;
hideAll(): void;
login(options: LoginOptions): Promise<LoginResult>;
getLoginStatus(): boolean;
logout(): void;
getProductsData(params: ProductsParams): Promise<ProductsResult>;
on(event: string, callback: Function): void;
off(event: string, callback?: Function): void;
getModule(module: 'menu' | 'payment' | 'login'): any;
setErrorHandler(handler: (error: MinigameError) => void): void;
}
interface MenuShowOptions {
gradually?: boolean;
}
interface MenuHideOptions {
gradually?: boolean;
}
interface PaymentShowOptions {
params: PaymentParams;
extra?: PaymentExtra;
}
interface ShowResult {
res: string;
size?: {
width?: string;
height?: string;
};
}
interface LoginOptions {
success?: (result: LoginResult) => void;
fail?: (error: LoginError) => void;
}
interface LoginError {
code: number;
message: string;
error: string;
}
interface LoginResult {
code: number;
message: string;
data: {
jwtToken: string;
expiresIn: number;
refreshToken: string;
};
}
interface PaymentResult {
order_no: string;
openid: string;
order_no_hash: string;
}
interface PaymentError extends Error {
code: string;
type: 'failed' | 'hide' | 'queryChannelsFailed';
data?: any;
timestamp: number;
}
interface ProductsParams {
game_openid: string;
role_id: string;
server_id?: string;
}
interface ProductItem {
product_id: string;
game_product_id: string;
quantity: number;
product_type: 'currency' | 'item';
product_icon: string;
name: string;
price_info: {
price: string;
original_price: string;
currency: string;
display_price: string;
display_original_price: string;
};
bonus: {
virtual_currency_quantity: number;
virtual_item_list: {
product_id: string;
game_product_id: string;
name: string;
quantity: number;
icon: string;
}[];
};
meta: any;
}
interface ProductsResult {
products: ProductItem[];
}
function minigame(options: MinigameOptions): MinigameAPI;
}