Advertisement
Guest User

Untitled

a guest
May 23rd, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.22 KB | None | 0 0
  1. var TRANSFER_URL = "https://api.pocketfulofquarters.com";
  2. var SERVER_TOKEN = "l1jsez9od0r906tsz3rwqhd0prwgxh2gb9o9iarovutic3wt74g0mmt"; //ENTER SERVER TOKEN HERE
  3. var APP_ADDRESS = "0x365bd2c36a92f4228d7f0d6d6265e8637671be0d"; //ENTER APP ADDRESS HERE
  4.  
  5.  
  6. //PlayFab Cloud script handler
  7. handlers.AwardQuarters = function (args, context) {
  8. var result = AwardQuarters(args);
  9. return result;
  10. };
  11.  
  12.  
  13.  
  14. function AwardQuarters (args) {
  15.  
  16. var amount = args["amount"];
  17. var user = args["userId"];
  18.  
  19. if (SERVER_TOKEN == "") {
  20. log.error("Missing SERVER_TOKEN parameter");
  21. return;
  22. }
  23. if (APP_ADDRESS == "") {
  24. log.error("Missing APP_ADDRESS parameter");
  25. return;
  26. }
  27. if (amount == undefined || amount == null) {
  28. log.error("Missing amount parameter");
  29. return;
  30. }
  31. if (user == undefined || user == null) {
  32. log.error("Missing user parameter");
  33. return;
  34. }
  35.  
  36. log.info("Award " + amount + " quarters to user: " + user);
  37.  
  38.  
  39. var requestAuthorized = true;
  40.  
  41. /*
  42. ######## ENTER YOUR CUSTOM LOGIC HERE,
  43. BY DEFAULT EVERY AWARD REQUEST IS ACCEPTED
  44.  
  45.  
  46. var shouldReceiveDailyBonus = !DidReceivedBonusToday(userId); //DidReceivedBonusToday could be a custom logic method checking Playfab user data
  47.  
  48. if (shouldReceiveDailyBonus == false) {
  49. log.error("Daily bonus already given today");
  50. requestAuthorized = false;
  51. }
  52.  
  53. if (amount != DAILY_BONUS_AMOUNT) {
  54. log.error("Requested daily bonus amount is incorrect");
  55. requestAuthorized = false;
  56. }
  57.  
  58.  
  59. */
  60.  
  61.  
  62. if (!requestAuthorized) return { error: "Award Quarters request not authorized by game server" };
  63.  
  64. var postData = {
  65. "amount": amount,
  66. "user": user
  67. };
  68.  
  69. var url = TRANSFER_URL + "/v1/accounts/" + APP_ADDRESS + "/transfer";
  70.  
  71. var headers = {
  72. 'Authorization': 'Bearer ' + SERVER_TOKEN,
  73. 'Content-Type': 'application/json;charset=UTF-8'
  74. };
  75.  
  76. var contentType = "application/json";
  77. var contentBody = JSON.stringify(postData);
  78. var response = http.request(url, "post", contentBody, contentType, headers);
  79.  
  80. return response;
  81. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement