Midasbuy Trade SDK
1. SDK Description
Launch the Midasbuy item list and trading mall by passing player information.
2. Integrating the SDK
Include the script in your HTML file:
<script src="https://cdn.midasbuy.com/js/trade.stable.js"></script>
3. API Documentation
3.1. midas.trade(options)
Create an instance of tradeApi:
const tradeApi = midas.trade({
appid: '1460000764',
language: 'en',
region: 'us',
sandbox: 1,
});
Parameter | Required | Location | Type | Format | Description |
---|---|---|---|---|---|
appid | Yes | params | String | string.min_len: 1 | Application ID |
language | Yes | params | String | string.len: 2 | Language code; currently, Midasbuy supports ar,hk,tr,de,id,pu,tw,en,ja,ru,vn,es,ko,fr,my,th |
region | Yes | params | String | string.len: 2 | Country code; refer to the [region select] for available options |
sandbox | No | params | Number | 0 for production, 1 for sandbox. Default is 0, use 1 for debugging |
3.2. tradeApi.show(playerInfo).then(paymentSuccessCallback).catch(failCallback)
Display the item list popup and handle success and failure callbacks:
tradeApi.show({
game_openid: '1321xxx',
role_id: '186xxx',
server_id: '319',
charac_name: 'test name',
})
.then((data) => {
// Payment success callback
})
.catch((err) => {
// Payment failure callback; various failure reasons, see error codes below
});
Player Information Parameters
Parameter | Required | Location | Type | Format | Description |
---|---|---|---|---|---|
game_openid | Yes | params | String | string.min_len: 1 | Game user ID |
role_id | Yes | params | String | string.min_len: 1 | Role ID |
server_id | Yes | params | String | string.min_len: 1 | Server ID |
charac_name | Yes | params | String | string.min_len: 1 | Player nickname |
balance | No | params | String | Number | |
thirdBalance | No | params | String | Number |
3.2.1. Payment Success Callback Data
Parameter | Type | Description |
---|---|---|
order_id | String | Order number |
product_id | String | Product ID |
Success example:
{
"product_id": "1460000764_18_coins_midasbuy_us",
"order_id": "SG2410xxxxxx"
}
3.2.2. Payment Failure Callback Data
Parameter | Type | Description |
---|---|---|
name | Enum | Various failure reasons, e.g., parameter validation failure, user manually interrupted the SDK, program crash, etc.; cannot be empty |
message | String | Describes the error response; may be empty |
details | Array | Provides more detailed information, e.g., retry details, quota errors, channel errors; may be empty |
links | Array | May return documentation links for resolving the issue when a failure occurs; may be empty |
debug_id | String | Identifier for the current request, representing a single request to Midas. Include this ID when reporting issues; may be empty |
causes | Array | Solutions for the exception; may be empty |
Failure example:
{
"name": "INVALID_ARGUMENT",
"message": "invalid CreateOrderRequest.ApplicationContext: embedded message failed validation | caused by: invalid ApplicationContext.RegionCode: value does not match regex pattern \"^[A-Z]{2}$\"",
"details": [
{
"@type": "type.apis.com/rpc.BadRequest.FieldViolation",
"field": "ApplicationContext",
"description": "embedded message failed validation",
"value": ""
}
],
"links": [],
"debug_id": "247df6a6ed3ab364",
"causes": []
}
3.2.3. Name Error Code Enumeration
Parameter | Description |
---|---|
INVALID_ARGUMENT | Parameter validation failed |
USER_IS_DISTURBED | User manually interrupted the SDK purchase flow |
QUERY_SHELF_FAILED | Failed to request shelf items |
QUERY_CHANNEL_FAILED | Failed to launch channel |
PAYMENT_COMP_NOT_LOADED | Payment component load failed |
ORDER_FAILED | Order failed |
PAYMENT_FAILED | Payment failed |
UNKNOWN_CRASH | SDK program crash |
4. Calling Example
Demo page link: Midasbuy Trade SDK Demo