Midasbuy Minigame SDK API Protocol
1. Overview
Midasbuy Minigame SDK is a unified mini-game SDK loader and adapter that provides consistent API interfaces for Menu, Payment, and Login function modules.
2. SDK Integration
<script src="https://cdn.midasbuy.com/js/minigame.stable.js"></script>
3. API Protocol
3.1 Initialization midas.minigame(options)
const minigameApi = midas.minigame({
// Basic Configuration
appid: '1460000904',
region: 'us',
language: 'en',
sandbox: 1,
shopcode: 'xxxinapp',
// Menu Module Configuration, optional
menu: {
isWithPcHeader: true,
isLandscapeMode: false // Portrait mode (navigation bar), default
},
// Payment Module Configuration, optional
payment: {
openid: '1018553529511732', // optional, to reduce bad debt rate
charac_name: 'Player1', // optional, to reduce bad debt rate
},
// Login Module Configuration, optional
login: {
debug: true,
timeout: 30000
}
});
Parameter Description
| Parameter | Type | Required | Description |
|---|---|---|---|
| appid | string | Yes | Application ID |
| region | string | Yes | Region code, 2 characters |
| language | string | No | Language code, default 'en' |
| sandbox | number | No | Environment: 0-production, 1-sandbox, 2-test, default 0 |
| shopcode | string | No | Shop code |
| menu | MenuConfig | No | Menu module configuration |
| payment | PaymentConfig | No | Payment module configuration |
| login | LoginConfig | No | Login module configuration |
MenuConfig Type
interface MenuConfig {
isWithPcHeader?: boolean; // Whether to include top header on PC
isLandscapeMode?: boolean; // Enable landscape mode (bubble style menu), default false
}
PaymentConfig Type
interface PaymentConfig {
openid?: string; // User openid
charac_name?: string; // Character name
}
LoginConfig Type
interface LoginConfig {
debug?: boolean; // Debug mode
timeout?: number; // Request timeout (milliseconds)
}
3.2 Menu Functions
The menu module supports two display modes:
- Portrait Mode (Navigation Bar): Traditional top navigation bar style, suitable for mobile portrait orientation
- Landscape Mode (Bubble Menu): Floating bubble style menu, suitable for mobile landscape orientation
3.2.1 Show Menu minigameApi.showMenu(options)
Portrait Mode Example (Navigation Bar):
// Initialize with portrait mode
const minigameApi = midas.minigame({
appid: '1460000904',
region: 'us',
menu: {
isLandscapeMode: false // Portrait mode (default)
}
});
// Show portrait menu
minigameApi.showMenu({
gradually: true
});
Landscape Mode Example (Bubble Menu):
// Initialize with landscape mode
const minigameApi = midas.minigame({
appid: '1460000904',
region: 'us',
menu: {
isLandscapeMode: true // Landscape mode (bubble style)
}
});
// Show landscape menu
minigameApi.showMenu({
gradually: true
});
Parameter Description
| Parameter | Type | Required | Description |
|---|---|---|---|
| gradually | boolean | No | Whether to show progressively, default true |
3.2.2 Hide Menu minigameApi.hideMenu(options)
// Hide game menu (works for both portrait and landscape modes)
minigameApi.hideMenu({
gradually: true
});
Parameter Description
| Parameter | Type | Required | Description |
|---|---|---|---|
| gradually | boolean | No | Whether to hide progressively, default true |
3.3 Payment Functions
3.3.1 Show Payment Page minigameApi.showPayment(options)
Event-based Style (Legacy):
// Show payment page with event listeners
minigameApi.on('payment:success', (data) => {
console.log('Payment successful:', data);
});
minigameApi.on('payment:failed', (error) => {
console.log('Payment failed:', error);
});
minigameApi.showPayment({
params: {
game_openid: '1018553529511732',
role_id: '1555629938',
product_id: 'coins_01-midasbuy'
},
extra: {
hideResultPage: true
}
});
Promise Style (Recommended):
// Show payment page with Promise
minigameApi.showPayment({
params: {
game_openid: '1018553529511732',
role_id: '1555629938',
product_id: 'coins_01-midasbuy',
server_id: 'server_001'
},
extra: {
hideResultPage: true
}
})
.then(data => {
console.log('Payment successful:', data);
// data contains: { order_no, openid, order_no_hash }
})
.catch(error => {
console.log('Payment error:', error);
// Handle different error types
switch(error.type) {
case 'failed':
console.log('Payment failed:', error.data);
break;
case 'hide':
console.log('Payment dialog was closed');
break;
case 'queryChannelsFailed':
console.log('Failed to load payment channels:', error.data);
break;
}
});
// Using async/await
async function handlePayment() {
try {
const result = await minigameApi.showPayment({
params: {
game_openid: '1018553529511732',
role_id: '1555629938',
product_id: 'coins_01-midasbuy',
server_id: 'server_001'
}
});
console.log('Payment successful:', result);
} catch (error) {
console.log('Payment failed:', error.type, error.message);
}
}
Parameter Description
| Parameter | Type | Required | Description |
|---|---|---|---|
| params | PaymentParams | Yes | Payment parameters |
| extra | PaymentExtra | No | Additional payment parameters |
PaymentParams Type
interface PaymentParams {
game_openid: string; // Game user ID
role_id: string; // Role ID
product_id: string; // Product ID
server_id?: string; // Server ID for game partitioning
is_vip_product?: boolean; // Whether it's a VIP product
}
PaymentExtra Type
interface PaymentExtra {
hideResultPage?: boolean; // Whether to hide result page
}
PaymentError Type
interface PaymentError extends Error {
code: string; // Error code
type: 'failed' | 'hide' | 'queryChannelsFailed'; // Error type
data?: any; // Additional error data
timestamp: number; // Error timestamp
}