How is it possible to access a player's transactions through Cloud code ?
- In Test Harness, there is the ListTransactionsRequest event
- In NoSQL tab I can see them in the system collection "PlayerTransactionAudit"
But in Cloud code or dynamic forms, didn't found...
Thanks for your help.
Best Answer
C
Customer Support
said
almost 5 years ago
Hi Eric,
Not directly I'm afraid, Marcel has pointed you in the right direction here. You could indeed use SparkRequests in Cloud Code for this.
//sets the from date to 10 days back from now
var dateFrom = new Date();
dateFrom.setDate(dateFrom.getDate()-10);
//sets the to date to now
var dateTo = new Date();
dateTo.setDate(dateTo.getDate());
//send our ListTransactionsRequest
var request = new SparkRequests.ListTransactionsRequest();
request.dateFrom = getDateString(dateFrom);
request.dateTo = getDateString(dateTo);
request.entryCount = 5;
var response = request.Send();
//display the response in scriptData
Spark.setScriptData("vGoods", response)
//function to correctly format the dates for the request
function getDateString(date){
var dateString = date.toISOString();
return dateString.substr(0, dateString.lastIndexOf(".")) + "Z";
}
You could also include the "include" field in the request to filter the results.
var req = new SparkRequests.ListTransactionsRequest();
req.dateFrom = ...;
req.dateTo = ...;
req.entryCount = ...;
req.include = ...;
req.offset = ...;
var resp = req.Send(); // This object contains the response
Best,
Marcel
Customer Support
said
almost 5 years ago
Answer
Hi Eric,
Not directly I'm afraid, Marcel has pointed you in the right direction here. You could indeed use SparkRequests in Cloud Code for this.
//sets the from date to 10 days back from now
var dateFrom = new Date();
dateFrom.setDate(dateFrom.getDate()-10);
//sets the to date to now
var dateTo = new Date();
dateTo.setDate(dateTo.getDate());
//send our ListTransactionsRequest
var request = new SparkRequests.ListTransactionsRequest();
request.dateFrom = getDateString(dateFrom);
request.dateTo = getDateString(dateTo);
request.entryCount = 5;
var response = request.Send();
//display the response in scriptData
Spark.setScriptData("vGoods", response)
//function to correctly format the dates for the request
function getDateString(date){
var dateString = date.toISOString();
return dateString.substr(0, dateString.lastIndexOf(".")) + "Z";
}
You could also include the "include" field in the request to filter the results.
Thanks,
Liam
E
Eric Moncada
said
almost 5 years ago
Hi,
Thanks for your help Marcel & Liam, it's getting clearer...
But I'm still stuck.
The final goal is to display last N transactions for a given player in dynamic forms, so I need to get this list for a given userId and ordered by descending date.
Can't see these 2 options...
Customer Support
said
almost 5 years ago
Hi Eric,
You could try using SendRequestAs for this in Cloud Code, this will work the same as above but will return the transaction list for the given playerId.
It would also use the date function from the code above, let me know if that helps.
Thanks,
Liam
E
Eric Moncada
said
almost 5 years ago
Thanks Liam, I missed this way of doing...
Last thing : what is the sort order of the result ? Is it possible to change it ?
Customer Support
said
almost 5 years ago
Hi Eric,
By default the results will list the transactions starting with the most recent one first and working backwards, once you have the transactionList array you can sort it however you'd like in the response. For example response.transactionList.reverse() will reverse the list. You can play around with with this until you find something that suits your needs.
Thanks,
Liam
E
Eric Moncada
said
almost 5 years ago
Thanks Liam, you're right, once in an array, I can manipulate it locally.
Eric Moncada
How is it possible to access a player's transactions through Cloud code ?
- In Test Harness, there is the ListTransactionsRequest event
- In NoSQL tab I can see them in the system collection "PlayerTransactionAudit"
But in Cloud code or dynamic forms, didn't found...
Thanks for your help.
Hi Eric,
Not directly I'm afraid, Marcel has pointed you in the right direction here. You could indeed use SparkRequests in Cloud Code for this.
You could also include the "include" field in the request to filter the results.
Thanks,
Liam
- Oldest First
- Popular
- Newest First
Sorted by Oldest FirstMarcel Piestansky
Hi Eric,
You can create such request like this:
Best,
Marcel
Customer Support
Hi Eric,
Not directly I'm afraid, Marcel has pointed you in the right direction here. You could indeed use SparkRequests in Cloud Code for this.
You could also include the "include" field in the request to filter the results.
Thanks,
Liam
Eric Moncada
Hi,
Thanks for your help Marcel & Liam, it's getting clearer...
But I'm still stuck.
The final goal is to display last N transactions for a given player in dynamic forms, so I need to get this list for a given userId and ordered by descending date.
Can't see these 2 options...
Customer Support
Hi Eric,
You could try using SendRequestAs for this in Cloud Code, this will work the same as above but will return the transaction list for the given playerId.
It would also use the date function from the code above, let me know if that helps.
Thanks,
Liam
Eric Moncada
Thanks Liam, I missed this way of doing...
Last thing : what is the sort order of the result ? Is it possible to change it ?
Customer Support
Hi Eric,
By default the results will list the transactions starting with the most recent one first and working backwards, once you have the transactionList array you can sort it however you'd like in the response. For example response.transactionList.reverse() will reverse the list. You can play around with with this until you find something that suits your needs.
Thanks,
Liam
Eric Moncada
Thanks Liam, you're right, once in an array, I can manipulate it locally.
-
Documentation Notes
-
Design issues with user events
-
Using NoSQL
-
Runtime Collections vs Metadata Collections
-
Anonymous authentication from browser app
-
Modules
-
Movement With Unity
-
Problem with url parameters for downloadables
-
Querying NoSql GameSparks database
-
Challenge accesType
See all 2486 topics