I am using Cloud Code and need to get custom data of a virtual purchase, how can I do this? Thanks in advance
-Edit: I am using JavaScript
I am using Cloud Code and need to get custom data of a virtual purchase, how can I do this? Thanks in advance
-Edit: I am using JavaScript
Hi @muhammet12
I provided a sample of how to do this with Inventory Items here: How can I grab an Inventory Item Custom Data using Cloud Code? - in order to faciliate mapping to the virtual purchases, I’ve created the virtual purchase as below:
Then the previous sample can be modified to filter the player configuration for the virtual purchases like so:
const { ConfigurationApi } = require("@unity-services/economy-2.4");
module.exports = async ({ params, context, logger }) => {
const {playerId, projectId} = context;
const {configAssignmentHash} = params;
const configApi = new ConfigurationApi(context);
const getPlayerConfigRequest = {
configAssignmentHash,
playerId,
projectId,
}
try {
var config = await configApi.getPlayerConfiguration(getPlayerConfigRequest);
const virtualPurchaseConfig = config.data.results.filter((configItem) => {
return configItem.type === "VIRTUAL_PURCHASE";
})
return virtualPurchaseConfig;
// [
// {
// "costs": [
// {
// "amount": 100,
// "resourceId": "GOLD"
// }
// ],
// "created": {
// "date": "2024-04-03T10:29:05Z"
// },
// "customData": {
// "purchased": true
// },
// "id": "PURCHASE_SWORD",
// "modified": {
// "date": "2024-04-03T10:29:05Z"
// },
// "name": "PURCHASE SWORD",
// "rewards": [
// {
// "amount": 1,
// "resourceId": "SWORD"
// }
// ],
// "type": "VIRTUAL_PURCHASE"
// }
// ]
} catch (err) {
logger.error("Error while retrieving virtual purchase items", {"error.message": err.message});
throw err;
}
};