Linking Purchase Complete Event(Client)
To apply IWP purchase confirmation events in the World, you must create a new ZEPETOScript and link the OnPurchaseComplete and OnPurchaseFailed event functions.
Each function is designed to receive the following purchase comments:
API | Description |
---|---|
OnPurchaseComplete(item) | Callback called at the completion of the purchase. |
OnPurchaseFailed(error) | Callback called on purchase failure. ZEM will not be deducted, and will not be called if the user cancels the purchase. |
You can find details on the item you purchased.
API | Description |
---|---|
item.itemId | You can access the purchased item via item ID. |
item.name | You can access the purchased item via item name. |
item.description | You can access the purchased item via item description. |
item.price | You can access the purchased item via item price. |
In Scene, create a GameObject to link with IWP events, and add the ZEPETOScript below.
import { ZepetoScriptBehaviour } from 'ZEPETO.Script';
export default class IWPSample extends ZepetoScriptBehaviour {
OnPurchaseComplete(item) {
console.log("OnPurchaseComplete");
console.log(`item.itemId : ${item.itemId}, item.name : ${item.name}, item.description : ${item.description}, item.price : ${item.price}`);
}
OnPurchaseFailed(error) {
console.log(`OnPurchaseFailed : ${error.message}`);
}
}
Click the [+] button in the OnPurchaseCompletion and OnPurchaseFailed items from the ZEPETO IWP Button component to select the ZEPETO Script to link to the purchase event.
The ids in "ItemID" will populate based on the IWP items you've set up in the world console.
Please refer to the following guide. [Making World Products]
Caution
- You must register a World cover image to do an item purchase test before publishing.
- Please ensure you've entered a valid world cover image, otherwise you may encounter an error.



Screen when OnPurchaseComplete and OnPurchaseFailed are successfully linked
The Item ID value associated with zepetoIWPButton can also be set in code using the SetItemId function.
import { ZepetoScriptBehaviour } from 'ZEPETO.Script';
import { ZepetoIWPButton } from 'ZEPETO.IWP';
export default class IWPTest extends ZepetoScriptBehaviour {
public zepetoIWPButton: ZepetoIWPButton;
Start() {
this.zepetoIWPButton.SetItemId("item_01");
}
}
Updated 3 months ago