github.com/plutov/paypal/v4@v4.7.1/payout.go (about)

     1  package paypal
     2  
     3  import (
     4  	"context"
     5  	"fmt"
     6  )
     7  
     8  // CreatePayout submits a payout with an asynchronous API call, which immediately returns the results of a PayPal payment.
     9  // For email payout set RecipientType: "EMAIL" and receiver email into Receiver
    10  // Endpoint: POST /v1/payments/payouts
    11  func (c *Client) CreatePayout(ctx context.Context, p Payout) (*PayoutResponse, error) {
    12  	req, err := c.NewRequest(ctx, "POST", fmt.Sprintf("%s%s", c.APIBase, "/v1/payments/payouts"), p)
    13  	response := &PayoutResponse{}
    14  
    15  	if err != nil {
    16  		return response, err
    17  	}
    18  
    19  	if err = c.SendWithAuth(req, response); err != nil {
    20  		return response, err
    21  	}
    22  
    23  	return response, nil
    24  }
    25  
    26  // CreateSinglePayout is deprecated, use CreatePayout instead.
    27  func (c *Client) CreateSinglePayout(ctx context.Context, p Payout) (*PayoutResponse, error) {
    28  	return c.CreatePayout(ctx, p)
    29  }
    30  
    31  // GetPayout shows the latest status of a batch payout along with the transaction status and other data for individual items.
    32  // Also, returns IDs for the individual payout items. You can use these item IDs in other calls.
    33  // Endpoint: GET /v1/payments/payouts/ID
    34  func (c *Client) GetPayout(ctx context.Context, payoutBatchID string) (*PayoutResponse, error) {
    35  	req, err := c.NewRequest(ctx, "GET", fmt.Sprintf("%s%s", c.APIBase, "/v1/payments/payouts/"+payoutBatchID), nil)
    36  	response := &PayoutResponse{}
    37  
    38  	if err != nil {
    39  		return response, err
    40  	}
    41  
    42  	if err = c.SendWithAuth(req, response); err != nil {
    43  		return response, err
    44  	}
    45  
    46  	return response, nil
    47  }
    48  
    49  // GetPayoutItem shows the details for a payout item.
    50  // Use this call to review the current status of a previously unclaimed, or pending, payout item.
    51  // Endpoint: GET /v1/payments/payouts-item/ID
    52  func (c *Client) GetPayoutItem(ctx context.Context, payoutItemID string) (*PayoutItemResponse, error) {
    53  	req, err := c.NewRequest(ctx, "GET", fmt.Sprintf("%s%s", c.APIBase, "/v1/payments/payouts-item/"+payoutItemID), nil)
    54  	response := &PayoutItemResponse{}
    55  
    56  	if err != nil {
    57  		return response, err
    58  	}
    59  
    60  	if err = c.SendWithAuth(req, response); err != nil {
    61  		return response, err
    62  	}
    63  
    64  	return response, nil
    65  }
    66  
    67  // CancelPayoutItem cancels an unclaimed Payout Item. If no one claims the unclaimed item within 30 days,
    68  // the funds are automatically returned to the sender. Use this call to cancel the unclaimed item before the automatic 30-day refund.
    69  // Endpoint: POST /v1/payments/payouts-item/ID/cancel
    70  func (c *Client) CancelPayoutItem(ctx context.Context, payoutItemID string) (*PayoutItemResponse, error) {
    71  	req, err := c.NewRequest(ctx, "POST", fmt.Sprintf("%s%s", c.APIBase, "/v1/payments/payouts-item/"+payoutItemID+"/cancel"), nil)
    72  	response := &PayoutItemResponse{}
    73  
    74  	if err != nil {
    75  		return response, err
    76  	}
    77  
    78  	if err = c.SendWithAuth(req, response); err != nil {
    79  		return response, err
    80  	}
    81  
    82  	return response, nil
    83  }