@@ -8,26 +8,38 @@ exports.optional = ['recurring', 'usePercentage', 'jar']
8
8
9
9
// Define
10
10
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
+ } )
22
26
}
23
27
}
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
+ } )
31
43
}
32
44
33
45
// 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) {
45
57
var amount = args . amount
46
58
var recurring = args . recurring
47
59
var usePercentage = recurring ? true : args . usePercentage
48
- var data = { }
60
+ var data = [ ]
49
61
50
62
if ( ! ( member instanceof Array ) ) {
51
63
member = [ member ]
@@ -65,7 +77,11 @@ exports.func = function (args) {
65
77
throw new Error ( 'Sum of percent values must be less than 100' )
66
78
}
67
79
}
68
- data [ member [ i ] ] = value
80
+ data . push ( {
81
+ recipientId : member [ i ] ,
82
+ recipientType : 'User' ,
83
+ amount : value
84
+ } )
69
85
}
70
86
71
87
return getGeneralToken ( { jar : jar } )
0 commit comments