Skip to content

Commit 25e9fee

Browse files
committedFeb 2, 2020
Use latest Roblox endpoint
1 parent 2c06428 commit 25e9fee

File tree

1 file changed

+36
-20
lines changed

1 file changed

+36
-20
lines changed
 

‎lib/group/groupPayout.js

+36-20
Original file line numberDiff line numberDiff line change
@@ -8,26 +8,38 @@ exports.optional = ['recurring', 'usePercentage', 'jar']
88

99
// Define
1010
function groupPayout (jar, token, group, data, recurring, usePercentage) {
11-
var httpOpt = {
12-
url: '//www.roblox.com/groups/' + group + (recurring === true ? '/recurring-payout' : ('/one-time-payout/' + (usePercentage === true ? 'true' : 'false'))),
13-
options: {
14-
resolveWithFullResponse: true,
15-
method: 'POST',
16-
jar: jar,
17-
headers: {
18-
'X-CSRF-TOKEN': token
19-
},
20-
form: {
21-
percentages: JSON.stringify(data)
11+
return new Promise((resolve, reject) => {
12+
var httpOpt = {
13+
url: `//groups.roblox.com/v1/groups/${group}/payouts${recurring ? '/recurring' : ''}`,
14+
options: {
15+
resolveWithFullResponse: true,
16+
method: 'POST',
17+
jar: jar,
18+
headers: {
19+
'X-CSRF-TOKEN': token,
20+
'Content-Type': 'application/json'
21+
},
22+
body: JSON.stringify({
23+
PayoutType: (usePercentage ? 'Percentage' : 'FixedAmount'),
24+
Recipients: data
25+
})
2226
}
2327
}
24-
}
25-
return http(httpOpt)
26-
.then(function (res) {
27-
if (res.statusCode !== 200) {
28-
throw new Error(res.statusMessage)
29-
}
30-
})
28+
return http(httpOpt)
29+
.then(function (res) {
30+
if (res.statusCode === 200) {
31+
resolve()
32+
} else {
33+
const body = JSON.parse(res.body) || {}
34+
if (body.errors && body.errors.length > 0) {
35+
var errors = body.errors.map((e) => {
36+
return e.message
37+
})
38+
reject(new Error(`${res.statusCode} ${errors.join(', ')}`))
39+
}
40+
}
41+
})
42+
})
3143
}
3244

3345
// Although I would normally leave it to the endpoint to error when incorrect percentages are given, it's not very reliable so I'll do it instead
@@ -45,7 +57,7 @@ exports.func = function (args) {
4557
var amount = args.amount
4658
var recurring = args.recurring
4759
var usePercentage = recurring ? true : args.usePercentage
48-
var data = {}
60+
var data = []
4961

5062
if (!(member instanceof Array)) {
5163
member = [member]
@@ -65,7 +77,11 @@ exports.func = function (args) {
6577
throw new Error('Sum of percent values must be less than 100')
6678
}
6779
}
68-
data[member[i]] = value
80+
data.push({
81+
recipientId: member[i],
82+
recipientType: 'User',
83+
amount: value
84+
})
6985
}
7086

7187
return getGeneralToken({ jar: jar })

0 commit comments

Comments
 (0)