@@ -30,7 +30,6 @@ type PullPaymentResponse struct {
3030func (c * Client ) GetPullPayments (ctx context.Context , storeID * StoreID , includeArchived ... bool ) ([]* PullPaymentResponse , int , error ) {
3131 var endpoint string
3232 if len (includeArchived ) > 0 {
33- fmt .Println (includeArchived [0 ])
3433 endpoint = fmt .Sprintf ("%s/api/v1/stores/%s/pull-payments?includeArchived=%t" , c .URL , * storeID , includeArchived [0 ])
3534 } else {
3635 endpoint = fmt .Sprintf ("%s/api/v1/stores/%s/pull-payments" , c .URL , * storeID )
@@ -54,7 +53,6 @@ func (c *Client) GetPullPayments(ctx context.Context, storeID *StoreID, includeA
5453func (s * Store ) GetPullPayments (ctx context.Context , includeArchived ... bool ) ([]* PullPaymentResponse , int , error ) {
5554 var endpoint string
5655 if len (includeArchived ) > 0 {
57- fmt .Println (includeArchived [0 ])
5856 endpoint = fmt .Sprintf ("%s/api/v1/stores/%s/pull-payments?includeArchived=%t" , s .Client .URL , s .ID , includeArchived [0 ])
5957 } else {
6058 endpoint = fmt .Sprintf ("%s/api/v1/stores/%s/pull-payments" , s .Client .URL , s .ID )
@@ -169,18 +167,18 @@ func (p *PullPayment) ArchivePullPayment(ctx context.Context) (int, error) {
169167}
170168
171169// Enums NetworkFeeMode
172- type BTCPayPullPaymentStatus string
173-
174- type PullPaymentStatus struct {
175- AwaitingApproval BTCPayPullPaymentStatus
176- AwaitingPayment BTCPayPullPaymentStatus
177- InProgress BTCPayPullPaymentStatus
178- Completed BTCPayPullPaymentStatus
179- Cancelled BTCPayPullPaymentStatus
170+ type BTCPayPayoutStatus string
171+
172+ type PayoutStatus struct {
173+ AwaitingApproval BTCPayPayoutStatus
174+ AwaitingPayment BTCPayPayoutStatus
175+ InProgress BTCPayPayoutStatus
176+ Completed BTCPayPayoutStatus
177+ Cancelled BTCPayPayoutStatus
180178}
181179
182- func GetPullPaymentStatus () * PullPaymentStatus {
183- return & PullPaymentStatus {
180+ func GetPayoutStatus () * PayoutStatus {
181+ return & PayoutStatus {
184182 AwaitingApproval : "AwaitingApproval" ,
185183 AwaitingPayment : "AwaitingPayment" ,
186184 InProgress : "InProgress" ,
@@ -198,25 +196,26 @@ type Payout struct {
198196}
199197
200198type PayoutResponse struct {
201- ID PayoutID `json:"id"`
202- Revision int64 `json:"revision"`
203- PullPaymentID PullPaymentID `json:"pullPaymentId"`
204- Date string `json:"date"`
205- Destination string `json:"destination"`
206- Amount string `json:"amount"`
207- PaymentMethod string `json:"paymentMethod"`
208- PaymentMethodAmount string `json:"paymentMethodAmount"`
199+ ID PayoutID `json:"id"`
200+ Revision int64 `json:"revision"`
201+ PullPaymentID PullPaymentID `json:"pullPaymentId"`
202+ Date string `json:"date"`
203+ Destination string `json:"destination"`
204+ Amount string `json:"amount"`
205+ PaymentMethod string `json:"paymentMethod"`
206+ PaymentMethodAmount string `json:"paymentMethodAmount"`
207+ State BTCPayPayoutStatus `json:"state"`
209208}
210209
211- type PayoutRequest struct {
210+ type PayoutApproveRequest struct {
212211 Revision int64 `json:"revision"`
213212 RateRule string `json:"rateRule,omitempty"`
214213}
215214
216215// Approve a payout
217- func (c * Client ) ApprovePayout (ctx context.Context , storeID * StoreID , payoutID * PayoutID , payoutRequest * PayoutRequest ) (* PayoutResponse , int , error ) {
216+ func (c * Client ) ApprovePayout (ctx context.Context , storeID * StoreID , payoutID * PayoutID , PayoutApproveRequest * PayoutApproveRequest ) (* PayoutResponse , int , error ) {
218217 endpoint := fmt .Sprintf ("%s/api/v1/stores/%s/payouts/%s" , c .URL , * storeID , * payoutID )
219- dataReq , err := json .Marshal (payoutRequest )
218+ dataReq , err := json .Marshal (PayoutApproveRequest )
220219 if err != nil {
221220 return nil , 0 , err
222221 }
@@ -236,9 +235,9 @@ func (c *Client) ApprovePayout(ctx context.Context, storeID *StoreID, payoutID *
236235 return & dataRes , statusCode , nil
237236}
238237
239- func (s * Store ) ApprovePayout (ctx context.Context , payoutID * PayoutID , payoutRequest * PayoutRequest ) (* PayoutResponse , int , error ) {
238+ func (s * Store ) ApprovePayout (ctx context.Context , payoutID * PayoutID , PayoutApproveRequest * PayoutApproveRequest ) (* PayoutResponse , int , error ) {
240239 endpoint := fmt .Sprintf ("%s/api/v1/stores/%s/payouts/%s" , s .Client .URL , s .ID , * payoutID )
241- dataReq , err := json .Marshal (payoutRequest )
240+ dataReq , err := json .Marshal (PayoutApproveRequest )
242241 if err != nil {
243242 return nil , 0 , err
244243 }
@@ -258,8 +257,183 @@ func (s *Store) ApprovePayout(ctx context.Context, payoutID *PayoutID, payoutReq
258257 return & dataRes , statusCode , nil
259258}
260259
261- func (p * Payout ) ApprovePayout (ctx context.Context , payoutRequest * PayoutRequest ) (* PayoutResponse , int , error ) {
260+ func (p * Payout ) ApprovePayout (ctx context.Context , PayoutApproveRequest * PayoutApproveRequest ) (* PayoutResponse , int , error ) {
262261 endpoint := fmt .Sprintf ("%s/api/v1/stores/%s/payouts/%s" , p .Client .URL , p .Store .ID , p .ID )
262+ dataReq , err := json .Marshal (PayoutApproveRequest )
263+ if err != nil {
264+ return nil , 0 , err
265+ }
266+ req , err := http .NewRequestWithContext (ctx , "POST" , endpoint , bytes .NewBuffer (dataReq ))
267+ if err != nil {
268+ return nil , 0 , err
269+ }
270+ bytes , statusCode , err := p .Client .doRequest (req )
271+ if err != nil {
272+ return nil , statusCode , err
273+ }
274+ var dataRes PayoutResponse
275+ err = json .Unmarshal (bytes , & dataRes )
276+ if err != nil {
277+ return nil , 0 , err
278+ }
279+ return & dataRes , statusCode , nil
280+ }
281+
282+ // Cancel the payout
283+ func (c * Client ) CancelPayout (ctx context.Context , storeID * StoreID , payoutID * PayoutID ) (int , error ) {
284+ endpoint := fmt .Sprintf ("%s/api/v1/stores/%s/payouts/%s" , c .URL , * storeID , * payoutID )
285+ req , err := http .NewRequestWithContext (ctx , "DELETE" , endpoint , nil )
286+ if err != nil {
287+ return 0 , err
288+ }
289+ _ , statusCode , err := c .doRequest (req )
290+ if err != nil {
291+ return statusCode , err
292+ }
293+ return statusCode , nil
294+ }
295+
296+ func (s * Store ) CancelPayout (ctx context.Context , payoutID * PayoutID ) (int , error ) {
297+ endpoint := fmt .Sprintf ("%s/api/v1/stores/%s/payouts/%s" , s .Client .URL , s .ID , * payoutID )
298+ req , err := http .NewRequestWithContext (ctx , "DELETE" , endpoint , nil )
299+ if err != nil {
300+ return 0 , err
301+ }
302+ _ , statusCode , err := s .Client .doRequest (req )
303+ if err != nil {
304+ return statusCode , err
305+ }
306+ return statusCode , nil
307+ }
308+
309+ func (p * Payout ) CancelPayout (ctx context.Context ) (int , error ) {
310+ endpoint := fmt .Sprintf ("%s/api/v1/stores/%s/payouts/%s" , p .Client .URL , p .Store .ID , p .ID )
311+ req , err := http .NewRequestWithContext (ctx , "DELETE" , endpoint , nil )
312+ if err != nil {
313+ return 0 , err
314+ }
315+ _ , statusCode , err := p .Client .doRequest (req )
316+ if err != nil {
317+ return statusCode , err
318+ }
319+ return statusCode , nil
320+ }
321+
322+ // Get a pull payment
323+ func (c * Client ) GetPullPayment (ctx context.Context , pullPaymentID * PullPaymentID ) (* PullPaymentResponse , int , error ) {
324+ endpoint := fmt .Sprintf ("%s/api/v1/pull-payments/%s" , c .URL , * pullPaymentID )
325+ req , err := http .NewRequestWithContext (ctx , "GET" , endpoint , nil )
326+ if err != nil {
327+ return nil , 0 , err
328+ }
329+ bytes , statusCode , err := c .doRequest (req )
330+ if err != nil {
331+ return nil , statusCode , err
332+ }
333+ var dataRes PullPaymentResponse
334+ err = json .Unmarshal (bytes , & dataRes )
335+ if err != nil {
336+ return nil , 0 , err
337+ }
338+ return & dataRes , statusCode , nil
339+ }
340+
341+ func (p * PullPayment ) GetPullPayment (ctx context.Context ) (* PullPaymentResponse , int , error ) {
342+ endpoint := fmt .Sprintf ("%s/api/v1/pull-payments/%s" , p .Client .URL , p .ID )
343+ req , err := http .NewRequestWithContext (ctx , "GET" , endpoint , nil )
344+ if err != nil {
345+ return nil , 0 , err
346+ }
347+ bytes , statusCode , err := p .Client .doRequest (req )
348+ if err != nil {
349+ return nil , statusCode , err
350+ }
351+ var dataRes PullPaymentResponse
352+ err = json .Unmarshal (bytes , & dataRes )
353+ if err != nil {
354+ return nil , 0 , err
355+ }
356+ return & dataRes , statusCode , nil
357+ }
358+
359+ // Get payouts
360+ func (c * Client ) GetPayouts (ctx context.Context , pullPaymentID * PullPaymentID , includeCancelled ... bool ) ([]* PayoutResponse , int , error ) {
361+ var endpoint string
362+ if len (includeCancelled ) > 0 {
363+ endpoint = fmt .Sprintf ("%s/api/v1/pull-payments/%s/payouts?includeCancelled=%t" , c .URL , * pullPaymentID , includeCancelled [0 ])
364+ } else {
365+ endpoint = fmt .Sprintf ("%s/api/v1/pull-payments/%s/payouts" , c .URL , * pullPaymentID )
366+ }
367+ req , err := http .NewRequestWithContext (ctx , "GET" , endpoint , nil )
368+ if err != nil {
369+ return nil , 0 , err
370+ }
371+ bytes , statusCode , err := c .doRequest (req )
372+ if err != nil {
373+ return nil , statusCode , err
374+ }
375+ var dataRes []* PayoutResponse
376+ err = json .Unmarshal (bytes , & dataRes )
377+ if err != nil {
378+ return nil , 0 , err
379+ }
380+ return dataRes , statusCode , nil
381+ }
382+
383+ func (p * PullPayment ) GetPayouts (ctx context.Context , includeCancelled ... bool ) ([]* PayoutResponse , int , error ) {
384+ var endpoint string
385+ if len (includeCancelled ) > 0 {
386+ endpoint = fmt .Sprintf ("%s/api/v1/pull-payments/%s/payouts?includeCancelled=%t" , p .Client .URL , p .ID , includeCancelled [0 ])
387+ } else {
388+ endpoint = fmt .Sprintf ("%s/api/v1/pull-payments/%s/payouts" , p .Client .URL , p .ID )
389+ }
390+ req , err := http .NewRequestWithContext (ctx , "GET" , endpoint , nil )
391+ if err != nil {
392+ return nil , 0 , err
393+ }
394+ bytes , statusCode , err := p .Client .doRequest (req )
395+ if err != nil {
396+ return nil , statusCode , err
397+ }
398+ var dataRes []* PayoutResponse
399+ err = json .Unmarshal (bytes , & dataRes )
400+ if err != nil {
401+ return nil , 0 , err
402+ }
403+ return dataRes , statusCode , nil
404+ }
405+
406+ type PayoutRequest struct {
407+ Destination string `json:"destination"`
408+ Amount string `json:"amount"`
409+ PaymentMethod string `json:"paymentMethod"`
410+ }
411+
412+ // create a new payout
413+ func (c * Client ) CreatePayout (ctx context.Context , pullPaymentID * PullPaymentID , payoutRequest * PayoutRequest ) (* PayoutResponse , int , error ) {
414+ endpoint := fmt .Sprintf ("%s/api/v1/pull-payments/%s/payouts" , c .URL , * pullPaymentID )
415+ dataReq , err := json .Marshal (payoutRequest )
416+ if err != nil {
417+ return nil , 0 , err
418+ }
419+ req , err := http .NewRequestWithContext (ctx , "POST" , endpoint , bytes .NewBuffer (dataReq ))
420+ if err != nil {
421+ return nil , 0 , err
422+ }
423+ bytes , statusCode , err := c .doRequest (req )
424+ if err != nil {
425+ return nil , statusCode , err
426+ }
427+ var dataRes PayoutResponse
428+ err = json .Unmarshal (bytes , & dataRes )
429+ if err != nil {
430+ return nil , 0 , err
431+ }
432+ return & dataRes , statusCode , nil
433+ }
434+
435+ func (p * PullPayment ) CreatePayout (ctx context.Context , payoutRequest * PayoutRequest ) (* PayoutResponse , int , error ) {
436+ endpoint := fmt .Sprintf ("%s/api/v1/pull-payments/%s/payouts" , p .Client .URL , p .ID )
263437 dataReq , err := json .Marshal (payoutRequest )
264438 if err != nil {
265439 return nil , 0 , err
0 commit comments