Skip to main content

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,
});
ParameterRequiredLocationTypeFormatDescription
appidYesparamsStringstring.min_len: 1Application ID
languageYesparamsStringstring.len: 2Language code; currently, Midasbuy supports ar,hk,tr,de,id,pu,tw,en,ja,ru,vn,es,ko,fr,my,th
regionYesparamsStringstring.len: 2Country code; refer to the [region select] for available options
sandboxNoparamsNumber0 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

ParameterRequiredLocationTypeFormatDescription
game_openidYesparamsStringstring.min_len: 1Game user ID
role_idYesparamsStringstring.min_len: 1Role ID
server_idYesparamsStringstring.min_len: 1Server ID
charac_nameYesparamsStringstring.min_len: 1Player nickname
balanceNoparamsStringNumber
thirdBalanceNoparamsStringNumber

3.2.1. Payment Success Callback Data

ParameterTypeDescription
order_idStringOrder number
product_idStringProduct ID

Success example:

{
"product_id": "1460000764_18_coins_midasbuy_us",
"order_id": "SG2410xxxxxx"
}

3.2.2. Payment Failure Callback Data

ParameterTypeDescription
nameEnumVarious failure reasons, e.g., parameter validation failure, user manually interrupted the SDK, program crash, etc.; cannot be empty
messageStringDescribes the error response; may be empty
detailsArrayProvides more detailed information, e.g., retry details, quota errors, channel errors; may be empty
linksArrayMay return documentation links for resolving the issue when a failure occurs; may be empty
debug_idStringIdentifier for the current request, representing a single request to Midas. Include this ID when reporting issues; may be empty
causesArraySolutions 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

ParameterDescription
INVALID_ARGUMENTParameter validation failed
USER_IS_DISTURBEDUser manually interrupted the SDK purchase flow
QUERY_SHELF_FAILEDFailed to request shelf items
QUERY_CHANNEL_FAILEDFailed to launch channel
PAYMENT_COMP_NOT_LOADEDPayment component load failed
ORDER_FAILEDOrder failed
PAYMENT_FAILEDPayment failed
UNKNOWN_CRASHSDK program crash

4. Calling Example

Demo page link: Midasbuy Trade SDK Demo