github.com/plutov/paypal/v4@v4.7.1/sale.go (about) 1 package paypal 2 3 import ( 4 "context" 5 "fmt" 6 ) 7 8 // GetSale returns a sale by ID 9 // Use this call to get details about a sale transaction. 10 // Note: This call returns only the sales that were created via the REST API. 11 // Endpoint: GET /v1/payments/sale/ID 12 func (c *Client) GetSale(ctx context.Context, saleID string) (*Sale, error) { 13 sale := &Sale{} 14 15 req, err := c.NewRequest(ctx, "GET", fmt.Sprintf("%s%s", c.APIBase, "/v1/payments/sale/"+saleID), nil) 16 if err != nil { 17 return sale, err 18 } 19 20 if err = c.SendWithAuth(req, sale); err != nil { 21 return sale, err 22 } 23 24 return sale, nil 25 } 26 27 // RefundSale refunds a completed payment. 28 // Use this call to refund a completed payment. Provide the sale_id in the URI and an empty JSON payload for a full refund. For partial refunds, you can include an amount. 29 // Endpoint: POST /v1/payments/sale/ID/refund 30 func (c *Client) RefundSale(ctx context.Context, saleID string, a *Amount) (*Refund, error) { 31 type refundRequest struct { 32 Amount *Amount `json:"amount"` 33 } 34 35 refund := &Refund{} 36 37 req, err := c.NewRequest(ctx, "POST", fmt.Sprintf("%s%s", c.APIBase, "/v1/payments/sale/"+saleID+"/refund"), &refundRequest{Amount: a}) 38 if err != nil { 39 return refund, err 40 } 41 42 if err = c.SendWithAuth(req, refund); err != nil { 43 return refund, err 44 } 45 46 return refund, nil 47 } 48 49 // GetRefund by ID 50 // Use it to look up details of a specific refund on direct and captured payments. 51 // Endpoint: GET /v2/payments/refund/ID 52 func (c *Client) GetRefund(ctx context.Context, refundID string) (*Refund, error) { 53 refund := &Refund{} 54 55 req, err := c.NewRequest(ctx, "GET", fmt.Sprintf("%s%s", c.APIBase, "/v2/payments/refund/"+refundID), nil) 56 if err != nil { 57 return refund, err 58 } 59 60 if err = c.SendWithAuth(req, refund); err != nil { 61 return refund, err 62 } 63 64 return refund, nil 65 }