Skip to content

Commit

Permalink
#177 feature/Invoice: init, added Invoice related structs, implemente…
Browse files Browse the repository at this point in the history
…d met… (#249)

* 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>
  • Loading branch information
akshayDev17 and Akshay Prabhakant committed Oct 28, 2022
1 parent 1bb626d commit 4c16ffa
Show file tree
Hide file tree
Showing 4 changed files with 728 additions and 0 deletions.
26 changes: 26 additions & 0 deletions README.md
Expand Up @@ -101,6 +101,11 @@
* POST /v1/billing/subscriptions/:id/capture
* POST /v1/billing/subscriptions/:id/suspend
* GET /v1/billing/subscriptions/:id/transactions

### Invoicing

* POST /v2/invoicing/generate-next-invoice-number
* GET /v2/invoicing/invoices/:id

## Missing endpoints

Expand Down Expand Up @@ -371,6 +376,27 @@ c.DeleteWebhook("WebhookID")
c.ListWebhooks(paypal.AncorTypeApplication)
```

### Generate Next Invoice Number
```go
// GenerateInvoiceNumber: generates the next invoice number that is available to the merchant.
c.GenerateInvoiceNumber(ctx) // might return something like "0001" or "0010".
```

### Get Invoice Details by ID
```go
// the second argument is an ID, it should be valid
invoice, err := c.GetInvoiceDetails(ctx, "INV2-XFXV-YW42-ZANU-4F33")
```
* for now, we are yet to implement the ShowAllInvoices endpoint, so use the following cURL request for the same(this gives you the list of invoice-IDs for this customer)
```bash
curl -v -X GET https://api-m.sandbox.paypal.com/v2/invoicing/invoices?total_required=true \
-H "Content-Type: application/json" \
-H "Authorization: Bearer <Token>"
```

* refer to the beginning of this Usage section for obtaining a Token.


## How to Contribute

* Fork a repository
Expand Down
38 changes: 38 additions & 0 deletions invoicing.go
@@ -0,0 +1,38 @@
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
}

0 comments on commit 4c16ffa

Please sign in to comment.