Skip to main content

Midasbuy Payment SDK

1. SDK Description

To launch the available payment channels for items on Midasbuy based on the player's "person" and "item" information.

2. Integrating the SDK

Include the script in your HTML file:

<script src="https://cdn.midasbuy.com/no-sw-common-sdk/static/js/commonSdkApi.js"></script>

3. API Documentation

3.1. Initialize

Initialize the pay instance:

const { pay } = window.midasbuyCommonSdk;
pay?.preload({
appid: "1460000904",
region: "id",
buysdk_mode: 1,
// sdkUrl: 'https://sandbox.midasbuy.com/payment-sdk', // Sandbox
sdkUrl: 'https://www.midasbuy.com/payment-sdk',
openid: "1018553529511732",
charac_name: 'xxx',
shopcode: 'xxx',
forceReportRootTag: '1'
});
ParameterRequiredLocationTypeFormatDescription
appidYesparamsStringstring.min_len: 1Application ID
regionYesparamsStringstring.len: 2region code; refer to the [region select] for available options
buysdk_modeYesparamsNumberFixed to 1.
sdkUrlYesparamsNumberUsed to differentiate between sandbox and production environments.
openidYesparamsStringGame user ID
charac_nameYesparamsStringUser nickname
shopcodeYesparamsStringShop code
forceReportRootTagYesparamsStringReporting mode switch

3.2. Trigger channel payment and event callback.

Trigger channel payment popup:

const reqParams = {
params: {
app_id: "1460000904",
game_openid: "1018553529511732",
role_id: "1555629938",
product_id: "coins_01-midasbuy",
region: "id",
shop_code: 'xxx',
},
extra: {
hideResultPage: true
},
};
pay?.emit('checkout', reqParams);

Parameter

ParameterRequiredLocationTypeFormatDescription
game_openidYesparamsStringstring.min_len: 1Game user ID
role_idYesparamsStringstring.min_len: 1Role ID
product_idYesparamsStringstring.min_len: 1Product ID
regionYesparamsStringstring.min_len: 1Region, language affecting item information.
shop_codeYesparamsStringstring.min_len: 1Shop code
server_idNoparamsStringstring.min_len: 1Server id

extra param

ParameterRequiredLocationTypeFormatDescription
hideResultPageNOextraStringstring.min_len: 1hide result page

3.2.1. Payment success callback

Successful example:

pay.on('paymentSuccess', (data) => {
console.log('data', data);
console.log(`payment success: ${JSON.stringify(data)}`);

Data instance:

{
"order_no":"SG250225BHGE8KPUZKXDFE",
"openid":"34131737143805224",
"order_no_hash":"ca171bec7737d557d54f15706404bddc129bd2f09749f76b5dfae055a44b11e9"
}
ParameterDescription
order_noOrder NO
openidGame user ID
order_no_hashOrder NO HASH

3.2.2. Other event enumerations

参数说明
hideHide payment popup
queryChannelsFailedFailed to initialize payment popup, usually due to item query failure or channel query failure.
paymentFailedSuccessful initialization of payment popup, but the user was not successful in subsequent payment.

4. Sandbox demo

<html>
<head>
<title>Payment SDK Demo</title>
<script src="https://cdn.midasbuy.com/no-sw-common-sdk/static/js/commonSdkApi.js"></script>
</head>
<body>
<button onclick="clickToPay()">Pay</button>
<script>
const { pay } = window.midasbuyCommonSdk;
pay?.preload({
appid: "1460000904",
region: "id",
buysdk_mode: 1,
// sdkUrl: 'https://sandbox.midasbuy.com/payment-sdk', // Sandbox
sdkUrl: 'https://www.midasbuy.com/payment-sdk',
openid: "1018553529511732",
charac_name: 'xxx', // User nickname
shopcode: 'xxx', // Fixed value
forceReportRootTag: '1' // Fixed value
});

try {
pay?.on('loaded', () => {
console.log('PaySDK loaded');
this.channelWraperLoaded = true;
});
} catch (error) {
console.log('Error:', error);
throw error;
}

function clickToPay() {
console.log('Loading payment channels...');
pay?.off('hide');
pay?.off('queryChannelsFailed');
pay?.off('paymentSuccess');
pay?.off('paymentFailed');
pay?.off('handlerPlayerId');
pay?.off('drawerFilterPop');

pay?.on('hide', () => {
pay.emit('hide');
}).on('queryChannelsFailed', (msg) => {
console.log(`Channel query failed: ${JSON.stringify(msg)}`);
})?.on('paymentSuccess', (data) => {
console.log('Payment data:', data);
pay.emit('hide');
console.log(`Payment succeeded: ${JSON.stringify(data)}`);
alert(`Payment succeeded: ${JSON.stringify(data)}`);
})?.on('paymentFailed', (error) => {
console.log('Error:', error);
console.log(`Payment failed: ${JSON.stringify(error)}`);
})?.on('show', () => {
pay.emit('show');
});

const reqParams = {
params: {
app_id: "1460000904",
game_openid: "1018553529511732",
role_id: "1555629938",
product_id: "coins_01-midasbuy",
region: "id",
shop_code: 'ludoinapp', // Fixed value
},
extra: {
hideResultPage: true
},
};
pay?.emit('checkout', reqParams);
pay?.emit('show');
}
</script>
</body>
</html>