forked from go-packages/paypal
4c16ffad0a
* feature/Invoice: init, added Invoice related structs, implemented methods:GenerateInvoiceNumber,GetInvoiceDetails(by ID) * feature/Invoice: added implemented endpoints to README along with Usage Co-authored-by: Akshay Prabhakant <akshayprabhakant@Akshays-MacBook-Pro.local>
39 lines
1.1 KiB
Go
39 lines
1.1 KiB
Go
package paypal
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
)
|
|
|
|
// GenerateInvoiceNumber: generates the next invoice number that is available to the merchant.
|
|
// Endpoint: POST /v2/invoicing/generate-next-invoice-number
|
|
func (c *Client) GenerateInvoiceNumber(ctx context.Context) (*InvoiceNumber, error) {
|
|
|
|
req, err := c.NewRequest(ctx, "POST", fmt.Sprintf("%s%s", c.APIBase, "/v2/invoicing/generate-next-invoice-number"), nil)
|
|
nextInvoiceNumber := &InvoiceNumber{}
|
|
if err != nil {
|
|
return nextInvoiceNumber, err
|
|
}
|
|
|
|
if err = c.SendWithAuth(req, nextInvoiceNumber); err != nil {
|
|
return nextInvoiceNumber, err
|
|
}
|
|
|
|
return nextInvoiceNumber, nil
|
|
}
|
|
|
|
// GetInvoiceDetails: show invoice details for a particular invoice by ID.
|
|
// Endpoint: GET /v2/invoicing/invoices/{invoice_id}
|
|
func (c *Client) GetInvoiceDetails(ctx context.Context, invoiceID string) (*Invoice, error) {
|
|
req, err := c.NewRequest(ctx, "GET", fmt.Sprintf("%s%s%s", c.APIBase, "/v2/invoicing/invoices/", invoiceID), nil)
|
|
invoice := &Invoice{}
|
|
if err != nil {
|
|
return invoice, err
|
|
}
|
|
|
|
if err = c.SendWithAuth(req, invoice); err != nil {
|
|
return invoice, err
|
|
}
|
|
return invoice, nil
|
|
}
|