paypale/payout.go

84 lines
2.8 KiB
Go
Raw Normal View History

2019-08-21 15:50:20 +02:00
package paypal
2016-02-17 05:10:49 +01:00
import (
2021-01-03 10:28:52 +01:00
"context"
"fmt"
)
2016-02-17 05:10:49 +01:00
// CreatePayout submits a payout with an asynchronous API call, which immediately returns the results of a PayPal payment.
2016-02-17 05:10:49 +01:00
// For email payout set RecipientType: "EMAIL" and receiver email into Receiver
// Endpoint: POST /v1/payments/payouts
func (c *Client) CreatePayout(ctx context.Context, p Payout) (*PayoutResponse, error) {
2021-01-03 10:28:52 +01:00
req, err := c.NewRequest(ctx, "POST", fmt.Sprintf("%s%s", c.APIBase, "/v1/payments/payouts"), p)
2019-06-16 04:39:08 +02:00
response := &PayoutResponse{}
2016-02-17 05:10:49 +01:00
if err != nil {
2019-06-16 04:39:08 +02:00
return response, err
2016-02-17 05:10:49 +01:00
}
2017-11-23 03:15:11 +01:00
if err = c.SendWithAuth(req, response); err != nil {
2016-02-17 05:10:49 +01:00
return response, err
}
return response, nil
}
// CreateSinglePayout is deprecated, use CreatePayout instead.
func (c *Client) CreateSinglePayout(ctx context.Context, p Payout) (*PayoutResponse, error) {
return c.CreatePayout(ctx, p)
}
// GetPayout shows the latest status of a batch payout along with the transaction status and other data for individual items.
// Also, returns IDs for the individual payout items. You can use these item IDs in other calls.
// Endpoint: GET /v1/payments/payouts/ID
2021-01-03 10:28:52 +01:00
func (c *Client) GetPayout(ctx context.Context, payoutBatchID string) (*PayoutResponse, error) {
req, err := c.NewRequest(ctx, "GET", fmt.Sprintf("%s%s", c.APIBase, "/v1/payments/payouts/"+payoutBatchID), nil)
2019-06-16 04:39:08 +02:00
response := &PayoutResponse{}
if err != nil {
2019-06-16 04:39:08 +02:00
return response, err
}
2017-11-23 03:15:11 +01:00
if err = c.SendWithAuth(req, response); err != nil {
return response, err
}
return response, nil
}
// GetPayoutItem shows the details for a payout item.
// Use this call to review the current status of a previously unclaimed, or pending, payout item.
// Endpoint: GET /v1/payments/payouts-item/ID
2021-01-03 10:28:52 +01:00
func (c *Client) GetPayoutItem(ctx context.Context, payoutItemID string) (*PayoutItemResponse, error) {
req, err := c.NewRequest(ctx, "GET", fmt.Sprintf("%s%s", c.APIBase, "/v1/payments/payouts-item/"+payoutItemID), nil)
2019-06-16 04:39:08 +02:00
response := &PayoutItemResponse{}
if err != nil {
2019-06-16 04:39:08 +02:00
return response, err
}
2017-11-23 03:15:11 +01:00
if err = c.SendWithAuth(req, response); err != nil {
return response, err
}
return response, nil
}
// CancelPayoutItem cancels an unclaimed Payout Item. If no one claims the unclaimed item within 30 days,
// the funds are automatically returned to the sender. Use this call to cancel the unclaimed item before the automatic 30-day refund.
// Endpoint: POST /v1/payments/payouts-item/ID/cancel
2021-01-03 10:28:52 +01:00
func (c *Client) CancelPayoutItem(ctx context.Context, payoutItemID string) (*PayoutItemResponse, error) {
req, err := c.NewRequest(ctx, "POST", fmt.Sprintf("%s%s", c.APIBase, "/v1/payments/payouts-item/"+payoutItemID+"/cancel"), nil)
2019-06-16 04:39:08 +02:00
response := &PayoutItemResponse{}
if err != nil {
2019-06-16 04:39:08 +02:00
return response, err
}
2017-11-23 03:15:11 +01:00
if err = c.SendWithAuth(req, response); err != nil {
return response, err
}
return response, nil
}