Service / PurchaseService
PurchaseService Class
In app purchase service
Table of contents
Accessors
onOrderDelivered(): MulticastDelegate <OnOrderDelivered > other |
---|
Get the delegate of order shipment |
onPremiumMemberOrderDelivered(): MulticastDelegate <OnKeyConsume > other |
Get the delegate of order shipment |
onPremiumMemberStatusUpdate(): MulticastDelegate <(result : boolean ) => void > other |
Delegate triggered when obtaining update of large member status |
Methods
consumeKey(boxId : string , number : number , keyType : number , placeOrderResult : (status : consumeKeyStatus ) => void ): void other |
---|
Big members open treasure chests and consume gold keys |
findKeyUsageHistory(currentPage : number , pageSize : number , historyResult : (total : number , currentPage : number , bill : keyUsageInfo []) => void ): void other |
Page by page query of key usage history of major members |
getUserKeyNumber([getUserKeyNumber](mw.PurchaseService.md#getuserkeynumber)Result , keyType? : number ): void other |
Obtain the remaining number of keys for the user |
isPremiumMember([isPremiumMember](mw.PurchaseService.md#ispremiummember)Result ): void other |
Determine whether the user is a major member |
isPremiumMemberSupported(isSupportedResult : (result : boolean ) => void ): void other |
Obtain whether the software version used by the user has a major membership function |
openPremiumMemberPurchasePage(): void other |
Jump to the member recharge page |
placeOrder(commodityId : string , amount : number , [placeOrder](mw.PurchaseService.md#placeorder)Result ): void other |
Order a specified quantity of specified products |
redeemGiftCode(player : Player , GiftCode : string , redeemCallback : (result : RedeemResponse ) => void ): void other |
Gift Code Redemption |
Accessors
onOrderDelivered
• | ||
---|---|---|
Get the delegate of order shipment Precautions Only valid on the server side. The stand-alone mode is not considered yet, so use it carefully Returns
|
onPremiumMemberOrderDelivered
• | ||
---|---|---|
Get the delegate of order shipment Precautions Only valid on the server side. The stand-alone mode is not considered yet, so use it carefully Returns
|
onPremiumMemberStatusUpdate
• |
---|
Delegate triggered when obtaining update of large member status Returns |
MulticastDelegate <(result : boolean ) => void > | Delegate triggered when large member status is update |
---|
Methods
consumeKey
• Static
consumeKey(boxId
, number
, keyType
, placeOrderResult
): void
other
Big members open treasure chests and consume gold keys
Parameters
boxId string | Usage: Treasure Box ID, representing a benefit, temporarily customized ID. We will configure the range on the developer platform in the future: based on the boxId length |
---|---|
number number | Usage: Number of treasure chests collected default: 1 range: No limit type: Integer |
keyType number | Usage: Key type, currently there is only one key type with a value of 1 default: 1 range: 1 type: integer |
placeOrderResult (status : consumeKeyStatus ) => void | Usage: Order result. Status: VIP member deduction key order status |
Usage example: you need to monitor the shipment information on the server first, and when you deduct the key, you will judge whether the server monitors
if (SystemUtil.isServer()) {
Console.log ("Monitor shipment");
//Shipment monitoring
mw.PurchaseService.onPremiumMemberOrderDelivered.add((
playerController: mw.Player,
orderId: string,
boxId: string,
amount: number,
confirmOrder: (bReceived: boolean) => void
) => {
mw.Event.dispatchToClient(playerController, orderId, boxId, amount);
//Confirm receipt of goods
confirmOrder(true);
});
}
// Deducting keys
mw.PurchaseService.consumeKey("1000", 1, 1, (status : mw.consumeKeyStatus) => {
console.log("consumeKey status : " + status);
if (status == mw.consumeKeyStatus.Success) {
Console.log ("Order placed successfully");
} else if (status == mw.consumeKeyStatus.PremiumMemberNotSupported) {
Console.log ("No support for large members");
} else if (status == mw.consumeKeyStatus.NotPremiumMember) {
Console.log ("not a major member");
} else if (status == mw.consumeKeyStatus.InsufficientKeys) {
Console.log ("insufficient keys");
} else if (status == mw.consumeKeyStatus.Error) {
Console.log ("Deduction failed");
}
});
if (SystemUtil.isServer()) {
Console.log ("Monitor shipment");
//Shipment monitoring
mw.PurchaseService.onPremiumMemberOrderDelivered.add((
playerController: mw.Player,
orderId: string,
boxId: string,
amount: number,
confirmOrder: (bReceived: boolean) => void
) => {
mw.Event.dispatchToClient(playerController, orderId, boxId, amount);
//Confirm receipt of goods
confirmOrder(true);
});
}
// Deducting keys
mw.PurchaseService.consumeKey("1000", 1, 1, (status : mw.consumeKeyStatus) => {
console.log("consumeKey status : " + status);
if (status == mw.consumeKeyStatus.Success) {
Console.log ("Order placed successfully");
} else if (status == mw.consumeKeyStatus.PremiumMemberNotSupported) {
Console.log ("No support for large members");
} else if (status == mw.consumeKeyStatus.NotPremiumMember) {
Console.log ("not a major member");
} else if (status == mw.consumeKeyStatus.InsufficientKeys) {
Console.log ("insufficient keys");
} else if (status == mw.consumeKeyStatus.Error) {
Console.log ("Deduction failed");
}
});
findKeyUsageHistory
• Static
findKeyUsageHistory(currentPage
, pageSize
, historyResult
): void
other
Page by page query of key usage history of major members
Parameters
currentPage number | Usage: Find page type: integer range: (1,65535) |
---|---|
pageSize number | Usage: Page size Type: Integer Range: (1,100) |
historyResult (total : number , currentPage : number , bill : keyUsageInfo []) => void | Usage: Query result callback function |
Usage example: Simply insert the code snippet into the script
mw.PurchaseService.findKeyUsageHistory(1, 100, (total : number, currentPage : number, bills : mw.keyUsageInfo[]) => {
console.log("bill len : " + bills.length);
for(let bill of bills)
{
console.log("bill orderId : " + bill.orderId);
console.log("bill boxId : " + bill.boxId);
console.log("bill number : " + bill.number);
console.log("bill consumeTime : " + bill.consumeTime);
}
});
mw.PurchaseService.findKeyUsageHistory(1, 100, (total : number, currentPage : number, bills : mw.keyUsageInfo[]) => {
console.log("bill len : " + bills.length);
for(let bill of bills)
{
console.log("bill orderId : " + bill.orderId);
console.log("bill boxId : " + bill.boxId);
console.log("bill number : " + bill.number);
console.log("bill consumeTime : " + bill.consumeTime);
}
});
getUserKeyNumber
• Static
getUserKeyNumber(getUserKeyNumberResult
, keyType?
): void
other
Obtain the remaining number of keys for the user
Parameters
getUserKeyNumberResult (keyNumber : number ) => void | Usage: Result callback, execute callback function after querying the result. KeyNumber: Remaining number of keys |
---|---|
keyType? number | Usage: The key type being searched is currently only type 1 default: 1 range: 1 type: integer |
Example usage: Create a script called PurchaseExample, place it in the object bar, open the script, modify the original content to the following, publish the game for mobile testing, and you can see the remaining number of keys for the current user
@Component
export default class PurchaseExample extends mw.Script {
protected onStart(): void {
if (!SystemUtil.isClient()) return;
this.test();
}
private async test(): Promise<void> {
let player = Player.localPlayer;
PurchaseService.getUserKeyNumber(keyNumber => {
player.character.displayName = Current user's remaining key quantity: ", keyNumber. toString();
})
}
}
@Component
export default class PurchaseExample extends mw.Script {
protected onStart(): void {
if (!SystemUtil.isClient()) return;
this.test();
}
private async test(): Promise<void> {
let player = Player.localPlayer;
PurchaseService.getUserKeyNumber(keyNumber => {
player.character.displayName = Current user's remaining key quantity: ", keyNumber. toString();
})
}
}
isPremiumMember
• Static
isPremiumMember(isPremiumMemberResult
): void
other
Determine whether the user is a major member
Parameters
isPremiumMemberResult (result : boolean ) => void | Usage: Result callback, execute callback function after querying the result. True: is a major member, false: is not a major member |
---|
Precautions
We have not yet considered the standalone mode. The first result will be returned through asynchronous callbacks (automatically requested during construction), and subsequent callback functions will be executed directly through cache (synchronous),
Usage example: create a script named PurchaseExample, place it in the object bar, open the script, modify the original content to the following content, and test the publish game on the mobile terminal to see whether the current user is a large member
@Component
export default class PurchaseExample extends mw.Script {
protected onStart(): void {
if (!SystemUtil.isClient()) return;
this.test();
}
private async test(): Promise<void> {
let player = Player.localPlayer;
PurchaseService.isPremiumMember(isSupport => {
player.character.displayName = isSupport ? "The current Player is a large member": "The current Player is not a large member";
})
}
}
@Component
export default class PurchaseExample extends mw.Script {
protected onStart(): void {
if (!SystemUtil.isClient()) return;
this.test();
}
private async test(): Promise<void> {
let player = Player.localPlayer;
PurchaseService.isPremiumMember(isSupport => {
player.character.displayName = isSupport ? "The current Player is a large member": "The current Player is not a large member";
})
}
}
isPremiumMemberSupported
• Static
isPremiumMemberSupported(isSupportedResult
): void
other
Obtain whether the software version used by the user has a major membership function
Parameters
isSupportedResult (result : boolean ) => void | Usage: Result callback, execute callback function after querying the result. True: support large member function, false: do not support large member function |
---|
Precautions
At present, the standalone mode has not been considered. The first result will be returned through asynchronous callback (automatically requested during construction), and subsequent callback functions will be executed directly through cache (synchronous). The old version of app may experience no callback, and it is necessary to determine the timeout on your own
Example usage: Create a script called PurchaseExample, place it in the object bar, open the script, modify the original content to the following, publish the game for mobile testing, and you can see if the current app supports the large membership function
@Component
export default class PurchaseExample extends mw.Script {
protected onStart(): void {
if (!SystemUtil.isClient()) return;
this.test();
}
private async test(): Promise<void> {
let player = Player.localPlayer;
PurchaseService.isPremiumMemberSupported(isSupport => {
player.character.displayName = isSupport ? "The current app support large member function": "The current app does not support large member function";
})
}
}
@Component
export default class PurchaseExample extends mw.Script {
protected onStart(): void {
if (!SystemUtil.isClient()) return;
this.test();
}
private async test(): Promise<void> {
let player = Player.localPlayer;
PurchaseService.isPremiumMemberSupported(isSupport => {
player.character.displayName = isSupport ? "The current app support large member function": "The current app does not support large member function";
})
}
}
openPremiumMemberPurchasePage
• Static
openPremiumMemberPurchasePage(): void
other
Jump to the member recharge page
Usage example: create a script named PurchaseExample, place it in the object bar, open the script, modify the original content to the following content, test the publish game on the mobile terminal, and automatically open the member recharge page 10 seconds later.
@Component
export default class PurchaseExample extends mw.Script {
protected onStart(): void {
if (!SystemUtil.isClient()) return;
this.test();
}
private async test(): Promise<void> {
await TimeUtil.delaySecond(10);
PurchaseService.openPremiumMemberPurchasePage();
}
}
@Component
export default class PurchaseExample extends mw.Script {
protected onStart(): void {
if (!SystemUtil.isClient()) return;
this.test();
}
private async test(): Promise<void> {
await TimeUtil.delaySecond(10);
PurchaseService.openPremiumMemberPurchasePage();
}
}
placeOrder
• Static
placeOrder(commodityId
, amount
, placeOrderResult
): void
other
Order a specified quantity of specified products
Parameters
commodityId string | Product ID range: Depending on the length of the product ID |
---|---|
amount number | Quantity range: unlimited type: integer |
placeOrderResult (status : number , msg : string ) => void | Order status callback |
status meaning:
status = 200: Order payment successful
status = 408: request timeout
status = 409: Processing order callback error
status = 410: Processing payment callback error
status = 501: Sorry, your credit is running low
status = 502: Not yet available for purchase
status = 503: The amount parameter type is incorrect
redeemGiftCode
• Static
redeemGiftCode(player
, GiftCode
, redeemCallback
): void
other
Gift Code Redemption
Parameters
player Player | Player objects that need to be exchanged |
---|---|
GiftCode string | Gift Code range: Depending on the length of the redemption code |
redeemCallback (result : RedeemResponse ) => void | The callback function for the exchange result |
RedeemResponse status: Exchange status.
200 : Redemption successful
400 : Exchange failed (exchange code does not exist)
423 : Exchange failed (frequent requests)
1002 Exchange failed (exchange code is not within its expiration date)
1010 Exchange failed (exchange code already used)
1011 Exchange failed (exchange timeout)
1012 Exchange failed (gift package inventory insufficient)
1013 Exchange failed (exceeding the number of exchanges)
1014 Exchange failed (database failure)
1015 Exchange failed (non game item)
RedeemResponse message: Redeem information
When the redemption status is successful: the redemption information is the details of the gift package content and props.
When the exchange status is failed: the exchange information is the failure details, for example: the exchange code does not exist.
Example usage: Create a script called PurchaseExample, place it in the object bar, open the script, modify the original content to the following, publish the game for mobile testing, and after 5 seconds, the coin balance will be displayed
@Component
export default class NewScript extends Script {
@Property({replicated:true,multicast:true})
public player:Player;
@Property({replicated:true,multicast:true})
public playerid:string
protected onStart(): void {
if(SystemUtil.isClient()) {
this.playerid = Player.localPlayer.userId;
console.log(this.playerid);
}
if(SystemUtil.isServer()){
this.textFunc();
}
}
@RemoteFunction(Server)
public textFunc(){
Player.getAllPlayers().forEach(element => {
this.player = element;
});
// Fill in the redemption code in ''
PurchaseService.redeemGiftCode(this.player, "" ,(result:RedeemResponse)=>{
console.log("result.message------------" + result.message);
console.log("result.message------------" + result.status);
});
console.log("--------over----------")
}
}
@Component
export default class NewScript extends Script {
@Property({replicated:true,multicast:true})
public player:Player;
@Property({replicated:true,multicast:true})
public playerid:string
protected onStart(): void {
if(SystemUtil.isClient()) {
this.playerid = Player.localPlayer.userId;
console.log(this.playerid);
}
if(SystemUtil.isServer()){
this.textFunc();
}
}
@RemoteFunction(Server)
public textFunc(){
Player.getAllPlayers().forEach(element => {
this.player = element;
});
// Fill in the redemption code in ''
PurchaseService.redeemGiftCode(this.player, "" ,(result:RedeemResponse)=>{
console.log("result.message------------" + result.message);
console.log("result.message------------" + result.status);
});
console.log("--------over----------")
}
}