You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
42 lines
938 B
42 lines
938 B
6 months ago
|
package paypal
|
||
|
|
||
|
import (
|
||
|
"bkb-payment/pkg/util"
|
||
|
"bytes"
|
||
|
"encoding/json"
|
||
|
"fmt"
|
||
|
"io"
|
||
|
"net/http"
|
||
|
)
|
||
|
|
||
|
func CreateBatchPayouts(token string, params *PayoutRequest) (error, PayoutResponse) {
|
||
|
var (
|
||
|
err error
|
||
|
result PayoutResponse
|
||
|
)
|
||
|
reqBytes, _ := json.Marshal(¶ms)
|
||
|
req, err := http.NewRequest(http.MethodPost, baseurl+payouts, bytes.NewBuffer(reqBytes))
|
||
|
if err != nil {
|
||
|
return err, result
|
||
|
}
|
||
|
req.Header.Add("Content-Type", "application/json")
|
||
|
req.Header.Add("PayPal-Request-Id", util.GetRandomString(20))
|
||
|
req.Header.Add("Authorization", "Bearer "+token)
|
||
|
httpClient := &http.Client{}
|
||
|
resp, err := httpClient.Do(req)
|
||
|
if err != nil {
|
||
|
return err, result
|
||
|
}
|
||
|
defer resp.Body.Close()
|
||
|
resBody, err := io.ReadAll(resp.Body)
|
||
|
if err != nil {
|
||
|
return err, result
|
||
|
}
|
||
|
fmt.Println("CreateBatchPayouts:", string(resBody))
|
||
|
err = json.Unmarshal(resBody, &result)
|
||
|
if err != nil {
|
||
|
return err, result
|
||
|
}
|
||
|
return nil, result
|
||
|
}
|