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: "1450015065",
region: "hk",
buysdk_mode: 1,
sdkUrl: 'https://sandbox.midasbuy.com/payment-sdk'
});
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.

3.2. Trigger channel payment and event callback.

Trigger channel payment popup:

const reqParams = {
params: {
app_id: '1460000764',
game_openid: '123456789',
role_id: '123',
product_id: 'productId',
region: 'HK'
},
extra: {},
} as any;
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.

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: "1450015065",
region: "hk",
buysdk_mode: 1,
sdkUrl: 'https://sandbox.midasbuy.com/payment-sdk'
});
try {
pay?.on('loaded', () => {
console.log('PaySDK has been 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(`Failed to query channels: ${JSON.stringify(msg)}`);
})?.on('paymentSuccess', (data) => {
console.log('data', data);
console.log(`Payment successful: ${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: "1450015065",
game_openid: "34131737143805224",
role_id: "5557607661",
product_id: "60_coins_vip",
region: "hk",
is_vip_product: true,
},
extra: {},
};
pay?.emit('checkout', reqParams);
pay?.emit('show');
}
</script>
</body>

</html>