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'
});
Parameter | Required | Location | Type | Format | Description |
---|---|---|---|---|---|
appid | Yes | params | String | string.min_len: 1 | Application ID |
region | Yes | params | String | string.len: 2 | region code; refer to the [region select] for available options |
buysdk_mode | Yes | params | Number | Fixed to 1. | |
sdkUrl | Yes | params | Number | Used to differentiate between sandbox and production environments. | |
openid | Yes | params | String | Game user ID | |
charac_name | Yes | params | String | User nickname | |
shopcode | Yes | params | String | Shop code | |
forceReportRootTag | Yes | params | String | Reporting 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
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 |
product_id | Yes | params | String | string.min_len: 1 | Product ID |
region | Yes | params | String | string.min_len: 1 | Region, language affecting item information. |
shop_code | Yes | params | String | string.min_len: 1 | Shop code |
server_id | No | params | String | string.min_len: 1 | Server id |
extra param
Parameter | Required | Location | Type | Format | Description |
---|---|---|---|---|---|
hideResultPage | NO | extra | String | string.min_len: 1 | hide 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"
}
Parameter | Description |
---|---|
order_no | Order NO |
openid | Game user ID |
order_no_hash | Order NO HASH |
3.2.2. Other event enumerations
参数 | 说明 |
---|---|
hide | Hide payment popup |
queryChannelsFailed | Failed to initialize payment popup, usually due to item query failure or channel query failure. |
paymentFailed | Successful 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>